From 24a55f58a15ce9a0c5f6f2b740c04c038c438bcc Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Sun, 15 Feb 2026 18:14:19 +0100 Subject: [PATCH 1/3] Add files via upload --- nx/source/services/pwm.c | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 nx/source/services/pwm.c diff --git a/nx/source/services/pwm.c b/nx/source/services/pwm.c new file mode 100644 index 0000000000..b3e1385416 --- /dev/null +++ b/nx/source/services/pwm.c @@ -0,0 +1,46 @@ +#define NX_SERVICE_ASSUME_NON_DOMAIN +#include "service_guard.h" +#include "services/pwm.h" +#include "runtime/hosversion.h" + +static Service g_pwmSrv; + +NX_GENERATE_SERVICE_GUARD(pwm); + +Result _pwmInitialize(void) { + return smGetService(&g_pwmSrv, "pwm"); +} + +void _pwmCleanup(void) { + serviceClose(&g_pwmSrv); +} + +Service* pwmGetServiceSession(void) { + return &g_pwmSrv; +} + +Result pwmOpenSession2(PwmChannelSession *out, PwmChannelDeviceCode device_code) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + u32 tmp = device_code; + + return serviceDispatchIn(&g_pwmSrv, 2, tmp, + .out_num_objects = 1, + .out_objects = &out->s, + ); +} + +void pwmChannelSessionClose(PwmChannelSession *c) { + serviceClose(&c->s); +} + +Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double* out) { + if (hosversionBefore(6,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + if (!serviceIsActive(&c->s)) + return MAKERESULT(Module_Libnx, LibnxError_NotInitialized); + + return serviceDispatchOut(&c->s, 7, *out); +} From e3f2dac3722eae028143d7e0a034623303a1f69b Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Sun, 15 Feb 2026 18:14:36 +0100 Subject: [PATCH 2/3] Add files via upload --- nx/include/switch/services/pwm.h | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 nx/include/switch/services/pwm.h diff --git a/nx/include/switch/services/pwm.h b/nx/include/switch/services/pwm.h new file mode 100644 index 0000000000..f0e78b9575 --- /dev/null +++ b/nx/include/switch/services/pwm.h @@ -0,0 +1,38 @@ +/** + * @file pwm.h + * @author MasaGratoR + * @copyright libnx Authors + */ + +#pragma once + +#include "../types.h" +#include "../sf/service.h" + +typedef struct { + Service s; +} PwmChannelSession; + +typedef enum { + PwmChannelDeviceCode_CpuFan = 0x3D000001, + PwmChannelDeviceCode_LcdBacklight = 0x3400003D, + PwmChannelDeviceCode_Led = 0x35000065 +} PwmChannelDeviceCode; + +/// Initialize pwm. +Result pwmInitialize(void); + +/// Exit pwm. +void pwmExit(void); + +/// Gets the Service for pwm. +Service* pwmGetServiceSession(void); + +/// Takes a PwmChannelDeviceCode and returns a PwmChannelSession. Only available on [6.0.0+]. +Result pwmOpenSession2(PwmChannelSession *out, PwmChannelDeviceCode device_code); + +/// Closes a PwmChannelSession. +void pwmChannelSessionClose(PwmChannelSession *c); + +/// Takes a PwmChannelSession, returns an output double. Only available on [6.0.0+]. +Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double* out); From 5c2d3e6ae46764022d00085e7b8313d590e4abf9 Mon Sep 17 00:00:00 2001 From: MasaGratoR Date: Sun, 15 Feb 2026 19:23:09 +0100 Subject: [PATCH 3/3] Update switch.h --- nx/include/switch.h | 1 + 1 file changed, 1 insertion(+) diff --git a/nx/include/switch.h b/nx/include/switch.h index 6ba918e697..cbd92feab8 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -132,6 +132,7 @@ extern "C" { #include "switch/services/ectx.h" #include "switch/services/avm.h" #include "switch/services/mm.h" +#include "switch/services/pwm.h" #include "switch/display/binder.h" #include "switch/display/parcel.h"