[sys-clk-OC] Disable unsafe frequencies by default; Remove emulator-mode; Move fast-charging handler to sysmodule

This commit is contained in:
KazushiM
2022-05-15 17:48:24 +08:00
parent fd77dfa6eb
commit 6f5de53382
14 changed files with 222 additions and 100 deletions

View File

@@ -65,10 +65,11 @@ For users in China mainland facing connection or downloading issues on GitHub, g
- **CPU/GPU Overclock** - **CPU/GPU Overclock**
- Safe: CPU/GPU @ 1785/921 MHz (HOS maximum) - Safe: CPU/GPU @ 1963/921 MHz
- It has been proved safe without charger (not reaching battery power draw threshold) - It has been proved safe without charger (not reaching battery power draw threshold)
- Unsafe: CPU/GPU @ 2397/1305 MHz - Unsafe: CPU/GPU up to 2397/1305 MHz
- **Disabled by default**, toggle "Allow Unsafe Frequencies" on in overlay or add `allow_unsafe_freq=1` to `config.ini`
<details> <details>
- Without chargers, CPU/GPU would be capped @ 1963/921 MHz or -/460 MHz (Emulator mode). - Without chargers, CPU/GPU would be capped @ 1963/921 MHz or -/460 MHz (Emulator mode).

View File

@@ -74,11 +74,11 @@ From Hekate Minerva module [sys_sdrammtc.c](https://github.com/CTCaer/hekate/blo
To protect the battery from excessive strain, clocks requested from config may be capped before applying, depending on your current profile: To protect the battery from excessive strain, clocks requested from config may be capped before applying, depending on your current profile:
| | Handheld | Handheld (Emulator) | Charging (USB) | Charging (Official) | Docked | | | Handheld | Charging (USB) | Charging (Official) | Docked |
|:-------:|:--------:|:-------------------:|:--------------:|:-------------------:|:------:| |:-------:|:--------:|:--------------:|:-------------------:|:------:|
| **MEM** | - | - | - | - | - | | **MEM** | - | - | - | - |
| **CPU** | 1963 | - | - | - | - | | **CPU** | - | - | - | - |
| **GPU** | 921 | 460 | 1267 | - | - | | **GPU** | 921 | 1267 | - | - |
## Installation ## Installation
@@ -180,8 +180,10 @@ The `[values]` section allows you to alter timings in sys-clk, you should not ne
| Key | Desc | Default | | Key | Desc | Default |
|:-----------------------:|-------------------------------------------------------------------------------|:-------:| |:-----------------------:|-------------------------------------------------------------------------------|:-------:|
|**auto_cpu_boost** | Auto-boost CPU when system Core #3 utilization ≥ 95% | ON | |**allow_unsafe_freq** | Allow unsafe frequencies (CPU > 1963.5 MHz, GPU > 921.6 MHz) | OFF |
|**auto_cpu_boost** | Auto-boost CPU when system Core #3 utilization ≥ 95% | ON |
|**sync_reversenx_mode** | Sync nominal profile (mode) with ReverseNX (-Tool and -RT) | ON | |**sync_reversenx_mode** | Sync nominal profile (mode) with ReverseNX (-Tool and -RT) | ON |
|**disable_fast_charging**| Disable Fast Charging (2000mA -> 500 mA) | OFF |
|**temp_log_interval_ms** | Defines how often sys-clk log temperatures, in milliseconds (`0` to disable) | 0 ms | |**temp_log_interval_ms** | Defines how often sys-clk log temperatures, in milliseconds (`0` to disable) | 0 ms |
|**csv_write_interval_ms**| Defines how often sys-clk writes to the CSV, in milliseconds (`0` to disable) | 0 ms | |**csv_write_interval_ms**| Defines how often sys-clk writes to the CSV, in milliseconds (`0` to disable) | 0 ms |
|**poll_interval_ms** | Defines how fast sys-clk checks and applies profiles, in milliseconds | 500 ms | |**poll_interval_ms** | Defines how fast sys-clk checks and applies profiles, in milliseconds | 500 ms |

View File

@@ -3,7 +3,7 @@ set -e
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIST_DIR="$ROOT_DIR/dist" DIST_DIR="$ROOT_DIR/dist"
CORES=8 CORES=$(nproc --all)
if [[ -n "$1" ]]; then if [[ -n "$1" ]]; then
DIST_DIR="$1" DIST_DIR="$1"

View File

@@ -67,7 +67,7 @@ typedef struct
{ {
bool systemCoreBoostCPU; bool systemCoreBoostCPU;
bool gotBoostCPUFreq; bool gotBoostCPUFreq;
bool handheldEmulatorMode; bool allowUnsafeFreq;
ReverseNXMode reverseNXMode; ReverseNXMode reverseNXMode;
uint32_t maxMEMFreq; uint32_t maxMEMFreq;
uint32_t boostCPUFreq; uint32_t boostCPUFreq;
@@ -81,8 +81,7 @@ typedef struct
}; };
} SysClkTitleProfileList; } SysClkTitleProfileList;
#define SYSCLK_CPU_HANDHELD_MAX_HZ 1963500000U #define SYSCLK_CPU_SAFE_MAX_HZ 1963500000U
#define SYSCLK_GPU_HANDHELD_EMULATOR_HZ 460800000U
#define SYSCLK_GPU_HANDHELD_MAX_HZ 921600000U #define SYSCLK_GPU_HANDHELD_MAX_HZ 921600000U
#define SYSCLK_GPU_CHARGING_USB_MAX_HZ 1267200000U #define SYSCLK_GPU_CHARGING_USB_MAX_HZ 1267200000U

View File

@@ -19,6 +19,9 @@ typedef enum {
SysClkConfigValue_CsvWriteIntervalMs, SysClkConfigValue_CsvWriteIntervalMs,
SysClkConfigValue_AutoCPUBoost, SysClkConfigValue_AutoCPUBoost,
SysClkConfigValue_SyncReverseNXMode, SysClkConfigValue_SyncReverseNXMode,
SysClkConfigValue_AllowUnsafeFrequencies,
SysClkConfigValue_DisableFastCharging,
SysClkConfigValue_ChargingLimitPercentage,
SysClkConfigValue_EnumMax, SysClkConfigValue_EnumMax,
} SysClkConfigValue; } SysClkConfigValue;
@@ -40,6 +43,12 @@ static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pr
return pretty ? "Enable Auto CPU Boost" : "auto_cpu_boost"; return pretty ? "Enable Auto CPU Boost" : "auto_cpu_boost";
case SysClkConfigValue_SyncReverseNXMode: case SysClkConfigValue_SyncReverseNXMode:
return pretty ? "Enable ReverseNX Mode Sync" : "sync_reversenx_mode"; return pretty ? "Enable ReverseNX Mode Sync" : "sync_reversenx_mode";
case SysClkConfigValue_AllowUnsafeFrequencies:
return pretty ? "Allow Unsafe Frequencies" : "allow_unsafe_freq";
case SysClkConfigValue_DisableFastCharging:
return pretty ? "Disable Fast Charging" : "disable_fast_charging";
case SysClkConfigValue_ChargingLimitPercentage:
return pretty ? "Charging Limit (%%)" : "charging_limit_perc";
default: default:
return NULL; return NULL;
} }
@@ -53,10 +62,14 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
return 500ULL; return 500ULL;
case SysClkConfigValue_TempLogIntervalMs: case SysClkConfigValue_TempLogIntervalMs:
case SysClkConfigValue_CsvWriteIntervalMs: case SysClkConfigValue_CsvWriteIntervalMs:
case SysClkConfigValue_AllowUnsafeFrequencies:
case SysClkConfigValue_DisableFastCharging:
return 0ULL; return 0ULL;
case SysClkConfigValue_AutoCPUBoost: case SysClkConfigValue_AutoCPUBoost:
case SysClkConfigValue_SyncReverseNXMode: case SysClkConfigValue_SyncReverseNXMode:
return 1ULL; return 1ULL;
case SysClkConfigValue_ChargingLimitPercentage:
return 100ULL;
default: default:
return 0ULL; return 0ULL;
} }
@@ -73,7 +86,11 @@ static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t in
return true; return true;
case SysClkConfigValue_AutoCPUBoost: case SysClkConfigValue_AutoCPUBoost:
case SysClkConfigValue_SyncReverseNXMode: case SysClkConfigValue_SyncReverseNXMode:
case SysClkConfigValue_AllowUnsafeFrequencies:
case SysClkConfigValue_DisableFastCharging:
return (input & 0x1) == input; return (input & 0x1) == input;
case SysClkConfigValue_ChargingLimitPercentage:
return (input <= 100 && input >= 20);
default: default:
return false; return false;
} }

View File

@@ -205,7 +205,7 @@ void StatusTab::updateWarningForProfile(SysClkProfile profile, bool animated)
case SysClkProfile_Handheld: case SysClkProfile_Handheld:
if (this->warningLabel->isHidden()) if (this->warningLabel->isHidden())
this->warningLabel->show([](){}); this->warningLabel->show([](){});
this->warningLabel->setText("\uE140 Handheld Mode: Max CPU freq: " + formatFreq(SYSCLK_CPU_HANDHELD_MAX_HZ) + ", Max GPU freq: " + formatFreq(SYSCLK_GPU_HANDHELD_MAX_HZ)); this->warningLabel->setText("\uE140 Handheld Mode: Max GPU freq: " + formatFreq(SYSCLK_GPU_HANDHELD_MAX_HZ));
break; break;
case SysClkProfile_HandheldChargingUSB: case SysClkProfile_HandheldChargingUSB:
if (this->warningLabel->isHidden()) if (this->warningLabel->isHidden())

View File

@@ -49,46 +49,46 @@ void MiscGui::updateConfigToggle(tsl::elm::ToggleListItem *toggle, SysClkConfigV
void MiscGui::listUI() void MiscGui::listUI()
{ {
sysclkIpcGetConfigValues(this->configList); sysclkIpcGetConfigValues(this->configList);
this->listElement->addItem(new tsl::elm::CategoryHeader("Config"));
this->unsafeFreqToggle = addConfigToggle(SysClkConfigValue_AllowUnsafeFrequencies, "Allow Unsafe Frequencies");
this->cpuBoostToggle = addConfigToggle(SysClkConfigValue_AutoCPUBoost, "Auto CPU Boost"); this->cpuBoostToggle = addConfigToggle(SysClkConfigValue_AutoCPUBoost, "Auto CPU Boost");
this->syncModeToggle = addConfigToggle(SysClkConfigValue_SyncReverseNXMode, "Sync ReverseNX Mode"); this->syncModeToggle = addConfigToggle(SysClkConfigValue_SyncReverseNXMode, "Sync ReverseNX Mode");
this->fastChargingToggle = addConfigToggle(SysClkConfigValue_DisableFastCharging, "Disable Fast Charging");
// this->chargingLimitHeader = new tsl::elm::CategoryHeader("");
// this->listElement->addItem(this->chargingLimitHeader);
// this->chargingLimitBar = new MultiStepTrackBar("", 100 - 20 + 1);
// this->chargingLimitBar->setProgress((this->configList->values[SysClkConfigValue_ChargingLimitPercentage] - 20.0F) * 100 / (100 - 20));
// this->chargingLimitBar->setValueChangedListener([this](u8 val) {
// this->configList->values[SysClkConfigValue_ChargingLimitPercentage] = val + 20;
// snprintf(chargingLimitBarDesc, 50, "Battery Charging Limit: %lu%%", this->configList->values[SysClkConfigValue_ChargingLimitPercentage]);
// this->chargingLimitHeader->setText(chargingLimitBarDesc);
// Result rc = sysclkIpcSetConfigValues(this->configList);
// if (R_FAILED(rc))
// FatalGui::openWithResultCode("sysclkIpcSetConfigValues", rc);
// this->lastContextUpdate = armGetSystemTick();
// });
// this->listElement->addItem(this->chargingLimitBar);
this->listElement->addItem(new tsl::elm::CategoryHeader("Temporary toggles"));
// Charging
this->chargingToggle = new tsl::elm::ToggleListItem("Charging", false); this->chargingToggle = new tsl::elm::ToggleListItem("Charging", false);
chargingToggle->setStateChangedListener([this](bool state) { chargingToggle->setStateChangedListener([this](bool state) {
if (PsmChargingToggler(state)) PsmChargingToggler(&state);
{ this->chargingToggle->setState(state);
this->chargingToggle->setState(state);
this->fastChargingToggle->setState(this->PsmIsFastCharging());
}
else
{
this->chargingToggle->setState(!state);
}
}); });
this->listElement->addItem(this->chargingToggle); this->listElement->addItem(this->chargingToggle);
// FastCharging
this->fastChargingToggle = new tsl::elm::ToggleListItem("Fast Charging", false);
fastChargingToggle->setStateChangedListener([this](bool state) {
if (PsmFastChargingToggler(state))
{
this->fastChargingToggle->setState(state);
}
else
{
this->fastChargingToggle->setState(!state);
}
});
this->listElement->addItem(this->fastChargingToggle);
// Backlight
this->backlightToggle = new tsl::elm::ToggleListItem("Screen Backlight", false); this->backlightToggle = new tsl::elm::ToggleListItem("Screen Backlight", false);
backlightToggle->setStateChangedListener([this](bool state) { backlightToggle->setStateChangedListener([this](bool state) {
LblUpdate(true); LblUpdate(true);
}); });
this->listElement->addItem(this->backlightToggle); this->listElement->addItem(this->backlightToggle);
this->listElement->addItem(new tsl::elm::CategoryHeader("Battery & Charging Info"));
this->listElement->addItem(new tsl::elm::CustomDrawer([this](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) { this->listElement->addItem(new tsl::elm::CustomDrawer([this](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
renderer->drawString(this->infoOutput, false, x, y, SMALL_TEXT_SIZE, DESC_COLOR); renderer->drawString(this->infoOutput, false, x, y, SMALL_TEXT_SIZE, DESC_COLOR);
}), SMALL_TEXT_SIZE * 13); }), SMALL_TEXT_SIZE * 13);
@@ -97,21 +97,24 @@ void MiscGui::listUI()
void MiscGui::refresh() { void MiscGui::refresh() {
BaseMenuGui::refresh(); BaseMenuGui::refresh();
if (this->context) { if (this->context && ++frameCounter >= 60)
sysclkIpcGetConfigValues(this->configList);
updateConfigToggle(this->cpuBoostToggle, SysClkConfigValue_AutoCPUBoost);
updateConfigToggle(this->syncModeToggle, SysClkConfigValue_SyncReverseNXMode);
}
if (++frameCounter >= 60)
{ {
frameCounter = 0; frameCounter = 0;
sysclkIpcGetConfigValues(this->configList);
updateConfigToggle(this->unsafeFreqToggle, SysClkConfigValue_AllowUnsafeFrequencies);
updateConfigToggle(this->cpuBoostToggle, SysClkConfigValue_AutoCPUBoost);
updateConfigToggle(this->syncModeToggle, SysClkConfigValue_SyncReverseNXMode);
updateConfigToggle(this->fastChargingToggle, SysClkConfigValue_DisableFastCharging);
// this->chargingLimitBar->setProgress(this->configList->values[SysClkConfigValue_ChargingLimitPercentage] - 20);
// snprintf(chargingLimitBarDesc, 50, "Battery Charging Limit: %u%%", u8(this->configList->values[SysClkConfigValue_ChargingLimitPercentage]));
// this->chargingLimitHeader->setText(chargingLimitBarDesc);
PsmUpdate(); PsmUpdate();
LblUpdate(); LblUpdate();
this->backlightToggle->setState(lblstatus); this->backlightToggle->setState(lblstatus);
I2cGetInfo(this->i2cInfo); I2cGetInfo(this->i2cInfo);
PrintInfo(this->infoOutput, sizeof(this->infoOutput)); PrintInfo(this->infoOutput, sizeof(this->infoOutput));
this->chargingToggle->setState(this->PsmIsCharging()); this->chargingToggle->setState(this->PsmIsCharging());
this->fastChargingToggle->setState(this->PsmIsFastCharging());
} }
} }

View File

@@ -13,6 +13,23 @@
#include "base_menu_gui.h" #include "base_menu_gui.h"
#include <inttypes.h> #include <inttypes.h>
class MultiStepTrackBar : public tsl::elm::StepTrackBar {
public:
MultiStepTrackBar(const char icon[3], size_t numSteps)
: tsl::elm::StepTrackBar(icon, numSteps) { }
virtual ~MultiStepTrackBar() {}
virtual inline u8 getProgress() override {
return this->m_value / (100.0F / (this->m_numSteps - 1));
}
virtual void setProgress(u8 value) override {
value = std::min(value, u8(this->m_numSteps - 1));
this->m_value = value * (100.0F / (this->m_numSteps - 1));
}
};
class MiscGui : public BaseMenuGui class MiscGui : public BaseMenuGui
{ {
public: public:
@@ -149,11 +166,6 @@ class MiscGui : public BaseMenuGui
return PsmIsChargerConnected() && ((this->chargeInfo->unk_x14 >> 8) & 1); return PsmIsChargerConnected() && ((this->chargeInfo->unk_x14 >> 8) & 1);
} }
bool PsmIsFastCharging()
{
return this->chargeInfo->ChargeCurrentLimit > 768;
}
bool PsmIsEnoughPowerSupplied() bool PsmIsEnoughPowerSupplied()
{ {
return this->isEnoughPowerSupplied; return this->isEnoughPowerSupplied;
@@ -289,21 +301,17 @@ class MiscGui : public BaseMenuGui
); );
} }
bool PsmChargingToggler(bool enable) void PsmChargingToggler(bool* enable)
{ {
if (!PsmIsChargerConnected()) if (!PsmIsChargerConnected())
return false; {
*enable = false;
return;
}
PsmUpdate(enable ? 2 : 3); PsmUpdate(*enable ? 2 : 3);
return PsmIsCharging() == enable; *enable = (PsmIsCharging() == *enable);
}
bool PsmFastChargingToggler(bool enable)
{
PsmUpdate(enable ? 10 : 11);
return PsmIsFastCharging() == enable;
} }
void LblUpdate(bool shouldSwitch = false) void LblUpdate(bool shouldSwitch = false)
@@ -325,8 +333,12 @@ class MiscGui : public BaseMenuGui
tsl::elm::ToggleListItem* addConfigToggle(SysClkConfigValue, std::string); tsl::elm::ToggleListItem* addConfigToggle(SysClkConfigValue, std::string);
void updateConfigToggle(tsl::elm::ToggleListItem*, SysClkConfigValue); void updateConfigToggle(tsl::elm::ToggleListItem*, SysClkConfigValue);
void updateLiftChargingLimitToggle();
tsl::elm::ToggleListItem *cpuBoostToggle, *syncModeToggle, *chargingToggle, *fastChargingToggle, *backlightToggle; tsl::elm::ToggleListItem *unsafeFreqToggle, *cpuBoostToggle, *syncModeToggle, *chargingToggle, *fastChargingToggle, *backlightToggle;
// tsl::elm::CategoryHeader *chargingLimitHeader;
// MultiStepTrackBar *chargingLimitBar;
// char chargingLimitBarDesc[50] = "";
SysClkConfigValueList* configList; SysClkConfigValueList* configList;
ChargeInfo* chargeInfo; ChargeInfo* chargeInfo;

View File

@@ -60,7 +60,7 @@ ClockManager::ClockManager()
this->oc = new SysClkOcExtra; this->oc = new SysClkOcExtra;
this->oc->systemCoreBoostCPU = false; this->oc->systemCoreBoostCPU = false;
this->oc->gotBoostCPUFreq = false; this->oc->gotBoostCPUFreq = false;
this->oc->handheldEmulatorMode = false; this->oc->allowUnsafeFreq = false;
this->oc->reverseNXMode = ReverseNX_NotFound; this->oc->reverseNXMode = ReverseNX_NotFound;
this->oc->maxMEMFreq = 0; this->oc->maxMEMFreq = 0;
this->oc->boostCPUFreq = 1785'000'000; this->oc->boostCPUFreq = 1785'000'000;
@@ -148,7 +148,7 @@ uint32_t ClockManager::GetHz(SysClkModule module)
if (hz) if (hz)
{ {
/* Considering realProfile frequency limit */ /* Considering realProfile frequency limit */
hz = Clocks::GetNearestHz(module, this->context->realProfile, hz); hz = Clocks::GetNearestHz(module, this->context->realProfile, hz, this->oc->allowUnsafeFreq);
if (module == SysClkModule_MEM && hz == MAX_MEM_CLOCK) if (module == SysClkModule_MEM && hz == MAX_MEM_CLOCK)
{ {
@@ -165,23 +165,6 @@ uint32_t ClockManager::GetHz(SysClkModule module)
} }
} }
/* Handle Handheld Emulator-Mode limit */
if (this->context->realProfile == SysClkProfile_Handheld)
{
switch (module)
{
case SysClkModule_CPU:
this->oc->handheldEmulatorMode = (hz > SYSCLK_CPU_HANDHELD_MAX_HZ);
break;
case SysClkModule_GPU:
if (this->oc->handheldEmulatorMode)
hz = std::min(hz, SYSCLK_GPU_HANDHELD_EMULATOR_HZ);
break;
default:
break;
}
}
/* Handle CPU Auto Boost, no user-defined hz required */ /* Handle CPU Auto Boost, no user-defined hz required */
if (module == SysClkModule_CPU) if (module == SysClkModule_CPU)
{ {
@@ -199,7 +182,11 @@ void ClockManager::Tick()
{ {
std::scoped_lock lock{this->contextMutex}; std::scoped_lock lock{this->contextMutex};
if ((this->RefreshContext() || this->config->Refresh()) && this->context->enabled) bool setClock = false;
setClock |= this->config->Refresh();
setClock |= this->RefreshContext();
setClock &= this->context->enabled;
if (setClock)
{ {
for (unsigned int module = 0; module < SysClkModule_EnumMax; module++) for (unsigned int module = 0; module < SysClkModule_EnumMax; module++)
{ {
@@ -344,26 +331,64 @@ bool ClockManager::CheckReverseNXRT()
{ {
bool shouldAdjustProfile = false; bool shouldAdjustProfile = false;
ReverseNXMode getMode = this->GetConfig()->GetReverseNXRTModeAndClear(); ReverseNXMode getMode = this->GetConfig()->GetReverseNXRTMode();
if (getMode) if (getMode)
{ {
this->oc->reverseNXMode = getMode; this->GetConfig()->SetReverseNXRTMode(ReverseNX_GotValue);
this->oc->reverseNXMode = (getMode == ReverseNX_RTResetToDefault) ?
ReverseNX_SystemDefault : getMode;
shouldAdjustProfile = true; shouldAdjustProfile = true;
} }
if (getMode == ReverseNX_RTResetToDefault)
{
this->oc->reverseNXMode = ReverseNX_SystemDefault;
}
return shouldAdjustProfile; return shouldAdjustProfile;
} }
void ClockManager::ChargingHandler()
{
smInitialize();
psmInitialize();
ChargeInfo* chargeInfoField = new ChargeInfo;
Service* session = psmGetServiceSession();
serviceDispatchOut(session, GetBatteryChargeInfoFields, *(chargeInfoField));
bool fastChargingEnabled = chargeInfoField->ChargeCurrentLimit > 768;
bool fastChargingConfig = !(this->GetConfig()->GetConfigValue(SysClkConfigValue_DisableFastCharging));
if (fastChargingEnabled != fastChargingConfig)
{
serviceDispatch(session, fastChargingConfig ? EnableFastBatteryCharging : DisableFastBatteryCharging);
}
// bool isChargerConnected = (chargeInfoField->ChargerType != ChargerType_None);
// if (isChargerConnected)
// {
// u32 chargeNow = 0;
// if (R_SUCCEEDED(psmGetBatteryChargePercentage(&chargeNow)))
// {
// bool isCharging = ((chargeInfoField->unk_x14 >> 8) & 1);
// u32 chargeLimit = this->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingLimitPercentage);
// if (isCharging && chargeLimit < chargeNow) {
// serviceDispatch(session, DisableBatteryCharging);
// } else if (!isCharging && chargeNow < 100 && chargeLimit > chargeNow) {
// serviceDispatch(session, EnableBatteryCharging);
// }
// }
// }
delete chargeInfoField;
psmExit();
smExit();
}
bool ClockManager::RefreshContext() bool ClockManager::RefreshContext()
{ {
ChargingHandler();
bool hasChanged = false; bool hasChanged = false;
bool enabled = this->GetConfig()->Enabled();
bool isReverseNXSyncEnabled = this->GetConfig()->GetConfigValue(SysClkConfigValue_SyncReverseNXMode); bool isReverseNXSyncEnabled = this->GetConfig()->GetConfigValue(SysClkConfigValue_SyncReverseNXMode);
this->oc->allowUnsafeFreq = this->GetConfig()->GetConfigValue(SysClkConfigValue_AllowUnsafeFrequencies);
bool enabled = this->GetConfig()->Enabled();
if(enabled != this->context->enabled) if(enabled != this->context->enabled)
{ {
this->context->enabled = enabled; this->context->enabled = enabled;

View File

@@ -32,6 +32,64 @@ class ClockManager
SysClkContext GetCurrentContext(); SysClkContext GetCurrentContext();
Config* GetConfig(); Config* GetConfig();
typedef enum {
PDCtrler_NewPDO = 1, //Received new Power Data Object
PDCtrler_NoPD = 2, //No Power Delivery source is detected
PDCtrler_AcceptedRDO = 3 //Received and accepted Request Data Object
} ChargeInfoPDCtrler; //BM92T series
typedef enum {
PowerRole_Sink = 1,
PowerRole_Source = 2
} ChargeInfoPowerRole;
typedef enum {
ChargerType_None = 0,
ChargerType_PD = 1,
ChargerType_TypeC_1500mA = 2,
ChargerType_TypeC_3000mA = 3,
ChargerType_DCP = 4,
ChargerType_CDP = 5,
ChargerType_SDP = 6,
ChargerType_Apple_500mA = 7,
ChargerType_Apple_1000mA = 8,
ChargerType_Apple_2000mA = 9
} ChargeInfoChargerType;
typedef enum {
Flags_NoHub = BIT(0), //If hub is disconnected
Flags_Rail = BIT(8), //At least one Joy-con is charging from rail
Flags_SPDSRC = BIT(12), //OTG
Flags_ACC = BIT(16) //Accessory
} ChargeInfoFlags;
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
ChargeInfoPDCtrler PDCtrlerState; //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)
ChargeInfoPowerRole PowerRole;
ChargeInfoChargerType ChargerType;
int32_t ChargerVoltageLimit; //Charger and external device voltage limit in mV
int32_t ChargerCurrentLimit; //Charger and external device current limit in mA
ChargeInfoFlags Flags; //Unknown flags
} ChargeInfo;
typedef enum {
EnableBatteryCharging = 2,
DisableBatteryCharging = 3,
EnableFastBatteryCharging = 10,
DisableFastBatteryCharging = 11,
GetBatteryChargeInfoFields = 17,
} IPsmServerCmd;
protected: protected:
ClockManager(); ClockManager();
virtual ~ClockManager(); virtual ~ClockManager();
@@ -58,4 +116,6 @@ class ClockManager
void CheckReverseNXTool(); void CheckReverseNXTool();
bool CheckReverseNXRT(); bool CheckReverseNXRT();
void ChargingHandler();
}; };

View File

@@ -282,10 +282,10 @@ std::uint32_t Clocks::GetCurrentHz(SysClkModule module)
return hz; return hz;
} }
std::uint32_t Clocks::GetNearestHz(SysClkModule module, SysClkProfile profile, std::uint32_t inHz) std::uint32_t Clocks::GetNearestHz(SysClkModule module, SysClkProfile profile, std::uint32_t inHz, bool allowUnsafe)
{ {
std::uint32_t hz = GetNearestHz(module, inHz); std::uint32_t hz = GetNearestHz(module, inHz);
std::uint32_t maxHz = GetMaxAllowedHz(module, profile); std::uint32_t maxHz = GetMaxAllowedHz(module, profile, allowUnsafe);
if(maxHz != 0) if(maxHz != 0)
{ {
@@ -295,11 +295,15 @@ std::uint32_t Clocks::GetNearestHz(SysClkModule module, SysClkProfile profile, s
return hz; return hz;
} }
std::uint32_t Clocks::GetMaxAllowedHz(SysClkModule module, SysClkProfile profile) std::uint32_t Clocks::GetMaxAllowedHz(SysClkModule module, SysClkProfile profile, bool allowUnsafe)
{ {
switch (module) { switch (module) {
case SysClkModule_CPU:
if (!allowUnsafe)
return SYSCLK_CPU_SAFE_MAX_HZ;
break;
case SysClkModule_GPU: case SysClkModule_GPU:
if (profile == SysClkProfile_Handheld) if (profile == SysClkProfile_Handheld || !allowUnsafe)
return SYSCLK_GPU_HANDHELD_MAX_HZ; return SYSCLK_GPU_HANDHELD_MAX_HZ;
if (profile == SysClkProfile_HandheldChargingUSB) if (profile == SysClkProfile_HandheldChargingUSB)
return SYSCLK_GPU_CHARGING_USB_MAX_HZ; return SYSCLK_GPU_CHARGING_USB_MAX_HZ;

View File

@@ -27,7 +27,7 @@ class Clocks
static const char* GetProfileName(SysClkProfile profile, bool pretty); static const char* GetProfileName(SysClkProfile profile, bool pretty);
static const char* GetModuleName(SysClkModule module, bool pretty); static const char* GetModuleName(SysClkModule module, bool pretty);
static const char* GetThermalSensorName(SysClkThermalSensor sensor, bool pretty); static const char* GetThermalSensorName(SysClkThermalSensor sensor, bool pretty);
static std::uint32_t GetNearestHz(SysClkModule module, SysClkProfile profile, std::uint32_t inHz); static std::uint32_t GetNearestHz(SysClkModule module, SysClkProfile profile, std::uint32_t inHz, bool allowUnsafe);
static std::uint32_t GetTemperatureMilli(SysClkThermalSensor sensor); static std::uint32_t GetTemperatureMilli(SysClkThermalSensor sensor);
protected: protected:
@@ -36,5 +36,5 @@ class Clocks
static PcvModuleId GetPcvModuleId(SysClkModule sysclkModule); static PcvModuleId GetPcvModuleId(SysClkModule sysclkModule);
static std::uint32_t GetNearestHz(SysClkModule module, std::uint32_t inHz); static std::uint32_t GetNearestHz(SysClkModule module, std::uint32_t inHz);
static void GetList(SysClkModule module, std::uint32_t **outClocks); static void GetList(SysClkModule module, std::uint32_t **outClocks);
static std::uint32_t GetMaxAllowedHz(SysClkModule module, SysClkProfile profile); static std::uint32_t GetMaxAllowedHz(SysClkModule module, SysClkProfile profile, bool allowUnsafe);
}; };

View File

@@ -483,10 +483,9 @@ bool Config::SetConfigValues(SysClkConfigValueList* configValues, bool immediate
return true; return true;
} }
ReverseNXMode Config::GetReverseNXRTModeAndClear() { ReverseNXMode Config::GetReverseNXRTMode() {
std::scoped_lock lock{this->reverseNXRTMutex}; std::scoped_lock lock{this->reverseNXRTMutex};
ReverseNXMode mode = this->reverseNXRTMode; ReverseNXMode mode = this->reverseNXRTMode;
this->reverseNXRTMode = ReverseNX_GotValue;
return mode; return mode;
} }

View File

@@ -47,7 +47,7 @@ class Config
const char* GetConfigValueName(SysClkConfigValue val, bool pretty); const char* GetConfigValueName(SysClkConfigValue val, bool pretty);
void GetConfigValues(SysClkConfigValueList* out_configValues); void GetConfigValues(SysClkConfigValueList* out_configValues);
bool SetConfigValues(SysClkConfigValueList* configValues, bool immediate); bool SetConfigValues(SysClkConfigValueList* configValues, bool immediate);
ReverseNXMode GetReverseNXRTModeAndClear(); ReverseNXMode GetReverseNXRTMode();
void SetReverseNXRTMode(ReverseNXMode); void SetReverseNXRTMode(ReverseNXMode);
protected: protected:
void Load(); void Load();