powctl: implement client api (needs board-specific impl)

This commit is contained in:
Michael Scire
2020-11-02 18:13:36 -08:00
parent aa63b1eab7
commit cd7d7894f1
37 changed files with 1984 additions and 11 deletions

View File

@@ -0,0 +1,25 @@
/*
* 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 {
void Initialize(bool enable_interrupt_handlers);
void Finalize();
}

View File

@@ -0,0 +1,70 @@
/*
* 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/powctl_session_api.hpp>
namespace ams::powctl {
/* Battery API. */
Result GetBatterySocRep(float *out_percent, Session &session);
Result GetBatterySocVf(float *out_percent, Session &session);
Result GetBatteryFullCapacity(u32 *out_mah, Session &session);
Result GetBatteryRemainingCapacity(u32 *out_mah, Session &session);
Result SetBatteryPercentageMinimumAlertThreshold(Session &session, float percentage);
Result SetBatteryPercentageMaximumAlertThreshold(Session &session, float percentage);
Result SetBatteryPercentageFullThreshold(Session &session, float percentage);
Result GetBatteryAverageCurrent(u32 *out_ma, Session &session);
Result GetBatteryCurrent(u32 *out_ma, Session &session);
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 GetBatteryNeedToRestoreParameters(bool *out, Session &session);
Result SetBatteryNeedToRestoreParameters(Session &session, bool en);
Result IsBatteryI2cShutdownEnabled(bool *out, Session &session);
Result SetBatteryI2cShutdownEnabled(Session &session, bool en);
Result IsBatteryRemoved(bool *out, Session &session);
Result GetBatteryCycles(u32 *out, Session &session);
Result SetBatteryCycles(Session &session, u32 cycles);
Result GetBatteryAge(float *out_percent, Session &session);
Result GetBatteryTemperature(float *out_c, Session &session);
Result GetBatteryMaximumTemperature(float *out_c, Session &session);
Result SetBatteryTemperatureMinimumAlertThreshold(Session &session, float c);
Result SetBatteryTemperatureMaximumAlertThreshold(Session &session, float c);
Result GetBatteryVCell(u32 *out_mv, Session &session);
Result GetBatteryAverageVCell(u32 *out_mv, Session &session);
Result GetBatteryAverageVCellTime(TimeSpan *out, Session &session);
Result GetBatteryOpenCircuitVoltage(u32 *out_mv, Session &session);
Result SetBatteryVoltageMinimumAlertThreshold(Session &session, u32 mv);
Result SetBatteryVoltageMaximumAlertThreshold(Session &session, u32 mv);
}

View File

@@ -0,0 +1,58 @@
/*
* 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/powctl_session_api.hpp>
namespace ams::powctl {
/* Charger API. */
Result GetChargerChargeCurrentState(ChargeCurrentState *out, Session &session);
Result SetChargerChargeCurrentState(Session &session, ChargeCurrentState state);
Result GetChargerFastChargeCurrentLimit(u32 *out_ma, Session &session);
Result SetChargerFastChargeCurrentLimit(Session &session, u32 ma);
Result GetChargerChargeVoltageLimit(u32 *out_mv, Session &session);
Result SetChargerChargeVoltageLimit(Session &session, u32 mv);
Result SetChargerChargerConfiguration(Session &session, ChargerConfiguration cfg);
Result IsChargerHiZEnabled(bool *out, Session &session);
Result SetChargerHiZEnabled(Session &session, bool en);
Result GetChargerInputCurrentLimit(u32 *out_ma, Session &session);
Result SetChargerInputCurrentLimit(Session &session, u32 ma);
Result GetChargerInputVoltageLimit(u32 *out_mv, Session &session);
Result SetChargerInputVoltageLimit(Session &session, u32 mv);
Result GetChargerChargerStatus(ChargerStatus *out, Session &session);
Result IsChargerWatchdogTimerEnabled(bool *out, Session &session);
Result SetChargerWatchdogTimerEnabled(Session &session, bool en);
Result SetChargerWatchdogTimerTimeout(Session &session, TimeSpan timeout);
Result ResetChargerWatchdogTimer(Session &session);
Result GetChargerBatteryCompensation(u32 *out_mo, Session &session);
Result SetChargerBatteryCompensation(Session &session, u32 mo);
Result GetChargerVoltageClamp(u32 *out_mv, Session &session);
Result SetChargerVoltageClamp(Session &session, u32 mv);
}

View File

@@ -0,0 +1,29 @@
/*
* 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/i2c.hpp>
#include <stratosphere/powctl/powctl_types.hpp>
namespace ams::powctl {
/* Fuel Gauge. */
constexpr inline const DeviceCode DeviceCode_Max17050 = i2c::DeviceCode_Max17050;
/* Charger. */
constexpr inline const DeviceCode DeviceCode_Bq24193 = i2c::DeviceCode_Bq24193;
}

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 <vapours.hpp>
#include <stratosphere/powctl/powctl_types.hpp>
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
#include <stratosphere/powctl/powctl_devices.board.nintendo_nx.hpp>
#else
/* Error? */
#endif

View File

@@ -0,0 +1,46 @@
/*
* 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 {
namespace impl {
class SessionImpl : public ::ams::ddsf::ISession {
NON_COPYABLE(SessionImpl);
NON_MOVEABLE(SessionImpl);
AMS_DDSF_CASTABLE_TRAITS(ams::powctl::impl::SessionImpl, ::ams::ddsf::ISession);
public:
SessionImpl() : ISession() { /* ... */ }
~SessionImpl() { ddsf::CloseSession(this); }
};
}
struct Session {
bool has_session;
TYPED_STORAGE(impl::SessionImpl) impl_storage;
Session() : has_session(false) { /* ... */ }
};
Result OpenSession(Session *out, DeviceCode device_code, ddsf::AccessMode access_mode);
void CloseSession(Session &session);
}

View File

@@ -0,0 +1,41 @@
/*
* 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::powctl {
/* Charger types. */
enum ChargerStatus {
ChargerStatus_Charging = 1,
ChargerStatus_NotCharging = 3,
ChargerStatus_ChargeTerminationDone = 4,
};
enum ChargerConfiguration {
ChargerConfiguration_ChargeDisable = 0,
ChargerConfiguration_ChargeBattery = 1,
ChargerConfiguration_Otg = 2,
};
enum ChargeCurrentState {
ChargeCurrentState_NotCharging = 0x1,
ChargeCurrentState_ChargingForce20Percent = 0x2,
ChargeCurrentState_Charging = 0x3,
};
}