mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-06-22 19:32:39 +02:00
boot: refactor battery checking to use new powctl apis
This commit is contained in:
parent
d2b6c6c818
commit
f11884e0fe
@ -41,6 +41,7 @@
|
|||||||
/* At this point, just include the rest alphabetically. */
|
/* At this point, just include the rest alphabetically. */
|
||||||
/* TODO: Figure out optimal order. */
|
/* TODO: Figure out optimal order. */
|
||||||
#include <stratosphere/boot2.hpp>
|
#include <stratosphere/boot2.hpp>
|
||||||
|
#include <stratosphere/cal.hpp>
|
||||||
#include <stratosphere/capsrv.hpp>
|
#include <stratosphere/capsrv.hpp>
|
||||||
#include <stratosphere/cfg.hpp>
|
#include <stratosphere/cfg.hpp>
|
||||||
#include <stratosphere/clkrst.hpp>
|
#include <stratosphere/clkrst.hpp>
|
||||||
|
19
libstratosphere/include/stratosphere/cal.hpp
Normal file
19
libstratosphere/include/stratosphere/cal.hpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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/cal/cal_battery_api.hpp>
|
24
libstratosphere/include/stratosphere/cal/cal_battery_api.hpp
Normal file
24
libstratosphere/include/stratosphere/cal/cal_battery_api.hpp
Normal 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 <vapours.hpp>
|
||||||
|
|
||||||
|
namespace ams::cal {
|
||||||
|
|
||||||
|
Result GetBatteryVersion(u8 *out);
|
||||||
|
Result GetBatteryVendor(size_t *out_vendor_size, void *dst, size_t dst_size);
|
||||||
|
|
||||||
|
}
|
@ -20,4 +20,7 @@
|
|||||||
#include <stratosphere/powctl/powctl_session_api.hpp>
|
#include <stratosphere/powctl/powctl_session_api.hpp>
|
||||||
#include <stratosphere/powctl/powctl_battery_api.hpp>
|
#include <stratosphere/powctl/powctl_battery_api.hpp>
|
||||||
#include <stratosphere/powctl/powctl_charger_api.hpp>
|
#include <stratosphere/powctl/powctl_charger_api.hpp>
|
||||||
|
#include <stratosphere/powctl/impl/powctl_battery_charge_percentage.hpp>
|
||||||
#include <stratosphere/powctl/driver/powctl_driver_api.hpp>
|
#include <stratosphere/powctl/driver/powctl_driver_api.hpp>
|
||||||
|
#include <stratosphere/powctl/driver/impl/powctl_select_charger_parameters.hpp>
|
||||||
|
#include <stratosphere/powctl/driver/impl/powctl_charge_arbiter.hpp>
|
||||||
|
@ -0,0 +1,161 @@
|
|||||||
|
/*
|
||||||
|
* 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 <vapours.hpp>
|
||||||
|
#include <stratosphere/powctl/powctl_types.hpp>
|
||||||
|
#include <stratosphere/powctl/driver/impl/powctl_select_charger_parameters.hpp>
|
||||||
|
|
||||||
|
namespace ams::powctl::driver::impl {
|
||||||
|
|
||||||
|
class ChargeArbiter {
|
||||||
|
private:
|
||||||
|
const ChargeParametersRule *rules;
|
||||||
|
size_t num_rules;
|
||||||
|
int charge_voltage_limit;
|
||||||
|
BatteryTemperatureLevel temperature_level;
|
||||||
|
int avg_v_cell;
|
||||||
|
int open_circuit_voltage;
|
||||||
|
bool has_battery_done_current;
|
||||||
|
int battery_done_current;
|
||||||
|
PowerState power_state;
|
||||||
|
const ChargeParametersRule *selected_rule;
|
||||||
|
bool check_battery_done_current;
|
||||||
|
private:
|
||||||
|
static constexpr bool IsInRange(int value, int min, int max) {
|
||||||
|
if (!(min <= value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max == std::numeric_limits<int>::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) {
|
||||||
|
if (this->power_state == acceptable[i]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
ChargeArbiter(const ChargeParametersRule *r, size_t nr, int cvl)
|
||||||
|
: rules(r), num_rules(nr), charge_voltage_limit(cvl), temperature_level(BatteryTemperatureLevel::Medium),
|
||||||
|
avg_v_cell(4080), open_circuit_voltage(4001), has_battery_done_current(false), battery_done_current(0),
|
||||||
|
power_state(PowerState::FullAwake), selected_rule(nullptr), check_battery_done_current(false)
|
||||||
|
{
|
||||||
|
this->UpdateSelectedRule();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetBatteryTemperatureLevel(BatteryTemperatureLevel btl) {
|
||||||
|
this->temperature_level = btl;
|
||||||
|
this->UpdateSelectedRule();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetBatteryAverageVCell(int avg) {
|
||||||
|
this->avg_v_cell = avg;
|
||||||
|
this->UpdateSelectedRule();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetBatteryOpenCircuitVoltage(int ocv) {
|
||||||
|
this->open_circuit_voltage = ocv;
|
||||||
|
this->UpdateSelectedRule();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetBatteryDoneCurrent(int current) {
|
||||||
|
this->battery_done_current = current;
|
||||||
|
this->has_battery_done_current = true;
|
||||||
|
this->UpdateSelectedRule();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetPowerState(PowerState ps) {
|
||||||
|
this->power_state = ps;
|
||||||
|
this->UpdateSelectedRule();
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetChargeVoltageLimit() const {
|
||||||
|
return this->charge_voltage_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsBatteryDoneCurrentAcceptable(int current) const {
|
||||||
|
const auto *rule = this->GetSelectedRule();
|
||||||
|
AMS_ASSERT(rule != nullptr);
|
||||||
|
|
||||||
|
return IsInRange(0, rule->min_battery_done_current, rule->max_battery_done_current);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ChargeParametersRule *GetSelectedRule() const {
|
||||||
|
return this->selected_rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateSelectedRule() {
|
||||||
|
/* Try to find an entry that fits our current requirements. */
|
||||||
|
const ChargeParametersRule *best_rule = nullptr;
|
||||||
|
for (size_t i = 0; i < this->num_rules; ++i) {
|
||||||
|
/* Get the current rule. */
|
||||||
|
const ChargeParametersRule &cur_rule = this->rules[i];
|
||||||
|
|
||||||
|
/* Check the temperature level. */
|
||||||
|
if (this->temperature_level != cur_rule.temperature_level) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check that average voltage is in range. */
|
||||||
|
if (!IsInRange(this->avg_v_cell, cur_rule.min_avg_v_cell, cur_rule.max_avg_v_cell)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check that open circuit voltage is in range. */
|
||||||
|
if (!IsInRange(this->open_circuit_voltage, cur_rule.min_open_circuit_voltage, cur_rule.max_open_circuit_voltage)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if our power state is acceptable. */
|
||||||
|
if (!this->IsAcceptablePowerState(cur_rule.acceptable_power_states, cur_rule.num_acceptable_power_states)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The limit is probably acceptable. */
|
||||||
|
if (this->selected_rule != std::addressof(cur_rule)) {
|
||||||
|
/* We're selecting a new rule. Check if our need to deal with battery current is acceptable. */
|
||||||
|
if (cur_rule.check_battery_current && this->check_battery_done_current) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set whether we need to check the battery done current. */
|
||||||
|
this->has_battery_done_current = false;
|
||||||
|
this->check_battery_done_current |= cur_rule.check_battery_current;
|
||||||
|
} else {
|
||||||
|
/* We're selecting the currently selected rule. Make sure the battery done current is acceptable if we have one. */
|
||||||
|
if (this->has_battery_done_current && !IsInRange(this->battery_done_current, cur_rule.min_battery_done_current, cur_rule.max_battery_done_current)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Select the current rule. */
|
||||||
|
best_rule = std::addressof(cur_rule);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update our selected rule. */
|
||||||
|
this->selected_rule = best_rule;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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 <vapours.hpp>
|
||||||
|
#include <stratosphere/powctl/powctl_types.hpp>
|
||||||
|
|
||||||
|
namespace ams::powctl::driver::impl {
|
||||||
|
|
||||||
|
struct ChargeParametersRule {
|
||||||
|
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;
|
||||||
|
const PowerState *acceptable_power_states;
|
||||||
|
size_t num_acceptable_power_states;
|
||||||
|
bool check_battery_current;
|
||||||
|
bool reinitialize_charger;
|
||||||
|
int charge_voltage_limit;
|
||||||
|
int fast_charge_current_limit;
|
||||||
|
int battery_compensation;
|
||||||
|
int voltage_clamp;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UnknownParameterX {
|
||||||
|
int _00;
|
||||||
|
int _04;
|
||||||
|
double _08;
|
||||||
|
double _10;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ChargeParameters {
|
||||||
|
int temp_min;
|
||||||
|
int temp_low;
|
||||||
|
int temp_high;
|
||||||
|
int temp_max;
|
||||||
|
int low_voltage_fast_charge_current_limit;
|
||||||
|
int default_charge_voltage_limit;
|
||||||
|
const UnknownParameterX *unknown_x_table;
|
||||||
|
size_t x_table_size;
|
||||||
|
double _28;
|
||||||
|
double _30;
|
||||||
|
const ChargeParametersRule *rules;
|
||||||
|
size_t num_rules;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ChargeParameters &GetChargeParameters();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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 <vapours.hpp>
|
||||||
|
#include <stratosphere/powctl/powctl_types.hpp>
|
||||||
|
|
||||||
|
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
|
||||||
|
|
||||||
|
#include <stratosphere/powctl/driver/impl/powctl_charger_parameters.board.nintendo_nx.hpp>
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "unknown board for powctl::driver::impl::ChargerParameters"
|
||||||
|
#endif
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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 <vapours.hpp>
|
||||||
|
#include <stratosphere/powctl/powctl_types.hpp>
|
||||||
|
|
||||||
|
namespace ams::powctl::impl {
|
||||||
|
|
||||||
|
constexpr inline const double MinRawDefaultPercentage = 3.0;
|
||||||
|
constexpr inline const double MaxRawDefaultPercentage = 99.0;
|
||||||
|
|
||||||
|
constexpr inline const double MinRawThresholdPercentage = 11.0;
|
||||||
|
|
||||||
|
constexpr inline const int MinDisplayPercentage = 1;
|
||||||
|
constexpr inline const int MaxDisplayPercentage = 100;
|
||||||
|
|
||||||
|
constexpr inline void CalculateMarginatedRawPercentage(double *out_marginated_min, double *out_marginated_max, double min, double max) {
|
||||||
|
/* Ensure minimum is in correct range. */
|
||||||
|
min = std::max(std::min(min, MinRawThresholdPercentage), MinRawDefaultPercentage);
|
||||||
|
|
||||||
|
/* Calculate the marginated values. */
|
||||||
|
constexpr const double MinMarginPercentage = 0.93359375;
|
||||||
|
constexpr const double MaxMarginPercentage = -0.83593750;
|
||||||
|
|
||||||
|
const auto margin_factor = (max - min) / (MaxRawDefaultPercentage - MinRawDefaultPercentage);
|
||||||
|
*out_marginated_min = min + MinMarginPercentage * margin_factor;
|
||||||
|
*out_marginated_max = max + MaxMarginPercentage * margin_factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
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<double>(MaxDisplayPercentage - MinDisplayPercentage) * (raw_percentage - min)) / (max - min));
|
||||||
|
|
||||||
|
/* Clamp the display percentage within bounds. */
|
||||||
|
return std::max(std::min(static_cast<int>(display_percentage), MaxDisplayPercentage), MinDisplayPercentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr inline int ConvertBatteryChargePercentage(double raw_percentage, double min, double max) {
|
||||||
|
/* Marginate the min/max. */
|
||||||
|
double marginated_min = 0.0, marginated_max = 0.0;
|
||||||
|
CalculateMarginatedRawPercentage(std::addressof(marginated_min), std::addressof(marginated_max), min, max);
|
||||||
|
|
||||||
|
/* Convert to display percentage. */
|
||||||
|
return GetDisplayPercentage(raw_percentage, marginated_min, marginated_max);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr inline int ConvertBatteryChargePercentage(double raw_percentage) {
|
||||||
|
return ConvertBatteryChargePercentage(raw_percentage, MinRawDefaultPercentage, MaxRawDefaultPercentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -25,15 +25,15 @@ namespace ams::powctl {
|
|||||||
|
|
||||||
Result GetBatterySocVf(float *out_percent, Session &session);
|
Result GetBatterySocVf(float *out_percent, Session &session);
|
||||||
|
|
||||||
Result GetBatteryFullCapacity(u32 *out_mah, Session &session);
|
Result GetBatteryFullCapacity(int *out_mah, Session &session);
|
||||||
Result GetBatteryRemainingCapacity(u32 *out_mah, Session &session);
|
Result GetBatteryRemainingCapacity(int *out_mah, Session &session);
|
||||||
|
|
||||||
Result SetBatteryPercentageMinimumAlertThreshold(Session &session, float percentage);
|
Result SetBatteryPercentageMinimumAlertThreshold(Session &session, float percentage);
|
||||||
Result SetBatteryPercentageMaximumAlertThreshold(Session &session, float percentage);
|
Result SetBatteryPercentageMaximumAlertThreshold(Session &session, float percentage);
|
||||||
Result SetBatteryPercentageFullThreshold(Session &session, float percentage);
|
Result SetBatteryPercentageFullThreshold(Session &session, float percentage);
|
||||||
|
|
||||||
Result GetBatteryAverageCurrent(u32 *out_ma, Session &session);
|
Result GetBatteryAverageCurrent(int *out_ma, Session &session);
|
||||||
Result GetBatteryCurrent(u32 *out_ma, Session &session);
|
Result GetBatteryCurrent(int *out_ma, Session &session);
|
||||||
|
|
||||||
Result GetBatteryInternalState(void *dst, size_t *out_size, Session &session, size_t dst_size);
|
Result GetBatteryInternalState(void *dst, size_t *out_size, Session &session, size_t dst_size);
|
||||||
Result SetBatteryInternalState(Session &session, const void *src, size_t src_size);
|
Result SetBatteryInternalState(Session &session, const void *src, size_t src_size);
|
||||||
@ -44,10 +44,10 @@ namespace ams::powctl {
|
|||||||
Result IsBatteryI2cShutdownEnabled(bool *out, Session &session);
|
Result IsBatteryI2cShutdownEnabled(bool *out, Session &session);
|
||||||
Result SetBatteryI2cShutdownEnabled(Session &session, bool en);
|
Result SetBatteryI2cShutdownEnabled(Session &session, bool en);
|
||||||
|
|
||||||
Result IsBatteryRemoved(bool *out, Session &session);
|
Result IsBatteryPresent(bool *out, Session &session);
|
||||||
|
|
||||||
Result GetBatteryCycles(u32 *out, Session &session);
|
Result GetBatteryCycles(int *out, Session &session);
|
||||||
Result SetBatteryCycles(Session &session, u32 cycles);
|
Result SetBatteryCycles(Session &session, int cycles);
|
||||||
|
|
||||||
Result GetBatteryAge(float *out_percent, Session &session);
|
Result GetBatteryAge(float *out_percent, Session &session);
|
||||||
|
|
||||||
@ -57,14 +57,14 @@ namespace ams::powctl {
|
|||||||
Result SetBatteryTemperatureMinimumAlertThreshold(Session &session, float c);
|
Result SetBatteryTemperatureMinimumAlertThreshold(Session &session, float c);
|
||||||
Result SetBatteryTemperatureMaximumAlertThreshold(Session &session, float c);
|
Result SetBatteryTemperatureMaximumAlertThreshold(Session &session, float c);
|
||||||
|
|
||||||
Result GetBatteryVCell(u32 *out_mv, Session &session);
|
Result GetBatteryVCell(int *out_mv, Session &session);
|
||||||
Result GetBatteryAverageVCell(u32 *out_mv, Session &session);
|
Result GetBatteryAverageVCell(int *out_mv, Session &session);
|
||||||
|
|
||||||
Result GetBatteryAverageVCellTime(TimeSpan *out, Session &session);
|
Result GetBatteryAverageVCellTime(TimeSpan *out, Session &session);
|
||||||
|
|
||||||
Result GetBatteryOpenCircuitVoltage(u32 *out_mv, Session &session);
|
Result GetBatteryOpenCircuitVoltage(int *out_mv, Session &session);
|
||||||
|
|
||||||
Result SetBatteryVoltageMinimumAlertThreshold(Session &session, u32 mv);
|
Result SetBatteryVoltageMinimumAlertThreshold(Session &session, int mv);
|
||||||
Result SetBatteryVoltageMaximumAlertThreshold(Session &session, u32 mv);
|
Result SetBatteryVoltageMaximumAlertThreshold(Session &session, int mv);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,22 +24,22 @@ namespace ams::powctl {
|
|||||||
Result GetChargerChargeCurrentState(ChargeCurrentState *out, Session &session);
|
Result GetChargerChargeCurrentState(ChargeCurrentState *out, Session &session);
|
||||||
Result SetChargerChargeCurrentState(Session &session, ChargeCurrentState state);
|
Result SetChargerChargeCurrentState(Session &session, ChargeCurrentState state);
|
||||||
|
|
||||||
Result GetChargerFastChargeCurrentLimit(u32 *out_ma, Session &session);
|
Result GetChargerFastChargeCurrentLimit(int *out_ma, Session &session);
|
||||||
Result SetChargerFastChargeCurrentLimit(Session &session, u32 ma);
|
Result SetChargerFastChargeCurrentLimit(Session &session, int ma);
|
||||||
|
|
||||||
Result GetChargerChargeVoltageLimit(u32 *out_mv, Session &session);
|
Result GetChargerChargeVoltageLimit(int *out_mv, Session &session);
|
||||||
Result SetChargerChargeVoltageLimit(Session &session, u32 mv);
|
Result SetChargerChargeVoltageLimit(Session &session, int mv);
|
||||||
|
|
||||||
Result SetChargerChargerConfiguration(Session &session, ChargerConfiguration cfg);
|
Result SetChargerChargerConfiguration(Session &session, ChargerConfiguration cfg);
|
||||||
|
|
||||||
Result IsChargerHiZEnabled(bool *out, Session &session);
|
Result IsChargerHiZEnabled(bool *out, Session &session);
|
||||||
Result SetChargerHiZEnabled(Session &session, bool en);
|
Result SetChargerHiZEnabled(Session &session, bool en);
|
||||||
|
|
||||||
Result GetChargerInputCurrentLimit(u32 *out_ma, Session &session);
|
Result GetChargerInputCurrentLimit(int *out_ma, Session &session);
|
||||||
Result SetChargerInputCurrentLimit(Session &session, u32 ma);
|
Result SetChargerInputCurrentLimit(Session &session, int ma);
|
||||||
|
|
||||||
Result GetChargerInputVoltageLimit(u32 *out_mv, Session &session);
|
Result GetChargerInputVoltageLimit(int *out_mv, Session &session);
|
||||||
Result SetChargerInputVoltageLimit(Session &session, u32 mv);
|
Result SetChargerInputVoltageLimit(Session &session, int mv);
|
||||||
|
|
||||||
Result GetChargerChargerStatus(ChargerStatus *out, Session &session);
|
Result GetChargerChargerStatus(ChargerStatus *out, Session &session);
|
||||||
|
|
||||||
@ -49,10 +49,10 @@ namespace ams::powctl {
|
|||||||
Result SetChargerWatchdogTimerTimeout(Session &session, TimeSpan timeout);
|
Result SetChargerWatchdogTimerTimeout(Session &session, TimeSpan timeout);
|
||||||
Result ResetChargerWatchdogTimer(Session &session);
|
Result ResetChargerWatchdogTimer(Session &session);
|
||||||
|
|
||||||
Result GetChargerBatteryCompensation(u32 *out_mo, Session &session);
|
Result GetChargerBatteryCompensation(int *out_mo, Session &session);
|
||||||
Result SetChargerBatteryCompensation(Session &session, u32 mo);
|
Result SetChargerBatteryCompensation(Session &session, int mo);
|
||||||
|
|
||||||
Result GetChargerVoltageClamp(u32 *out_mv, Session &session);
|
Result GetChargerVoltageClamp(int *out_mv, Session &session);
|
||||||
Result SetChargerVoltageClamp(Session &session, u32 mv);
|
Result SetChargerVoltageClamp(Session &session, int mv);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@ namespace ams::powctl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum ChargerConfiguration {
|
enum ChargerConfiguration {
|
||||||
ChargerConfiguration_ChargeDisable = 0,
|
ChargerConfiguration_ChargeDisable = 1,
|
||||||
ChargerConfiguration_ChargeBattery = 1,
|
ChargerConfiguration_ChargeBattery = 2,
|
||||||
ChargerConfiguration_Otg = 2,
|
ChargerConfiguration_Otg = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ChargeCurrentState {
|
enum ChargeCurrentState {
|
||||||
@ -38,4 +38,20 @@ namespace ams::powctl {
|
|||||||
ChargeCurrentState_Charging = 0x3,
|
ChargeCurrentState_Charging = 0x3,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class BatteryTemperatureLevel {
|
||||||
|
TooLow = 0,
|
||||||
|
Low = 1,
|
||||||
|
Medium = 2,
|
||||||
|
High = 3,
|
||||||
|
TooHigh = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class PowerState {
|
||||||
|
FullAwake = 0,
|
||||||
|
MinimumAwake = 1,
|
||||||
|
SleepCharge = 2,
|
||||||
|
SleepDischarge = 3,
|
||||||
|
ShutdownChargeMain = 4,
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -150,6 +150,15 @@ namespace ams::spl {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
static_assert(sizeof(BootReasonValue) == sizeof(u32), "BootReasonValue definition!");
|
static_assert(sizeof(BootReasonValue) == sizeof(u32), "BootReasonValue definition!");
|
||||||
|
|
||||||
|
enum BootReason {
|
||||||
|
BootReason_Unknown = 0,
|
||||||
|
BootReason_AcOk = 1,
|
||||||
|
BootReason_OnKey = 2,
|
||||||
|
BootReason_RtcAlarm1 = 3,
|
||||||
|
BootReason_RtcAlarm2 = 4,
|
||||||
|
};
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
|
|
||||||
struct AesKey {
|
struct AesKey {
|
||||||
|
53
libstratosphere/source/cal/cal_battery_api.cpp
Normal file
53
libstratosphere/source/cal/cal_battery_api.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
libstratosphere/source/cal/cal_crc_utils.cpp
Normal file
53
libstratosphere/source/cal/cal_crc_utils.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
libstratosphere/source/cal/cal_crc_utils.hpp
Normal file
24
libstratosphere/source/cal/cal_crc_utils.hpp
Normal 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);
|
||||||
|
|
||||||
|
}
|
36
libstratosphere/source/cal/cal_fs_utils.cpp
Normal file
36
libstratosphere/source/cal/cal_fs_utils.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
23
libstratosphere/source/cal/cal_fs_utils.hpp
Normal file
23
libstratosphere/source/cal/cal_fs_utils.hpp
Normal 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);
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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)
|
||||||
|
};
|
@ -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;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
@ -55,8 +55,8 @@ namespace ams::powctl::impl {
|
|||||||
|
|
||||||
virtual Result GetBatterySocVf(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 GetBatteryFullCapacity(int *out_mah, IDevice *device) = 0;
|
||||||
virtual Result GetBatteryRemainingCapacity(u32 *out_mah, IDevice *device) = 0;
|
virtual Result GetBatteryRemainingCapacity(int *out_mah, IDevice *device) = 0;
|
||||||
|
|
||||||
virtual Result SetBatteryPercentageMinimumAlertThreshold(IDevice *device, float percentage) = 0;
|
virtual Result SetBatteryPercentageMinimumAlertThreshold(IDevice *device, float percentage) = 0;
|
||||||
virtual Result SetBatteryPercentageMaximumAlertThreshold(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 GetChargerChargeCurrentState(ChargeCurrentState *out, IDevice *device) = 0;
|
||||||
virtual Result SetChargerChargeCurrentState(IDevice *device, ChargeCurrentState state) = 0;
|
virtual Result SetChargerChargeCurrentState(IDevice *device, ChargeCurrentState state) = 0;
|
||||||
|
|
||||||
virtual Result GetChargerFastChargeCurrentLimit(u32 *out_ma, IDevice *device) = 0;
|
virtual Result GetChargerFastChargeCurrentLimit(int *out_ma, IDevice *device) = 0;
|
||||||
virtual Result SetChargerFastChargeCurrentLimit(IDevice *device, u32 ma) = 0;
|
virtual Result SetChargerFastChargeCurrentLimit(IDevice *device, int ma) = 0;
|
||||||
|
|
||||||
virtual Result GetChargerChargeVoltageLimit(u32 *out_mv, IDevice *device) = 0;
|
virtual Result GetChargerChargeVoltageLimit(int *out_mv, IDevice *device) = 0;
|
||||||
virtual Result SetChargerChargeVoltageLimit(IDevice *device, u32 mv) = 0;
|
virtual Result SetChargerChargeVoltageLimit(IDevice *device, int mv) = 0;
|
||||||
|
|
||||||
virtual Result SetChargerChargerConfiguration(IDevice *device, ChargerConfiguration cfg) = 0;
|
virtual Result SetChargerChargerConfiguration(IDevice *device, ChargerConfiguration cfg) = 0;
|
||||||
|
|
||||||
virtual Result IsChargerHiZEnabled(bool *out, IDevice *device) = 0;
|
virtual Result IsChargerHiZEnabled(bool *out, IDevice *device) = 0;
|
||||||
virtual Result SetChargerHiZEnabled(IDevice *device, bool en) = 0;
|
virtual Result SetChargerHiZEnabled(IDevice *device, bool en) = 0;
|
||||||
|
|
||||||
virtual Result GetBatteryAverageCurrent(u32 *out_ma, IDevice *device) = 0;
|
virtual Result GetBatteryAverageCurrent(int *out_ma, IDevice *device) = 0;
|
||||||
virtual Result GetBatteryCurrent(u32 *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 GetChargerInputCurrentLimit(int *out_ma, IDevice *device) = 0;
|
||||||
virtual Result SetChargerInputCurrentLimit(IDevice *device, u32 ma) = 0;
|
virtual Result SetChargerInputCurrentLimit(IDevice *device, int ma) = 0;
|
||||||
|
|
||||||
virtual Result GetChargerInputVoltageLimit(u32 *out_mv, IDevice *device) = 0;
|
virtual Result GetChargerInputVoltageLimit(int *out_mv, IDevice *device) = 0;
|
||||||
virtual Result SetChargerInputVoltageLimit(IDevice *device, u32 mv) = 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 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 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 IsBatteryI2cShutdownEnabled(bool *out, IDevice *device) = 0;
|
||||||
virtual Result SetBatteryI2cShutdownEnabled(IDevice *device, bool en) = 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 GetChargerChargerStatus(ChargerStatus *out, IDevice *device) = 0;
|
||||||
|
|
||||||
virtual Result GetBatteryCycles(u32 *out, IDevice *device) = 0;
|
virtual Result GetBatteryCycles(int *out, IDevice *device) = 0;
|
||||||
virtual Result SetBatteryCycles(IDevice *device, u32 cycles) = 0;
|
virtual Result SetBatteryCycles(IDevice *device, int cycles) = 0;
|
||||||
|
|
||||||
virtual Result GetBatteryAge(float *out_percent, IDevice *device) = 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 SetBatteryTemperatureMinimumAlertThreshold(IDevice *device, float c) = 0;
|
||||||
virtual Result SetBatteryTemperatureMaximumAlertThreshold(IDevice *device, float c) = 0;
|
virtual Result SetBatteryTemperatureMaximumAlertThreshold(IDevice *device, float c) = 0;
|
||||||
|
|
||||||
virtual Result GetBatteryVCell(u32 *out_mv, IDevice *device) = 0;
|
virtual Result GetBatteryVCell(int *out_mv, IDevice *device) = 0;
|
||||||
virtual Result GetBatteryAverageVCell(u32 *out_mv, IDevice *device) = 0;
|
virtual Result GetBatteryAverageVCell(int *out_mv, IDevice *device) = 0;
|
||||||
|
|
||||||
virtual Result GetBatteryAverageVCellTime(TimeSpan *out, 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 IsChargerWatchdogTimerEnabled(bool *out, IDevice *device) = 0;
|
||||||
virtual Result SetChargerWatchdogTimerEnabled(IDevice *device, bool en) = 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 SetChargerWatchdogTimerTimeout(IDevice *device, TimeSpan timeout) = 0;
|
||||||
virtual Result ResetChargerWatchdogTimer(IDevice *device) = 0;
|
virtual Result ResetChargerWatchdogTimer(IDevice *device) = 0;
|
||||||
|
|
||||||
virtual Result GetChargerBatteryCompensation(u32 *out_mo, IDevice *device) = 0;
|
virtual Result GetChargerBatteryCompensation(int *out_mo, IDevice *device) = 0;
|
||||||
virtual Result SetChargerBatteryCompensation(IDevice *device, u32 mo) = 0;
|
virtual Result SetChargerBatteryCompensation(IDevice *device, int mo) = 0;
|
||||||
|
|
||||||
virtual Result GetChargerVoltageClamp(u32 *out_mv, IDevice *device) = 0;
|
virtual Result GetChargerVoltageClamp(int *out_mv, IDevice *device) = 0;
|
||||||
virtual Result SetChargerVoltageClamp(IDevice *device, u32 mv) = 0;
|
virtual Result SetChargerVoltageClamp(IDevice *device, int mv) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatterySocVf(out_percent, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryFullCapacity(out_mah, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetBatteryPercentageFullThreshold(std::addressof(device), percentage);
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryAverageCurrent(out_ma, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetBatteryI2cShutdownEnabled(std::addressof(device), en);
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -251,10 +251,10 @@ namespace ams::powctl {
|
|||||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||||
|
|
||||||
/* Call into the driver. */
|
/* 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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryCycles(out, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -352,7 +352,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetBatteryTemperatureMaximumAlertThreshold(std::addressof(device), c);
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -366,7 +366,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryVCell(out_mv, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -394,7 +394,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryAverageVCellTime(out, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetBatteryOpenCircuitVoltage(out_mv, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -422,7 +422,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetBatteryVoltageMinimumAlertThreshold(std::addressof(device), mv);
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerChargeCurrentState(std::addressof(device), state);
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerFastChargeCurrentLimit(out_ma, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerFastChargeCurrentLimit(std::addressof(device), ma);
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerChargeVoltageLimit(out_mv, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerHiZEnabled(std::addressof(device), en);
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerInputCurrentLimit(out_ma, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerInputCurrentLimit(std::addressof(device), ma);
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerInputVoltageLimit(out_mv, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ namespace ams::powctl {
|
|||||||
|
|
||||||
Result ResetChargerWatchdogTimer(Session &session);
|
Result ResetChargerWatchdogTimer(Session &session);
|
||||||
|
|
||||||
Result GetChargerBatteryCompensation(u32 *out_mo, Session &session) {
|
Result GetChargerBatteryCompensation(int *out_mo, Session &session) {
|
||||||
/* Get the session impl. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerBatteryCompensation(out_mo, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerBatteryCompensation(std::addressof(device), mo);
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ namespace ams::powctl {
|
|||||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerVoltageClamp(out_mv, std::addressof(device));
|
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. */
|
/* Get the session impl. */
|
||||||
auto &impl = GetOpenSessionImpl(session);
|
auto &impl = GetOpenSessionImpl(session);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user