STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
usbh_hid.h
Go to the documentation of this file.
1 
28 /* Define to prevent recursive ----------------------------------------------*/
29 #ifndef __USBH_HID_H
30 #define __USBH_HID_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------*/
37 #include "usbh_core.h"
38 #include "usbh_hid_mouse.h"
39 #include "usbh_hid_keybd.h"
40 
63 #define HID_MIN_POLL 10
64 #define HID_REPORT_SIZE 16
65 #define HID_MAX_USAGE 10
66 #define HID_MAX_NBR_REPORT_FMT 10
67 #define HID_QUEUE_SIZE 10
68 
69 #define HID_ITEM_LONG 0xFE
70 
71 #define HID_ITEM_TYPE_MAIN 0x00
72 #define HID_ITEM_TYPE_GLOBAL 0x01
73 #define HID_ITEM_TYPE_LOCAL 0x02
74 #define HID_ITEM_TYPE_RESERVED 0x03
75 
76 
77 #define HID_MAIN_ITEM_TAG_INPUT 0x08
78 #define HID_MAIN_ITEM_TAG_OUTPUT 0x09
79 #define HID_MAIN_ITEM_TAG_COLLECTION 0x0A
80 #define HID_MAIN_ITEM_TAG_FEATURE 0x0B
81 #define HID_MAIN_ITEM_TAG_ENDCOLLECTION 0x0C
82 
83 
84 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0x00
85 #define HID_GLOBAL_ITEM_TAG_LOG_MIN 0x01
86 #define HID_GLOBAL_ITEM_TAG_LOG_MAX 0x02
87 #define HID_GLOBAL_ITEM_TAG_PHY_MIN 0x03
88 #define HID_GLOBAL_ITEM_TAG_PHY_MAX 0x04
89 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 0x05
90 #define HID_GLOBAL_ITEM_TAG_UNIT 0x06
91 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 0x07
92 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 0x08
93 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 0x09
94 #define HID_GLOBAL_ITEM_TAG_PUSH 0x0A
95 #define HID_GLOBAL_ITEM_TAG_POP 0x0B
96 
97 
98 #define HID_LOCAL_ITEM_TAG_USAGE 0x00
99 #define HID_LOCAL_ITEM_TAG_USAGE_MIN 0x01
100 #define HID_LOCAL_ITEM_TAG_USAGE_MAX 0x02
101 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 0x03
102 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MIN 0x04
103 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAX 0x05
104 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 0x07
105 #define HID_LOCAL_ITEM_TAG_STRING_MIN 0x08
106 #define HID_LOCAL_ITEM_TAG_STRING_MAX 0x09
107 #define HID_LOCAL_ITEM_TAG_DELIMITER 0x0A
108 
109 
110 /* States for HID State Machine */
111 typedef enum
112 {
113  HID_INIT= 0,
121 }
123 
124 typedef enum
125 {
133 
134 }
136 
137 typedef enum
138 {
139  HID_MOUSE = 0x01,
140  HID_KEYBOARD = 0x02,
141  HID_UNKNOWN = 0xFF,
142 }
144 
145 
146 typedef struct _HID_ReportData
147 {
148  uint8_t ReportID;
149  uint8_t ReportType;
150  uint16_t UsagePage;
151  uint32_t Usage[HID_MAX_USAGE];
152  uint32_t NbrUsage;
153  uint32_t UsageMin;
154  uint32_t UsageMax;
155  int32_t LogMin;
156  int32_t LogMax;
157  int32_t PhyMin;
158  int32_t PhyMax;
159  int32_t UnitExp;
160  uint32_t Unit;
161  uint32_t ReportSize;
162  uint32_t ReportCnt;
163  uint32_t Flag;
164  uint32_t PhyUsage;
165  uint32_t AppUsage;
166  uint32_t LogUsage;
167 }
169 
170 typedef struct _HID_ReportIDTypeDef {
171  uint8_t Size; /* Report size return by the device id */
172  uint8_t ReportID; /* Report Id */
173  uint8_t Type; /* Report Type (INPUT/OUTPUT/FEATURE) */
175 
176 typedef struct _HID_CollectionTypeDef
177 {
178  uint32_t Usage;
179  uint8_t Type;
182 
183 
185  uint32_t Usage;
186  uint8_t Type;
187  uint8_t NbrReportFmt;
190 
191 
192 typedef struct _HIDDescriptor
193 {
194  uint8_t bLength;
196  uint16_t bcdHID; /* indicates what endpoint this descriptor is describing */
197  uint8_t bCountryCode; /* specifies the transfer type. */
198  uint8_t bNumDescriptors; /* specifies the transfer type. */
199  uint8_t bReportDescriptorType; /* Maximum Packet Size this endpoint is capable of sending or receiving */
200  uint16_t wItemLength; /* is used to specify the polling interval of certain transfers. */
201 }
203 
204 
205 typedef struct
206 {
207  uint8_t *buf;
208  uint16_t head;
209  uint16_t tail;
210  uint16_t size;
211  uint8_t lock;
212 } FIFO_TypeDef;
213 
214 
215 /* Structure for HID process */
216 typedef struct _HID_Process
217 {
218  uint8_t OutPipe;
219  uint8_t InPipe;
220  HID_StateTypeDef state;
221  uint8_t OutEp;
222  uint8_t InEp;
223  HID_CtlStateTypeDef ctl_state;
225  uint8_t *pData;
226  uint16_t length;
227  uint8_t ep_addr;
228  uint16_t poll;
229  uint32_t timer;
230  uint8_t DataReady;
233 }
235 
244 #define USB_HID_GET_REPORT 0x01
245 #define USB_HID_GET_IDLE 0x02
246 #define USB_HID_GET_PROTOCOL 0x03
247 #define USB_HID_SET_REPORT 0x09
248 #define USB_HID_SET_IDLE 0x0A
249 #define USB_HID_SET_PROTOCOL 0x0B
250 
251 
252 
253 
254 /* HID Class Codes */
255 #define USB_HID_CLASS 0x03
256 
257 /* Interface Descriptor field values for HID Boot Protocol */
258 #define HID_BOOT_CODE 0x01
259 #define HID_KEYBRD_BOOT_CODE 0x01
260 #define HID_MOUSE_BOOT_CODE 0x02
261 
262 
278 #define USBH_HID_CLASS &HID_Class
279 
288  uint8_t reportType,
289  uint8_t reportId,
290  uint8_t* reportBuff,
291  uint8_t reportLen);
292 
294  uint8_t reportType,
295  uint8_t reportId,
296  uint8_t* reportBuff,
297  uint8_t reportLen);
298 
300  uint16_t length);
301 
303  uint16_t length);
304 
306  uint8_t duration,
307  uint8_t reportId);
308 
310  uint8_t protocol);
311 
313 
315 
317 
318 void fifo_init(FIFO_TypeDef * f, uint8_t * buf, uint16_t size);
319 
320 uint16_t fifo_read(FIFO_TypeDef * f, void * buf, uint16_t nbytes);
321 
322 uint16_t fifo_write(FIFO_TypeDef * f, const void * buf, uint16_t nbytes);
323 
328 #ifdef __cplusplus
329 }
330 #endif
331 
332 #endif /* __USBH_HID_H */
333 
349 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
350 
struct _HID_CollectionTypeDef * NextPtr
Definition: usbh_hid.h:180
uint8_t bNumDescriptors
Definition: usbh_hid.h:198
USBH_ClassTypeDef HID_Class
Definition: usbh_hid.c:111
Header file for usbh_core.c.
uint32_t NbrUsage
Definition: usbh_hid.h:152
uint32_t Flag
Definition: usbh_hid.h:163
uint16_t head
Definition: usbh_hid.h:208
HID_TypeTypeDef
Definition: usbh_hid.h:137
HID_StateTypeDef
Definition: usbh_hid.h:111
uint16_t length
Definition: usbh_hid.h:226
USBH_StatusTypeDef USBH_HID_SetIdle(USBH_HandleTypeDef *phost, uint8_t duration, uint8_t reportId)
USBH_Set_Idle Set Idle State.
Definition: usbh_hid.c:523
This file contains all the prototypes for the usbh_hid_keybd.c.
#define HID_MAX_USAGE
Definition: usbh_hid.h:65
uint32_t timer
Definition: usbh_hid.h:229
uint8_t USBH_HID_GetPollInterval(USBH_HandleTypeDef *phost)
USBH_HID_GetPollInterval Return HID device poll time.
Definition: usbh_hid.c:681
uint8_t DataReady
Definition: usbh_hid.h:230
USBH_StatusTypeDef USBH_HID_GetReport(USBH_HandleTypeDef *phost, uint8_t reportType, uint8_t reportId, uint8_t *reportBuff, uint8_t reportLen)
USBH_HID_GetReport retreive Set Report.
Definition: usbh_hid.c:583
uint8_t ReportType
Definition: usbh_hid.h:149
int32_t UnitExp
Definition: usbh_hid.h:159
FIFO_TypeDef fifo
Definition: usbh_hid.h:224
uint16_t wItemLength
Definition: usbh_hid.h:200
struct _HID_ReportData HID_ReportDataTypeDef
USBH_StatusTypeDef USBH_HID_GetHIDDescriptor(USBH_HandleTypeDef *phost, uint16_t length)
USBH_Get_HID_Descriptor Issue HID Descriptor command to the device. Once the response received...
Definition: usbh_hid.c:500
uint16_t poll
Definition: usbh_hid.h:228
int32_t PhyMin
Definition: usbh_hid.h:157
void USBH_HID_EventCallback(USBH_HandleTypeDef *phost)
The function is a callback about HID Data events.
Definition: usbh_hid.c:798
uint8_t * buf
Definition: usbh_hid.h:207
uint16_t tail
Definition: usbh_hid.h:209
uint32_t PhyUsage
Definition: usbh_hid.h:164
int32_t PhyMax
Definition: usbh_hid.h:158
struct _HIDDescriptor HID_DescTypeDef
int32_t LogMax
Definition: usbh_hid.h:156
struct _HID_CollectionTypeDef HID_CollectionTypeDef
uint8_t * pData
Definition: usbh_hid.h:225
struct _HID_AppCollectionTypeDef HID_AppCollectionTypeDef
HID_DescTypeDef HID_Desc
Definition: usbh_hid.h:231
uint8_t bDescriptorType
Definition: usbh_hid.h:195
This file contains all the prototypes for the usbh_hid_mouse.c.
struct _HID_Process HID_HandleTypeDef
uint32_t ReportSize
Definition: usbh_hid.h:161
uint16_t UsagePage
Definition: usbh_hid.h:150
uint16_t size
Definition: usbh_hid.h:210
HID_StateTypeDef state
Definition: usbh_hid.h:220
uint32_t Unit
Definition: usbh_hid.h:160
USBH_StatusTypeDef USBH_HID_SetReport(USBH_HandleTypeDef *phost, uint8_t reportType, uint8_t reportId, uint8_t *reportBuff, uint8_t reportLen)
USBH_HID_Set_Report Issues Set Report.
Definition: usbh_hid.c:552
uint8_t ReportID
Definition: usbh_hid.h:148
uint32_t AppUsage
Definition: usbh_hid.h:165
uint16_t fifo_write(FIFO_TypeDef *f, const void *buf, uint16_t nbytes)
fifo_write Read from FIFO.
Definition: usbh_hid.c:761
uint8_t lock
Definition: usbh_hid.h:211
#define HID_MAX_NBR_REPORT_FMT
Definition: usbh_hid.h:66
uint8_t bReportDescriptorType
Definition: usbh_hid.h:199
uint8_t ep_addr
Definition: usbh_hid.h:227
uint8_t InPipe
Definition: usbh_hid.h:219
USBH_StatusTypeDef USBH_HID_SetProtocol(USBH_HandleTypeDef *phost, uint8_t protocol)
USBH_Set_Protocol Set protocol State.
Definition: usbh_hid.c:610
uint32_t UsageMax
Definition: usbh_hid.h:154
struct _HID_ReportIDTypeDef HID_ReportIDTypeDef
USBH_StatusTypeDef
Definition: usbh_def.h:302
uint16_t fifo_read(FIFO_TypeDef *f, void *buf, uint16_t nbytes)
fifo_read Read from FIFO.
Definition: usbh_hid.c:723
uint8_t OutEp
Definition: usbh_hid.h:221
uint32_t UsageMin
Definition: usbh_hid.h:153
uint8_t bCountryCode
Definition: usbh_hid.h:197
uint8_t OutPipe
Definition: usbh_hid.h:218
int32_t LogMin
Definition: usbh_hid.h:155
uint8_t bLength
Definition: usbh_hid.h:194
HID_TypeTypeDef USBH_HID_GetDeviceType(USBH_HandleTypeDef *phost)
USBH_HID_GetDeviceType Return Device function.
Definition: usbh_hid.c:653
HID_CtlStateTypeDef ctl_state
Definition: usbh_hid.h:223
void fifo_init(FIFO_TypeDef *f, uint8_t *buf, uint16_t size)
fifo_init Initialize FIFO.
Definition: usbh_hid.c:706
uint32_t Usage[HID_MAX_USAGE]
Definition: usbh_hid.h:151
USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor(USBH_HandleTypeDef *phost, uint16_t length)
USBH_Get_HID_ReportDescriptor Issue report Descriptor command to the device. Once the response receiv...
Definition: usbh_hid.c:470
uint32_t LogUsage
Definition: usbh_hid.h:166
HID_CtlStateTypeDef
Definition: usbh_hid.h:124
uint32_t ReportCnt
Definition: usbh_hid.h:162
uint16_t bcdHID
Definition: usbh_hid.h:196
uint8_t InEp
Definition: usbh_hid.h:222