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"
40 /* -------------------------
41 * TMK host driver defs
42 * -------------------------
46 uint8_t keyboard_leds(void);
47 void send_keyboard(report_keyboard_t *report);
48 void send_mouse(report_mouse_t *report);
49 void send_system(uint16_t data);
50 void send_consumer(uint16_t data);
53 host_driver_t chibios_driver = {
63 * Amber LED blinker thread, times are in milliseconds.
65 /* set this variable to non-zero anywhere to blink once */
66 // uint8_t blinkLed = 0;
67 // static THD_WORKING_AREA(waBlinkerThread, 128);
68 // static THD_FUNCTION(blinkerThread, arg) {
70 // chRegSetThreadName("blinkOrange");
74 // palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
75 // chThdSleepMilliseconds(100);
76 // palClearPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
78 // chThdSleepMilliseconds(100);
92 // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL);
95 init_usb_driver(&USB_DRIVER);
98 init_printf(NULL,sendchar_pf);
100 /* Wait until the USB is active */
101 while(USB_DRIVER.state != USB_ACTIVE)
102 chThdSleepMilliseconds(50);
104 print("USB configured.\n");
106 /* init TMK modules */
108 host_set_driver(&chibios_driver);
110 #ifdef SLEEP_LED_ENABLE
114 print("Keyboard start.\n");
119 if(USB_DRIVER.state == USB_SUSPENDED) {
121 while(USB_DRIVER.state == USB_SUSPENDED) {
122 /* Do this in the suspended state */
123 suspend_power_down(); // on AVR this deep sleeps for 15ms
125 if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
126 send_remote_wakeup(&USB_DRIVER);
130 // variables has been already cleared by the wakeup hook
131 send_keyboard_report();
132 #ifdef MOUSEKEY_ENABLE
134 #endif /* MOUSEKEY_ENABLE */