diff options
Diffstat (limited to 'lib/chibios-contrib/os/hal/include/usbh/dev/hid.h')
-rw-r--r-- | lib/chibios-contrib/os/hal/include/usbh/dev/hid.h | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/include/usbh/dev/hid.h b/lib/chibios-contrib/os/hal/include/usbh/dev/hid.h new file mode 100644 index 000000000..de001ab3c --- /dev/null +++ b/lib/chibios-contrib/os/hal/include/usbh/dev/hid.h | |||
@@ -0,0 +1,144 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio | ||
3 | Copyright (C) 2015..2019 Diego Ismirlian, (dismirlian(at)google's mail) | ||
4 | |||
5 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | you may not use this file except in compliance with the License. | ||
7 | You may obtain a copy of the License at | ||
8 | |||
9 | http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | |||
11 | Unless required by applicable law or agreed to in writing, software | ||
12 | distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | See the License for the specific language governing permissions and | ||
15 | limitations under the License. | ||
16 | */ | ||
17 | |||
18 | #ifndef USBH_HID_H_ | ||
19 | #define USBH_HID_H_ | ||
20 | |||
21 | #include "hal_usbh.h" | ||
22 | |||
23 | #if HAL_USE_USBH && HAL_USBH_USE_HID | ||
24 | |||
25 | /* TODO: | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | |||
30 | /*===========================================================================*/ | ||
31 | /* Driver pre-compile time settings. */ | ||
32 | /*===========================================================================*/ | ||
33 | #if !defined(HAL_USBHHID_USE_INTERRUPT_OUT) | ||
34 | #define HAL_USBHHID_USE_INTERRUPT_OUT FALSE | ||
35 | #endif | ||
36 | |||
37 | /*===========================================================================*/ | ||
38 | /* Derived constants and error checks. */ | ||
39 | /*===========================================================================*/ | ||
40 | |||
41 | |||
42 | /*===========================================================================*/ | ||
43 | /* Driver data structures and types. */ | ||
44 | /*===========================================================================*/ | ||
45 | |||
46 | typedef enum { | ||
47 | USBHHID_STATE_UNINIT = 0, | ||
48 | USBHHID_STATE_STOP = 1, | ||
49 | USBHHID_STATE_ACTIVE = 2, | ||
50 | USBHHID_STATE_READY = 3 | ||
51 | } usbhhid_state_t; | ||
52 | |||
53 | typedef enum { | ||
54 | USBHHID_DEVTYPE_GENERIC = 0, | ||
55 | USBHHID_DEVTYPE_BOOT_KEYBOARD = 1, | ||
56 | USBHHID_DEVTYPE_BOOT_MOUSE = 2, | ||
57 | } usbhhid_devtype_t; | ||
58 | |||
59 | typedef enum { | ||
60 | USBHHID_REPORTTYPE_INPUT = 1, | ||
61 | USBHHID_REPORTTYPE_OUTPUT = 2, | ||
62 | USBHHID_REPORTTYPE_FEATURE = 3, | ||
63 | } usbhhid_reporttype_t; | ||
64 | |||
65 | typedef enum { | ||
66 | USBHHID_PROTOCOL_BOOT = 0, | ||
67 | USBHHID_PROTOCOL_REPORT = 1, | ||
68 | } usbhhid_protocol_t; | ||
69 | |||
70 | typedef struct USBHHIDDriver USBHHIDDriver; | ||
71 | typedef struct USBHHIDConfig USBHHIDConfig; | ||
72 | |||
73 | typedef void (*usbhhid_report_callback)(USBHHIDDriver *hidp, uint16_t len); | ||
74 | |||
75 | struct USBHHIDConfig { | ||
76 | usbhhid_report_callback cb_report; | ||
77 | void *report_buffer; | ||
78 | uint16_t report_len; | ||
79 | usbhhid_protocol_t protocol; | ||
80 | }; | ||
81 | |||
82 | struct USBHHIDDriver { | ||
83 | /* inherited from abstract class driver */ | ||
84 | _usbh_base_classdriver_data | ||
85 | |||
86 | usbh_ep_t epin; | ||
87 | #if HAL_USBHHID_USE_INTERRUPT_OUT | ||
88 | usbh_ep_t epout; | ||
89 | #endif | ||
90 | uint8_t ifnum; | ||
91 | |||
92 | usbhhid_devtype_t type; | ||
93 | usbhhid_state_t state; | ||
94 | |||
95 | usbh_urb_t in_urb; | ||
96 | |||
97 | const USBHHIDConfig *config; | ||
98 | |||
99 | semaphore_t sem; | ||
100 | }; | ||
101 | |||
102 | |||
103 | /*===========================================================================*/ | ||
104 | /* Driver macros. */ | ||
105 | /*===========================================================================*/ | ||
106 | |||
107 | |||
108 | /*===========================================================================*/ | ||
109 | /* External declarations. */ | ||
110 | /*===========================================================================*/ | ||
111 | |||
112 | extern USBHHIDDriver USBHHIDD[HAL_USBHHID_MAX_INSTANCES]; | ||
113 | |||
114 | #ifdef __cplusplus | ||
115 | extern "C" { | ||
116 | #endif | ||
117 | /* HID Common API */ | ||
118 | usbh_urbstatus_t usbhhidGetReport(USBHHIDDriver *hidp, | ||
119 | uint8_t report_id, usbhhid_reporttype_t report_type, | ||
120 | void *data, uint16_t len); | ||
121 | usbh_urbstatus_t usbhhidSetReport(USBHHIDDriver *hidp, | ||
122 | uint8_t report_id, usbhhid_reporttype_t report_type, | ||
123 | const void *data, uint16_t len); | ||
124 | usbh_urbstatus_t usbhhidGetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t *duration); | ||
125 | usbh_urbstatus_t usbhhidSetIdle(USBHHIDDriver *hidp, uint8_t report_id, uint8_t duration); | ||
126 | usbh_urbstatus_t usbhhidGetProtocol(USBHHIDDriver *hidp, uint8_t *protocol); | ||
127 | usbh_urbstatus_t usbhhidSetProtocol(USBHHIDDriver *hidp, uint8_t protocol); | ||
128 | |||
129 | static inline uint8_t usbhhidGetType(USBHHIDDriver *hidp) { | ||
130 | return hidp->type; | ||
131 | } | ||
132 | |||
133 | static inline usbhhid_state_t usbhhidGetState(USBHHIDDriver *hidp) { | ||
134 | return hidp->state; | ||
135 | } | ||
136 | |||
137 | void usbhhidStart(USBHHIDDriver *hidp, const USBHHIDConfig *cfg); | ||
138 | #ifdef __cplusplus | ||
139 | } | ||
140 | #endif | ||
141 | |||
142 | #endif | ||
143 | |||
144 | #endif /* USBH_HID_H_ */ | ||