diff --git a/src/console/nuon/nuon.c b/src/console/nuon/nuon.c index 1d869c8..5b02172 100644 --- a/src/console/nuon/nuon.c +++ b/src/console/nuon/nuon.c @@ -532,6 +532,17 @@ void __not_in_flash_func(post_mouse_globals)( if (player_index >= 0) { players[player_index].global_buttons = buttons; + + // Swap B2 and S2 + if (!(buttons & USBR_BUTTON_B2)) { + players[player_index].global_buttons |= USBR_BUTTON_B2; + players[player_index].global_buttons &= ~USBR_BUTTON_S2; + } + if (!(buttons & USBR_BUTTON_S2)) { + players[player_index].global_buttons |= USBR_BUTTON_S2; + players[player_index].global_buttons &= ~USBR_BUTTON_B2; + } + players[player_index].output_buttons = map_nuon_buttons(players[player_index].global_buttons & players[player_index].altern_buttons); players[player_index].output_analog_1x = 128; players[player_index].output_analog_1y = 128; diff --git a/src/devices/hid_gamepad.c b/src/devices/hid_gamepad.c index 7b8cba6..35a52e4 100644 --- a/src/devices/hid_gamepad.c +++ b/src/devices/hid_gamepad.c @@ -23,6 +23,7 @@ typedef struct TU_ATTR_PACKED dinput_usage_t hatLoc; dinput_usage_t buttonLoc[MAX_BUTTONS]; // assuming a maximum of 12 buttons uint8_t buttonCnt; + uint8_t type; } dinput_instance_t; // Cached device report properties on mount @@ -94,12 +95,32 @@ void parse_descriptor(uint8_t dev_addr, uint8_t instance) if (USB_GetHIDReportItemInfoWithReportId(report, item)) { if (HID_DEBUG) TU_LOG1("PAGE: %d ", item->Attributes.Usage.Page); + hid_devices[dev_addr].instances[instance].type = HID_GAMEPAD; + switch (item->Attributes.Usage.Page) { case HID_USAGE_PAGE_DESKTOP: { switch (item->Attributes.Usage.Usage) { + case HID_USAGE_DESKTOP_WHEEL: + { + if (HID_DEBUG) TU_LOG1(" HID_USAGE_DESKTOP_WHEEL "); + hid_devices[dev_addr].instances[instance].type = HID_MOUSE; + break; + } + case HID_USAGE_DESKTOP_MOUSE: + { + if (HID_DEBUG) TU_LOG1(" HID_USAGE_DESKTOP_MOUSE "); + hid_devices[dev_addr].instances[instance].type = HID_MOUSE; + break; + } + case HID_USAGE_DESKTOP_KEYBOARD: + { + if (HID_DEBUG) TU_LOG1(" HID_USAGE_DESKTOP_KEYBOARD "); + hid_devices[dev_addr].instances[instance].type = HID_KEYBOARD; + break; + } case HID_USAGE_DESKTOP_X: // Left Analog X { if (HID_DEBUG) TU_LOG1(" HID_USAGE_DESKTOP_X "); @@ -225,7 +246,9 @@ bool parse_hid_gamepad(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_r info = NULL; // assume it is d-input device if buttons exist on report - if (hid_devices[dev_addr].instances[instance].buttonCnt > 0) { + if (hid_devices[dev_addr].instances[instance].buttonCnt > 0 && + hid_devices[dev_addr].instances[instance].type == HID_GAMEPAD + ) { return true; } @@ -247,10 +270,12 @@ bool CALLBACK_HIDParser_FilterHIDReportItem(uint8_t dev_addr, uint8_t instance, // { // hid_devices[dev_addr].instances[instance].reportID = CurrentItem->ReportID; // } + + TU_LOG1("ITEM_PAGE: 0x%x", CurrentItem->Attributes.Usage.Page); + TU_LOG1(" USAGE: 0x%x\n", CurrentItem->Attributes.Usage.Usage); switch (CurrentItem->Attributes.Usage.Page) { case HID_USAGE_PAGE_DESKTOP: - // TU_LOG1("HID_USAGE: 0x%x\n", CurrentItem->Attributes.Usage.Usage); switch (CurrentItem->Attributes.Usage.Usage) { case HID_USAGE_DESKTOP_X: @@ -264,6 +289,9 @@ bool CALLBACK_HIDParser_FilterHIDReportItem(uint8_t dev_addr, uint8_t instance, case HID_USAGE_DESKTOP_DPAD_DOWN: case HID_USAGE_DESKTOP_DPAD_LEFT: case HID_USAGE_DESKTOP_DPAD_RIGHT: + case HID_USAGE_DESKTOP_WHEEL: + case HID_USAGE_DESKTOP_MOUSE: + case HID_USAGE_DESKTOP_KEYBOARD: return true; } return false; diff --git a/src/devices/hid_gamepad.h b/src/devices/hid_gamepad.h index af1242c..d0ea53b 100644 --- a/src/devices/hid_gamepad.h +++ b/src/devices/hid_gamepad.h @@ -11,6 +11,10 @@ #define MAX_BUTTONS 12 // max generic HID buttons to map #define HID_DEBUG 1 +#define HID_GAMEPAD 0x00 +#define HID_MOUSE 0x01 +#define HID_KEYBOARD 0x02 + typedef union { struct diff --git a/src/devices/hid_mouse.c b/src/devices/hid_mouse.c index 203f53b..2ceaf9d 100644 --- a/src/devices/hid_mouse.c +++ b/src/devices/hid_mouse.c @@ -79,6 +79,7 @@ void process_hid_mouse(uint8_t dev_addr, uint8_t instance, uint8_t const* mouse_ ((0x0000f)) | // no dpad button presses (isMouse) ((report->buttons & MOUSE_BUTTON_RIGHT) ? 0x00 : USBR_BUTTON_B1) | ((report->buttons & MOUSE_BUTTON_LEFT) ? 0x00 : USBR_BUTTON_B2) | + ((report->buttons & MOUSE_BUTTON_BACKWARD)? 0x00 : USBR_BUTTON_B3) | ((report->buttons & MOUSE_BUTTON_FORWARD) ? 0x00 : USBR_BUTTON_S1) | ((report->buttons & MOUSE_BUTTON_MIDDLE) ? 0x00 : USBR_BUTTON_S2)); } else { @@ -86,6 +87,7 @@ void process_hid_mouse(uint8_t dev_addr, uint8_t instance, uint8_t const* mouse_ ((0x0000f)) | ((report->buttons & MOUSE_BUTTON_LEFT) ? 0x00 : USBR_BUTTON_B1) | ((report->buttons & MOUSE_BUTTON_RIGHT) ? 0x00 : USBR_BUTTON_B2) | + ((report->buttons & MOUSE_BUTTON_BACKWARD)? 0x00 : USBR_BUTTON_B3) | ((report->buttons & MOUSE_BUTTON_FORWARD) ? 0x00 : USBR_BUTTON_S1) | ((report->buttons & MOUSE_BUTTON_MIDDLE) ? 0x00 : USBR_BUTTON_S2)); } diff --git a/src/hid_app.c b/src/hid_app.c index d76996a..97ef395 100644 --- a/src/hid_app.c +++ b/src/hid_app.c @@ -192,17 +192,17 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons switch (itf_protocol) { case HID_ITF_PROTOCOL_KEYBOARD: - TU_LOG2("HID receive boot keyboard report\r\n"); + TU_LOG1("HID receive boot keyboard report\r\n"); device_interfaces[CONTROLLER_KEYBOARD]->process(dev_addr, instance, report, len); break; case HID_ITF_PROTOCOL_MOUSE: - TU_LOG2("HID receive boot mouse report\r\n"); + TU_LOG1("HID receive boot mouse report\r\n"); device_interfaces[CONTROLLER_MOUSE]->process(dev_addr, instance, report, len); break; default: - TU_LOG2("HID receive generic report\r\n"); + TU_LOG1("HID receive generic report\r\n"); process_generic_report(dev_addr, instance, report, len); break; }