From d9e3be27a2ea2499ea1b15f990947dcb0229de22 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 15 Sep 2018 11:38:41 -0700 Subject: [PATCH] Add psm:GetChargerType --- nx/include/switch/services/psm.h | 7 ++++++ nx/source/services/psm.c | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/nx/include/switch/services/psm.h b/nx/include/switch/services/psm.h index d233ee01..ed45d775 100644 --- a/nx/include/switch/services/psm.h +++ b/nx/include/switch/services/psm.h @@ -7,7 +7,14 @@ #pragma once #include "../types.h" +typedef enum { + ChargerType_None = 0, ///< No charger + ChargerType_Charger = 1, ///< Official charger or dock + ChargerType_Usb = 2 ///< Other USB-C chargers +} ChargerType; + Result psmInitialize(void); void psmExit(void); Result psmGetBatteryChargePercentage(u32 *out); +Result psmGetChargerType(ChargerType *out); diff --git a/nx/source/services/psm.c b/nx/source/services/psm.c index 26b302cb..f3d0a0c2 100644 --- a/nx/source/services/psm.c +++ b/nx/source/services/psm.c @@ -65,3 +65,40 @@ Result psmGetBatteryChargePercentage(u32 *out) return rc; } + +Result psmGetChargerType(ChargerType *out) +{ + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 1; + + Result rc = serviceIpcDispatch(&g_psmSrv); + + if(R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u32 charger; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc)) { + *out = resp->charger; + } + } + + return rc; +}