boot: refactor battery checking to use new powctl apis

This commit is contained in:
Michael Scire
2020-11-08 04:16:50 -08:00
parent cd7d7894f1
commit e93c3cbf58
44 changed files with 1426 additions and 1554 deletions

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* 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/>.
*/
#include <stratosphere.hpp>
#include "cal_fs_utils.hpp"
namespace ams::cal {
namespace {
constexpr inline s64 BatteryLotOffset = 0x2CE0;
constexpr inline size_t BatteryLotSize = 0x20;
constexpr inline s64 BatteryVersionOffset = 0x4310;
constexpr inline size_t BatteryVersionSize = 0x10;
constexpr inline size_t BatteryVendorSizeMax = 0x18;
}
Result GetBatteryVersion(u8 *out) {
/* Read the battery version. */
u8 battery_version[BatteryVersionSize];
R_TRY(cal::impl::ReadCalibrationBlock(BatteryVersionOffset, battery_version, sizeof(battery_version)));
/* Write the output. */
*out = battery_version[0];
return ResultSuccess();
}
Result GetBatteryVendor(size_t *out_vendor_size, void *dst, size_t dst_size) {
/* Read the battery lot. */
char battery_lot[BatteryLotSize];
R_TRY(cal::impl::ReadCalibrationBlock(BatteryLotOffset, battery_lot, sizeof(battery_lot)));
/* Copy output. */
*out_vendor_size = static_cast<size_t>(util::Strlcpy(static_cast<char *>(dst), battery_lot, std::min(dst_size, BatteryVendorSizeMax)));
return ResultSuccess();
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* 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/>.
*/
#include <stratosphere.hpp>
#include "cal_crc_utils.hpp"
namespace ams::cal::impl {
namespace {
constexpr inline const u16 CrcTable[0x10] = {
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
};
}
u16 CalculateCrc16(const void *data, size_t size) {
AMS_ASSERT(data != nullptr);
u16 crc = 0x55AA;
const u8 *data_u8 = static_cast<const u8 *>(data);
for (size_t i = 0; i < size; ++i) {
crc = (crc >> 4) ^ (CrcTable[crc & 0xF]) ^ (CrcTable[(data_u8[i] >> 0) & 0xF]);
crc = (crc >> 4) ^ (CrcTable[crc & 0xF]) ^ (CrcTable[(data_u8[i] >> 4) & 0xF]);
}
return crc;
}
Result ValidateCalibrationCrc(const void *data, size_t size) {
AMS_ASSERT(data != nullptr);
AMS_ASSERT(size >= sizeof(u16));
const u16 crc = *reinterpret_cast<const u16 *>(reinterpret_cast<uintptr_t>(data) + size - sizeof(u16));
R_UNLESS(CalculateCrc16(data, size - sizeof(u16)) == crc, cal::ResultCalibrationDataCrcError());
return ResultSuccess();
}
}

View File

@@ -0,0 +1,24 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* 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
#include <stratosphere.hpp>
namespace ams::cal::impl {
u16 CalculateCrc16(const void *data, size_t size);
Result ValidateCalibrationCrc(const void *data, size_t size);
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* 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/>.
*/
#include <stratosphere.hpp>
#include "cal_crc_utils.hpp"
#include "cal_fs_utils.hpp"
namespace ams::cal::impl {
Result ReadCalibrationBlock(s64 offset, void *dst, size_t block_size) {
/* Open the calibration binary partition. */
std::unique_ptr<fs::IStorage> storage;
R_TRY(fs::OpenBisPartition(std::addressof(storage), fs::BisPartitionId::CalibrationBinary));
/* Read data from the partition. */
R_TRY(storage->Read(offset, dst, block_size));
/* Validate the crc. */
R_TRY(ValidateCalibrationCrc(dst, block_size));
return ResultSuccess();
}
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* 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
#include <stratosphere.hpp>
namespace ams::cal::impl {
Result ReadCalibrationBlock(s64 offset, void *dst, size_t block_size);
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* 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/>.
*/
#include <stratosphere.hpp>
namespace ams::powctl::driver::impl {
namespace {
constexpr inline const PowerState AcceptablePowerStates[] = {
PowerState::FullAwake,
PowerState::MinimumAwake,
PowerState::SleepCharge,
PowerState::SleepDischarge,
PowerState::ShutdownChargeMain,
};
constexpr inline const PowerState AcceptablePowerStatesForNotAwakeCharge[] = {
PowerState::SleepCharge,
PowerState::ShutdownChargeMain,
};
constexpr inline const int Min = std::numeric_limits<int>::min();
constexpr inline const int Max = std::numeric_limits<int>::max();
constexpr inline const UnknownParameterX UnknownXTableForBatteryVersion2[] = {
{ 20000, 4320, 95.0, 100.4 },
{ 30000, 4304, 94.0, 99.7 },
{ 40000, 4288, 93.0, 98.4 },
{ 50000, 4272, 92.0, 97.0 },
{ 60000, 4256, 90.0, 95.7 },
{ 80000, 4240, 89.0, 94.2 },
{ 100000, 4224, 88.0, 93.0 },
{ Max, 4192, 85.0, 90.0 },
};
/* Include automatically extracted charger parameters. */
#include "powctl_charger_parameters.board.nintendo_nx.inc"
}
const ChargeParameters &GetChargeParameters() {
/* Get the battery version. */
u8 battery_version;
if (R_FAILED(cal::GetBatteryVersion(std::addressof(battery_version)))) {
battery_version = 0;
}
if (battery_version == 2) {
return ChargeParametersForBatteryVersion2;
} else if (battery_version == 1) {
return ChargeParametersForBatteryVersion1;
} else {
if (spl::GetHardwareType() == spl::HardwareType::_Five_) {
return ChargeParametersForBatteryVersion0ForFive;
} else {
return ChargeParametersForBatteryVersion0;
}
}
}
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* 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/>.
*/
/* 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 },
};
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 },
};
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 },
};
constexpr inline const ChargeParametersRule ChargeParametersRulesForBatteryVersion0ForFive[] = {
{ 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 },
};
constexpr inline const ChargeParameters ChargeParametersForBatteryVersion0 = {
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)
};
constexpr inline const ChargeParameters ChargeParametersForBatteryVersion2 = {
1, 19, 48, 59, 1664, 4320, UnknownXTableForBatteryVersion2, util::size(UnknownXTableForBatteryVersion2), 95.0, 100.4, ChargeParametersRulesForBatteryVersion2, util::size(ChargeParametersRulesForBatteryVersion2)
};
constexpr inline const ChargeParameters ChargeParametersForBatteryVersion0ForFive = {
4, 17, 51, 60, 512, 4208, nullptr, 0, 95.0, 99.0, ChargeParametersRulesForBatteryVersion0ForFive, util::size(ChargeParametersRulesForBatteryVersion0ForFive)
};

View File

@@ -1,136 +0,0 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* 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
#include <stratosphere.hpp>
namespace ams::powctl::impl {
class IDevice : public ::ams::ddsf::IDevice {
NON_COPYABLE(IDevice);
NON_MOVEABLE(IDevice);
AMS_DDSF_CASTABLE_TRAITS(ams::powctl::impl::IDevice, ::ams::ddsf::IDevice);
public:
IDevice() : ddsf::IDevice(false) { /* ... */ }
virtual ~IDevice() { /* ... */ }
};
class IPowerControlDriver : public ::ams::ddsf::IDriver {
NON_COPYABLE(IPowerControlDriver);
NON_MOVEABLE(IPowerControlDriver);
AMS_DDSF_CASTABLE_TRAITS(ams::powctl::impl::IPowerControlDriver, ::ams::ddsf::IDriver);
private:
bool event_handler_enabled;
protected:
constexpr bool IsEventHandlerEnabled() const {
return this->event_handler_enabled;
}
public:
IPowerControlDriver(bool ev) : IDriver(), event_handler_enabled(ev) { /* ... */ }
virtual ~IPowerControlDriver() { /* ... */ }
virtual void InitializeDriver() = 0;
virtual void FinalizeDriver() = 0;
virtual Result GetDeviceSystemEvent(IDevice *device) = 0;
virtual Result SetDeviceInterruptEnabled(IDevice *device, bool enable) = 0;
/* TODO: Eventually implement proper error status enum? */
virtual Result GetDeviceErrorStatus(u32 *out, IDevice *device) = 0;
virtual Result SetDeviceErrorStatus(IDevice *device, u32 status) = 0;
virtual Result GetBatterySocRep(float *out_percent, IDevice *device) = 0;
virtual Result GetBatterySocVf(float *out_percent, IDevice *device) = 0;
virtual Result GetBatteryFullCapacity(u32 *out_mah, IDevice *device) = 0;
virtual Result GetBatteryRemainingCapacity(u32 *out_mah, IDevice *device) = 0;
virtual Result SetBatteryPercentageMinimumAlertThreshold(IDevice *device, float percentage) = 0;
virtual Result SetBatteryPercentageMaximumAlertThreshold(IDevice *device, float percentage) = 0;
virtual Result SetBatteryPercentageFullThreshold(IDevice *device, float percentage) = 0;
virtual Result GetChargerChargeCurrentState(ChargeCurrentState *out, IDevice *device) = 0;
virtual Result SetChargerChargeCurrentState(IDevice *device, ChargeCurrentState state) = 0;
virtual Result GetChargerFastChargeCurrentLimit(u32 *out_ma, IDevice *device) = 0;
virtual Result SetChargerFastChargeCurrentLimit(IDevice *device, u32 ma) = 0;
virtual Result GetChargerChargeVoltageLimit(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerChargeVoltageLimit(IDevice *device, u32 mv) = 0;
virtual Result SetChargerChargerConfiguration(IDevice *device, ChargerConfiguration cfg) = 0;
virtual Result IsChargerHiZEnabled(bool *out, IDevice *device) = 0;
virtual Result SetChargerHiZEnabled(IDevice *device, bool en) = 0;
virtual Result GetBatteryAverageCurrent(u32 *out_ma, IDevice *device) = 0;
virtual Result GetBatteryCurrent(u32 *out_ma, IDevice *device) = 0;
virtual Result GetChargerInputCurrentLimit(u32 *out_ma, IDevice *device) = 0;
virtual Result SetChargerInputCurrentLimit(IDevice *device, u32 ma) = 0;
virtual Result GetChargerInputVoltageLimit(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerInputVoltageLimit(IDevice *device, u32 mv) = 0;
virtual Result GetBatteryInternalState(void *dst, size_t *out_size, IDevice *device, size_t dst_size) = 0;
virtual Result SetBatteryInternalState(IDevice *device, const void *src, size_t src_size) = 0;
virtual Result GetBatteryNeedToRestoreParameters(bool *out, IDevice *device) = 0;
virtual Result SetBatteryNeedToRestoreParameters(IDevice *device, bool en) = 0;
virtual Result IsBatteryI2cShutdownEnabled(bool *out, IDevice *device) = 0;
virtual Result SetBatteryI2cShutdownEnabled(IDevice *device, bool en) = 0;
virtual Result IsBatteryRemoved(bool *out, IDevice *device) = 0;
virtual Result GetChargerChargerStatus(ChargerStatus *out, IDevice *device) = 0;
virtual Result GetBatteryCycles(u32 *out, IDevice *device) = 0;
virtual Result SetBatteryCycles(IDevice *device, u32 cycles) = 0;
virtual Result GetBatteryAge(float *out_percent, IDevice *device) = 0;
virtual Result GetBatteryTemperature(float *out_c, IDevice *device) = 0;
virtual Result GetBatteryMaximumTemperature(float *out_c, IDevice *device) = 0;
virtual Result SetBatteryTemperatureMinimumAlertThreshold(IDevice *device, float c) = 0;
virtual Result SetBatteryTemperatureMaximumAlertThreshold(IDevice *device, float c) = 0;
virtual Result GetBatteryVCell(u32 *out_mv, IDevice *device) = 0;
virtual Result GetBatteryAverageVCell(u32 *out_mv, IDevice *device) = 0;
virtual Result GetBatteryAverageVCellTime(TimeSpan *out, IDevice *device) = 0;
virtual Result SetBatteryVoltageMinimumAlertThreshold(IDevice *device, u32 mv) = 0;
virtual Result GetBatteryOpenCircuitVoltage(u32 *out_mv, IDevice *device) = 0;
virtual Result SetBatteryVoltageMaximumAlertThreshold(IDevice *device, u32 mv) = 0;
virtual Result IsChargerWatchdogTimerEnabled(bool *out, IDevice *device) = 0;
virtual Result SetChargerWatchdogTimerEnabled(IDevice *device, bool en) = 0;
virtual Result SetChargerWatchdogTimerTimeout(IDevice *device, TimeSpan timeout) = 0;
virtual Result ResetChargerWatchdogTimer(IDevice *device) = 0;
virtual Result GetChargerBatteryCompensation(u32 *out_mo, IDevice *device) = 0;
virtual Result SetChargerBatteryCompensation(IDevice *device, u32 mo) = 0;
virtual Result GetChargerVoltageClamp(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerVoltageClamp(IDevice *device, u32 mv) = 0;
};
}

View File

@@ -55,8 +55,8 @@ namespace ams::powctl::impl {
virtual Result GetBatterySocVf(float *out_percent, IDevice *device) = 0;
virtual Result GetBatteryFullCapacity(u32 *out_mah, IDevice *device) = 0;
virtual Result GetBatteryRemainingCapacity(u32 *out_mah, IDevice *device) = 0;
virtual Result GetBatteryFullCapacity(int *out_mah, IDevice *device) = 0;
virtual Result GetBatteryRemainingCapacity(int *out_mah, IDevice *device) = 0;
virtual Result SetBatteryPercentageMinimumAlertThreshold(IDevice *device, float percentage) = 0;
virtual Result SetBatteryPercentageMaximumAlertThreshold(IDevice *device, float percentage) = 0;
@@ -65,25 +65,25 @@ namespace ams::powctl::impl {
virtual Result GetChargerChargeCurrentState(ChargeCurrentState *out, IDevice *device) = 0;
virtual Result SetChargerChargeCurrentState(IDevice *device, ChargeCurrentState state) = 0;
virtual Result GetChargerFastChargeCurrentLimit(u32 *out_ma, IDevice *device) = 0;
virtual Result SetChargerFastChargeCurrentLimit(IDevice *device, u32 ma) = 0;
virtual Result GetChargerFastChargeCurrentLimit(int *out_ma, IDevice *device) = 0;
virtual Result SetChargerFastChargeCurrentLimit(IDevice *device, int ma) = 0;
virtual Result GetChargerChargeVoltageLimit(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerChargeVoltageLimit(IDevice *device, u32 mv) = 0;
virtual Result GetChargerChargeVoltageLimit(int *out_mv, IDevice *device) = 0;
virtual Result SetChargerChargeVoltageLimit(IDevice *device, int mv) = 0;
virtual Result SetChargerChargerConfiguration(IDevice *device, ChargerConfiguration cfg) = 0;
virtual Result IsChargerHiZEnabled(bool *out, IDevice *device) = 0;
virtual Result SetChargerHiZEnabled(IDevice *device, bool en) = 0;
virtual Result GetBatteryAverageCurrent(u32 *out_ma, IDevice *device) = 0;
virtual Result GetBatteryCurrent(u32 *out_ma, IDevice *device) = 0;
virtual Result GetBatteryAverageCurrent(int *out_ma, IDevice *device) = 0;
virtual Result GetBatteryCurrent(int *out_ma, IDevice *device) = 0;
virtual Result GetChargerInputCurrentLimit(u32 *out_ma, IDevice *device) = 0;
virtual Result SetChargerInputCurrentLimit(IDevice *device, u32 ma) = 0;
virtual Result GetChargerInputCurrentLimit(int *out_ma, IDevice *device) = 0;
virtual Result SetChargerInputCurrentLimit(IDevice *device, int ma) = 0;
virtual Result GetChargerInputVoltageLimit(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerInputVoltageLimit(IDevice *device, u32 mv) = 0;
virtual Result GetChargerInputVoltageLimit(int *out_mv, IDevice *device) = 0;
virtual Result SetChargerInputVoltageLimit(IDevice *device, int mv) = 0;
virtual Result GetBatteryInternalState(void *dst, size_t *out_size, IDevice *device, size_t dst_size) = 0;
virtual Result SetBatteryInternalState(IDevice *device, const void *src, size_t src_size) = 0;
@@ -94,12 +94,12 @@ namespace ams::powctl::impl {
virtual Result IsBatteryI2cShutdownEnabled(bool *out, IDevice *device) = 0;
virtual Result SetBatteryI2cShutdownEnabled(IDevice *device, bool en) = 0;
virtual Result IsBatteryRemoved(bool *out, IDevice *device) = 0;
virtual Result IsBatteryPresent(bool *out, IDevice *device) = 0;
virtual Result GetChargerChargerStatus(ChargerStatus *out, IDevice *device) = 0;
virtual Result GetBatteryCycles(u32 *out, IDevice *device) = 0;
virtual Result SetBatteryCycles(IDevice *device, u32 cycles) = 0;
virtual Result GetBatteryCycles(int *out, IDevice *device) = 0;
virtual Result SetBatteryCycles(IDevice *device, int cycles) = 0;
virtual Result GetBatteryAge(float *out_percent, IDevice *device) = 0;
@@ -109,16 +109,16 @@ namespace ams::powctl::impl {
virtual Result SetBatteryTemperatureMinimumAlertThreshold(IDevice *device, float c) = 0;
virtual Result SetBatteryTemperatureMaximumAlertThreshold(IDevice *device, float c) = 0;
virtual Result GetBatteryVCell(u32 *out_mv, IDevice *device) = 0;
virtual Result GetBatteryAverageVCell(u32 *out_mv, IDevice *device) = 0;
virtual Result GetBatteryVCell(int *out_mv, IDevice *device) = 0;
virtual Result GetBatteryAverageVCell(int *out_mv, IDevice *device) = 0;
virtual Result GetBatteryAverageVCellTime(TimeSpan *out, IDevice *device) = 0;
virtual Result SetBatteryVoltageMinimumAlertThreshold(IDevice *device, u32 mv) = 0;
virtual Result SetBatteryVoltageMinimumAlertThreshold(IDevice *device, int mv) = 0;
virtual Result GetBatteryOpenCircuitVoltage(u32 *out_mv, IDevice *device) = 0;
virtual Result GetBatteryOpenCircuitVoltage(int *out_mv, IDevice *device) = 0;
virtual Result SetBatteryVoltageMaximumAlertThreshold(IDevice *device, u32 mv) = 0;
virtual Result SetBatteryVoltageMaximumAlertThreshold(IDevice *device, int mv) = 0;
virtual Result IsChargerWatchdogTimerEnabled(bool *out, IDevice *device) = 0;
virtual Result SetChargerWatchdogTimerEnabled(IDevice *device, bool en) = 0;
@@ -126,11 +126,11 @@ namespace ams::powctl::impl {
virtual Result SetChargerWatchdogTimerTimeout(IDevice *device, TimeSpan timeout) = 0;
virtual Result ResetChargerWatchdogTimer(IDevice *device) = 0;
virtual Result GetChargerBatteryCompensation(u32 *out_mo, IDevice *device) = 0;
virtual Result SetChargerBatteryCompensation(IDevice *device, u32 mo) = 0;
virtual Result GetChargerBatteryCompensation(int *out_mo, IDevice *device) = 0;
virtual Result SetChargerBatteryCompensation(IDevice *device, int mo) = 0;
virtual Result GetChargerVoltageClamp(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerVoltageClamp(IDevice *device, u32 mv) = 0;
virtual Result GetChargerVoltageClamp(int *out_mv, IDevice *device) = 0;
virtual Result SetChargerVoltageClamp(IDevice *device, int mv) = 0;
};
}

View File

@@ -58,7 +58,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatterySocVf(out_percent, std::addressof(device));
}
Result GetBatteryFullCapacity(u32 *out_mah, Session &session) {
Result GetBatteryFullCapacity(int *out_mah, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -72,7 +72,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryFullCapacity(out_mah, std::addressof(device));
}
Result GetBatteryRemainingCapacity(u32 *out_mah, Session &session) {
Result GetBatteryRemainingCapacity(int *out_mah, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -128,7 +128,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetBatteryPercentageFullThreshold(std::addressof(device), percentage);
}
Result GetBatteryAverageCurrent(u32 *out_ma, Session &session) {
Result GetBatteryAverageCurrent(int *out_ma, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -142,7 +142,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryAverageCurrent(out_ma, std::addressof(device));
}
Result GetBatteryCurrent(u32 *out_ma, Session &session) {
Result GetBatteryCurrent(int *out_ma, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -240,7 +240,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetBatteryI2cShutdownEnabled(std::addressof(device), en);
}
Result IsBatteryRemoved(bool *out, Session &session) {
Result IsBatteryPresent(bool *out, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -251,10 +251,10 @@ namespace ams::powctl {
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
/* Call into the driver. */
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().IsBatteryRemoved(out, std::addressof(device));
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().IsBatteryPresent(out, std::addressof(device));
}
Result GetBatteryCycles(u32 *out, Session &session) {
Result GetBatteryCycles(int *out, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -268,7 +268,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryCycles(out, std::addressof(device));
}
Result SetBatteryCycles(Session &session, u32 cycles) {
Result SetBatteryCycles(Session &session, int cycles) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -352,7 +352,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetBatteryTemperatureMaximumAlertThreshold(std::addressof(device), c);
}
Result GetBatteryVCell(u32 *out_mv, Session &session) {
Result GetBatteryVCell(int *out_mv, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -366,7 +366,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryVCell(out_mv, std::addressof(device));
}
Result GetBatteryAverageVCell(u32 *out_mv, Session &session) {
Result GetBatteryAverageVCell(int *out_mv, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -394,7 +394,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryAverageVCellTime(out, std::addressof(device));
}
Result GetBatteryOpenCircuitVoltage(u32 *out_mv, Session &session) {
Result GetBatteryOpenCircuitVoltage(int *out_mv, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -408,7 +408,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryOpenCircuitVoltage(out_mv, std::addressof(device));
}
Result SetBatteryVoltageMinimumAlertThreshold(Session &session, u32 mv) {
Result SetBatteryVoltageMinimumAlertThreshold(Session &session, int mv) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -422,7 +422,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetBatteryVoltageMinimumAlertThreshold(std::addressof(device), mv);
}
Result SetBatteryVoltageMaximumAlertThreshold(Session &session, u32 mv) {
Result SetBatteryVoltageMaximumAlertThreshold(Session &session, int mv) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);

View File

@@ -58,7 +58,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerChargeCurrentState(std::addressof(device), state);
}
Result GetChargerFastChargeCurrentLimit(u32 *out_ma, Session &session) {
Result GetChargerFastChargeCurrentLimit(int *out_ma, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -72,7 +72,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerFastChargeCurrentLimit(out_ma, std::addressof(device));
}
Result SetChargerFastChargeCurrentLimit(Session &session, u32 ma) {
Result SetChargerFastChargeCurrentLimit(Session &session, int ma) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -86,7 +86,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerFastChargeCurrentLimit(std::addressof(device), ma);
}
Result GetChargerChargeVoltageLimit(u32 *out_mv, Session &session) {
Result GetChargerChargeVoltageLimit(int *out_mv, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -100,7 +100,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerChargeVoltageLimit(out_mv, std::addressof(device));
}
Result SetChargerChargeVoltageLimit(Session &session, u32 mv) {
Result SetChargerChargeVoltageLimit(Session &session, int mv) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -156,7 +156,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerHiZEnabled(std::addressof(device), en);
}
Result GetChargerInputCurrentLimit(u32 *out_ma, Session &session) {
Result GetChargerInputCurrentLimit(int *out_ma, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -170,7 +170,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerInputCurrentLimit(out_ma, std::addressof(device));
}
Result SetChargerInputCurrentLimit(Session &session, u32 ma) {
Result SetChargerInputCurrentLimit(Session &session, int ma) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -184,7 +184,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerInputCurrentLimit(std::addressof(device), ma);
}
Result GetChargerInputVoltageLimit(u32 *out_mv, Session &session) {
Result GetChargerInputVoltageLimit(int *out_mv, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -198,7 +198,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerInputVoltageLimit(out_mv, std::addressof(device));
}
Result SetChargerInputVoltageLimit(Session &session, u32 mv) {
Result SetChargerInputVoltageLimit(Session &session, int mv) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -270,7 +270,7 @@ namespace ams::powctl {
Result ResetChargerWatchdogTimer(Session &session);
Result GetChargerBatteryCompensation(u32 *out_mo, Session &session) {
Result GetChargerBatteryCompensation(int *out_mo, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -284,7 +284,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerBatteryCompensation(out_mo, std::addressof(device));
}
Result SetChargerBatteryCompensation(Session &session, u32 mo) {
Result SetChargerBatteryCompensation(Session &session, int mo) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -298,7 +298,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerBatteryCompensation(std::addressof(device), mo);
}
Result GetChargerVoltageClamp(u32 *out_mv, Session &session) {
Result GetChargerVoltageClamp(int *out_mv, Session &session) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);
@@ -312,7 +312,7 @@ namespace ams::powctl {
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerVoltageClamp(out_mv, std::addressof(device));
}
Result SetChargerVoltageClamp(Session &session, u32 mv) {
Result SetChargerVoltageClamp(Session &session, int mv) {
/* Get the session impl. */
auto &impl = GetOpenSessionImpl(session);