diff --git a/nx/include/switch.h b/nx/include/switch.h index 6ba918e697..127993db83 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/omm.h" #include "switch/display/binder.h" #include "switch/display/parcel.h" diff --git a/nx/include/switch/services/omm.h b/nx/include/switch/services/omm.h new file mode 100644 index 0000000000..083828f427 --- /dev/null +++ b/nx/include/switch/services/omm.h @@ -0,0 +1,41 @@ +/** + * @file omm.h + * @author MasaGratoR + * @copyright libnx Authors + */ + +#pragma once + +#include "../types.h" +#include "../sf/service.h" + +///OperationMode +typedef enum { + OmmOperationMode_Handheld = 0, + OmmOperationMode_Console = 1 +} OmmOperationMode; + +///OperationModePolicy +typedef enum { + OmmOperationModePolicy_Auto = 0, + OmmOperationModePolicy_Handheld = 1, + OmmOperationModePolicy_Console = 2 +} OmmOperationModePolicy; + +/// Initialize omm. +Result ommInitialize(void); + +/// Exit omm. +void ommExit(void); + +/// Gets the Service for omm. +Service* ommGetServiceSession(void); + +/// Returns a DefaultDisplayResolution. Only available on [3.0.0+]. +Result ommGetDefaultDisplayResolution(s32* width, s32* height); + +/// Returns an OmmOperationMode. +Result ommGetOperationMode(OmmOperationMode* s); + +/// Takes an OmmOperationModePolicy. Only available on [3.0.0+]. +Result ommSetOperationModePolicy(OmmOperationModePolicy value); diff --git a/nx/source/services/omm.c b/nx/source/services/omm.c new file mode 100644 index 0000000000..6da7c7024d --- /dev/null +++ b/nx/source/services/omm.c @@ -0,0 +1,58 @@ +#define NX_SERVICE_ASSUME_NON_DOMAIN +#include "service_guard.h" +#include "services/omm.h" +#include "runtime/hosversion.h" + +static Service g_ommSrv; + +NX_GENERATE_SERVICE_GUARD(omm); + +Result _ommInitialize(void) { + return smGetService(&g_ommSrv, "omm"); +} + +void _ommCleanup(void) { + serviceClose(&g_ommSrv); +} + +Service* ommGetServiceSession(void) { + return &g_ommSrv; +} + +Result ommGetDefaultDisplayResolution(s32* width, s32* height) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + struct { + s32 width; + s32 height; + } out; + + Result rc = serviceDispatchOut(&g_ommSrv, 11, out); + + if (R_SUCCEEDED(rc)) { + *width = out.width; + *height = out.height; + } + + return rc; +} + +Result ommGetOperationMode(OmmOperationMode* s) { + u8 out; + Result rc = serviceDispatchOut(&g_ommSrv, 0, out); + + if (R_SUCCEEDED(rc)) { + *s = out; + } + + return rc; +} + +Result ommSetOperationModePolicy(OmmOperationModePolicy value) { + if (hosversionBefore(3,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + u8 tmp = value; + return serviceDispatchIn(&g_ommSrv, 10, tmp); +}