libnx v4.12.0
Loading...
Searching...
No Matches
psm.h
Go to the documentation of this file.
1/**
2 * @file psm.h
3 * @brief PSM service IPC wrapper.
4 * @author XorTroll, endrift, and yellows8
5 * @copyright libnx Authors
6 */
7#pragma once
8#include "../types.h"
9#include "../sf/service.h"
10#include "../kernel/event.h"
11
12/// ChargerType
13typedef enum {
14 PsmChargerType_Unconnected = 0, ///< No charger
15 PsmChargerType_EnoughPower = 1, ///< Full supported power
16 PsmChargerType_LowPower = 2, ///< Lower power supported USB-PD mode
17 PsmChargerType_NotSupported = 3, ///< No common supported USB-PD modes
19
20/// Vdd50State
21typedef enum {
22 PsmVdd50State_Unknown = 0,
23 PsmVdd50State_Vdd50AOffVdd50BOff = 1,
24 PsmVdd50State_Vdd50AOnVdd50BOff = 2,
25 PsmVdd50State_Vdd50AOffVdd50BOn = 3,
27
28/// BatteryVoltageState
29typedef enum {
30 PsmBatteryVoltageState_NeedsShutdown = 0, ///< Power state should transition to shutdown
31 PsmBatteryVoltageState_NeedsSleep = 1, ///< Power state should transition to sleep
32 PsmBatteryVoltageState_NoPerformanceBoost = 2, ///< Performance boost modes cannot be entered
33 PsmBatteryVoltageState_Normal = 3, ///< Everything is normal
35
36/// BatteryChargeInfoFieldsOld [1.0.0-16.1.0]
37typedef struct {
38 u32 input_current_limit;
39 u32 boost_mode_current_limit;
40 u32 fast_charge_current_limit;
41 u32 charge_voltage_limit;
42 PsmChargerType charger_type;
43 u8 hi_z_mode;
44 bool battery_charging;
45 u8 pad[2];
46 PsmVdd50State vdd50_state;
47 u32 temperature_celcius;
48 u32 battery_charge_percentage;
49 u32 battery_charge_milli_voltage;
50 u32 battery_age_percentage;
51 u32 usb_power_role;
52 u32 usb_charger_type;
53 u32 charger_input_voltage_limit;
54 u32 charger_input_current_limit;
55 bool fast_battery_charging;
56 bool controller_power_supply;
57 bool otg_request;
58 u8 reserved;
60
61/// BatteryChargeInfoFields [17.0.0+]
62typedef struct {
63 u32 input_current_limit; ///< Input (Sink) current limit in mA
64 u32 boost_mode_current_limit; ///< Output (Source/VBUS/OTG) current limit in mA
65 u32 fast_charge_current_limit; ///< Battery charging current limit in mA
66 u32 charge_voltage_limit; ///< Battery charging voltage limit in mV
67 PsmChargerType charger_type;
68 u8 hi_z_mode;
69 bool battery_charging;
70 u8 pad[2];
71 PsmVdd50State vdd50_state; ///< Power Delivery Controller State
72 u32 temperature_celcius; ///< Battery temperature in milli C
73 u32 battery_charge_percentage; ///< Raw battery charged capacity per cent-mille
74 u32 battery_charge_milli_voltage; ///< Voltage average in mV
75 u32 battery_age_percentage; ///< Battery age per cent-mille
76 u32 usb_power_role;
77 u32 usb_charger_type;
78 u32 charger_input_voltage_limit; ///< Charger and external device voltage limit in mV
79 u32 charger_input_current_limit; ///< Charger and external device current limit in mA
80 bool fast_battery_charging;
81 bool controller_power_supply;
82 bool otg_request;
83 u8 reserved;
84 u8 unk_x40[0x14];
86
87/// IPsmSession
88typedef struct {
89 Service s;
90 Event StateChangeEvent; ///< autoclear=false
92
93/// Initialize psm.
95
96/// Exit psm.
97void psmExit(void);
98
99/// Gets the Service object for the actual psm service session.
101
102/**
103 * @brief GetBatteryChargePercentage
104 * @param[out] out Battery charge percentage.
105 */
107
108/**
109 * @brief GetChargerType
110 * @param[out] out \ref PsmChargerType
111 */
113
114/**
115 * @brief EnableBatteryCharging
116 */
118
119/**
120 * @brief DisableBatteryCharging
121 */
123
124/**
125 * @brief IsBatteryChargingEnabled
126 * @param[out] out Output flag.
127 */
129
130/**
131 * @brief AcquireControllerPowerSupply
132 */
134
135/**
136 * @brief ReleaseControllerPowerSupply
137 */
139
140/**
141 * @brief EnableEnoughPowerChargeEmulation
142 */
144
145/**
146 * @brief DisableEnoughPowerChargeEmulation
147 */
149
150/**
151 * @brief EnableFastBatteryCharging
152 */
154
155/**
156 * @brief DisableFastBatteryCharging
157 */
159
160/**
161 * @brief GetBatteryVoltageState
162 * @param[out] out \ref PsmBatteryVoltageState
163 */
165
166/**
167 * @brief GetRawBatteryChargePercentage
168 * @param[out] out Raw battery charge percentage.
169 */
171
172/**
173 * @brief IsEnoughPowerSupplied
174 * @param[out] out Output flag.
175 */
177
178/**
179 * @brief GetBatteryAgePercentage
180 * @param[out] out Battery age percentage.
181 */
183
184/**
185 * @brief GetBatteryChargeInfoEvent
186 * @param[out] out_event Event object.
187 * @param[in] autoclear Event autoclear.
188 */
189Result psmGetBatteryChargeInfoEvent(Event* out_event, bool autoclear);
190
191/**
192 * @brief GetBatteryChargeInfoFields
193 * @param[out] out_fields \ref PsmBatteryChargeInfoFields
194 */
196
197/**
198 * @brief GetBatteryChargeCalibratedEvent
199 * @note Only available on [3.0.0+].
200 * @param[out] out_event Event object.
201 * @param[in] autoclear Event autoclear.
202 */
204
205/**
206 * @brief Wrapper func which opens a PsmSession and handles event setup.
207 * @note Uses the actual BindStateChangeEvent cmd internally.
208 * @note The event is not signalled on BatteryChargePercentage changes.
209 * @param[out] s PsmSession object.
210 * @param[in] ChargerType Passed to SetChargerTypeChangeEventEnabled.
211 * @param[in] PowerSupply Passed to SetPowerSupplyChangeEventEnabled.
212 * @param[in] BatteryVoltage Passed to SetBatteryVoltageStateChangeEventEnabled.
213 */
214Result psmBindStateChangeEvent(PsmSession* s, bool ChargerType, bool PowerSupply, bool BatteryVoltage);
215
216/// Wait on the Event setup by \ref psmBindStateChangeEvent.
218
219/// Cleanup version of \ref psmBindStateChangeEvent. Must be called by the user once the PsmSession is done being used.
Service * psmGetServiceSession(void)
Gets the Service object for the actual psm service session.
Result psmGetBatteryChargeInfoFields(PsmBatteryChargeInfoFields *out_fields)
GetBatteryChargeInfoFields.
PsmBatteryVoltageState
BatteryVoltageState.
Definition psm.h:29
@ PsmBatteryVoltageState_NeedsShutdown
Power state should transition to shutdown.
Definition psm.h:30
@ PsmBatteryVoltageState_NeedsSleep
Power state should transition to sleep.
Definition psm.h:31
@ PsmBatteryVoltageState_Normal
Everything is normal.
Definition psm.h:33
@ PsmBatteryVoltageState_NoPerformanceBoost
Performance boost modes cannot be entered.
Definition psm.h:32
Result psmGetBatteryChargePercentage(u32 *out)
GetBatteryChargePercentage.
Result psmGetBatteryChargeCalibratedEvent(Event *out_event, bool autoclear)
GetBatteryChargeCalibratedEvent.
Result psmEnableEnoughPowerChargeEmulation(void)
EnableEnoughPowerChargeEmulation.
Result psmEnableBatteryCharging(void)
EnableBatteryCharging.
Result psmIsBatteryChargingEnabled(bool *out)
IsBatteryChargingEnabled.
Result psmGetBatteryChargeInfoEvent(Event *out_event, bool autoclear)
GetBatteryChargeInfoEvent.
Result psmGetRawBatteryChargePercentage(double *out)
GetRawBatteryChargePercentage.
Result psmDisableBatteryCharging(void)
DisableBatteryCharging.
Result psmDisableFastBatteryCharging(void)
DisableFastBatteryCharging.
Result psmUnbindStateChangeEvent(PsmSession *s)
Cleanup version of psmBindStateChangeEvent. Must be called by the user once the PsmSession is done be...
PsmVdd50State
Vdd50State.
Definition psm.h:21
Result psmIsEnoughPowerSupplied(bool *out)
IsEnoughPowerSupplied.
void psmExit(void)
Exit psm.
Result psmDisableEnoughPowerChargeEmulation(void)
DisableEnoughPowerChargeEmulation.
Result psmEnableFastBatteryCharging(void)
EnableFastBatteryCharging.
PsmChargerType
ChargerType.
Definition psm.h:13
@ PsmChargerType_NotSupported
No common supported USB-PD modes.
Definition psm.h:17
@ PsmChargerType_LowPower
Lower power supported USB-PD mode.
Definition psm.h:16
@ PsmChargerType_Unconnected
No charger.
Definition psm.h:14
@ PsmChargerType_EnoughPower
Full supported power.
Definition psm.h:15
Result psmGetBatteryAgePercentage(double *out)
GetBatteryAgePercentage.
Result psmReleaseControllerPowerSupply(void)
ReleaseControllerPowerSupply.
Result psmWaitStateChangeEvent(PsmSession *s, u64 timeout)
Wait on the Event setup by psmBindStateChangeEvent.
Result psmAcquireControllerPowerSupply(void)
AcquireControllerPowerSupply.
Result psmInitialize(void)
Initialize psm.
Result psmGetBatteryVoltageState(PsmBatteryVoltageState *out)
GetBatteryVoltageState.
Result psmBindStateChangeEvent(PsmSession *s, bool ChargerType, bool PowerSupply, bool BatteryVoltage)
Wrapper func which opens a PsmSession and handles event setup.
Result psmGetChargerType(PsmChargerType *out)
GetChargerType.
Kernel-mode event structure.
Definition event.h:13
BatteryChargeInfoFieldsOld [1.0.0-16.1.0].
Definition psm.h:37
BatteryChargeInfoFields [17.0.0+].
Definition psm.h:62
u32 input_current_limit
Input (Sink) current limit in mA.
Definition psm.h:63
u32 charger_input_current_limit
Charger and external device current limit in mA.
Definition psm.h:79
u32 boost_mode_current_limit
Output (Source/VBUS/OTG) current limit in mA.
Definition psm.h:64
u32 battery_age_percentage
Battery age per cent-mille.
Definition psm.h:75
u32 battery_charge_percentage
Raw battery charged capacity per cent-mille.
Definition psm.h:73
PsmVdd50State vdd50_state
Power Delivery Controller State.
Definition psm.h:71
u32 battery_charge_milli_voltage
Voltage average in mV.
Definition psm.h:74
u32 fast_charge_current_limit
Battery charging current limit in mA.
Definition psm.h:65
u32 charger_input_voltage_limit
Charger and external device voltage limit in mV.
Definition psm.h:78
u32 charge_voltage_limit
Battery charging voltage limit in mV.
Definition psm.h:66
u32 temperature_celcius
Battery temperature in milli C.
Definition psm.h:72
IPsmSession.
Definition psm.h:88
Event StateChangeEvent
autoclear=false
Definition psm.h:90
Service object structure.
Definition service.h:14
uint64_t u64
64-bit unsigned integer.
Definition types.h:22
uint8_t u8
8-bit unsigned integer.
Definition types.h:19
u32 Result
Function error code result type.
Definition types.h:44
uint32_t u32
32-bit unsigned integer.
Definition types.h:21