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