You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

usb_main.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * (c) 2015 flabberast <[email protected]>
  3. *
  4. * Based on the following work:
  5. * - Guillaume Duc's raw hid example (MIT License)
  6. * https://github.com/guiduc/usb-hid-chibios-example
  7. * - PJRC Teensy examples (MIT License)
  8. * https://www.pjrc.com/teensy/usb_keyboard.html
  9. * - hasu's TMK keyboard code (GPL v2 and some code Modified BSD)
  10. * https://github.com/tmk/tmk_keyboard/
  11. * - ChibiOS demo code (Apache 2.0 License)
  12. * http://www.chibios.org
  13. *
  14. * Since some GPL'd code is used, this work is licensed under
  15. * GPL v2 or later.
  16. */
  17. #ifndef _USB_MAIN_H_
  18. #define _USB_MAIN_H_
  19. #include "ch.h"
  20. #include "hal.h"
  21. /* -------------------------
  22. * General USB driver header
  23. * -------------------------
  24. */
  25. /* The USB driver to use */
  26. #define USB_DRIVER USBD1
  27. /* Initialize the USB driver and bus */
  28. void init_usb_driver(void);
  29. /* ---------------
  30. * Keyboard header
  31. * ---------------
  32. */
  33. /* main keyboard (6kro) */
  34. #define KBD_INTERFACE 0
  35. #define KBD_ENDPOINT 1
  36. #define KBD_SIZE 8
  37. #define KBD_REPORT_KEYS (KBD_SIZE - 2)
  38. /* secondary keyboard */
  39. #ifdef NKRO_ENABLE
  40. #define NKRO_INTERFACE 4
  41. #define NKRO_ENDPOINT 5
  42. #define NKRO_SIZE 16
  43. #define NKRO_REPORT_KEYS (NKRO_SIZE - 1)
  44. #endif
  45. /* this defines report_keyboard_t and computes REPORT_SIZE defines */
  46. #include "report.h"
  47. /* extern report_keyboard_t keyboard_report_sent; */
  48. /* keyboard IN request callback handler */
  49. void kbd_in_cb(USBDriver *usbp, usbep_t ep);
  50. /* start-of-frame handler */
  51. void kbd_sof_cb(USBDriver *usbp);
  52. #ifdef NKRO_ENABLE
  53. /* nkro IN callback hander */
  54. void nkro_in_cb(USBDriver *usbp, usbep_t ep);
  55. #endif /* NKRO_ENABLE */
  56. /* ------------
  57. * Mouse header
  58. * ------------
  59. */
  60. #ifdef MOUSE_ENABLE
  61. #define MOUSE_INTERFACE 1
  62. #define MOUSE_ENDPOINT 2
  63. #define MOUSE_SIZE 8
  64. /* mouse IN request callback handler */
  65. void mouse_in_cb(USBDriver *usbp, usbep_t ep);
  66. #endif /* MOUSE_ENABLE */
  67. /* ---------------
  68. * Extrakey header
  69. * ---------------
  70. */
  71. #ifdef EXTRAKEY_ENABLE
  72. #define EXTRA_INTERFACE 3
  73. #define EXTRA_ENDPOINT 4
  74. #define EXTRA_SIZE 8
  75. /* extrakey IN request callback handler */
  76. void extra_in_cb(USBDriver *usbp, usbep_t ep);
  77. /* extra report structure */
  78. typedef struct {
  79. uint8_t report_id;
  80. uint16_t usage;
  81. } __attribute__ ((packed)) report_extra_t;
  82. #endif /* EXTRAKEY_ENABLE */
  83. /* --------------
  84. * Console header
  85. * --------------
  86. */
  87. #ifdef CONSOLE_ENABLE
  88. #define CONSOLE_INTERFACE 2
  89. #define CONSOLE_ENDPOINT 3
  90. #define CONSOLE_SIZE 16
  91. /* Number of IN reports that can be stored inside the output queue */
  92. #define CONSOLE_QUEUE_CAPACITY 2
  93. #define CONSOLE_QUEUE_BUFFER_SIZE (CONSOLE_QUEUE_CAPACITY * CONSOLE_SIZE)
  94. /* Console flush time */
  95. #define CONSOLE_FLUSH_MS 50
  96. /* Putchar over the USB console */
  97. int8_t sendchar(uint8_t c);
  98. /* wrapper for printf lib */
  99. /* Flush output (send everything immediately) */
  100. void console_flush_output(void);
  101. /* console IN request callback handler */
  102. void console_in_cb(USBDriver *usbp, usbep_t ep);
  103. #endif /* CONSOLE_ENABLE */
  104. void sendchar_pf(void *p, char c);
  105. /* ---------------------------
  106. * Host driver functions (TMK)
  107. * ---------------------------
  108. */
  109. uint8_t keyboard_leds(void);
  110. void send_keyboard(report_keyboard_t *report);
  111. void send_mouse(report_mouse_t *report);
  112. void send_system(uint16_t data);
  113. void send_consumer(uint16_t data);
  114. #endif /* _USB_MAIN_H_ */