]> git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/chibios/usb_main.h
Make usb_main more USB_DRIVER #define independent.
[tmk_keyboard.git] / tmk_core / protocol / chibios / usb_main.h
1 /*
2 * (c) 2015 flabberast <s3+flabbergast@sdfeu.org>
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
18
19 #ifndef _USB_MAIN_H_
20 #define _USB_MAIN_H_
21
22 #include "ch.h"
23 #include "hal.h"
24
25 /* -------------------------
26 * General USB driver header
27 * -------------------------
28 */
29
30 /* The USB driver to use */
31 #define USB_DRIVER USBD1
32
33 /* Initialize the USB driver and bus */
34 void init_usb_driver(USBDriver *usbp);
35
36 /* ---------------
37 * Keyboard header
38 * ---------------
39 */
40
41 /* main keyboard (6kro) */
42 #define KBD_INTERFACE 0
43 #define KBD_ENDPOINT 1
44 #define KBD_SIZE 8
45 #define KBD_REPORT_KEYS (KBD_SIZE - 2)
46
47 /* secondary keyboard */
48 #ifdef NKRO_ENABLE
49 #define NKRO_INTERFACE 4
50 #define NKRO_ENDPOINT 5
51 #define NKRO_SIZE 16
52 #define NKRO_REPORT_KEYS (NKRO_SIZE - 1)
53 #endif
54
55 /* this defines report_keyboard_t and computes REPORT_SIZE defines */
56 #include "report.h"
57
58 /* extern report_keyboard_t keyboard_report_sent; */
59
60 /* keyboard IN request callback handler */
61 void kbd_in_cb(USBDriver *usbp, usbep_t ep);
62
63 /* start-of-frame handler */
64 void kbd_sof_cb(USBDriver *usbp);
65
66 #ifdef NKRO_ENABLE
67 /* nkro IN callback hander */
68 void nkro_in_cb(USBDriver *usbp, usbep_t ep);
69 #endif /* NKRO_ENABLE */
70
71 /* ------------
72 * Mouse header
73 * ------------
74 */
75
76 #ifdef MOUSE_ENABLE
77
78 #define MOUSE_INTERFACE 1
79 #define MOUSE_ENDPOINT 2
80 #define MOUSE_SIZE 8
81
82 /* mouse IN request callback handler */
83 void mouse_in_cb(USBDriver *usbp, usbep_t ep);
84 #endif /* MOUSE_ENABLE */
85
86 /* ---------------
87 * Extrakey header
88 * ---------------
89 */
90
91 #ifdef EXTRAKEY_ENABLE
92
93 #define EXTRA_INTERFACE 3
94 #define EXTRA_ENDPOINT 4
95 #define EXTRA_SIZE 8
96
97 /* extrakey IN request callback handler */
98 void extra_in_cb(USBDriver *usbp, usbep_t ep);
99
100 /* extra report structure */
101 typedef struct {
102 uint8_t report_id;
103 uint16_t usage;
104 } __attribute__ ((packed)) report_extra_t;
105 #endif /* EXTRAKEY_ENABLE */
106
107 /* --------------
108 * Console header
109 * --------------
110 */
111
112 #ifdef CONSOLE_ENABLE
113
114 #define CONSOLE_INTERFACE 2
115 #define CONSOLE_ENDPOINT 3
116 #define CONSOLE_SIZE 16
117
118 /* Number of IN reports that can be stored inside the output queue */
119 #define CONSOLE_QUEUE_CAPACITY 2
120 #define CONSOLE_QUEUE_BUFFER_SIZE (CONSOLE_QUEUE_CAPACITY * CONSOLE_SIZE)
121
122 /* Console flush time */
123 #define CONSOLE_FLUSH_MS 50
124
125 /* Putchar over the USB console */
126 int8_t sendchar(uint8_t c);
127 /* wrapper for printf lib */
128
129 /* Flush output (send everything immediately) */
130 void console_flush_output(void);
131
132 /* console IN request callback handler */
133 void console_in_cb(USBDriver *usbp, usbep_t ep);
134 #endif /* CONSOLE_ENABLE */
135
136 void sendchar_pf(void *p, char c);
137
138 /* ---------------------------
139 * Host driver functions (TMK)
140 * ---------------------------
141 */
142
143 uint8_t keyboard_leds(void);
144 void send_keyboard(report_keyboard_t *report);
145 void send_mouse(report_mouse_t *report);
146 void send_system(uint16_t data);
147 void send_consumer(uint16_t data);
148
149 #endif /* _USB_MAIN_H_ */
Imprint / Impressum