Skip to content

Commit df05082

Browse files
authored
Add missing hid shared memory structures and accessor functions for system buttons (#647)
* hid: add missing shared memory format structures * hid: add functions for getting the state of the home, sleep and capture buttons from shmem
1 parent c769852 commit df05082

File tree

2 files changed

+369
-6
lines changed
  • nx

2 files changed

+369
-6
lines changed

nx/include/switch/services/hid.h

Lines changed: 342 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,297 @@ typedef struct HidKeyboardSharedMemoryFormat {
755755

756756
// End HidKeyboard
757757

758+
// Begin HidBasicXpad
759+
760+
/// HidBasicXpadState
761+
typedef struct {
762+
u64 sampling_number;
763+
u32 attributes;
764+
u32 buttons;
765+
u64 analog_stick_left;
766+
u64 analog_stick_right;
767+
} HidBasicXpadState;
768+
769+
/// HidBasicXpadStateAtomicStorage
770+
typedef struct {
771+
u64 sampling_number;
772+
HidBasicXpadState state;
773+
} HidBasicXpadStateAtomicStorage;
774+
775+
/// HidBasicXpadLifo
776+
typedef struct {
777+
HidCommonLifoHeader header;
778+
HidBasicXpadStateAtomicStorage storage[17];
779+
} HidBasicXpadLifo;
780+
781+
/// HidBasicXpadSharedMemoryEntry
782+
typedef struct {
783+
HidBasicXpadLifo lifo;
784+
u8 padding[0x138];
785+
} HidBasicXpadSharedMemoryEntry;
786+
787+
/// HidBasicXpadSharedMemoryFormat
788+
typedef struct {
789+
HidBasicXpadSharedMemoryEntry entries[4];
790+
} HidBasicXpadSharedMemoryFormat;
791+
792+
// End HidBasicXpad
793+
794+
// Begin HidDigitizer
795+
796+
/// HidDigitizerState
797+
typedef struct {
798+
u64 sampling_number;
799+
u32 unk_0x8;
800+
u32 unk_0xC;
801+
u32 attributes;
802+
u32 buttons;
803+
u32 unk_0x18;
804+
u32 unk_0x1C;
805+
u32 unk_0x20;
806+
u32 unk_0x24;
807+
u32 unk_0x28;
808+
u32 unk_0x2C;
809+
u32 unk_0x30;
810+
u32 unk_0x34;
811+
u32 unk_0x38;
812+
u32 unk_0x3C;
813+
u32 unk_0x40;
814+
u32 unk_0x44;
815+
u32 unk_0x48;
816+
u32 unk_0x4C;
817+
u32 unk_0x50;
818+
u32 unk_0x54;
819+
} HidDigitizerState;
820+
821+
/// HidDigitizerStateAtomicStorage
822+
typedef struct {
823+
u64 sampling_number;
824+
HidDigitizerState state;
825+
} HidDigitizerStateAtomicStorage;
826+
827+
/// HidDigitizerLifo
828+
typedef struct {
829+
HidCommonLifoHeader header;
830+
HidDigitizerStateAtomicStorage storage[17];
831+
} HidDigitizerLifo;
832+
833+
/// HidDigitizerSharedMemoryFormat
834+
typedef struct {
835+
HidDigitizerLifo lifo;
836+
u8 padding[0x980];
837+
} HidDigitizerSharedMemoryFormat;
838+
839+
// End HidDigitizer
840+
841+
// Begin HidHomeButton
842+
843+
/// HidHomeButtonState
844+
typedef struct {
845+
u64 sampling_number;
846+
u64 buttons;
847+
} HidHomeButtonState;
848+
849+
/// HidHomeButtonStateAtomicStorage
850+
typedef struct {
851+
u64 sampling_number;
852+
HidHomeButtonState state;
853+
} HidHomeButtonStateAtomicStorage;
854+
855+
/// HidHomeButtonLifo
856+
typedef struct {
857+
HidCommonLifoHeader header;
858+
HidHomeButtonStateAtomicStorage storage[17];
859+
} HidHomeButtonLifo;
860+
861+
/// HidHomeButtonSharedMemoryFormat
862+
typedef struct {
863+
HidHomeButtonLifo lifo;
864+
u8 padding[0x48];
865+
} HidHomeButtonSharedMemoryFormat;
866+
867+
// End HidHomeButton
868+
869+
// Begin HidSleepButton
870+
871+
/// HidSleepButtonState
872+
typedef struct {
873+
u64 sampling_number;
874+
u64 buttons;
875+
} HidSleepButtonState;
876+
877+
/// HidSleepButtonStateAtomicStorage
878+
typedef struct {
879+
u64 sampling_number;
880+
HidSleepButtonState state;
881+
} HidSleepButtonStateAtomicStorage;
882+
883+
/// HidSleepButtonLifo
884+
typedef struct {
885+
HidCommonLifoHeader header;
886+
HidSleepButtonStateAtomicStorage storage[17];
887+
} HidSleepButtonLifo;
888+
889+
/// HidSleepButtonSharedMemoryFormat
890+
typedef struct {
891+
HidSleepButtonLifo lifo;
892+
u8 padding[0x48];
893+
} HidSleepButtonSharedMemoryFormat;
894+
895+
// End HidSleepButton
896+
897+
// Begin HidCaptureButton
898+
899+
/// HidCaptureButtonState
900+
typedef struct {
901+
u64 sampling_number;
902+
u64 buttons;
903+
} HidCaptureButtonState;
904+
905+
/// HidCaptureButtonStateAtomicStorage
906+
typedef struct {
907+
u64 sampling_number;
908+
HidCaptureButtonState state;
909+
} HidCaptureButtonStateAtomicStorage;
910+
911+
/// HidCaptureButtonLifo
912+
typedef struct {
913+
HidCommonLifoHeader header;
914+
HidCaptureButtonStateAtomicStorage storage[17];
915+
} HidCaptureButtonLifo;
916+
917+
/// HidCaptureButtonSharedMemoryFormat
918+
typedef struct {
919+
HidCaptureButtonLifo lifo;
920+
u8 padding[0x48];
921+
} HidCaptureButtonSharedMemoryFormat;
922+
923+
// End HidCaptureButton
924+
925+
// Begin HidInputDetector
926+
927+
/// HidInputDetectorState
928+
typedef struct {
929+
u64 input_source_state;
930+
u64 sampling_number;
931+
} HidInputDetectorState;
932+
933+
/// HidInputDetectorStateAtomicStorage
934+
typedef struct {
935+
u64 sampling_number;
936+
HidInputDetectorState state;
937+
} HidInputDetectorStateAtomicStorage;
938+
939+
/// HidInputDetectorLifo
940+
typedef struct {
941+
HidCommonLifoHeader header;
942+
HidInputDetectorStateAtomicStorage storage[2];
943+
} HidInputDetectorLifo;
944+
945+
/// HidInputDetectorSharedMemoryEntry
946+
typedef struct {
947+
HidInputDetectorLifo lifo;
948+
u8 padding[0x30];
949+
} HidInputDetectorSharedMemoryEntry;
950+
951+
/// HidInputDetectorSharedMemoryFormat
952+
typedef struct {
953+
HidInputDetectorSharedMemoryEntry entries[16];
954+
} HidInputDetectorSharedMemoryFormat;
955+
956+
// End HidInputDetector
957+
958+
// Begin HidUniquePad
959+
960+
/// HidUniquePadConfigMutex
961+
typedef struct {
962+
u8 unk_0x0[0x20];
963+
} HidUniquePadConfigMutex;
964+
965+
/// HidSixAxisSensorUserCalibrationState
966+
typedef struct {
967+
u32 flags;
968+
u8 reserved[4];
969+
u64 stage;
970+
u64 sampling_number;
971+
} HidSixAxisSensorUserCalibrationState;
972+
973+
/// HidSixAxisSensorUserCalibrationStateAtomicStorage
974+
typedef struct {
975+
u64 sampling_number;
976+
HidSixAxisSensorUserCalibrationState calib_state;
977+
} HidSixAxisSensorUserCalibrationStateAtomicStorage;
978+
979+
/// HidSixAxisSensorUserCalibrationStateLifo
980+
typedef struct {
981+
HidCommonLifoHeader header;
982+
HidSixAxisSensorUserCalibrationStateAtomicStorage storage[2];
983+
} HidSixAxisSensorUserCalibrationStateLifo;
984+
985+
/// HidAnalogStickCalibrationStateImpl
986+
typedef struct {
987+
u64 state;
988+
u64 flags;
989+
u64 stage;
990+
u64 sampling_number;
991+
} HidAnalogStickCalibrationStateImpl;
992+
993+
/// HidAnalogStickCalibrationStateImplAtomicStorage
994+
typedef struct {
995+
u64 sampling_number;
996+
HidAnalogStickCalibrationStateImpl calib_state;
997+
} HidAnalogStickCalibrationStateImplAtomicStorage;
998+
999+
/// HidAnalogStickCalibrationStateImplLifo
1000+
typedef struct {
1001+
HidCommonLifoHeader header;
1002+
HidAnalogStickCalibrationStateImplAtomicStorage storage[2];
1003+
} HidAnalogStickCalibrationStateImplLifo;
1004+
1005+
/// HidUniquePadConfig
1006+
typedef struct {
1007+
u32 type;
1008+
u32 interface;
1009+
u8 serial_number[0x10];
1010+
u32 controller_number;
1011+
bool is_active;
1012+
u8 reserved[3];
1013+
u64 sampling_number;
1014+
} HidUniquePadConfig;
1015+
1016+
/// HidUniquePadConfigAtomicStorage
1017+
typedef struct {
1018+
u64 sampling_number;
1019+
HidUniquePadConfig config;
1020+
} HidUniquePadConfigAtomicStorage;
1021+
1022+
/// HidUniquePadConfigLifo
1023+
typedef struct {
1024+
HidCommonLifoHeader header;
1025+
HidUniquePadConfigAtomicStorage storage[2];
1026+
} HidUniquePadConfigLifo;
1027+
1028+
/// HidUniquePadLifo
1029+
typedef struct {
1030+
HidUniquePadConfigLifo config_lifo;
1031+
HidAnalogStickCalibrationStateImplLifo analog_stick_calib_lifo[2];
1032+
HidSixAxisSensorUserCalibrationStateLifo sixaxis_calib_lifo;
1033+
HidUniquePadConfigMutex mutex;
1034+
} HidUniquePadLifo;
1035+
1036+
/// HidUniquePadSharedMemoryEntry
1037+
typedef struct {
1038+
HidUniquePadLifo lifo;
1039+
u8 padding[0x220];
1040+
} HidUniquePadSharedMemoryEntry;
1041+
1042+
/// HidUniquePadSharedMemoryFormat
1043+
typedef struct {
1044+
HidUniquePadSharedMemoryEntry entries[16];
1045+
} HidUniquePadSharedMemoryFormat;
1046+
1047+
// End HidUniquePad
1048+
7581049
// Begin HidNpad
7591050

7601051
/// Npad colors.
@@ -1080,12 +1371,15 @@ typedef struct HidSharedMemory {
10801371
HidTouchScreenSharedMemoryFormat touchscreen;
10811372
HidMouseSharedMemoryFormat mouse;
10821373
HidKeyboardSharedMemoryFormat keyboard;
1083-
u8 digitizer[0x1000]; ///< [10.0.0+] Digitizer [1.0.0-9.2.0] BasicXpad
1084-
u8 home_button[0x200];
1085-
u8 sleep_button[0x200];
1086-
u8 capture_button[0x200];
1087-
u8 input_detector[0x800];
1088-
u8 unique_pad[0x4000]; ///< [1.0.0-4.1.0] UniquePad
1374+
union {
1375+
HidBasicXpadSharedMemoryFormat basic_xpad; ///< [1.0.0-9.2.0] BasicXpad
1376+
HidDigitizerSharedMemoryFormat digitizer; ///< [10.0.0+] Digitizer
1377+
};
1378+
HidHomeButtonSharedMemoryFormat home_button;
1379+
HidSleepButtonSharedMemoryFormat sleep_button;
1380+
HidCaptureButtonSharedMemoryFormat capture_button;
1381+
HidInputDetectorSharedMemoryFormat input_detector;
1382+
HidUniquePadSharedMemoryFormat unique_pad; ///< [1.0.0-4.1.0] UniquePad
10891383
HidNpadSharedMemoryFormat npad;
10901384
HidGestureSharedMemoryFormat gesture;
10911385
HidConsoleSixAxisSensor console_six_axis_sensor; ///< [5.0.0+] ConsoleSixAxisSensor
@@ -1245,6 +1539,48 @@ NX_CONSTEXPR bool hidKeyboardStateGetKey(const HidKeyboardState *state, HidKeybo
12451539

12461540
///@}
12471541

1542+
///@name HomeButton
1543+
///@{
1544+
1545+
/**
1546+
* @brief Gets \ref HidHomeButtonState.
1547+
* @note Home button shmem must be activated with \ref hidsysActivateHomeButton
1548+
* @param[out] states Output array of \ref HidHomeButtonState.
1549+
* @param[in] count Size of the states array in entries.
1550+
* @return Total output entries.
1551+
*/
1552+
size_t hidGetHomeButtonStates(HidHomeButtonState *states, size_t count);
1553+
1554+
///@}
1555+
1556+
///@name SleepButton
1557+
///@{
1558+
1559+
/**
1560+
* @brief Gets \ref HidSleepButtonState.
1561+
* @note Sleep button shmem must be activated with \ref hidsysActivateSleepButton
1562+
* @param[out] states Output array of \ref HidSleepButtonState.
1563+
* @param[in] count Size of the states array in entries.
1564+
* @return Total output entries.
1565+
*/
1566+
size_t hidGetSleepButtonStates(HidSleepButtonState *states, size_t count);
1567+
1568+
///@}
1569+
1570+
///@name CaptureButton
1571+
///@{
1572+
1573+
/**
1574+
* @brief Gets \ref HidCaptureButtonState.
1575+
* @note Capture button shmem must be activated with \ref hidsysActivateCaptureButton
1576+
* @param[out] states Output array of \ref HidCaptureButtonState.
1577+
* @param[in] count Size of the states array in entries.
1578+
* @return Total output entries.
1579+
*/
1580+
size_t hidGetCaptureButtonStates(HidCaptureButtonState *states, size_t count);
1581+
1582+
///@}
1583+
12481584
///@name Npad
12491585
///@{
12501586

0 commit comments

Comments
 (0)