aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/vusb
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/vusb')
-rw-r--r--tmk_core/protocol/vusb/protocol.c (renamed from tmk_core/protocol/vusb/main.c)89
1 files changed, 44 insertions, 45 deletions
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/protocol.c
index 53926a749..89dc795b2 100644
--- a/tmk_core/protocol/vusb/main.c
+++ b/tmk_core/protocol/vusb/protocol.c
@@ -99,14 +99,11 @@ static void vusb_wakeup(void) {
99 */ 99 */
100static void setup_usb(void) { initForUsbConnectivity(); } 100static void setup_usb(void) { initForUsbConnectivity(); }
101 101
102/** \brief Main 102uint16_t sof_timer = 0;
103 * 103
104 * FIXME: Needs doc 104void protocol_setup(void) {
105 */
106int main(void) __attribute__((weak));
107int main(void) {
108#if USB_COUNT_SOF 105#if USB_COUNT_SOF
109 uint16_t sof_timer = timer_read(); 106 sof_timer = timer_read();
110#endif 107#endif
111 108
112#ifdef CLKPR 109#ifdef CLKPR
@@ -115,9 +112,14 @@ int main(void) {
115 clock_prescale_set(clock_div_1); 112 clock_prescale_set(clock_div_1);
116#endif 113#endif
117 keyboard_setup(); 114 keyboard_setup();
115}
116
117void protocol_init(void) {
118 setup_usb(); 118 setup_usb();
119 sei(); 119 sei();
120
120 keyboard_init(); 121 keyboard_init();
122
121 host_set_driver(vusb_driver()); 123 host_set_driver(vusb_driver());
122 124
123 wait_ms(50); 125 wait_ms(50);
@@ -125,55 +127,52 @@ int main(void) {
125#ifdef SLEEP_LED_ENABLE 127#ifdef SLEEP_LED_ENABLE
126 sleep_led_init(); 128 sleep_led_init();
127#endif 129#endif
130}
128 131
129 while (1) { 132void protocol_task(void) {
130#if USB_COUNT_SOF 133#if USB_COUNT_SOF
131 if (usbSofCount != 0) { 134 if (usbSofCount != 0) {
132 usbSofCount = 0; 135 usbSofCount = 0;
133 sof_timer = timer_read(); 136 sof_timer = timer_read();
134 if (vusb_suspended) {
135 vusb_wakeup();
136 }
137 } else {
138 // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
139 if (!vusb_suspended && timer_elapsed(sof_timer) > 5) {
140 vusb_suspend();
141 }
142 }
143#endif
144 if (vusb_suspended) { 137 if (vusb_suspended) {
138 vusb_wakeup();
139 }
140 } else {
141 // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
142 if (!vusb_suspended && timer_elapsed(sof_timer) > 5) {
145 vusb_suspend(); 143 vusb_suspend();
146 if (suspend_wakeup_condition()) { 144 }
147 vusb_send_remote_wakeup(); 145 }
148 } 146#endif
149 } else { 147 if (vusb_suspended) {
150 usbPoll(); 148 vusb_suspend();
151 149 if (suspend_wakeup_condition()) {
152 // TODO: configuration process is inconsistent. it sometime fails. 150 vusb_send_remote_wakeup();
153 // To prevent failing to configure NOT scan keyboard during configuration 151 }
154 if (usbConfiguration && usbInterruptIsReady()) { 152 } else {
155 keyboard_task(); 153 usbPoll();
156 } 154
157 vusb_transfer_keyboard(); 155 // TODO: configuration process is inconsistent. it sometime fails.
156 // To prevent failing to configure NOT scan keyboard during configuration
157 if (usbConfiguration && usbInterruptIsReady()) {
158 keyboard_task();
159 }
160 vusb_transfer_keyboard();
158 161
159#ifdef RAW_ENABLE 162#ifdef RAW_ENABLE
160 usbPoll(); 163 usbPoll();
161 164
162 if (usbConfiguration && usbInterruptIsReady3()) { 165 if (usbConfiguration && usbInterruptIsReady3()) {
163 raw_hid_task(); 166 raw_hid_task();
164 } 167 }
165#endif 168#endif
166 169
167#ifdef CONSOLE_ENABLE 170#ifdef CONSOLE_ENABLE
168 usbPoll(); 171 usbPoll();
169 172
170 if (usbConfiguration && usbInterruptIsReady3()) { 173 if (usbConfiguration && usbInterruptIsReady3()) {
171 console_task(); 174 console_task();
172 }
173#endif
174
175 // Run housekeeping
176 housekeeping_task();
177 } 175 }
176#endif
178 } 177 }
179} 178}