2 * (c) 2015 flabberast <s3+flabbergast@sdfeu.org>
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
14 * Since some GPL'd code is used, this work is licensed under
26 #include "host_driver.h"
29 #include "action_util.h"
35 #include "rgblight_reconfig.h"
37 #if (defined(RGB_MIDI) || defined(RGBLIGHT_ANIMATIONS)) && defined(RGBLIGHT_ENABLE)
38 # include "rgblight.h"
40 #ifdef SLEEP_LED_ENABLE
41 # include "sleep_led.h"
43 #ifdef SERIAL_LINK_ENABLE
44 # include "serial_link/system/serial_link.h"
46 #ifdef VISUALIZER_ENABLE
47 # include "visualizer/visualizer.h"
50 # include "qmk_midi.h"
52 #ifdef STM32_EEPROM_ENABLE
53 # include "eeprom_stm32.h"
58 /* -------------------------
59 * TMK host driver defs
60 * -------------------------
64 uint8_t keyboard_leds(void);
65 void send_keyboard(report_keyboard_t
*report
);
66 void send_mouse(report_mouse_t
*report
);
67 void send_system(uint16_t data
);
68 void send_consumer(uint16_t data
);
71 host_driver_t chibios_driver
= {keyboard_leds
, send_keyboard
, send_mouse
, send_system
, send_consumer
};
74 void virtser_task(void);
78 void raw_hid_task(void);
82 void console_task(void);
86 * Amber LED blinker thread, times are in milliseconds.
88 /* set this variable to non-zero anywhere to blink once */
89 // static THD_WORKING_AREA(waThread1, 128);
90 // static THD_FUNCTION(Thread1, arg) {
93 // chRegSetThreadName("blinker");
97 // time = USB_DRIVER.state == USB_ACTIVE ? 250 : 500;
98 // palClearLine(LINE_CAPS_LOCK);
99 // chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
100 // palSetLine(LINE_CAPS_LOCK);
101 // chSysPolledDelayX(MS2RTC(STM32_HCLK, time));
108 /* ChibiOS/RT init */
112 #ifdef STM32_EEPROM_ENABLE
117 // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
122 init_usb_driver(&USB_DRIVER
);
125 init_printf(NULL
, sendchar_pf
);
131 #ifdef SERIAL_LINK_ENABLE
135 #ifdef VISUALIZER_ENABLE
139 host_driver_t
*driver
= NULL
;
141 /* Wait until the USB or serial link is active */
143 #if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE)
144 if (USB_DRIVER
.state
== USB_ACTIVE
) {
145 driver
= &chibios_driver
;
149 driver
= &chibios_driver
;
152 #ifdef SERIAL_LINK_ENABLE
153 if (is_serial_link_connected()) {
154 driver
= get_serial_link_driver();
157 serial_link_update();
162 /* Do need to wait here!
163 * Otherwise the next print might start a transfer on console EP
164 * before the USB is completely ready, which sometimes causes
169 print("USB configured.\n");
171 /* init TMK modules */
173 host_set_driver(driver
);
175 #ifdef SLEEP_LED_ENABLE
179 print("Keyboard start.\n");
183 #if !defined(NO_USB_STARTUP_CHECK)
184 if (USB_DRIVER
.state
== USB_SUSPENDED
) {
186 # ifdef VISUALIZER_ENABLE
187 visualizer_suspend();
189 while (USB_DRIVER
.state
== USB_SUSPENDED
) {
190 /* Do this in the suspended state */
191 # ifdef SERIAL_LINK_ENABLE
192 serial_link_update();
194 suspend_power_down(); // on AVR this deep sleeps for 15ms
196 if (suspend_wakeup_condition()) {
197 usbWakeupHost(&USB_DRIVER
);
201 // variables has been already cleared by the wakeup hook
202 send_keyboard_report();
203 # ifdef MOUSEKEY_ENABLE
205 # endif /* MOUSEKEY_ENABLE */
207 # ifdef VISUALIZER_ENABLE
214 #ifdef CONSOLE_ENABLE
217 #ifdef VIRTSER_ENABLE
223 #if defined(RGBLIGHT_ANIMATIONS) && defined(RGBLIGHT_ENABLE)