hocclk: add input current override feature
Co-Authored-By: cat130504 <231865593+cat130504@users.noreply.github.com>
This commit is contained in:
@@ -47,6 +47,7 @@ typedef enum {
|
||||
HocClkConfigValue_ThermalThrottleThreshold,
|
||||
|
||||
HocClkConfigValue_BatteryChargeCurrent,
|
||||
HocClkConfigValue_InputCurrentLimit,
|
||||
|
||||
HocClkConfigValue_OverwriteRefreshRate,
|
||||
HocClkConfigValue_MaxDisplayClockH,
|
||||
@@ -236,6 +237,9 @@ static inline const char* hocclkFormatConfigValue(HocClkConfigValue val, bool pr
|
||||
|
||||
case HocClkConfigValue_BatteryChargeCurrent:
|
||||
return pretty ? "Battery Charge Current" : "bat_charge_current";
|
||||
|
||||
case HocClkConfigValue_InputCurrentLimit:
|
||||
return pretty ? "Input Current Limit" : "in_curr_limit";
|
||||
|
||||
case HocClkConfigValue_OverwriteRefreshRate:
|
||||
return pretty ? "Display Refresh Rate Changing" : "drr_changing";
|
||||
@@ -486,6 +490,7 @@ static inline uint64_t hocclkDefaultConfigValue(HocClkConfigValue val)
|
||||
case HocClkConfigValue_UncappedClocks:
|
||||
case HocClkConfigValue_OverwriteBoostMode:
|
||||
case HocClkConfigValue_BatteryChargeCurrent:
|
||||
case HocClkConfigValue_InputCurrentLimit:
|
||||
case HocClkConfigValue_OverwriteRefreshRate:
|
||||
case HocClkConfigValue_GPUScheduling:
|
||||
case HocClkConfigValue_LiveCpuUv:
|
||||
@@ -670,10 +675,14 @@ static inline uint64_t hocclkValidConfigValue(HocClkConfigValue val, uint64_t in
|
||||
return true;
|
||||
case HocClkConfigValue_BatteryChargeCurrent:
|
||||
return ((input >= 1024) && (input <= 3072)) || !input;
|
||||
|
||||
case HocClkConfigValue_InputCurrentLimit:
|
||||
return ((input >= 100) && (input <= 3000)) || !input;
|
||||
|
||||
case HocClkConfigValue_DisplayVoltage:
|
||||
return ((input >= 800) && (input <= 1325));
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,13 @@ std::vector<std::string> ConfigInfoStrings(HocClkConfigValue val, bool isMariko,
|
||||
isHoag ? "Default: 1664 mA" : "2048 mA"
|
||||
};
|
||||
|
||||
|
||||
case HocClkConfigValue_InputCurrentLimit:
|
||||
return {
|
||||
"Overrides the maximum input current from the charger.",
|
||||
isHoag ? "Default: 900 mA" : "1200 mA"
|
||||
};
|
||||
|
||||
case HocClkConfigValue_AulaDisplayColorPreset:
|
||||
return {
|
||||
"Current display color preset. Default is Basic",
|
||||
@@ -544,4 +551,4 @@ std::vector<std::string> ConfigInfoStrings(HocClkConfigValue val, bool isMariko,
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -761,7 +761,7 @@ protected:
|
||||
tsl::elm::CustomDrawer* chargeWarningText = new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
|
||||
renderer->drawString("\uE150 Overriding the charge current", false, x + 20, y + 30, 18, tsl::style::color::ColorText);
|
||||
renderer->drawString("can be dangerous and may cause", false, x + 20, y + 50, 18, tsl::style::color::ColorText);
|
||||
renderer->drawString("damage to your battery or charger!", false, x + 20, y + 70, 18, tsl::style::color::ColorText);
|
||||
renderer->drawString("damage to your battery or orcodeus!", false, x + 20, y + 70, 18, tsl::style::color::ColorText);
|
||||
});
|
||||
chargeWarningText->setBoundaries(0, 0, tsl::cfg::FramebufferWidth, 90);
|
||||
this->listElement->addItem(chargeWarningText);
|
||||
@@ -819,6 +819,43 @@ protected:
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
tsl::elm::CustomDrawer* inputLimitWarningText = new tsl::elm::CustomDrawer([](tsl::gfx::Renderer *renderer, s32 x, s32 y, s32 w, s32 h) {
|
||||
renderer->drawString("\uE150 Overriding the input current", false, x + 20, y + 30, 18, tsl::style::color::ColorText);
|
||||
renderer->drawString("limit increases power draw from", false, x + 20, y + 50, 18, tsl::style::color::ColorText);
|
||||
renderer->drawString("your charger. Use only with the", false, x + 20, y + 70, 18, tsl::style::color::ColorText);
|
||||
renderer->drawString("official Nintendo charger!", false, x + 20, y + 90, 18, tsl::style::color::ColorText);
|
||||
});
|
||||
inputLimitWarningText->setBoundaries(0, 0, tsl::cfg::FramebufferWidth, 110);
|
||||
this->listElement->addItem(inputLimitWarningText);
|
||||
|
||||
// having an option for hoag would be cool and disabling 100-500 and 2000+
|
||||
std::vector<NamedValue> inputCurrentLimits = {
|
||||
NamedValue("Disabled", 0),
|
||||
NamedValue("100mA", 100),
|
||||
NamedValue("150mA", 150),
|
||||
NamedValue("500mA", 500),
|
||||
NamedValue("900mA", 900, "Hoag Default"),
|
||||
NamedValue("1200mA", 1200, "Default"),
|
||||
NamedValue("1500mA", 1500),
|
||||
NamedValue("2000mA", 2000),
|
||||
NamedValue("3000mA", 3000),
|
||||
};
|
||||
|
||||
ValueThresholds inputLimitThresholds(2000, 2001);
|
||||
|
||||
addConfigButton(
|
||||
HocClkConfigValue_InputCurrentLimit,
|
||||
"Input Current Limit Override",
|
||||
ValueRange(0, 0, 1, "", 0),
|
||||
"Input Current Limit Override",
|
||||
&inputLimitThresholds,
|
||||
{},
|
||||
inputCurrentLimits,
|
||||
false
|
||||
);
|
||||
|
||||
if(IsAula()) {
|
||||
std::vector<NamedValue> displayClrPreset = {
|
||||
NamedValue("Do Not Override", AulaDisplayColorMode_DoNotOverride),
|
||||
|
||||
@@ -219,4 +219,55 @@ Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Converts mA to the raw value for bits [2:0] of REG00
|
||||
static u8 I2c_Bq24193_Convert_InputmA_Raw(u32 ma) {
|
||||
if (ma <= 100) return 0b000;
|
||||
if (ma <= 150) return 0b001;
|
||||
if (ma <= 500) return 0b010;
|
||||
if (ma <= 900) return 0b011;
|
||||
if (ma <= 1200) return 0b100;
|
||||
if (ma <= 1500) return 0b101;
|
||||
if (ma <= 2000) return 0b110;
|
||||
return 0b111; // 3000mA max
|
||||
}
|
||||
|
||||
Result I2c_Bq24193_SetInputCurrentLimit(u32 ma) {
|
||||
// don't do anything if it's disabled
|
||||
if (ma == 0)
|
||||
return 0;
|
||||
|
||||
u8 raw;
|
||||
Result res = I2cRead_OutU8(I2cDevice_Bq24193,
|
||||
BQ24193_INPUT_SOURCE_CONTROL_REG,
|
||||
&raw);
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
raw &= ~0x07;
|
||||
raw |= I2c_Bq24193_Convert_InputmA_Raw(ma);
|
||||
|
||||
return I2cSet_U8(I2cDevice_Bq24193,BQ24193_INPUT_SOURCE_CONTROL_REG,raw);
|
||||
}
|
||||
|
||||
// not used
|
||||
Result I2c_Bq24193_GetInputCurrentLimit(u32 *ma) {
|
||||
u8 raw;
|
||||
Result res = I2cRead_OutU8(I2cDevice_Bq24193,BQ24193_INPUT_SOURCE_CONTROL_REG,&raw);
|
||||
if (R_FAILED(res))
|
||||
return res;
|
||||
|
||||
switch (raw & 0x07) {
|
||||
case 0b000: *ma = 100; break;
|
||||
case 0b001: *ma = 150; break;
|
||||
case 0b010: *ma = 500; break;
|
||||
case 0b011: *ma = 900; break;
|
||||
case 0b100: *ma = 1200; break;
|
||||
case 0b101: *ma = 1500; break;
|
||||
case 0b110: *ma = 2000; break;
|
||||
case 0b111: *ma = 3000; break;
|
||||
default: *ma = 0; break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -63,4 +63,9 @@ 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;
|
||||
const u8 BQ24193_CHARGE_CURRENT_CONTROL_REG = 0x2;
|
||||
|
||||
Result I2c_Bq24193_SetInputCurrentLimit(u32 ma);
|
||||
Result I2c_Bq24193_GetInputCurrentLimit(u32 *ma);
|
||||
|
||||
const u8 BQ24193_INPUT_SOURCE_CONTROL_REG = 0x00;
|
||||
@@ -341,24 +341,29 @@ namespace clockManager {
|
||||
}
|
||||
void HandleMiscFeatures()
|
||||
{
|
||||
// these dont need to run that often, so dont bother
|
||||
static u32 tick = 0;
|
||||
if(++tick > 10) {
|
||||
tick = 0;
|
||||
|
||||
if (config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)) {
|
||||
I2c_Bq24193_SetFastChargeCurrentLimit(config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent));
|
||||
}
|
||||
// these dont need to run that often, so dont bother
|
||||
static u32 tick = 0;
|
||||
if(++tick > 10) {
|
||||
tick = 0;
|
||||
|
||||
I2c_BuckConverter_SetMvOut(&I2c_Display, config::GetConfigValue(HocClkConfigValue_DisplayVoltage));
|
||||
if (config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent)) {
|
||||
I2c_Bq24193_SetFastChargeCurrentLimit(config::GetConfigValue(HocClkConfigValue_BatteryChargeCurrent));
|
||||
}
|
||||
|
||||
if(board::GetConsoleType() == HocClkConsoleType_Aula)
|
||||
AulaDisplay::SetDisplayColorMode((AulaColorMode)config::GetConfigValue(HocClkConfigValue_AulaDisplayColorPreset));
|
||||
if(config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) {
|
||||
board::HandleCpuUv();
|
||||
}
|
||||
if (config::GetConfigValue(HocClkConfigValue_InputCurrentLimit)) {
|
||||
I2c_Bq24193_SetInputCurrentLimit(config::GetConfigValue(HocClkConfigValue_InputCurrentLimit));
|
||||
}
|
||||
|
||||
I2c_BuckConverter_SetMvOut(&I2c_Display, config::GetConfigValue(HocClkConfigValue_DisplayVoltage));
|
||||
|
||||
if(board::GetConsoleType() == HocClkConsoleType_Aula)
|
||||
AulaDisplay::SetDisplayColorMode((AulaColorMode)config::GetConfigValue(HocClkConfigValue_AulaDisplayColorPreset));
|
||||
if(config::GetConfigValue(HocClkConfigValue_LiveCpuUv)) {
|
||||
board::HandleCpuUv();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyGpuDvfs(u32 targetHz) {
|
||||
s32 dvfsOffset = config::GetConfigValue(HocClkConfigValue_DVFSOffset);
|
||||
|
||||
BIN
dist/atmosphere/contents/00FF0000636C6BFF/exefs.nsp
vendored
BIN
dist/atmosphere/contents/00FF0000636C6BFF/exefs.nsp
vendored
Binary file not shown.
BIN
dist/switch/.overlays/horizon-oc-overlay.ovl
vendored
BIN
dist/switch/.overlays/horizon-oc-overlay.ovl
vendored
Binary file not shown.
Reference in New Issue
Block a user