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