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,31 @@
/*
* 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 "powctl_board_impl.hpp"
namespace ams::powctl::impl::board::nintendo_nx {
void Initialize(bool use_event_handlers) {
/* TODO */
AMS_ABORT();
}
void Finalize() {
/* TODO */
AMS_ABORT();
}
}

View File

@@ -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 <stratosphere.hpp>
#include "powctl_interrupt_event_handler.hpp"
namespace ams::powctl::impl::board::nintendo_nx {
void Initialize(bool use_event_handlers);
void Finalize();
}

View File

@@ -0,0 +1,31 @@
/*
* 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 "powctl_interrupt_event_handler.hpp"
namespace ams::powctl::impl::board::nintendo_nx {
void ChargerInterruptEventHandler::SignalEvent(IDevice *device) {
/* TODO */
AMS_ABORT();
}
void BatteryInterruptEventHandler::SignalEvent(IDevice *device) {
/* TODO */
AMS_ABORT();
}
}

View File

@@ -0,0 +1,94 @@
/*
* 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>
#include "../../powctl_i_power_control_driver.hpp"
namespace ams::powctl::impl::board::nintendo_nx {
template<typename Derived>
class InterruptEventHandler : public ddsf::IEventHandler {
private:
IDevice *device;
gpio::GpioPadSession gpio_session;
os::SystemEventType gpio_system_event;
os::SdkMutex mutex;
public:
InterruptEventHandler(IDevice *dv) : IEventHandler(), device(dv), mutex() {
/* Initialize the gpio session. */
Derived::Initialize(std::addressof(this->gpio_session), std::addressof(this->gpio_system_event));
/* Initialize ourselves as an event handler. */
IEventHandler::Initialize(std::addressof(this->gpio_system_event));
}
os::SystemEventType *GetSystemEvent() {
return std::addressof(this->gpio_system_event);
}
virtual void HandleEvent() override final {
/* Acquire exclusive access to ourselves. */
std::scoped_lock lk(this->mutex);
/* Clear our interrupt status. */
gpio::ClearInterruptStatus(std::addressof(this->gpio_session));
/* Clear our system event. */
os::ClearSystemEvent(std::addressof(this->gpio_system_event));
/* Signal the event. */
Derived::SignalEvent(this->device);
}
};
class ChargerInterruptEventHandler : public InterruptEventHandler<ChargerInterruptEventHandler> {
friend class InterruptEventHandler<ChargerInterruptEventHandler>;
private:
static void Initialize(gpio::GpioPadSession *session, os::SystemEventType *event) {
/* Open the gpio session. */
R_ABORT_UNLESS(gpio::OpenSession(session, gpio::DeviceCode_Bq24190Irq));
/* Configure the gpio session. */
gpio::SetDirection(session, gpio::Direction_Input);
gpio::SetInterruptMode(session, gpio::InterruptMode_FallingEdge);
gpio::SetInterruptEnable(session, true);
/* Bind the interrupt event. */
R_ABORT_UNLESS(gpio::BindInterrupt(event, session));
}
void SignalEvent(IDevice *device);
};
class BatteryInterruptEventHandler : public InterruptEventHandler<BatteryInterruptEventHandler> {
friend class InterruptEventHandler<BatteryInterruptEventHandler>;
private:
static void Initialize(gpio::GpioPadSession *session, os::SystemEventType *event) {
/* Open the gpio session. */
R_ABORT_UNLESS(gpio::OpenSession(session, gpio::DeviceCode_BattMgicIrq));
/* Configure the gpio session. */
gpio::SetDirection(session, gpio::Direction_Input);
gpio::SetInterruptMode(session, gpio::InterruptMode_LowLevel);
/* Bind the interrupt event. */
R_ABORT_UNLESS(gpio::BindInterrupt(event, session));
}
void SignalEvent(IDevice *device);
};
}

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 <stratosphere.hpp>
namespace ams::powctl::impl {
constexpr inline const TimeSpan PowerControlRetryTimeout = TimeSpan::FromSeconds(10);
constexpr inline const TimeSpan PowerControlRetryInterval = TimeSpan::FromMilliSeconds(20);
#define AMS_POWCTL_R_TRY_WITH_RETRY(__EXPR__) \
({ \
TimeSpan __powctl_retry_current_time = 0; \
while (true) { \
const Result __powctl_retry_result = (__EXPR__); \
if (R_SUCCEEDED(__powctl_retry_result)) { \
break; \
} \
\
__powctl_retry_current_time += PowerControlRetryInterval; \
R_UNLESS(__powctl_retry_current_time < PowerControlRetryTimeout, __powctl_retry_result); \
\
os::SleepThread(PowerControlRetryInterval); \
} \
})
}

View File

@@ -0,0 +1,136 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
namespace ams::powctl::impl {
class IDevice : public ::ams::ddsf::IDevice {
NON_COPYABLE(IDevice);
NON_MOVEABLE(IDevice);
AMS_DDSF_CASTABLE_TRAITS(ams::powctl::impl::IDevice, ::ams::ddsf::IDevice);
public:
IDevice() : ddsf::IDevice(false) { /* ... */ }
virtual ~IDevice() { /* ... */ }
};
class IPowerControlDriver : public ::ams::ddsf::IDriver {
NON_COPYABLE(IPowerControlDriver);
NON_MOVEABLE(IPowerControlDriver);
AMS_DDSF_CASTABLE_TRAITS(ams::powctl::impl::IPowerControlDriver, ::ams::ddsf::IDriver);
private:
bool event_handler_enabled;
protected:
constexpr bool IsEventHandlerEnabled() const {
return this->event_handler_enabled;
}
public:
IPowerControlDriver(bool ev) : IDriver(), event_handler_enabled(ev) { /* ... */ }
virtual ~IPowerControlDriver() { /* ... */ }
virtual void InitializeDriver() = 0;
virtual void FinalizeDriver() = 0;
virtual Result GetDeviceSystemEvent(IDevice *device) = 0;
virtual Result SetDeviceInterruptEnabled(IDevice *device, bool enable) = 0;
/* TODO: Eventually implement proper error status enum? */
virtual Result GetDeviceErrorStatus(u32 *out, IDevice *device) = 0;
virtual Result SetDeviceErrorStatus(IDevice *device, u32 status) = 0;
virtual Result GetBatterySocRep(float *out_percent, IDevice *device) = 0;
virtual Result GetBatterySocVf(float *out_percent, IDevice *device) = 0;
virtual Result GetBatteryFullCapacity(u32 *out_mah, IDevice *device) = 0;
virtual Result GetBatteryRemainingCapacity(u32 *out_mah, IDevice *device) = 0;
virtual Result SetBatteryPercentageMinimumAlertThreshold(IDevice *device, float percentage) = 0;
virtual Result SetBatteryPercentageMaximumAlertThreshold(IDevice *device, float percentage) = 0;
virtual Result SetBatteryPercentageFullThreshold(IDevice *device, float percentage) = 0;
virtual Result GetChargerChargeCurrentState(ChargeCurrentState *out, IDevice *device) = 0;
virtual Result SetChargerChargeCurrentState(IDevice *device, ChargeCurrentState state) = 0;
virtual Result GetChargerFastChargeCurrentLimit(u32 *out_ma, IDevice *device) = 0;
virtual Result SetChargerFastChargeCurrentLimit(IDevice *device, u32 ma) = 0;
virtual Result GetChargerChargeVoltageLimit(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerChargeVoltageLimit(IDevice *device, u32 mv) = 0;
virtual Result SetChargerChargerConfiguration(IDevice *device, ChargerConfiguration cfg) = 0;
virtual Result IsChargerHiZEnabled(bool *out, IDevice *device) = 0;
virtual Result SetChargerHiZEnabled(IDevice *device, bool en) = 0;
virtual Result GetBatteryAverageCurrent(u32 *out_ma, IDevice *device) = 0;
virtual Result GetBatteryCurrent(u32 *out_ma, IDevice *device) = 0;
virtual Result GetChargerInputCurrentLimit(u32 *out_ma, IDevice *device) = 0;
virtual Result SetChargerInputCurrentLimit(IDevice *device, u32 ma) = 0;
virtual Result GetChargerInputVoltageLimit(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerInputVoltageLimit(IDevice *device, u32 mv) = 0;
virtual Result GetBatteryInternalState(void *dst, size_t *out_size, IDevice *device, size_t dst_size) = 0;
virtual Result SetBatteryInternalState(IDevice *device, const void *src, size_t src_size) = 0;
virtual Result GetBatteryNeedToRestoreParameters(bool *out, IDevice *device) = 0;
virtual Result SetBatteryNeedToRestoreParameters(IDevice *device, bool en) = 0;
virtual Result IsBatteryI2cShutdownEnabled(bool *out, IDevice *device) = 0;
virtual Result SetBatteryI2cShutdownEnabled(IDevice *device, bool en) = 0;
virtual Result IsBatteryRemoved(bool *out, IDevice *device) = 0;
virtual Result GetChargerChargerStatus(ChargerStatus *out, IDevice *device) = 0;
virtual Result GetBatteryCycles(u32 *out, IDevice *device) = 0;
virtual Result SetBatteryCycles(IDevice *device, u32 cycles) = 0;
virtual Result GetBatteryAge(float *out_percent, IDevice *device) = 0;
virtual Result GetBatteryTemperature(float *out_c, IDevice *device) = 0;
virtual Result GetBatteryMaximumTemperature(float *out_c, IDevice *device) = 0;
virtual Result SetBatteryTemperatureMinimumAlertThreshold(IDevice *device, float c) = 0;
virtual Result SetBatteryTemperatureMaximumAlertThreshold(IDevice *device, float c) = 0;
virtual Result GetBatteryVCell(u32 *out_mv, IDevice *device) = 0;
virtual Result GetBatteryAverageVCell(u32 *out_mv, IDevice *device) = 0;
virtual Result GetBatteryAverageVCellTime(TimeSpan *out, IDevice *device) = 0;
virtual Result SetBatteryVoltageMinimumAlertThreshold(IDevice *device, u32 mv) = 0;
virtual Result GetBatteryOpenCircuitVoltage(u32 *out_mv, IDevice *device) = 0;
virtual Result SetBatteryVoltageMaximumAlertThreshold(IDevice *device, u32 mv) = 0;
virtual Result IsChargerWatchdogTimerEnabled(bool *out, IDevice *device) = 0;
virtual Result SetChargerWatchdogTimerEnabled(IDevice *device, bool en) = 0;
virtual Result SetChargerWatchdogTimerTimeout(IDevice *device, TimeSpan timeout) = 0;
virtual Result ResetChargerWatchdogTimer(IDevice *device) = 0;
virtual Result GetChargerBatteryCompensation(u32 *out_mo, IDevice *device) = 0;
virtual Result SetChargerBatteryCompensation(IDevice *device, u32 mo) = 0;
virtual Result GetChargerVoltageClamp(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerVoltageClamp(IDevice *device, u32 mv) = 0;
};
}

View File

@@ -0,0 +1,138 @@
/*
* 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 "powctl_device_management.hpp"
namespace ams::powctl::impl {
namespace {
os::ThreadType g_interrupt_thread;
constexpr inline size_t InterruptThreadStackSize = os::MemoryPageSize;
alignas(os::MemoryPageSize) u8 g_interrupt_thread_stack[InterruptThreadStackSize];
constinit u8 g_unit_heap_memory[2_KB];
constinit lmem::HeapHandle g_unit_heap_handle;
constinit sf::UnitHeapMemoryResource g_unit_heap_memory_resource;
IPowerControlDriver::List &GetDriverList() {
static IPowerControlDriver::List s_driver_list;
return s_driver_list;
}
ddsf::EventHandlerManager &GetInterruptHandlerManager() {
static ddsf::EventHandlerManager s_interrupt_handler_manager;
return s_interrupt_handler_manager;
}
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
static ddsf::DeviceCodeEntryManager s_device_code_entry_manager = [] {
/* Initialize the entry code heap. */
g_unit_heap_handle = lmem::CreateUnitHeap(g_unit_heap_memory, sizeof(g_unit_heap_memory), sizeof(ddsf::DeviceCodeEntryHolder), lmem::CreateOption_ThreadSafe);
/* Initialize the entry code memory resource. */
g_unit_heap_memory_resource.Attach(g_unit_heap_handle);
/* Make the entry manager using the newly initialized memory resource. */
return ddsf::DeviceCodeEntryManager(std::addressof(g_unit_heap_memory_resource));
}();
return s_device_code_entry_manager;
}
void InterruptThreadFunction(void *arg) {
AMS_UNUSED(arg);
GetInterruptHandlerManager().LoopAuto();
}
}
void InitializeDrivers() {
/* Ensure the event handler manager is initialized. */
GetInterruptHandlerManager().Initialize();
/* Initialize all registered drivers. */
for (auto &driver : GetDriverList()) {
driver.SafeCastTo<IPowerControlDriver>().InitializeDriver();
}
/* Create the interrupt thread. */
R_ABORT_UNLESS(os::CreateThread(std::addressof(g_interrupt_thread), InterruptThreadFunction, nullptr, g_interrupt_thread_stack, InterruptThreadStackSize, AMS_GET_SYSTEM_THREAD_PRIORITY(powctl, InterruptHandler)));
os::SetThreadNamePointer(std::addressof(g_interrupt_thread), AMS_GET_SYSTEM_THREAD_NAME(powctl, InterruptHandler));
os::StartThread(std::addressof(g_interrupt_thread));
/* Wait for the interrupt thread to enter the loop. */
GetInterruptHandlerManager().WaitLoopEnter();
}
void FinalizeDrivers() {
/* Request the interrupt thread stop. */
GetInterruptHandlerManager().RequestStop();
os::WaitThread(std::addressof(g_interrupt_thread));
os::DestroyThread(std::addressof(g_interrupt_thread));
/* TODO: What else? */
AMS_ABORT();
}
void RegisterDriver(IPowerControlDriver *driver) {
AMS_ASSERT(driver != nullptr);
GetDriverList().push_back(*driver);
}
void UnregisterDriver(IPowerControlDriver *driver) {
AMS_ASSERT(driver != nullptr);
if (driver->IsLinkedToList()) {
auto &list = GetDriverList();
list.erase(list.iterator_to(*driver));
}
}
Result RegisterDeviceCode(DeviceCode device_code, IDevice *device) {
AMS_ASSERT(device != nullptr);
R_TRY(GetDeviceCodeEntryManager().Add(device_code, device));
return ResultSuccess();
}
bool UnregisterDeviceCode(DeviceCode device_code) {
return GetDeviceCodeEntryManager().Remove(device_code);
}
void RegisterInterruptHandler(ddsf::IEventHandler *handler) {
AMS_ASSERT(handler != nullptr);
GetInterruptHandlerManager().RegisterHandler(handler);
}
void UnregisterInterruptHandler(ddsf::IEventHandler *handler) {
AMS_ASSERT(handler != nullptr);
GetInterruptHandlerManager().UnregisterHandler(handler);
}
Result FindDevice(powctl::impl::IDevice **out, DeviceCode device_code) {
/* Validate output. */
AMS_ASSERT(out != nullptr);
/* Find the device. */
ddsf::IDevice *device;
R_TRY(GetDeviceCodeEntryManager().FindDevice(std::addressof(device), device_code));
/* Set output. */
*out = device->SafeCastToPointer<powctl::impl::IDevice>();
return ResultSuccess();
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
#include "powctl_i_power_control_driver.hpp"
namespace ams::powctl::impl {
void InitializeDrivers();
void FinalizeDrivers();
void RegisterDriver(IPowerControlDriver *driver);
void UnregisterDriver(IPowerControlDriver *driver);
Result RegisterDeviceCode(DeviceCode device_code, IDevice *device);
bool UnregisterDeviceCode(DeviceCode device_code);
void RegisterInterruptHandler(ddsf::IEventHandler *handler);
void UnregisterInterruptHandler(ddsf::IEventHandler *handler);
Result FindDevice(IDevice **out, DeviceCode device_code);
}

View File

@@ -0,0 +1,136 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
namespace ams::powctl::impl {
class IDevice : public ::ams::ddsf::IDevice {
NON_COPYABLE(IDevice);
NON_MOVEABLE(IDevice);
AMS_DDSF_CASTABLE_TRAITS(ams::powctl::impl::IDevice, ::ams::ddsf::IDevice);
public:
IDevice() : ddsf::IDevice(false) { /* ... */ }
virtual ~IDevice() { /* ... */ }
};
class IPowerControlDriver : public ::ams::ddsf::IDriver {
NON_COPYABLE(IPowerControlDriver);
NON_MOVEABLE(IPowerControlDriver);
AMS_DDSF_CASTABLE_TRAITS(ams::powctl::impl::IPowerControlDriver, ::ams::ddsf::IDriver);
private:
bool event_handler_enabled;
protected:
constexpr bool IsEventHandlerEnabled() const {
return this->event_handler_enabled;
}
public:
IPowerControlDriver(bool ev) : IDriver(), event_handler_enabled(ev) { /* ... */ }
virtual ~IPowerControlDriver() { /* ... */ }
virtual void InitializeDriver() = 0;
virtual void FinalizeDriver() = 0;
virtual Result GetDeviceSystemEvent(IDevice *device) = 0;
virtual Result SetDeviceInterruptEnabled(IDevice *device, bool enable) = 0;
/* TODO: Eventually implement proper error status enum? */
virtual Result GetDeviceErrorStatus(u32 *out, IDevice *device) = 0;
virtual Result SetDeviceErrorStatus(IDevice *device, u32 status) = 0;
virtual Result GetBatterySocRep(float *out_percent, IDevice *device) = 0;
virtual Result GetBatterySocVf(float *out_percent, IDevice *device) = 0;
virtual Result GetBatteryFullCapacity(u32 *out_mah, IDevice *device) = 0;
virtual Result GetBatteryRemainingCapacity(u32 *out_mah, IDevice *device) = 0;
virtual Result SetBatteryPercentageMinimumAlertThreshold(IDevice *device, float percentage) = 0;
virtual Result SetBatteryPercentageMaximumAlertThreshold(IDevice *device, float percentage) = 0;
virtual Result SetBatteryPercentageFullThreshold(IDevice *device, float percentage) = 0;
virtual Result GetChargerChargeCurrentState(ChargeCurrentState *out, IDevice *device) = 0;
virtual Result SetChargerChargeCurrentState(IDevice *device, ChargeCurrentState state) = 0;
virtual Result GetChargerFastChargeCurrentLimit(u32 *out_ma, IDevice *device) = 0;
virtual Result SetChargerFastChargeCurrentLimit(IDevice *device, u32 ma) = 0;
virtual Result GetChargerChargeVoltageLimit(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerChargeVoltageLimit(IDevice *device, u32 mv) = 0;
virtual Result SetChargerChargerConfiguration(IDevice *device, ChargerConfiguration cfg) = 0;
virtual Result IsChargerHiZEnabled(bool *out, IDevice *device) = 0;
virtual Result SetChargerHiZEnabled(IDevice *device, bool en) = 0;
virtual Result GetBatteryAverageCurrent(u32 *out_ma, IDevice *device) = 0;
virtual Result GetBatteryCurrent(u32 *out_ma, IDevice *device) = 0;
virtual Result GetChargerInputCurrentLimit(u32 *out_ma, IDevice *device) = 0;
virtual Result SetChargerInputCurrentLimit(IDevice *device, u32 ma) = 0;
virtual Result GetChargerInputVoltageLimit(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerInputVoltageLimit(IDevice *device, u32 mv) = 0;
virtual Result GetBatteryInternalState(void *dst, size_t *out_size, IDevice *device, size_t dst_size) = 0;
virtual Result SetBatteryInternalState(IDevice *device, const void *src, size_t src_size) = 0;
virtual Result GetBatteryNeedToRestoreParameters(bool *out, IDevice *device) = 0;
virtual Result SetBatteryNeedToRestoreParameters(IDevice *device, bool en) = 0;
virtual Result IsBatteryI2cShutdownEnabled(bool *out, IDevice *device) = 0;
virtual Result SetBatteryI2cShutdownEnabled(IDevice *device, bool en) = 0;
virtual Result IsBatteryRemoved(bool *out, IDevice *device) = 0;
virtual Result GetChargerChargerStatus(ChargerStatus *out, IDevice *device) = 0;
virtual Result GetBatteryCycles(u32 *out, IDevice *device) = 0;
virtual Result SetBatteryCycles(IDevice *device, u32 cycles) = 0;
virtual Result GetBatteryAge(float *out_percent, IDevice *device) = 0;
virtual Result GetBatteryTemperature(float *out_c, IDevice *device) = 0;
virtual Result GetBatteryMaximumTemperature(float *out_c, IDevice *device) = 0;
virtual Result SetBatteryTemperatureMinimumAlertThreshold(IDevice *device, float c) = 0;
virtual Result SetBatteryTemperatureMaximumAlertThreshold(IDevice *device, float c) = 0;
virtual Result GetBatteryVCell(u32 *out_mv, IDevice *device) = 0;
virtual Result GetBatteryAverageVCell(u32 *out_mv, IDevice *device) = 0;
virtual Result GetBatteryAverageVCellTime(TimeSpan *out, IDevice *device) = 0;
virtual Result SetBatteryVoltageMinimumAlertThreshold(IDevice *device, u32 mv) = 0;
virtual Result GetBatteryOpenCircuitVoltage(u32 *out_mv, IDevice *device) = 0;
virtual Result SetBatteryVoltageMaximumAlertThreshold(IDevice *device, u32 mv) = 0;
virtual Result IsChargerWatchdogTimerEnabled(bool *out, IDevice *device) = 0;
virtual Result SetChargerWatchdogTimerEnabled(IDevice *device, bool en) = 0;
virtual Result SetChargerWatchdogTimerTimeout(IDevice *device, TimeSpan timeout) = 0;
virtual Result ResetChargerWatchdogTimer(IDevice *device) = 0;
virtual Result GetChargerBatteryCompensation(u32 *out_mo, IDevice *device) = 0;
virtual Result SetChargerBatteryCompensation(IDevice *device, u32 mo) = 0;
virtual Result GetChargerVoltageClamp(u32 *out_mv, IDevice *device) = 0;
virtual Result SetChargerVoltageClamp(IDevice *device, u32 mv) = 0;
};
}

View File

@@ -0,0 +1,32 @@
/*
* 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>
#include "powctl_i_power_control_driver.hpp"
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
#include "board/nintendo_nx/powctl_board_impl.hpp"
namespace ams::powctl::impl::board {
using namespace ams::powctl::impl::board::nintendo_nx;
}
#else
#error "Unknown board for ams::powctl::impl"
#endif