usbdhid.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
3 // usbdhid.h - Definitions used by HID 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 #ifndef __USBDHID_H__
24 #define __USBDHID_H__
25 
26 //*****************************************************************************
27 //
28 // If building with a C++ compiler, make all of the definitions in this header
29 // have a C binding.
30 //
31 //*****************************************************************************
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36 
37 //*****************************************************************************
38 //
41 //
42 //*****************************************************************************
43 
44 //*****************************************************************************
45 //
46 // This is the size of the g_pui8HIDInterface array in bytes.
47 //
48 //*****************************************************************************
49 #define HIDINTERFACE_SIZE (9)
50 
51 //*****************************************************************************
52 //
53 // This is the size of the g_pui8HIDInEndpoint array in bytes.
54 //
55 //*****************************************************************************
56 #define HIDINENDPOINT_SIZE (7)
57 
58 //*****************************************************************************
59 //
60 // This is the size of the g_pui8HIDOutEndpoint array in bytes.
61 //
62 //*****************************************************************************
63 #define HIDOUTENDPOINT_SIZE (7)
64 
65 //*****************************************************************************
66 //
67 // This is the size of the tHIDDescriptor in bytes.
68 //
69 //*****************************************************************************
70 #define HIDDESCRIPTOR_SIZE (9)
71 
72 //*****************************************************************************
73 //
78 //
79 //*****************************************************************************
80 #define COMPOSITE_DHID_SIZE (HIDINTERFACE_SIZE + HIDINENDPOINT_SIZE + \
81  HIDOUTENDPOINT_SIZE + HIDDESCRIPTOR_SIZE)
82 
83 //*****************************************************************************
84 //
85 // Macros used to create the static Report Descriptors.
86 //
87 //*****************************************************************************
88 
89 //*****************************************************************************
90 //
101 //
102 //*****************************************************************************
103 #define UsagePage(ui8Value) 0x05, ((ui8Value) & 0xff)
104 
105 //*****************************************************************************
106 //
118 //
119 //*****************************************************************************
120 #define UsagePageVendor(ui16Value) 0x06, ((ui16Value) & 0xFF), \
121  (((ui16Value) >> 8) & 0xFF)
122 
123 //*****************************************************************************
124 //
133 //
134 //*****************************************************************************
135 #define Usage(ui8Value) 0x09, ((ui8Value) & 0xff)
136 
137 //*****************************************************************************
138 //
149 //
150 //*****************************************************************************
151 #define UsageVendor(ui16Value) 0x0A, ((ui16Value) & 0xFF), \
152  (((ui16Value) >> 8) & 0xFF)
153 
154 //*****************************************************************************
155 //
166 //
167 //*****************************************************************************
168 #define UsageMinimum(ui8Value) 0x19, ((ui8Value) & 0xff)
169 
170 //*****************************************************************************
171 //
182 //
183 //*****************************************************************************
184 #define UsageMaximum(ui8Value) 0x29, ((ui8Value) & 0xff)
185 
186 //*****************************************************************************
187 //
198 //
199 //*****************************************************************************
200 #define LogicalMinimum(i8Value) 0x15, ((i8Value) & 0xff)
201 
202 //*****************************************************************************
203 //
214 //
215 //*****************************************************************************
216 #define LogicalMaximum(i8Value) 0x25, ((i8Value) & 0xff)
217 
218 //*****************************************************************************
219 //
232 //
233 //*****************************************************************************
234 #define PhysicalMinimum(i16Value) \
235  0x36, ((i16Value) & 0xFF), \
236  (((i16Value) >> 8) & 0xFF)
237 
238 //*****************************************************************************
239 //
252 //
253 //*****************************************************************************
254 #define PhysicalMaximum(i16Value) \
255  0x46, ((i16Value) & 0xFF), \
256  (((i16Value) >> 8) & 0xFF)
257 
258 //*****************************************************************************
259 //
271 //
272 //*****************************************************************************
273 #define Collection(ui8Value) 0xa1, ((ui8Value) & 0xff)
274 
275 //*****************************************************************************
276 //
286 //
287 //*****************************************************************************
288 #define EndCollection 0xc0
289 
290 //*****************************************************************************
291 //
302 //
303 //*****************************************************************************
304 #define ReportCount(ui8Value) 0x95, ((ui8Value) & 0xff)
305 
306 //*****************************************************************************
307 //
318 //
319 //*****************************************************************************
320 #define ReportID(ui8Value) 0x85, ((ui8Value) & 0xff)
321 
322 //*****************************************************************************
323 //
335 //
336 //*****************************************************************************
337 #define ReportSize(ui8Value) 0x75, ((ui8Value) & 0xff)
338 
339 //*****************************************************************************
340 //
354 //
355 //*****************************************************************************
356 #define Input(ui8Value) 0x81, ((ui8Value) & 0xff)
357 
358 //*****************************************************************************
359 //
374 //
375 //*****************************************************************************
376 #define Input2(ui16Value) 0x82, ((ui16Value) & 0xff), \
377  (((ui16Value) >> 8) & 0xFF)
378 
379 //*****************************************************************************
380 //
394 //
395 //*****************************************************************************
396 #define Feature(ui8Value) 0xB1, ((ui8Value) & 0xff)
397 
398 //*****************************************************************************
399 //
414 //
415 //*****************************************************************************
416 #define Feature2(ui16Value) 0xB2, ((ui16Value) & 0xff), \
417  (((ui16Value) >> 8) & 0xFF)
418 
419 //*****************************************************************************
420 //
434 //
435 //*****************************************************************************
436 #define Output(ui8Value) 0x91, ((ui8Value) & 0xff)
437 
438 //*****************************************************************************
439 //
454 //
455 //*****************************************************************************
456 #define Output2(ui16Value) 0x92, ((ui16Value) & 0xff), \
457  (((ui16Value) >> 8) & 0xFF)
458 
459 //*****************************************************************************
460 //
472 //
473 //*****************************************************************************
474 #define UnitExponent(i8Value) 0x55, ((i8Value) & 0x0f)
475 
476 //*****************************************************************************
477 //
491 //
492 //*****************************************************************************
493 #define Unit(ui32Value) 0x67, (ui32Value) & 0x0f), \
494  (((ui32Value) >> 8) & 0xFF), \
495  (((ui32Value) >> 16) & 0xFF), \
496  (((ui32Value) >> 24) & 0xFF)
497 
498 //*****************************************************************************
499 //
502 //*****************************************************************************
503 #define UnitDistance_cm 0x66, 0x11, 0x00
504 
505 //*****************************************************************************
506 //
509 //*****************************************************************************
510 #define UnitDistance_i 0x66, 0x13, 0x00
511 
512 //*****************************************************************************
513 //
516 //*****************************************************************************
517 #define UnitRotation_deg 0x66, 0x14, 0x00
518 
519 //*****************************************************************************
520 //
523 //*****************************************************************************
524 #define UnitRotation_rad 0x66, 0x12, 0x00
525 
526 //*****************************************************************************
527 //
530 //*****************************************************************************
531 #define UnitMass_g 0x66, 0x01, 0x01
532 
533 //*****************************************************************************
534 //
537 //*****************************************************************************
538 #define UnitTime_s 0x66, 0x01, 0x10
539 
540 //*****************************************************************************
541 //
545 //*****************************************************************************
546 #define UnitTemp_K 0x67, 0x01, 0x00, 0x01, 0x00
547 
548 //*****************************************************************************
549 //
553 //*****************************************************************************
554 #define UnitTemp_F 0x67, 0x03, 0x00, 0x01, 0x00
555 
556 //*****************************************************************************
557 //
561 //*****************************************************************************
562 #define UnitVelocitySI 0x66, 0x11, 0xF0
563 
564 //*****************************************************************************
565 //
569 //*****************************************************************************
570 #define UnitMomentumSI 0x66, 0x11, 0xF1
571 
572 //*****************************************************************************
573 //
577 //*****************************************************************************
578 #define UnitAccelerationSI 0x66, 0x11, 0xE0
579 
580 //*****************************************************************************
581 //
585 //*****************************************************************************
586 #define UnitForceSI 0x66, 0x11, 0xE1
587 
588 //*****************************************************************************
589 //
593 //*****************************************************************************
594 #define UnitEnergySI 0x66, 0x21, 0xE1
595 
596 //*****************************************************************************
597 //
601 //*****************************************************************************
602 #define UnitAngAccelerationSI 0x66, 0x12, 0xE0
603 
604 //*****************************************************************************
605 //
608 //*****************************************************************************
609 #define UnitVoltage 0x67, 0x21, 0xD1, 0xF0, 0x00
610 
611 //*****************************************************************************
612 //
615 //*****************************************************************************
616 #define UnitCurrent_A 0x67, 0x01, 0x00, 0x10, 0x00
617 
618 //*****************************************************************************
619 //
620 // PRIVATE
621 //
622 // The first few sections of this header are private defines that are used by
623 // the USB HID code and are here only to help with the application
624 // allocating the correct amount of memory for the HID device code.
625 //
626 //*****************************************************************************
627 #define USBDHID_MAX_PACKET 64
628 
629 //*****************************************************************************
630 //
631 // PRIVATE
632 //
633 // This enumeration holds the various states that the device can be in during
634 // normal operation.
635 //
636 //*****************************************************************************
637 typedef enum
638 {
639  //
640  // Unconfigured.
641  //
643 
644  //
645  // No outstanding transaction remains to be completed.
646  //
648 
649  //
650  // Waiting on completion of a send or receive transaction.
651  //
653 }
654 tHIDState;
655 
656 //*****************************************************************************
657 //
658 // PRIVATE
659 //
660 // This structure defines the private instance data and state variables for
661 // HID devices. The memory for this structure is included in the
662 // sPrivateData field in the tUSBDHIDDevice structure passed in the
663 // USBDHIDInit() function.
664 //
665 //*****************************************************************************
666 typedef struct
667 {
668  //
669  // Base address for the USB controller.
670  //
671  uint32_t ui32USBBase;
672 
673  //
674  // The device info to interact with the lower level DCD code.
675  //
677 
678  //
679  // The state of the HID receive channel.
680  //
681  volatile tHIDState iHIDRxState;
682 
683  //
684  // The state of the HID transmit channel.
685  //
686  volatile tHIDState iHIDTxState;
687 
688  //
689  // State of any pending operations that could not be handled immediately
690  // upon receipt.
691  //
692  volatile uint16_t ui16DeferredOpFlags;
693 
694  //
695  // Size of the HID IN report.
696  //
698 
699  //
700  // .
701  //
703 
704  //
705  // Size of the HID OUT report.
706  //
708 
709  //
710  // Pointer to the current HID IN report data.
711  //
713 
714  //
715  // Pointer to the current HID OUT report data.
716  //
718 
719  //
720  // The connection status of the device.
721  //
722  volatile bool bConnected;
723 
724  //
725  // Whether an IN transaction is in process.
726  //
727  volatile bool bSendInProgress;
728 
729  //
730  // An HID request transaction is in process(Endpoint 0).
731  //
733 
734  //
735  // The IN endpoint number, this is modified in composite devices.
736  //
737  uint8_t ui8INEndpoint;
738 
739  //
740  // The OUT endpoint number, this is modified in composite devices.
741  //
742  uint8_t ui8OUTEndpoint;
743 
744  //
745  // The bulk class interface number, this is modified in composite devices.
746  //
747  uint8_t ui8Interface;
748 }
750 
751 //*****************************************************************************
752 //
757 //
758 //*****************************************************************************
759 typedef struct
760 {
761  //
765  //
766  uint8_t ui8Duration4mS;
767 
768  //
774  //
775  uint8_t ui8ReportID;
776 
777  //
781  //
783 
784  //
789  //
791 }
793 
794 //*****************************************************************************
795 //
798 //
799 //*****************************************************************************
800 typedef struct
801 {
802  //
804  //
805  uint16_t ui16VID;
806 
807  //
809  //
810  uint16_t ui16PID;
811 
812  //
814  //
815  uint16_t ui16MaxPowermA;
816 
817  //
822  //
824 
825  //
827  //
828  uint8_t ui8Subclass;
829 
830  //
832  //
833  uint8_t ui8Protocol;
834 
835  //
840  //
842 
843  //
852  //
854 
859  //
861 
862  //
866  //
867  void *pvRxCBData;
868 
869  //
873  //
875 
876  //
880  //
881  void *pvTxCBData;
882 
883  //
890  //
892 
893  //
897  //
898  const tHIDDescriptor *psHIDDescriptor;
899 
900  //
906  //
907  const uint8_t * const *ppui8ClassDescriptors;
908 
909  //
926  //
927  const uint8_t * const *ppui8StringDescriptors;
928 
929  //
932  //
934 
935  //
936  // ! The configuration descriptor for this HID device.
937  //
939 
940  //
944  //
946 }
948 
949 //*****************************************************************************
950 //
951 // HID-specific device class driver events
952 //
953 //*****************************************************************************
954 
955 //*****************************************************************************
956 //
966 //
967 //*****************************************************************************
968 #define USBD_HID_EVENT_GET_REPORT \
969  (USBD_HID_EVENT_BASE + 0)
970 
971 //*****************************************************************************
972 //
981 //
982 //*****************************************************************************
983 #define USBD_HID_EVENT_REPORT_SENT \
984  (USBD_HID_EVENT_BASE + 1)
985 
986 //*****************************************************************************
987 //
997 //
998 //*****************************************************************************
999 #define USBD_HID_EVENT_GET_REPORT_BUFFER \
1000  (USBD_HID_EVENT_BASE + 2)
1001 
1002 //*****************************************************************************
1003 //
1012 //
1013 //*****************************************************************************
1014 #define USBD_HID_EVENT_SET_REPORT \
1015  (USBD_HID_EVENT_BASE + 3)
1016 
1017 //*****************************************************************************
1018 //
1022 //
1023 //*****************************************************************************
1024 #define USBD_HID_EVENT_GET_PROTOCOL \
1025  (USBD_HID_EVENT_BASE + 4)
1026 
1027 //*****************************************************************************
1028 //
1032 //
1033 //*****************************************************************************
1034 #define USBD_HID_EVENT_SET_PROTOCOL \
1035  (USBD_HID_EVENT_BASE + 5)
1036 
1037 //*****************************************************************************
1038 //
1045 //
1046 //*****************************************************************************
1047 #define USBD_HID_EVENT_IDLE_TIMEOUT \
1048  (USBD_HID_EVENT_BASE + 6)
1049 
1050 //*****************************************************************************
1051 //
1052 // API Function Prototypes
1053 //
1054 //*****************************************************************************
1055 extern void *USBDHIDInit(uint32_t ui32Index, tUSBDHIDDevice *psHIDDevice);
1056 extern void *USBDHIDCompositeInit(uint32_t ui32Index,
1057  tUSBDHIDDevice *psDevice,
1058  tCompositeEntry *psCompEntry);
1059 extern void USBDHIDTerm(void *pvHIDInstance);
1060 extern void *USBDHIDSetRxCBData(void *pvHIDInstance, void *pvCBData);
1061 extern void *USBDHIDSetTxCBData(void *pvHIDInstance, void *pvCBData);
1062 extern uint32_t USBDHIDReportWrite(void *pvHIDInstance, uint8_t *pi8Data,
1063  uint32_t ui32Length, bool bLast);
1064 extern uint32_t USBDHIDPacketRead(void *pvHIDInstance, uint8_t *pi8Data,
1065  uint32_t ui32Length, bool bLast);
1066 extern uint32_t USBDHIDTxPacketAvailable(void *pvHIDInstance);
1067 extern uint32_t USBDHIDRxPacketAvailable(void *pvHIDInstance);
1068 extern bool USBDHIDRemoteWakeupRequest(void *pvHIDInstance);
1069 
1070 //*****************************************************************************
1071 //
1072 // Close the Doxygen group.
1074 //
1075 //*****************************************************************************
1076 
1077 //*****************************************************************************
1078 //
1079 // The following APIs are deprecated.
1080 //
1081 //*****************************************************************************
1082 #ifndef DEPRECATED
1083 
1084 //
1085 // Use USBDCDFeatureSet() or USBHCDFeatureSet() with \b USBLIB_FEATURE_POWER
1086 // configuration option.
1087 //
1088 extern void USBDHIDPowerStatusSet(void *pvHIDInstance, uint8_t ui8Power);
1089 #endif
1090 
1091 //*****************************************************************************
1092 //
1093 // Mark the end of the C bindings section for C++ compilers.
1094 //
1095 //*****************************************************************************
1096 #ifdef __cplusplus
1097 }
1098 #endif
1099 
1100 #endif // __USBDHID_H__
Definition: usblib.h:1077
uint8_t ui8NumInputReports
Definition: usbdhid.h:841
tHIDInstance sPrivateData
Definition: usbdhid.h:945
Definition: usbdhid.h:759
bool bUseOutEndpoint
Definition: usbdhid.h:891
uint16_t ui16MaxPowermA
The maximum power consumption of the device, expressed in milliamps.
Definition: usbdhid.h:815
tUSBCallback pfnTxCallback
Definition: usbdhid.h:874
void USBDHIDTerm(void *pvHIDInstance)
Definition: usbdhid.c:2007
const uint8_t *const * ppui8ClassDescriptors
Definition: usbdhid.h:907
Definition: usbdhid.h:666
uint8_t ui8INEndpoint
Definition: usbdhid.h:737
uint32_t ui32NumStringDescriptors
Definition: usbdhid.h:933
bool bGetRequestPending
Definition: usbdhid.h:732
Definition: usbdhid.h:652
tHIDReportIdle * psReportIdle
Definition: usbdhid.h:853
uint8_t ui8ReportID
Definition: usbdhid.h:775
uint16_t ui16VID
The vendor ID that this device is to present in the device descriptor.
Definition: usbdhid.h:805
uint8_t * pui8OutReportData
Definition: usbdhid.h:717
tDeviceInfo sDevInfo
Definition: usbdhid.h:676
uint16_t ui16OutReportSize
Definition: usbdhid.h:707
uint32_t ui32USBBase
Definition: usbdhid.h:671
Definition: usbdevice.h:135
tHIDState
Definition: usbdhid.h:637
Definition: usbdhid.h:800
void USBDHIDPowerStatusSet(void *pvHIDInstance, uint8_t ui8Power)
Definition: usbdhid.c:2450
const tHIDDescriptor * psHIDDescriptor
Definition: usbdhid.h:898
void * USBDHIDInit(uint32_t ui32Index, tUSBDHIDDevice *psHIDDevice)
Definition: usbdhid.c:1789
uint32_t ui32TimeSinceReportmS
Definition: usbdhid.h:790
const tConfigHeader *const * ppsConfigDescriptor
Definition: usbdhid.h:938
void * pvTxCBData
Definition: usbdhid.h:881
volatile uint16_t ui16DeferredOpFlags
Definition: usbdhid.h:692
uint16_t ui16InReportSize
Definition: usbdhid.h:697
bool USBDHIDRemoteWakeupRequest(void *pvHIDInstance)
Definition: usbdhid.c:2481
uint8_t ui8PwrAttributes
Definition: usbdhid.h:823
uint8_t ui8Subclass
The interface subclass to publish to the server for this HID device.
Definition: usbdhid.h:828
uint32_t USBDHIDTxPacketAvailable(void *pvHIDInstance)
Definition: usbdhid.c:2347
uint32_t USBDHIDReportWrite(void *pvHIDInstance, uint8_t *pi8Data, uint32_t ui32Length, bool bLast)
Definition: usbdhid.c:2141
void * pvRxCBData
Definition: usbdhid.h:867
volatile bool bSendInProgress
Definition: usbdhid.h:727
uint8_t ui8OUTEndpoint
Definition: usbdhid.h:742
uint8_t * pui8InReportData
Definition: usbdhid.h:712
tUSBCallback pfnRxCallback
Definition: usbdhid.h:860
volatile tHIDState iHIDRxState
Definition: usbdhid.h:681
uint16_t ui16InReportIndex
Definition: usbdhid.h:702
Definition: usbdevice.h:66
uint32_t(* tUSBCallback)(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgParam, void *pvMsgData)
Definition: usblib.h:1220
volatile bool bConnected
Definition: usbdhid.h:722
uint32_t USBDHIDPacketRead(void *pvHIDInstance, uint8_t *pi8Data, uint32_t ui32Length, bool bLast)
Definition: usbdhid.c:2246
uint16_t ui16PID
The product ID that this device is to present in the device descriptor.
Definition: usbdhid.h:810
Definition: usbdhid.h:642
uint32_t USBDHIDRxPacketAvailable(void *pvHIDInstance)
Definition: usbdhid.c:2395
uint8_t ui8Duration4mS
Definition: usbdhid.h:766
void * USBDHIDCompositeInit(uint32_t ui32Index, tUSBDHIDDevice *psHIDDevice, tCompositeEntry *psCompEntry)
Definition: usbdhid.c:1849
struct tHIDInstance tHIDInstance
Definition: usbhhid.h:44
uint16_t ui16TimeTillNextmS
Definition: usbdhid.h:782
void * USBDHIDSetRxCBData(void *pvHIDInstance, void *pvCBData)
Definition: usbdhid.c:2050
uint8_t ui8Protocol
The interface protocol to publish to the server for this HID device.
Definition: usbdhid.h:833
uint8_t ui8Interface
Definition: usbdhid.h:747
void * USBDHIDSetTxCBData(void *pvHIDInstance, void *pvCBData)
Definition: usbdhid.c:2092
const uint8_t *const * ppui8StringDescriptors
Definition: usbdhid.h:927
volatile tHIDState iHIDTxState
Definition: usbdhid.h:686
Definition: usbdhid.h:647
Copyright 2017, Texas Instruments Incorporated