]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/chibios/main.c
Implement jump-to-bootloader.
[max/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 host_driver_t chibios_driver = {
44   keyboard_leds,
45   send_keyboard,
46   send_mouse,
47   send_system,
48   send_consumer
49 };
50
51 /* Main thread
52  */
53 int main(void) {
54   /* ChibiOS/RT init */
55   halInit();
56   chSysInit();
57
58   palSetPad(GPIOC, GPIOC_LED_BLUE);
59   chThdSleepMilliseconds(400);
60   palClearPad(GPIOC, GPIOC_LED_BLUE);
61
62   /* Init USB */
63   init_usb_driver(&USB_DRIVER);
64
65   /* init printf */
66   init_printf(NULL,sendchar_pf);
67
68   /* Wait until the USB is active */
69   while(USB_DRIVER.state != USB_ACTIVE)
70     chThdSleepMilliseconds(50);
71
72   print("USB configured.\n");
73
74   /* init TMK modules */
75   keyboard_init();
76   host_set_driver(&chibios_driver);
77
78 #ifdef SLEEP_LED_ENABLE
79     sleep_led_init();
80 #endif
81
82   print("Keyboard start.\n");
83
84   /* Main loop */
85   while(true) {
86     /* TODO: check for suspended event */
87
88     keyboard_task();
89     chThdSleepMilliseconds(5);
90   }
91 }