Skip to content

Commit

Permalink
Merge pull request #35 from RobertDaleSmith/fix-nuon-spinner
Browse files Browse the repository at this point in the history
fix(nuon): corrects recently introduced spinner input issues
  • Loading branch information
RobertDaleSmith authored Feb 20, 2024
2 parents 3423df3 + 66942ce commit 371c09a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/console/nuon/nuon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 30 additions & 2 deletions src/devices/hid_gamepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ");
Expand Down Expand Up @@ -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;
}

Expand All @@ -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:
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/devices/hid_gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/devices/hid_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ 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 {
buttons = (((0xfff00)) |
((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));
}
Expand Down
6 changes: 3 additions & 3 deletions src/hid_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 371c09a

Please sign in to comment.