ARMEBS4  revision-26.06.2015
usbh_def.h
1 #include "heivs/config.h"
2 #if (USE_STM32_USB_HOST_MODE || USE_STM32_USB_USE_DEVICE_MODE || USE_STM32_USB_OTG_MODE)
3 /**
4  ******************************************************************************
5  * @file usbh_def.h
6  * @author MCD Application Team
7  * @version V2.1.0
8  * @date 19-March-2012
9  * @brief Definitions used in the USB host library
10  ******************************************************************************
11  * @attention
12  *
13  * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
14  *
15  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
16  * You may not use this file except in compliance with the License.
17  * You may obtain a copy of the License at:
18  *
19  * http://www.st.com/software_license_agreement_liberty_v2
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  *
27  ******************************************************************************
28  */
29 
30 /** @addtogroup USBH_LIB
31  * @{
32  */
33 
34 /** @addtogroup USBH_LIB_CORE
35 * @{
36 */
37 
38 /** @defgroup USBH_DEF
39  * @brief This file is includes USB descriptors
40  * @{
41  */
42 
43 #ifndef USBH_DEF_H
44 #define USBH_DEF_H
45 
46 #ifndef USBH_NULL
47 #define USBH_NULL ((void *)0)
48 #endif
49 
50 #ifndef FALSE
51 #define FALSE 0
52 #endif
53 
54 #ifndef TRUE
55 #define TRUE 1
56 #endif
57 
58 
59 #define ValBit(VAR,POS) (VAR & (1 << POS))
60 #define SetBit(VAR,POS) (VAR |= (1 << POS))
61 #define ClrBit(VAR,POS) (VAR &= ((1 << POS)^255))
62 
63 #define LE16(addr) (((u16)(*((u8 *)(addr))))\
64  + (((u16)(*(((u8 *)(addr)) + 1))) << 8))
65 
66 #define USB_LEN_DESC_HDR 0x02
67 #define USB_LEN_DEV_DESC 0x12
68 #define USB_LEN_CFG_DESC 0x09
69 #define USB_LEN_IF_DESC 0x09
70 #define USB_LEN_EP_DESC 0x07
71 #define USB_LEN_OTG_DESC 0x03
72 #define USB_LEN_SETUP_PKT 0x08
73 
74 /* bmRequestType :D7 Data Phase Transfer Direction */
75 #define USB_REQ_DIR_MASK 0x80
76 #define USB_H2D 0x00
77 #define USB_D2H 0x80
78 
79 /* bmRequestType D6..5 Type */
80 #define USB_REQ_TYPE_STANDARD 0x00
81 #define USB_REQ_TYPE_CLASS 0x20
82 #define USB_REQ_TYPE_VENDOR 0x40
83 #define USB_REQ_TYPE_RESERVED 0x60
84 
85 /* bmRequestType D4..0 Recipient */
86 #define USB_REQ_RECIPIENT_DEVICE 0x00
87 #define USB_REQ_RECIPIENT_INTERFACE 0x01
88 #define USB_REQ_RECIPIENT_ENDPOINT 0x02
89 #define USB_REQ_RECIPIENT_OTHER 0x03
90 
91 /* Table 9-4. Standard Request Codes */
92 /* bRequest , Value */
93 #define USB_REQ_GET_STATUS 0x00
94 #define USB_REQ_CLEAR_FEATURE 0x01
95 #define USB_REQ_SET_FEATURE 0x03
96 #define USB_REQ_SET_ADDRESS 0x05
97 #define USB_REQ_GET_DESCRIPTOR 0x06
98 #define USB_REQ_SET_DESCRIPTOR 0x07
99 #define USB_REQ_GET_CONFIGURATION 0x08
100 #define USB_REQ_SET_CONFIGURATION 0x09
101 #define USB_REQ_GET_INTERFACE 0x0A
102 #define USB_REQ_SET_INTERFACE 0x0B
103 #define USB_REQ_SYNCH_FRAME 0x0C
104 
105 /* Table 9-5. Descriptor Types of USB Specifications */
106 #define USB_DESC_TYPE_DEVICE 1
107 #define USB_DESC_TYPE_CONFIGURATION 2
108 #define USB_DESC_TYPE_STRING 3
109 #define USB_DESC_TYPE_INTERFACE 4
110 #define USB_DESC_TYPE_ENDPOINT 5
111 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6
112 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
113 #define USB_DESC_TYPE_INTERFACE_POWER 8
114 #define USB_DESC_TYPE_HID 0x21
115 #define USB_DESC_TYPE_HID_REPORT 0x22
116 
117 
118 #define USB_DEVICE_DESC_SIZE 18
119 #define USB_CONFIGURATION_DESC_SIZE 9
120 #define USB_HID_DESC_SIZE 9
121 #define USB_INTERFACE_DESC_SIZE 9
122 #define USB_ENDPOINT_DESC_SIZE 7
123 
124 /* Descriptor Type and Descriptor Index */
125 /* Use the following values when calling the function USBH_GetDescriptor */
126 #define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00)
127 #define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00)
128 #define USB_DESC_STRING ((USB_DESC_TYPE_STRING << 8) & 0xFF00)
129 #define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
130 #define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00)
131 #define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00)
132 #define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00)
133 #define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00)
134 #define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00)
135 #define USB_DESC_HID ((USB_DESC_TYPE_HID << 8) & 0xFF00)
136 
137 
138 #define USB_EP_TYPE_CTRL 0x00
139 #define USB_EP_TYPE_ISOC 0x01
140 #define USB_EP_TYPE_BULK 0x02
141 #define USB_EP_TYPE_INTR 0x03
142 
143 #define USB_EP_DIR_OUT 0x00
144 #define USB_EP_DIR_IN 0x80
145 #define USB_EP_DIR_MSK 0x80
146 
147 /* supported classes */
148 #define USB_MSC_CLASS 0x08
149 #define USB_HID_CLASS 0x03
150 
151 /* Interface Descriptor field values for HID Boot Protocol */
152 #define HID_BOOT_CODE 0x01
153 #define HID_KEYBRD_BOOT_CODE 0x01
154 #define HID_MOUSE_BOOT_CODE 0x02
155 
156 /* As per USB specs 9.2.6.4 :Standard request with data request timeout: 5sec
157  Standard request with no data stage timeout : 50ms */
158 #define DATA_STAGE_TIMEOUT 5000
159 #define NODATA_STAGE_TIMEOUT 50
160 
161 /**
162  * @}
163  */
164 
165 
166 #define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
167  + USB_INTERFACE_DESC_SIZE\
168  + (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))
169 
170 
171 #define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
172  ConfigurationDescriptor.wTotalLength)
173 
174 
175 /* This Union is copied from usb_core.h */
176 typedef union
177 {
178  uint16_t w;
179  struct BW
180  {
181  uint8_t msb;
182  uint8_t lsb;
183  }
184  bw;
185 }
186 uint16_t_uint8_t;
187 
188 
189 typedef union _USB_Setup
190 {
191  uint8_t d8[8];
192 
193  struct _SetupPkt_Struc
194  {
195  uint8_t bmRequestType;
196  uint8_t bRequest;
197  uint16_t_uint8_t wValue;
198  uint16_t_uint8_t wIndex;
199  uint16_t_uint8_t wLength;
200  } b;
201 }
202 USB_Setup_TypeDef;
203 
204 typedef struct _DescHeader
205 {
206  uint8_t bLength;
207  uint8_t bDescriptorType;
208 }
209 USBH_DescHeader_t;
210 
211 typedef struct _DeviceDescriptor
212 {
213  uint8_t bLength;
214  uint8_t bDescriptorType;
215  uint16_t bcdUSB; /* USB Specification Number which device complies too */
216  uint8_t bDeviceClass;
217  uint8_t bDeviceSubClass;
218  uint8_t bDeviceProtocol;
219  /* If equal to Zero, each interface specifies its own class
220  code if equal to 0xFF, the class code is vendor specified.
221  Otherwise field is valid Class Code.*/
222  uint8_t bMaxPacketSize;
223  uint16_t idVendor; /* Vendor ID (Assigned by USB Org) */
224  uint16_t idProduct; /* Product ID (Assigned by Manufacturer) */
225  uint16_t bcdDevice; /* Device Release Number */
226  uint8_t iManufacturer; /* Index of Manufacturer String Descriptor */
227  uint8_t iProduct; /* Index of Product String Descriptor */
228  uint8_t iSerialNumber; /* Index of Serial Number String Descriptor */
229  uint8_t bNumConfigurations; /* Number of Possible Configurations */
230 }
231 USBH_DevDesc_TypeDef;
232 
233 
234 typedef struct _ConfigurationDescriptor
235 {
236  uint8_t bLength;
237  uint8_t bDescriptorType;
238  uint16_t wTotalLength; /* Total Length of Data Returned */
239  uint8_t bNumInterfaces; /* Number of Interfaces */
240  uint8_t bConfigurationValue; /* Value to use as an argument to select this configuration*/
241  uint8_t iConfiguration; /*Index of String Descriptor Describing this configuration */
242  uint8_t bmAttributes; /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/
243  uint8_t bMaxPower; /*Maximum Power Consumption */
244 }
245 USBH_CfgDesc_TypeDef;
246 
247 
248 typedef struct _HIDDescriptor
249 {
250  uint8_t bLength;
251  uint8_t bDescriptorType;
252  uint16_t bcdHID; /* indicates what endpoint this descriptor is describing */
253  uint8_t bCountryCode; /* specifies the transfer type. */
254  uint8_t bNumDescriptors; /* specifies the transfer type. */
255  uint8_t bReportDescriptorType; /* Maximum Packet Size this endpoint is capable of sending or receiving */
256  uint16_t wItemLength; /* is used to specify the polling interval of certain transfers. */
257 }
258 USBH_HIDDesc_TypeDef;
259 
260 
261 typedef struct _InterfaceDescriptor
262 {
263  uint8_t bLength;
264  uint8_t bDescriptorType;
265  uint8_t bInterfaceNumber;
266  uint8_t bAlternateSetting; /* Value used to select alternative setting */
267  uint8_t bNumEndpoints; /* Number of Endpoints used for this interface */
268  uint8_t bInterfaceClass; /* Class Code (Assigned by USB Org) */
269  uint8_t bInterfaceSubClass; /* Subclass Code (Assigned by USB Org) */
270  uint8_t bInterfaceProtocol; /* Protocol Code */
271  uint8_t iInterface; /* Index of String Descriptor Describing this interface */
272 
273 }
274 USBH_InterfaceDesc_TypeDef;
275 
276 
277 typedef struct _EndpointDescriptor
278 {
279  uint8_t bLength;
280  uint8_t bDescriptorType;
281  uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */
282  uint8_t bmAttributes; /* specifies the transfer type. */
283  uint16_t wMaxPacketSize; /* Maximum Packet Size this endpoint is capable of sending or receiving */
284  uint8_t bInterval; /* is used to specify the polling interval of certain transfers. */
285 }
286 USBH_EpDesc_TypeDef;
287 #endif
288 
289 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
290 #endif /* (USE_STM32_USB_HOST_MODE || USE_STM32_USB_USE_DEVICE_MODE || USE_STM32_USB_OTG_MODE) */
libheivs configuration file