Make the configuration descriptor easier to read along with the rest of the file.
This commit is contained in:
+101
-112
@@ -11,130 +11,118 @@
|
|||||||
#include "usb_mouse_descriptors.h"
|
#include "usb_mouse_descriptors.h"
|
||||||
|
|
||||||
uint8_t g_UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = {
|
uint8_t g_UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = {
|
||||||
USB_DESCRIPTOR_LENGTH_DEVICE, /* Size of this descriptor in bytes */
|
USB_DESCRIPTOR_LENGTH_DEVICE,
|
||||||
USB_DESCRIPTOR_TYPE_DEVICE, /* DEVICE Descriptor Type */
|
USB_DESCRIPTOR_TYPE_DEVICE,
|
||||||
USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION),
|
USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION),
|
||||||
USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), /* USB Specification Release Number in
|
USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), // USB Specification Release Number in
|
||||||
Binary-Coded Decimal (i.e., 2.10 is 210H). */
|
// Binary-Coded Decimal (i.e., 2.10 is 210H).
|
||||||
USB_DEVICE_CLASS, /* Class code (assigned by the USB-IF). */
|
USB_DEVICE_CLASS,
|
||||||
USB_DEVICE_SUBCLASS, /* Subclass code (assigned by the USB-IF). */
|
USB_DEVICE_SUBCLASS,
|
||||||
USB_DEVICE_PROTOCOL, /* Protocol code (assigned by the USB-IF). */
|
USB_DEVICE_PROTOCOL,
|
||||||
USB_CONTROL_MAX_PACKET_SIZE, /* Maximum packet size for endpoint zero
|
USB_CONTROL_MAX_PACKET_SIZE, // Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid)
|
||||||
(only 8, 16, 32, or 64 are valid) */
|
0xA2U, 0x15U, // Vendor ID (assigned by the USB-IF)
|
||||||
0xA2U, 0x15U, /* Vendor ID (assigned by the USB-IF) */
|
0x7EU, 0x00U, // Product ID (assigned by the manufacturer)
|
||||||
0x7EU, 0x00U, /* Product ID (assigned by the manufacturer) */
|
|
||||||
USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION),
|
USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION),
|
||||||
USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION), /* Device release number in binary-coded decimal */
|
USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION), // Device release number in binary-coded decimal
|
||||||
0x01U, /* Index of string descriptor describing manufacturer */
|
0x01U, // Index of string descriptor describing manufacturer
|
||||||
0x02U, /* Index of string descriptor describing product */
|
0x02U, // Index of string descriptor describing product
|
||||||
0x00U, /* Index of string descriptor describing the
|
0x00U, // Index of string descriptor describing the device's serial number
|
||||||
device's serial number */
|
USB_DEVICE_CONFIGURATION_COUNT,
|
||||||
USB_DEVICE_CONFIGURATION_COUNT, /* Number of possible configurations */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t g_UsbDeviceConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = {
|
uint8_t g_UsbDeviceConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = {
|
||||||
USB_DESCRIPTOR_LENGTH_CONFIGURE, /* Size of this descriptor in bytes */
|
|
||||||
USB_DESCRIPTOR_TYPE_CONFIGURE, /* CONFIGURATION Descriptor Type */
|
// Configuration descriptor
|
||||||
|
|
||||||
|
USB_DESCRIPTOR_LENGTH_CONFIGURE,
|
||||||
|
USB_DESCRIPTOR_TYPE_CONFIGURE,
|
||||||
USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL),
|
USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL),
|
||||||
USB_SHORT_GET_HIGH(
|
USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL), // Total length of data returned for this configuration.
|
||||||
USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL), /* Total length of data returned for this configuration. */
|
USB_COMPOSITE_INTERFACE_COUNT,
|
||||||
USB_COMPOSITE_INTERFACE_COUNT, /* Number of interfaces supported by this configuration */
|
USB_COMPOSITE_CONFIGURE_INDEX, // Value to use as an argument to the SetConfiguration() request to select this configuration
|
||||||
USB_COMPOSITE_CONFIGURE_INDEX, /* Value to use as an argument to the
|
0x00U, // Index of string descriptor describing this configuration
|
||||||
SetConfiguration() request to select this configuration */
|
|
||||||
0x00U, /* Index of string descriptor describing this configuration */
|
// Configuration characteristics
|
||||||
|
// D7: Reserved (set to one)
|
||||||
|
// D6: Self-powered
|
||||||
|
// D5: Remote Wakeup
|
||||||
|
// D4...0: Reserved (reset to zero)
|
||||||
(USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_MASK) |
|
(USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_MASK) |
|
||||||
(USB_DEVICE_CONFIG_SELF_POWER << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_SELF_POWERED_SHIFT) |
|
(USB_DEVICE_CONFIG_SELF_POWER << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_SELF_POWERED_SHIFT) |
|
||||||
(USB_DEVICE_CONFIG_REMOTE_WAKEUP << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_REMOTE_WAKEUP_SHIFT),
|
(USB_DEVICE_CONFIG_REMOTE_WAKEUP << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_REMOTE_WAKEUP_SHIFT),
|
||||||
/* Configuration characteristics
|
|
||||||
D7: Reserved (set to one)
|
|
||||||
D6: Self-powered
|
|
||||||
D5: Remote Wakeup
|
|
||||||
D4...0: Reserved (reset to zero)
|
|
||||||
*/
|
|
||||||
USB_DEVICE_MAX_POWER, /* Maximum power consumption of the USB
|
|
||||||
* device from the bus in this specific
|
|
||||||
* configuration when the device is fully
|
|
||||||
* operational. Expressed in 2 mA units
|
|
||||||
* (i.e., 50 = 100 mA).
|
|
||||||
*/
|
|
||||||
USB_DESCRIPTOR_LENGTH_INTERFACE, /* Size of this descriptor in bytes */
|
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type */
|
|
||||||
USB_HID_MOUSE_INTERFACE_INDEX, /* Number of this interface. */
|
|
||||||
0x00U, /* Value used to select this alternate setting
|
|
||||||
for the interface identified in the prior field */
|
|
||||||
USB_HID_MOUSE_ENDPOINT_COUNT, /* Number of endpoints used by this
|
|
||||||
interface (excluding endpoint zero). */
|
|
||||||
USB_HID_MOUSE_CLASS, /* Class code (assigned by the USB-IF). */
|
|
||||||
USB_HID_MOUSE_SUBCLASS, /* Subclass code (assigned by the USB-IF). */
|
|
||||||
USB_HID_MOUSE_PROTOCOL, /* Protocol code (assigned by the USB). */
|
|
||||||
0x03U, /* Index of string descriptor describing this interface */
|
|
||||||
|
|
||||||
USB_DESCRIPTOR_LENGTH_HID, /* Numeric expression that is the total size of the
|
// Maximum power consumption of the USB device from the bus in this specific configuration
|
||||||
HID descriptor. */
|
// when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
|
||||||
USB_DESCRIPTOR_TYPE_HID, /* Constant name specifying type of HID
|
USB_DEVICE_MAX_POWER,
|
||||||
descriptor. */
|
|
||||||
0x00U, 0x01U, /* Numeric expression identifying the HID Class
|
// Mouse interface descriptor
|
||||||
Specification release. */
|
|
||||||
0x00U, /* Numeric expression identifying country code of
|
USB_DESCRIPTOR_LENGTH_INTERFACE,
|
||||||
the localized hardware */
|
USB_DESCRIPTOR_TYPE_INTERFACE,
|
||||||
0x01U, /* Numeric expression specifying the number of
|
USB_HID_MOUSE_INTERFACE_INDEX,
|
||||||
class descriptors(at least one report descriptor) */
|
0x00U, // Value used to select this alternate setting for the interface identified in the prior field
|
||||||
USB_DESCRIPTOR_TYPE_HID_REPORT, /* Constant name identifying type of class descriptor. */
|
USB_HID_MOUSE_ENDPOINT_COUNT,
|
||||||
|
USB_HID_MOUSE_CLASS,
|
||||||
|
USB_HID_MOUSE_SUBCLASS,
|
||||||
|
USB_HID_MOUSE_PROTOCOL,
|
||||||
|
0x03U, // Index of string descriptor describing this interface
|
||||||
|
|
||||||
|
// Mouse HID descriptor
|
||||||
|
|
||||||
|
USB_DESCRIPTOR_LENGTH_HID,
|
||||||
|
USB_DESCRIPTOR_TYPE_HID,
|
||||||
|
0x00U, 0x01U, // ID Class Specification release.
|
||||||
|
0x00U, // Country code of the localized hardware
|
||||||
|
0x01U, // Number of class descriptors (at least one report descriptor)
|
||||||
|
USB_DESCRIPTOR_TYPE_HID_REPORT,
|
||||||
USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT),
|
USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT),
|
||||||
USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT),
|
USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT),
|
||||||
/* Numeric expression that is the total size of the
|
|
||||||
Report descriptor. */
|
// Mouse endpoint descriptor
|
||||||
USB_DESCRIPTOR_LENGTH_ENDPOINT, /* Size of this descriptor in bytes */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* ENDPOINT Descriptor Type */
|
USB_DESCRIPTOR_LENGTH_ENDPOINT,
|
||||||
|
USB_DESCRIPTOR_TYPE_ENDPOINT,
|
||||||
|
// The address of the endpoint on the USB device described by this descriptor.
|
||||||
USB_HID_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
USB_HID_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||||
/* The address of the endpoint on the USB device
|
USB_ENDPOINT_INTERRUPT, // This field describes the endpoint's attributes
|
||||||
described by this descriptor. */
|
// Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected.
|
||||||
USB_ENDPOINT_INTERRUPT, /* This field describes the endpoint's attributes */
|
|
||||||
USB_SHORT_GET_LOW(FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE), USB_SHORT_GET_HIGH(FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE),
|
USB_SHORT_GET_LOW(FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE), USB_SHORT_GET_HIGH(FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE),
|
||||||
/* Maximum packet size this endpoint is capable of
|
FS_HID_MOUSE_INTERRUPT_IN_INTERVAL, // Interval for polling endpoint for data transfers.
|
||||||
sending or receiving when this configuration is
|
|
||||||
selected. */
|
|
||||||
FS_HID_MOUSE_INTERRUPT_IN_INTERVAL, /* Interval for polling endpoint for data transfers. */
|
|
||||||
|
|
||||||
USB_DESCRIPTOR_LENGTH_INTERFACE, /* Size of this descriptor in bytes */
|
// Keyboard interface descriptor
|
||||||
USB_DESCRIPTOR_TYPE_INTERFACE, /* INTERFACE Descriptor Type */
|
|
||||||
USB_HID_KEYBOARD_INTERFACE_INDEX, /* Number of this interface. */
|
|
||||||
0x00U, /* Value used to select this alternate setting
|
|
||||||
for the interface identified in the prior field */
|
|
||||||
USB_HID_KEYBOARD_ENDPOINT_COUNT, /* Number of endpoints used by this
|
|
||||||
interface (excluding endpoint zero). */
|
|
||||||
USB_HID_KEYBOARD_CLASS, /* Class code (assigned by the USB-IF). */
|
|
||||||
USB_HID_KEYBOARD_SUBCLASS, /* Subclass code (assigned by the USB-IF). */
|
|
||||||
USB_HID_KEYBOARD_PROTOCOL, /* Protocol code (assigned by the USB). */
|
|
||||||
0x04U, /* Index of string descriptor describing this interface */
|
|
||||||
|
|
||||||
USB_DESCRIPTOR_LENGTH_HID, /* Numeric expression that is the total size of the
|
USB_DESCRIPTOR_LENGTH_INTERFACE,
|
||||||
HID descriptor. */
|
USB_DESCRIPTOR_TYPE_INTERFACE,
|
||||||
USB_DESCRIPTOR_TYPE_HID, /* Constant name specifying type of HID
|
USB_HID_KEYBOARD_INTERFACE_INDEX,
|
||||||
descriptor. */
|
0x00U, // Value used to select this alternate setting for the interface identified in the prior field
|
||||||
0x00U, 0x01U, /* Numeric expression identifying the HID Class
|
USB_HID_KEYBOARD_ENDPOINT_COUNT,
|
||||||
Specification release. */
|
USB_HID_KEYBOARD_CLASS,
|
||||||
0x00U, /* Numeric expression identifying country code of
|
USB_HID_KEYBOARD_SUBCLASS,
|
||||||
the localized hardware */
|
USB_HID_KEYBOARD_PROTOCOL,
|
||||||
0x01U, /* Numeric expression specifying the number of
|
0x04U, // Index of string descriptor describing this interface
|
||||||
class descriptors(at least one report descriptor) */
|
|
||||||
USB_DESCRIPTOR_TYPE_HID_REPORT, /* Constant name identifying type of class descriptor. */
|
// Keyboard HID descriptor
|
||||||
|
|
||||||
|
USB_DESCRIPTOR_LENGTH_HID,
|
||||||
|
USB_DESCRIPTOR_TYPE_HID,
|
||||||
|
0x00U, 0x01U, // HID Class Specification release
|
||||||
|
0x00U, // Country code of the localized hardware
|
||||||
|
0x01U, // Number of class descriptors (at least one report descriptor)
|
||||||
|
USB_DESCRIPTOR_TYPE_HID_REPORT,
|
||||||
USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT),
|
USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT),
|
||||||
USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT),
|
USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT),
|
||||||
/* Numeric expression that is the total size of the
|
|
||||||
Report descriptor. */
|
// Keyboard endpoint descriptor
|
||||||
USB_DESCRIPTOR_LENGTH_ENDPOINT, /* Size of this descriptor in bytes */
|
|
||||||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* ENDPOINT Descriptor Type */
|
USB_DESCRIPTOR_LENGTH_ENDPOINT,
|
||||||
|
USB_DESCRIPTOR_TYPE_ENDPOINT,
|
||||||
USB_HID_KEYBOARD_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
USB_HID_KEYBOARD_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||||
/* The address of the endpoint on the USB device
|
// The address of the endpoint on the USB device described by this descriptor.
|
||||||
described by this descriptor. */
|
USB_ENDPOINT_INTERRUPT, // This field describes the endpoint's attributes
|
||||||
USB_ENDPOINT_INTERRUPT, /* This field describes the endpoint's attributes */
|
|
||||||
USB_SHORT_GET_LOW(FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
|
USB_SHORT_GET_LOW(FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
|
||||||
USB_SHORT_GET_HIGH(FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
|
USB_SHORT_GET_HIGH(FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
|
||||||
/* Maximum packet size this endpoint is capable of
|
// Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected.
|
||||||
sending or receiving when this configuration is
|
FS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL, // Interval for polling endpoint for data transfers.
|
||||||
selected. */
|
|
||||||
FS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL, /* Interval for polling endpoint for data transfers. */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t g_UsbDeviceString0[USB_DESCRIPTOR_LENGTH_STRING0] = {
|
uint8_t g_UsbDeviceString0[USB_DESCRIPTOR_LENGTH_STRING0] = {
|
||||||
@@ -212,8 +200,8 @@ usb_language_list_t g_UsbDeviceLanguageList = {
|
|||||||
g_UsbDeviceString0, sizeof(g_UsbDeviceString0), g_UsbDeviceLanguage, USB_DEVICE_LANGUAGE_COUNT,
|
g_UsbDeviceString0, sizeof(g_UsbDeviceString0), g_UsbDeviceLanguage, USB_DEVICE_LANGUAGE_COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
usb_status_t USB_DeviceGetDeviceDescriptor(usb_device_handle handle,
|
usb_status_t USB_DeviceGetDeviceDescriptor(
|
||||||
usb_device_get_device_descriptor_struct_t *deviceDescriptor)
|
usb_device_handle handle, usb_device_get_device_descriptor_struct_t *deviceDescriptor)
|
||||||
{
|
{
|
||||||
deviceDescriptor->buffer = g_UsbDeviceDescriptor;
|
deviceDescriptor->buffer = g_UsbDeviceDescriptor;
|
||||||
deviceDescriptor->length = USB_DESCRIPTOR_LENGTH_DEVICE;
|
deviceDescriptor->length = USB_DESCRIPTOR_LENGTH_DEVICE;
|
||||||
@@ -231,8 +219,8 @@ usb_status_t USB_DeviceGetConfigurationDescriptor(
|
|||||||
return kStatus_USB_InvalidRequest;
|
return kStatus_USB_InvalidRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_status_t USB_DeviceGetStringDescriptor(usb_device_handle handle,
|
usb_status_t USB_DeviceGetStringDescriptor(
|
||||||
usb_device_get_string_descriptor_struct_t *stringDescriptor)
|
usb_device_handle handle, usb_device_get_string_descriptor_struct_t *stringDescriptor)
|
||||||
{
|
{
|
||||||
if (stringDescriptor->stringIndex == 0U) {
|
if (stringDescriptor->stringIndex == 0U) {
|
||||||
stringDescriptor->buffer = (uint8_t *)g_UsbDeviceLanguageList.languageString;
|
stringDescriptor->buffer = (uint8_t *)g_UsbDeviceLanguageList.languageString;
|
||||||
@@ -259,13 +247,14 @@ usb_status_t USB_DeviceGetStringDescriptor(usb_device_handle handle,
|
|||||||
return kStatus_USB_Success;
|
return kStatus_USB_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_status_t USB_DeviceGetHidDescriptor(usb_device_handle handle, usb_device_get_hid_descriptor_struct_t *hidDescriptor)
|
usb_status_t USB_DeviceGetHidDescriptor(
|
||||||
|
usb_device_handle handle, usb_device_get_hid_descriptor_struct_t *hidDescriptor)
|
||||||
{
|
{
|
||||||
return kStatus_USB_InvalidRequest;
|
return kStatus_USB_InvalidRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_status_t USB_DeviceGetHidReportDescriptor(usb_device_handle handle,
|
usb_status_t USB_DeviceGetHidReportDescriptor(
|
||||||
usb_device_get_hid_report_descriptor_struct_t *hidReportDescriptor)
|
usb_device_handle handle, usb_device_get_hid_report_descriptor_struct_t *hidReportDescriptor)
|
||||||
{
|
{
|
||||||
if (USB_HID_MOUSE_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
|
if (USB_HID_MOUSE_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
|
||||||
hidReportDescriptor->buffer = g_UsbDeviceHidMouseReportDescriptor;
|
hidReportDescriptor->buffer = g_UsbDeviceHidMouseReportDescriptor;
|
||||||
@@ -279,8 +268,8 @@ usb_status_t USB_DeviceGetHidReportDescriptor(usb_device_handle handle,
|
|||||||
return kStatus_USB_Success;
|
return kStatus_USB_Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
usb_status_t USB_DeviceGetHidPhysicalDescriptor(usb_device_handle handle,
|
usb_status_t USB_DeviceGetHidPhysicalDescriptor(
|
||||||
usb_device_get_hid_physical_descriptor_struct_t *hidPhysicalDescriptor)
|
usb_device_handle handle, usb_device_get_hid_physical_descriptor_struct_t *hidPhysicalDescriptor)
|
||||||
{
|
{
|
||||||
return kStatus_USB_InvalidRequest;
|
return kStatus_USB_InvalidRequest;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user