1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
|
---|
2 |
|
---|
3 | This software may be distributed and modified under the terms of the GNU
|
---|
4 | General Public License version 2 (GPL2) as published by the Free Software
|
---|
5 | Foundation and appearing in the file GPL2.TXT included in the packaging of
|
---|
6 | this file. Please note that GPL2 Section 2[b] requires that all works based
|
---|
7 | on this software must also be made publicly available under the terms of
|
---|
8 | the GPL2 ("Copyleft").
|
---|
9 |
|
---|
10 | Contact information
|
---|
11 | -------------------
|
---|
12 |
|
---|
13 | Circuits At Home, LTD
|
---|
14 | Web : http://www.circuitsathome.com
|
---|
15 | e-mail : support@circuitsathome.com
|
---|
16 | */
|
---|
17 | /* USB chapter 9 structures */
|
---|
18 |
|
---|
19 | #ifndef USB_CH9_H_INCLUDED
|
---|
20 | #define USB_CH9_H_INCLUDED
|
---|
21 |
|
---|
22 | #include <stdint.h>
|
---|
23 |
|
---|
24 | /* Misc.USB constants */
|
---|
25 | #define DEV_DESCR_LEN 18 //device descriptor length
|
---|
26 | #define CONF_DESCR_LEN 9 //configuration descriptor length
|
---|
27 | #define INTR_DESCR_LEN 9 //interface descriptor length
|
---|
28 | #define EP_DESCR_LEN 7 //endpoint descriptor length
|
---|
29 |
|
---|
30 | /* Standard Device Requests */
|
---|
31 |
|
---|
32 | #define USB_REQUEST_GET_STATUS 0 // Standard Device Request - GET STATUS
|
---|
33 | #define USB_REQUEST_CLEAR_FEATURE 1 // Standard Device Request - CLEAR FEATURE
|
---|
34 | #define USB_REQUEST_SET_FEATURE 3 // Standard Device Request - SET FEATURE
|
---|
35 | #define USB_REQUEST_SET_ADDRESS 5 // Standard Device Request - SET ADDRESS
|
---|
36 | #define USB_REQUEST_GET_DESCRIPTOR 6 // Standard Device Request - GET DESCRIPTOR
|
---|
37 | #define USB_REQUEST_SET_DESCRIPTOR 7 // Standard Device Request - SET DESCRIPTOR
|
---|
38 | #define USB_REQUEST_GET_CONFIGURATION 8 // Standard Device Request - GET CONFIGURATION
|
---|
39 | #define USB_REQUEST_SET_CONFIGURATION 9 // Standard Device Request - SET CONFIGURATION
|
---|
40 | #define USB_REQUEST_GET_INTERFACE 10 // Standard Device Request - GET INTERFACE
|
---|
41 | #define USB_REQUEST_SET_INTERFACE 11 // Standard Device Request - SET INTERFACE
|
---|
42 | #define USB_REQUEST_SYNCH_FRAME 12 // Standard Device Request - SYNCH FRAME
|
---|
43 |
|
---|
44 | #define USB_FEATURE_ENDPOINT_HALT 0 // CLEAR/SET FEATURE - Endpoint Halt
|
---|
45 | #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // CLEAR/SET FEATURE - Device remote wake-up
|
---|
46 | #define USB_FEATURE_TEST_MODE 2 // CLEAR/SET FEATURE - Test mode
|
---|
47 |
|
---|
48 | /* Setup Data Constants */
|
---|
49 |
|
---|
50 | #define USB_SETUP_HOST_TO_DEVICE 0x00 // Device Request bmRequestType transfer direction - host to device transfer
|
---|
51 | #define USB_SETUP_DEVICE_TO_HOST 0x80 // Device Request bmRequestType transfer direction - device to host transfer
|
---|
52 | #define USB_SETUP_TYPE_STANDARD 0x00 // Device Request bmRequestType type - standard
|
---|
53 | #define USB_SETUP_TYPE_CLASS 0x20 // Device Request bmRequestType type - class
|
---|
54 | #define USB_SETUP_TYPE_VENDOR 0x40 // Device Request bmRequestType type - vendor
|
---|
55 | #define USB_SETUP_RECIPIENT_DEVICE 0x00 // Device Request bmRequestType recipient - device
|
---|
56 | #define USB_SETUP_RECIPIENT_INTERFACE 0x01 // Device Request bmRequestType recipient - interface
|
---|
57 | #define USB_SETUP_RECIPIENT_ENDPOINT 0x02 // Device Request bmRequestType recipient - endpoint
|
---|
58 | #define USB_SETUP_RECIPIENT_OTHER 0x03 // Device Request bmRequestType recipient - other
|
---|
59 |
|
---|
60 | /* USB descriptors */
|
---|
61 |
|
---|
62 | #define USB_DESCRIPTOR_DEVICE 0x01 // bDescriptorType for a Device Descriptor.
|
---|
63 | #define USB_DESCRIPTOR_CONFIGURATION 0x02 // bDescriptorType for a Configuration Descriptor.
|
---|
64 | #define USB_DESCRIPTOR_STRING 0x03 // bDescriptorType for a String Descriptor.
|
---|
65 | #define USB_DESCRIPTOR_INTERFACE 0x04 // bDescriptorType for an Interface Descriptor.
|
---|
66 | #define USB_DESCRIPTOR_ENDPOINT 0x05 // bDescriptorType for an Endpoint Descriptor.
|
---|
67 | #define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06 // bDescriptorType for a Device Qualifier.
|
---|
68 | #define USB_DESCRIPTOR_OTHER_SPEED 0x07 // bDescriptorType for a Other Speed Configuration.
|
---|
69 | #define USB_DESCRIPTOR_INTERFACE_POWER 0x08 // bDescriptorType for Interface Power.
|
---|
70 | #define USB_DESCRIPTOR_OTG 0x09 // bDescriptorType for an OTG Descriptor.
|
---|
71 |
|
---|
72 | #define HID_DESCRIPTOR_HID 0x21
|
---|
73 |
|
---|
74 |
|
---|
75 |
|
---|
76 | /* OTG SET FEATURE Constants */
|
---|
77 | #define OTG_FEATURE_B_HNP_ENABLE 3 // SET FEATURE OTG - Enable B device to perform HNP
|
---|
78 | #define OTG_FEATURE_A_HNP_SUPPORT 4 // SET FEATURE OTG - A device supports HNP
|
---|
79 | #define OTG_FEATURE_A_ALT_HNP_SUPPORT 5 // SET FEATURE OTG - Another port on the A device supports HNP
|
---|
80 |
|
---|
81 | /* USB Endpoint Transfer Types */
|
---|
82 | #define USB_TRANSFER_TYPE_CONTROL 0x00 // Endpoint is a control endpoint.
|
---|
83 | #define USB_TRANSFER_TYPE_ISOCHRONOUS 0x01 // Endpoint is an isochronous endpoint.
|
---|
84 | #define USB_TRANSFER_TYPE_BULK 0x02 // Endpoint is a bulk endpoint.
|
---|
85 | #define USB_TRANSFER_TYPE_INTERRUPT 0x03 // Endpoint is an interrupt endpoint.
|
---|
86 | #define bmUSB_TRANSFER_TYPE 0x03 // bit mask to separate transfer type from ISO attributes
|
---|
87 |
|
---|
88 |
|
---|
89 | /* Standard Feature Selectors for CLEAR_FEATURE Requests */
|
---|
90 | #define USB_FEATURE_ENDPOINT_STALL 0 // Endpoint recipient
|
---|
91 | #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 // Device recipient
|
---|
92 | #define USB_FEATURE_TEST_MODE 2 // Device recipient
|
---|
93 |
|
---|
94 | _Pragma("pack(1)")
|
---|
95 |
|
---|
96 | /* descriptor data structures */
|
---|
97 |
|
---|
98 | /* Device descriptor structure */
|
---|
99 | typedef struct
|
---|
100 | {
|
---|
101 | uint8_t bLength; // Length of this descriptor.
|
---|
102 | uint8_t bDescriptorType; // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE).
|
---|
103 | uint16_t bcdUSB; // USB Spec Release Number (BCD).
|
---|
104 | uint8_t bDeviceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
|
---|
105 | uint8_t bDeviceSubClass; // Subclass code (assigned by the USB-IF).
|
---|
106 | uint8_t bDeviceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
|
---|
107 | uint8_t bMaxPacketSize0; // Maximum packet size for endpoint 0.
|
---|
108 | uint16_t idVendor; // Vendor ID (assigned by the USB-IF).
|
---|
109 | uint16_t idProduct; // Product ID (assigned by the manufacturer).
|
---|
110 | uint16_t bcdDevice; // Device release number (BCD).
|
---|
111 | uint8_t iManufacturer; // Index of String Descriptor describing the manufacturer.
|
---|
112 | uint8_t iProduct; // Index of String Descriptor describing the product.
|
---|
113 | uint8_t iSerialNumber; // Index of String Descriptor with the device's serial number.
|
---|
114 | uint8_t bNumConfigurations; // Number of possible configurations.
|
---|
115 | } USB_DEVICE_DESCRIPTOR;
|
---|
116 |
|
---|
117 | /* Configuration descriptor structure */
|
---|
118 | typedef struct
|
---|
119 | {
|
---|
120 | uint8_t bLength; // Length of this descriptor.
|
---|
121 | uint8_t bDescriptorType; // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION).
|
---|
122 | uint16_t wTotalLength; // Total length of all descriptors for this configuration.
|
---|
123 | uint8_t bNumInterfaces; // Number of interfaces in this configuration.
|
---|
124 | uint8_t bConfigurationValue; // Value of this configuration (1 based).
|
---|
125 | uint8_t iConfiguration; // Index of String Descriptor describing the configuration.
|
---|
126 | uint8_t bmAttributes; // Configuration characteristics.
|
---|
127 | uint8_t bMaxPower; // Maximum power consumed by this configuration.
|
---|
128 | } USB_CONFIGURATION_DESCRIPTOR;
|
---|
129 |
|
---|
130 | /* Interface descriptor structure */
|
---|
131 | typedef struct
|
---|
132 | {
|
---|
133 | uint8_t bLength; // Length of this descriptor.
|
---|
134 | uint8_t bDescriptorType; // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE).
|
---|
135 | uint8_t bInterfaceNumber; // Number of this interface (0 based).
|
---|
136 | uint8_t bAlternateSetting; // Value of this alternate interface setting.
|
---|
137 | uint8_t bNumEndpoints; // Number of endpoints in this interface.
|
---|
138 | uint8_t bInterfaceClass; // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
|
---|
139 | uint8_t bInterfaceSubClass; // Subclass code (assigned by the USB-IF).
|
---|
140 | uint8_t bInterfaceProtocol; // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
|
---|
141 | uint8_t iInterface; // Index of String Descriptor describing the interface.
|
---|
142 | } USB_INTERFACE_DESCRIPTOR;
|
---|
143 |
|
---|
144 | /* Endpoint descriptor structure */
|
---|
145 | typedef struct
|
---|
146 | {
|
---|
147 | uint8_t bLength; // Length of this descriptor.
|
---|
148 | uint8_t bDescriptorType; // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT).
|
---|
149 | uint8_t bEndpointAddress; // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN).
|
---|
150 | uint8_t bmAttributes; // Endpoint transfer type.
|
---|
151 | uint16_t wMaxPacketSize; // Maximum packet size.
|
---|
152 | uint8_t bInterval; // Polling interval in frames.
|
---|
153 | } USB_ENDPOINT_DESCRIPTOR;
|
---|
154 |
|
---|
155 |
|
---|
156 | /* HID descriptor */
|
---|
157 | typedef struct
|
---|
158 | {
|
---|
159 | uint8_t bLength;
|
---|
160 | uint8_t bDescriptorType;
|
---|
161 | uint16_t bcdHID; // HID class specification release
|
---|
162 | uint8_t bCountryCode;
|
---|
163 | uint8_t bNumDescriptors; // Number of additional class specific descriptors
|
---|
164 | uint8_t bDescrType; // Type of class descriptor
|
---|
165 | uint16_t wDescriptorLength; // Total size of the Report descriptor
|
---|
166 | } USB_HID_DESCRIPTOR;
|
---|
167 |
|
---|
168 | typedef struct
|
---|
169 | {
|
---|
170 | uint8_t bDescrType; // Type of class descriptor
|
---|
171 | uint16_t wDescriptorLength; // Total size of the Report descriptor
|
---|
172 | } HID_CLASS_DESCRIPTOR_LEN_AND_TYPE;
|
---|
173 |
|
---|
174 | _Pragma("pack()")
|
---|
175 |
|
---|
176 | #endif /* USB_CH9_H_INCLUDED */
|
---|