aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/chibios/main.c
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tmk_core/protocol/chibios/main.c
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'tmk_core/protocol/chibios/main.c')
-rw-r--r--tmk_core/protocol/chibios/main.c180
1 files changed, 85 insertions, 95 deletions
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
index 8de55bfe3..de2b493b8 100644
--- a/tmk_core/protocol/chibios/main.c
+++ b/tmk_core/protocol/chibios/main.c
@@ -33,19 +33,19 @@
33#include "debug.h" 33#include "debug.h"
34#include "printf.h" 34#include "printf.h"
35#ifdef SLEEP_LED_ENABLE 35#ifdef SLEEP_LED_ENABLE
36#include "sleep_led.h" 36# include "sleep_led.h"
37#endif 37#endif
38#ifdef SERIAL_LINK_ENABLE 38#ifdef SERIAL_LINK_ENABLE
39#include "serial_link/system/serial_link.h" 39# include "serial_link/system/serial_link.h"
40#endif 40#endif
41#ifdef VISUALIZER_ENABLE 41#ifdef VISUALIZER_ENABLE
42#include "visualizer/visualizer.h" 42# include "visualizer/visualizer.h"
43#endif 43#endif
44#ifdef MIDI_ENABLE 44#ifdef MIDI_ENABLE
45#include "qmk_midi.h" 45# include "qmk_midi.h"
46#endif 46#endif
47#ifdef STM32_EEPROM_ENABLE 47#ifdef STM32_EEPROM_ENABLE
48#include "eeprom_stm32.h" 48# include "eeprom_stm32.h"
49#endif 49#endif
50#include "suspend.h" 50#include "suspend.h"
51#include "wait.h" 51#include "wait.h"
@@ -57,19 +57,13 @@
57 57
58/* declarations */ 58/* declarations */
59uint8_t keyboard_leds(void); 59uint8_t keyboard_leds(void);
60void send_keyboard(report_keyboard_t *report); 60void send_keyboard(report_keyboard_t *report);
61void send_mouse(report_mouse_t *report); 61void send_mouse(report_mouse_t *report);
62void send_system(uint16_t data); 62void send_system(uint16_t data);
63void send_consumer(uint16_t data); 63void send_consumer(uint16_t data);
64 64
65/* host struct */ 65/* host struct */
66host_driver_t chibios_driver = { 66host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
67 keyboard_leds,
68 send_keyboard,
69 send_mouse,
70 send_system,
71 send_consumer
72};
73 67
74#ifdef VIRTSER_ENABLE 68#ifdef VIRTSER_ENABLE
75void virtser_task(void); 69void virtser_task(void);
@@ -103,127 +97,123 @@ void console_task(void);
103// } 97// }
104// } 98// }
105 99
106
107
108/* Main thread 100/* Main thread
109 */ 101 */
110int main(void) { 102int main(void) {
111 /* ChibiOS/RT init */ 103 /* ChibiOS/RT init */
112 halInit(); 104 halInit();
113 chSysInit(); 105 chSysInit();
114 106
115#ifdef STM32_EEPROM_ENABLE 107#ifdef STM32_EEPROM_ENABLE
116 EEPROM_Init(); 108 EEPROM_Init();
117#endif 109#endif
118 110
119 // TESTING 111 // TESTING
120 // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); 112 // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
121 113
122 keyboard_setup(); 114 keyboard_setup();
123 115
124 /* Init USB */ 116 /* Init USB */
125 init_usb_driver(&USB_DRIVER); 117 init_usb_driver(&USB_DRIVER);
126 118
127 /* init printf */ 119 /* init printf */
128 init_printf(NULL,sendchar_pf); 120 init_printf(NULL, sendchar_pf);
129 121
130#ifdef MIDI_ENABLE 122#ifdef MIDI_ENABLE
131 setup_midi(); 123 setup_midi();
132#endif 124#endif
133 125
134#ifdef SERIAL_LINK_ENABLE 126#ifdef SERIAL_LINK_ENABLE
135 init_serial_link(); 127 init_serial_link();
136#endif 128#endif
137 129
138#ifdef VISUALIZER_ENABLE 130#ifdef VISUALIZER_ENABLE
139 visualizer_init(); 131 visualizer_init();
140#endif 132#endif
141 133
134 host_driver_t *driver = NULL;
142 135
143 host_driver_t* driver = NULL; 136 /* Wait until the USB or serial link is active */
144 137 while (true) {
145 /* Wait until the USB or serial link is active */
146 while (true) {
147#if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE) 138#if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE)
148 if(USB_DRIVER.state == USB_ACTIVE) { 139 if (USB_DRIVER.state == USB_ACTIVE) {
149 driver = &chibios_driver; 140 driver = &chibios_driver;
150 break; 141 break;
151 } 142 }
152#else 143#else
153 driver = &chibios_driver; 144 driver = &chibios_driver;
154 break; 145 break;
155#endif 146#endif
156#ifdef SERIAL_LINK_ENABLE 147#ifdef SERIAL_LINK_ENABLE
157 if(is_serial_link_connected()) { 148 if (is_serial_link_connected()) {
158 driver = get_serial_link_driver(); 149 driver = get_serial_link_driver();
159 break; 150 break;
160 } 151 }
161 serial_link_update(); 152 serial_link_update();
162#endif 153#endif
163 wait_ms(50); 154 wait_ms(50);
164 } 155 }
165 156
166 /* Do need to wait here! 157 /* Do need to wait here!
167 * Otherwise the next print might start a transfer on console EP 158 * Otherwise the next print might start a transfer on console EP
168 * before the USB is completely ready, which sometimes causes 159 * before the USB is completely ready, which sometimes causes
169 * HardFaults. 160 * HardFaults.
170 */ 161 */
171 wait_ms(50); 162 wait_ms(50);
172 163
173 print("USB configured.\n"); 164 print("USB configured.\n");
174 165
175 /* init TMK modules */ 166 /* init TMK modules */
176 keyboard_init(); 167 keyboard_init();
177 host_set_driver(driver); 168 host_set_driver(driver);
178 169
179#ifdef SLEEP_LED_ENABLE 170#ifdef SLEEP_LED_ENABLE
180 sleep_led_init(); 171 sleep_led_init();
181#endif 172#endif
182 173
183 print("Keyboard start.\n"); 174 print("Keyboard start.\n");
184
185 /* Main loop */
186 while(true) {
187 175
176 /* Main loop */
177 while (true) {
188#if !defined(NO_USB_STARTUP_CHECK) 178#if !defined(NO_USB_STARTUP_CHECK)
189 if(USB_DRIVER.state == USB_SUSPENDED) { 179 if (USB_DRIVER.state == USB_SUSPENDED) {
190 print("[s]"); 180 print("[s]");
191#ifdef VISUALIZER_ENABLE 181# ifdef VISUALIZER_ENABLE
192 visualizer_suspend(); 182 visualizer_suspend();
193#endif 183# endif
194 while(USB_DRIVER.state == USB_SUSPENDED) { 184 while (USB_DRIVER.state == USB_SUSPENDED) {
195 /* Do this in the suspended state */ 185 /* Do this in the suspended state */
196#ifdef SERIAL_LINK_ENABLE 186# ifdef SERIAL_LINK_ENABLE
197 serial_link_update(); 187 serial_link_update();
198#endif 188# endif
199 suspend_power_down(); // on AVR this deep sleeps for 15ms 189 suspend_power_down(); // on AVR this deep sleeps for 15ms
200 /* Remote wakeup */ 190 /* Remote wakeup */
201 if(suspend_wakeup_condition()) { 191 if (suspend_wakeup_condition()) {
202 usbWakeupHost(&USB_DRIVER); 192 usbWakeupHost(&USB_DRIVER);
193 }
194 }
195 /* Woken up */
196 // variables has been already cleared by the wakeup hook
197 send_keyboard_report();
198# ifdef MOUSEKEY_ENABLE
199 mousekey_send();
200# endif /* MOUSEKEY_ENABLE */
201
202# ifdef VISUALIZER_ENABLE
203 visualizer_resume();
204# endif
203 } 205 }
204 }
205 /* Woken up */
206 // variables has been already cleared by the wakeup hook
207 send_keyboard_report();
208#ifdef MOUSEKEY_ENABLE
209 mousekey_send();
210#endif /* MOUSEKEY_ENABLE */
211
212#ifdef VISUALIZER_ENABLE
213 visualizer_resume();
214#endif
215 }
216#endif 206#endif
217 207
218 keyboard_task(); 208 keyboard_task();
219#ifdef CONSOLE_ENABLE 209#ifdef CONSOLE_ENABLE
220 console_task(); 210 console_task();
221#endif 211#endif
222#ifdef VIRTSER_ENABLE 212#ifdef VIRTSER_ENABLE
223 virtser_task(); 213 virtser_task();
224#endif 214#endif
225#ifdef RAW_ENABLE 215#ifdef RAW_ENABLE
226 raw_hid_task(); 216 raw_hid_task();
227#endif 217#endif
228 } 218 }
229} 219}