]> git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/chibios/main.c
NKRO fixes.
[tmk_keyboard.git] / tmk_core / protocol / chibios / main.c
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 #include "ch.h"
19 #include "hal.h"
20
21 #include "usb_main.h"
22
23 /* TMK includes */
24 #include "report.h"
25 #include "host.h"
26 #include "host_driver.h"
27 #include "keyboard.h"
28 #include "action.h"
29 #include "led.h"
30 #include "sendchar.h"
31 #include "debug.h"
32 #ifdef SLEEP_LED_ENABLE
33 #include "sleep_led.h"
34 #endif
35 #include "suspend.h"
36
37
38 /* -------------------------
39 * TMK host driver defs
40 * -------------------------
41 */
42
43 /* declarations */
44 uint8_t keyboard_leds(void);
45 void send_keyboard(report_keyboard_t *report);
46 void send_mouse(report_mouse_t *report);
47 void send_system(uint16_t data);
48 void send_consumer(uint16_t data);
49
50 /* host struct */
51 host_driver_t chibios_driver = {
52 keyboard_leds,
53 send_keyboard,
54 send_mouse,
55 send_system,
56 send_consumer
57 };
58
59
60 /* TESTING
61 * Amber LED blinker thread, times are in milliseconds.
62 */
63 /* set this variable to non-zero anywhere to blink once */
64 // uint8_t blinkLed = 0;
65 // static THD_WORKING_AREA(waBlinkerThread, 128);
66 // static THD_FUNCTION(blinkerThread, arg) {
67 // (void)arg;
68 // chRegSetThreadName("blinkOrange");
69 // while(true) {
70 // if(blinkLed) {
71 // blinkLed = 0;
72 // palSetPad(GPIOC, GPIOC_LED_ORANGE);
73 // chThdSleepMilliseconds(100);
74 // palClearPad(GPIOC, GPIOC_LED_ORANGE);
75 // }
76 // chThdSleepMilliseconds(100);
77 // }
78 // }
79
80
81
82 /* Main thread
83 */
84 int main(void) {
85 /* ChibiOS/RT init */
86 halInit();
87 chSysInit();
88
89 palSetPad(GPIOC, GPIOC_LED_BLUE);
90 chThdSleepMilliseconds(400);
91 palClearPad(GPIOC, GPIOC_LED_BLUE);
92
93 // TESTING
94 // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL);
95
96 /* Init USB */
97 init_usb_driver(&USB_DRIVER);
98
99 /* init printf */
100 init_printf(NULL,sendchar_pf);
101
102 /* Wait until the USB is active */
103 while(USB_DRIVER.state != USB_ACTIVE)
104 chThdSleepMilliseconds(50);
105
106 print("USB configured.\n");
107
108 /* init TMK modules */
109 keyboard_init();
110 host_set_driver(&chibios_driver);
111
112 #ifdef SLEEP_LED_ENABLE
113 sleep_led_init();
114 #endif
115
116 print("Keyboard start.\n");
117
118 /* Main loop */
119 while(true) {
120 /* TODO: check for suspended event */
121
122 keyboard_task();
123 chThdSleepMilliseconds(5);
124 }
125 }
Imprint / Impressum