diff options
| author | Joel Challis <git@zvecr.com> | 2024-03-14 10:45:12 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-14 21:45:12 +1100 |
| commit | 63dd131d812be4b8d4894fc20ca9968e25996b07 (patch) | |
| tree | b51902172408e9325aef625034cbf8f6a92e55e0 /tmk_core/protocol | |
| parent | 4bbfecae90e994b4a7d9bf5db06a995fb05d6ab2 (diff) | |
Refactor vusb to protocol use pre/post task (#14944)
Diffstat (limited to 'tmk_core/protocol')
| -rw-r--r-- | tmk_core/protocol/chibios/chibios.c | 13 | ||||
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 6 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/protocol.c | 30 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 10 |
4 files changed, 16 insertions, 43 deletions
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 | |||
| 70 | void virtser_task(void); | 70 | void virtser_task(void); |
| 71 | #endif | 71 | #endif |
| 72 | 72 | ||
| 73 | #ifdef RAW_ENABLE | ||
| 74 | void raw_hid_task(void); | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #ifdef CONSOLE_ENABLE | ||
| 78 | void console_task(void); | ||
| 79 | #endif | ||
| 80 | #ifdef MIDI_ENABLE | 73 | #ifdef MIDI_ENABLE |
| 81 | void midi_ep_task(void); | 74 | void midi_ep_task(void); |
| 82 | #endif | 75 | #endif |
| @@ -209,17 +202,11 @@ void protocol_pre_task(void) { | |||
| 209 | } | 202 | } |
| 210 | 203 | ||
| 211 | void protocol_post_task(void) { | 204 | void 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 | */ |
| 154 | static void raw_hid_task(void) { | 154 | void 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 | ||
| 35 | void console_task(void); | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifdef RAW_ENABLE | ||
| 39 | void raw_hid_task(void); | ||
| 40 | #endif | ||
| 41 | |||
| 42 | /* This is from main.c of USBaspLoader */ | 34 | /* This is from main.c of USBaspLoader */ |
| 43 | static void initForUsbConnectivity(void) { | 35 | static 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 | ||
| 139 | void protocol_task(void) { | 131 | void 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 | ||
| 156 | void 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 | 166 | void 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 | ||
| 164 | void raw_hid_task(void) { | 164 | void 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 | ||
| 184 | void console_task(void) { | 190 | void console_task(void) { |
| 185 | if (!usbConfiguration) { | 191 | usbPoll(); |
| 192 | |||
| 193 | if (!usbConfiguration || !usbInterruptIsReady3()) { | ||
| 186 | return; | 194 | return; |
| 187 | } | 195 | } |
| 188 | 196 | ||
