Skip to content

Commit

Permalink
Formatting, getting ready for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
arntsonl committed Sep 24, 2024
1 parent afa7c89 commit aed3e47
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 208 deletions.
245 changes: 121 additions & 124 deletions headers/drivers/xinput/XInputDescriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,120 +33,117 @@

typedef struct __attribute((packed, aligned(1)))
{
uint8_t report_id;
uint8_t report_size;
uint8_t buttons1;
uint8_t buttons2;
uint8_t lt;
uint8_t rt;
int16_t lx;
int16_t ly;
int16_t rx;
int16_t ry;
uint8_t _reserved[6];
uint8_t report_id;
uint8_t report_size;
uint8_t buttons1;
uint8_t buttons2;
uint8_t lt;
uint8_t rt;
int16_t lx;
int16_t ly;
int16_t rx;
int16_t ry;
uint8_t _reserved[6];
} XInputReport;

static const uint8_t xinput_string_language[] = { 0x09, 0x04 };
static const uint8_t xinput_string_serial[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
//static const uint8_t xinput_string_manfacturer[] = "Microsoft";
//static const uint8_t xinput_string_product[] = "XInput STANDARD GAMEPAD";
//static const uint8_t xinput_string_version[] = "1.0";
static const uint8_t xinput_string_manfacturer[] = "\xa9Microsoft Corporation";
static const uint8_t xinput_string_product[] = "Controller";
static const uint8_t xinput_string_version[] = "08FEC93"; // serial?
static const uint8_t xinput_string_version[] = "08FEC93"; // Fake a random serial, doesn't matter
static const uint8_t xinput_string_xsm3[] = "Xbox Security Method 3, Version 1.00, \xa9 2005 Microsoft Corporation. All rights reserved.";

static const uint8_t *xinput_string_descriptors[] __attribute__((unused)) =
{
xinput_string_serial,
xinput_string_manfacturer,
xinput_string_product,
xinput_string_version,
xinput_string_serial,
xinput_string_manfacturer,
xinput_string_product,
xinput_string_version,
xinput_string_xsm3
};

static const uint8_t xinput_device_descriptor[] =
{
0x12, // bLength
0x01, // bDescriptorType (Device)
0x00, 0x02, // bcdUSB 2.00
0xFF, // bDeviceClass
0xFF, // bDeviceSubClass
0xFF, // bDeviceProtocol
0x40, // bMaxPacketSize0 64
0x5E, 0x04, // idVendor 0x045E
0x8E, 0x02, // idProduct 0x028E
0x14, 0x01, // bcdDevice 2.14
0x01, // iManufacturer (String Index)
0x02, // iProduct (String Index)
0x03, // iSerialNumber (String Index)
0x01, // bNumConfigurations 1
0x12, // bLength
0x01, // bDescriptorType (Device)
0x00, 0x02, // bcdUSB 2.00
0xFF, // bDeviceClass
0xFF, // bDeviceSubClass
0xFF, // bDeviceProtocol
0x40, // bMaxPacketSize0 64
0x5E, 0x04, // idVendor 0x045E
0x8E, 0x02, // idProduct 0x028E
0x14, 0x01, // bcdDevice 2.14
0x01, // iManufacturer (String Index)
0x02, // iProduct (String Index)
0x03, // iSerialNumber (String Index)
0x01, // bNumConfigurations 1
};

// This needs to be:
// 4 interfaces
// remote wakeup enabled
static const uint8_t xinput_configuration_descriptor[] =
{
0x09, // bLength
0x02, // bDescriptorType (Configuration)
0x99, 0x00, // wTotalLength 0x99
0x04, // bNumInterfaces 4
0x01, // bConfigurationValue
0x00, // iConfiguration (String Index)
0xA0, // bmAttributes (remote wakeup)
0xFA, // bMaxPower 500mA
0x09, // bLength
0x02, // bDescriptorType (Configuration)
0x99, 0x00, // wTotalLength 0x99
0x04, // bNumInterfaces 4
0x01, // bConfigurationValue
0x00, // iConfiguration (String Index)
0xA0, // bmAttributes (remote wakeup)
0xFA, // bMaxPower 500mA

// Control Interface (0x5D 0xFF)
0x09, // bLength
0x04, // bDescriptorType (Interface)
0x00, // bInterfaceNumber 0
0x00, // bAlternateSetting
0x02, // bNumEndpoints 2
0xFF, // bInterfaceClass
0x5D, // bInterfaceSubClass
0x01, // bInterfaceProtocol
0x00, // iInterface (String Index)
0x09, // bLength
0x04, // bDescriptorType (Interface)
0x00, // bInterfaceNumber 0
0x00, // bAlternateSetting
0x02, // bNumEndpoints 2
0xFF, // bInterfaceClass
0x5D, // bInterfaceSubClass
0x01, // bInterfaceProtocol
0x00, // iInterface (String Index)

// Gamepad Descriptor
0x11, // bLength
0x21, // bDescriptorType (HID)
0x00, 0x01, // bcdHID 1.10
0x01, // SUB_TYPE
0x25, // reserved2
0x81, // DEVICE_EPADDR_IN
0x11, // bLength
0x21, // bDescriptorType (HID)
0x00, 0x01, // bcdHID 1.10
0x01, // SUB_TYPE
0x25, // reserved2
0x81, // DEVICE_EPADDR_IN
0x14, // bMaxDataSizeIn
0x00, 0x00, 0x00, 0x00, 0x13, // reserved3
0x02, // DEVICE_EPADDR_OUT is this right?
0x08, // bMaxDataSizeOut
0x02, // DEVICE_EPADDR_OUT is this right?
0x08, // bMaxDataSizeOut
0x00, 0x00, // reserved4

// Report IN Endpoint 1.1
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x81, // bEndpointAddress (IN/D2H)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x01, // bInterval 1 (unit depends on device speed)
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x81, // bEndpointAddress (IN/D2H)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x01, // bInterval 1 (unit depends on device speed)

// Report OUT Endpoint 1.2
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x02, // bEndpointAddress (OUT/H2D)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x08, // bInterval 8 (unit depends on device speed)
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x02, // bEndpointAddress (OUT/H2D)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x08, // bInterval 8 (unit depends on device speed)

// Interface Audio
0x09, // bLength
0x04, // bDescriptorType (Interface)
0x01, // bInterfaceNumber 1
0x00, // bAlternateSetting
0x04, // bNumEndpoints 4
0xFF, // bInterfaceClass
0x5D, // bInterfaceSubClass
0x03, // bInterfaceProtocol
0x00, // iInterface (String Index)
0x09, // bLength
0x04, // bDescriptorType (Interface)
0x01, // bInterfaceNumber 1
0x00, // bAlternateSetting
0x04, // bNumEndpoints 4
0xFF, // bInterfaceClass
0x5D, // bInterfaceSubClass
0x03, // bInterfaceProtocol
0x00, // iInterface (String Index)

// Audio Descriptor
0x1B, // bLength
Expand Down Expand Up @@ -178,47 +175,47 @@ static const uint8_t xinput_configuration_descriptor[] =
0x00,

// Report IN Endpoint 2.1
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x83, // bEndpointAddress (XINPUT_MIC_IN)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x02, // bInterval 2 (unit depends on device speed)
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x83, // bEndpointAddress (XINPUT_MIC_IN)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x02, // bInterval 2 (unit depends on device speed)

// Report OUT Endpoint 2.2
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x04, // bEndpointAddress (XINPUT_AUDIO_OUT)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x04, // bInterval 4 (unit depends on device speed)
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x04, // bEndpointAddress (XINPUT_AUDIO_OUT)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x04, // bInterval 4 (unit depends on device speed)

// Report IN Endpoint 2.3
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x85, // bEndpointAddress (XINPUT_UNK_IN)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x40, // bInterval 128
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x85, // bEndpointAddress (XINPUT_UNK_IN)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x40, // bInterval 128

// Report OUT Endpoint 2.4
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x06, // bEndpointAddress (XINPUT_UNK_OUT)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x10, // bInterval 16
0x05, // bDescriptorType (Endpoint)
0x06, // bEndpointAddress (XINPUT_UNK_OUT)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x10, // bInterval 16

// Interface Plugin Module
0x09, // bLength
0x04, // bDescriptorType (Interface)
0x02, // bInterfaceNumber 2
0x00, // bAlternateSetting
0x01, // bNumEndpoints 1
0xFF, // bInterfaceClass
0x5D, // bInterfaceSubClass
0x02, // bInterfaceProtocol
0x00, // iInterface (String Index)
0x09, // bLength
0x04, // bDescriptorType (Interface)
0x02, // bInterfaceNumber 2
0x00, // bAlternateSetting
0x01, // bNumEndpoints 1
0xFF, // bInterfaceClass
0x5D, // bInterfaceSubClass
0x02, // bInterfaceProtocol
0x00, // iInterface (String Index)

//PluginModuleDescriptor : {
0x09, // bLength
Expand All @@ -232,22 +229,22 @@ static const uint8_t xinput_configuration_descriptor[] =

// Report IN Endpoint 3.1
0x07, // bLength
0x05, // bDescriptorType (Endpoint)
0x86, // bEndpointAddress (XINPUT_PLUGIN_MODULE_IN)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x10, // bInterval 8 (unit depends on device speed)
0x05, // bDescriptorType (Endpoint)
0x86, // bEndpointAddress (XINPUT_PLUGIN_MODULE_IN)
0x03, // bmAttributes (Interrupt)
0x20, 0x00, // wMaxPacketSize 32
0x10, // bInterval 8 (unit depends on device speed)

// Interface Security
0x09, // bLength
0x04, // bDescriptorType (Interface)
0x03, // bInterfaceNumber 3
0x00, // bAlternateSetting
0x00, // bNumEndpoints 0
0xFF, // bInterfaceClass
0xFD, // bInterfaceSubClass
0x13, // bInterfaceProtocol
0x04, // iInterface (String Index)
0x04, // bDescriptorType (Interface)
0x03, // bInterfaceNumber 3
0x00, // bAlternateSetting
0x00, // bNumEndpoints 0
0xFF, // bInterfaceClass
0xFD, // bInterfaceSubClass
0x13, // bInterfaceProtocol
0x04, // iInterface (String Index)

// SecurityDescriptor (XSM3)
0x06, // bLength
Expand Down
4 changes: 2 additions & 2 deletions headers/gp2040.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

class GP2040 {
public:
GP2040();
~GP2040();
GP2040(){}
~GP2040(){}
void setup(); // setup core0
void run(); // loop core0
private:
Expand Down
5 changes: 1 addition & 4 deletions src/drivers/shared/xinput_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ bool tuh_xinput_receive_report(uint8_t dev_addr, uint8_t instance) {
}

bool tuh_xinput_receive_vendor_report(uint8_t dev_addr, uint8_t instance, uint8_t request, uint16_t value, uint8_t index, uint16_t length, uint8_t * recvBuf) {
//xinputh_interface_t *xid_itf = get_instance(dev_addr, instance);
const tusb_control_request_t xfer_ctrl_req = {
.bmRequestType_bit {
.recipient = TUSB_REQ_RCPT_INTERFACE,
Expand Down Expand Up @@ -313,9 +312,7 @@ bool xinputh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const
// Set Configure
//--------------------------------------------------------------------+
static void config_driver_mount_complete(uint8_t dev_addr, uint8_t instance);
static void process_set_config(tuh_xfer_t *xfer) {

}
static void process_set_config(tuh_xfer_t *xfer);

bool xinputh_set_config(uint8_t dev_addr, uint8_t itf_num) {
uint8_t instance = get_instance_id_by_itfnum(dev_addr, itf_num);
Expand Down
Loading

0 comments on commit aed3e47

Please sign in to comment.