From f9f23bef8f2aab1c259547410141259ad23214df Mon Sep 17 00:00:00 2001 From: yellows8 Date: Mon, 23 Nov 2020 15:45:22 -0500 Subject: [PATCH] hid: Replaced the lifo layouts/sixaxis arrays with individual fields. Use the Lark/Lucia enum in the GetNpadStates funcs. --- nx/include/switch/services/hid.h | 18 +++++++- nx/source/services/hid.c | 71 ++++++++++++++------------------ 2 files changed, 47 insertions(+), 42 deletions(-) diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index 2d44a15c..d0b5c635 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -891,8 +891,22 @@ typedef struct HidNpadInternalState { u32 joy_assignment_mode; ///< \ref HidNpadJoyAssignmentMode HidNpadFullKeyColorState full_key_color; ///< \ref HidNpadFullKeyColorState HidNpadJoyColorState joy_color; ///< \ref HidNpadJoyColorState - HidNpadCommonLifo layouts[7]; - HidNpadSixAxisSensorLifo sixaxis[6]; + + HidNpadCommonLifo full_key_lifo; ///< FullKeyLifo + HidNpadCommonLifo handheld_lifo; ///< HandheldLifo + HidNpadCommonLifo joy_dual_lifo; ///< JoyDualLifo + HidNpadCommonLifo joy_left_lifo; ///< JoyLeftLifo + HidNpadCommonLifo joy_right_lifo; ///< JoyRightLifo + HidNpadCommonLifo palma_lifo; ///< PalmaLifo + HidNpadCommonLifo system_ext_lifo; ///< SystemExtLifo + + HidNpadSixAxisSensorLifo full_key_six_axis_sensor_lifo; ///< FullKeySixAxisSensorLifo + HidNpadSixAxisSensorLifo handheld_six_axis_sensor_lifo; ///< HandheldSixAxisSensorLifo + HidNpadSixAxisSensorLifo joy_dual_left_six_axis_sensor_lifo; ///< JoyDualLeftSixAxisSensorLifo + HidNpadSixAxisSensorLifo joy_dual_right_six_axis_sensor_lifo; ///< JoyDualRightSixAxisSensorLifo + HidNpadSixAxisSensorLifo joy_left_six_axis_sensor_lifo; ///< JoyLeftSixAxisSensorLifo + HidNpadSixAxisSensorLifo joy_right_six_axis_sensor_lifo; ///< JoyRightSixAxisSensorLifo + u32 device_type; ///< Bitfield of \ref HidDeviceTypeBits. u32 reserved; ///< Reserved HidNpadSystemProperties system_properties; diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index cdaa5ae6..29e77994 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -456,15 +456,13 @@ void hidInitializeNpad(void) { if (R_FAILED(rc)) diagAbortWithResult(rc); } -static size_t _hidGetNpadStates(HidNpadInternalState *npad, u32 layout, HidNpadCommonState *states, size_t count) { - HidNpadCommonLifo *states_buf = &npad->layouts[layout]; +static size_t _hidGetNpadStates(HidNpadCommonLifo *lifo, HidNpadCommonState *states, size_t count) { if (count > 17) count = 17; - return _hidGetStates(&states_buf->header, states_buf->storage, 17, offsetof(HidNpadCommonStateAtomicStorage,state), offsetof(HidNpadCommonState,sampling_number), states, sizeof(HidNpadCommonState), count); + return _hidGetStates(&lifo->header, lifo->storage, 17, offsetof(HidNpadCommonStateAtomicStorage,state), offsetof(HidNpadCommonState,sampling_number), states, sizeof(HidNpadCommonState), count); } size_t hidGetNpadStatesFullKey(HidNpadIdType id, HidNpadFullKeyState *states, size_t count) { - HidNpadInternalState *npad = _hidGetNpadInternalState(id); - size_t total = _hidGetNpadStates(npad, 0, states, count); + size_t total = _hidGetNpadStates(&_hidGetNpadInternalState(id)->full_key_lifo, states, count); // sdknso would handle button-bitmasking with ControlPadRestriction here. @@ -472,8 +470,7 @@ size_t hidGetNpadStatesFullKey(HidNpadIdType id, HidNpadFullKeyState *states, si } size_t hidGetNpadStatesHandheld(HidNpadIdType id, HidNpadHandheldState *states, size_t count) { - HidNpadInternalState *npad = _hidGetNpadInternalState(id); - size_t total = _hidGetNpadStates(npad, 1, states, count); + size_t total = _hidGetNpadStates(&_hidGetNpadInternalState(id)->handheld_lifo, states, count); // sdknso would handle button-bitmasking with ControlPadRestriction here. @@ -481,8 +478,7 @@ size_t hidGetNpadStatesHandheld(HidNpadIdType id, HidNpadHandheldState *states, } size_t hidGetNpadStatesJoyDual(HidNpadIdType id, HidNpadJoyDualState *states, size_t count) { - HidNpadInternalState *npad = _hidGetNpadInternalState(id); - size_t total = _hidGetNpadStates(npad, 2, states, count); + size_t total = _hidGetNpadStates(&_hidGetNpadInternalState(id)->joy_dual_lifo, states, count); // sdknso would handle button-bitmasking with ControlPadRestriction here. @@ -490,8 +486,7 @@ size_t hidGetNpadStatesJoyDual(HidNpadIdType id, HidNpadJoyDualState *states, si } size_t hidGetNpadStatesJoyLeft(HidNpadIdType id, HidNpadJoyLeftState *states, size_t count) { - HidNpadInternalState *npad = _hidGetNpadInternalState(id); - size_t total = _hidGetNpadStates(npad, 3, states, count); + size_t total = _hidGetNpadStates(&_hidGetNpadInternalState(id)->joy_left_lifo, states, count); // sdknso would handle button-bitmasking with ControlPadRestriction here. @@ -499,8 +494,7 @@ size_t hidGetNpadStatesJoyLeft(HidNpadIdType id, HidNpadJoyLeftState *states, si } size_t hidGetNpadStatesJoyRight(HidNpadIdType id, HidNpadJoyRightState *states, size_t count) { - HidNpadInternalState *npad = _hidGetNpadInternalState(id); - size_t total = _hidGetNpadStates(npad, 4, states, count); + size_t total = _hidGetNpadStates(&_hidGetNpadInternalState(id)->joy_right_lifo, states, count); // sdknso would handle button-bitmasking with ControlPadRestriction here. @@ -512,7 +506,7 @@ size_t hidGetNpadStatesGc(HidNpadIdType id, HidNpadGcState *states, size_t count HidNpadGcTriggerState tmp_entries_trigger[17]; HidNpadInternalState *npad = _hidGetNpadInternalState(id); - size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count); + size_t total = _hidGetNpadStates(&npad->full_key_lifo, tmp_entries, count); size_t total2 = _hidGetStates(&npad->gc_trigger_lifo.header, npad->gc_trigger_lifo.storage, 17, offsetof(HidNpadGcTriggerStateAtomicStorage,state), offsetof(HidNpadGcTriggerState,sampling_number), tmp_entries_trigger, sizeof(HidNpadGcTriggerState), total); if (total2 < total) total = total2; @@ -536,8 +530,7 @@ size_t hidGetNpadStatesGc(HidNpadIdType id, HidNpadGcState *states, size_t count } size_t hidGetNpadStatesPalma(HidNpadIdType id, HidNpadPalmaState *states, size_t count) { - HidNpadInternalState *npad = _hidGetNpadInternalState(id); - size_t total = _hidGetNpadStates(npad, 5, states, count); + size_t total = _hidGetNpadStates(&_hidGetNpadInternalState(id)->palma_lifo, states, count); // sdknso doesn't handle ControlPadRestriction with this. @@ -548,12 +541,12 @@ size_t hidGetNpadStatesLark(HidNpadIdType id, HidNpadLarkState *states, size_t c HidNpadCommonState tmp_entries[17]; HidNpadInternalState *npad = _hidGetNpadInternalState(id); - size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count); + size_t total = _hidGetNpadStates(&npad->full_key_lifo, tmp_entries, count); memset(states, 0, sizeof(HidNpadLarkState) * total); - u32 lark_type_l_and_main = atomic_load_explicit(&npad->lark_type_l_and_main, memory_order_acquire); - if (!(lark_type_l_and_main>=1 && lark_type_l_and_main<=4)) lark_type_l_and_main = 0; + HidNpadLarkType lark_type_l_and_main = atomic_load_explicit(&npad->lark_type_l_and_main, memory_order_acquire); + if (!(lark_type_l_and_main>=HidNpadLarkType_H1 && lark_type_l_and_main<=HidNpadLarkType_NR)) lark_type_l_and_main = HidNpadLarkType_Invalid; for (size_t i=0; ihandheld_lifo, tmp_entries, count); memset(states, 0, sizeof(HidNpadHandheldLarkState) * total); - u32 lark_type_l_and_main = atomic_load_explicit(&npad->lark_type_l_and_main, memory_order_acquire); - if (!(lark_type_l_and_main>=1 && lark_type_l_and_main<=4)) lark_type_l_and_main = 0; + HidNpadLarkType lark_type_l_and_main = atomic_load_explicit(&npad->lark_type_l_and_main, memory_order_acquire); + if (!(lark_type_l_and_main>=HidNpadLarkType_H1 && lark_type_l_and_main<=HidNpadLarkType_NR)) lark_type_l_and_main = HidNpadLarkType_Invalid; - u32 lark_type_r = atomic_load_explicit(&npad->lark_type_r, memory_order_acquire); - if (!(lark_type_r>=1 && lark_type_r<=4)) lark_type_r = 0; + HidNpadLarkType lark_type_r = atomic_load_explicit(&npad->lark_type_r, memory_order_acquire); + if (!(lark_type_r>=HidNpadLarkType_H1 && lark_type_r<=HidNpadLarkType_NR)) lark_type_r = HidNpadLarkType_Invalid; for (size_t i=0; ifull_key_lifo, tmp_entries, count); memset(states, 0, sizeof(HidNpadLuciaState) * total); - u32 lucia_type = atomic_load_explicit(&npad->lucia_type, memory_order_acquire); - if (!(lucia_type>=1 && lucia_type<=3)) lucia_type = 0; + HidNpadLuciaType lucia_type = atomic_load_explicit(&npad->lucia_type, memory_order_acquire); + if (!(lucia_type>=HidNpadLuciaType_J && lucia_type<=HidNpadLuciaType_U)) lucia_type = HidNpadLuciaType_Invalid; for (size_t i=0; isystem_ext_lifo, states, count); // sdknso would handle button-bitmasking with ControlPadRestriction here. @@ -638,8 +630,7 @@ size_t hidGetNpadStatesSystemExt(HidNpadIdType id, HidNpadSystemExtState *states } size_t hidGetNpadStatesSystem(HidNpadIdType id, HidNpadSystemState *states, size_t count) { - HidNpadInternalState *npad = _hidGetNpadInternalState(id); - size_t total = _hidGetNpadStates(npad, 6, states, count); + size_t total = _hidGetNpadStates(&_hidGetNpadInternalState(id)->system_ext_lifo, states, count); for (size_t i=0; ifull_key_six_axis_sensor_lifo; break; case 1: // NpadHandheld/NpadHandheldLark - index = 1; + lifo = &npad->handheld_six_axis_sensor_lifo; break; case 2: // NpadJoyDual - if (handle.idx==0) index = 2; - else if (handle.idx==1) index = 3; + if (handle.idx==0) lifo = &npad->joy_dual_left_six_axis_sensor_lifo; + else if (handle.idx==1) lifo = &npad->joy_dual_right_six_axis_sensor_lifo; else diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen)); break; case 3: // NpadJoyLeft - index = 4; + lifo = &npad->joy_left_six_axis_sensor_lifo; break; case 4: // NpadJoyRight - index = 5; + lifo = &npad->joy_right_six_axis_sensor_lifo; break; case 29: // System(Ext) (not actually returned by GetHandles) @@ -697,8 +689,7 @@ size_t hidGetSixAxisSensorStates(HidSixAxisSensorHandle handle, HidSixAxisSensor return 0; } - HidNpadInternalState *npad = _hidGetNpadInternalState(handle.npad_id_type); - size_t total = _hidGetStates(&npad->sixaxis[index].header, npad->sixaxis[index].storage, 17, offsetof(HidSixAxisSensorStateAtomicStorage,state), offsetof(HidSixAxisSensorState,sampling_number), states, sizeof(HidSixAxisSensorState), count); + size_t total = _hidGetStates(&lifo->header, lifo->storage, 17, offsetof(HidSixAxisSensorStateAtomicStorage,state), offsetof(HidSixAxisSensorState,sampling_number), states, sizeof(HidSixAxisSensorState), count); return total; }