2019-05-06 15:00:22 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2019-05-06 15:00:22 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
2020-11-08 12:16:50 +00:00
|
|
|
#include <stratosphere.hpp>
|
2019-05-06 15:00:22 +00:00
|
|
|
|
2019-10-24 09:30:10 +00:00
|
|
|
namespace ams::boot {
|
2019-05-06 15:00:22 +00:00
|
|
|
|
2019-06-22 07:10:21 +00:00
|
|
|
class BatteryDriver {
|
|
|
|
private:
|
2021-10-10 07:14:06 +00:00
|
|
|
powctl::Session m_battery_session;
|
2019-06-22 07:10:21 +00:00
|
|
|
public:
|
2021-10-10 07:14:06 +00:00
|
|
|
BatteryDriver() : m_battery_session() {
|
|
|
|
R_ABORT_UNLESS(powctl::OpenSession(std::addressof(m_battery_session), powctl::DeviceCode_Max17050, ddsf::AccessMode_ReadWrite));
|
2019-06-22 07:10:21 +00:00
|
|
|
}
|
2019-05-06 15:00:22 +00:00
|
|
|
|
2019-06-22 07:10:21 +00:00
|
|
|
~BatteryDriver() {
|
2021-10-10 07:14:06 +00:00
|
|
|
powctl::CloseSession(m_battery_session);
|
2019-06-22 07:10:21 +00:00
|
|
|
}
|
|
|
|
public:
|
2020-11-08 12:16:50 +00:00
|
|
|
Result IsBatteryRemoved(bool *out) {
|
|
|
|
bool present;
|
2021-10-10 07:14:06 +00:00
|
|
|
R_TRY(powctl::IsBatteryPresent(std::addressof(present), m_battery_session));
|
2020-11-08 12:16:50 +00:00
|
|
|
|
2021-10-07 06:22:54 +00:00
|
|
|
*out = !present;
|
|
|
|
return ResultSuccess();
|
2020-11-08 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetSocRep(float *out) {
|
2021-10-10 07:14:06 +00:00
|
|
|
return powctl::GetBatterySocRep(out, m_battery_session);
|
2020-11-08 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetAverageVCell(int *out) {
|
2021-10-10 07:14:06 +00:00
|
|
|
return powctl::GetBatteryAverageVCell(out, m_battery_session);
|
2020-11-08 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetOpenCircuitVoltage(int *out) {
|
2021-10-10 07:14:06 +00:00
|
|
|
return powctl::GetBatteryOpenCircuitVoltage(out, m_battery_session);
|
2020-11-08 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetAverageCurrent(int *out) {
|
2021-10-10 07:14:06 +00:00
|
|
|
return powctl::GetBatteryAverageCurrent(out, m_battery_session);
|
2020-11-08 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetCurrent(int *out) {
|
2021-10-10 07:14:06 +00:00
|
|
|
return powctl::GetBatteryCurrent(out, m_battery_session);
|
2020-11-08 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result GetTemperature(float *out) {
|
2021-10-10 07:14:06 +00:00
|
|
|
return powctl::GetBatteryTemperature(out, m_battery_session);
|
2020-11-08 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result IsI2cShutdownEnabled(bool *out) {
|
2021-10-10 07:14:06 +00:00
|
|
|
return powctl::IsBatteryI2cShutdownEnabled(out, m_battery_session);
|
2020-11-08 12:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Result SetI2cShutdownEnabled(bool en) {
|
2021-10-10 07:14:06 +00:00
|
|
|
return powctl::SetBatteryI2cShutdownEnabled(m_battery_session, en);
|
2020-11-08 12:16:50 +00:00
|
|
|
}
|
2019-06-22 07:10:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|