|
| 1 | +// Standard definitions for USB commands and data structures |
| 2 | +#ifndef __GENERIC_USBSTD_H |
| 3 | +#define __GENERIC_USBSTD_H |
| 4 | + |
| 5 | +#include <stdint.h> // uint8_t |
| 6 | +#include "compiler.h" // PACKED |
| 7 | + |
| 8 | +#define USB_DIR_OUT 0 /* to device */ |
| 9 | +#define USB_DIR_IN 0x80 /* to host */ |
| 10 | + |
| 11 | +#define USB_REQ_GET_STATUS 0x00 |
| 12 | +#define USB_REQ_CLEAR_FEATURE 0x01 |
| 13 | +#define USB_REQ_SET_FEATURE 0x03 |
| 14 | +#define USB_REQ_SET_ADDRESS 0x05 |
| 15 | +#define USB_REQ_GET_DESCRIPTOR 0x06 |
| 16 | +#define USB_REQ_SET_DESCRIPTOR 0x07 |
| 17 | +#define USB_REQ_GET_CONFIGURATION 0x08 |
| 18 | +#define USB_REQ_SET_CONFIGURATION 0x09 |
| 19 | +#define USB_REQ_GET_INTERFACE 0x0A |
| 20 | +#define USB_REQ_SET_INTERFACE 0x0B |
| 21 | +#define USB_REQ_SYNCH_FRAME 0x0C |
| 22 | + |
| 23 | +struct usb_ctrlrequest { |
| 24 | + uint8_t bRequestType; |
| 25 | + uint8_t bRequest; |
| 26 | + uint16_t wValue; |
| 27 | + uint16_t wIndex; |
| 28 | + uint16_t wLength; |
| 29 | +} PACKED; |
| 30 | + |
| 31 | +#define USB_DT_DEVICE 0x01 |
| 32 | +#define USB_DT_CONFIG 0x02 |
| 33 | +#define USB_DT_STRING 0x03 |
| 34 | +#define USB_DT_INTERFACE 0x04 |
| 35 | +#define USB_DT_ENDPOINT 0x05 |
| 36 | +#define USB_DT_DEVICE_QUALIFIER 0x06 |
| 37 | +#define USB_DT_OTHER_SPEED_CONFIG 0x07 |
| 38 | +#define USB_DT_ENDPOINT_COMPANION 0x30 |
| 39 | + |
| 40 | +struct usb_device_descriptor { |
| 41 | + uint8_t bLength; |
| 42 | + uint8_t bDescriptorType; |
| 43 | + |
| 44 | + uint16_t bcdUSB; |
| 45 | + uint8_t bDeviceClass; |
| 46 | + uint8_t bDeviceSubClass; |
| 47 | + uint8_t bDeviceProtocol; |
| 48 | + uint8_t bMaxPacketSize0; |
| 49 | + uint16_t idVendor; |
| 50 | + uint16_t idProduct; |
| 51 | + uint16_t bcdDevice; |
| 52 | + uint8_t iManufacturer; |
| 53 | + uint8_t iProduct; |
| 54 | + uint8_t iSerialNumber; |
| 55 | + uint8_t bNumConfigurations; |
| 56 | +} PACKED; |
| 57 | + |
| 58 | +#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */ |
| 59 | +#define USB_CLASS_AUDIO 1 |
| 60 | +#define USB_CLASS_COMM 2 |
| 61 | +#define USB_CLASS_HID 3 |
| 62 | +#define USB_CLASS_PHYSICAL 5 |
| 63 | +#define USB_CLASS_STILL_IMAGE 6 |
| 64 | +#define USB_CLASS_PRINTER 7 |
| 65 | +#define USB_CLASS_MASS_STORAGE 8 |
| 66 | +#define USB_CLASS_HUB 9 |
| 67 | + |
| 68 | +struct usb_config_descriptor { |
| 69 | + uint8_t bLength; |
| 70 | + uint8_t bDescriptorType; |
| 71 | + |
| 72 | + uint16_t wTotalLength; |
| 73 | + uint8_t bNumInterfaces; |
| 74 | + uint8_t bConfigurationValue; |
| 75 | + uint8_t iConfiguration; |
| 76 | + uint8_t bmAttributes; |
| 77 | + uint8_t bMaxPower; |
| 78 | +} PACKED; |
| 79 | + |
| 80 | +struct usb_interface_descriptor { |
| 81 | + uint8_t bLength; |
| 82 | + uint8_t bDescriptorType; |
| 83 | + |
| 84 | + uint8_t bInterfaceNumber; |
| 85 | + uint8_t bAlternateSetting; |
| 86 | + uint8_t bNumEndpoints; |
| 87 | + uint8_t bInterfaceClass; |
| 88 | + uint8_t bInterfaceSubClass; |
| 89 | + uint8_t bInterfaceProtocol; |
| 90 | + uint8_t iInterface; |
| 91 | +} PACKED; |
| 92 | + |
| 93 | +struct usb_endpoint_descriptor { |
| 94 | + uint8_t bLength; |
| 95 | + uint8_t bDescriptorType; |
| 96 | + |
| 97 | + uint8_t bEndpointAddress; |
| 98 | + uint8_t bmAttributes; |
| 99 | + uint16_t wMaxPacketSize; |
| 100 | + uint8_t bInterval; |
| 101 | +} PACKED; |
| 102 | + |
| 103 | +#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ |
| 104 | +#define USB_ENDPOINT_DIR_MASK 0x80 |
| 105 | + |
| 106 | +#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ |
| 107 | +#define USB_ENDPOINT_XFER_CONTROL 0 |
| 108 | +#define USB_ENDPOINT_XFER_ISOC 1 |
| 109 | +#define USB_ENDPOINT_XFER_BULK 2 |
| 110 | +#define USB_ENDPOINT_XFER_INT 3 |
| 111 | +#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 |
| 112 | + |
| 113 | +struct usb_string_descriptor { |
| 114 | + uint8_t bLength; |
| 115 | + uint8_t bDescriptorType; |
| 116 | + uint16_t data[]; |
| 117 | +} PACKED; |
| 118 | + |
| 119 | +#define USB_LANGID_ENGLISH_US 0x0409 |
| 120 | + |
| 121 | +#endif // usbstd.h |
0 commit comments