diff options
Diffstat (limited to 'tmk_core/protocol/vusb/main.c')
| -rw-r--r-- | tmk_core/protocol/vusb/main.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c index 610638e7d..7dc16926d 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/main.c | |||
| @@ -21,12 +21,23 @@ | |||
| 21 | #include "uart.h" | 21 | #include "uart.h" |
| 22 | #include "debug.h" | 22 | #include "debug.h" |
| 23 | #include "suspend.h" | 23 | #include "suspend.h" |
| 24 | #include "wait.h" | ||
| 25 | #include "sendchar.h" | ||
| 26 | |||
| 24 | #ifdef SLEEP_LED_ENABLE | 27 | #ifdef SLEEP_LED_ENABLE |
| 25 | # include "sleep_led.h" | 28 | # include "sleep_led.h" |
| 26 | #endif | 29 | #endif |
| 27 | 30 | ||
| 28 | #define UART_BAUD_RATE 115200 | 31 | #define UART_BAUD_RATE 115200 |
| 29 | 32 | ||
| 33 | #ifdef CONSOLE_ENABLE | ||
| 34 | void console_task(void); | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #ifdef RAW_ENABLE | ||
| 38 | void raw_hid_task(void); | ||
| 39 | #endif | ||
| 40 | |||
| 30 | /* This is from main.c of USBaspLoader */ | 41 | /* This is from main.c of USBaspLoader */ |
| 31 | static void initForUsbConnectivity(void) { | 42 | static void initForUsbConnectivity(void) { |
| 32 | uint8_t i = 0; | 43 | uint8_t i = 0; |
| @@ -39,10 +50,9 @@ static void initForUsbConnectivity(void) { | |||
| 39 | _delay_ms(1); | 50 | _delay_ms(1); |
| 40 | } | 51 | } |
| 41 | usbDeviceConnect(); | 52 | usbDeviceConnect(); |
| 42 | sei(); | ||
| 43 | } | 53 | } |
| 44 | 54 | ||
| 45 | void usb_remote_wakeup(void) { | 55 | static void usb_remote_wakeup(void) { |
| 46 | cli(); | 56 | cli(); |
| 47 | 57 | ||
| 48 | int8_t ddr_orig = USBDDR; | 58 | int8_t ddr_orig = USBDDR; |
| @@ -59,6 +69,23 @@ void usb_remote_wakeup(void) { | |||
| 59 | sei(); | 69 | sei(); |
| 60 | } | 70 | } |
| 61 | 71 | ||
| 72 | /** \brief Setup USB | ||
| 73 | * | ||
| 74 | * FIXME: Needs doc | ||
| 75 | */ | ||
| 76 | static void setup_usb(void) { | ||
| 77 | // debug("initForUsbConnectivity()\n"); | ||
| 78 | initForUsbConnectivity(); | ||
| 79 | |||
| 80 | // for Console_Task | ||
| 81 | print_set_sendchar(sendchar); | ||
| 82 | } | ||
| 83 | |||
| 84 | /** \brief Main | ||
| 85 | * | ||
| 86 | * FIXME: Needs doc | ||
| 87 | */ | ||
| 88 | int main(void) __attribute__((weak)); | ||
| 62 | int main(void) { | 89 | int main(void) { |
| 63 | bool suspended = false; | 90 | bool suspended = false; |
| 64 | #if USB_COUNT_SOF | 91 | #if USB_COUNT_SOF |
| @@ -76,8 +103,10 @@ int main(void) { | |||
| 76 | keyboard_setup(); | 103 | keyboard_setup(); |
| 77 | 104 | ||
| 78 | host_set_driver(vusb_driver()); | 105 | host_set_driver(vusb_driver()); |
| 79 | debug("initForUsbConnectivity()\n"); | 106 | setup_usb(); |
| 80 | initForUsbConnectivity(); | 107 | sei(); |
| 108 | |||
| 109 | wait_ms(50); | ||
| 81 | 110 | ||
| 82 | keyboard_init(); | 111 | keyboard_init(); |
| 83 | #ifdef SLEEP_LED_ENABLE | 112 | #ifdef SLEEP_LED_ENABLE |
| @@ -120,12 +149,13 @@ int main(void) { | |||
| 120 | if (!suspended) { | 149 | if (!suspended) { |
| 121 | usbPoll(); | 150 | usbPoll(); |
| 122 | 151 | ||
| 123 | // TODO: configuration process is incosistent. it sometime fails. | 152 | // TODO: configuration process is inconsistent. it sometime fails. |
| 124 | // To prevent failing to configure NOT scan keyboard during configuration | 153 | // To prevent failing to configure NOT scan keyboard during configuration |
| 125 | if (usbConfiguration && usbInterruptIsReady()) { | 154 | if (usbConfiguration && usbInterruptIsReady()) { |
| 126 | keyboard_task(); | 155 | keyboard_task(); |
| 127 | } | 156 | } |
| 128 | vusb_transfer_keyboard(); | 157 | vusb_transfer_keyboard(); |
| 158 | |||
| 129 | #ifdef RAW_ENABLE | 159 | #ifdef RAW_ENABLE |
| 130 | usbPoll(); | 160 | usbPoll(); |
| 131 | 161 | ||
| @@ -133,6 +163,13 @@ int main(void) { | |||
| 133 | raw_hid_task(); | 163 | raw_hid_task(); |
| 134 | } | 164 | } |
| 135 | #endif | 165 | #endif |
| 166 | #ifdef CONSOLE_ENABLE | ||
| 167 | usbPoll(); | ||
| 168 | |||
| 169 | if (usbConfiguration && usbInterruptIsReady3()) { | ||
| 170 | console_task(); | ||
| 171 | } | ||
| 172 | #endif | ||
| 136 | } else if (suspend_wakeup_condition()) { | 173 | } else if (suspend_wakeup_condition()) { |
| 137 | usb_remote_wakeup(); | 174 | usb_remote_wakeup(); |
| 138 | } | 175 | } |
