From e2c5593deb5cb6c0a1bdcb9b789ef185597a8fe9 Mon Sep 17 00:00:00 2001 From: InvoxiPlayGames Date: Tue, 30 Sep 2025 14:16:20 +0100 Subject: [PATCH] report controller types for wireless controllers and some wired guitars --- libxenon/drivers/input/input.c | 15 +++++++++++++++ libxenon/drivers/input/input.h | 16 ++++++++++++++++ libxenon/drivers/usb/usbctrl.c | 22 ++++++++++++++++++++++ libxenon/drivers/usb/usbdevs.c | 2 ++ 4 files changed, 55 insertions(+) diff --git a/libxenon/drivers/input/input.c b/libxenon/drivers/input/input.c index 7d7f67ea..16b47608 100644 --- a/libxenon/drivers/input/input.c +++ b/libxenon/drivers/input/input.c @@ -2,6 +2,7 @@ static struct controller_data_s ctrl[4]; static int valid[4]; +static int ctrl_type[4]; int get_controller_data(struct controller_data_s *d, int port) { @@ -21,6 +22,20 @@ void set_controller_data(int port, const struct controller_data_s *d) valid[port] = 1; } +int get_controller_type(int port) +{ + if (port >= 4) + return 0; + return ctrl_type[port]; +} + +void set_controller_type(int port, int type) +{ + if (port >= 4) + return; + ctrl_type[port] = type; +} + extern int usbctrl_set_rumble(int port, uint8_t l, uint8_t r); void set_controller_rumble(int port, uint8_t l, uint8_t r) diff --git a/libxenon/drivers/input/input.h b/libxenon/drivers/input/input.h index 6694560e..768d370a 100644 --- a/libxenon/drivers/input/input.h +++ b/libxenon/drivers/input/input.h @@ -7,6 +7,18 @@ #include +#define CTRL_TYPE_NONE 0x0 +#define CTRL_TYPE_GAMEPAD 0x1 +#define CTRL_TYPE_WHEEL 0x2 +#define CTRL_TYPE_ARCADE 0x3 +#define CTRL_TYPE_FLIGHT 0x4 +#define CTRL_TYPE_DANCE 0x5 +#define CTRL_TYPE_GUITAR 0x6 +#define CTRL_TYPE_GUITAR_ALT 0x7 +#define CTRL_TYPE_DRUMS 0x8 +#define CTRL_TYPE_GUITAR_BASS 0xB +#define CTRL_TYPE_ARCADE_PAD 0x13 + struct controller_data_s { signed short s1_x, s1_y, s2_x, s2_y; @@ -19,6 +31,10 @@ int get_controller_data(struct controller_data_s *d, int port); void set_controller_data(int port, const struct controller_data_s *d); +int get_controller_type(int port); + +void set_controller_type(int port, int type); + void set_controller_rumble(int port, uint8_t l, uint8_t r); #ifdef __cplusplus diff --git a/libxenon/drivers/usb/usbctrl.c b/libxenon/drivers/usb/usbctrl.c index 5c34105d..391ab5a3 100644 --- a/libxenon/drivers/usb/usbctrl.c +++ b/libxenon/drivers/usb/usbctrl.c @@ -346,11 +346,22 @@ static int usbctrl_ireq_callback(usbreq_t *ur) usbctrl_set_rol(controller_mask); + set_controller_type(uhid->index, CTRL_TYPE_NONE); + uhid->index = -1; goto ignore; } + if (b[0] == 0x0 && b[5] == 0xCC) + { + unsigned char pad_type = b[25] & 0x7F; + unsigned short pad_vendor = ((b[22] & 0xf) | b[24] << 4) << 8 | b[23]; + + set_controller_type(uhid->index, pad_type); + + goto ignore; + } @@ -588,6 +599,15 @@ static int usbctrl_attach(usbdev_t *dev,usb_driver_t *drv) usbctrl_set_rol(controller_mask); + // TODO: detect controller type from xbox id descriptor + if ((GETUSBFIELD(&dev->ud_devdescr, idVendor) == 0x1430 && // xplorer + GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x4748) || + (GETUSBFIELD(&dev->ud_devdescr, idVendor) == 0x1bad && // rb + GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x0002)) + set_controller_type(softc->index, CTRL_TYPE_GUITAR); + else + set_controller_type(softc->index, CTRL_TYPE_GAMEPAD); + /* * Allocate a DMA buffer */ @@ -655,6 +675,8 @@ static int usbctrl_detach(usbdev_t *dev) usbctrl_set_rol(controller_mask); + set_controller_type(uhid->index, CTRL_TYPE_NONE); + return 0; } diff --git a/libxenon/drivers/usb/usbdevs.c b/libxenon/drivers/usb/usbdevs.c index 50889dbf..a070e6cc 100644 --- a/libxenon/drivers/usb/usbdevs.c +++ b/libxenon/drivers/usb/usbdevs.c @@ -99,6 +99,8 @@ usb_drvlist_t usb_drivers[] = { {CLASS_ANY, 0x045e,0x2b0, &dummy_driver}, // Kinect, not handled so we load a dummy drive {CLASS_ANY, 0x1bad,0xf900, &usbctrl_driver}, // PDP Afterglow controller {CLASS_ANY, 0x045e,0x28f, &dummy_driver}, // play and charge kit, not a controller - let's ignore it + {CLASS_ANY, 0x1430,0x4748, &usbctrl_driver}, // Xplorer Guitar + {CLASS_ANY, 0x1bad,0x0002, &usbctrl_driver}, // RB Guitar /* * Mass storage devices