diff --git a/libraries/libstratosphere/include/stratosphere/gpio/gpio_pad_name.board.nintendo_nx.hpp b/libraries/libstratosphere/include/stratosphere/gpio/gpio_pad_name.board.nintendo_nx.hpp index 0f777e601..60b542e2c 100644 --- a/libraries/libstratosphere/include/stratosphere/gpio/gpio_pad_name.board.nintendo_nx.hpp +++ b/libraries/libstratosphere/include/stratosphere/gpio/gpio_pad_name.board.nintendo_nx.hpp @@ -114,7 +114,6 @@ namespace ams::gpio { GpioPadName_NfcEn = 92, }; - /* TODO: Better place for this? */ constexpr inline const DeviceCode DeviceCode_CodecLdoEnTemp = 0x33000002; constexpr inline const DeviceCode DeviceCode_PowSdEn = 0x3C000001; constexpr inline const DeviceCode DeviceCode_BtRst = 0x37000002; @@ -128,7 +127,7 @@ namespace ams::gpio { constexpr inline const DeviceCode DeviceCode_FanTach = 0x3D000002; constexpr inline const DeviceCode DeviceCode_ExtconDetS = 0x3500040B; constexpr inline const DeviceCode DeviceCode_Vdd50AEn = 0x39000401; - constexpr inline const DeviceCode DeviceCode_SdevCoaxSel1 = 0xCA000402; + constexpr inline const DeviceCode DeviceCode_SdevCoaxSel1 = 0xCA000406; constexpr inline const DeviceCode DeviceCode_GameCardCd = 0x3C000403; constexpr inline const DeviceCode DeviceCode_ProdType0 = 0xC900040B; constexpr inline const DeviceCode DeviceCode_ProdType1 = 0xC900040C; @@ -148,7 +147,7 @@ namespace ams::gpio { constexpr inline const DeviceCode DeviceCode_PdVconnEn = 0x040000CC; constexpr inline const DeviceCode DeviceCode_PdRstN = 0x040000CA; constexpr inline const DeviceCode DeviceCode_Bq24190Irq = 0x39000002; - constexpr inline const DeviceCode DeviceCode_SdevCoaxSel0 = 0xCA000401; + constexpr inline const DeviceCode DeviceCode_SdevCoaxSel0 = 0xCA000405; constexpr inline const DeviceCode DeviceCode_SdWp = 0x3C000003; constexpr inline const DeviceCode DeviceCode_TpReset = 0x35000035; constexpr inline const DeviceCode DeviceCode_BtGpio2 = 0x37000401; @@ -216,6 +215,7 @@ namespace ams::gpio { constexpr inline const DeviceCode DeviceCode_GpioPortY7 = 0x35000065; constexpr inline const DeviceCode DeviceCode_GpioPortF1 = 0x04000409; constexpr inline const DeviceCode DeviceCode_GpioPortH0 = 0x34000401; + constexpr inline const DeviceCode DeviceCode_GpioPortI6 = 0x37000405; constexpr inline GpioPadName ConvertToGpioPadName(DeviceCode dc) { switch (dc.GetInternalValue()) { diff --git a/libraries/libstratosphere/include/stratosphere/powctl/driver/impl/powctl_charge_arbiter.hpp b/libraries/libstratosphere/include/stratosphere/powctl/driver/impl/powctl_charge_arbiter.hpp index 636fa3a33..a27157e85 100644 --- a/libraries/libstratosphere/include/stratosphere/powctl/driver/impl/powctl_charge_arbiter.hpp +++ b/libraries/libstratosphere/include/stratosphere/powctl/driver/impl/powctl_charge_arbiter.hpp @@ -27,7 +27,7 @@ namespace ams::powctl::driver::impl { int m_charge_voltage_limit; BatteryTemperatureLevel m_temperature_level; int m_avg_v_cell; - int m_open_circuit_voltage; + float m_voltage_fuel_gauge_percentage; bool m_has_battery_done_current; int m_battery_done_current; PowerState m_power_state; @@ -45,6 +45,17 @@ namespace ams::powctl::driver::impl { return value < max; } } + static constexpr bool IsInRangeFloat(float value, float min, float max) { + if (!(min <= value)) { + return false; + } + + if (max == std::numeric_limits::max()) { + return value <= max; + } else { + return value < max; + } + } bool IsAcceptablePowerState(const PowerState *acceptable, size_t num_acceptable) const { for (size_t i = 0; i < num_acceptable; ++i) { @@ -57,7 +68,7 @@ namespace ams::powctl::driver::impl { public: ChargeArbiter(const ChargeParametersRule *r, size_t nr, int cvl) : m_rules(r), m_num_rules(nr), m_charge_voltage_limit(cvl), m_temperature_level(BatteryTemperatureLevel::Medium), - m_avg_v_cell(4080), m_open_circuit_voltage(4001), m_has_battery_done_current(false), m_battery_done_current(0), + m_avg_v_cell(4080), m_voltage_fuel_gauge_percentage(25.0), m_has_battery_done_current(false), m_battery_done_current(0), m_power_state(PowerState::FullAwake), m_selected_rule(nullptr), m_check_battery_done_current(false) { this->UpdateSelectedRule(); @@ -73,8 +84,8 @@ namespace ams::powctl::driver::impl { this->UpdateSelectedRule(); } - void SetBatteryOpenCircuitVoltage(int ocv) { - m_open_circuit_voltage = ocv; + void SetBatteryVoltageFuelGaugePercentage(float pct) { + m_voltage_fuel_gauge_percentage = pct; this->UpdateSelectedRule(); } @@ -121,8 +132,8 @@ namespace ams::powctl::driver::impl { continue; } - /* Check that open circuit voltage is in range. */ - if (!IsInRange(m_open_circuit_voltage, cur_rule.min_open_circuit_voltage, cur_rule.max_open_circuit_voltage)) { + /* Check that voltage fuel gauge percentage is in range. */ + if (!IsInRangeFloat(m_voltage_fuel_gauge_percentage, cur_rule.min_voltage_fuel_gauge_percentage, cur_rule.max_voltage_fuel_gauge_percentage)) { continue; } @@ -138,9 +149,25 @@ namespace ams::powctl::driver::impl { continue; } + /* Determine whether we should check battery done current. */ + bool check_battery_done_current; + + if (m_selected_rule != nullptr && m_selected_rule->check_battery_current) { + if (m_selected_rule->temperature_level == m_temperature_level && + IsInRange(m_avg_v_cell, m_selected_rule->min_avg_v_cell, m_selected_rule->max_avg_v_cell) && + IsInRangeFloat(m_voltage_fuel_gauge_percentage, m_selected_rule->min_voltage_fuel_gauge_percentage, m_selected_rule->max_voltage_fuel_gauge_percentage)) + { + check_battery_done_current = m_has_battery_done_current && !IsInRange(m_battery_done_current, m_selected_rule->min_battery_done_current, m_selected_rule->max_battery_done_current); + } else { + check_battery_done_current = true; + } + } else { + check_battery_done_current = false; + } + /* Set whether we need to check the battery done current. */ m_has_battery_done_current = false; - m_check_battery_done_current |= cur_rule.check_battery_current; + m_check_battery_done_current |= check_battery_done_current; } else { /* We're selecting the currently selected rule. Make sure the battery done current is acceptable if we have one. */ if (m_has_battery_done_current && !IsInRange(m_battery_done_current, cur_rule.min_battery_done_current, cur_rule.max_battery_done_current)) { diff --git a/libraries/libstratosphere/include/stratosphere/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.hpp b/libraries/libstratosphere/include/stratosphere/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.hpp index 4b7a66688..bba85ec6b 100644 --- a/libraries/libstratosphere/include/stratosphere/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.hpp +++ b/libraries/libstratosphere/include/stratosphere/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.hpp @@ -23,10 +23,12 @@ namespace ams::powctl::driver::impl { BatteryTemperatureLevel temperature_level; int min_avg_v_cell; int max_avg_v_cell; - int min_open_circuit_voltage; - int max_open_circuit_voltage; int min_battery_done_current; int max_battery_done_current; + float min_unknown_14; + float max_unknown_18; + float min_voltage_fuel_gauge_percentage; + float max_voltage_fuel_gauge_percentage; const PowerState *acceptable_power_states; size_t num_acceptable_power_states; bool check_battery_current; diff --git a/libraries/libstratosphere/include/stratosphere/powctl/impl/powctl_battery_charge_percentage.hpp b/libraries/libstratosphere/include/stratosphere/powctl/impl/powctl_battery_charge_percentage.hpp index ad452461f..a2a0881f2 100644 --- a/libraries/libstratosphere/include/stratosphere/powctl/impl/powctl_battery_charge_percentage.hpp +++ b/libraries/libstratosphere/include/stratosphere/powctl/impl/powctl_battery_charge_percentage.hpp @@ -43,7 +43,7 @@ namespace ams::powctl::impl { constexpr inline int GetDisplayPercentage(double raw_percentage, double min, double max) { /* Calculate the display percentage. */ constexpr const double BaseDisplayPercentage = 2.0; - const auto display_percentage = BaseDisplayPercentage + ((static_cast(MaxDisplayPercentage - MinDisplayPercentage) * (raw_percentage - min)) / (max - min)); + const auto display_percentage = BaseDisplayPercentage + ((static_cast(MaxDisplayPercentage - BaseDisplayPercentage) * (raw_percentage - min)) / (max - min)); /* Clamp the display percentage within bounds. */ return std::max(std::min(static_cast(display_percentage), MaxDisplayPercentage), MinDisplayPercentage); diff --git a/libraries/libstratosphere/source/gpio/driver/board/nintendo/nx/impl/gpio_internal_pad_map_combination.inc b/libraries/libstratosphere/source/gpio/driver/board/nintendo/nx/impl/gpio_internal_pad_map_combination.inc index db2991784..6b72a2099 100644 --- a/libraries/libstratosphere/source/gpio/driver/board/nintendo/nx/impl/gpio_internal_pad_map_combination.inc +++ b/libraries/libstratosphere/source/gpio/driver/board/nintendo/nx/impl/gpio_internal_pad_map_combination.inc @@ -94,6 +94,7 @@ constexpr inline const PadMapCombination PadMapCombinationList[] = { { DeviceCode_HdmiHpd, InternalGpioPadNumber_Port_CC_1, ams::wec::WakeEvent_None }, { DeviceCode_GpioPortF1, InternalGpioPadNumber_Port_F_1, ams::wec::WakeEvent_None }, { DeviceCode_GpioPortH0, InternalGpioPadNumber_Port_H_0, ams::wec::WakeEvent_None }, + { DeviceCode_GpioPortI6, InternalGpioPadNumber_Port_I_6, ams::wec::WakeEvent_None }, { DeviceCode_ExtconDetS, InternalGpioPadNumber_Port_E_6, ams::wec::WakeEvent_ExtconDetS }, { DeviceCode_GameCardCd, InternalGpioPadNumber_Port_S_3, ams::wec::WakeEvent_CamI2cSda }, { DeviceCode_BattMgicIrq, InternalGpioPadNumber_Port_Y_0, ams::wec::WakeEvent_ButtonSlideSw }, diff --git a/libraries/libstratosphere/source/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.cpp b/libraries/libstratosphere/source/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.cpp index d88c465a9..fd0ef3ba3 100644 --- a/libraries/libstratosphere/source/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.cpp +++ b/libraries/libstratosphere/source/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.cpp @@ -32,8 +32,11 @@ namespace ams::powctl::driver::impl { PowerState::ShutdownChargeMain, }; - constexpr inline const int Min = std::numeric_limits::min(); constexpr inline const int Max = std::numeric_limits::max(); + constexpr inline const int Min = std::numeric_limits::min(); + + constexpr inline const float FloatMax = std::numeric_limits::max(); + constexpr inline const float FloatMin = -FloatMax; constexpr inline const UnknownParameterX UnknownXTableForBatteryVersion2[] = { { 20000, 4320, 95.0, 100.4 }, diff --git a/libraries/libstratosphere/source/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.inc b/libraries/libstratosphere/source/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.inc index b280e6732..5b5a06046 100644 --- a/libraries/libstratosphere/source/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.inc +++ b/libraries/libstratosphere/source/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.inc @@ -17,63 +17,64 @@ /* NOTE: This file is auto-generated by charger_parameters.py, do not edit manually. */ constexpr inline const ChargeParametersRule ChargeParametersRulesForBatteryVersion0[] = { - { BatteryTemperatureLevel::TooLow, Min, 3320, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 512, 0, 0 }, - { BatteryTemperatureLevel::TooLow, 3320, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 768, 0, 0 }, - { BatteryTemperatureLevel::Low, Min, 3320, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 512, 0, 0 }, - { BatteryTemperatureLevel::Low, 3320, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 768, 0, 0 }, - { BatteryTemperatureLevel::Medium, Min, 3320, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 512, 0, 0 }, - { BatteryTemperatureLevel::Medium, 3320, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 2048, 0, 0 }, - { BatteryTemperatureLevel::High, Min, 3320, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 3952, 512, 0, 0 }, - { BatteryTemperatureLevel::High, 3320, 4050, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 3952, 2048, 0, 0 }, - { BatteryTemperatureLevel::High, 4050, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 2048, 0, 0 }, - { BatteryTemperatureLevel::TooHigh, Min, 3320, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 3952, 512, 0, 0 }, - { BatteryTemperatureLevel::TooHigh, 3320, 4050, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 3952, 2048, 0, 0 }, - { BatteryTemperatureLevel::TooHigh, 4050, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 2048, 0, 0 }, + { BatteryTemperatureLevel::TooLow, Min, 3320, Min, Max, FloatMin, 3.0, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 512, 0, 0 }, + { BatteryTemperatureLevel::TooLow, 3320, Max, Min, Max, 3.0, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 768, 0, 0 }, + { BatteryTemperatureLevel::Low, Min, 3320, Min, Max, FloatMin, 3.0, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 512, 0, 0 }, + { BatteryTemperatureLevel::Low, 3320, Max, Min, Max, 3.0, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 768, 0, 0 }, + { BatteryTemperatureLevel::Medium, Min, 3320, Min, Max, FloatMin, 3.0, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 512, 0, 0 }, + { BatteryTemperatureLevel::Medium, 3320, Max, Min, Max, 3.0, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 2048, 0, 0 }, + { BatteryTemperatureLevel::High, Min, 3320, Min, Max, FloatMin, 3.0, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 3952, 512, 0, 0 }, + { BatteryTemperatureLevel::High, 3320, 4050, Min, Max, 3.0, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 3952, 2048, 0, 0 }, + { BatteryTemperatureLevel::High, 4050, Max, Min, Max, 3.0, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 2048, 0, 0 }, + { BatteryTemperatureLevel::TooHigh, Min, 3320, Min, Max, FloatMin, 3.0, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 3952, 512, 0, 0 }, + { BatteryTemperatureLevel::TooHigh, 3320, 4050, Min, Max, 3.0, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 3952, 2048, 0, 0 }, + { BatteryTemperatureLevel::TooHigh, 4050, Max, Min, Max, 3.0, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 2048, 0, 0 }, }; constexpr inline const ChargeParametersRule ChargeParametersRulesForBatteryVersion1[] = { - { BatteryTemperatureLevel::TooLow, Min, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 576, 0, 0 }, - { BatteryTemperatureLevel::Low, Min, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 576, 0, 0 }, - { BatteryTemperatureLevel::Medium, Min, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 1536, 0, 0 }, - { BatteryTemperatureLevel::High, Min, 3984, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 3984, 1536, 0, 0 }, - { BatteryTemperatureLevel::High, 3984, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 1536, 0, 0 }, - { BatteryTemperatureLevel::TooHigh, Min, 3984, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 3984, 1536, 0, 0 }, - { BatteryTemperatureLevel::TooHigh, 3984, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 1536, 0, 0 }, + { BatteryTemperatureLevel::TooLow, Min, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 576, 0, 0 }, + { BatteryTemperatureLevel::Low, Min, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 576, 0, 0 }, + { BatteryTemperatureLevel::Medium, Min, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 1536, 0, 0 }, + { BatteryTemperatureLevel::High, Min, 3984, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 3984, 1536, 0, 0 }, + { BatteryTemperatureLevel::High, 3984, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 1536, 0, 0 }, + { BatteryTemperatureLevel::TooHigh, Min, 3984, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 3984, 1536, 0, 0 }, + { BatteryTemperatureLevel::TooHigh, 3984, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 1536, 0, 0 }, }; constexpr inline const ChargeParametersRule ChargeParametersRulesForBatteryVersion2[] = { - { BatteryTemperatureLevel::TooLow, Min, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4320, 640, 0, 0 }, - { BatteryTemperatureLevel::Low, Min, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4320, 640, 0, 0 }, - { BatteryTemperatureLevel::Medium, Min, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4320, 1664, 0, 0 }, - { BatteryTemperatureLevel::High, Min, 4080, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4080, 1664, 0, 0 }, - { BatteryTemperatureLevel::High, 4080, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4320, 1664, 0, 0 }, - { BatteryTemperatureLevel::TooHigh, Min, 4080, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4080, 1664, 0, 0 }, - { BatteryTemperatureLevel::TooHigh, 4080, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4320, 1664, 0, 0 }, + { BatteryTemperatureLevel::TooLow, Min, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4320, 640, 0, 0 }, + { BatteryTemperatureLevel::Low, Min, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4320, 640, 0, 0 }, + { BatteryTemperatureLevel::Medium, Min, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4320, 1664, 0, 0 }, + { BatteryTemperatureLevel::High, Min, 4080, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4080, 1664, 0, 0 }, + { BatteryTemperatureLevel::High, 4080, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4320, 1664, 0, 0 }, + { BatteryTemperatureLevel::TooHigh, Min, 4080, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4080, 1664, 0, 0 }, + { BatteryTemperatureLevel::TooHigh, 4080, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4320, 1664, 0, 0 }, }; constexpr inline const ChargeParametersRule ChargeParametersRulesForBatteryVersion0ForAula[] = { - { BatteryTemperatureLevel::TooLow, Min, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 768, 0, 0 }, - { BatteryTemperatureLevel::Low, Min, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 768, 0, 0 }, - { BatteryTemperatureLevel::Medium, Min, Max, Min, 4001, 2049, Max, AcceptablePowerStatesForNotAwakeCharge, util::size(AcceptablePowerStatesForNotAwakeCharge), true, true, 4000, 3072, 40, 112 }, - { BatteryTemperatureLevel::Medium, Min, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 2048, 0, 0 }, - { BatteryTemperatureLevel::High, Min, 4050, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 3952, 2048, 0, 0 }, - { BatteryTemperatureLevel::High, 4050, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 2048, 0, 0 }, - { BatteryTemperatureLevel::TooHigh, Min, 4050, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 3952, 2048, 0, 0 }, - { BatteryTemperatureLevel::TooHigh, 4050, Max, Min, Max, Min, Max, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 2048, 0, 0 }, + { BatteryTemperatureLevel::TooLow, Min, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 768, 0, 0 }, + { BatteryTemperatureLevel::Low, Min, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 768, 0, 0 }, + { BatteryTemperatureLevel::Medium, Min, Max, 2049, Max, FloatMin, FloatMax, FloatMin, 23.0, AcceptablePowerStatesForNotAwakeCharge, util::size(AcceptablePowerStatesForNotAwakeCharge), true, true, 4000, 3072, 40, 112 }, + { BatteryTemperatureLevel::Medium, Min, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 4208, 2048, 0, 0 }, + { BatteryTemperatureLevel::High, Min, 4050, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, true, 3952, 2048, 0, 0 }, + { BatteryTemperatureLevel::High, 4050, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 2048, 0, 0 }, + { BatteryTemperatureLevel::TooHigh, Min, 4050, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 3952, 2048, 0, 0 }, + { BatteryTemperatureLevel::TooHigh, 4050, Max, Min, Max, FloatMin, FloatMax, FloatMin, FloatMax, AcceptablePowerStates, util::size(AcceptablePowerStates), false, false, 4208, 2048, 0, 0 }, }; constexpr inline const ChargeParameters ChargeParametersForBatteryVersion0 = { - 4, 17, 51, 60, 512, 4208, nullptr, 0, 95.0, 99.0, ChargeParametersRulesForBatteryVersion0, util::size(ChargeParametersRulesForBatteryVersion0) + 4, 17, 51, 60, 512, 4208, nullptr, 0, 95.0, 99.0, ChargeParametersRulesForBatteryVersion0, util::size(ChargeParametersRulesForBatteryVersion0) }; constexpr inline const ChargeParameters ChargeParametersForBatteryVersion1 = { - 1, 19, 48, 59, 1536, 4208, nullptr, 0, 95.0, 99.0, ChargeParametersRulesForBatteryVersion1, util::size(ChargeParametersRulesForBatteryVersion1) + 1, 19, 48, 59, 1536, 4208, nullptr, 0, 95.0, 99.0, ChargeParametersRulesForBatteryVersion1, util::size(ChargeParametersRulesForBatteryVersion1) }; constexpr inline const ChargeParameters ChargeParametersForBatteryVersion2 = { - 1, 19, 48, 59, 1664, 4320, UnknownXTableForBatteryVersion2, util::size(UnknownXTableForBatteryVersion2), 95.0, 100.4, ChargeParametersRulesForBatteryVersion2, util::size(ChargeParametersRulesForBatteryVersion2) + 1, 19, 48, 59, 1664, 4320, UnknownXTableForBatteryVersion2, util::size(UnknownXTableForBatteryVersion2), 95.0, 100.4, ChargeParametersRulesForBatteryVersion2, util::size(ChargeParametersRulesForBatteryVersion2) }; constexpr inline const ChargeParameters ChargeParametersForBatteryVersion0ForAula = { 4, 17, 51, 60, 512, 4208, nullptr, 0, 95.0, 99.0, ChargeParametersRulesForBatteryVersion0ForAula, util::size(ChargeParametersRulesForBatteryVersion0ForAula) }; + diff --git a/stratosphere/boot/source/boot_battery_driver.hpp b/stratosphere/boot/source/boot_battery_driver.hpp index 3d3ef63e4..9b0c64c2b 100644 --- a/stratosphere/boot/source/boot_battery_driver.hpp +++ b/stratosphere/boot/source/boot_battery_driver.hpp @@ -53,8 +53,8 @@ namespace ams::boot { return powctl::GetBatteryAverageVCell(out, s_battery_session); } - Result GetOpenCircuitVoltage(int *out) { - return powctl::GetBatteryOpenCircuitVoltage(out, s_battery_session); + Result GetVoltageFuelGaugePercentage(float *out) { + return powctl::GetBatteryVoltageFuelGaugePercentage(out, s_battery_session); } Result GetAverageCurrent(int *out) { diff --git a/stratosphere/boot/source/boot_check_battery.cpp b/stratosphere/boot/source/boot_check_battery.cpp index f911f4c31..33f2396f5 100644 --- a/stratosphere/boot/source/boot_check_battery.cpp +++ b/stratosphere/boot/source/boot_check_battery.cpp @@ -110,8 +110,8 @@ namespace ams::boot { AMS_UNUSED(raw_charge, voltage, voltage_threshold); /* Get various battery metrics. */ - int avg_current, current, open_circuit_voltage; - float temp; + int avg_current, current; + float temp, voltage_fuel_gauge_percentage; if (R_FAILED(m_battery_driver.GetAverageCurrent(std::addressof(avg_current)))) { return; } @@ -121,12 +121,12 @@ namespace ams::boot { if (R_FAILED(m_battery_driver.GetTemperature(std::addressof(temp)))) { return; } - if (R_FAILED(m_battery_driver.GetOpenCircuitVoltage(std::addressof(open_circuit_voltage)))) { + if (R_FAILED(m_battery_driver.GetVoltageFuelGaugePercentage(std::addressof(voltage_fuel_gauge_percentage)))) { return; } /* TODO: Print the things we just got. */ - AMS_UNUSED(avg_current, current, temp, open_circuit_voltage); + AMS_UNUSED(avg_current, current, temp, voltage_fuel_gauge_percentage); } bool BatteryChecker::IsChargeDone() { @@ -198,12 +198,12 @@ namespace ams::boot { } m_charge_arbiter.SetBatteryAverageVCell(avg_v_cell); - /* Update open circuit voltage. */ - int ocv; - if (R_FAILED(m_battery_driver.GetOpenCircuitVoltage(std::addressof(ocv)))) { + /* Update voltage fuel gauge percentage. */ + float vfgp; + if (R_FAILED(m_battery_driver.GetVoltageFuelGaugePercentage(std::addressof(vfgp)))) { boot::ShutdownSystem(); } - m_charge_arbiter.SetBatteryOpenCircuitVoltage(ocv); + m_charge_arbiter.SetBatteryVoltageFuelGaugePercentage(vfgp); /* Update charge done current. */ this->UpdateChargeDoneCurrent(); @@ -450,7 +450,6 @@ namespace ams::boot { /* Update the charger. */ this->UpdateCharger(); } - } } @@ -492,7 +491,7 @@ namespace ams::boot { /* Get the charge voltage limit. */ int charge_voltage_limit_mv; - if (boot_reason != spl::BootReason_RtcAlarm2) { + if (boot_reason != spl::BootReason_RtcAlarm2 || charge_parameters.unknown_x_table == nullptr || charge_parameters.x_table_size == 0) { charge_voltage_limit_mv = charge_parameters.default_charge_voltage_limit; } else { if (R_FAILED(charger_driver.GetChargeVoltageLimit(std::addressof(charge_voltage_limit_mv)))) { diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index 30d8f998a..62163e283 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -135,11 +135,6 @@ namespace ams { /* Get the hardware type. */ const auto hw_type = spl::GetHardwareType(); - /* TODO: Aula support. */ - /* We haven't actually implemented battery configuration for Aula, running on OLED models */ - /* is likely not good for the hardware until we do that properly. */ - AMS_ABORT_UNLESS(hw_type != spl::HardwareType::Aula); - /* Initialize the power control library without interrupt event handling. */ if (hw_type != spl::HardwareType::Calcio) { powctl::Initialize(false);