]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/protocol/chibios/usb_main.h
Send usb wakeup through ChibiOS
[qmk_firmware.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 // 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 /* ---------------
40  * Keyboard header
41  * ---------------
42  */
43
44 /* main keyboard (6kro) */
45 #define KBD_INTERFACE   0
46 #define KBD_ENDPOINT    1
47 #define KBD_EPSIZE      8
48 #define KBD_REPORT_KEYS (KBD_EPSIZE - 2)
49
50 /* secondary keyboard */
51 #ifdef NKRO_ENABLE
52 #define NKRO_INTERFACE    4
53 #define NKRO_ENDPOINT     5
54 #define NKRO_EPSIZE       16
55 #define NKRO_REPORT_KEYS  (NKRO_EPSIZE - 1)
56 #endif
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_EPSIZE            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_EPSIZE            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_EPSIZE         16
117
118 /* Number of IN reports that can be stored inside the output queue */
119 #define CONSOLE_QUEUE_CAPACITY 4
120
121 /* Console flush time */
122 #define CONSOLE_FLUSH_MS 50
123
124 /* Putchar over the USB console */
125 int8_t sendchar(uint8_t c);
126
127 /* Flush output (send everything immediately) */
128 void console_flush_output(void);
129
130 /* console IN request callback handler */
131 void console_in_cb(USBDriver *usbp, usbep_t ep);
132 #endif /* CONSOLE_ENABLE */
133
134 void sendchar_pf(void *p, char c);
135
136 #endif /* _USB_MAIN_H_ */