libnx v4.9.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
12typedef enum {
13 PsmChargerType_Unconnected = 0, ///< No charger
14 PsmChargerType_EnoughPower = 1, ///< Full supported power
15 PsmChargerType_LowPower = 2, ///< Lower power supported USB-PD mode
16 PsmChargerType_NotSupported = 3, ///< No common supported USB-PD modes
18
19typedef enum {
20 PsmBatteryVoltageState_NeedsShutdown = 0, ///< Power state should transition to shutdown
21 PsmBatteryVoltageState_NeedsSleep = 1, ///< Power state should transition to sleep
22 PsmBatteryVoltageState_NoPerformanceBoost = 2, ///< Performance boost modes cannot be entered
23 PsmBatteryVoltageState_Normal = 3, ///< Everything is normal
25
26/// IPsmSession
27typedef struct {
28 Service s;
29 Event StateChangeEvent; ///< autoclear=false
31
32/// Initialize psm.
34
35/// Exit psm.
36void psmExit(void);
37
38/// Gets the Service object for the actual psm service session.
40
41Result psmGetBatteryChargePercentage(u32 *out);
42Result psmGetChargerType(PsmChargerType *out);
43Result psmGetBatteryVoltageState(PsmBatteryVoltageState *out);
44Result psmGetRawBatteryChargePercentage(double *out);
45Result psmIsEnoughPowerSupplied(bool *out);
46Result psmGetBatteryAgePercentage(double *out);
47
48/**
49 * @brief Wrapper func which opens a PsmSession and handles event setup.
50 * @note Uses the actual BindStateChangeEvent cmd internally.
51 * @note The event is not signalled on BatteryChargePercentage changes.
52 * @param[out] s PsmSession object.
53 * @param[in] ChargerType Passed to SetChargerTypeChangeEventEnabled.
54 * @param[in] PowerSupply Passed to SetPowerSupplyChangeEventEnabled.
55 * @param[in] BatteryVoltage Passed to SetBatteryVoltageStateChangeEventEnabled.
56 */
57Result psmBindStateChangeEvent(PsmSession* s, bool ChargerType, bool PowerSupply, bool BatteryVoltage);
58
59/// Wait on the Event setup by \ref psmBindStateChangeEvent.
61
62/// 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.
PsmBatteryVoltageState
Definition psm.h:19
@ PsmBatteryVoltageState_NeedsShutdown
Power state should transition to shutdown.
Definition psm.h:20
@ PsmBatteryVoltageState_NeedsSleep
Power state should transition to sleep.
Definition psm.h:21
@ PsmBatteryVoltageState_Normal
Everything is normal.
Definition psm.h:23
@ PsmBatteryVoltageState_NoPerformanceBoost
Performance boost modes cannot be entered.
Definition psm.h:22
Result psmUnbindStateChangeEvent(PsmSession *s)
Cleanup version of psmBindStateChangeEvent. Must be called by the user once the PsmSession is done be...
void psmExit(void)
Exit psm.
PsmChargerType
Definition psm.h:12
@ PsmChargerType_NotSupported
No common supported USB-PD modes.
Definition psm.h:16
@ PsmChargerType_LowPower
Lower power supported USB-PD mode.
Definition psm.h:15
@ PsmChargerType_Unconnected
No charger.
Definition psm.h:13
@ PsmChargerType_EnoughPower
Full supported power.
Definition psm.h:14
Result psmWaitStateChangeEvent(PsmSession *s, u64 timeout)
Wait on the Event setup by psmBindStateChangeEvent.
Result psmInitialize(void)
Initialize psm.
Result psmBindStateChangeEvent(PsmSession *s, bool ChargerType, bool PowerSupply, bool BatteryVoltage)
Wrapper func which opens a PsmSession and handles event setup.
Kernel-mode event structure.
Definition event.h:13
IPsmSession.
Definition psm.h:27
Event StateChangeEvent
autoclear=false
Definition psm.h:29
Service object structure.
Definition service.h:14
uint64_t u64
64-bit unsigned integer.
Definition types.h:22
u32 Result
Function error code result type.
Definition types.h:44
uint32_t u32
32-bit unsigned integer.
Definition types.h:21