usb_hid.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: BSD-3-Clause
  2. // Copyright (c) 2019-2022, Alex Taradov <alex@taradov.com>. All rights reserved.
  3. #ifndef _USB_HID_H_
  4. #define _USB_HID_H_
  5. /*- Includes ----------------------------------------------------------------*/
  6. #include "usb_std.h"
  7. /*- Definitions -------------------------------------------------------------*/
  8. #define USB_HID_BDC_V1_11 0x0111
  9. #define USB_HID_NO_COUNTRY_CODE 0
  10. enum
  11. {
  12. USB_HID_GET_REPORT = 0x01,
  13. USB_HID_GET_IDLE = 0x02,
  14. USB_HID_GET_PROTOCOL = 0x03,
  15. USB_HID_SET_REPORT = 0x09,
  16. USB_HID_SET_IDLE = 0x0a,
  17. USB_HID_SET_PROTOCOL = 0x0b,
  18. };
  19. enum
  20. {
  21. USB_HID_DEVICE_CLASS = 3, // USB Human Interface Device Class
  22. };
  23. enum
  24. {
  25. USB_HID_SUB_CLASS_NOBOOT = 0x00,
  26. USB_HID_SUB_CLASS_BOOT = 0x01,
  27. };
  28. enum
  29. {
  30. USB_HID_PROTOCOL_GENERIC = 0x00,
  31. USB_HID_PROTOCOL_KEYBOARD = 0x01,
  32. USB_HID_PROTOCOL_MOUSE = 0x02,
  33. };
  34. enum
  35. {
  36. USB_HID_DESCRIPTOR = 0x21,
  37. USB_HID_REPORT_DESCRIPTOR = 0x22,
  38. USB_HID_PHYSICAL_DESCRIPTOR = 0x23,
  39. };
  40. enum
  41. {
  42. USB_HID_REPORT_TYPE_INPUT = 1,
  43. USB_HID_REPORT_TYPE_OUTPUT = 2,
  44. USB_HID_REPORT_TYPE_FEATURE = 3,
  45. };
  46. enum
  47. {
  48. USB_HID_PROCOTOL_BOOT = 0,
  49. USB_HID_PROCOTOL_REPORT = 1,
  50. };
  51. /*- Types -------------------------------------------------------------------*/
  52. typedef struct USB_PACK
  53. {
  54. uint8_t bLength;
  55. uint8_t bDescriptorType;
  56. uint16_t bcdHID;
  57. uint8_t bCountryCode;
  58. uint8_t bNumDescriptors;
  59. uint8_t bDescriptorType1;
  60. uint16_t wDescriptorLength;
  61. } usb_hid_descriptor_t;
  62. /*- Prototypes --------------------------------------------------------------*/
  63. void usb_hid_init(void);
  64. bool usb_hid_handle_request(usb_request_t *request);
  65. void usb_hid_send(uint8_t *data, int size);
  66. void usb_hid_recv(uint8_t *data, int size);
  67. void usb_hid_send_callback(void);
  68. void usb_hid_recv_callback(int size);
  69. #endif // _USB_HID_H_