Austin Schuh | 41baf20 | 2022-01-01 14:33:40 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * The MIT License (MIT) |
| 3 | * |
| 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | * |
| 24 | * This file is part of the TinyUSB stack. |
| 25 | */ |
| 26 | |
| 27 | #ifndef _TUSB_HID_DEVICE_H_ |
| 28 | #define _TUSB_HID_DEVICE_H_ |
| 29 | |
| 30 | #include "hid.h" |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
| 36 | //--------------------------------------------------------------------+ |
| 37 | // Class Driver Default Configure & Validation |
| 38 | //--------------------------------------------------------------------+ |
| 39 | |
| 40 | #if !defined(CFG_TUD_HID_EP_BUFSIZE) & defined(CFG_TUD_HID_BUFSIZE) |
| 41 | // TODO warn user to use new name later on |
| 42 | // #warning CFG_TUD_HID_BUFSIZE is renamed to CFG_TUD_HID_EP_BUFSIZE, please update to use the new name |
| 43 | #define CFG_TUD_HID_EP_BUFSIZE CFG_TUD_HID_BUFSIZE |
| 44 | #endif |
| 45 | |
| 46 | #ifndef CFG_TUD_HID_EP_BUFSIZE |
| 47 | #define CFG_TUD_HID_EP_BUFSIZE 64 |
| 48 | #endif |
| 49 | |
| 50 | //--------------------------------------------------------------------+ |
| 51 | // Application API (Multiple Instances) |
| 52 | // CFG_TUD_HID > 1 |
| 53 | //--------------------------------------------------------------------+ |
| 54 | |
| 55 | // Check if the interface is ready to use |
| 56 | bool tud_hid_n_ready(uint8_t instance); |
| 57 | |
| 58 | // Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values |
| 59 | uint8_t tud_hid_n_interface_protocol(uint8_t instance); |
| 60 | |
| 61 | // Get current active protocol: HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1) |
| 62 | uint8_t tud_hid_n_get_protocol(uint8_t instance); |
| 63 | |
| 64 | // Send report to host |
| 65 | bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, uint8_t len); |
| 66 | |
| 67 | // KEYBOARD: convenient helper to send keyboard report if application |
| 68 | // use template layout report as defined by hid_keyboard_report_t |
| 69 | bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]); |
| 70 | |
| 71 | // MOUSE: convenient helper to send mouse report if application |
| 72 | // use template layout report as defined by hid_mouse_report_t |
| 73 | bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); |
| 74 | |
| 75 | // Gamepad: convenient helper to send gamepad report if application |
| 76 | // use template layout report TUD_HID_REPORT_DESC_GAMEPAD |
| 77 | bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons); |
| 78 | |
| 79 | //--------------------------------------------------------------------+ |
| 80 | // Application API (Single Port) |
| 81 | //--------------------------------------------------------------------+ |
| 82 | static inline bool tud_hid_ready(void); |
| 83 | static inline uint8_t tud_hid_interface_protocol(void); |
| 84 | static inline uint8_t tud_hid_get_protocol(void); |
| 85 | static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len); |
| 86 | static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]); |
| 87 | static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); |
| 88 | static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons); |
| 89 | |
| 90 | //--------------------------------------------------------------------+ |
| 91 | // Callbacks (Weak is optional) |
| 92 | //--------------------------------------------------------------------+ |
| 93 | |
| 94 | // Invoked when received GET HID REPORT DESCRIPTOR request |
| 95 | // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete |
| 96 | uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance); |
| 97 | |
| 98 | // Invoked when received GET_REPORT control request |
| 99 | // Application must fill buffer report's content and return its length. |
| 100 | // Return zero will cause the stack to STALL request |
| 101 | uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); |
| 102 | |
| 103 | // Invoked when received SET_REPORT control request or |
| 104 | // received data on OUT endpoint ( Report ID = 0, Type = 0 ) |
| 105 | void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); |
| 106 | |
| 107 | // Invoked when received SET_PROTOCOL request |
| 108 | // protocol is either HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1) |
| 109 | TU_ATTR_WEAK void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol); |
| 110 | |
| 111 | // Invoked when received SET_IDLE request. return false will stall the request |
| 112 | // - Idle Rate = 0 : only send report if there is changes, i.e skip duplication |
| 113 | // - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms). |
| 114 | TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate); |
| 115 | |
| 116 | // Invoked when sent REPORT successfully to host |
| 117 | // Application can use this to send the next report |
| 118 | // Note: For composite reports, report[0] is report ID |
| 119 | TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len); |
| 120 | |
| 121 | |
| 122 | //--------------------------------------------------------------------+ |
| 123 | // Inline Functions |
| 124 | //--------------------------------------------------------------------+ |
| 125 | static inline bool tud_hid_ready(void) |
| 126 | { |
| 127 | return tud_hid_n_ready(0); |
| 128 | } |
| 129 | |
| 130 | static inline uint8_t tud_hid_interface_protocol(void) |
| 131 | { |
| 132 | return tud_hid_n_interface_protocol(0); |
| 133 | } |
| 134 | |
| 135 | static inline uint8_t tud_hid_get_protocol(void) |
| 136 | { |
| 137 | return tud_hid_n_get_protocol(0); |
| 138 | } |
| 139 | |
| 140 | static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len) |
| 141 | { |
| 142 | return tud_hid_n_report(0, report_id, report, len); |
| 143 | } |
| 144 | |
| 145 | static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]) |
| 146 | { |
| 147 | return tud_hid_n_keyboard_report(0, report_id, modifier, keycode); |
| 148 | } |
| 149 | |
| 150 | static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal) |
| 151 | { |
| 152 | return tud_hid_n_mouse_report(0, report_id, buttons, x, y, vertical, horizontal); |
| 153 | } |
| 154 | |
| 155 | static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons) |
| 156 | { |
| 157 | return tud_hid_n_gamepad_report(0, report_id, x, y, z, rz, rx, ry, hat, buttons); |
| 158 | } |
| 159 | |
| 160 | /* --------------------------------------------------------------------+ |
| 161 | * HID Report Descriptor Template |
| 162 | * |
| 163 | * Convenient for declaring popular HID device (keyboard, mouse, consumer, |
| 164 | * gamepad etc...). Templates take "HID_REPORT_ID(n)" as input, leave |
| 165 | * empty if multiple reports is not used |
| 166 | * |
| 167 | * - Only 1 report: no parameter |
| 168 | * uint8_t const report_desc[] = { TUD_HID_REPORT_DESC_KEYBOARD() }; |
| 169 | * |
| 170 | * - Multiple Reports: "HID_REPORT_ID(ID)" must be passed to template |
| 171 | * uint8_t const report_desc[] = |
| 172 | * { |
| 173 | * TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1) ) , |
| 174 | * TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(2) ) |
| 175 | * }; |
| 176 | *--------------------------------------------------------------------*/ |
| 177 | |
| 178 | // Keyboard Report Descriptor Template |
| 179 | #define TUD_HID_REPORT_DESC_KEYBOARD(...) \ |
| 180 | HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 181 | HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ) ,\ |
| 182 | HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\ |
| 183 | /* Report ID if any */\ |
| 184 | __VA_ARGS__ \ |
| 185 | /* 8 bits Modifier Keys (Shfit, Control, Alt) */ \ |
| 186 | HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\ |
| 187 | HID_USAGE_MIN ( 224 ) ,\ |
| 188 | HID_USAGE_MAX ( 231 ) ,\ |
| 189 | HID_LOGICAL_MIN ( 0 ) ,\ |
| 190 | HID_LOGICAL_MAX ( 1 ) ,\ |
| 191 | HID_REPORT_COUNT ( 8 ) ,\ |
| 192 | HID_REPORT_SIZE ( 1 ) ,\ |
| 193 | HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ |
| 194 | /* 8 bit reserved */ \ |
| 195 | HID_REPORT_COUNT ( 1 ) ,\ |
| 196 | HID_REPORT_SIZE ( 8 ) ,\ |
| 197 | HID_INPUT ( HID_CONSTANT ) ,\ |
| 198 | /* Output 5-bit LED Indicator Kana | Compose | ScrollLock | CapsLock | NumLock */ \ |
| 199 | HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ) ,\ |
| 200 | HID_USAGE_MIN ( 1 ) ,\ |
| 201 | HID_USAGE_MAX ( 5 ) ,\ |
| 202 | HID_REPORT_COUNT ( 5 ) ,\ |
| 203 | HID_REPORT_SIZE ( 1 ) ,\ |
| 204 | HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ |
| 205 | /* led padding */ \ |
| 206 | HID_REPORT_COUNT ( 1 ) ,\ |
| 207 | HID_REPORT_SIZE ( 3 ) ,\ |
| 208 | HID_OUTPUT ( HID_CONSTANT ) ,\ |
| 209 | /* 6-byte Keycodes */ \ |
| 210 | HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\ |
| 211 | HID_USAGE_MIN ( 0 ) ,\ |
| 212 | HID_USAGE_MAX_N ( 255, 2 ) ,\ |
| 213 | HID_LOGICAL_MIN ( 0 ) ,\ |
| 214 | HID_LOGICAL_MAX_N( 255, 2 ) ,\ |
| 215 | HID_REPORT_COUNT ( 6 ) ,\ |
| 216 | HID_REPORT_SIZE ( 8 ) ,\ |
| 217 | HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\ |
| 218 | HID_COLLECTION_END \ |
| 219 | |
| 220 | // Mouse Report Descriptor Template |
| 221 | #define TUD_HID_REPORT_DESC_MOUSE(...) \ |
| 222 | HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 223 | HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\ |
| 224 | HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\ |
| 225 | /* Report ID if any */\ |
| 226 | __VA_ARGS__ \ |
| 227 | HID_USAGE ( HID_USAGE_DESKTOP_POINTER ) ,\ |
| 228 | HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) ,\ |
| 229 | HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\ |
| 230 | HID_USAGE_MIN ( 1 ) ,\ |
| 231 | HID_USAGE_MAX ( 5 ) ,\ |
| 232 | HID_LOGICAL_MIN ( 0 ) ,\ |
| 233 | HID_LOGICAL_MAX ( 1 ) ,\ |
| 234 | /* Left, Right, Middle, Backward, Forward buttons */ \ |
| 235 | HID_REPORT_COUNT( 5 ) ,\ |
| 236 | HID_REPORT_SIZE ( 1 ) ,\ |
| 237 | HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ |
| 238 | /* 3 bit padding */ \ |
| 239 | HID_REPORT_COUNT( 1 ) ,\ |
| 240 | HID_REPORT_SIZE ( 3 ) ,\ |
| 241 | HID_INPUT ( HID_CONSTANT ) ,\ |
| 242 | HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 243 | /* X, Y position [-127, 127] */ \ |
| 244 | HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\ |
| 245 | HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\ |
| 246 | HID_LOGICAL_MIN ( 0x81 ) ,\ |
| 247 | HID_LOGICAL_MAX ( 0x7f ) ,\ |
| 248 | HID_REPORT_COUNT( 2 ) ,\ |
| 249 | HID_REPORT_SIZE ( 8 ) ,\ |
| 250 | HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\ |
| 251 | /* Verital wheel scroll [-127, 127] */ \ |
| 252 | HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ) ,\ |
| 253 | HID_LOGICAL_MIN ( 0x81 ) ,\ |
| 254 | HID_LOGICAL_MAX ( 0x7f ) ,\ |
| 255 | HID_REPORT_COUNT( 1 ) ,\ |
| 256 | HID_REPORT_SIZE ( 8 ) ,\ |
| 257 | HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\ |
| 258 | HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ), \ |
| 259 | /* Horizontal wheel scroll [-127, 127] */ \ |
| 260 | HID_USAGE_N ( HID_USAGE_CONSUMER_AC_PAN, 2 ), \ |
| 261 | HID_LOGICAL_MIN ( 0x81 ), \ |
| 262 | HID_LOGICAL_MAX ( 0x7f ), \ |
| 263 | HID_REPORT_COUNT( 1 ), \ |
| 264 | HID_REPORT_SIZE ( 8 ), \ |
| 265 | HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), \ |
| 266 | HID_COLLECTION_END , \ |
| 267 | HID_COLLECTION_END \ |
| 268 | |
| 269 | // Consumer Control Report Descriptor Template |
| 270 | #define TUD_HID_REPORT_DESC_CONSUMER(...) \ |
| 271 | HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ) ,\ |
| 272 | HID_USAGE ( HID_USAGE_CONSUMER_CONTROL ) ,\ |
| 273 | HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\ |
| 274 | /* Report ID if any */\ |
| 275 | __VA_ARGS__ \ |
| 276 | HID_LOGICAL_MIN ( 0x00 ) ,\ |
| 277 | HID_LOGICAL_MAX_N( 0x03FF, 2 ) ,\ |
| 278 | HID_USAGE_MIN ( 0x00 ) ,\ |
| 279 | HID_USAGE_MAX_N ( 0x03FF, 2 ) ,\ |
| 280 | HID_REPORT_COUNT ( 1 ) ,\ |
| 281 | HID_REPORT_SIZE ( 16 ) ,\ |
| 282 | HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\ |
| 283 | HID_COLLECTION_END \ |
| 284 | |
| 285 | /* System Control Report Descriptor Template |
| 286 | * 0x00 - do nothing |
| 287 | * 0x01 - Power Off |
| 288 | * 0x02 - Standby |
| 289 | * 0x03 - Wake Host |
| 290 | */ |
| 291 | #define TUD_HID_REPORT_DESC_SYSTEM_CONTROL(...) \ |
| 292 | HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 293 | HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_CONTROL ) ,\ |
| 294 | HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\ |
| 295 | /* Report ID if any */\ |
| 296 | __VA_ARGS__ \ |
| 297 | /* 2 bit system power control */ \ |
| 298 | HID_LOGICAL_MIN ( 1 ) ,\ |
| 299 | HID_LOGICAL_MAX ( 3 ) ,\ |
| 300 | HID_REPORT_COUNT ( 1 ) ,\ |
| 301 | HID_REPORT_SIZE ( 2 ) ,\ |
| 302 | HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN ) ,\ |
| 303 | HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_SLEEP ) ,\ |
| 304 | HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_WAKE_UP ) ,\ |
| 305 | HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\ |
| 306 | /* 6 bit padding */ \ |
| 307 | HID_REPORT_COUNT ( 1 ) ,\ |
| 308 | HID_REPORT_SIZE ( 6 ) ,\ |
| 309 | HID_INPUT ( HID_CONSTANT ) ,\ |
| 310 | HID_COLLECTION_END \ |
| 311 | |
| 312 | // Gamepad Report Descriptor Template |
| 313 | // with 32 buttons, 2 joysticks and 1 hat/dpad with following layout |
| 314 | // | X | Y | Z | Rz | Rx | Ry (1 byte each) | hat/DPAD (1 byte) | Button Map (4 bytes) | |
| 315 | #define TUD_HID_REPORT_DESC_GAMEPAD(...) \ |
| 316 | HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 317 | HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\ |
| 318 | HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\ |
| 319 | /* Report ID if any */\ |
| 320 | __VA_ARGS__ \ |
| 321 | /* 8 bit X, Y, Z, Rz, Rx, Ry (min -127, max 127 ) */ \ |
| 322 | HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 323 | HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\ |
| 324 | HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\ |
| 325 | HID_USAGE ( HID_USAGE_DESKTOP_Z ) ,\ |
| 326 | HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\ |
| 327 | HID_USAGE ( HID_USAGE_DESKTOP_RX ) ,\ |
| 328 | HID_USAGE ( HID_USAGE_DESKTOP_RY ) ,\ |
| 329 | HID_LOGICAL_MIN ( 0x81 ) ,\ |
| 330 | HID_LOGICAL_MAX ( 0x7f ) ,\ |
| 331 | HID_REPORT_COUNT ( 6 ) ,\ |
| 332 | HID_REPORT_SIZE ( 8 ) ,\ |
| 333 | HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ |
| 334 | /* 8 bit DPad/Hat Button Map */ \ |
| 335 | HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\ |
| 336 | HID_USAGE ( HID_USAGE_DESKTOP_HAT_SWITCH ) ,\ |
| 337 | HID_LOGICAL_MIN ( 1 ) ,\ |
| 338 | HID_LOGICAL_MAX ( 8 ) ,\ |
| 339 | HID_PHYSICAL_MIN ( 0 ) ,\ |
| 340 | HID_PHYSICAL_MAX_N ( 315, 2 ) ,\ |
| 341 | HID_REPORT_COUNT ( 1 ) ,\ |
| 342 | HID_REPORT_SIZE ( 8 ) ,\ |
| 343 | HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ |
| 344 | /* 32 bit Button Map */ \ |
| 345 | HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\ |
| 346 | HID_USAGE_MIN ( 1 ) ,\ |
| 347 | HID_USAGE_MAX ( 32 ) ,\ |
| 348 | HID_LOGICAL_MIN ( 0 ) ,\ |
| 349 | HID_LOGICAL_MAX ( 1 ) ,\ |
| 350 | HID_REPORT_COUNT ( 32 ) ,\ |
| 351 | HID_REPORT_SIZE ( 1 ) ,\ |
| 352 | HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ |
| 353 | HID_COLLECTION_END \ |
| 354 | |
| 355 | // HID Generic Input & Output |
| 356 | // - 1st parameter is report size (mandatory) |
| 357 | // - 2nd parameter is report id HID_REPORT_ID(n) (optional) |
| 358 | #define TUD_HID_REPORT_DESC_GENERIC_INOUT(report_size, ...) \ |
| 359 | HID_USAGE_PAGE_N ( HID_USAGE_PAGE_VENDOR, 2 ),\ |
| 360 | HID_USAGE ( 0x01 ),\ |
| 361 | HID_COLLECTION ( HID_COLLECTION_APPLICATION ),\ |
| 362 | /* Report ID if any */\ |
| 363 | __VA_ARGS__ \ |
| 364 | /* Input */ \ |
| 365 | HID_USAGE ( 0x02 ),\ |
| 366 | HID_LOGICAL_MIN ( 0x00 ),\ |
| 367 | HID_LOGICAL_MAX_N ( 0xff, 2 ),\ |
| 368 | HID_REPORT_SIZE ( 8 ),\ |
| 369 | HID_REPORT_COUNT( report_size ),\ |
| 370 | HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\ |
| 371 | /* Output */ \ |
| 372 | HID_USAGE ( 0x03 ),\ |
| 373 | HID_LOGICAL_MIN ( 0x00 ),\ |
| 374 | HID_LOGICAL_MAX_N ( 0xff, 2 ),\ |
| 375 | HID_REPORT_SIZE ( 8 ),\ |
| 376 | HID_REPORT_COUNT( report_size ),\ |
| 377 | HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\ |
| 378 | HID_COLLECTION_END \ |
| 379 | |
| 380 | //--------------------------------------------------------------------+ |
| 381 | // Internal Class Driver API |
| 382 | //--------------------------------------------------------------------+ |
| 383 | void hidd_init (void); |
| 384 | void hidd_reset (uint8_t rhport); |
| 385 | uint16_t hidd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); |
| 386 | bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request); |
| 387 | bool hidd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); |
| 388 | |
| 389 | #ifdef __cplusplus |
| 390 | } |
| 391 | #endif |
| 392 | |
| 393 | #endif /* _TUSB_HID_DEVICE_H_ */ |