hid: Introduce HidNpadIdType, see details:

- Replaced most usages of HidControllerID with HidNpadIdType
- HidControllerID still exists for now, and the following functions
  keep accepting it for compatibility with most homebrew:
  - hidIsControllerConnected
  - hidKeysHeld/Down/Up
  - hidJoystickRead
  - hidSixAxisSensorValuesRead
- hidControllerIDTo/FromOfficial renamed to ToNpadIdType/FromNpadIdType
- Updated some comments that were left untouched during previous hid refactoring
- Partial internal refactor of hidGetNpadStates*
This commit is contained in:
fincs 2020-11-18 17:07:12 +01:00
parent 40e5b08f70
commit 0640c9da76
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
12 changed files with 243 additions and 312 deletions

View File

@ -79,7 +79,7 @@ typedef struct {
typedef struct { typedef struct {
s8 player_count; ///< playerCount. s8 player_count; ///< playerCount.
u8 pad[3]; ///< Padding. u8 pad[3]; ///< Padding.
u32 selected_id; ///< \ref HidControllerID, selectedId. u32 selected_id; ///< \ref HidNpadIdType, selectedId.
} HidLaControllerSupportResultInfo; } HidLaControllerSupportResultInfo;
/// Struct for the applet output storage. /// Struct for the applet output storage.
@ -111,7 +111,7 @@ void hidLaCreateControllerFirmwareUpdateArg(HidLaControllerFirmwareUpdateArg *ar
* @param[in] str Input ExplainText UTF-8 string, max length is 0x80 excluding NUL-terminator. * @param[in] str Input ExplainText UTF-8 string, max length is 0x80 excluding NUL-terminator.
+ @oaram[in] id Player controller, must be <8. + @oaram[in] id Player controller, must be <8.
*/ */
Result hidLaSetExplainText(HidLaControllerSupportArg *arg, const char *str, HidControllerID id); Result hidLaSetExplainText(HidLaControllerSupportArg *arg, const char *str, HidNpadIdType id);
/** /**
* @brief Launches the applet for ControllerSupport. * @brief Launches the applet for ControllerSupport.

View File

@ -74,9 +74,9 @@ typedef struct {
/** /**
* @brief Creates a \ref RingCon object, and handles the various initialization for it. * @brief Creates a \ref RingCon object, and handles the various initialization for it.
* @param c \ref RingCon * @param c \ref RingCon
* @param[in] id \ref HidControllerID. A Ring-Con must be attached to this controller. * @param[in] id \ref HidNpadIdType. A Ring-Con must be attached to this controller.
*/ */
Result ringconCreate(RingCon *c, HidControllerID id); Result ringconCreate(RingCon *c, HidNpadIdType id);
/** /**
* @brief Close a \ref RingCon. * @brief Close a \ref RingCon.

View File

@ -214,6 +214,20 @@ typedef enum {
KBD_MEDIA_CALC = 0xfb KBD_MEDIA_CALC = 0xfb
} HidKeyboardScancode; } HidKeyboardScancode;
/// HID controller IDs
typedef enum {
HidNpadIdType_No1 = 0, ///< Player 1 controller
HidNpadIdType_No2 = 1, ///< Player 2 controller
HidNpadIdType_No3 = 2, ///< Player 3 controller
HidNpadIdType_No4 = 3, ///< Player 4 controller
HidNpadIdType_No5 = 4, ///< Player 5 controller
HidNpadIdType_No6 = 5, ///< Player 6 controller
HidNpadIdType_No7 = 6, ///< Player 7 controller
HidNpadIdType_No8 = 7, ///< Player 8 controller
HidNpadIdType_Other = 0x10, ///< Other controller
HidNpadIdType_Handheld = 0x20, ///< Handheld mode controls
} HidNpadIdType;
/// HID controller styles /// HID controller styles
typedef enum { typedef enum {
HidNpadStyleTag_NpadFullKey = BIT(0), ///< Pro Controller HidNpadStyleTag_NpadFullKey = BIT(0), ///< Pro Controller
@ -808,15 +822,15 @@ typedef struct HidVibrationValue {
float freq_high; ///< High Band frequency in Hz. float freq_high; ///< High Band frequency in Hz.
} HidVibrationValue; } HidVibrationValue;
static inline u32 hidControllerIDToOfficial(HidControllerID id) { static inline HidNpadIdType hidControllerIDToNpadIdType(HidControllerID id) {
if (id < CONTROLLER_HANDHELD) return id; if (id <= CONTROLLER_PLAYER_8) return (HidNpadIdType)id;
if (id == CONTROLLER_HANDHELD) return 0x20; if (id == CONTROLLER_HANDHELD) return HidNpadIdType_Handheld;
return 0x10;//For CONTROLLER_UNKNOWN and invalid values return this. return HidNpadIdType_Other;//For CONTROLLER_UNKNOWN and invalid values return this.
} }
static inline HidControllerID hidControllerIDFromOfficial(u32 id) { static inline HidControllerID hidControllerIDFromNpadIdType(HidNpadIdType id) {
if (id < 8) return (HidControllerID)id; if (id <= HidNpadIdType_No8) return (HidControllerID)id;
if (id == 0x20) return CONTROLLER_HANDHELD; if (id == HidNpadIdType_Handheld) return CONTROLLER_HANDHELD;
return CONTROLLER_UNKNOWN; return CONTROLLER_UNKNOWN;
} }
@ -837,52 +851,52 @@ void* hidGetSharedmemAddr(void);
void hidScanInput(void); void hidScanInput(void);
/// Gets a bitfield of \ref HidNpadStyleTag for the specified controller. /// Gets a bitfield of \ref HidNpadStyleTag for the specified controller.
u32 hidGetNpadStyleSet(u32 id); u32 hidGetNpadStyleSet(HidNpadIdType id);
/// Gets the \ref HidNpadJoyAssignmentMode for the specified controller. /// Gets the \ref HidNpadJoyAssignmentMode for the specified controller.
HidNpadJoyAssignmentMode hidGetNpadJoyAssignment(u32 id); HidNpadJoyAssignmentMode hidGetNpadJoyAssignment(HidNpadIdType id);
/// Gets the main \ref HidNpadControllerColor for the specified controller. /// Gets the main \ref HidNpadControllerColor for the specified controller.
Result hidGetNpadControllerColorSingle(u32 id, HidNpadControllerColor *color); Result hidGetNpadControllerColorSingle(HidNpadIdType id, HidNpadControllerColor *color);
/// Gets the left/right \ref HidNpadControllerColor for the specified controller (Joy-Con pair in dual mode). /// Gets the left/right \ref HidNpadControllerColor for the specified controller (Joy-Con pair in dual mode).
Result hidGetNpadControllerColorSplit(u32 id, HidNpadControllerColor *color_left, HidNpadControllerColor *color_right); Result hidGetNpadControllerColorSplit(HidNpadIdType id, HidNpadControllerColor *color_left, HidNpadControllerColor *color_right);
/// Gets the \ref HidDeviceTypeBits for the specified controller. /// Gets the \ref HidDeviceTypeBits for the specified controller.
u32 hidGetNpadDeviceType(u32 id); u32 hidGetNpadDeviceType(HidNpadIdType id);
/// Gets the \ref HidNpadSystemProperties for the specified controller. /// Gets the \ref HidNpadSystemProperties for the specified controller.
void hidGetNpadSystemProperties(u32 id, HidNpadSystemProperties *out); void hidGetNpadSystemProperties(HidNpadIdType id, HidNpadSystemProperties *out);
/// Gets the \ref HidNpadSystemButtonProperties for the specified controller. /// Gets the \ref HidNpadSystemButtonProperties for the specified controller.
void hidGetNpadSystemButtonProperties(u32 id, HidNpadSystemButtonProperties *out); void hidGetNpadSystemButtonProperties(HidNpadIdType id, HidNpadSystemButtonProperties *out);
/// Gets the main \ref HidPowerInfo for the specified controller. /// Gets the main \ref HidPowerInfo for the specified controller.
void hidGetNpadPowerInfoSingle(u32 id, HidPowerInfo *info); void hidGetNpadPowerInfoSingle(HidNpadIdType id, HidPowerInfo *info);
/// Gets the left/right \ref HidPowerInfo for the specified controller (Joy-Con pair in dual mode). /// Gets the left/right \ref HidPowerInfo for the specified controller (Joy-Con pair in dual mode).
void hidGetNpadPowerInfoSplit(u32 id, HidPowerInfo *info_left, HidPowerInfo *info_right); void hidGetNpadPowerInfoSplit(HidNpadIdType id, HidPowerInfo *info_left, HidPowerInfo *info_right);
/// Gets a bitfield of AppletFooterUiAttributes for the specified Npad. /// Gets a bitfield of AppletFooterUiAttributes for the specified Npad.
/// Only available on [9.0.0+]. /// Only available on [9.0.0+].
u32 hidGetAppletFooterUiAttributesSet(u32 id); u32 hidGetAppletFooterUiAttributesSet(HidNpadIdType id);
/// Gets AppletFooterUiTypes for the specified Npad. /// Gets AppletFooterUiTypes for the specified Npad.
/// Only available on [9.0.0+]. /// Only available on [9.0.0+].
u8 hidGetAppletFooterUiTypes(u32 id); u8 hidGetAppletFooterUiTypes(HidNpadIdType id);
void hidGetNpadStatesFullKey(u32 id, HidNpadFullKeyState *states, size_t count, size_t *total_out); void hidGetNpadStatesFullKey(HidNpadIdType id, HidNpadFullKeyState *states, size_t count, size_t *total_out);
void hidGetNpadStatesHandheld(u32 id, HidNpadHandheldState *states, size_t count, size_t *total_out); void hidGetNpadStatesHandheld(HidNpadIdType id, HidNpadHandheldState *states, size_t count, size_t *total_out);
void hidGetNpadStatesJoyDual(u32 id, HidNpadJoyDualState *states, size_t count, size_t *total_out); void hidGetNpadStatesJoyDual(HidNpadIdType id, HidNpadJoyDualState *states, size_t count, size_t *total_out);
void hidGetNpadStatesJoyLeft(u32 id, HidNpadJoyLeftState *states, size_t count, size_t *total_out); void hidGetNpadStatesJoyLeft(HidNpadIdType id, HidNpadJoyLeftState *states, size_t count, size_t *total_out);
void hidGetNpadStatesJoyRight(u32 id, HidNpadJoyRightState *states, size_t count, size_t *total_out); void hidGetNpadStatesJoyRight(HidNpadIdType id, HidNpadJoyRightState *states, size_t count, size_t *total_out);
void hidGetNpadStatesGc(u32 id, HidNpadGcState *states, size_t count, size_t *total_out); void hidGetNpadStatesGc(HidNpadIdType id, HidNpadGcState *states, size_t count, size_t *total_out);
void hidGetNpadStatesPalma(u32 id, HidNpadPalmaState *states, size_t count, size_t *total_out); void hidGetNpadStatesPalma(HidNpadIdType id, HidNpadPalmaState *states, size_t count, size_t *total_out);
void hidGetNpadStatesLark(u32 id, HidNpadLarkState *states, size_t count, size_t *total_out); void hidGetNpadStatesLark(HidNpadIdType id, HidNpadLarkState *states, size_t count, size_t *total_out);
void hidGetNpadStatesHandheldLark(u32 id, HidNpadHandheldLarkState *states, size_t count, size_t *total_out); void hidGetNpadStatesHandheldLark(HidNpadIdType id, HidNpadHandheldLarkState *states, size_t count, size_t *total_out);
void hidGetNpadStatesLucia(u32 id, HidNpadLuciaState *states, size_t count, size_t *total_out); void hidGetNpadStatesLucia(HidNpadIdType id, HidNpadLuciaState *states, size_t count, size_t *total_out);
void hidGetNpadStatesSystemExt(u32 id, HidNpadSystemExtState *states, size_t count, size_t *total_out); void hidGetNpadStatesSystemExt(HidNpadIdType id, HidNpadSystemExtState *states, size_t count, size_t *total_out);
void hidGetNpadStatesSystem(u32 id, HidNpadSystemState *states, size_t count, size_t *total_out); void hidGetNpadStatesSystem(HidNpadIdType id, HidNpadSystemState *states, size_t count, size_t *total_out);
bool hidIsControllerConnected(HidControllerID id); bool hidIsControllerConnected(HidControllerID id);
@ -938,14 +952,14 @@ Result hidSetSupportedNpadStyleSet(u32 style_set);
/// Gets which controller styles are supported, bitfield of \ref HidNpadStyleTag. /// Gets which controller styles are supported, bitfield of \ref HidNpadStyleTag.
Result hidGetSupportedNpadStyleSet(u32 *style_set); Result hidGetSupportedNpadStyleSet(u32 *style_set);
/// This is automatically called with CONTROLLER_PLAYER_{1-8} and CONTROLLER_HANDHELD in \ref hidInitialize. /// This is automatically called with HidNpadIdType_No{1-8} and HidNpadIdType_Handheld in \ref hidInitialize.
/// count must be <=10. Each entry in buf must be CONTROLLER_PLAYER_{1-8} or CONTROLLER_HANDHELD. /// count must be <=10. Each entry in buf must be HidNpadIdType_No{1-8} or HidNpadIdType_Handheld.
Result hidSetSupportedNpadIdType(const HidControllerID *buf, size_t count); Result hidSetSupportedNpadIdType(const HidNpadIdType *buf, size_t count);
/// Gets an event with the specified autoclear for the input controller. /// Gets an event with the specified autoclear for the input controller.
/// The user *must* close the event when finished with it / before the app exits. /// The user *must* close the event when finished with it / before the app exits.
/// This is signaled when the \ref hidGetControllerType output is updated for the controller. /// This is signaled when the \ref hidGetNpadStyleSet output is updated for the controller.
Result hidAcquireNpadStyleSetUpdateEventHandle(HidControllerID id, Event* out_event, bool autoclear); Result hidAcquireNpadStyleSetUpdateEventHandle(HidNpadIdType id, Event* out_event, bool autoclear);
/// Sets the hold-type, see \ref HidJoyHoldType. /// Sets the hold-type, see \ref HidJoyHoldType.
Result hidSetNpadJoyHoldType(HidJoyHoldType type); Result hidSetNpadJoyHoldType(HidJoyHoldType type);
@ -953,23 +967,23 @@ Result hidSetNpadJoyHoldType(HidJoyHoldType type);
/// Gets the hold-type, see \ref HidJoyHoldType. /// Gets the hold-type, see \ref HidJoyHoldType.
Result hidGetNpadJoyHoldType(HidJoyHoldType *type); Result hidGetNpadJoyHoldType(HidJoyHoldType *type);
/// Use this if you want to use a single joy-con as a dedicated CONTROLLER_PLAYER_*. /// Use this if you want to use a single joy-con as a dedicated HidNpadIdType_No*.
/// When used, both joy-cons in a pair should be used with this (CONTROLLER_PLAYER_1 and CONTROLLER_PLAYER_2 for example). /// When used, both joy-cons in a pair should be used with this (HidNpadIdType_No1 and HidNpadIdType_No2 for example).
/// id must be CONTROLLER_PLAYER_*. /// id must be HidNpadIdType_No*.
Result hidSetNpadJoyAssignmentModeSingleByDefault(HidControllerID id); Result hidSetNpadJoyAssignmentModeSingleByDefault(HidNpadIdType id);
/// Use this if you want to use a pair of joy-cons as a single CONTROLLER_PLAYER_*. Only necessary if you want to use this mode in your application after \ref hidSetNpadJoyAssignmentModeSingleByDefault was used with this pair of joy-cons. /// Use this if you want to use a pair of joy-cons as a single HidNpadIdType_No*. Only necessary if you want to use this mode in your application after \ref hidSetNpadJoyAssignmentModeSingleByDefault was used with this pair of joy-cons.
/// Used automatically during app startup/exit for all controllers. /// Used automatically during app startup/exit for all controllers.
/// When used, both joy-cons in a pair should be used with this (CONTROLLER_PLAYER_1 and CONTROLLER_PLAYER_2 for example). /// When used, both joy-cons in a pair should be used with this (HidNpadIdType_No1 and HidNpadIdType_No2 for example).
/// id must be CONTROLLER_PLAYER_*. /// id must be HidNpadIdType_No*.
Result hidSetNpadJoyAssignmentModeDual(HidControllerID id); Result hidSetNpadJoyAssignmentModeDual(HidNpadIdType id);
/// Merge two single joy-cons into a dual-mode controller. Use this after \ref hidSetNpadJoyAssignmentModeDual, when \ref hidSetNpadJoyAssignmentModeSingleByDefault was previously used (this includes using this manually at application exit). /// Merge two single joy-cons into a dual-mode controller. Use this after \ref hidSetNpadJoyAssignmentModeDual, when \ref hidSetNpadJoyAssignmentModeSingleByDefault was previously used (this includes using this manually at application exit).
/// To be successful, id0/id1 must correspond to controller types TYPE_JOYCON_LEFT/TYPE_JOYCON_RIGHT, or TYPE_JOYCON_RIGHT/TYPE_JOYCON_LEFT. /// To be successful, id0/id1 must correspond to controllers supporting styles HidNpadStyleTag_NpadJoyLeft/Right, or HidNpadStyleTag_NpadJoyRight/Left.
/// If successful, the id of the resulting dual controller is set to id0. /// If successful, the id of the resulting dual controller is set to id0.
Result hidMergeSingleJoyAsDualJoy(HidControllerID id0, HidControllerID id1); Result hidMergeSingleJoyAsDualJoy(HidNpadIdType id0, HidNpadIdType id1);
Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, s32 total_handles, HidControllerID id, HidNpadStyleTag style); Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style);
/// Gets HidVibrationDeviceInfo for the specified VibrationDeviceHandle. /// Gets HidVibrationDeviceInfo for the specified VibrationDeviceHandle.
Result hidGetVibrationDeviceInfo(const u32 *VibrationDeviceHandle, HidVibrationDeviceInfo *VibrationDeviceInfo); Result hidGetVibrationDeviceInfo(const u32 *VibrationDeviceHandle, HidVibrationDeviceInfo *VibrationDeviceInfo);
@ -993,7 +1007,7 @@ Result hidSendVibrationValues(const u32 *VibrationDeviceHandles, HidVibrationVal
Result hidIsVibrationDeviceMounted(const u32 *VibrationDeviceHandle, bool *flag); Result hidIsVibrationDeviceMounted(const u32 *VibrationDeviceHandle, bool *flag);
/// Gets SixAxisSensorHandles. total_handles==2 can only be used with ::HidNpadStyleTag_NpadJoyDual. /// Gets SixAxisSensorHandles. total_handles==2 can only be used with ::HidNpadStyleTag_NpadJoyDual.
Result hidGetSixAxisSensorHandles(u32 *SixAxisSensorHandles, s32 total_handles, HidControllerID id, HidNpadStyleTag style); Result hidGetSixAxisSensorHandles(u32 *SixAxisSensorHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style);
/// Starts the SixAxisSensor for the specified handle. /// Starts the SixAxisSensor for the specified handle.
Result hidStartSixAxisSensor(u32 SixAxisSensorHandle); Result hidStartSixAxisSensor(u32 SixAxisSensorHandle);
@ -1036,5 +1050,5 @@ Result hidGetGyroBias(UtilFloat3 *out);
/// Gets the \ref HidNpadInterfaceType for the specified controller. /// Gets the \ref HidNpadInterfaceType for the specified controller.
/// Only available on [4.0.0+]. /// Only available on [4.0.0+].
Result hidGetNpadInterfaceType(HidControllerID id, u8 *out); Result hidGetNpadInterfaceType(HidNpadIdType id, u8 *out);

View File

@ -154,10 +154,10 @@ void* hidbusGetSharedmemAddr(void);
* @brief GetBusHandle * @brief GetBusHandle
* @param[out] handle \ref HidbusBusHandle * @param[out] handle \ref HidbusBusHandle
* @param[out] flag Output flag indicating whether the handle is valid. * @param[out] flag Output flag indicating whether the handle is valid.
* @param[in] id \ref HidControllerID * @param[in] id \ref HidNpadIdType
* @param[in] bus_type \ref HidbusBusType * @param[in] bus_type \ref HidbusBusType
*/ */
Result hidbusGetBusHandle(HidbusBusHandle *handle, bool *flag, HidControllerID id, HidbusBusType bus_type); Result hidbusGetBusHandle(HidbusBusHandle *handle, bool *flag, HidNpadIdType id, HidbusBusType bus_type);
/** /**
* @brief Initialize * @brief Initialize

View File

@ -170,7 +170,7 @@ Result hidsysGetSupportedNpadStyleSetOfCallerApplet(u32 *out);
* @param Max number of entries for the UniquePadIds array. * @param Max number of entries for the UniquePadIds array.
* @param total_entries Total output array entries. Optional, can be NULL. * @param total_entries Total output array entries. Optional, can be NULL.
*/ */
Result hidsysGetUniquePadsFromNpad(HidControllerID id, u64 *UniquePadIds, s32 count, s32 *total_entries); Result hidsysGetUniquePadsFromNpad(HidNpadIdType id, u64 *UniquePadIds, s32 count, s32 *total_entries);
/** /**
* @brief EnableAppletToGetInput * @brief EnableAppletToGetInput

View File

@ -391,7 +391,7 @@ Service* irsGetServiceSession(void);
void* irsGetSharedmemAddr(void); void* irsGetSharedmemAddr(void);
/// Gets the \ref IrsIrCameraHandle for the specified controller. /// Gets the \ref IrsIrCameraHandle for the specified controller.
Result irsGetIrCameraHandle(IrsIrCameraHandle *handle, HidControllerID id); Result irsGetIrCameraHandle(IrsIrCameraHandle *handle, HidNpadIdType id);
/// GetIrCameraStatus /// GetIrCameraStatus
Result irsGetIrCameraStatus(IrsIrCameraHandle handle, IrsIrCameraStatus *out); Result irsGetIrCameraStatus(IrsIrCameraHandle handle, IrsIrCameraStatus *out);

View File

@ -60,7 +60,7 @@ static Result _hidLaShowControllerSupportCore(HidLaControllerSupportResultInfo *
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
if (result_info) { if (result_info) {
*result_info = res.info; *result_info = res.info;
result_info->selected_id = hidControllerIDFromOfficial(result_info->selected_id); result_info->selected_id = result_info->selected_id;
} }
if (res.res != 0) { if (res.res != 0) {
@ -119,7 +119,7 @@ void hidLaCreateControllerFirmwareUpdateArg(HidLaControllerFirmwareUpdateArg *ar
memset(arg, 0, sizeof(*arg)); memset(arg, 0, sizeof(*arg));
} }
Result hidLaSetExplainText(HidLaControllerSupportArg *arg, const char *str, HidControllerID id) { Result hidLaSetExplainText(HidLaControllerSupportArg *arg, const char *str, HidNpadIdType id) {
if (id >= 8) if (id >= 8)
return MAKERESULT(Module_Libnx, LibnxError_BadInput); return MAKERESULT(Module_Libnx, LibnxError_BadInput);

View File

@ -52,11 +52,11 @@ static void _ringconSetErrorFlag(RingCon *c, RingConErrorFlag flag, bool value)
c->error_flags &= ~BIT(flag); c->error_flags &= ~BIT(flag);
} }
Result ringconCreate(RingCon *c, HidControllerID id) { Result ringconCreate(RingCon *c, HidNpadIdType id) {
Result rc=0; Result rc=0;
bool handleflag=0; bool handleflag=0;
HidbusBusType bus_type; HidbusBusType bus_type;
u32 style_set = hidGetNpadStyleSet(hidControllerIDToOfficial(id)); u32 style_set = hidGetNpadStyleSet(id);
u32 cmd = 0x00020101; u32 cmd = 0x00020101;
memset(c, 0, sizeof(*c)); memset(c, 0, sizeof(*c));

View File

@ -50,16 +50,17 @@ static Result _hidSetDualModeAll(void);
NX_GENERATE_SERVICE_GUARD(hid); NX_GENERATE_SERVICE_GUARD(hid);
Result _hidInitialize(void) { Result _hidInitialize(void) {
HidControllerID idbuf[9] = { static const HidNpadIdType idbuf[9] = {
CONTROLLER_PLAYER_1, HidNpadIdType_No1,
CONTROLLER_PLAYER_2, HidNpadIdType_No2,
CONTROLLER_PLAYER_3, HidNpadIdType_No3,
CONTROLLER_PLAYER_4, HidNpadIdType_No4,
CONTROLLER_PLAYER_5, HidNpadIdType_No5,
CONTROLLER_PLAYER_6, HidNpadIdType_No6,
CONTROLLER_PLAYER_7, HidNpadIdType_No7,
CONTROLLER_PLAYER_8, HidNpadIdType_No8,
CONTROLLER_HANDHELD}; HidNpadIdType_Handheld,
};
Result rc=0; Result rc=0;
Handle sharedmem_handle; Handle sharedmem_handle;
@ -86,7 +87,7 @@ Result _hidInitialize(void) {
rc = hidSetSupportedNpadStyleSet(HidNpadStyleTag_NpadFullKey | HidNpadStyleTag_NpadHandheld | HidNpadStyleTag_NpadJoyDual | HidNpadStyleTag_NpadJoyLeft | HidNpadStyleTag_NpadJoyRight | HidNpadStyleTag_NpadSystemExt | HidNpadStyleTag_NpadSystem); rc = hidSetSupportedNpadStyleSet(HidNpadStyleTag_NpadFullKey | HidNpadStyleTag_NpadHandheld | HidNpadStyleTag_NpadJoyDual | HidNpadStyleTag_NpadJoyLeft | HidNpadStyleTag_NpadJoyRight | HidNpadStyleTag_NpadSystemExt | HidNpadStyleTag_NpadSystem);
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
rc = hidSetSupportedNpadIdType(idbuf, 9); rc = hidSetSupportedNpadIdType(idbuf, sizeof(idbuf)/sizeof(*idbuf));
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
rc = _hidSetDualModeAll(); rc = _hidSetDualModeAll();
@ -209,7 +210,7 @@ void hidScanInput(void) {
} }
for (u32 i = 0; i < 10; i++) { for (u32 i = 0; i < 10; i++) {
u32 id = hidControllerIDToOfficial(i); HidNpadIdType id = hidControllerIDToNpadIdType(i);
u32 style_set = hidGetNpadStyleSet(id); u32 style_set = hidGetNpadStyleSet(id);
size_t total_out=0; size_t total_out=0;
@ -308,64 +309,56 @@ void hidScanInput(void) {
rwlockWriteUnlock(&g_hidLock); rwlockWriteUnlock(&g_hidLock);
} }
static Result _hidVerifyNpadIdType(u32 id) { static Result _hidGetNpadInternalState(HidNpadIdType id, HidNpad **npad) {
if (id >= 0x8 && (id!=0x10 && id!=0x20))
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
return 0;
}
static HidNpad *_hidNpadSharedmemGetInternalState(u32 id) {
if (id >= 0x8) id = id==0x10 ? 0x9 : 0x8;
HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr(); HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr();
if (sharedmem == NULL) return NULL; if (sharedmem == NULL)
return &sharedmem->npad[id]; return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
}
u32 hidGetNpadStyleSet(u32 id) { if (id <= HidNpadIdType_No8) {
Result rc = _hidVerifyNpadIdType(id); *npad = &sharedmem->npad[id];
u32 tmp=0; return 0;
if (R_SUCCEEDED(rc)) {
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else
tmp = atomic_load_explicit(&npad->header.style_set, memory_order_acquire);
} }
else if (id == HidNpadIdType_Handheld) {
if (R_FAILED(rc)) diagAbortWithResult(rc); *npad = &sharedmem->npad[8];
return tmp; return 0;
}
else if (id == HidNpadIdType_Other) {
*npad = &sharedmem->npad[9];
return 0;
}
else
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
} }
HidNpadJoyAssignmentMode hidGetNpadJoyAssignment(u32 id) { u32 hidGetNpadStyleSet(HidNpadIdType id) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
Result rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc))
diagAbortWithResult(rc);
return atomic_load_explicit(&npad->header.style_set, memory_order_acquire);
}
HidNpadJoyAssignmentMode hidGetNpadJoyAssignment(HidNpadIdType id) {
HidNpad *npad = NULL;
Result rc = _hidGetNpadInternalState(id, &npad);
HidNpadJoyAssignmentMode tmp=0; HidNpadJoyAssignmentMode tmp=0;
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else {
tmp = atomic_load_explicit(&npad->header.npad_joy_assignment_mode, memory_order_acquire); tmp = atomic_load_explicit(&npad->header.npad_joy_assignment_mode, memory_order_acquire);
if (tmp != HidNpadJoyAssignmentMode_Dual && tmp != HidNpadJoyAssignmentMode_Single) if (tmp != HidNpadJoyAssignmentMode_Dual && tmp != HidNpadJoyAssignmentMode_Single)
rc = MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen); rc = MAKERESULT(Module_Libnx, LibnxError_ShouldNotHappen);
} }
}
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
return tmp; return tmp;
} }
Result hidGetNpadControllerColorSingle(u32 id, HidNpadControllerColor *color) { Result hidGetNpadControllerColorSingle(HidNpadIdType id, HidNpadControllerColor *color) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
Result rc = _hidGetNpadInternalState(id, &npad);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else {
u32 tmp = npad->header.single_colors_descriptor; u32 tmp = npad->header.single_colors_descriptor;
if (tmp==2) rc = MAKERESULT(202, 604); if (tmp==2) rc = MAKERESULT(202, 604);
else if (tmp==1) rc = MAKERESULT(202, 603); else if (tmp==1) rc = MAKERESULT(202, 603);
@ -374,19 +367,15 @@ Result hidGetNpadControllerColorSingle(u32 id, HidNpadControllerColor *color) {
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
*color = npad->header.single_colors; *color = npad->header.single_colors;
} }
}
return rc; return rc;
} }
Result hidGetNpadControllerColorSplit(u32 id, HidNpadControllerColor *color_left, HidNpadControllerColor *color_right) { Result hidGetNpadControllerColorSplit(HidNpadIdType id, HidNpadControllerColor *color_left, HidNpadControllerColor *color_right) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
Result rc = _hidGetNpadInternalState(id, &npad);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else {
u32 tmp = npad->header.split_colors_descriptor; u32 tmp = npad->header.split_colors_descriptor;
if (tmp==2) rc = MAKERESULT(202, 604); if (tmp==2) rc = MAKERESULT(202, 604);
else if (tmp==1) rc = MAKERESULT(202, 603); else if (tmp==1) rc = MAKERESULT(202, 603);
@ -397,53 +386,35 @@ Result hidGetNpadControllerColorSplit(u32 id, HidNpadControllerColor *color_left
*color_right = npad->header.right_colors; *color_right = npad->header.right_colors;
} }
} }
}
return rc; return rc;
} }
u32 hidGetNpadDeviceType(u32 id) { u32 hidGetNpadDeviceType(HidNpadIdType id) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
u32 tmp=0; Result rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc))
diagAbortWithResult(rc);
if (R_SUCCEEDED(rc)) { return atomic_load_explicit(&npad->deviceType, memory_order_acquire);
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else
tmp = atomic_load_explicit(&npad->deviceType, memory_order_acquire);
}
if (R_FAILED(rc)) diagAbortWithResult(rc);
return tmp;
} }
void hidGetNpadSystemProperties(u32 id, HidNpadSystemProperties *out) { void hidGetNpadSystemProperties(HidNpadIdType id, HidNpadSystemProperties *out) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
Result rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc))
diagAbortWithResult(rc);
if (R_SUCCEEDED(rc)) {
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else
*out = atomic_load_explicit(&npad->system_properties, memory_order_acquire); *out = atomic_load_explicit(&npad->system_properties, memory_order_acquire);
}
if (R_FAILED(rc)) diagAbortWithResult(rc);
} }
void hidGetNpadSystemButtonProperties(u32 id, HidNpadSystemButtonProperties *out) { void hidGetNpadSystemButtonProperties(HidNpadIdType id, HidNpadSystemButtonProperties *out) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
Result rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc))
diagAbortWithResult(rc);
if (R_SUCCEEDED(rc)) {
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else
*out = atomic_load_explicit(&npad->system_button_properties, memory_order_acquire); *out = atomic_load_explicit(&npad->system_button_properties, memory_order_acquire);
}
if (R_FAILED(rc)) diagAbortWithResult(rc);
} }
static void _hidGetNpadPowerInfo(HidNpad *npad, HidPowerInfo *info, u32 powerInfo, u32 i) { static void _hidGetNpadPowerInfo(HidNpad *npad, HidPowerInfo *info, u32 powerInfo, u32 i) {
@ -454,73 +425,47 @@ static void _hidGetNpadPowerInfo(HidNpad *npad, HidPowerInfo *info, u32 powerInf
info->powerConnected = (powerInfo & BIT(i+3)) != 0; info->powerConnected = (powerInfo & BIT(i+3)) != 0;
} }
void hidGetNpadPowerInfoSingle(u32 id, HidPowerInfo *info) { void hidGetNpadPowerInfoSingle(HidNpadIdType id, HidPowerInfo *info) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
Result rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc))
diagAbortWithResult(rc);
if (R_SUCCEEDED(rc)) {
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else {
HidNpadSystemProperties properties; HidNpadSystemProperties properties;
properties = atomic_load_explicit(&npad->system_properties, memory_order_acquire); properties = atomic_load_explicit(&npad->system_properties, memory_order_acquire);
_hidGetNpadPowerInfo(npad, info, properties.powerInfo, 0); _hidGetNpadPowerInfo(npad, info, properties.powerInfo, 0);
}
}
if (R_FAILED(rc)) diagAbortWithResult(rc);
} }
void hidGetNpadPowerInfoSplit(u32 id, HidPowerInfo *info_left, HidPowerInfo *info_right) { void hidGetNpadPowerInfoSplit(HidNpadIdType id, HidPowerInfo *info_left, HidPowerInfo *info_right) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
Result rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc))
diagAbortWithResult(rc);
if (R_SUCCEEDED(rc)) {
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else {
HidNpadSystemProperties properties; HidNpadSystemProperties properties;
properties = atomic_load_explicit(&npad->system_properties, memory_order_acquire); properties = atomic_load_explicit(&npad->system_properties, memory_order_acquire);
_hidGetNpadPowerInfo(npad, info_left, properties.powerInfo, 1); _hidGetNpadPowerInfo(npad, info_left, properties.powerInfo, 1);
_hidGetNpadPowerInfo(npad, info_right, properties.powerInfo, 2); _hidGetNpadPowerInfo(npad, info_right, properties.powerInfo, 2);
}
}
if (R_FAILED(rc)) diagAbortWithResult(rc);
} }
u32 hidGetAppletFooterUiAttributesSet(u32 id) { u32 hidGetAppletFooterUiAttributesSet(HidNpadIdType id) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
u32 tmp=0; Result rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc))
diagAbortWithResult(rc);
if (R_SUCCEEDED(rc)) { return atomic_load_explicit(&npad->applet_footer_ui_attribute, memory_order_acquire);
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else
tmp = atomic_load_explicit(&npad->applet_footer_ui_attribute, memory_order_acquire);
}
if (R_FAILED(rc)) diagAbortWithResult(rc);
return tmp;
} }
u8 hidGetAppletFooterUiTypes(u32 id) { u8 hidGetAppletFooterUiTypes(HidNpadIdType id) {
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
u32 tmp=0; Result rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc))
diagAbortWithResult(rc);
if (R_SUCCEEDED(rc)) { return atomic_load_explicit(&npad->applet_footer_ui_type, memory_order_acquire);
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
else
tmp = atomic_load_explicit(&npad->applet_footer_ui_type, memory_order_acquire);
}
if (R_FAILED(rc)) diagAbortWithResult(rc);
return tmp;
} }
static Result _hidGetStates(HidCommonStateHeader *header, void* in_states, void* states, size_t entrysize, size_t count, size_t *total_out) { static Result _hidGetStates(HidCommonStateHeader *header, void* in_states, void* states, size_t entrysize, size_t count, size_t *total_out) {
@ -558,57 +503,54 @@ static Result _hidGetStates(HidCommonStateHeader *header, void* in_states, void*
return 0; return 0;
} }
static Result _hidGetNpadStates(u32 id, u32 layout, HidNpadStateEntry *states, size_t count, size_t *total_out) { static Result _hidGetNpadStates(HidNpadIdType id, u32 layout, HidNpadStateEntry *states, size_t count, size_t *total_out) {
if (total_out) *total_out = 0; if (total_out) *total_out = 0;
Result rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
if (R_FAILED(rc)) return rc; Result rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc))
HidNpad *npad = _hidNpadSharedmemGetInternalState(id); return rc;
if (npad == NULL)
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
HidControllerLayout *states_buf = &npad->layouts[layout]; HidControllerLayout *states_buf = &npad->layouts[layout];
return _hidGetStates(&states_buf->header, states_buf->entries, states, sizeof(HidNpadStateEntry), count, total_out); return _hidGetStates(&states_buf->header, states_buf->entries, states, sizeof(HidNpadStateEntry), count, total_out);
} }
void hidGetNpadStatesFullKey(u32 id, HidNpadFullKeyState *states, size_t count, size_t *total_out) { void hidGetNpadStatesFullKey(HidNpadIdType id, HidNpadFullKeyState *states, size_t count, size_t *total_out) {
Result rc = _hidGetNpadStates(id, 0, states, count, total_out); Result rc = _hidGetNpadStates(id, 0, states, count, total_out);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
} }
void hidGetNpadStatesHandheld(u32 id, HidNpadHandheldState *states, size_t count, size_t *total_out) { void hidGetNpadStatesHandheld(HidNpadIdType id, HidNpadHandheldState *states, size_t count, size_t *total_out) {
Result rc = _hidGetNpadStates(id, 1, states, count, total_out); Result rc = _hidGetNpadStates(id, 1, states, count, total_out);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
} }
void hidGetNpadStatesJoyDual(u32 id, HidNpadJoyDualState *states, size_t count, size_t *total_out) { void hidGetNpadStatesJoyDual(HidNpadIdType id, HidNpadJoyDualState *states, size_t count, size_t *total_out) {
Result rc = _hidGetNpadStates(id, 2, states, count, total_out); Result rc = _hidGetNpadStates(id, 2, states, count, total_out);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
} }
void hidGetNpadStatesJoyLeft(u32 id, HidNpadJoyLeftState *states, size_t count, size_t *total_out) { void hidGetNpadStatesJoyLeft(HidNpadIdType id, HidNpadJoyLeftState *states, size_t count, size_t *total_out) {
Result rc = _hidGetNpadStates(id, 3, states, count, total_out); Result rc = _hidGetNpadStates(id, 3, states, count, total_out);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
} }
void hidGetNpadStatesJoyRight(u32 id, HidNpadJoyRightState *states, size_t count, size_t *total_out) { void hidGetNpadStatesJoyRight(HidNpadIdType id, HidNpadJoyRightState *states, size_t count, size_t *total_out) {
Result rc = _hidGetNpadStates(id, 4, states, count, total_out); Result rc = _hidGetNpadStates(id, 4, states, count, total_out);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
} }
void hidGetNpadStatesGc(u32 id, HidNpadGcState *states, size_t count, size_t *total_out) { void hidGetNpadStatesGc(HidNpadIdType id, HidNpadGcState *states, size_t count, size_t *total_out) {
HidNpadStateEntry tmp_entries[17]={0}; HidNpadStateEntry tmp_entries[17]={0};
HidNpadGcTriggerState tmp_entries_trigger[17]={0}; HidNpadGcTriggerState tmp_entries_trigger[17]={0};
@ -618,13 +560,10 @@ void hidGetNpadStatesGc(u32 id, HidNpadGcState *states, size_t count, size_t *to
Result rc = _hidGetNpadStates(id, 0, tmp_entries, count, &tmp_out); Result rc = _hidGetNpadStates(id, 0, tmp_entries, count, &tmp_out);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
rc = _hidVerifyNpadIdType(id); HidNpad *npad = NULL;
rc = _hidGetNpadInternalState(id, &npad);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
if (npad == NULL)
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized));
size_t tmp_out2=0; size_t tmp_out2=0;
rc = _hidGetStates(&npad->npad_gc_trigger_header, npad->npad_gc_trigger_state, tmp_entries_trigger, sizeof(HidNpadGcTriggerState), count, &tmp_out2); rc = _hidGetStates(&npad->npad_gc_trigger_header, npad->npad_gc_trigger_state, tmp_entries_trigger, sizeof(HidNpadGcTriggerState), count, &tmp_out2);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
@ -648,14 +587,14 @@ void hidGetNpadStatesGc(u32 id, HidNpadGcState *states, size_t count, size_t *to
} }
} }
void hidGetNpadStatesPalma(u32 id, HidNpadPalmaState *states, size_t count, size_t *total_out) { void hidGetNpadStatesPalma(HidNpadIdType id, HidNpadPalmaState *states, size_t count, size_t *total_out) {
Result rc = _hidGetNpadStates(id, 5, states, count, total_out); Result rc = _hidGetNpadStates(id, 5, states, count, total_out);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
// sdknso doesn't handle ControlPadRestriction with this. // sdknso doesn't handle ControlPadRestriction with this.
} }
void hidGetNpadStatesLark(u32 id, HidNpadLarkState *states, size_t count, size_t *total_out) { void hidGetNpadStatesLark(HidNpadIdType id, HidNpadLarkState *states, size_t count, size_t *total_out) {
HidNpadStateEntry tmp_entries[17]={0}; HidNpadStateEntry tmp_entries[17]={0};
if (total_out) *total_out = 0; if (total_out) *total_out = 0;
@ -666,9 +605,9 @@ void hidGetNpadStatesLark(u32 id, HidNpadLarkState *states, size_t count, size_t
memset(states, 0, sizeof(HidNpadLarkState) * tmp_out); memset(states, 0, sizeof(HidNpadLarkState) * tmp_out);
HidNpad *npad = _hidNpadSharedmemGetInternalState(id); HidNpad *npad = NULL;
if (npad == NULL) rc = _hidGetNpadInternalState(id, &npad);
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); if (R_FAILED(rc)) diagAbortWithResult(rc);
u32 unk = atomic_load_explicit(&npad->unk_x43E0, memory_order_acquire); u32 unk = atomic_load_explicit(&npad->unk_x43E0, memory_order_acquire);
if (!(unk>=1 && unk<=4)) unk = 0; if (!(unk>=1 && unk<=4)) unk = 0;
@ -689,7 +628,7 @@ void hidGetNpadStatesLark(u32 id, HidNpadLarkState *states, size_t count, size_t
} }
} }
void hidGetNpadStatesHandheldLark(u32 id, HidNpadHandheldLarkState *states, size_t count, size_t *total_out) { void hidGetNpadStatesHandheldLark(HidNpadIdType id, HidNpadHandheldLarkState *states, size_t count, size_t *total_out) {
HidNpadStateEntry tmp_entries[17]={0}; HidNpadStateEntry tmp_entries[17]={0};
if (total_out) *total_out = 0; if (total_out) *total_out = 0;
@ -700,9 +639,9 @@ void hidGetNpadStatesHandheldLark(u32 id, HidNpadHandheldLarkState *states, size
memset(states, 0, sizeof(HidNpadHandheldLarkState) * tmp_out); memset(states, 0, sizeof(HidNpadHandheldLarkState) * tmp_out);
HidNpad *npad = _hidNpadSharedmemGetInternalState(id); HidNpad *npad = NULL;
if (npad == NULL) rc = _hidGetNpadInternalState(id, &npad);
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); if (R_FAILED(rc)) diagAbortWithResult(rc);
u32 unk0 = atomic_load_explicit(&npad->unk_x43E0, memory_order_acquire); u32 unk0 = atomic_load_explicit(&npad->unk_x43E0, memory_order_acquire);
if (!(unk0>=1 && unk0<=4)) unk0 = 0; if (!(unk0>=1 && unk0<=4)) unk0 = 0;
@ -726,7 +665,7 @@ void hidGetNpadStatesHandheldLark(u32 id, HidNpadHandheldLarkState *states, size
} }
} }
void hidGetNpadStatesLucia(u32 id, HidNpadLuciaState *states, size_t count, size_t *total_out) { void hidGetNpadStatesLucia(HidNpadIdType id, HidNpadLuciaState *states, size_t count, size_t *total_out) {
HidNpadStateEntry tmp_entries[17]={0}; HidNpadStateEntry tmp_entries[17]={0};
if (total_out) *total_out = 0; if (total_out) *total_out = 0;
@ -737,9 +676,9 @@ void hidGetNpadStatesLucia(u32 id, HidNpadLuciaState *states, size_t count, size
memset(states, 0, sizeof(HidNpadLuciaState) * tmp_out); memset(states, 0, sizeof(HidNpadLuciaState) * tmp_out);
HidNpad *npad = _hidNpadSharedmemGetInternalState(id); HidNpad *npad = NULL;
if (npad == NULL) rc = _hidGetNpadInternalState(id, &npad);
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); if (R_FAILED(rc)) diagAbortWithResult(rc);
u32 unk = atomic_load_explicit(&npad->unk_x43E8, memory_order_acquire); u32 unk = atomic_load_explicit(&npad->unk_x43E8, memory_order_acquire);
if (!(unk>=1 && unk<=3)) unk = 0; if (!(unk>=1 && unk<=3)) unk = 0;
@ -760,14 +699,14 @@ void hidGetNpadStatesLucia(u32 id, HidNpadLuciaState *states, size_t count, size
} }
} }
void hidGetNpadStatesSystemExt(u32 id, HidNpadSystemExtState *states, size_t count, size_t *total_out) { void hidGetNpadStatesSystemExt(HidNpadIdType id, HidNpadSystemExtState *states, size_t count, size_t *total_out) {
Result rc = _hidGetNpadStates(id, 6, states, count, total_out); Result rc = _hidGetNpadStates(id, 6, states, count, total_out);
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
} }
void hidGetNpadStatesSystem(u32 id, HidNpadSystemState *states, size_t count, size_t *total_out) { void hidGetNpadStatesSystem(HidNpadIdType id, HidNpadSystemState *states, size_t count, size_t *total_out) {
if (total_out) *total_out = 0; if (total_out) *total_out = 0;
size_t tmp_out=0; size_t tmp_out=0;
Result rc = _hidGetNpadStates(id, 6, states, count, &tmp_out); Result rc = _hidGetNpadStates(id, 6, states, count, &tmp_out);
@ -1226,31 +1165,12 @@ Result hidGetSupportedNpadStyleSet(u32 *style_set) {
return rc; return rc;
} }
Result hidSetSupportedNpadIdType(const HidControllerID *buf, size_t count) { Result hidSetSupportedNpadIdType(const HidNpadIdType *buf, size_t count) {
u64 AppletResourceUserId = appletGetAppletResourceUserId(); u64 AppletResourceUserId = appletGetAppletResourceUserId();
size_t i;
u32 tmpval=0;
u32 tmpbuf[10];
if (count > 10)
return MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
memset(tmpbuf, 0, sizeof(tmpbuf));
for (i=0; i<count; i++) {
tmpval = buf[i];
if (tmpval == CONTROLLER_HANDHELD) {
tmpval = 0x20;
}
else if (tmpval >= CONTROLLER_UNKNOWN) {
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
}
tmpbuf[i] = tmpval;
}
return serviceDispatchIn(&g_hidSrv, 102, AppletResourceUserId, return serviceDispatchIn(&g_hidSrv, 102, AppletResourceUserId,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In },
.buffers = { { tmpbuf, count*sizeof(u32) } }, .buffers = { { buf, count*sizeof(HidNpadIdType) } },
.in_send_pid = true, .in_send_pid = true,
); );
} }
@ -1274,7 +1194,7 @@ static Result _hidDeactivateNpad(void) {
return _hidCmdWithNoInput(104); return _hidCmdWithNoInput(104);
} }
Result hidAcquireNpadStyleSetUpdateEventHandle(HidControllerID id, Event* out_event, bool autoclear) { Result hidAcquireNpadStyleSetUpdateEventHandle(HidNpadIdType id, Event* out_event, bool autoclear) {
Result rc; Result rc;
Handle tmp_handle = INVALID_HANDLE; Handle tmp_handle = INVALID_HANDLE;
@ -1283,7 +1203,7 @@ Result hidAcquireNpadStyleSetUpdateEventHandle(HidControllerID id, Event* out_ev
u32 pad; u32 pad;
u64 AppletResourceUserId; u64 AppletResourceUserId;
u64 event_ptr; // Official sw sets this to a ptr, which the sysmodule doesn't seem to use. u64 event_ptr; // Official sw sets this to a ptr, which the sysmodule doesn't seem to use.
} in = { hidControllerIDToOfficial(id), 0, appletGetAppletResourceUserId(), 0 }; } in = { id, 0, appletGetAppletResourceUserId(), 0 };
rc = serviceDispatchIn(&g_hidSrv, 106, in, rc = serviceDispatchIn(&g_hidSrv, 106, in,
.in_send_pid = true, .in_send_pid = true,
@ -1305,19 +1225,19 @@ Result hidGetNpadJoyHoldType(HidJoyHoldType *type) {
return rc; return rc;
} }
Result hidSetNpadJoyAssignmentModeSingleByDefault(HidControllerID id) { Result hidSetNpadJoyAssignmentModeSingleByDefault(HidNpadIdType id) {
return _hidCmdWithInputU32(hidControllerIDToOfficial(id), 122); return _hidCmdWithInputU32(id, 122);
} }
Result hidSetNpadJoyAssignmentModeDual(HidControllerID id) { Result hidSetNpadJoyAssignmentModeDual(HidNpadIdType id) {
return _hidCmdWithInputU32(hidControllerIDToOfficial(id), 124); return _hidCmdWithInputU32(id, 124);
} }
Result hidMergeSingleJoyAsDualJoy(HidControllerID id0, HidControllerID id1) { Result hidMergeSingleJoyAsDualJoy(HidNpadIdType id0, HidNpadIdType id1) {
const struct { const struct {
u32 id0, id1; u32 id0, id1;
u64 AppletResourceUserId; u64 AppletResourceUserId;
} in = { hidControllerIDToOfficial(id0), hidControllerIDToOfficial(id1), appletGetAppletResourceUserId() }; } in = { id0, id1, appletGetAppletResourceUserId() };
return serviceDispatchIn(&g_hidSrv, 125, in, return serviceDispatchIn(&g_hidSrv, 125, in,
.in_send_pid = true, .in_send_pid = true,
@ -1402,16 +1322,13 @@ Result hidIsVibrationDeviceMounted(const u32 *VibrationDeviceHandle, bool *flag)
return rc; return rc;
} }
static Result _hidGetDeviceHandles(u32 devicetype, u32 *DeviceHandles, s32 total_handles, HidControllerID id, HidNpadStyleTag style) { static Result _hidGetDeviceHandles(u32 devicetype, u32 *DeviceHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) {
Result rc=0; Result rc=0;
u32 tmp_type=0; u32 tmp_type=0;
u32 tmp_id=0;
if (total_handles <= 0 || total_handles > 2 || devicetype > 1) if (total_handles <= 0 || total_handles > 2 || devicetype > 1)
return MAKERESULT(Module_Libnx, LibnxError_BadInput); return MAKERESULT(Module_Libnx, LibnxError_BadInput);
tmp_id = hidControllerIDToOfficial(id);
if (style & HidNpadStyleTag_NpadFullKey) { if (style & HidNpadStyleTag_NpadFullKey) {
tmp_type = 3; tmp_type = 3;
} }
@ -1462,7 +1379,7 @@ static Result _hidGetDeviceHandles(u32 devicetype, u32 *DeviceHandles, s32 total
return MAKERESULT(Module_Libnx, LibnxError_BadInput); return MAKERESULT(Module_Libnx, LibnxError_BadInput);
} }
DeviceHandles[0] = tmp_type | (tmp_id & 0xff)<<8; DeviceHandles[0] = tmp_type | (id & 0xff)<<8;
if (devicetype==1 && (tmp_type==3 || tmp_type==4)) if (devicetype==1 && (tmp_type==3 || tmp_type==4))
DeviceHandles[0] |= 0x020000; DeviceHandles[0] |= 0x020000;
@ -1483,7 +1400,7 @@ static Result _hidGetDeviceHandles(u32 devicetype, u32 *DeviceHandles, s32 total
return rc; return rc;
} }
Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, s32 total_handles, HidControllerID id, HidNpadStyleTag style) { Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) {
Result rc=0; Result rc=0;
s32 i; s32 i;
@ -1507,7 +1424,7 @@ Result hidInitializeVibrationDevices(u32 *VibrationDeviceHandles, s32 total_hand
return rc; return rc;
} }
Result hidGetSixAxisSensorHandles(u32 *SixAxisSensorHandles, s32 total_handles, HidControllerID id, HidNpadStyleTag style) { Result hidGetSixAxisSensorHandles(u32 *SixAxisSensorHandles, s32 total_handles, HidNpadIdType id, HidNpadStyleTag style) {
return _hidGetDeviceHandles(1, SixAxisSensorHandles, total_handles, id, style); return _hidGetDeviceHandles(1, SixAxisSensorHandles, total_handles, id, style);
} }
@ -1730,11 +1647,11 @@ Result hidGetGyroBias(UtilFloat3 *out) {
return 0; return 0;
} }
Result hidGetNpadInterfaceType(HidControllerID id, u8 *out) { Result hidGetNpadInterfaceType(HidNpadIdType id, u8 *out) {
if (hosversionBefore(4,0,0)) if (hosversionBefore(4,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
u32 tmp = hidControllerIDToOfficial(id); u32 tmp = id;
return serviceDispatchInOut(&g_hidSrv, 405, tmp, *out); return serviceDispatchInOut(&g_hidSrv, 405, tmp, *out);
} }

View File

@ -42,7 +42,7 @@ static Result _hidbusCmdGetHandle(Service* srv, Handle* handle_out, u32 cmd_id)
); );
} }
static Result _hidbusGetBusHandle(Service* srv, u32 id, u64 bus_type, bool *flag, HidbusBusHandle *handle) { static Result _hidbusGetBusHandle(Service* srv, HidNpadIdType id, u64 bus_type, bool *flag, HidbusBusHandle *handle) {
const struct { const struct {
u32 id; u32 id;
u32 pad; u32 pad;
@ -204,7 +204,7 @@ static HidbusJoyPollingMode _hidbusGetStatusManagerEntryPollingMode(u8 internal_
return atomic_load_explicit(&_hidbusGetStatusManagerEntryCommon(internal_index)->polling_mode, memory_order_acquire); return atomic_load_explicit(&_hidbusGetStatusManagerEntryCommon(internal_index)->polling_mode, memory_order_acquire);
} }
Result hidbusGetBusHandle(HidbusBusHandle *handle, bool *flag, HidControllerID id, HidbusBusType bus_type) { Result hidbusGetBusHandle(HidbusBusHandle *handle, bool *flag, HidNpadIdType id, HidbusBusType bus_type) {
Service srv={0}; Service srv={0};
Result rc = hidbusGetServiceSession(&srv); Result rc = hidbusGetServiceSession(&srv);
*flag = 0; *flag = 0;
@ -212,7 +212,7 @@ Result hidbusGetBusHandle(HidbusBusHandle *handle, bool *flag, HidControllerID i
HidbusBusHandle tmphandle={0}; HidbusBusHandle tmphandle={0};
bool tmpflag=0; bool tmpflag=0;
rc = _hidbusGetBusHandle(&srv, hidControllerIDToOfficial(id), bus_type, &tmpflag, &tmphandle); rc = _hidbusGetBusHandle(&srv, id, bus_type, &tmpflag, &tmphandle);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
if (!tmpflag) *flag = tmpflag; if (!tmpflag) *flag = tmpflag;
else { else {

View File

@ -181,11 +181,11 @@ Result hidsysGetSupportedNpadStyleSetOfCallerApplet(u32 *out) {
return _hidsysGetMaskedSupportedNpadStyleSet(AppletResourceUserId, out); return _hidsysGetMaskedSupportedNpadStyleSet(AppletResourceUserId, out);
} }
Result hidsysGetUniquePadsFromNpad(HidControllerID id, u64 *UniquePadIds, s32 count, s32 *total_entries) { Result hidsysGetUniquePadsFromNpad(HidNpadIdType id, u64 *UniquePadIds, s32 count, s32 *total_entries) {
if (hosversionBefore(3,0,0)) if (hosversionBefore(3,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
u32 tmp=hidControllerIDToOfficial(id); u32 tmp=id;
s64 out=0; s64 out=0;
Result rc = serviceDispatchInOut(&g_hidsysSrv, 321, tmp, out, Result rc = serviceDispatchInOut(&g_hidsysSrv, 321, tmp, out,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out }, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out },

View File

@ -277,8 +277,8 @@ static Result _irsCheckInternalStatus(IrsIrCameraHandle handle) {
return rc; return rc;
} }
Result irsGetIrCameraHandle(IrsIrCameraHandle *handle, HidControllerID id) { Result irsGetIrCameraHandle(IrsIrCameraHandle *handle, HidNpadIdType id) {
u32 tmp = hidControllerIDToOfficial(id); u32 tmp = id;
return serviceDispatchInOut(&g_irsSrv, 311, tmp, *handle); return serviceDispatchInOut(&g_irsSrv, 311, tmp, *handle);
} }