- Revert commit a45b767a80 in favor of tinkering "enough_power_threshold_mw" in system-settings.ini

- Add InfoNX (For battery, charger, clocks, voltages, etc.)
This commit is contained in:
KazushiM
2021-09-16 16:16:30 +08:00
parent cb13e21e85
commit bf3bd67dd6
23 changed files with 10176 additions and 83 deletions

View File

@@ -20,11 +20,12 @@ Overclocking suite for Switch **(Mariko Only)** running on Atmosphere CFW. Suppo
- **Auto-Boost CPU for faster game loading**
- **Fan Control Optimization** at high load
- **Modded sys-clk and ReverseNX**(-Tools and -RT)
- Option to regard Power Delivery chargers supplying >=18W (typically, 9V/2A) as official chargers
- **No need to change clocks manually** after toggling modes in ReverseNX
- Profile-aware clock override for all games
- Disable background services, less heat and power consumption in standby mode
- Game recording and SysDVR streaming @ 60fps with high video bitrate
- System Settings
- Disable background services, less heat and power consumption in standby mode
- Game recording and SysDVR streaming @ 60fps with high video bitrate
- Option to change the threshold for chargers providing enough power
- Remove copyright watermark in screenshots/recordings, courtesy of [HookedBehemoth](https://github.com/HookedBehemoth/exefs_patches)
- **TinyMemBenchNX**: DRAM throughput and latency test based on [tinymembench](https://github.com/ssvb/tinymembench)
@@ -43,12 +44,10 @@ Overclocking suite for Switch **(Mariko Only)** running on Atmosphere CFW. Suppo
- When a game launches or is in loading screen, sys-clk will boost CPU to 1963.5 MHz (w/o charger) and 2295.0 MHz (with charger) for ~10 seconds or until the loading screen ends.
- Some games don't utilize `SetCpuBoostMode` at all, e.g. Overcooked 2, so Auto-Boost will be unavailable to these games.
- To **disable this feature**, simply remove `boost_start.flag` and `boost.flag` in `/config/sys-clk/ `.
- **Fan Control Optimization** at high load
- **Fan Control Optimization** at high load for IcosaMariko/Hoag
- Higher tolerable temperature and smoother fan curve. Set `holdable_tskin` to 56˚C. Previously it's set to 48˚C, so by default the fan would go crazy (80~100%) easily with a slight degree of OC.
- **Modded sys-clk and ReverseNX**(-Tools and -RT)
- Option to regard Power Delivery chargers that could supply >=18W (typically, 9V/2A) as official chargers.
- To **disable this feature**, remove `/config/sys-clk/pd18w_official.flag `.
- **No need to change clocks manually** after toggling modes in ReverseNX
- **No need to change clocks manually** after toggling modes in ReverseNX
- Add `/config/sys-clk/downclock_dock.flag` to use handheld clocks in Docked mode when Handheld mode is set in ReverseNX.
- To **disable this feature**, use original version of ReverseNX-RT and delete `/config/sys-clk/ReverseNX_sync.flag`.
- Profile-aware clock override for all games
@@ -76,8 +75,9 @@ Overclocking suite for Switch **(Mariko Only)** running on Atmosphere CFW. Suppo
- It has noticeable performance impacts in demanding games.
- Video duration shown in album will be twice than the actual value, while the playback speed is not affected.
- To **disable** this feature, simply remove the `[am.debug]` section in `system_settings.ini`.
- Option to change the threshold for chargers providing enough power
- Find the string `enough_power_threshold_mw` in `system_settings.ini`. The default value is `0x9858` (39,000 mW).
- To lower the threshold, you may change the value to `0x4268` (17,000 mW). Now the system and "sys-clk" will see typical Power Delivery chargers that only supply up to 18W (9V/2A) as "Official Chargers".
## Installation
@@ -132,7 +132,7 @@ Simply build `loader.kip` from Atmosphere and load it with hekate if you don't f
- CTCaer for [Hekate-ipl](https://github.com/CTCaer/hekate) bootloader, RE and hardware research
- [devkitPro](https://devkitpro.org/) for All-In-One homebrew toolchains
- HookedBehemoth for am_no_copyright [patch](https://github.com/HookedBehemoth/exefs_patches)
- masagrator for [ReverseNX-RT](https://github.com/masagrator/ReverseNX-RT)
- masagrator for [ReverseNX-RT](https://github.com/masagrator/ReverseNX-RT) and [BatteryChargeInfoNX](https://github.com/masagrator/BatteryChargeInfoNX)
- RetroNX team for [sys-clk](https://github.com/retronx-team/sys-clk)
- SciresM and Reswitched Team for the state-of-the-art [Atmosphere](https://github.com/Atmosphere-NX/Atmosphere) CFW of Switch
- suchmememanyskill for [TegraExplorer](https://github.com/suchmememanyskill/TegraExplorer) and [TegraScript](https://github.com/suchmememanyskill/TegraScript)

View File

@@ -9,6 +9,18 @@ tskin_rate_table_handheld = str!"[[-1000000, 40000, 0, 0], [36000, 43000, 51, 51
; 0xDAC0 = 56,000 = 56˚C
holdable_tskin = u32!0xDAC0
;Charger Parameters
[psm]
;5V CDP/DCP (BC1.2/QC?) Charger Current Limit
;0x4B0 = 1200mA(Hoag Default)
;0x5DC = 1500mA(IcosaMariko/Aula Default)
;0x7D0 = 2000mA
cdp_dcp_input_current_limit_in_ma = u32!0x5DC
;Enough Power Threshold in mW
;0x9858 = 39,000mW(Default)
;0x4268 = 17,000mW(typical 9V/2A PD chargers)
enough_power_threshold_mw = u32!0x9858 ;39,000mW
;Game Recording FPS and Bitrate
[am.debug]
;30 or 60
@@ -17,7 +29,7 @@ continuous_recording_fps=u32!60
continuous_recording_video_bit_rate=u32!0x780000
;Disable services for power saving in standby mode
;Delete following part if you use Nintendo Online Services
;Delete all the following lines if you use Nintendo Online Services
[bgtc]
enable_halfawake = u32!0x0
minimum_interval_normal = u32!0x7FFFFFFF
@@ -103,20 +115,17 @@ autonomic_correction_immediate_try_interval_milliseconds = u32!0x7FFFFFFF
[systemupdate]
bgnup_retry_seconds = u32!0x7FFFFFFF
;Test
[ns.rights]
;skip_account_validation_on_rights_check = u8!0x1
;next_available_time_of_unexpected_error = u32!0x7FFFFFFF
skip_account_validation_on_rights_check = u8!0x1
next_available_time_of_unexpected_error = u32!0x7FFFFFFF
[pctl]
;intermittent_task_interval_seconds = u32!0x7FFFFFFF
intermittent_task_interval_seconds = u32!0x7FFFFFFF
[apm]
;throttling_for_undock_enabled = u8!0x0 ;1 for IcosaMariko/Aula, 0 for Hoag
throttling_for_undock_enabled = u8!0x0 ;1 for IcosaMariko/Aula, 0 for Hoag
[psm]
;cdp_dcp_input_current_limit_in_ma = u32!0x5DC ;1500mA for IcosaMariko/Aula, 1200mA for Hoag
;enough_power_threshold_mw = u32!0x9858 ;39,000mW
;boost_threshold_in_milli_volt = u32!0xCF8 ;3,320mV for IcosaMariko/Hoag, 0 for Aula
;charge_configuration_number = u32!0x0 ;0 for IcosaMariko/Hoag, 1 for Aula

Binary file not shown.

11
Source/InfoNX/.gitignore vendored Normal file
View File

@@ -0,0 +1,11 @@
build/
*.ovl
*.elf
*.nacp
*.nro
*.DS_Store

3
Source/InfoNX/.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "libs/libtesla"]
path = libs/libtesla
url = https://github.com/WerWolv/libtesla

208
Source/InfoNX/Makefile Normal file
View File

@@ -0,0 +1,208 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/libnx/switch_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
#
# NO_ICON: if set to anything, do not use icon.
# NO_NACP: if set to anything, no .nacp file is generated.
# APP_TITLE is the name of the app stored in the .nacp file (Optional)
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
# APP_VERSION is the version of the app stored in the .nacp file (Optional)
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
# ICON is the filename of the icon (.jpg), relative to the project folder.
# If not set, it attempts to use one of the following (in this order):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/default_icon.jpg
#
# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
# If not set, it attempts to use one of the following (in this order):
# - <Project name>.json
# - config.json
# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
# NACP building is skipped as well.
#---------------------------------------------------------------------------------
APP_TITLE := InfoNX
APP_VERSION := 1.0.1
TARGET := InfoNX-ovl
BUILD := build
SOURCES := source
DATA := data
INCLUDES := libs/libtesla/include
NO_ICON := 1
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := -g -Wall -Os -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__ -DAPP_VERSION="\"$(APP_VERSION)\""
CXXFLAGS := $(CFLAGS) -fno-exceptions -std=c++20
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lnx
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(CONFIG_JSON)),)
jsons := $(wildcard *.json)
ifneq (,$(findstring $(TARGET).json,$(jsons)))
export APP_JSON := $(TOPDIR)/$(TARGET).json
else
ifneq (,$(findstring config.json,$(jsons)))
export APP_JSON := $(TOPDIR)/config.json
endif
endif
else
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
endif
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.jpg)
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
else
ifneq (,$(findstring icon.jpg,$(icons)))
export APP_ICON := $(TOPDIR)/icon.jpg
endif
endif
else
export APP_ICON := $(TOPDIR)/$(ICON)
endif
ifeq ($(strip $(NO_ICON)),)
export NROFLAGS += --icon=$(APP_ICON)
endif
ifeq ($(strip $(NO_NACP)),)
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
endif
ifneq ($(APP_TITLEID),)
export NACPFLAGS += --titleid=$(APP_TITLEID)
endif
ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@rm -fr $(BUILD) $(TARGET).ovl $(TARGET).nro $(TARGET).nacp $(TARGET).elf
#---------------------------------------------------------------------------------
else
.PHONY: all
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT).ovl
$(OUTPUT).ovl : $(OUTPUT).elf $(OUTPUT).nacp
@elf2nro $< $@ $(NROFLAGS)
@echo "built ... $(notdir $(OUTPUT).ovl)"
$(OUTPUT).elf : $(OFILES)
$(OFILES_SRC) : $(HFILES_BIN)
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@@ -0,0 +1,5 @@
# These are supported funding model platforms
patreon: werwolv
custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KP7XRJAND9KWU&source=url
github: WerWolv

12
Source/InfoNX/libs/libtesla/.gitignore vendored Normal file
View File

@@ -0,0 +1,12 @@
debug
release
lib
*.bz2
example/build/
*.elf
*.nacp
*.ovl

View File

@@ -0,0 +1,45 @@
{
"configurations": [
{
"name": "DKP Aarch64 Windows",
"includePath": [
"C:/devkitPro/devkitA64/aarch64-none-elf/include/**",
"C:/devkitPro/devkitA64/lib/gcc/aarch64-none-elf/9.2.0/include/**",
"C:/devkitPro/libnx/include/**",
"C:/devkitPro/portlibs/switch/include/**",
"${workspaceFolder}/include/**"
],
"defines": [
"SWITCH",
"VERSION=\"\"",
"__SWITCH__",
"__aarch64__"
],
"compilerPath": "C:/devkitPro/devkitA64/bin/aarch64-none-elf-g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
},
{
"name": "DKP Aarch64 Linux",
"includePath": [
"/opt/devkitpro/devkitA64/aarch64-none-elf/include/**",
"/opt/devkitpro/devkitA64/lib/gcc/aarch64-none-elf/9.2.0/include/**",
"/opt/devkitpro/libnx/include/**",
"/opt/devkitpro/portlibs/switch/include/**",
"${workspaceFolder}/include/**"
],
"defines": [
"SWITCH",
"VERSION=\"\"",
"__SWITCH__",
"__aarch64__"
],
"compilerPath": "/opt/devkitpro/devkitA64/bin/aarch64-none-elf-g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}

View File

@@ -0,0 +1,58 @@
{
"files.associations": {
"*.tcc": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"map": "cpp",
"stack": "cpp",
"list": "cpp"
}
}

View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@@ -0,0 +1,32 @@
# libtesla
<p align="center">
<img src="https://i.imgur.com/fhwyjbd.png">
</p>
libtesla is the interface between the Tesla overlay loader and user-made Overlays. It handles all layer creation, UI creation, drawing and input management.
It's main goal is to make sure all overlays look and feel similar and don't differenciate themselves from the switch's native overlays.
## Screenshots
<div>
<img src="https://i.imgur.com/jJpxYjb.jpg" style="width: 50%; float: center">
<img src="https://i.imgur.com/nBUc7ps.jpg" style="width: 50%; float: right">
</div>
`Overlays do NOT show up on Screenshots. These pictures were taken using a capture card`
## Example
An example for how to use libtesla can be found here: https://github.com/WerWolv/libtesla/tree/master/example
To create your own Overlay, please consider creating a new repository using the official Tesla overlay template: https://github.com/WerWolv/Tesla-Template
**Please Note:** While it is possible to create overlays without libtesla, it's highly recommended to not do so. libtesla handles showing and hiding of overlays, button combo detection, layer creation and a lot more. Not using it will lead to an inconsistent user experience when using multiple different overlays ultimately making it worse for the end user. If something's missing, please consider opening a PR here.
## Credits
- **switchbrew** for nx-hbloader which is used as basis for overlay loading
- **kardch** for the amazing icon
- **All the devs on AtlasNX, RetroNX and Switchbrew** for their feedback
- **All overlay devs** for making something awesome out of this :)

View File

@@ -0,0 +1,209 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/libnx/switch_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
#
# NO_ICON: if set to anything, do not use icon.
# NO_NACP: if set to anything, no .nacp file is generated.
# APP_TITLE is the name of the app stored in the .nacp file (Optional)
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
# APP_VERSION is the version of the app stored in the .nacp file (Optional)
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
# ICON is the filename of the icon (.jpg), relative to the project folder.
# If not set, it attempts to use one of the following (in this order):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/default_icon.jpg
#
# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
# If not set, it attempts to use one of the following (in this order):
# - <Project name>.json
# - config.json
# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
# NACP building is skipped as well.
#---------------------------------------------------------------------------------
APP_TITLE := Tesla Example
APP_VERSION := 1.3.0
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := ../include
NO_ICON := 1
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CXXFLAGS := $(CFLAGS) -fno-exceptions -std=c++17
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lnx
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(LIBNX)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
ifeq ($(strip $(CONFIG_JSON)),)
jsons := $(wildcard *.json)
ifneq (,$(findstring $(TARGET).json,$(jsons)))
export APP_JSON := $(TOPDIR)/$(TARGET).json
else
ifneq (,$(findstring config.json,$(jsons)))
export APP_JSON := $(TOPDIR)/config.json
endif
endif
else
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
endif
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.jpg)
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
else
ifneq (,$(findstring icon.jpg,$(icons)))
export APP_ICON := $(TOPDIR)/icon.jpg
endif
endif
else
export APP_ICON := $(TOPDIR)/$(ICON)
endif
ifeq ($(strip $(NO_ICON)),)
export NROFLAGS += --icon=$(APP_ICON)
endif
ifeq ($(strip $(NO_NACP)),)
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
endif
ifneq ($(APP_TITLEID),)
export NACPFLAGS += --titleid=$(APP_TITLEID)
endif
ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@rm -fr $(BUILD) $(TARGET).ovl $(TARGET).nro $(TARGET).nacp $(TARGET).elf
#---------------------------------------------------------------------------------
else
.PHONY: all
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT).ovl
$(OUTPUT).ovl : $(OUTPUT).elf $(OUTPUT).nacp
@elf2nro $< $@ $(NROFLAGS)
@echo "built ... $(notdir $(OUTPUT).ovl)"
$(OUTPUT).elf : $(OFILES)
$(OFILES_SRC) : $(HFILES_BIN)
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@@ -0,0 +1,100 @@
#define TESLA_INIT_IMPL // If you have more than one file using the tesla header, only define this in the main one
#include <tesla.hpp> // The Tesla Header
class GuiSecondary : public tsl::Gui {
public:
GuiSecondary() {}
virtual tsl::elm::Element* createUI() override {
auto *rootFrame = new tsl::elm::OverlayFrame("Tesla Example", "v1.3.2 - Secondary Gui");
rootFrame->setContent(new tsl::elm::DebugRectangle(tsl::Color{ 0x8, 0x3, 0x8, 0xF }));
return rootFrame;
}
};
class GuiTest : public tsl::Gui {
public:
GuiTest(u8 arg1, u8 arg2, bool arg3) { }
// Called when this Gui gets loaded to create the UI
// Allocate all elements on the heap. libtesla will make sure to clean them up when not needed anymore
virtual tsl::elm::Element* createUI() override {
// A OverlayFrame is the base element every overlay consists of. This will draw the default Title and Subtitle.
// If you need more information in the header or want to change it's look, use a HeaderOverlayFrame.
auto frame = new tsl::elm::OverlayFrame("Tesla Example", "v1.3.2");
// A list that can contain sub elements and handles scrolling
auto list = new tsl::elm::List();
// List Items
list->addItem(new tsl::elm::CategoryHeader("List items"));
auto *clickableListItem = new tsl::elm::ListItem("Clickable List Item", "...");
clickableListItem->setClickListener([](u64 keys) {
if (keys & HidNpadButton_A) {
tsl::changeTo<GuiSecondary>();
return true;
}
return false;
});
list->addItem(clickableListItem);
list->addItem(new tsl::elm::ListItem("Default List Item"));
list->addItem(new tsl::elm::ListItem("Default List Item with an extra long name to trigger truncation and scrolling"));
list->addItem(new tsl::elm::ToggleListItem("Toggle List Item", true));
// Custom Drawer, a element that gives direct access to the renderer
list->addItem(new tsl::elm::CategoryHeader("Custom Drawer", true));
list->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawCircle(x + 40, y + 40, 20, true, renderer->a(0xF00F));
renderer->drawCircle(x + 50, y + 50, 20, true, renderer->a(0xF0F0));
renderer->drawRect(x + 130, y + 30, 60, 40, renderer->a(0xFF00));
renderer->drawString("Hello :)", false, x + 250, y + 70, 20, renderer->a(0xFF0F));
renderer->drawRect(x + 40, y + 90, 300, 10, renderer->a(0xF0FF));
}), 100);
// Track bars
list->addItem(new tsl::elm::CategoryHeader("Track bars"));
list->addItem(new tsl::elm::TrackBar("\u2600"));
list->addItem(new tsl::elm::StepTrackBar("\uE13C", 20));
list->addItem(new tsl::elm::NamedStepTrackBar("\uE132", { "Selection 1", "Selection 2", "Selection 3" }));
// Add the list to the frame for it to be drawn
frame->setContent(list);
// Return the frame to have it become the top level element of this Gui
return frame;
}
// Called once every frame to update values
virtual void update() override {
}
// Called once every frame to handle inputs not handled by other UI elements
virtual bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight) override {
return false; // Return true here to signal the inputs have been consumed
}
};
class OverlayTest : public tsl::Overlay {
public:
// libtesla already initialized fs, hid, pl, pmdmnt, hid:sys and set:sys
virtual void initServices() override {} // Called at the start to initialize all services necessary for this Overlay
virtual void exitServices() override {} // Called at the end to clean up all services previously initialized
virtual void onShow() override {} // Called before overlay wants to change from invisible to visible state
virtual void onHide() override {} // Called before overlay wants to change from visible to invisible state
virtual std::unique_ptr<tsl::Gui> loadInitialGui() override {
return initially<GuiTest>(1, 2, true); // Initial Gui to load. It's possible to pass arguments to it's constructor like this
}
};
int main(int argc, char **argv) {
return tsl::loop<OverlayTest>(argc, argv);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,411 @@
#define TESLA_INIT_IMPL // If you have more than one file using the tesla header, only define this in the main one
#include <tesla.hpp> // The Tesla Header
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <switch.h>
#include "rgltr.h"
#define IS_BAT_CHARGE_ON ((_batteryChargeInfoFields->unk_x14 >> 8) & 1)
#define IS_SLOW_CHARGE_ON (_batteryChargeInfoFields->ChargeCurrentLimit < 1024)
static Service g_rgltrSrv;
Result rgltrInitialize(void) {
if(hosversionBefore(8,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
return smGetService(&g_rgltrSrv, "rgltr");
}
void rgltrExit(void) {
serviceClose(&g_rgltrSrv);
}
Service* rgltrGetServiceSession(void) {
return &g_rgltrSrv;
}
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id) {
const u32 in = module_id;
return serviceDispatchIn(&g_rgltrSrv, 0, in,
.out_num_objects = 1,
.out_objects = &session_out->s,
);
}
Result rgltrGetPowerModuleNumLimit(u32 *out) {
return serviceDispatchOut(&g_rgltrSrv, 3, *out);
}
void rgltrCloseSession(RgltrSession* session) {
serviceClose(&session->s);
}
Result rgltrGetVoltageEnabled(RgltrSession* session, u32 *out) {
return serviceDispatchOut(&session->s, 2, *out);
}
Result rgltrGetVoltage(RgltrSession* session, u32 *out_volt) {
return serviceDispatchOut(&session->s, 4, *out_volt);
}
///* Notes VoltageAvg
//
// Vavg time = 175.8ms x 2^(6+VOLT), default: VOLT = 2 (Vavg time = 45s)
//
///End of Notes
extern "C" bool is_mariko();
extern "C" void clk_check();
typedef struct {
u32 cpu_out_hz;
u32 gpu_out_hz;
u32 emc_out_hz;
u32 cpu_out_volt;
u32 gpu_out_volt;
u32 emc_out_volt;
} ClkFields;
bool is_mariko() {
u64 hardware_type = 0;
splInitialize();
splGetConfig(SplConfigItem_HardwareType, &hardware_type);
splExit();
switch(hardware_type) {
case 0: //Icosa
case 1: //Copper
return false;
case 2: //Hoag
case 3: //Iowa
case 4: //Calcio
case 5: //Aula
return true;
default:
return false;
}
}
void clk_check(ClkFields *out, bool mariko) {
int res = 0;
ClkrstSession clkrstSession;
RgltrSession rgltrSession;
res = clkrstInitialize();
if(R_FAILED(res)) {
fatalThrow(res);
}
res = rgltrInitialize();
if(R_FAILED(res)) {
fatalThrow(res);
}
rgltrOpenSession(&rgltrSession, mariko ? PcvPowerDomainId_Max77812_Cpu : PcvPowerDomainId_Max77621_Cpu);
clkrstOpenSession(&clkrstSession, PcvModuleId_CpuBus, 3);
rgltrGetVoltage(&rgltrSession, &out->cpu_out_volt);
clkrstGetClockRate(&clkrstSession, &out->cpu_out_hz);
clkrstCloseSession(&clkrstSession);
rgltrCloseSession(&rgltrSession);
rgltrOpenSession(&rgltrSession, mariko ? PcvPowerDomainId_Max77812_Gpu : PcvPowerDomainId_Max77621_Gpu);
clkrstOpenSession(&clkrstSession, PcvModuleId_GPU, 3);
rgltrGetVoltage(&rgltrSession, &out->gpu_out_volt);
clkrstGetClockRate(&clkrstSession, &out->gpu_out_hz);
clkrstCloseSession(&clkrstSession);
rgltrCloseSession(&rgltrSession);
rgltrOpenSession(&rgltrSession, mariko ? PcvPowerDomainId_Max77812_Dram : PcvPowerDomainId_Max77620_Sd1);
clkrstOpenSession(&clkrstSession, PcvModuleId_EMC, 3);
rgltrGetVoltage(&rgltrSession, &out->emc_out_volt);
clkrstGetClockRate(&clkrstSession, &out->emc_out_hz);
clkrstCloseSession(&clkrstSession);
rgltrCloseSession(&rgltrSession);
clkrstExit();
rgltrExit();
}
typedef enum {
NoHub = BIT(0), //If hub is disconnected
Rail = BIT(8), //At least one Joy-con is charging from rail
SPDSRC = BIT(12), //OTG
ACC = BIT(16) //Accessory
} BatteryChargeInfoFieldsFlags;
typedef enum {
NewPDO = 1, //Received new Power Data Object
NoPD = 2, //No Power Delivery source is detected
AcceptedRDO = 3 //Received and accepted Request Data Object
} BatteryChargeInfoFieldsPDControllerState; //BM92T series
const char* strPDControllerState[] = {
"Received new PDO",
"No PD Source",
"Received/Accpted RDO"
};
typedef enum {
None = 0,
PD = 1,
TypeC_1500mA = 2,
TypeC_3000mA = 3,
DCP = 4,
CDP = 5,
SDP = 6,
Apple_500mA = 7,
Apple_1000mA = 8,
Apple_2000mA = 9
} BatteryChargeInfoFieldsChargerType;
const char* strChargerType[] = {
"None",
"PD",
"USB-C@1.5A",
"USB-C@3.0A",
"USB-DCP",
"USB-CDP",
"USB-SDP",
"Apple@0.5A",
"Apple@1.0A",
"Apple@2.0A",
};
typedef enum {
Sink = 1,
Source = 2
} BatteryChargeInfoFieldsPowerRole;
const char* strPowerRole[] = {
"Sink",
"Source",
};
typedef struct {
int32_t InputCurrentLimit; //Input (Sink) current limit in mA
int32_t VBUSCurrentLimit; //Output (Source/VBUS/OTG) current limit in mA
int32_t ChargeCurrentLimit; //Battery charging current limit in mA (512mA when Docked, 768mA when BatteryTemperature < 17.0 C)
int32_t ChargeVoltageLimit; //Battery charging voltage limit in mV (3952mV when BatteryTemperature >= 51.0 C)
int32_t unk_x10; //Possibly an emum, getting the same value as PowerRole in all tested cases
int32_t unk_x14; //Possibly flags
BatteryChargeInfoFieldsPDControllerState PDControllerState; //Power Delivery Controller State
int32_t BatteryTemperature; //Battery temperature in milli C
int32_t RawBatteryCharge; //Raw battery charged capacity per cent-mille (i.e. 100% = 100000 pcm)
int32_t VoltageAvg; //Voltage avg in mV (more in Notes)
int32_t BatteryAge; //Battery age (capacity full / capacity design) per cent-mille (i.e. 100% = 100000 pcm)
BatteryChargeInfoFieldsPowerRole PowerRole;
BatteryChargeInfoFieldsChargerType ChargerType;
int32_t ChargerVoltageLimit; //Charger and external device voltage limit in mV
int32_t ChargerCurrentLimit; //Charger and external device current limit in mA
BatteryChargeInfoFieldsFlags Flags; //Unknown flags
} BatteryChargeInfoFields;
Result psmGetBatteryChargeInfoFields(Service* psmService, BatteryChargeInfoFields *out) {
return serviceDispatchOut(psmService, 17, *out);
}
static Result psmEnableBatteryCharging(Service* psmService) {
return serviceDispatch(psmService, 2);
}
static Result psmDisableBatteryCharging(Service* psmService) {
return serviceDispatch(psmService, 3);
}
static Result psmDisableSlowCharging(Service* psmService) {
return serviceDispatch(psmService, 10);
}
static Result psmEnableSlowCharging(Service* psmService) {
return serviceDispatch(psmService, 11);
}
FanController g_ICon;
float rotationSpeedLevel = 0;
unsigned int changeSlowChargingState = 0;
unsigned int changeDisableChargingState = 0;
bool threadexit = false;
int32_t socTempMili = 0;
char Print_x[800];
Thread t0;
bool IsEnoughPowerSupplied;
void Loop(void*) {
static Service* psmService = psmGetServiceSession();
static BatteryChargeInfoFields* _batteryChargeInfoFields = new BatteryChargeInfoFields;
static ClkFields* _clkFields = new ClkFields;
while (threadexit == false) {
if(changeSlowChargingState)
{
changeSlowChargingState = 0;
if(IS_SLOW_CHARGE_ON)
psmDisableSlowCharging(psmService);
else
psmEnableSlowCharging(psmService);
}
if(changeDisableChargingState)
{
changeDisableChargingState = 0;
if(IS_BAT_CHARGE_ON)
psmDisableBatteryCharging(psmService);
else
psmEnableBatteryCharging(psmService);
}
psmGetBatteryChargeInfoFields(psmService, _batteryChargeInfoFields);
clk_check(_clkFields, is_mariko());
tsGetTemperatureMilliC(TsLocation_External, &socTempMili);
psmIsEnoughPowerSupplied(&IsEnoughPowerSupplied);
fanControllerGetRotationSpeedLevel(&g_ICon, &rotationSpeedLevel);
snprintf(Print_x, sizeof(Print_x),
"Current Limit: %u mA IN, %u mA OUT"
"\nBattery Charg. Limit: %u mA, %u mV"
"\nunk_x10: 0x%08" PRIx32
"\nunk_x14: 0x%08" PRIx32
"\nPD Contr. State: %s (%u)"
"\nBattery Temp.: %.2f\u00B0C"
"\nRaw Battery Charge: %.2f%%"
"\nVoltage Avg: %u mV"
"\nBattery Age: %.2f%%"
"\nPower Role: %s (%u)"
"\nCharger Type: %s (%u)"
"\nCharger Limit: %u mV, %u mA"
"\nunk_x3c: 0x%08" PRIx32
"\nEnough Power Supplied: %s"
"\n"
"\nCPU Clock: %6.1f MHz"
"\nCPU Volt : %6.1f mV\n"
"\nGPU Clock: %6.1f MHz"
"\nGPU Volt : %6.1f mV\n"
"\nEMC Clock: %6.1f MHz"
"\nEMC Volt : %6.1f mV\n"
"\nSoC Temp : %2.2f \u00B0C"
"\nFan Speed: %2.2f %%\n"
"\nL-Stick: Slow Charging(0.5A) (%s)"
"\nR-Stick: Disable Charging (%s)"
,
_batteryChargeInfoFields->InputCurrentLimit,
_batteryChargeInfoFields->VBUSCurrentLimit,
_batteryChargeInfoFields->ChargeCurrentLimit,
_batteryChargeInfoFields->ChargeVoltageLimit,
_batteryChargeInfoFields->unk_x10,
_batteryChargeInfoFields->unk_x14,
strPDControllerState[_batteryChargeInfoFields->PDControllerState], _batteryChargeInfoFields->PDControllerState,
(float)_batteryChargeInfoFields->BatteryTemperature / 1000,
(float)_batteryChargeInfoFields->RawBatteryCharge / 1000,
_batteryChargeInfoFields->VoltageAvg,
(float)_batteryChargeInfoFields->BatteryAge / 1000,
strPowerRole[_batteryChargeInfoFields->PowerRole], _batteryChargeInfoFields->PowerRole,
strChargerType[_batteryChargeInfoFields->ChargerType], _batteryChargeInfoFields->ChargerType,
_batteryChargeInfoFields->ChargerVoltageLimit,
_batteryChargeInfoFields->ChargerCurrentLimit,
(int32_t)_batteryChargeInfoFields->Flags,
IsEnoughPowerSupplied ? "Yes" : "No",
(double)_clkFields->cpu_out_hz / 1000000,
(double)_clkFields->cpu_out_volt / 1000,
(double)_clkFields->gpu_out_hz / 1000000,
(double)_clkFields->gpu_out_volt / 1000,
(double)_clkFields->emc_out_hz / 1000000,
(double)_clkFields->emc_out_volt / 1000,
(float)socTempMili / 1000,
rotationSpeedLevel * 100,
IS_SLOW_CHARGE_ON ? "ON" : "OFF",
!IS_BAT_CHARGE_ON ? "ON" : "OFF"
);
svcSleepThread(800'000'000);
}
delete _batteryChargeInfoFields;
delete _clkFields;
}
class GuiTest : public tsl::Gui {
public:
GuiTest(u8 arg1, u8 arg2, bool arg3) { }
// Called when this Gui gets loaded to create the UI
// Allocate all elements on the heap. libtesla will make sure to clean them up when not needed anymore
virtual tsl::elm::Element* createUI() override {
// A OverlayFrame is the base element every overlay consists of. This will draw the default Title and Subtitle.
// If you need more information in the header or want to change it's look, use a HeaderOverlayFrame.
auto frame = new tsl::elm::OverlayFrame("InfoNX", APP_VERSION);
// A list that can contain sub elements and handles scrolling
auto list = new tsl::elm::List();
list->addItem(new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString(Print_x, false, x, y+20, 15, renderer->a(0xFFFF));
}), 500);
// Add the list to the frame for it to be drawn
frame->setContent(list);
// Return the frame to have it become the top level element of this Gui
return frame;
}
// Called once every frame to update values
virtual void update() override {}
// Called once every frame to handle inputs not handled by other UI elements
virtual bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight) override {
if (keysHeld & HidNpadButton_A) {
tsl::hlp::requestForeground(false);
return true;
}
if (keysHeld & HidNpadButton_StickL) {
changeSlowChargingState++;
return true;
}
if (keysHeld & HidNpadButton_StickR) {
changeDisableChargingState++;
return true;
}
return false; // Return true here to singal the inputs have been consumed
}
};
class OverlayTest : public tsl::Overlay {
public:
// libtesla already initialized fs, hid, pl, pmdmnt, hid:sys and set:sys
virtual void initServices() override {
smInitialize();
psmInitialize();
tsInitialize();
fanInitialize();
fanOpenController(&g_ICon, 0x3D000001);
threadCreate(&t0, Loop, NULL, NULL, 0x4000, 0x3F, -2);
threadStart(&t0);
} // Called at the start to initialize all services necessary for this Overlay
virtual void exitServices() override {
threadexit = true;
threadWaitForExit(&t0);
threadClose(&t0);
fanControllerClose(&g_ICon);
fanExit();
tsExit();
psmExit();
smExit();
} // Callet at the end to clean up all services previously initialized
virtual void onShow() override {} // Called before overlay wants to change from invisible to visible state
virtual void onHide() override {} // Called before overlay wants to change from visible to invisible state
virtual std::unique_ptr<tsl::Gui> loadInitialGui() override {
return initially<GuiTest>(1, 2, true); // Initial Gui to load. It's possible to pass arguments to it's constructor like this
}
};
int main(int argc, char **argv) {
return tsl::loop<OverlayTest>(argc, argv);
}

View File

@@ -0,0 +1,41 @@
typedef enum {
PcvPowerDomain_Max77620_Sd0 = 0,
PcvPowerDomain_Max77620_Sd1 = 1,
PcvPowerDomain_Max77620_Sd2 = 2,
PcvPowerDomain_Max77620_Sd3 = 3,
PcvPowerDomain_Max77620_Ldo0 = 4,
PcvPowerDomain_Max77620_Ldo1 = 5,
PcvPowerDomain_Max77620_Ldo2 = 6,
PcvPowerDomain_Max77620_Ldo3 = 7,
PcvPowerDomain_Max77620_Ldo4 = 8,
PcvPowerDomain_Max77620_Ldo5 = 9,
PcvPowerDomain_Max77620_Ldo6 = 10,
PcvPowerDomain_Max77620_Ldo7 = 11,
PcvPowerDomain_Max77620_Ldo8 = 12,
PcvPowerDomain_Max77621_Cpu = 13,
PcvPowerDomain_Max77621_Gpu = 14,
PcvPowerDomain_Max77812_Cpu = 15,
PcvPowerDomain_Max77812_Gpu = 16,
PcvPowerDomain_Max77812_Dram = 17,
} PowerDomain;
typedef enum {
PcvPowerDomainId_Max77620_Sd0 = 0x3A000080,
PcvPowerDomainId_Max77620_Sd1 = 0x3A000081,
PcvPowerDomainId_Max77620_Sd2 = 0x3A000082,
PcvPowerDomainId_Max77620_Sd3 = 0x3A000083,
PcvPowerDomainId_Max77620_Ldo0 = 0x3A0000A0,
PcvPowerDomainId_Max77620_Ldo1 = 0x3A0000A1,
PcvPowerDomainId_Max77620_Ldo2 = 0x3A0000A2,
PcvPowerDomainId_Max77620_Ldo3 = 0x3A0000A3,
PcvPowerDomainId_Max77620_Ldo4 = 0x3A0000A4,
PcvPowerDomainId_Max77620_Ldo5 = 0x3A0000A5,
PcvPowerDomainId_Max77620_Ldo6 = 0x3A0000A6,
PcvPowerDomainId_Max77620_Ldo7 = 0x3A0000A7,
PcvPowerDomainId_Max77620_Ldo8 = 0x3A0000A8,
PcvPowerDomainId_Max77621_Cpu = 0x3A000003,
PcvPowerDomainId_Max77621_Gpu = 0x3A000004,
PcvPowerDomainId_Max77812_Cpu = 0x3A000003,
PcvPowerDomainId_Max77812_Gpu = 0x3A000004,
PcvPowerDomainId_Max77812_Dram = 0x3A000005,
} PowerDomainId;

View File

@@ -0,0 +1,22 @@
#pragma once
//#include "../types.h"
//#include "../sf/service.h"
//#include "../services/pcv.h"
#include <switch.h>
#include "pcv_types.h"
typedef struct {
Service s;
} RgltrSession;
Result rgltrInitialize(void);
void rgltrExit(void);
Service* rgltrGetServiceSession(void);
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id);
void rgltrCloseSession(RgltrSession* session);
Result rgltrGetVoltage(RgltrSession* session, u32 *out_volt);
Result rgltrGetPowerModuleNumLimit(u32 *out);
Result rgltrGetVoltageEnabled(RgltrSession* session, u32 *out);

View File

@@ -11,42 +11,9 @@
#include <nxExt.h>
#include "clocks.h"
#include "errors.h"
#include "file_utils.h"
bool Clocks::isMariko = false;
typedef enum {
None = 0,
PD = 1,
TypeC_1500mA = 2,
TypeC_3000mA = 3,
DCP = 4,
CDP = 5,
SDP = 6,
Apple_500mA = 7,
Apple_1000mA = 8,
Apple_2000mA = 9
} BatteryChargeInfoFieldsChargerType;
typedef struct {
uint32_t InputCurrentLimit; //Input (Sink) current limit in mA
uint32_t VBUSCurrentLimit; //Output (Source/VBUS/OTG) current limit in mA
uint32_t ChargeCurrentLimit; //Battery charging current limit in mA (512mA when Docked, 768mA when BatteryTemperature < 17.0 C)
uint32_t ChargeVoltageLimit; //Battery charging voltage limit in mV (3952mV when BatteryTemperature >= 51.0 C)
uint32_t unk_x10; //Possibly an emum, getting the same value as PowerRole in all tested cases
uint32_t unk_x14; //Possibly flags
uint16_t PDControllerState; //Power Delivery Controller State
uint32_t BatteryTemperature; //Battery temperature in milli C
uint32_t RawBatteryCharge; //Raw battery charged capacity per cent-mille (i.e. 100% = 100000 pcm)
uint32_t VoltageAvg; //Voltage avg in mV (more in Notes)
uint32_t BatteryAge; //Battery age (capacity full / capacity design) per cent-mille (i.e. 100% = 100000 pcm)
uint16_t PowerRole; //Sink or Source
BatteryChargeInfoFieldsChargerType ChargerType;
uint32_t ChargerVoltageLimit; //Charger and external device voltage limit in mV
uint32_t ChargerCurrentLimit; //Charger and external device current limit in mA
uint16_t Flags; //Unknown flags
} BatteryChargeInfoFields;
void Clocks::GetList(SysClkModule module, std::uint32_t **outClocks)
{
switch(module)
@@ -226,10 +193,6 @@ void Clocks::ResetToStock(unsigned int module)
}
}
Result psmGetBatteryChargeInfoFields(Service* psmService, BatteryChargeInfoFields *out) {
return serviceDispatchOut(psmService, 17, *out);
}
SysClkProfile Clocks::GetCurrentProfile()
{
std::uint32_t mode = 0;
@@ -241,19 +204,6 @@ SysClkProfile Clocks::GetCurrentProfile()
return SysClkProfile_Docked;
}
if(FileUtils::IsPd18wAsOfficialChargerEnabled())
{
static Service* psmService = psmGetServiceSession();
static BatteryChargeInfoFields* _Fields = new BatteryChargeInfoFields;
psmGetBatteryChargeInfoFields(psmService, _Fields);
if(_Fields->ChargerType == PD)
{
uint8_t ChargerWatts = (_Fields->ChargerVoltageLimit * _Fields->ChargerCurrentLimit)/1000000.0;
if(ChargerWatts >= 17)
return SysClkProfile_HandheldChargingOfficial;
}
}
PsmChargerType chargerType;
rc = psmGetChargerType(&chargerType);

View File

@@ -21,7 +21,6 @@ static bool g_log_enabled = false;
static bool g_boost_enabled = false;
static bool g_boost_start_enabled = false;
static bool g_downclock_dock_enabled = false;
static bool g_pd18w_as_official_charger_enabled = false;
static bool g_reversenx_tool_exist = false;
static bool g_reversenx_sync_enabled = false;
static std::uint64_t g_last_flag_check = 0;
@@ -184,13 +183,6 @@ void FileUtils::InitCheckFlags()
fclose(file);
}
file = fopen(FILE_PD18W_AS_OFFICIAL_CHARGER_FLAG_PATH, "r");
if (file)
{
g_pd18w_as_official_charger_enabled = true;
fclose(file);
}
file = fopen(FILE_REVERSENX_SYNC_FLAG_PATH, "r");
if (file)
{
@@ -221,11 +213,6 @@ bool FileUtils::IsDownclockDockEnabled()
return g_downclock_dock_enabled;
}
bool FileUtils::IsPd18wAsOfficialChargerEnabled()
{
return g_pd18w_as_official_charger_enabled;
}
bool FileUtils::IsReverseNXToolExist()
{
return g_reversenx_tool_exist;

View File

@@ -25,7 +25,6 @@
#define FILE_BOOST_FLAG_PATH FILE_CONFIG_DIR "/boost.flag"
#define FILE_BOOST_START_FLAG_PATH FILE_CONFIG_DIR "/boost_start.flag"
#define FILE_DOWNCLOCK_DOCK_FLAG_PATH FILE_CONFIG_DIR "/downclock_dock.flag"
#define FILE_PD18W_AS_OFFICIAL_CHARGER_FLAG_PATH FILE_CONFIG_DIR "/pd18w_official.flag"
#define FILE_SALTYNX_PATH "/atmosphere/contents/0000000000534C56/flags/boot2.flag" // Just check for SaltyNX boot flag
#define FILE_REVERSENX_SYNC_FLAG_PATH FILE_CONFIG_DIR "/ReverseNX_sync.flag"
#define FILE_REVERSENX_RT_CONF_PATH FILE_CONFIG_DIR "/ReverseNX-RT.conf"
@@ -40,7 +39,6 @@ class FileUtils
static bool IsBoostEnabled();
static bool IsBoostStartEnabled();
static bool IsDownclockDockEnabled();
static bool IsPd18wAsOfficialChargerEnabled();
static bool IsReverseNXSyncEnabled();
static bool IsReverseNXToolExist();
static void InitializeAsync();