diff --git a/Source/hoc-clk/common/include/hocclk/config.h b/Source/hoc-clk/common/include/hocclk/config.h index cb0656db..5abd4f85 100644 --- a/Source/hoc-clk/common/include/hocclk/config.h +++ b/Source/hoc-clk/common/include/hocclk/config.h @@ -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; } -} \ No newline at end of file +} diff --git a/Source/hoc-clk/overlay/src/ui/gui/config_info_strings.cpp b/Source/hoc-clk/overlay/src/ui/gui/config_info_strings.cpp index dac0f7a8..809bed56 100644 --- a/Source/hoc-clk/overlay/src/ui/gui/config_info_strings.cpp +++ b/Source/hoc-clk/overlay/src/ui/gui/config_info_strings.cpp @@ -90,6 +90,13 @@ std::vector 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 ConfigInfoStrings(HocClkConfigValue val, bool isMariko, default: return {}; } -} +} \ No newline at end of file diff --git a/Source/hoc-clk/overlay/src/ui/gui/misc_gui.cpp b/Source/hoc-clk/overlay/src/ui/gui/misc_gui.cpp index 2f7b7d2d..f051bdbd 100644 --- a/Source/hoc-clk/overlay/src/ui/gui/misc_gui.cpp +++ b/Source/hoc-clk/overlay/src/ui/gui/misc_gui.cpp @@ -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 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 displayClrPreset = { NamedValue("Do Not Override", AulaDisplayColorMode_DoNotOverride), diff --git a/Source/hoc-clk/sysmodule/src/i2c/i2cDrv.cpp b/Source/hoc-clk/sysmodule/src/i2c/i2cDrv.cpp index 1b72ad99..d0f069d0 100644 --- a/Source/hoc-clk/sysmodule/src/i2c/i2cDrv.cpp +++ b/Source/hoc-clk/sysmodule/src/i2c/i2cDrv.cpp @@ -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); -} \ No newline at end of file +} + +// 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; +} diff --git a/Source/hoc-clk/sysmodule/src/i2c/i2cDrv.h b/Source/hoc-clk/sysmodule/src/i2c/i2cDrv.h index 161306fe..5754398c 100644 --- a/Source/hoc-clk/sysmodule/src/i2c/i2cDrv.h +++ b/Source/hoc-clk/sysmodule/src/i2c/i2cDrv.h @@ -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; \ No newline at end of file +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; \ No newline at end of file diff --git a/Source/hoc-clk/sysmodule/src/mgr/clock_manager.cpp b/Source/hoc-clk/sysmodule/src/mgr/clock_manager.cpp index e447eacc..fd430f29 100644 --- a/Source/hoc-clk/sysmodule/src/mgr/clock_manager.cpp +++ b/Source/hoc-clk/sysmodule/src/mgr/clock_manager.cpp @@ -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); diff --git a/dist/atmosphere/contents/00FF0000636C6BFF/exefs.nsp b/dist/atmosphere/contents/00FF0000636C6BFF/exefs.nsp index 44465eb8..80687652 100644 Binary files a/dist/atmosphere/contents/00FF0000636C6BFF/exefs.nsp and b/dist/atmosphere/contents/00FF0000636C6BFF/exefs.nsp differ diff --git a/dist/switch/.overlays/horizon-oc-overlay.ovl b/dist/switch/.overlays/horizon-oc-overlay.ovl index a1de43d9..69e3caa3 100644 Binary files a/dist/switch/.overlays/horizon-oc-overlay.ovl and b/dist/switch/.overlays/horizon-oc-overlay.ovl differ