Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libxenon/drivers/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions libxenon/drivers/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

#include <stdint.h>

#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;
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions libxenon/drivers/usb/usbctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}



Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;

}
Expand Down
2 changes: 2 additions & 0 deletions libxenon/drivers/usb/usbdevs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading