Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "usbh_hid_keybd.h"
#include "usbh_hid_parser.h"
#define QWERTY_KEYBOARD
#define KBD_LEFT_CTRL
#define KBD_LEFT_SHIFT
#define KBD_LEFT_ALT
#define KBD_LEFT_GUI
#define KBD_RIGHT_CTRL
#define KBD_RIGHT_SHIFT
#define KBD_RIGHT_ALT
#define KBD_RIGHT_GUI
#define KBR_MAX_NBR_PRESSED
keybd_info
keybd_rx_report_buf
keybd_report_data
imp_0_lctrl
imp_0_lshift
imp_0_lalt
imp_0_lgui
imp_0_rctrl
imp_0_rshift
imp_0_ralt
imp_0_rgui
imp_0_key_array
HID_KEYBRD_Key
HID_KEYBRD_ShiftKey
HID_KEYBRD_Codes
USBH_HID_KeybdInit(USBH_HandleTypeDef *)
USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *)
USBH_HID_KeybdDecode(USBH_HandleTypeDef *)
USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *)
Files
loading...
SourceVuSTM32 Libraries and SamplesSTM32_USB_Host_LibraryClass/HID/Src/usbh_hid_keybd.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file usbh_hid_keybd.c * @author MCD Application Team * @brief This file is the application layer for USB Host HID Keyboard handling * QWERTY and AZERTY Keyboard are supported as per the selection in * usbh_hid_keybd.h ****************************************************************************** * @attention * * Copyright (c) 2015 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* BSPDependencies - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - "stm32xxxxx_{eval}{discovery}_io.c" - "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c" - "stm32xxxxx_{eval}{discovery}_sdram.c" EndBSPDependencies *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid_keybd.h" #include "usbh_hid_parser.h" /** @addtogroup USBH_LIB * @{ *//* ... */ /** @addtogroup USBH_CLASS * @{ *//* ... */ /** @addtogroup USBH_HID_CLASS * @{ *//* ... */ /** @defgroup USBH_HID_KEYBD * @brief This file includes HID Layer Handlers for USB Host HID class. * @{ *//* ... */ /** @defgroup USBH_HID_KEYBD_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_HID_KEYBD_Private_Defines * @{ *//* ... */ /** * @} *//* ... */ #ifndef AZERTY_KEYBOARD #define QWERTY_KEYBOARD #endif #define KBD_LEFT_CTRL 0x01 #define KBD_LEFT_SHIFT 0x02 #define KBD_LEFT_ALT 0x04 #define KBD_LEFT_GUI 0x08 #define KBD_RIGHT_CTRL 0x10 #define KBD_RIGHT_SHIFT 0x20 #define KBD_RIGHT_ALT 0x40 #define KBD_RIGHT_GUI 0x80 #define KBR_MAX_NBR_PRESSED 6 9 defines /** @defgroup USBH_HID_KEYBD_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup USBH_HID_KEYBD_Private_FunctionPrototypes * @{ *//* ... */ static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost); /** * @} *//* ... */ /** @defgroup USBH_HID_KEYBD_Private_Variables * @{ *//* ... */ HID_KEYBD_Info_TypeDef keybd_info; uint8_t keybd_rx_report_buf[USBH_HID_KEYBD_REPORT_SIZE]; uint8_t keybd_report_data[USBH_HID_KEYBD_REPORT_SIZE]; static const HID_Report_ItemTypedef imp_0_lctrl = { keybd_report_data, /*data*/ 1, /*size*/ 0, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min vale device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; static const HID_Report_ItemTypedef imp_0_lshift = { keybd_report_data, /*data*/ 1, /*size*/ 1, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min vale device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; static const HID_Report_ItemTypedef imp_0_lalt = { keybd_report_data, /*data*/ 1, /*size*/ 2, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min vale device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; static const HID_Report_ItemTypedef imp_0_lgui = { keybd_report_data, /*data*/ 1, /*size*/ 3, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min vale device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; static const HID_Report_ItemTypedef imp_0_rctrl = { keybd_report_data, /*data*/ 1, /*size*/ 4, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min vale device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; static const HID_Report_ItemTypedef imp_0_rshift = { keybd_report_data, /*data*/ 1, /*size*/ 5, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min vale device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; static const HID_Report_ItemTypedef imp_0_ralt = { keybd_report_data, /*data*/ 1, /*size*/ 6, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min vale device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; static const HID_Report_ItemTypedef imp_0_rgui = { keybd_report_data, /*data*/ 1, /*size*/ 7, /*shift*/ 0, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 1, /*max value read can return*/ 0, /*min vale device can report*/ 1, /*max value device can report*/ 1 /*resolution*/ ...}; static const HID_Report_ItemTypedef imp_0_key_array = { keybd_report_data + 2U, /*data*/ 8, /*size*/ 0, /*shift*/ 6, /*count (only for array items)*/ 0, /*signed?*/ 0, /*min value read can return*/ 101, /*max value read can return*/ 0, /*min vale device can report*/ 101, /*max value device can report*/ 1 /*resolution*/ ...}; #ifdef QWERTY_KEYBOARD static const uint8_t HID_KEYBRD_Key[] = { '\0', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\0', '\r', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\', '\0', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '\0', '\n', '\0', '\0', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '\0', '\0', '\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1', '\0', '/', '8', '5', '2', '0', '*', '9', '6', '3', '.', '-', '+', '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' ...}; static const uint8_t HID_KEYBRD_ShiftKey[] = { '\0', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\0', '\0', '\0', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '|', '\0', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '\0', '\n', '\0', '\0', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' ...}; /* ... */ #else static const uint8_t HID_KEYBRD_Key[] = { '\0', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\0', '\r', '\t', 'a', 'z', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\', '\0', 'q', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', '\0', '\0', '\n', '\0', '\0', 'w', 'x', 'c', 'v', 'b', 'n', ',', ';', ':', '!', '\0', '\0', '\0', '\0', '\0', ' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\r', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '7', '4', '1', '\0', '/', '8', '5', '2', '0', '*', '9', '6', '3', '.', '-', '+', '\0', '\n', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' ...}; static const uint8_t HID_KEYBRD_ShiftKey[] = { '\0' , '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\0', '\0', '\0', 'A', 'Z', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '*', '\0', 'Q', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', '%', '\0', '\n', '\0', '\0', 'W', 'X', 'C', 'V', 'B', 'N', '?', '.', '/', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' ...};/* ... */ #endif static const uint8_t HID_KEYBRD_Codes[] = { 0, 0, 0, 0, 31, 50, 48, 33, 19, 34, 35, 36, 24, 37, 38, 39, /* 0x00 - 0x0F */ 52, 51, 25, 26, 17, 20, 32, 21, 23, 49, 18, 47, 22, 46, 2, 3, /* 0x10 - 0x1F */ 4, 5, 6, 7, 8, 9, 10, 11, 43, 110, 15, 16, 61, 12, 13, 27, /* 0x20 - 0x2F */ 28, 29, 42, 40, 41, 1, 53, 54, 55, 30, 112, 113, 114, 115, 116, 117, /* 0x30 - 0x3F */ 118, 119, 120, 121, 122, 123, 124, 125, 126, 75, 80, 85, 76, 81, 86, 89, /* 0x40 - 0x4F */ 79, 84, 83, 90, 95, 100, 105, 106, 108, 93, 98, 103, 92, 97, 102, 91, /* 0x50 - 0x5F */ 96, 101, 99, 104, 45, 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7F */ 0, 0, 0, 0, 0, 107, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xA0 - 0xAF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xB0 - 0xBF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xC0 - 0xCF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xD0 - 0xDF */ 58, 44, 60, 127, 64, 57, 62, 128 /* 0xE0 - 0xE7 */ ...}; /** * @brief USBH_HID_KeybdInit * The function init the HID keyboard. * @param phost: Host handle * @retval USBH Status *//* ... */ USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost) { uint32_t x; HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; keybd_info.lctrl = 0U; keybd_info.lshift = 0U; keybd_info.lalt = 0U; keybd_info.lgui = 0U; keybd_info.rctrl = 0U; keybd_info.rshift = 0U; keybd_info.ralt = 0U; keybd_info.rgui = 0U; for (x = 0U; x < sizeof(keybd_report_data); x++) { keybd_report_data[x] = 0U; keybd_rx_report_buf[x] = 0U; }for (x = 0U; x < sizeof(keybd_report_data); x++) { ... } if (HID_Handle->length > (sizeof(keybd_report_data))) { HID_Handle->length = (uint16_t)(sizeof(keybd_report_data)); }if (HID_Handle->length > (sizeof(keybd_report_data))) { ... } HID_Handle->pData = keybd_rx_report_buf; if ((HID_QUEUE_SIZE * sizeof(keybd_report_data)) > sizeof(phost->device.Data)) { return USBH_FAIL; }if ((HID_QUEUE_SIZE * sizeof(keybd_report_data)) > sizeof(phost->device.Data)) { ... } else { USBH_HID_FifoInit(&HID_Handle->fifo, phost->device.Data, (uint16_t)(HID_QUEUE_SIZE * sizeof(keybd_report_data))); }else { ... } return USBH_OK; }{ ... } /** * @brief USBH_HID_GetKeybdInfo * The function return keyboard information. * @param phost: Host handle * @retval keyboard information *//* ... */ HID_KEYBD_Info_TypeDef *USBH_HID_GetKeybdInfo(USBH_HandleTypeDef *phost) { if (USBH_HID_KeybdDecode(phost) == USBH_OK) { return &keybd_info; }if (USBH_HID_KeybdDecode(phost) == USBH_OK) { ... } else { return NULL; }else { ... } }{ ... } /** * @brief USBH_HID_KeybdDecode * The function decode keyboard data. * @param phost: Host handle * @retval USBH Status *//* ... */ static USBH_StatusTypeDef USBH_HID_KeybdDecode(USBH_HandleTypeDef *phost) { uint8_t x; HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; if ((HID_Handle->length == 0U) || (HID_Handle->fifo.buf == NULL)) { return USBH_FAIL; }if ((HID_Handle->length == 0U) || (HID_Handle->fifo.buf == NULL)) { ... } /*Fill report */ if (USBH_HID_FifoRead(&HID_Handle->fifo, &keybd_report_data, HID_Handle->length) == HID_Handle->length) { keybd_info.lctrl = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lctrl, 0U); keybd_info.lshift = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lshift, 0U); keybd_info.lalt = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lalt, 0U); keybd_info.lgui = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_lgui, 0U); keybd_info.rctrl = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rctrl, 0U); keybd_info.rshift = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rshift, 0U); keybd_info.ralt = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_ralt, 0U); keybd_info.rgui = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_rgui, 0U); for (x = 0U; x < sizeof(keybd_info.keys); x++) { keybd_info.keys[x] = (uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &imp_0_key_array, x); }for (x = 0U; x < sizeof(keybd_info.keys); x++) { ... } return USBH_OK; }if (USBH_HID_FifoRead(&HID_Handle->fifo, &keybd_report_data, HID_Handle->length) == HID_Handle->length) { ... } return USBH_FAIL; }{ ... } /** * @brief USBH_HID_GetASCIICode * The function decode keyboard data into ASCII characters. * @param phost: Host handle * @param info: Keyboard information * @retval ASCII code *//* ... */ uint8_t USBH_HID_GetASCIICode(HID_KEYBD_Info_TypeDef *info) { uint8_t output; if ((info->lshift != 0U) || (info->rshift != 0U)) { output = HID_KEYBRD_ShiftKey[HID_KEYBRD_Codes[info->keys[0]]]; }if ((info->lshift != 0U) || (info->rshift != 0U)) { ... } else { output = HID_KEYBRD_Key[HID_KEYBRD_Codes[info->keys[0]]]; }else { ... } return output; }{ ... }
Details