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"
34 #ifdef SLEEP_LED_ENABLE
35 #include "sleep_led.h"
41 /* -------------------------
42 * TMK host driver defs
43 * -------------------------
47 uint8_t keyboard_leds(void);
48 void send_keyboard(report_keyboard_t *report);
49 void send_mouse(report_mouse_t *report);
50 void send_system(uint16_t data);
51 void send_consumer(uint16_t data);
54 host_driver_t chibios_driver = {
62 /* Default hooks definitions. */
64 void hook_early_init(void) {}
67 void hook_late_init(void) {}
70 void hook_usb_suspend_loop(void) {
71 /* Do this in the suspended state */
72 suspend_power_down(); // on AVR this deep sleeps for 15ms
74 if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
75 send_remote_wakeup(&USB_DRIVER);
80 * Amber LED blinker thread, times are in milliseconds.
82 /* set this variable to non-zero anywhere to blink once */
83 // uint8_t blinkLed = 0;
84 // static THD_WORKING_AREA(waBlinkerThread, 128);
85 // static THD_FUNCTION(blinkerThread, arg) {
87 // chRegSetThreadName("blinkOrange");
91 // palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
92 // chThdSleepMilliseconds(100);
93 // palClearPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
95 // chThdSleepMilliseconds(100);
104 /* ChibiOS/RT init */
109 // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL);
114 init_usb_driver(&USB_DRIVER);
117 init_printf(NULL,sendchar_pf);
119 /* Wait until the USB is active */
120 while(USB_DRIVER.state != USB_ACTIVE)
121 chThdSleepMilliseconds(50);
123 /* Do need to wait here!
124 * Otherwise the next print might start a transfer on console EP
125 * before the USB is completely ready, which sometimes causes
128 chThdSleepMilliseconds(50);
130 print("USB configured.\n");
132 /* init TMK modules */
134 host_set_driver(&chibios_driver);
136 #ifdef SLEEP_LED_ENABLE
140 print("Keyboard start.\n");
147 if(USB_DRIVER.state == USB_SUSPENDED) {
149 while(USB_DRIVER.state == USB_SUSPENDED) {
150 hook_usb_suspend_loop();
153 // variables have been already cleared
154 send_keyboard_report();
155 #ifdef MOUSEKEY_ENABLE
157 #endif /* MOUSEKEY_ENABLE */