- sys-clk-OC: Charging current limit
This commit is contained in:
@@ -28,7 +28,7 @@ Overclocking suite for Horizon OS (HOS) running on Atmosphere CFW.
|
|||||||
|
|
||||||
- Modded sys-clk and ReverseNX-RT
|
- Modded sys-clk and ReverseNX-RT
|
||||||
- CPU & GPU frequency governor (Experimental)
|
- CPU & GPU frequency governor (Experimental)
|
||||||
- Fast-charging (2A) toggle, set charge limit (20% - 100%)
|
- Set charging current (100 mA - 2000 mA) and charging limit (20% - 100%)
|
||||||
- Global Profile
|
- Global Profile
|
||||||
- Sync ReverseNX Mode
|
- Sync ReverseNX Mode
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ Overclocking suite for Horizon OS (HOS) running on Atmosphere CFW.
|
|||||||
- Modded sys-clk and ReverseNX-RT
|
- Modded sys-clk and ReverseNX-RT
|
||||||
- Auto CPU Boost
|
- Auto CPU Boost
|
||||||
- CPU & GPU frequency governor (Experimental)
|
- CPU & GPU frequency governor (Experimental)
|
||||||
- Fast-charging (2A) toggle, set charge limit (20% - 100%)
|
- Set charging current (100 mA - 2000 mA) and charging limit (20% - 100%)
|
||||||
- Global Profile
|
- Global Profile
|
||||||
- Sync ReverseNX Mode
|
- Sync ReverseNX Mode
|
||||||
|
|
||||||
@@ -86,9 +86,9 @@ Overclocking suite for Horizon OS (HOS) running on Atmosphere CFW.
|
|||||||
|
|
||||||
| Defaults | Mariko | Erista |
|
| Defaults | Mariko | Erista |
|
||||||
| ---------- | ------------- | ------------ |
|
| ---------- | ------------- | ------------ |
|
||||||
| CPU OC | 2397 MHz Max | Disabled |
|
| CPU OC | 2397 MHz Max | 2091 MHz Max |
|
||||||
| CPU Boost | 1785 MHz | N/A |
|
| CPU Boost | 1785 MHz | N/A |
|
||||||
| CPU Volt | 1220 mV Max | Disabled |
|
| CPU Volt | 1235 mV Max | 1257 mV Max |
|
||||||
| GPU OC | 1305 MHz Max | N/A |
|
| GPU OC | 1305 MHz Max | N/A |
|
||||||
| RAM OC | 1996 MHz Max | 1862 MHz Max |
|
| RAM OC | 1996 MHz Max | 1862 MHz Max |
|
||||||
| RAM Volt | N/A | Disabled |
|
| RAM Volt | N/A | Disabled |
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ The `[values]` section allows you to alter timings in sys-clk, you should not ne
|
|||||||
|**allow_unsafe_freq** | (Mariko Only) Allow unsafe frequencies (CPU > 1963.5 MHz, GPU > 921.6 MHz) | OFF |
|
|**allow_unsafe_freq** | (Mariko Only) Allow unsafe frequencies (CPU > 1963.5 MHz, GPU > 921.6 MHz) | OFF |
|
||||||
|**auto_cpu_boost** | (Mariko Only) Auto-boost CPU when system Core #3 utilization ≥ 95% | ON |
|
|**auto_cpu_boost** | (Mariko Only) 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 |
|
|**charging_current** | Charging current limit (100 mA - 2000 mA) | 2000 mA |
|
||||||
|**charging_limit_perc** | Charging limit (20% - 100%) | 100%(OFF) |
|
|**charging_limit_perc** | Charging limit (20% - 100%) | 100%(OFF) |
|
||||||
|**governor_experimental** | CPU & GPU frequency governor (Experimental) | OFF |
|
|**governor_experimental** | CPU & GPU frequency governor (Experimental) | 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 |
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ extern "C" {
|
|||||||
#include "sysclk/apm.h"
|
#include "sysclk/apm.h"
|
||||||
#include "sysclk/config.h"
|
#include "sysclk/config.h"
|
||||||
#include "sysclk/errors.h"
|
#include "sysclk/errors.h"
|
||||||
|
#include "sysclk/i2c.h"
|
||||||
#include "sysclk/psm_ext.h"
|
#include "sysclk/psm_ext.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ typedef enum {
|
|||||||
SysClkConfigValue_AutoCPUBoost,
|
SysClkConfigValue_AutoCPUBoost,
|
||||||
SysClkConfigValue_SyncReverseNXMode,
|
SysClkConfigValue_SyncReverseNXMode,
|
||||||
SysClkConfigValue_AllowUnsafeFrequencies,
|
SysClkConfigValue_AllowUnsafeFrequencies,
|
||||||
SysClkConfigValue_DisableFastCharging,
|
SysClkConfigValue_ChargingCurrentLimit,
|
||||||
SysClkConfigValue_ChargingLimitPercentage,
|
SysClkConfigValue_ChargingLimitPercentage,
|
||||||
SysClkConfigValue_GovernorExperimental,
|
SysClkConfigValue_GovernorExperimental,
|
||||||
SysClkConfigValue_EnumMax,
|
SysClkConfigValue_EnumMax,
|
||||||
@@ -46,8 +46,8 @@ static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pr
|
|||||||
return pretty ? "Sync ReverseNX Mode Sync" : "sync_reversenx_mode";
|
return pretty ? "Sync ReverseNX Mode Sync" : "sync_reversenx_mode";
|
||||||
case SysClkConfigValue_AllowUnsafeFrequencies:
|
case SysClkConfigValue_AllowUnsafeFrequencies:
|
||||||
return pretty ? "Allow Unsafe Frequencies" : "allow_unsafe_freq";
|
return pretty ? "Allow Unsafe Frequencies" : "allow_unsafe_freq";
|
||||||
case SysClkConfigValue_DisableFastCharging:
|
case SysClkConfigValue_ChargingCurrentLimit:
|
||||||
return pretty ? "Disable Fast Charging" : "disable_fast_charging";
|
return pretty ? "Charging Current Limit (mA)" : "charging_current";
|
||||||
case SysClkConfigValue_ChargingLimitPercentage:
|
case SysClkConfigValue_ChargingLimitPercentage:
|
||||||
return pretty ? "Charging Limit (%%)" : "charging_limit_perc";
|
return pretty ? "Charging Limit (%%)" : "charging_limit_perc";
|
||||||
case SysClkConfigValue_GovernorExperimental:
|
case SysClkConfigValue_GovernorExperimental:
|
||||||
@@ -66,12 +66,13 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
|
|||||||
case SysClkConfigValue_TempLogIntervalMs:
|
case SysClkConfigValue_TempLogIntervalMs:
|
||||||
case SysClkConfigValue_CsvWriteIntervalMs:
|
case SysClkConfigValue_CsvWriteIntervalMs:
|
||||||
case SysClkConfigValue_AllowUnsafeFrequencies:
|
case SysClkConfigValue_AllowUnsafeFrequencies:
|
||||||
case SysClkConfigValue_DisableFastCharging:
|
|
||||||
case SysClkConfigValue_GovernorExperimental:
|
case SysClkConfigValue_GovernorExperimental:
|
||||||
return 0ULL;
|
return 0ULL;
|
||||||
case SysClkConfigValue_AutoCPUBoost:
|
case SysClkConfigValue_AutoCPUBoost:
|
||||||
case SysClkConfigValue_SyncReverseNXMode:
|
case SysClkConfigValue_SyncReverseNXMode:
|
||||||
return 1ULL;
|
return 1ULL;
|
||||||
|
case SysClkConfigValue_ChargingCurrentLimit:
|
||||||
|
return 2000ULL;
|
||||||
case SysClkConfigValue_ChargingLimitPercentage:
|
case SysClkConfigValue_ChargingLimitPercentage:
|
||||||
return 100ULL;
|
return 100ULL;
|
||||||
default:
|
default:
|
||||||
@@ -91,9 +92,10 @@ static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t in
|
|||||||
case SysClkConfigValue_AutoCPUBoost:
|
case SysClkConfigValue_AutoCPUBoost:
|
||||||
case SysClkConfigValue_SyncReverseNXMode:
|
case SysClkConfigValue_SyncReverseNXMode:
|
||||||
case SysClkConfigValue_AllowUnsafeFrequencies:
|
case SysClkConfigValue_AllowUnsafeFrequencies:
|
||||||
case SysClkConfigValue_DisableFastCharging:
|
|
||||||
case SysClkConfigValue_GovernorExperimental:
|
case SysClkConfigValue_GovernorExperimental:
|
||||||
return (input & 0x1) == input;
|
return (input & 0x1) == input;
|
||||||
|
case SysClkConfigValue_ChargingCurrentLimit:
|
||||||
|
return (input >= 100 && input <= 2000 && input % 100 == 0);
|
||||||
case SysClkConfigValue_ChargingLimitPercentage:
|
case SysClkConfigValue_ChargingLimitPercentage:
|
||||||
return (input <= 100 && input >= 20);
|
return (input <= 100 && input >= 20);
|
||||||
default:
|
default:
|
||||||
|
|||||||
36
Source/sys-clk-OC/common/include/sysclk/i2c.h
Normal file
36
Source/sys-clk-OC/common/include/sysclk/i2c.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
|
// To use i2c service, sm and i2c should be intialized via smInitialize() and i2cInitialize().
|
||||||
|
|
||||||
|
Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val);
|
||||||
|
|
||||||
|
Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out);
|
||||||
|
Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out);
|
||||||
|
|
||||||
|
// Max17050 fuel gauge
|
||||||
|
float I2c_Max17050_GetBatteryCurrent();
|
||||||
|
|
||||||
|
const u8 MAX17050_CURRENT_REG = 0x0A;
|
||||||
|
|
||||||
|
// Max77812 Mariko-specific buck converter
|
||||||
|
typedef enum I2c_Max77812_Volt_Type {
|
||||||
|
I2c_Max77812_CPUVOLT_REG = 0x26,
|
||||||
|
I2c_Max77812_GPUVOLT_REG = 0x23,
|
||||||
|
I2c_Max77812_MEMVOLT_REG = 0x25,
|
||||||
|
} I2c_Max77812_Volt_Type;
|
||||||
|
|
||||||
|
u32 I2c_Max77812_GetMVOUT(I2c_Max77812_Volt_Type type);
|
||||||
|
|
||||||
|
// Bq24193 Battery management
|
||||||
|
u32 I2c_Bq24193_Convert_Raw_mA(u8 raw);
|
||||||
|
u8 I2c_Bq24193_Convert_mA_Raw(u32 ma);
|
||||||
|
|
||||||
|
Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma);
|
||||||
|
Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma);
|
||||||
|
|
||||||
|
const u32 MA_RANGE_MIN = 512;
|
||||||
|
const u32 MA_RANGE_MAX = 4544;
|
||||||
|
|
||||||
|
const u8 BQ24193_CHARGE_CURRENT_CONTROL_REG = 0x2;
|
||||||
@@ -66,12 +66,10 @@ typedef enum {
|
|||||||
|
|
||||||
bool PsmIsChargerConnected(const PsmChargeInfo* info);
|
bool PsmIsChargerConnected(const PsmChargeInfo* info);
|
||||||
bool PsmIsCharging(const PsmChargeInfo* info);
|
bool PsmIsCharging(const PsmChargeInfo* info);
|
||||||
bool PsmIsFastChargingEnabled(const PsmChargeInfo* info);
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PsmBatteryState_Discharging,
|
PsmBatteryState_Discharging,
|
||||||
PsmBatteryState_ChargingPaused,
|
PsmBatteryState_ChargingPaused,
|
||||||
PsmBatteryState_SlowCharging,
|
|
||||||
PsmBatteryState_FastCharging
|
PsmBatteryState_FastCharging
|
||||||
} PsmBatteryState;
|
} PsmBatteryState;
|
||||||
|
|
||||||
|
|||||||
150
Source/sys-clk-OC/common/src/i2c.c
Normal file
150
Source/sys-clk-OC/common/src/i2c.c
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
#include <sysclk/i2c.h>
|
||||||
|
|
||||||
|
Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val) {
|
||||||
|
// ams::fatal::srv::StopSoundTask::StopSound()
|
||||||
|
// I2C Bus Communication Reference: https://www.ti.com/lit/an/slva704/slva704.pdf
|
||||||
|
struct {
|
||||||
|
u8 reg;
|
||||||
|
u8 val;
|
||||||
|
} __attribute__((packed)) cmd;
|
||||||
|
|
||||||
|
I2cSession _session;
|
||||||
|
Result res = i2cOpenSession(&_session, dev);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
cmd.reg = reg;
|
||||||
|
cmd.val = val;
|
||||||
|
res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||||
|
i2csessionClose(&_session);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out) {
|
||||||
|
struct { u8 reg; } __attribute__((packed)) cmd;
|
||||||
|
struct { u8 val; } __attribute__((packed)) rec;
|
||||||
|
|
||||||
|
I2cSession _session;
|
||||||
|
Result res = i2cOpenSession(&_session, dev);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
cmd.reg = reg;
|
||||||
|
res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||||
|
if (res) {
|
||||||
|
i2csessionClose(&_session);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = i2csessionReceiveAuto(&_session, &rec, sizeof(rec), I2cTransactionOption_All);
|
||||||
|
i2csessionClose(&_session);
|
||||||
|
if (res) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = rec.val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out) {
|
||||||
|
struct { u8 reg; } __attribute__((packed)) cmd;
|
||||||
|
struct { u16 val; } __attribute__((packed)) rec;
|
||||||
|
|
||||||
|
I2cSession _session;
|
||||||
|
Result res = i2cOpenSession(&_session, dev);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
cmd.reg = reg;
|
||||||
|
res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
||||||
|
if (res) {
|
||||||
|
i2csessionClose(&_session);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = i2csessionReceiveAuto(&_session, &rec, sizeof(rec), I2cTransactionOption_All);
|
||||||
|
i2csessionClose(&_session);
|
||||||
|
if (res) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = rec.val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float I2c_Max17050_GetBatteryCurrent() {
|
||||||
|
u16 val;
|
||||||
|
Result res = I2cRead_OutU16(I2cDevice_Max17050, MAX17050_CURRENT_REG, &val);
|
||||||
|
if (res)
|
||||||
|
return 0.f;
|
||||||
|
|
||||||
|
const float SenseResistor = 5.; // in uOhm
|
||||||
|
const float CGain = 1.99993;
|
||||||
|
return (s16)val * (1.5625 / (SenseResistor * CGain));
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 I2c_Max77812_GetMVOUT(I2c_Max77812_Volt_Type type) {
|
||||||
|
u8 reg = (u8)type;
|
||||||
|
|
||||||
|
const u32 MIN_MV = 250;
|
||||||
|
const u32 MV_STEP = 5;
|
||||||
|
const u8 RESET_VAL = 0x78;
|
||||||
|
|
||||||
|
u8 val = RESET_VAL;
|
||||||
|
// Retry 3 times if received RESET_VAL
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (I2cRead_OutU8(I2cDevice_Max77812_2, reg, &val))
|
||||||
|
return 0u;
|
||||||
|
if (val != RESET_VAL)
|
||||||
|
break;
|
||||||
|
svcSleepThread(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return val * MV_STEP + MIN_MV;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 I2c_Bq24193_Convert_mA_Raw(u32 ma) {
|
||||||
|
// Adjustment is required
|
||||||
|
u8 raw = 0;
|
||||||
|
|
||||||
|
if (ma > MA_RANGE_MAX) // capping
|
||||||
|
ma = MA_RANGE_MAX;
|
||||||
|
|
||||||
|
bool pct20 = ma <= (MA_RANGE_MIN - 64);
|
||||||
|
if (pct20) {
|
||||||
|
ma = ma * 5;
|
||||||
|
raw |= 0x1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ma -= ma % 100; // round to 100
|
||||||
|
ma -= (MA_RANGE_MIN - 64); // ceiling
|
||||||
|
raw |= (ma >> 6) << 2;
|
||||||
|
|
||||||
|
return raw;
|
||||||
|
};
|
||||||
|
|
||||||
|
u32 I2c_Bq24193_Convert_Raw_mA(u8 raw) {
|
||||||
|
// No adjustment is allowed
|
||||||
|
u32 ma = (((raw >> 2)) << 6) + MA_RANGE_MIN;
|
||||||
|
|
||||||
|
bool pct20 = raw & 1;
|
||||||
|
if (pct20)
|
||||||
|
ma = ma * 20 / 100;
|
||||||
|
|
||||||
|
return ma;
|
||||||
|
};
|
||||||
|
|
||||||
|
Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma) {
|
||||||
|
u8 raw;
|
||||||
|
Result res = I2cRead_OutU8(I2cDevice_Bq24193, BQ24193_CHARGE_CURRENT_CONTROL_REG, &raw);
|
||||||
|
if (res)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
*ma = I2c_Bq24193_Convert_Raw_mA(raw);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma) {
|
||||||
|
u8 raw = I2c_Bq24193_Convert_mA_Raw(ma);
|
||||||
|
return I2cSet_U8(I2cDevice_Bq24193, BQ24193_CHARGE_CURRENT_CONTROL_REG, raw);
|
||||||
|
}
|
||||||
@@ -32,24 +32,19 @@ bool PsmIsCharging(const PsmChargeInfo* info) {
|
|||||||
return PsmIsChargerConnected(info) && ((info->unk_x14 >> 8) & 1);
|
return PsmIsChargerConnected(info) && ((info->unk_x14 >> 8) & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PsmIsFastChargingEnabled(const PsmChargeInfo* info) {
|
|
||||||
return info->ChargeCurrentLimit > 768;
|
|
||||||
}
|
|
||||||
|
|
||||||
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) {
|
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) {
|
||||||
if (!PsmIsChargerConnected(info))
|
if (!PsmIsChargerConnected(info))
|
||||||
return PsmBatteryState_Discharging;
|
return PsmBatteryState_Discharging;
|
||||||
if (!PsmIsCharging(info))
|
if (!PsmIsCharging(info))
|
||||||
return PsmBatteryState_ChargingPaused;
|
return PsmBatteryState_ChargingPaused;
|
||||||
return PsmIsFastChargingEnabled(info) ? PsmBatteryState_FastCharging : PsmBatteryState_SlowCharging;
|
return PsmBatteryState_FastCharging;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info) {
|
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info) {
|
||||||
switch (PsmGetBatteryState(info)) {
|
switch (PsmGetBatteryState(info)) {
|
||||||
case PsmBatteryState_Discharging: return "\u25c0"; // ◀
|
case PsmBatteryState_Discharging: return "\u25c0"; // ◀
|
||||||
case PsmBatteryState_ChargingPaused:return "| |";
|
case PsmBatteryState_ChargingPaused:return "| |";
|
||||||
case PsmBatteryState_SlowCharging: return "\u25b6"; // ▶
|
case PsmBatteryState_FastCharging: return "\u25b6"; // ▶
|
||||||
case PsmBatteryState_FastCharging: return "\u25b6\u25b6"; // ▶▶
|
|
||||||
default: return "?";
|
default: return "?";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
MiscGui::MiscGui()
|
MiscGui::MiscGui()
|
||||||
{
|
{
|
||||||
|
smInitialize();
|
||||||
|
|
||||||
this->configList = new SysClkConfigValueList {};
|
this->configList = new SysClkConfigValueList {};
|
||||||
this->chargeInfo = new PsmChargeInfo {};
|
this->chargeInfo = new PsmChargeInfo {};
|
||||||
this->i2cInfo = new I2cInfo {};
|
this->i2cInfo = new I2cInfo {};
|
||||||
@@ -27,6 +29,8 @@ MiscGui::~MiscGui()
|
|||||||
delete this->chargeInfo;
|
delete this->chargeInfo;
|
||||||
delete this->i2cInfo;
|
delete this->i2cInfo;
|
||||||
this->configToggles.clear();
|
this->configToggles.clear();
|
||||||
|
|
||||||
|
smExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MiscGui::addConfigToggle(SysClkConfigValue configVal) {
|
void MiscGui::addConfigToggle(SysClkConfigValue configVal) {
|
||||||
@@ -62,9 +66,35 @@ void MiscGui::listUI()
|
|||||||
|
|
||||||
addConfigToggle(SysClkConfigValue_AllowUnsafeFrequencies);
|
addConfigToggle(SysClkConfigValue_AllowUnsafeFrequencies);
|
||||||
addConfigToggle(SysClkConfigValue_SyncReverseNXMode);
|
addConfigToggle(SysClkConfigValue_SyncReverseNXMode);
|
||||||
addConfigToggle(SysClkConfigValue_DisableFastCharging);
|
|
||||||
addConfigToggle(SysClkConfigValue_GovernorExperimental);
|
addConfigToggle(SysClkConfigValue_GovernorExperimental);
|
||||||
|
|
||||||
|
this->chargingCurrentHeader = new tsl::elm::CategoryHeader("");
|
||||||
|
this->listElement->addItem(this->chargingCurrentHeader);
|
||||||
|
this->chargingCurrentBar = new StepTrackBarIcon("", 2000 / 100 + 1);
|
||||||
|
this->chargingCurrentBar->setProgress(this->configList->values[SysClkConfigValue_ChargingCurrentLimit]);
|
||||||
|
this->chargingCurrentBar->setValueChangedListener([this](u8 val) {
|
||||||
|
if (val < 1) {
|
||||||
|
val = 1;
|
||||||
|
this->chargingCurrentBar->setProgress(val);
|
||||||
|
}
|
||||||
|
if (val > 20) {
|
||||||
|
val = 20;
|
||||||
|
this->chargingCurrentBar->setProgress(val);
|
||||||
|
}
|
||||||
|
uint32_t current_ma = val * 100;
|
||||||
|
this->configList->values[SysClkConfigValue_ChargingCurrentLimit] = current_ma;
|
||||||
|
|
||||||
|
snprintf(chargingCurrentBarDesc, sizeof(chargingCurrentBarDesc), "Battery Charging Current: %lu mA", this->configList->values[SysClkConfigValue_ChargingCurrentLimit]);
|
||||||
|
this->chargingCurrentHeader->setText(chargingCurrentBarDesc);
|
||||||
|
|
||||||
|
Result rc = sysclkIpcSetConfigValues(this->configList);
|
||||||
|
if (R_FAILED(rc))
|
||||||
|
FatalGui::openWithResultCode("sysclkIpcSetConfigValues", rc);
|
||||||
|
|
||||||
|
this->lastContextUpdate = armGetSystemTick();
|
||||||
|
});
|
||||||
|
this->listElement->addItem(this->chargingCurrentBar);
|
||||||
|
|
||||||
this->chargingLimitHeader = new tsl::elm::CategoryHeader("");
|
this->chargingLimitHeader = new tsl::elm::CategoryHeader("");
|
||||||
this->listElement->addItem(this->chargingLimitHeader);
|
this->listElement->addItem(this->chargingLimitHeader);
|
||||||
this->chargingLimitBar = new StepTrackBarIcon("", 100 + 1);
|
this->chargingLimitBar = new StepTrackBarIcon("", 100 + 1);
|
||||||
@@ -76,7 +106,7 @@ void MiscGui::listUI()
|
|||||||
}
|
}
|
||||||
this->configList->values[SysClkConfigValue_ChargingLimitPercentage] = val;
|
this->configList->values[SysClkConfigValue_ChargingLimitPercentage] = val;
|
||||||
|
|
||||||
snprintf(chargingLimitBarDesc, 30, "Battery Charging Limit: %lu%%", this->configList->values[SysClkConfigValue_ChargingLimitPercentage]);
|
snprintf(chargingLimitBarDesc, sizeof(chargingLimitBarDesc), "Battery Charging Limit: %lu%% (%u%%)", this->configList->values[SysClkConfigValue_ChargingLimitPercentage], this->batteryChargePerc);
|
||||||
this->chargingLimitHeader->setText(chargingLimitBarDesc);
|
this->chargingLimitHeader->setText(chargingLimitBarDesc);
|
||||||
this->chargingLimitBar->setIcon(PsmGetBatteryStateIcon(this->chargeInfo));
|
this->chargingLimitBar->setIcon(PsmGetBatteryStateIcon(this->chargeInfo));
|
||||||
|
|
||||||
@@ -116,16 +146,20 @@ void MiscGui::refresh() {
|
|||||||
sysclkIpcGetConfigValues(this->configList);
|
sysclkIpcGetConfigValues(this->configList);
|
||||||
updateConfigToggles();
|
updateConfigToggles();
|
||||||
|
|
||||||
this->chargingLimitBar->setProgress(this->configList->values[SysClkConfigValue_ChargingLimitPercentage]);
|
|
||||||
snprintf(chargingLimitBarDesc, 30, "Battery Charging Limit: %lu%%", this->configList->values[SysClkConfigValue_ChargingLimitPercentage]);
|
|
||||||
this->chargingLimitHeader->setText(chargingLimitBarDesc);
|
|
||||||
|
|
||||||
PsmUpdate();
|
PsmUpdate();
|
||||||
this->chargingLimitBar->setIcon(PsmGetBatteryStateIcon(this->chargeInfo));
|
this->chargingLimitBar->setIcon(PsmGetBatteryStateIcon(this->chargeInfo));
|
||||||
|
|
||||||
LblUpdate();
|
LblUpdate();
|
||||||
this->backlightToggle->setState(lblstatus);
|
this->backlightToggle->setState(lblstatus);
|
||||||
|
|
||||||
|
this->chargingCurrentBar->setProgress(this->configList->values[SysClkConfigValue_ChargingCurrentLimit] / 100);
|
||||||
|
snprintf(chargingCurrentBarDesc, sizeof(chargingCurrentBarDesc), "Battery Charging Current: %lu mA", this->configList->values[SysClkConfigValue_ChargingCurrentLimit]);
|
||||||
|
this->chargingCurrentHeader->setText(chargingCurrentBarDesc);
|
||||||
|
|
||||||
|
this->chargingLimitBar->setProgress(this->configList->values[SysClkConfigValue_ChargingLimitPercentage]);
|
||||||
|
snprintf(chargingLimitBarDesc, sizeof(chargingLimitBarDesc), "Battery Charging Limit: %lu%% (%u%%)", this->configList->values[SysClkConfigValue_ChargingLimitPercentage], this->batteryChargePerc);
|
||||||
|
this->chargingLimitHeader->setText(chargingLimitBarDesc);
|
||||||
|
|
||||||
if (this->isMariko) {
|
if (this->isMariko) {
|
||||||
I2cGetInfo(this->i2cInfo);
|
I2cGetInfo(this->i2cInfo);
|
||||||
UpdateInfo(this->infoVals, sizeof(this->infoVals));
|
UpdateInfo(this->infoVals, sizeof(this->infoVals));
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ class MiscGui : public BaseMenuGui
|
|||||||
|
|
||||||
void PsmUpdate(uint32_t dispatchId = 0)
|
void PsmUpdate(uint32_t dispatchId = 0)
|
||||||
{
|
{
|
||||||
smInitialize();
|
|
||||||
psmInitialize();
|
psmInitialize();
|
||||||
|
|
||||||
if (dispatchId)
|
if (dispatchId)
|
||||||
@@ -49,113 +48,24 @@ class MiscGui : public BaseMenuGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
serviceDispatchOut(psmGetServiceSession(), 17, *(this->chargeInfo));
|
serviceDispatchOut(psmGetServiceSession(), 17, *(this->chargeInfo));
|
||||||
|
psmGetBatteryChargePercentage(&(this->batteryChargePerc));
|
||||||
|
|
||||||
psmExit();
|
psmExit();
|
||||||
smExit();
|
|
||||||
}
|
|
||||||
|
|
||||||
Result I2cRead_OutU16(u8 reg, I2cDevice dev, u16 *out)
|
|
||||||
{
|
|
||||||
// ams::fatal::srv::StopSoundTask::StopSound()
|
|
||||||
// I2C Bus Communication Reference: https://www.ti.com/lit/an/slva704/slva704.pdf
|
|
||||||
struct { u8 reg; } __attribute__((packed)) cmd;
|
|
||||||
struct { u16 val; } __attribute__((packed)) rec;
|
|
||||||
|
|
||||||
I2cSession _session;
|
|
||||||
|
|
||||||
Result res = i2cOpenSession(&_session, dev);
|
|
||||||
if (res)
|
|
||||||
return res;
|
|
||||||
|
|
||||||
cmd.reg = reg;
|
|
||||||
res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
|
||||||
if (res) {
|
|
||||||
i2csessionClose(&_session);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = i2csessionReceiveAuto(&_session, &rec, sizeof(rec), I2cTransactionOption_All);
|
|
||||||
if (res) {
|
|
||||||
i2csessionClose(&_session);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out = rec.val;
|
|
||||||
i2csessionClose(&_session);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result I2cRead_OutU8(u8 reg, I2cDevice dev, u8 *out)
|
|
||||||
{
|
|
||||||
struct { u8 reg; } __attribute__((packed)) cmd;
|
|
||||||
struct { u8 val; } __attribute__((packed)) rec;
|
|
||||||
|
|
||||||
I2cSession _session;
|
|
||||||
|
|
||||||
Result res = i2cOpenSession(&_session, dev);
|
|
||||||
if (res)
|
|
||||||
return res;
|
|
||||||
|
|
||||||
cmd.reg = reg;
|
|
||||||
res = i2csessionSendAuto(&_session, &cmd, sizeof(cmd), I2cTransactionOption_All);
|
|
||||||
if (res) {
|
|
||||||
i2csessionClose(&_session);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = i2csessionReceiveAuto(&_session, &rec, sizeof(rec), I2cTransactionOption_All);
|
|
||||||
if (res) {
|
|
||||||
i2csessionClose(&_session);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out = rec.val;
|
|
||||||
i2csessionClose(&_session);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2cGetInfo(I2cInfo* i2cInfo)
|
void I2cGetInfo(I2cInfo* i2cInfo)
|
||||||
{
|
{
|
||||||
smInitialize();
|
|
||||||
i2cInitialize();
|
i2cInitialize();
|
||||||
|
|
||||||
// Max17050 fuel gauge regs. Sense resistor and CGain are from Hekate, too lazy to query configuration from reg
|
i2cInfo->batCurrent = I2c_Max17050_GetBatteryCurrent();
|
||||||
constexpr float SenseResistor = 5.; // in uOhm
|
|
||||||
constexpr float CGain = 1.99993;
|
|
||||||
constexpr u8 Max17050Reg_Current = 0x0A;
|
|
||||||
// constexpr u8 Max17050Reg_AvgCurrent = 0x0B;
|
|
||||||
// constexpr u8 Max17050Reg_Cycle = 0x17;
|
|
||||||
u16 tmp = 0;
|
|
||||||
if (R_SUCCEEDED(I2cRead_OutU16(Max17050Reg_Current, I2cDevice_Max17050, &tmp)))
|
|
||||||
i2cInfo->batCurrent = (s16)tmp * (1.5625 / (SenseResistor * CGain));
|
|
||||||
|
|
||||||
auto I2cRead_Max77812_M_VOUT = [this](u8 reg) {
|
i2cInfo->cpuVolt = I2c_Max77812_GetMVOUT(I2c_Max77812_CPUVOLT_REG);
|
||||||
constexpr u32 MIN_MV = 250;
|
i2cInfo->gpuVolt = I2c_Max77812_GetMVOUT(I2c_Max77812_GPUVOLT_REG);
|
||||||
constexpr u32 MV_STEP = 5;
|
i2cInfo->dramVolt = I2c_Max77812_GetMVOUT(I2c_Max77812_MEMVOLT_REG);
|
||||||
constexpr u8 RESET_VAL = 0x78;
|
|
||||||
|
|
||||||
u8 tmp = RESET_VAL;
|
I2c_Bq24193_GetFastChargeCurrentLimit(reinterpret_cast<u32 *>(&(chargeInfo->ChargeCurrentLimit)));
|
||||||
// Retry 3 times if received RESET_VAL
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
if (R_FAILED(I2cRead_OutU8(reg, I2cDevice_Max77812_2, &tmp)))
|
|
||||||
return 0u;
|
|
||||||
if (tmp != RESET_VAL)
|
|
||||||
break;
|
|
||||||
usleep(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tmp * MV_STEP + MIN_MV;
|
|
||||||
};
|
|
||||||
|
|
||||||
constexpr u8 Max77812Reg_CPUVolt = 0x26;
|
|
||||||
constexpr u8 Max77812Reg_GPUVolt = 0x23;
|
|
||||||
constexpr u8 Max77812Reg_DRAMVolt = 0x25;
|
|
||||||
i2cInfo->cpuVolt = I2cRead_Max77812_M_VOUT(Max77812Reg_CPUVolt);
|
|
||||||
i2cInfo->gpuVolt = I2cRead_Max77812_M_VOUT(Max77812Reg_GPUVolt);
|
|
||||||
i2cInfo->dramVolt = I2cRead_Max77812_M_VOUT(Max77812Reg_DRAMVolt);
|
|
||||||
|
|
||||||
i2cExit();
|
i2cExit();
|
||||||
smExit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateInfo(char* out, size_t outsize)
|
void UpdateInfo(char* out, size_t outsize)
|
||||||
@@ -193,8 +103,7 @@ class MiscGui : public BaseMenuGui
|
|||||||
"%dmV\n"
|
"%dmV\n"
|
||||||
,
|
,
|
||||||
PsmInfoChargerTypeToStr(chargeInfo->ChargerType), chargWattsInfo,
|
PsmInfoChargerTypeToStr(chargeInfo->ChargerType), chargWattsInfo,
|
||||||
(float)chargeInfo->VoltageAvg / 1000,
|
(float)chargeInfo->VoltageAvg / 1000, (float)chargeInfo->BatteryTemperature / 1000,
|
||||||
(float)chargeInfo->BatteryTemperature / 1000,
|
|
||||||
chargeInfo->InputCurrentLimit, chargeInfo->VBUSCurrentLimit,
|
chargeInfo->InputCurrentLimit, chargeInfo->VBUSCurrentLimit,
|
||||||
chargeInfo->ChargeCurrentLimit, chargeVoltLimit,
|
chargeInfo->ChargeCurrentLimit, chargeVoltLimit,
|
||||||
(float)chargeInfo->RawBatteryCharge / 1000,
|
(float)chargeInfo->RawBatteryCharge / 1000,
|
||||||
@@ -222,7 +131,6 @@ class MiscGui : public BaseMenuGui
|
|||||||
|
|
||||||
void LblUpdate(bool shouldSwitch = false)
|
void LblUpdate(bool shouldSwitch = false)
|
||||||
{
|
{
|
||||||
smInitialize();
|
|
||||||
lblInitialize();
|
lblInitialize();
|
||||||
|
|
||||||
lblGetBacklightSwitchStatus(&lblstatus);
|
lblGetBacklightSwitchStatus(&lblstatus);
|
||||||
@@ -230,7 +138,6 @@ class MiscGui : public BaseMenuGui
|
|||||||
lblstatus ? lblSwitchBacklightOff(0) : lblSwitchBacklightOn(0);
|
lblstatus ? lblSwitchBacklightOff(0) : lblSwitchBacklightOn(0);
|
||||||
|
|
||||||
lblExit();
|
lblExit();
|
||||||
smExit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isMariko = false;
|
bool isMariko = false;
|
||||||
@@ -240,8 +147,8 @@ class MiscGui : public BaseMenuGui
|
|||||||
void updateConfigToggles();
|
void updateConfigToggles();
|
||||||
|
|
||||||
tsl::elm::ToggleListItem* backlightToggle;
|
tsl::elm::ToggleListItem* backlightToggle;
|
||||||
tsl::elm::CategoryHeader* chargingLimitHeader;
|
tsl::elm::CategoryHeader *chargingCurrentHeader, *chargingLimitHeader;
|
||||||
StepTrackBarIcon* chargingLimitBar;
|
StepTrackBarIcon *chargingCurrentBar, *chargingLimitBar;
|
||||||
|
|
||||||
SysClkConfigValueList* configList;
|
SysClkConfigValueList* configList;
|
||||||
PsmChargeInfo* chargeInfo;
|
PsmChargeInfo* chargeInfo;
|
||||||
@@ -250,6 +157,8 @@ class MiscGui : public BaseMenuGui
|
|||||||
|
|
||||||
const char* infoNames = "Charger:\nBattery:\nCurrent Limit:\nCharging Limit:\nRaw Charge:\nBattery Age:\nPower Role:\nCurrent Flow:\n\nCPU Volt:\nGPU Volt:\nDRAM Volt:";
|
const char* infoNames = "Charger:\nBattery:\nCurrent Limit:\nCharging Limit:\nRaw Charge:\nBattery Age:\nPower Role:\nCurrent Flow:\n\nCPU Volt:\nGPU Volt:\nDRAM Volt:";
|
||||||
char infoVals[300] = "";
|
char infoVals[300] = "";
|
||||||
char chargingLimitBarDesc[30] = "";
|
char chargingLimitBarDesc[40] = "";
|
||||||
|
char chargingCurrentBarDesc[45] = "";
|
||||||
|
u32 batteryChargePerc = 0;
|
||||||
u8 frameCounter = 60;
|
u8 frameCounter = 60;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -209,9 +209,9 @@ void ClockManager::WaitForNextTick()
|
|||||||
|
|
||||||
bool ClockManager::RefreshContext()
|
bool ClockManager::RefreshContext()
|
||||||
{
|
{
|
||||||
bool fastChargingEnabled = !(this->GetConfig()->GetConfigValue(SysClkConfigValue_DisableFastCharging));
|
uint32_t chargingCurrent = this->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingCurrentLimit);
|
||||||
uint32_t chargingLimit = this->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingLimitPercentage);
|
uint32_t chargingLimit = this->GetConfig()->GetConfigValue(SysClkConfigValue_ChargingLimitPercentage);
|
||||||
PsmExt::ChargingHandler(fastChargingEnabled, chargingLimit);
|
PsmExt::ChargingHandler(chargingCurrent, chargingLimit);
|
||||||
|
|
||||||
bool hasChanged = this->config->Refresh();
|
bool hasChanged = this->config->Refresh();
|
||||||
if (hasChanged) {
|
if (hasChanged) {
|
||||||
|
|||||||
@@ -69,10 +69,15 @@ extern "C"
|
|||||||
hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro));
|
hosversionSet(MAKEHOSVERSION(fw.major, fw.minor, fw.micro));
|
||||||
setsysExit();
|
setsysExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = i2cInitialize();
|
||||||
|
if (R_FAILED(rc))
|
||||||
|
fatalThrow(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __appExit(void)
|
void __appExit(void)
|
||||||
{
|
{
|
||||||
|
i2cExit();
|
||||||
smExit();
|
smExit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,14 +105,19 @@ ReverseNXMode ReverseNXSync::RecheckToolMode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PsmExt::ChargingHandler(bool fastChargingEnabled, uint32_t chargingLimit) {
|
void PsmExt::ChargingHandler(uint32_t chargingCurrent, uint32_t chargingLimit) {
|
||||||
|
u32 current;
|
||||||
|
Result res = I2c_Bq24193_GetFastChargeCurrentLimit(¤t);
|
||||||
|
if (R_SUCCEEDED(res)) {
|
||||||
|
current -= current % 100;
|
||||||
|
if (current != chargingCurrent)
|
||||||
|
I2c_Bq24193_SetFastChargeCurrentLimit(chargingCurrent);
|
||||||
|
}
|
||||||
|
|
||||||
PsmChargeInfo* info = new PsmChargeInfo;
|
PsmChargeInfo* info = new PsmChargeInfo;
|
||||||
Service* session = psmGetServiceSession();
|
Service* session = psmGetServiceSession();
|
||||||
serviceDispatchOut(session, Psm_GetBatteryChargeInfoFields, *info);
|
serviceDispatchOut(session, Psm_GetBatteryChargeInfoFields, *info);
|
||||||
|
|
||||||
if (PsmIsFastChargingEnabled(info) != fastChargingEnabled)
|
|
||||||
serviceDispatch(session, fastChargingEnabled ? Psm_EnableFastBatteryCharging : Psm_DisableFastBatteryCharging);
|
|
||||||
|
|
||||||
if (PsmIsChargerConnected(info)) {
|
if (PsmIsChargerConnected(info)) {
|
||||||
u32 chargeNow = 0;
|
u32 chargeNow = 0;
|
||||||
if (R_SUCCEEDED(psmGetBatteryChargePercentage(&chargeNow))) {
|
if (R_SUCCEEDED(psmGetBatteryChargePercentage(&chargeNow))) {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
namespace PsmExt {
|
namespace PsmExt {
|
||||||
void ChargingHandler(bool fastChargingEnabled, uint32_t chargingLimit);
|
void ChargingHandler(uint32_t chargingCurrent, uint32_t chargingLimit);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Governor {
|
class Governor {
|
||||||
|
|||||||
Reference in New Issue
Block a user