summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2024-03-14 10:45:12 +0000
committerGitHub <noreply@github.com>2024-03-14 21:45:12 +1100
commit63dd131d812be4b8d4894fc20ca9968e25996b07 (patch)
treeb51902172408e9325aef625034cbf8f6a92e55e0
parent4bbfecae90e994b4a7d9bf5db06a995fb05d6ab2 (diff)
Refactor vusb to protocol use pre/post task (#14944)
-rw-r--r--quantum/main.c35
-rw-r--r--tmk_core/protocol/chibios/chibios.c13
-rw-r--r--tmk_core/protocol/lufa/lufa.c6
-rw-r--r--tmk_core/protocol/vusb/protocol.c30
-rw-r--r--tmk_core/protocol/vusb/vusb.c10
5 files changed, 34 insertions, 60 deletions
diff --git a/quantum/main.c b/quantum/main.c
index 3b101c522c..3159c55850 100644
--- a/quantum/main.c
+++ b/quantum/main.c
@@ -25,22 +25,9 @@ void protocol_pre_task(void);
25void protocol_post_task(void); 25void protocol_post_task(void);
26 26
27// Bodge as refactoring this area sucks.... 27// Bodge as refactoring this area sucks....
28void protocol_init(void) __attribute__((weak)); 28void protocol_keyboard_task(void) __attribute__((weak));
29void protocol_init(void) { 29void protocol_keyboard_task(void) {
30 protocol_pre_init();
31
32 keyboard_init();
33
34 protocol_post_init();
35}
36
37void protocol_task(void) __attribute__((weak));
38void protocol_task(void) {
39 protocol_pre_task();
40
41 keyboard_task(); 30 keyboard_task();
42
43 protocol_post_task();
44} 31}
45 32
46/** \brief Main 33/** \brief Main
@@ -53,11 +40,25 @@ int main(void) {
53 protocol_setup(); 40 protocol_setup();
54 keyboard_setup(); 41 keyboard_setup();
55 42
56 protocol_init(); 43 protocol_pre_init();
44 keyboard_init();
45 protocol_post_init();
57 46
58 /* Main loop */ 47 /* Main loop */
59 while (true) { 48 while (true) {
60 protocol_task(); 49 protocol_pre_task();
50 protocol_keyboard_task();
51 protocol_post_task();
52
53#ifdef RAW_ENABLE
54 void raw_hid_task(void);
55 raw_hid_task();
56#endif
57
58#ifdef CONSOLE_ENABLE
59 void console_task(void);
60 console_task();
61#endif
61 62
62#ifdef QUANTUM_PAINTER_ENABLE 63#ifdef QUANTUM_PAINTER_ENABLE
63 // Run Quantum Painter task 64 // Run Quantum Painter task
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c
index 76a37ae538..360e6b4b04 100644
--- a/tmk_core/protocol/chibios/chibios.c
+++ b/tmk_core/protocol/chibios/chibios.c
@@ -70,13 +70,6 @@ host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_nkro, send_mo
70void virtser_task(void); 70void virtser_task(void);
71#endif 71#endif
72 72
73#ifdef RAW_ENABLE
74void raw_hid_task(void);
75#endif
76
77#ifdef CONSOLE_ENABLE
78void console_task(void);
79#endif
80#ifdef MIDI_ENABLE 73#ifdef MIDI_ENABLE
81void midi_ep_task(void); 74void midi_ep_task(void);
82#endif 75#endif
@@ -209,17 +202,11 @@ void protocol_pre_task(void) {
209} 202}
210 203
211void protocol_post_task(void) { 204void protocol_post_task(void) {
212#ifdef CONSOLE_ENABLE
213 console_task();
214#endif
215#ifdef MIDI_ENABLE 205#ifdef MIDI_ENABLE
216 midi_ep_task(); 206 midi_ep_task();
217#endif 207#endif
218#ifdef VIRTSER_ENABLE 208#ifdef VIRTSER_ENABLE
219 virtser_task(); 209 virtser_task();
220#endif 210#endif
221#ifdef RAW_ENABLE
222 raw_hid_task();
223#endif
224 usb_idle_task(); 211 usb_idle_task();
225} 212}
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 22cc0db8ce..d6f0c69b6b 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -151,7 +151,7 @@ __attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) {
151 * 151 *
152 * FIXME: Needs doc 152 * FIXME: Needs doc
153 */ 153 */
154static void raw_hid_task(void) { 154void raw_hid_task(void) {
155 // Create a temporary buffer to hold the read in data from the host 155 // Create a temporary buffer to hold the read in data from the host
156 uint8_t data[RAW_EPSIZE]; 156 uint8_t data[RAW_EPSIZE];
157 bool data_read = false; 157 bool data_read = false;
@@ -865,10 +865,6 @@ void protocol_post_task(void) {
865 CDC_Device_USBTask(&cdc_device); 865 CDC_Device_USBTask(&cdc_device);
866#endif 866#endif
867 867
868#ifdef RAW_ENABLE
869 raw_hid_task();
870#endif
871
872#if !defined(INTERRUPT_CONTROL_ENDPOINT) 868#if !defined(INTERRUPT_CONTROL_ENDPOINT)
873 USB_USBTask(); 869 USB_USBTask();
874#endif 870#endif
diff --git a/tmk_core/protocol/vusb/protocol.c b/tmk_core/protocol/vusb/protocol.c
index 6178d48ef2..41ccf451fd 100644
--- a/tmk_core/protocol/vusb/protocol.c
+++ b/tmk_core/protocol/vusb/protocol.c
@@ -31,14 +31,6 @@
31# include "sleep_led.h" 31# include "sleep_led.h"
32#endif 32#endif
33 33
34#ifdef CONSOLE_ENABLE
35void console_task(void);
36#endif
37
38#ifdef RAW_ENABLE
39void raw_hid_task(void);
40#endif
41
42/* This is from main.c of USBaspLoader */ 34/* This is from main.c of USBaspLoader */
43static void initForUsbConnectivity(void) { 35static void initForUsbConnectivity(void) {
44 uint8_t i = 0; 36 uint8_t i = 0;
@@ -136,7 +128,7 @@ static inline bool should_do_suspend(void) {
136 return vusb_suspended; 128 return vusb_suspended;
137} 129}
138 130
139void protocol_task(void) { 131void protocol_pre_task(void) {
140#if !defined(NO_USB_STARTUP_CHECK) 132#if !defined(NO_USB_STARTUP_CHECK)
141 if (should_do_suspend()) { 133 if (should_do_suspend()) {
142 dprintln("suspending keyboard"); 134 dprintln("suspending keyboard");
@@ -159,7 +151,9 @@ void protocol_task(void) {
159 vusb_wakeup(); 151 vusb_wakeup();
160 } 152 }
161#endif 153#endif
154}
162 155
156void protocol_keyboard_task(void) {
163 usbPoll(); 157 usbPoll();
164 158
165 // TODO: configuration process is inconsistent. it sometime fails. 159 // TODO: configuration process is inconsistent. it sometime fails.
@@ -167,20 +161,8 @@ void protocol_task(void) {
167 if (usbConfiguration && usbInterruptIsReady()) { 161 if (usbConfiguration && usbInterruptIsReady()) {
168 keyboard_task(); 162 keyboard_task();
169 } 163 }
164}
170 165
171#ifdef RAW_ENABLE 166void protocol_post_task(void) {
172 usbPoll(); 167 // do nothing
173
174 if (usbConfiguration && usbInterruptIsReady4()) {
175 raw_hid_task();
176 }
177#endif
178
179#ifdef CONSOLE_ENABLE
180 usbPoll();
181
182 if (usbConfiguration && usbInterruptIsReady3()) {
183 console_task();
184 }
185#endif
186} 168}
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index cfeeed3712..c8ab494253 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -162,6 +162,12 @@ __attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) {
162} 162}
163 163
164void raw_hid_task(void) { 164void raw_hid_task(void) {
165 usbPoll();
166
167 if (!usbConfiguration || !usbInterruptIsReady4()) {
168 return;
169 }
170
165 if (raw_output_received_bytes == RAW_BUFFER_SIZE) { 171 if (raw_output_received_bytes == RAW_BUFFER_SIZE) {
166 raw_hid_receive(raw_output_buffer, RAW_BUFFER_SIZE); 172 raw_hid_receive(raw_output_buffer, RAW_BUFFER_SIZE);
167 raw_output_received_bytes = 0; 173 raw_output_received_bytes = 0;
@@ -182,7 +188,9 @@ int8_t sendchar(uint8_t c) {
182} 188}
183 189
184void console_task(void) { 190void console_task(void) {
185 if (!usbConfiguration) { 191 usbPoll();
192
193 if (!usbConfiguration || !usbInterruptIsReady3()) {
186 return; 194 return;
187 } 195 }
188 196