From 4010c70b1e4c0533975010c0e15388abc9599e49 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sat, 28 Nov 2020 21:21:26 -0500 Subject: [PATCH] hiddbg: Added support for AutoPilot with the following: DebugPad, TouchScreen, Mouse, Keyboard. --- nx/include/switch/services/hiddbg.h | 70 +++++++++++++++++++++++++++++ nx/source/services/hiddbg.c | 35 +++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/nx/include/switch/services/hiddbg.h b/nx/include/switch/services/hiddbg.h index 94845609..63ae90e3 100644 --- a/nx/include/switch/services/hiddbg.h +++ b/nx/include/switch/services/hiddbg.h @@ -9,6 +9,31 @@ #include "../services/hidsys.h" #include "../sf/service.h" +/// State for overriding \ref HidDebugPadState. +typedef struct { + u32 attributes; ///< Bitfield of \ref HidDebugPadAttribute. + u32 buttons; ///< Bitfield of \ref HidDebugPadButton. + HidAnalogStickState analog_stick_l; ///< AnalogStickL + HidAnalogStickState analog_stick_r; ///< AnalogStickR +} HiddbgDebugPadAutoPilotState; + +/// State for overriding \ref HidMouseState. +typedef struct { + s32 x; ///< X + s32 y; ///< Y + s32 unk0; ///< Unknown + s32 unk1; ///< Unknown + s32 unk2; ///< Unknown + u32 buttons; ///< Bitfield of \ref HidMouseButton. + u32 attributes; ///< Bitfield of \ref HidMouseAttribute. +} HiddbgMouseAutoPilotState; + +/// State for overriding \ref HidKeyboardState. +typedef struct { + u64 modifiers; ///< Bitfield of \ref HidKeyboardModifier. + u64 keys[4]; +} HiddbgKeyboardAutoPilotState; + /// HdlsHandle typedef struct { u64 handle; ///< Handle @@ -134,6 +159,51 @@ void hiddbgExit(void); /// Gets the Service object for the actual hiddbg service session. Service* hiddbgGetServiceSession(void); +/** + * @brief SetDebugPadAutoPilotState + * @param[in] state \ref HiddbgDebugPadAutoPilotState + */ +Result hiddbgSetDebugPadAutoPilotState(const HiddbgDebugPadAutoPilotState *state); + +/** + * @brief UnsetDebugPadAutoPilotState + */ +Result hiddbgUnsetDebugPadAutoPilotState(void); + +/** + * @brief SetTouchScreenAutoPilotState + * @param[in] states Input array of \ref HiddbgMouseAutoPilotState. + * @param[in] count Total entries in the states array. Max is 16. + */ +Result hiddbgSetTouchScreenAutoPilotState(const HidTouchState *states, s32 count); + +/** + * @brief UnsetTouchScreenAutoPilotState + */ +Result hiddbgUnsetTouchScreenAutoPilotState(void); + +/** + * @brief SetMouseAutoPilotState + * @param[in] state \ref HiddbgMouseAutoPilotState + */ +Result hiddbgSetMouseAutoPilotState(const HiddbgMouseAutoPilotState *state); + +/** + * @brief UnsetMouseAutoPilotState + */ +Result hiddbgUnsetMouseAutoPilotState(void); + +/** + * @brief SetKeyboardAutoPilotState + * @param[in] state \ref HiddbgKeyboardAutoPilotState + */ +Result hiddbgSetKeyboardAutoPilotState(const HiddbgKeyboardAutoPilotState *state); + +/** + * @brief UnsetKeyboardAutoPilotState + */ +Result hiddbgUnsetKeyboardAutoPilotState(void); + /** * @brief Deactivates the HomeButton. */ diff --git a/nx/source/services/hiddbg.c b/nx/source/services/hiddbg.c index 643b7da5..b9022259 100644 --- a/nx/source/services/hiddbg.c +++ b/nx/source/services/hiddbg.c @@ -76,6 +76,41 @@ static Result _hiddbgCmdInTmemNoOut(TransferMemory *tmem, u32 cmd_id) { return _hiddbgCmdInHandle64NoOut(tmem->handle, tmem->size, cmd_id); } +Result hiddbgSetDebugPadAutoPilotState(const HiddbgDebugPadAutoPilotState *state) { + return serviceDispatchIn(&g_hiddbgSrv, 1, *state); +} + +Result hiddbgUnsetDebugPadAutoPilotState(void) { + return _hiddbgCmdNoIO(2); +} + +Result hiddbgSetTouchScreenAutoPilotState(const HidTouchState *states, s32 count) { + return serviceDispatch(&g_hiddbgSrv, 11, + .buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_In }, + .buffers = { { states, count*sizeof(HidTouchState) } }, + ); +} + +Result hiddbgUnsetTouchScreenAutoPilotState(void) { + return _hiddbgCmdNoIO(12); +} + +Result hiddbgSetMouseAutoPilotState(const HiddbgMouseAutoPilotState *state) { + return serviceDispatchIn(&g_hiddbgSrv, 21, *state); +} + +Result hiddbgUnsetMouseAutoPilotState(void) { + return _hiddbgCmdNoIO(22); +} + +Result hiddbgSetKeyboardAutoPilotState(const HiddbgKeyboardAutoPilotState *state) { + return serviceDispatchIn(&g_hiddbgSrv, 31, *state); +} + +Result hiddbgUnsetKeyboardAutoPilotState(void) { + return _hiddbgCmdNoIO(32); +} + Result hiddbgDeactivateHomeButton(void) { return _hiddbgCmdNoIO(110); }