mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-03 08:08:39 -04:00
powctl: implement client api (needs board-specific impl)
This commit is contained in:
parent
3d31837ca1
commit
485304bd17
37 changed files with 1984 additions and 11 deletions
|
@ -63,6 +63,7 @@
|
|||
#include <stratosphere/patcher.hpp>
|
||||
#include <stratosphere/pcv.hpp>
|
||||
#include <stratosphere/pgl.hpp>
|
||||
#include <stratosphere/powctl.hpp>
|
||||
#include <stratosphere/psc.hpp>
|
||||
#include <stratosphere/pm.hpp>
|
||||
#include <stratosphere/pwm.hpp>
|
||||
|
|
|
@ -95,6 +95,9 @@ namespace ams::impl {
|
|||
/* bpc. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(4, bpc, IpcServer);
|
||||
|
||||
/* powctl. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(9, powctl, InterruptHandler);
|
||||
|
||||
/* hid. */
|
||||
AMS_DEFINE_SYSTEM_THREAD(-10, hid, IpcServer);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace ams::ddsf {
|
|||
#if defined(AMS_BUILD_FOR_DEBUGGING) || defined(AMS_BUILD_FOR_AUDITING)
|
||||
|
||||
#define AMS_DDSF_CASTABLE_TRAITS(__CLASS__, __BASE__) \
|
||||
static_assert(std::convertible_to<__CLASS__ *, __BASE__ *>); \
|
||||
public: \
|
||||
static constexpr inline ::ams::ddsf::impl::TypeTag s_ams_ddsf_castable_type_tag{#__CLASS__, __BASE__::s_ams_ddsf_castable_type_tag}; \
|
||||
constexpr virtual const ::ams::ddsf::impl::TypeTag &GetTypeTag() const override { return s_ams_ddsf_castable_type_tag; }
|
||||
|
@ -30,6 +31,7 @@ namespace ams::ddsf {
|
|||
#else
|
||||
|
||||
#define AMS_DDSF_CASTABLE_TRAITS(__CLASS__, __BASE__) \
|
||||
static_assert(std::convertible_to<__CLASS__ *, __BASE__ *>); \
|
||||
public: \
|
||||
static constexpr inline ::ams::ddsf::impl::TypeTag s_ams_ddsf_castable_type_tag{__BASE__::s_ams_ddsf_castable_type_tag}; \
|
||||
constexpr virtual const ::ams::ddsf::impl::TypeTag &GetTypeTag() const override { return s_ams_ddsf_castable_type_tag; }
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace ams::gpio::driver {
|
|||
class IGpioDriver : public ::ams::ddsf::IDriver {
|
||||
NON_COPYABLE(IGpioDriver);
|
||||
NON_MOVEABLE(IGpioDriver);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::gpio::IGpioDriver, ::ams::ddsf::IDriver);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::gpio::driver::IGpioDriver, ::ams::ddsf::IDriver);
|
||||
public:
|
||||
IGpioDriver() : IDriver() { /* ... */ }
|
||||
virtual ~IGpioDriver() { /* ... */ }
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace ams::i2c::driver {
|
|||
class I2cDeviceProperty : public ::ams::ddsf::IDevice {
|
||||
NON_COPYABLE(I2cDeviceProperty);
|
||||
NON_MOVEABLE(I2cDeviceProperty);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::i2c::I2cDeviceProperty, ::ams::ddsf::IDevice);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::i2c::driver::I2cDeviceProperty, ::ams::ddsf::IDevice);
|
||||
private:
|
||||
u16 address;
|
||||
AddressingMode addressing_mode;
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace ams::i2c::driver {
|
|||
class II2cDriver : public ::ams::ddsf::IDriver {
|
||||
NON_COPYABLE(II2cDriver);
|
||||
NON_MOVEABLE(II2cDriver);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::i2c::II2cDriver, ::ams::ddsf::IDriver);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::i2c::driver::II2cDriver, ::ams::ddsf::IDriver);
|
||||
public:
|
||||
II2cDriver() : IDriver() { /* ... */ }
|
||||
virtual ~II2cDriver() { /* ... */ }
|
||||
|
|
23
libraries/libstratosphere/include/stratosphere/powctl.hpp
Normal file
23
libraries/libstratosphere/include/stratosphere/powctl.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/powctl/powctl_types.hpp>
|
||||
#include <stratosphere/powctl/powctl_select_devices.hpp>
|
||||
#include <stratosphere/powctl/powctl_session_api.hpp>
|
||||
#include <stratosphere/powctl/powctl_battery_api.hpp>
|
||||
#include <stratosphere/powctl/powctl_charger_api.hpp>
|
||||
#include <stratosphere/powctl/driver/powctl_driver_api.hpp>
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
}
|
|
@ -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
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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,
|
||||
};
|
||||
|
||||
}
|
|
@ -23,7 +23,7 @@ namespace ams::pwm::driver {
|
|||
class IPwmDevice : public ::ams::ddsf::IDevice {
|
||||
NON_COPYABLE(IPwmDevice);
|
||||
NON_MOVEABLE(IPwmDevice);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::pwm::IPwmDevice, ::ams::ddsf::IDriver);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::pwm::driver::IPwmDevice, ::ams::ddsf::IDevice);
|
||||
private:
|
||||
int channel_index;
|
||||
public:
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace ams::pwm::driver {
|
|||
class IPwmDriver : public ::ams::ddsf::IDriver {
|
||||
NON_COPYABLE(IPwmDriver);
|
||||
NON_MOVEABLE(IPwmDriver);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::pwm::IPwmDriver, ::ams::ddsf::IDriver);
|
||||
AMS_DDSF_CASTABLE_TRAITS(ams::pwm::driver::IPwmDriver, ::ams::ddsf::IDriver);
|
||||
public:
|
||||
IPwmDriver() : IDriver() { /* ... */ }
|
||||
virtual ~IPwmDriver() { /* ... */ }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue