Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions nx/include/switch/services/pwm.h
Original file line number Diff line number Diff line change
@@ -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);
46 changes: 46 additions & 0 deletions nx/source/services/pwm.c
Original file line number Diff line number Diff line change
@@ -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);
}