powctl: integrate 13.0.0 changes (aula params not done yet)

This commit is contained in:
Michael Scire 2021-10-15 16:30:27 -07:00
parent c04a262d49
commit 990daec3a2
16 changed files with 241 additions and 154 deletions

View file

@ -19,55 +19,62 @@
namespace ams::boot {
class BatteryDriver {
NON_COPYABLE(BatteryDriver);
NON_MOVEABLE(BatteryDriver);
private:
powctl::Session m_battery_session;
static constinit inline powctl::Session s_battery_session{powctl::Session::ConstantInitializeTag{}};
static constinit inline int s_reference_count{0};
public:
BatteryDriver() : m_battery_session() {
R_ABORT_UNLESS(powctl::OpenSession(std::addressof(m_battery_session), powctl::DeviceCode_Max17050, ddsf::AccessMode_ReadWrite));
BatteryDriver() {
if ((s_reference_count++) == 0) {
R_ABORT_UNLESS(powctl::OpenSession(std::addressof(s_battery_session), powctl::DeviceCode_Max17050, ddsf::AccessMode_ReadWrite));
}
}
~BatteryDriver() {
powctl::CloseSession(m_battery_session);
if ((--s_reference_count) == 0) {
powctl::CloseSession(s_battery_session);
}
}
public:
Result IsBatteryRemoved(bool *out) {
bool present;
R_TRY(powctl::IsBatteryPresent(std::addressof(present), m_battery_session));
R_TRY(powctl::IsBatteryPresent(std::addressof(present), s_battery_session));
*out = !present;
return ResultSuccess();
}
Result GetSocRep(float *out) {
return powctl::GetBatterySocRep(out, m_battery_session);
Result GetChargePercentage(float *out) {
return powctl::GetBatteryChargePercentage(out, s_battery_session);
}
Result GetAverageVCell(int *out) {
return powctl::GetBatteryAverageVCell(out, m_battery_session);
return powctl::GetBatteryAverageVCell(out, s_battery_session);
}
Result GetOpenCircuitVoltage(int *out) {
return powctl::GetBatteryOpenCircuitVoltage(out, m_battery_session);
return powctl::GetBatteryOpenCircuitVoltage(out, s_battery_session);
}
Result GetAverageCurrent(int *out) {
return powctl::GetBatteryAverageCurrent(out, m_battery_session);
return powctl::GetBatteryAverageCurrent(out, s_battery_session);
}
Result GetCurrent(int *out) {
return powctl::GetBatteryCurrent(out, m_battery_session);
return powctl::GetBatteryCurrent(out, s_battery_session);
}
Result GetTemperature(float *out) {
return powctl::GetBatteryTemperature(out, m_battery_session);
return powctl::GetBatteryTemperature(out, s_battery_session);
}
Result IsI2cShutdownEnabled(bool *out) {
return powctl::IsBatteryI2cShutdownEnabled(out, m_battery_session);
return powctl::IsBatteryI2cShutdownEnabled(out, s_battery_session);
}
Result SetI2cShutdownEnabled(bool en) {
return powctl::SetBatteryI2cShutdownEnabled(m_battery_session, en);
return powctl::SetBatteryI2cShutdownEnabled(s_battery_session, en);
}
};

View file

@ -357,7 +357,7 @@ namespace ams::boot {
if (show_charging_display) {
/* Get the raw battery charge. */
float raw_battery_charge;
if (R_FAILED(m_battery_driver.GetSocRep(std::addressof(raw_battery_charge)))) {
if (R_FAILED(m_battery_driver.GetChargePercentage(std::addressof(raw_battery_charge)))) {
return CheckBatteryResult::Shutdown;
}
@ -372,7 +372,7 @@ namespace ams::boot {
while (true) {
/* Get the raw battery charge. */
float raw_battery_charge;
if (R_FAILED(m_battery_driver.GetSocRep(std::addressof(raw_battery_charge)))) {
if (R_FAILED(m_battery_driver.GetChargePercentage(std::addressof(raw_battery_charge)))) {
return CheckBatteryResult::Shutdown;
}

View file

@ -100,7 +100,7 @@ namespace ams::boot {
bool use_desired_shutdown = true;
if (spl::GetHardwareType() == spl::HardwareType::Hoag) {
float battery_charge_raw;
if (R_FAILED(battery_driver.GetSocRep(std::addressof(battery_charge_raw))) || battery_charge_raw >= 80.0) {
if (R_FAILED(battery_driver.GetChargePercentage(std::addressof(battery_charge_raw))) || battery_charge_raw >= 80.0) {
use_desired_shutdown = false;
}
}