Created
December 29, 2020 03:11
-
-
Save SrgntBallistic/3eb88f745a3ad09d8d672e323af4ba3d to your computer and use it in GitHub Desktop.
USB Descriptors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************* | |
* Descriptor specific type definitions are defined in: | |
* usb_device.h | |
* | |
* Configuration options are defined in: | |
* usb_config.h | |
********************************************************************/ | |
/** INCLUDES *******************************************************/ | |
#include "usb.h" | |
#include "usb_device_hid.h" | |
/** CONSTANTS ******************************************************/ | |
#if defined(__18CXX) | |
#pragma romdata | |
#endif | |
/* Device Descriptor */ | |
const USB_DEVICE_DESCRIPTOR device_dsc = { | |
0x12, // Size of this descriptor in bytes | |
USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type | |
0x0200, // USB Spec Release Number in BCD format | |
0x00, // Class Code | |
0x00, // Subclass code | |
0x00, // Protocol code | |
USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h | |
MY_VID, // Vendor ID, see usb_config.h | |
MY_PID, // Specific Product ID 0xEAD3 for "GSI Wheel" | |
0x0001, // Device release number in BCD format | |
0x01, // Manufacturer string index | |
0x02, // Product string index | |
0x00, // Device serial number string index | |
0x01 // Number of possible configurations | |
}; | |
/* Configuration 1 Descriptor */ | |
const uint8_t configDescriptor1[] = { | |
/* Configuration Descriptor */ | |
0x09, //sizeof(USB_CFG_DSC), // Size of this descriptor in bytes | |
USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type | |
TOTAL_CONFIG_SIZE,0x00, // Total length of data for this cfg | |
2, // Number of interfaces in this cfg | |
1, // Index value of this configuration | |
0, // Configuration string index | |
_DEFAULT | _SELF, // Attributes, see usb_device.h | |
50, // Max power consumption (2X mA) | |
/* Joystick Interface Descriptor */ | |
0x09, //sizeof(USB_INTF_DSC), // Size of this descriptor in bytes | |
USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type | |
JOYSTICK_HID_INTF_ID, // Interface Number | |
0, // Alternate Setting Number | |
1, // Number of endpoints in this intf | |
HID_INTF, // Class code | |
0, // Subclass code | |
0, // Protocol code | |
3, // Interface string index | |
/* Joystick HID Class-Specific Descriptor */ | |
0x09, //sizeof(USB_HID_DSC)+3, // Size of this descriptor in bytes RRoj hack | |
DSC_HID, // HID descriptor type | |
0x11,0x01, // HID Spec Release Number in BCD format (1.11) | |
0x00, // Country Code (0x00 for Not supported) | |
JOYSTICK_HID_NUM_OF_DSC, // Number of class descriptors, see usbcfg.h | |
DSC_RPT, // Report descriptor type | |
JOYSTICK_HID_RPT01_SIZE,0x00, //sizeof(hid_rpt01), // Size of the report descriptor | |
/* Joystick Endpoint Descriptor */ | |
0x07, /*sizeof(USB_EP_DSC)*/ | |
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor | |
JOYSTICK_EP | _EP_IN, //EndpointAddress | |
_INTERRUPT, //Attributes | |
JOYSTICK_HID_INT_IN_EP_SIZE,0x00, //size | |
0x01, //Interval | |
/* Custom Interface Descriptor */ | |
0x09, //sizeof(USB_INTF_DSC), // Size of this descriptor in bytes | |
USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type | |
CUSTOM_HID_INTF_ID, // Interface Number | |
0, // Alternate Setting Number | |
2, // Number of endpoints in this intf | |
HID_INTF, // Class code | |
0, // Subclass code | |
0, // Protocol code | |
4, | |
/* Custom HID Class-Specific Descriptor */ | |
0x09, //sizeof(USB_HID_DSC)+3, // Size of this descriptor in bytes | |
DSC_HID, // HID descriptor type | |
0x11,0x01, // HID Spec Release Number in BCD format (1.11) | |
0x00, // Country Code (0x00 for Not supported) | |
CUSTOM_HID_NUM_OF_DSC, // Number of class descriptors, see usbcfg.h | |
DSC_RPT, // Report descriptor type | |
CUSTOM_HID_RPT01_SIZE,0x00, //sizeof(hid_rpt01), // Size of the report descriptor | |
/* Custom Endpoint IN Descriptor */ | |
0x07, /*sizeof(USB_EP_DSC)*/ | |
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor | |
CUSTOM_DEVICE_HID_EP | _EP_IN, //EndpointAddress | |
_INTERRUPT, //Attributes | |
CUSTOM_INT_IN_EP_SIZE,0x00, //size | |
0x01, //Interval | |
/* Custom Endpoint IN Descriptor */ | |
0x07, /*sizeof(USB_EP_DSC)*/ | |
USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor | |
CUSTOM_DEVICE_HID_EP | _EP_OUT, //EndpointAddress | |
_INTERRUPT, //Attributes | |
CUSTOM_INT_OUT_EP_SIZE,0x00, //size | |
0x01, //Interval | |
}; | |
//Language code string descriptor | |
const struct { | |
uint8_t bLength; | |
uint8_t bDscType; | |
uint16_t string[1]; | |
} | |
sd000 = { | |
sizeof (sd000), USB_DESCRIPTOR_STRING, { | |
0x0409 | |
} | |
}; | |
//Manufacturer string descriptor | |
const struct { | |
uint8_t bLength; | |
uint8_t bDscType; | |
uint16_t string[25]; | |
} | |
sd001 = { | |
sizeof (sd001), USB_DESCRIPTOR_STRING, { | |
'M', 'i', 'c', 'r', 'o', 'c', 'h', 'i', 'p', ' ', | |
'T', 'e', 'c', 'h', 'n', 'o', 'l', 'o', 'g', 'y', ' ', 'I', 'n', 'c', '.' | |
} | |
}; | |
//Product string descriptor | |
const struct { | |
uint8_t bLength; | |
uint8_t bDscType; | |
uint16_t string[18]; | |
} | |
sd002 = { | |
sizeof (sd002), USB_DESCRIPTOR_STRING, { | |
'G', 'S', 'I', ' ', 'S', 't', 'e', 'e', 'r', 'i', 'n', 'g', ' ', 'W', 'h', 'e', 'e', 'l' | |
} | |
}; | |
//Interface 1 Joystick string descriptor | |
const struct { | |
uint8_t bLength; | |
uint8_t bDscType; | |
uint16_t string[12]; | |
} | |
sd003 = { | |
sizeof (sd003), USB_DESCRIPTOR_STRING, { | |
'G', 'S', 'I', ' ', 'J', 'o', 'y', 's', 't', 'i', 'c', 'k' | |
} | |
}; | |
//Interface 2 Comms string descriptor | |
const struct { | |
uint8_t bLength; | |
uint8_t bDscType; | |
uint16_t string[12]; | |
} | |
sd004 = { | |
sizeof (sd004), USB_DESCRIPTOR_STRING, { | |
'G', 'S', 'I', ' ', 'C', 'o', 'm', 'm', 'a', 'n', 'd', 's' | |
} | |
}; | |
//Array of configuration descriptors | |
const uint8_t * const USB_CD_Ptr[] = { | |
(const uint8_t * const) &configDescriptor1 | |
}; | |
//Array of string descriptors | |
const uint8_t * const USB_SD_Ptr[] = { | |
(const uint8_t * const) &sd000, | |
(const uint8_t * const) &sd001, | |
(const uint8_t * const) &sd002, | |
(const uint8_t * const) &sd003, | |
(const uint8_t * const) &sd004 | |
}; | |
const struct { | |
uint8_t report[JOYSTICK_HID_RPT01_SIZE]; | |
} joystick_hid_rpt01 = { | |
{ | |
0x05, 0x01, //USAGE_PAGE (Generic Desktop) | |
0x09, 0x05, //USAGE (Game Pad) | |
0xA1, 0x01, //COLLECTION (Application) | |
0x15, 0x00, // LOGICAL_MINIMUM(0) | |
0x25, 0x01, // LOGICAL_MAXIMUM(1) | |
0x35, 0x00, // PHYSICAL_MINIMUM(0) | |
0x45, 0x01, // PHYSICAL_MAXIMUM(1) | |
0x75, 0x01, // REPORT_SIZE(1) | |
0x95, 30 /*0x0D*/, // REPORT_COUNT(13) | |
0x05, 0x09, // USAGE_PAGE(Button) | |
0x19, 0x01, // USAGE_MINIMUM(Button 1) | |
0x29, 30, // USAGE_MAXIMUM(Button 13) | |
0x81, 0x02, // INPUT(Data,Var,Abs) | |
0x95, 2, // REPORT_COUNT(3) Hier muss am Ende Mod 8 = 0 ergeben | |
0x81, 0x01, // INPUT(Cnst,Ary,Abs) | |
0x05, 0x01, // USAGE_PAGE(Generic Desktop) | |
0x25, 0x07, // LOGICAL_MAXIMUM(7) | |
0x46, 0x3B, 0x01, // PHYSICAL_MAXIMUM(315) | |
0x75, 0x04, // REPORT_SIZE(4) | |
0x95, 0x01, // REPORT_COUNT(1) | |
0x65, 0x14, // UNIT(Eng Rot:Angular Pos) | |
0x09, 0x39, // USAGE(Hat Switch) | |
0x81, 0x42, // INPUT(Data,Var,Abs,Null) | |
0x65, 0x00, // UNIT(None) | |
0x95, 0x01, // REPORT_COUNT(1) | |
0x81, 0x01, // INPUT(Cnst,Ary,Abs) | |
0x26, 0xFF, 0x00, // LOGICAL_MAXIMUM(255) | |
0x46, 0xFF, 0x00, // PHYSICAL_MAXIMUM(255) | |
0x09, 0x30, // USAGE(X) | |
0x09, 0x31, // USAGE(Y) | |
0x09, 0x32, // USAGE(Z) | |
0x09, 0x35, // USAGE(Rz) | |
0x75, 0x08, // REPORT_SIZE(8) | |
0x95, 4, // REPORT_COUNT(2) | |
0x81, 0x02, // INPUT(Data,Var,Abs) | |
0xC0 //END_COLLECTION | |
} | |
}; | |
//Class specific descriptor - HID | |
const struct { | |
uint8_t report[CUSTOM_HID_RPT01_SIZE]; | |
} custom_hid_rpt01 = { | |
{ | |
0x06, 0x00, 0xFF, // Usage Page = 0xFF00 (Vendor Defined Page 1) | |
0x09, 0x01, // Usage (Vendor Usage 1) | |
0xA1, 0x01, // Collection (Application) | |
0x19, 0x01, // Usage Minimum | |
0x29, 0x40, // Usage Maximum //64 input usages total (0x01 to 0x40) | |
0x15, 0x00, // Logical Minimum (data bytes in the report may have minimum value = 0x00) | |
0x26, 0xFF, 0x00, // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255) | |
0x75, 0x08, // Report Size: 8-bit field size | |
0x95, 0x40, // Report Count: Make sixty-four 8-bit fields (the next time the parser hits an "Input", "Output", or "Feature" item) | |
0x81, 0x00, // Input (Data, Array, Abs): Instantiates input packet fields based on the above report size, count, logical min/max, and usage. | |
0x19, 0x01, // Usage Minimum | |
0x29, 0x40, // Usage Maximum //64 output usages total (0x01 to 0x40) | |
0x91, 0x00, // Output (Data, Array, Abs): Instantiates output packet fields. Uses same report size and count as "Input" fields, since nothing new/different was specified to the parser since the "Input" item. | |
0xC0 | |
} // End Collection | |
}; | |
/** EOF usb_descriptors.c ***************************************************/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment