usbdhidkeyb.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // usbdhidkeyb.h - Definitions used by HID keyboard class devices.
4 //
5 // Copyright (c) 2008-2017 Texas Instruments Incorporated. All rights reserved.
6 // Software License Agreement
7 //
8 // Texas Instruments (TI) is supplying this software for use solely and
9 // exclusively on TI's microcontroller products. The software is owned by
10 // TI and/or its suppliers, and is protected under applicable copyright
11 // laws. You may not combine this software with "viral" open-source
12 // software in order to form a larger program.
13 //
14 // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
15 // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
16 // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
18 // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
19 // DAMAGES, FOR ANY REASON WHATSOEVER.
20 //
21 //
22 //*****************************************************************************
23 
24 #ifndef __USBDHIDKEYB_H__
25 #define __USBDHIDKEYB_H__
26 
27 //*****************************************************************************
28 //
29 // If building with a C++ compiler, make all of the definitions in this header
30 // have a C binding.
31 //
32 //*****************************************************************************
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
38 //*****************************************************************************
39 //
42 //
43 //*****************************************************************************
44 
45 //*****************************************************************************
46 //
52 //
53 //*****************************************************************************
54 #define KEYB_MAX_CHARS_PER_REPORT \
55  6
56 
57 //*****************************************************************************
58 //
59 // PRIVATE
60 //
61 // The first few sections of this header are private defines that are used by
62 // the USB HID keyboard code and are here only to help with the application
63 // allocating the correct amount of memory for the USB HID Keyboard device
64 // code.
65 //
66 //*****************************************************************************
67 
68 //*****************************************************************************
69 //
70 // PRIVATE
71 //
72 // This enumeration holds the various states that the keyboard can be in during
73 // normal operation.
74 //
75 //*****************************************************************************
76 typedef enum
77 {
78  //
79  // Unconfigured.
80  //
82 
83  //
84  // No keys to send and not waiting on data.
85  //
87 
88  //
89  // Waiting on report data from the host.
90  //
92 
93  //
94  // Waiting on data to be sent out.
95  //
97 }
99 
100 //*****************************************************************************
101 //
102 // PRIVATE
103 //
104 // The size of the keyboard input and output reports.
105 //
106 //*****************************************************************************
107 #define KEYB_IN_REPORT_SIZE 8
108 #define KEYB_OUT_REPORT_SIZE 1
109 
110 //*****************************************************************************
111 //
112 // PRIVATE
113 //
114 // This structure defines the private instance data structure for the USB HID
115 // keyboard device. This structure forms the RAM workspace used by each
116 // instance of the keyboard.
117 //
118 //*****************************************************************************
119 typedef struct
120 {
121  //
122  // The USB configuration number set by the host or 0 of the device is
123  // currently unconfigured.
124  //
126 
127  //
128  // The protocol requested by the host, USB_HID_PROTOCOL_BOOT or
129  // USB_HID_PROTOCOL_REPORT.
130  //
131  uint8_t ui8Protocol;
132 
133  //
134  // The current states that the keyboard LEDs are to be set to.
135  //
136  volatile uint8_t ui8LEDStates;
137 
138  //
139  // The total number of keys currently pressed. This indicates the number
140  // of key press entries in the pui8KeysPressed array.
141  //
142  uint8_t ui8KeyCount;
143 
144  //
145  // The current state of the keyboard interrupt IN endpoint.
146  //
147  volatile tKeyboardState eKeyboardState;
148 
149  //
150  // A flag to indicate that the application pressed or released a key
151  // but that we couldn't send the report immediately.
152  //
153  volatile bool bChangeMade;
154 
155  //
156  // A buffer used to receive output reports from the host.
157  //
158  uint8_t pui8DataBuffer[KEYB_OUT_REPORT_SIZE];
159 
160  //
161  // A buffer used to hold the last input report sent to the host.
162  //
163  uint8_t pui8Report[KEYB_IN_REPORT_SIZE];
164 
165  //
166  // A buffer containing the usage codes of all non-modifier keys currently
167  // in the pressed state.
168  //
169  uint8_t pui8KeysPressed[KEYB_MAX_CHARS_PER_REPORT];
170 
171  //
172  // The idle timeout control structure for our input report. This is
173  // required by the lower level HID driver.
174  //
176 
177  //
178  // This is needed for the lower level HID driver.
179  //
181 }
183 
184 //*****************************************************************************
185 //
188 //
189 //*****************************************************************************
190 typedef struct
191 {
192  //
194  //
195  const uint16_t ui16VID;
196 
197  //
199  //
200  const uint16_t ui16PID;
201 
202  //
204  //
205  const uint16_t ui16MaxPowermA;
206 
207  //
212  //
213  const uint8_t ui8PwrAttributes;
214 
218  //
220 
221  //
225  //
226  void *pvCBData;
227 
228  //
239  //
240  const uint8_t * const *ppui8StringDescriptors;
241 
242  //
245  //
246  const uint32_t ui32NumStringDescriptors;
247 
248  //
252  //
254 }
256 
257 //*****************************************************************************
258 //
259 // Keyboard-specific device class driver events
260 //
261 //*****************************************************************************
262 
263 //*****************************************************************************
264 //
272 //
273 //*****************************************************************************
274 #define USBD_HID_KEYB_EVENT_SET_LEDS \
275  USBD_HID_KEYB_EVENT_BASE
276 
277 //*****************************************************************************
278 //
280 //
281 //*****************************************************************************
282 #define KEYB_SUCCESS 0
283 
284 //*****************************************************************************
285 //
292 //
293 //*****************************************************************************
294 #define KEYB_ERR_TOO_MANY_KEYS 1
295 
296 //*****************************************************************************
297 //
301 //
302 //*****************************************************************************
303 #define KEYB_ERR_TX_ERROR 2
304 
305 //*****************************************************************************
306 //
314 //
315 //*****************************************************************************
316 #define KEYB_ERR_NOT_FOUND 3
317 
318 //*****************************************************************************
319 //
323 //
324 //*****************************************************************************
325 #define KEYB_ERR_NOT_CONFIGURED 4
326 
327 //*****************************************************************************
328 //
329 // API Function Prototypes
330 //
331 //*****************************************************************************
332 extern void *USBDHIDKeyboardInit(uint32_t ui32Index,
333  tUSBDHIDKeyboardDevice *psHIDKbDevice);
334 extern void *USBDHIDKeyboardCompositeInit(uint32_t ui32Index,
335  tUSBDHIDKeyboardDevice *psHIDKbDevice,
336  tCompositeEntry *psCompEntry);
337 extern void USBDHIDKeyboardTerm(void *pvKeyboardInstance);
338 extern void *USBDHIDKeyboardSetCBData(void *pvKeyboardInstance,
339  void *pvCBData);
340 extern uint32_t USBDHIDKeyboardKeyStateChange(void *pvKeyboardInstance,
341  uint8_t ui8Modifiers,
342  uint8_t ui8UsageCode,
343  bool bPressed);
344 extern void USBDHIDKeyboardPowerStatusSet(void *pvKeyboardInstance,
345  uint8_t ui8Power);
346 extern bool USBDHIDKeyboardRemoteWakeupRequest(void *pvKeyboardInstance);
347 
348 //*****************************************************************************
349 //
350 // Close the Doxygen group.
352 //
353 //*****************************************************************************
354 
355 //*****************************************************************************
356 //
357 // Mark the end of the C bindings section for C++ compilers.
358 //
359 //*****************************************************************************
360 #ifdef __cplusplus
361 }
362 #endif
363 
364 #endif // __USBDHIDKEYB_H__
Definition: usbdhid.h:798
uint32_t USBDHIDKeyboardKeyStateChange(void *pvKeyboardDevice, uint8_t ui8Modifiers, uint8_t ui8UsageCode, bool bPress)
Definition: usbdhidkeyb.c:1096
#define KEYB_OUT_REPORT_SIZE
Definition: usbdhidkeyb.h:108
const uint16_t ui16PID
The product ID that this device is to present in the device descriptor.
Definition: usbdhidkeyb.h:200
void * USBDHIDKeyboardSetCBData(void *pvKeyboardDevice, void *pvCBData)
Definition: usbdhidkeyb.c:1030
void * pvCBData
Definition: usbdhidkeyb.h:226
volatile uint8_t ui8LEDStates
Definition: usbdhidkeyb.h:136
uint8_t ui8USBConfigured
Definition: usbdhidkeyb.h:125
void USBDHIDKeyboardTerm(void *pvKeyboardDevice)
Definition: usbdhidkeyb.c:979
Definition: usbdhidkeyb.h:86
const uint8_t ui8PwrAttributes
Definition: usbdhidkeyb.h:213
Definition: usbdevice.h:135
Definition: usbdhid.h:839
const uint16_t ui16VID
The vendor ID that this device is to present in the device descriptor.
Definition: usbdhidkeyb.h:195
bool USBDHIDKeyboardRemoteWakeupRequest(void *pvKeyboardDevice)
Definition: usbdhidkeyb.c:1289
tHIDReportIdle sReportIdle
Definition: usbdhidkeyb.h:175
tUSBDHIDDevice sHIDDevice
Definition: usbdhidkeyb.h:180
void * USBDHIDKeyboardInit(uint32_t ui32Index, tUSBDHIDKeyboardDevice *psHIDKbDevice)
Definition: usbdhidkeyb.c:814
const uint32_t ui32NumStringDescriptors
Definition: usbdhidkeyb.h:246
Definition: usbdhidkeyb.h:91
uint8_t ui8KeyCount
Definition: usbdhidkeyb.h:142
#define KEYB_IN_REPORT_SIZE
Definition: usbdhidkeyb.h:107
volatile bool bChangeMade
Definition: usbdhidkeyb.h:153
const uint8_t *const * ppui8StringDescriptors
Definition: usbdhidkeyb.h:240
uint32_t(* tUSBCallback)(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvMsgData)
Definition: usblib.h:1220
Definition: usbdhidkeyb.h:81
Definition: usbdhidkeyb.h:119
uint8_t ui8Protocol
Definition: usbdhidkeyb.h:131
const uint16_t ui16MaxPowermA
The maximum power consumption of the device, expressed in milliamps.
Definition: usbdhidkeyb.h:205
void * USBDHIDKeyboardCompositeInit(uint32_t ui32Index, tUSBDHIDKeyboardDevice *psHIDKbDevice, tCompositeEntry *psCompEntry)
Definition: usbdhidkeyb.c:885
volatile tKeyboardState eKeyboardState
Definition: usbdhidkeyb.h:147
Definition: usbdhidkeyb.h:190
#define KEYB_MAX_CHARS_PER_REPORT
Definition: usbdhidkeyb.h:54
tHIDKeyboardInstance sPrivateData
Definition: usbdhidkeyb.h:253
tKeyboardState
Definition: usbdhidkeyb.h:76
void USBDHIDKeyboardPowerStatusSet(void *pvKeyboardDevice, uint8_t ui8Power)
Definition: usbdhidkeyb.c:1244
const tUSBCallback pfnCallback
Definition: usbdhidkeyb.h:219
Definition: usbdhidkeyb.h:96
Copyright 2018, Texas Instruments Incorporated