From 96e2b13d1de227cdc2b918fb0292bd832d346a25 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 18 Aug 2021 00:11:07 +0100 Subject: Begin to carve out platform/protocol API - Single main loop (#13843) * Begin to carve out platform/protocol API * Fix up after rebase --- tmk_core/protocol/lufa/lufa.c | 64 ++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 34 deletions(-) (limited to 'tmk_core/protocol/lufa') diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 8ddb8b1c4b..e638dbc0fb 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1033,18 +1033,16 @@ static void setup_usb(void) { USB_Device_EnableSOFEvents(); } -/** \brief Main - * - * FIXME: Needs doc - */ -int main(void) __attribute__((weak)); -int main(void) { +void protocol_setup(void) { #ifdef MIDI_ENABLE setup_midi(); #endif setup_mcu(); keyboard_setup(); +} + +void protocol_init(void) { setup_usb(); sei(); @@ -1078,57 +1076,55 @@ int main(void) { #endif print("Keyboard start.\n"); - while (1) { +} + +void protocol_task(void) { #if !defined(NO_USB_STARTUP_CHECK) - if (USB_DeviceState == DEVICE_STATE_Suspended) { - print("[s]"); - while (USB_DeviceState == DEVICE_STATE_Suspended) { - suspend_power_down(); - if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { - USB_Device_SendRemoteWakeup(); - clear_keyboard(); + if (USB_DeviceState == DEVICE_STATE_Suspended) { + print("[s]"); + while (USB_DeviceState == DEVICE_STATE_Suspended) { + suspend_power_down(); + if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { + USB_Device_SendRemoteWakeup(); + clear_keyboard(); # if USB_SUSPEND_WAKEUP_DELAY > 0 - // Some hubs, kvm switches, and monitors do - // weird things, with USB device state bouncing - // around wildly on wakeup, yielding race - // conditions that can corrupt the keyboard state. - // - // Pause for a while to let things settle... - wait_ms(USB_SUSPEND_WAKEUP_DELAY); + // Some hubs, kvm switches, and monitors do + // weird things, with USB device state bouncing + // around wildly on wakeup, yielding race + // conditions that can corrupt the keyboard state. + // + // Pause for a while to let things settle... + wait_ms(USB_SUSPEND_WAKEUP_DELAY); # endif - } } - suspend_wakeup_init(); } + suspend_wakeup_init(); + } #endif - keyboard_task(); + keyboard_task(); #ifdef MIDI_ENABLE - MIDI_Device_USBTask(&USB_MIDI_Interface); + MIDI_Device_USBTask(&USB_MIDI_Interface); #endif #ifdef MODULE_ADAFRUIT_BLE - adafruit_ble_task(); + adafruit_ble_task(); #endif #ifdef VIRTSER_ENABLE - virtser_task(); - CDC_Device_USBTask(&cdc_device); + virtser_task(); + CDC_Device_USBTask(&cdc_device); #endif #ifdef RAW_ENABLE - raw_hid_task(); + raw_hid_task(); #endif #if !defined(INTERRUPT_CONTROL_ENDPOINT) - USB_USBTask(); + USB_USBTask(); #endif - - // Run housekeeping - housekeeping_task(); - } } uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint16_t wIndex, const void **const DescriptorAddress) { return get_usb_descriptor(wValue, wIndex, DescriptorAddress); } -- cgit v1.2.3