Debian Codegraph @

ports/stm32/usbhost/Class/HID/Inc/usbh_hid.h

raw
1 /**
2 ******************************************************************************
3 * @file usbh_hid.h
4 * @author MCD Application Team
5 * @version V3.0.0
6 * @date 18-February-2014
7 * @brief This file contains all the prototypes for the usbh_hid.c
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
12 *
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
16 *
17 * http://www.st.com/software_license_agreement_liberty_v2
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 ******************************************************************************
26 */
27
28 /* Define to prevent recursive ----------------------------------------------*/
29 #ifndef __USBH_HID_H
30 #define __USBH_HID_H
31
32 /* Includes ------------------------------------------------------------------*/
33 #include "usbh_core.h"
34 #include "usbh_hid_mouse.h"
35 #include "usbh_hid_keybd.h"
36
37 /** @addtogroup USBH_LIB
38 * @{
39 */
40
41 /** @addtogroup USBH_CLASS
42 * @{
43 */
44
45 /** @addtogroup USBH_HID_CLASS
46 * @{
47 */
48
49 /** @defgroup USBH_HID_CORE
50 * @brief This file is the Header file for USBH_HID_CORE.c
51 * @{
52 */
53
54
55 /** @defgroup USBH_HID_CORE_Exported_Types
56 * @{
57 */
58
59 #define HID_MIN_POLL 10
60 #define HID_REPORT_SIZE 16
61 #define HID_MAX_USAGE 10
62 #define HID_MAX_NBR_REPORT_FMT 10
63 #define HID_QUEUE_SIZE 10
64
65 #define HID_ITEM_LONG 0xFE
66
67 #define HID_ITEM_TYPE_MAIN 0x00
68 #define HID_ITEM_TYPE_GLOBAL 0x01
69 #define HID_ITEM_TYPE_LOCAL 0x02
70 #define HID_ITEM_TYPE_RESERVED 0x03
71
72
73 #define HID_MAIN_ITEM_TAG_INPUT 0x08
74 #define HID_MAIN_ITEM_TAG_OUTPUT 0x09
75 #define HID_MAIN_ITEM_TAG_COLLECTION 0x0A
76 #define HID_MAIN_ITEM_TAG_FEATURE 0x0B
77 #define HID_MAIN_ITEM_TAG_ENDCOLLECTION 0x0C
78
79
80 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0x00
81 #define HID_GLOBAL_ITEM_TAG_LOG_MIN 0x01
82 #define HID_GLOBAL_ITEM_TAG_LOG_MAX 0x02
83 #define HID_GLOBAL_ITEM_TAG_PHY_MIN 0x03
84 #define HID_GLOBAL_ITEM_TAG_PHY_MAX 0x04
85 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 0x05
86 #define HID_GLOBAL_ITEM_TAG_UNIT 0x06
87 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 0x07
88 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 0x08
89 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 0x09
90 #define HID_GLOBAL_ITEM_TAG_PUSH 0x0A
91 #define HID_GLOBAL_ITEM_TAG_POP 0x0B
92
93
94 #define HID_LOCAL_ITEM_TAG_USAGE 0x00
95 #define HID_LOCAL_ITEM_TAG_USAGE_MIN 0x01
96 #define HID_LOCAL_ITEM_TAG_USAGE_MAX 0x02
97 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 0x03
98 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MIN 0x04
99 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAX 0x05
100 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 0x07
101 #define HID_LOCAL_ITEM_TAG_STRING_MIN 0x08
102 #define HID_LOCAL_ITEM_TAG_STRING_MAX 0x09
103 #define HID_LOCAL_ITEM_TAG_DELIMITER 0x0A
104
105
106 /* States for HID State Machine */
107 typedef enum
108 {
109 HID_INIT= 0,
110 HID_IDLE,
111 HID_SEND_DATA,
112 HID_BUSY,
113 HID_GET_DATA,
114 HID_SYNC,
115 HID_POLL,
116 HID_ERROR,
117 }
118 HID_StateTypeDef;
119
120 typedef enum
121 {
122 HID_REQ_INIT = 0,
123 HID_REQ_IDLE,
124 HID_REQ_GET_REPORT_DESC,
125 HID_REQ_GET_HID_DESC,
126 HID_REQ_SET_IDLE,
127 HID_REQ_SET_PROTOCOL,
128 HID_REQ_SET_REPORT,
129
130 }
131 HID_CtlStateTypeDef;
132
133 typedef enum
134 {
135 HID_MOUSE = 0x01,
136 HID_KEYBOARD = 0x02,
137 HID_UNKNOWN = 0xFF,
138 }
139 HID_TypeTypeDef;
140
141
142 typedef struct _HID_ReportData
143 {
144 uint8_t ReportID;
145 uint8_t ReportType;
146 uint16_t UsagePage;
147 uint32_t Usage[HID_MAX_USAGE];
148 uint32_t NbrUsage;
149 uint32_t UsageMin;
150 uint32_t UsageMax;
151 int32_t LogMin;
152 int32_t LogMax;
153 int32_t PhyMin;
154 int32_t PhyMax;
155 int32_t UnitExp;
156 uint32_t Unit;
157 uint32_t ReportSize;
158 uint32_t ReportCnt;
159 uint32_t Flag;
160 uint32_t PhyUsage;
161 uint32_t AppUsage;
162 uint32_t LogUsage;
163 }
164 HID_ReportDataTypeDef;
165
166 typedef struct _HID_ReportIDTypeDef {
167 uint8_t Size; /* Report size return by the device id */
168 uint8_t ReportID; /* Report Id */
169 uint8_t Type; /* Report Type (INPUT/OUTPUT/FEATURE) */
170 } HID_ReportIDTypeDef;
171
172 typedef struct _HID_CollectionTypeDef
173 {
174 uint32_t Usage;
175 uint8_t Type;
176 struct _HID_CollectionTypeDef *NextPtr;
177 } HID_CollectionTypeDef;
178
179
180 typedef struct _HID_AppCollectionTypeDef {
181 uint32_t Usage;
182 uint8_t Type;
183 uint8_t NbrReportFmt;
184 HID_ReportDataTypeDef ReportData[HID_MAX_NBR_REPORT_FMT];
185 } HID_AppCollectionTypeDef;
186
187
188 typedef struct _HIDDescriptor
189 {
190 uint8_t bLength;
191 uint8_t bDescriptorType;
192 uint16_t bcdHID; /* indicates what endpoint this descriptor is describing */
193 uint8_t bCountryCode; /* specifies the transfer type. */
194 uint8_t bNumDescriptors; /* specifies the transfer type. */
195 uint8_t bReportDescriptorType; /* Maximum Packet Size this endpoint is capable of sending or receiving */
196 uint16_t wItemLength; /* is used to specify the polling interval of certain transfers. */
197 }
198 HID_DescTypeDef;
199
200
201 typedef struct
202 {
203 uint8_t *buf;
204 uint16_t head;
205 uint16_t tail;
206 uint16_t size;
207 uint8_t lock;
208 } FIFO_TypeDef;
209
210
211 /* Structure for HID process */
212 typedef struct _HID_Process
213 {
214 uint8_t OutPipe;
215 uint8_t InPipe;
216 HID_StateTypeDef state;
217 uint8_t OutEp;
218 uint8_t InEp;
219 HID_CtlStateTypeDef ctl_state;
220 FIFO_TypeDef fifo;
221 uint8_t *pData;
222 uint16_t length;
223 uint8_t ep_addr;
224 uint16_t poll;
225 uint16_t timer;
226 uint8_t DataReady;
227 HID_DescTypeDef HID_Desc;
228 USBH_StatusTypeDef ( * Init)(USBH_HandleTypeDef *phost);
229 }
230 HID_HandleTypeDef;
231
232 /**
233 * @}
234 */
235
236 /** @defgroup USBH_HID_CORE_Exported_Defines
237 * @{
238 */
239
240 #define USB_HID_GET_REPORT 0x01
241 #define USB_HID_GET_IDLE 0x02
242 #define USB_HID_GET_PROTOCOL 0x03
243 #define USB_HID_SET_REPORT 0x09
244 #define USB_HID_SET_IDLE 0x0A
245 #define USB_HID_SET_PROTOCOL 0x0B
246
247
248
249
250 /* HID Class Codes */
251 #define USB_HID_CLASS 0x03
252
253 /* Interface Descriptor field values for HID Boot Protocol */
254 #define HID_BOOT_CODE 0x01
255 #define HID_KEYBRD_BOOT_CODE 0x01
256 #define HID_MOUSE_BOOT_CODE 0x02
257
258
259 /**
260 * @}
261 */
262
263 /** @defgroup USBH_HID_CORE_Exported_Macros
264 * @{
265 */
266 /**
267 * @}
268 */
269
270 /** @defgroup USBH_HID_CORE_Exported_Variables
271 * @{
272 */
273 extern USBH_ClassTypeDef HID_Class;
274 #define USBH_HID_CLASS &HID_Class
275 /**
276 * @}
277 */
278
279 /** @defgroup USBH_HID_CORE_Exported_FunctionsPrototype
280 * @{
281 */
282
283 USBH_StatusTypeDef USBH_HID_SetReport (USBH_HandleTypeDef *phost,
284 uint8_t reportType,
285 uint8_t reportId,
286 uint8_t* reportBuff,
287 uint8_t reportLen);
288
289 USBH_StatusTypeDef USBH_HID_GetReport (USBH_HandleTypeDef *phost,
290 uint8_t reportType,
291 uint8_t reportId,
292 uint8_t* reportBuff,
293 uint8_t reportLen);
294
295 USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost,
296 uint16_t length);
297
298 USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost,
299 uint16_t length);
300
301 USBH_StatusTypeDef USBH_HID_SetIdle (USBH_HandleTypeDef *phost,
302 uint8_t duration,
303 uint8_t reportId);
304
305 USBH_StatusTypeDef USBH_HID_SetProtocol (USBH_HandleTypeDef *phost,
306 uint8_t protocol);
307
308 void USBH_HID_EventCallback(USBH_HandleTypeDef *phost);
309
310 HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost);
311
312 void fifo_init(FIFO_TypeDef * f, uint8_t * buf, uint16_t size);
313
314 uint16_t fifo_read(FIFO_TypeDef * f, void * buf, uint16_t nbytes);
315
316 uint16_t fifo_write(FIFO_TypeDef * f, const void * buf, uint16_t nbytes);
317
318 /**
319 * @}
320 */
321
322
323 #endif /* __USBH_HID_H */
324
325 /**
326 * @}
327 */
328
329 /**
330 * @}
331 */
332
333 /**
334 * @}
335 */
336
337 /**
338 * @}
339 */
340 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
341