From 254490109d0c267ecd1336eb0dbad89285b5c9d3 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Wed, 13 Aug 2025 15:42:42 +0100 Subject: [PATCH 1/2] pico: add some code for handling a stick that is actually a dpad Revived from a commit from over two years ago! --- 32blit-pico/input/usb_hid.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/32blit-pico/input/usb_hid.cpp b/32blit-pico/input/usb_hid.cpp index 0ebc2d7dd..33d691be2 100644 --- a/32blit-pico/input/usb_hid.cpp +++ b/32blit-pico/input/usb_hid.cpp @@ -18,22 +18,29 @@ extern uint8_t hid_hat; extern uint32_t hid_buttons; extern uint8_t hid_keys[6]; +enum GamePadFlags { + Gamepad_StickIsDPAD = 1 << 0, +}; + struct GamepadMapping { uint32_t id; // vid:pid uint8_t a, b, x, y; uint8_t up, down, left, right; // if no hat uint8_t menu, home, joystick; + uint8_t flags; }; #define NO 0xFF +#define SD Gamepad_StickIsDPAD static const GamepadMapping gamepad_mappings[]{ - {0x15320705, 0, 1, 3, 4, NO, NO, NO, NO, 16, 15, 13}, // Razer Raiju Mobile - {0x20D6A711, 2, 1, 3, 0, NO, NO, NO, NO, 8, 12, 10}, // PowerA wired Switch pro controller - {0x2DC89018, 0, 1, 3, 4, NO, NO, NO, NO, 10, 11, NO}, // 8BitDo Zero 2 - {0x00000000, 0, 1, 2, 3, NO, NO, NO, NO, 4, 5, 6} // probably wrong fallback + {0x15320705, 0, 1, 3, 4, NO, NO, NO, NO, 16, 15, 13, 0}, // Razer Raiju Mobile + {0x20D6A711, 2, 1, 3, 0, NO, NO, NO, NO, 8, 12, 10, 0}, // PowerA wired Switch pro controller + {0x2DC89018, 0, 1, 3, 4, NO, NO, NO, NO, 10, 11, NO, 0}, // 8BitDo Zero 2 + {0x00000000, 0, 1, 2, 3, NO, NO, NO, NO, 4, 5, 6, 0} // probably wrong fallback }; +#undef SD #undef NO // hat -> dpad @@ -141,6 +148,19 @@ void update_input() { api_data.buttons = new_buttons; - api_data.joystick.x = (float(hid_joystick[0]) - 0x80) / 0x80; - api_data.joystick.y = (float(hid_joystick[1]) - 0x80) / 0x80; + if(mapping->flags & Gamepad_StickIsDPAD) { + // stick is actually a D-PAD + if(hid_joystick[0] < 0x40) + api_data.buttons.state |= uint32_t(Button::DPAD_LEFT); + else if(hid_joystick[0] > 0xC0) + api_data.buttons.state |= uint32_t(Button::DPAD_RIGHT); + + if(hid_joystick[1] < 0x40) + api_data.buttons.state |= uint32_t(Button::DPAD_UP); + else if(hid_joystick[1] > 0xC0) + api_data.buttons.state |= uint32_t(Button::DPAD_DOWN); + } else { + api_data.joystick.x = (float(hid_joystick[0]) - 0x80) / 0x80; + api_data.joystick.y = (float(hid_joystick[1]) - 0x80) / 0x80; + } } From 5c86cf7d92b6f3b750ae71d77f39f57e698922a0 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Wed, 13 Aug 2025 16:07:36 +0100 Subject: [PATCH 2/2] pico: add mapping for RetroFlag Classic USB Gamepad Works sometimes, which is an improvement on the last time --- 32blit-pico/input/usb_hid.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/32blit-pico/input/usb_hid.cpp b/32blit-pico/input/usb_hid.cpp index 33d691be2..799f19f63 100644 --- a/32blit-pico/input/usb_hid.cpp +++ b/32blit-pico/input/usb_hid.cpp @@ -37,6 +37,7 @@ static const GamepadMapping gamepad_mappings[]{ {0x15320705, 0, 1, 3, 4, NO, NO, NO, NO, 16, 15, 13, 0}, // Razer Raiju Mobile {0x20D6A711, 2, 1, 3, 0, NO, NO, NO, NO, 8, 12, 10, 0}, // PowerA wired Switch pro controller {0x2DC89018, 0, 1, 3, 4, NO, NO, NO, NO, 10, 11, NO, 0}, // 8BitDo Zero 2 + {0x05832060, 0, 1, 2, 3, NO, NO, NO, NO, 6, 7, NO, SD}, // RetroFlag Classic USB Gamepad {0x00000000, 0, 1, 2, 3, NO, NO, NO, NO, 4, 5, 6, 0} // probably wrong fallback };