diff options
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r-- | tmk_core/protocol/chibios.mk | 2 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/chibios.c (renamed from tmk_core/protocol/chibios/main.c) | 66 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 64 | ||||
-rw-r--r-- | tmk_core/protocol/vusb.mk | 2 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/protocol.c (renamed from tmk_core/protocol/vusb/main.c) | 89 |
5 files changed, 105 insertions, 118 deletions
diff --git a/tmk_core/protocol/chibios.mk b/tmk_core/protocol/chibios.mk index d01697835..a7f2d8e93 100644 --- a/tmk_core/protocol/chibios.mk +++ b/tmk_core/protocol/chibios.mk | |||
@@ -3,7 +3,7 @@ CHIBIOS_DIR = $(PROTOCOL_DIR)/chibios | |||
3 | 3 | ||
4 | 4 | ||
5 | SRC += $(CHIBIOS_DIR)/usb_main.c | 5 | SRC += $(CHIBIOS_DIR)/usb_main.c |
6 | SRC += $(CHIBIOS_DIR)/main.c | 6 | SRC += $(CHIBIOS_DIR)/chibios.c |
7 | SRC += usb_descriptor.c | 7 | SRC += usb_descriptor.c |
8 | SRC += $(CHIBIOS_DIR)/usb_driver.c | 8 | SRC += $(CHIBIOS_DIR)/usb_driver.c |
9 | SRC += $(CHIBIOS_DIR)/usb_util.c | 9 | SRC += $(CHIBIOS_DIR)/usb_util.c |
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/chibios.c index e41d6ff19..78a2e3fcb 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/chibios.c | |||
@@ -138,18 +138,14 @@ void boardInit(void) { | |||
138 | board_init(); | 138 | board_init(); |
139 | } | 139 | } |
140 | 140 | ||
141 | /* Main thread | 141 | void protocol_setup(void) { |
142 | */ | ||
143 | int main(void) { | ||
144 | /* ChibiOS/RT init */ | ||
145 | halInit(); | ||
146 | chSysInit(); | ||
147 | |||
148 | // TESTING | 142 | // TESTING |
149 | // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); | 143 | // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
150 | 144 | ||
151 | keyboard_setup(); | 145 | keyboard_setup(); |
146 | } | ||
152 | 147 | ||
148 | void protocol_init(void) { | ||
153 | /* Init USB */ | 149 | /* Init USB */ |
154 | usb_event_queue_init(); | 150 | usb_event_queue_init(); |
155 | init_usb_driver(&USB_DRIVER); | 151 | init_usb_driver(&USB_DRIVER); |
@@ -207,57 +203,53 @@ int main(void) { | |||
207 | #endif | 203 | #endif |
208 | 204 | ||
209 | print("Keyboard start.\n"); | 205 | print("Keyboard start.\n"); |
206 | } | ||
210 | 207 | ||
211 | /* Main loop */ | 208 | void protocol_task(void) { |
212 | while (true) { | 209 | usb_event_queue_task(); |
213 | usb_event_queue_task(); | ||
214 | 210 | ||
215 | #if !defined(NO_USB_STARTUP_CHECK) | 211 | #if !defined(NO_USB_STARTUP_CHECK) |
216 | if (USB_DRIVER.state == USB_SUSPENDED) { | 212 | if (USB_DRIVER.state == USB_SUSPENDED) { |
217 | print("[s]"); | 213 | print("[s]"); |
218 | # ifdef VISUALIZER_ENABLE | 214 | # ifdef VISUALIZER_ENABLE |
219 | visualizer_suspend(); | 215 | visualizer_suspend(); |
220 | # endif | 216 | # endif |
221 | while (USB_DRIVER.state == USB_SUSPENDED) { | 217 | while (USB_DRIVER.state == USB_SUSPENDED) { |
222 | /* Do this in the suspended state */ | 218 | /* Do this in the suspended state */ |
223 | # ifdef SERIAL_LINK_ENABLE | 219 | # ifdef SERIAL_LINK_ENABLE |
224 | serial_link_update(); | 220 | serial_link_update(); |
225 | # endif | 221 | # endif |
226 | suspend_power_down(); // on AVR this deep sleeps for 15ms | 222 | suspend_power_down(); // on AVR this deep sleeps for 15ms |
227 | /* Remote wakeup */ | 223 | /* Remote wakeup */ |
228 | if (suspend_wakeup_condition()) { | 224 | if (suspend_wakeup_condition()) { |
229 | usbWakeupHost(&USB_DRIVER); | 225 | usbWakeupHost(&USB_DRIVER); |
230 | restart_usb_driver(&USB_DRIVER); | 226 | restart_usb_driver(&USB_DRIVER); |
231 | } | ||
232 | } | 227 | } |
233 | /* Woken up */ | 228 | } |
234 | // variables has been already cleared by the wakeup hook | 229 | /* Woken up */ |
235 | send_keyboard_report(); | 230 | // variables has been already cleared by the wakeup hook |
231 | send_keyboard_report(); | ||
236 | # ifdef MOUSEKEY_ENABLE | 232 | # ifdef MOUSEKEY_ENABLE |
237 | mousekey_send(); | 233 | mousekey_send(); |
238 | # endif /* MOUSEKEY_ENABLE */ | 234 | # endif /* MOUSEKEY_ENABLE */ |
239 | 235 | ||
240 | # ifdef VISUALIZER_ENABLE | 236 | # ifdef VISUALIZER_ENABLE |
241 | visualizer_resume(); | 237 | visualizer_resume(); |
242 | # endif | 238 | # endif |
243 | } | 239 | } |
244 | #endif | 240 | #endif |
245 | 241 | ||
246 | keyboard_task(); | 242 | keyboard_task(); |
247 | #ifdef CONSOLE_ENABLE | 243 | #ifdef CONSOLE_ENABLE |
248 | console_task(); | 244 | console_task(); |
249 | #endif | 245 | #endif |
250 | #ifdef MIDI_ENABLE | 246 | #ifdef MIDI_ENABLE |
251 | midi_ep_task(); | 247 | midi_ep_task(); |
252 | #endif | 248 | #endif |
253 | #ifdef VIRTSER_ENABLE | 249 | #ifdef VIRTSER_ENABLE |
254 | virtser_task(); | 250 | virtser_task(); |
255 | #endif | 251 | #endif |
256 | #ifdef RAW_ENABLE | 252 | #ifdef RAW_ENABLE |
257 | raw_hid_task(); | 253 | raw_hid_task(); |
258 | #endif | 254 | #endif |
259 | |||
260 | // Run housekeeping | ||
261 | housekeeping_task(); | ||
262 | } | ||
263 | } | 255 | } |
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 8ddb8b1c4..e638dbc0f 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
@@ -1033,18 +1033,16 @@ static void setup_usb(void) { | |||
1033 | USB_Device_EnableSOFEvents(); | 1033 | USB_Device_EnableSOFEvents(); |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | /** \brief Main | 1036 | void protocol_setup(void) { |
1037 | * | ||
1038 | * FIXME: Needs doc | ||
1039 | */ | ||
1040 | int main(void) __attribute__((weak)); | ||
1041 | int main(void) { | ||
1042 | #ifdef MIDI_ENABLE | 1037 | #ifdef MIDI_ENABLE |
1043 | setup_midi(); | 1038 | setup_midi(); |
1044 | #endif | 1039 | #endif |
1045 | 1040 | ||
1046 | setup_mcu(); | 1041 | setup_mcu(); |
1047 | keyboard_setup(); | 1042 | keyboard_setup(); |
1043 | } | ||
1044 | |||
1045 | void protocol_init(void) { | ||
1048 | setup_usb(); | 1046 | setup_usb(); |
1049 | sei(); | 1047 | sei(); |
1050 | 1048 | ||
@@ -1078,57 +1076,55 @@ int main(void) { | |||
1078 | #endif | 1076 | #endif |
1079 | 1077 | ||
1080 | print("Keyboard start.\n"); | 1078 | print("Keyboard start.\n"); |
1081 | while (1) { | 1079 | } |
1080 | |||
1081 | void protocol_task(void) { | ||
1082 | #if !defined(NO_USB_STARTUP_CHECK) | 1082 | #if !defined(NO_USB_STARTUP_CHECK) |
1083 | if (USB_DeviceState == DEVICE_STATE_Suspended) { | 1083 | if (USB_DeviceState == DEVICE_STATE_Suspended) { |
1084 | print("[s]"); | 1084 | print("[s]"); |
1085 | while (USB_DeviceState == DEVICE_STATE_Suspended) { | 1085 | while (USB_DeviceState == DEVICE_STATE_Suspended) { |
1086 | suspend_power_down(); | 1086 | suspend_power_down(); |
1087 | if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { | 1087 | if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) { |
1088 | USB_Device_SendRemoteWakeup(); | 1088 | USB_Device_SendRemoteWakeup(); |
1089 | clear_keyboard(); | 1089 | clear_keyboard(); |
1090 | 1090 | ||
1091 | # if USB_SUSPEND_WAKEUP_DELAY > 0 | 1091 | # if USB_SUSPEND_WAKEUP_DELAY > 0 |
1092 | // Some hubs, kvm switches, and monitors do | 1092 | // Some hubs, kvm switches, and monitors do |
1093 | // weird things, with USB device state bouncing | 1093 | // weird things, with USB device state bouncing |
1094 | // around wildly on wakeup, yielding race | 1094 | // around wildly on wakeup, yielding race |
1095 | // conditions that can corrupt the keyboard state. | 1095 | // conditions that can corrupt the keyboard state. |
1096 | // | 1096 | // |
1097 | // Pause for a while to let things settle... | 1097 | // Pause for a while to let things settle... |
1098 | wait_ms(USB_SUSPEND_WAKEUP_DELAY); | 1098 | wait_ms(USB_SUSPEND_WAKEUP_DELAY); |
1099 | # endif | 1099 | # endif |
1100 | } | ||
1101 | } | 1100 | } |
1102 | suspend_wakeup_init(); | ||
1103 | } | 1101 | } |
1102 | suspend_wakeup_init(); | ||
1103 | } | ||
1104 | #endif | 1104 | #endif |
1105 | 1105 | ||
1106 | keyboard_task(); | 1106 | keyboard_task(); |
1107 | 1107 | ||
1108 | #ifdef MIDI_ENABLE | 1108 | #ifdef MIDI_ENABLE |
1109 | MIDI_Device_USBTask(&USB_MIDI_Interface); | 1109 | MIDI_Device_USBTask(&USB_MIDI_Interface); |
1110 | #endif | 1110 | #endif |
1111 | 1111 | ||
1112 | #ifdef MODULE_ADAFRUIT_BLE | 1112 | #ifdef MODULE_ADAFRUIT_BLE |
1113 | adafruit_ble_task(); | 1113 | adafruit_ble_task(); |
1114 | #endif | 1114 | #endif |
1115 | 1115 | ||
1116 | #ifdef VIRTSER_ENABLE | 1116 | #ifdef VIRTSER_ENABLE |
1117 | virtser_task(); | 1117 | virtser_task(); |
1118 | CDC_Device_USBTask(&cdc_device); | 1118 | CDC_Device_USBTask(&cdc_device); |
1119 | #endif | 1119 | #endif |
1120 | 1120 | ||
1121 | #ifdef RAW_ENABLE | 1121 | #ifdef RAW_ENABLE |
1122 | raw_hid_task(); | 1122 | raw_hid_task(); |
1123 | #endif | 1123 | #endif |
1124 | 1124 | ||
1125 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) | 1125 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) |
1126 | USB_USBTask(); | 1126 | USB_USBTask(); |
1127 | #endif | 1127 | #endif |
1128 | |||
1129 | // Run housekeeping | ||
1130 | housekeeping_task(); | ||
1131 | } | ||
1132 | } | 1128 | } |
1133 | 1129 | ||
1134 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint16_t wIndex, const void **const DescriptorAddress) { return get_usb_descriptor(wValue, wIndex, DescriptorAddress); } | 1130 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint16_t wIndex, const void **const DescriptorAddress) { return get_usb_descriptor(wValue, wIndex, DescriptorAddress); } |
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk index e4d013b38..5572597e2 100644 --- a/tmk_core/protocol/vusb.mk +++ b/tmk_core/protocol/vusb.mk | |||
@@ -3,7 +3,7 @@ VUSB_DIR = protocol/vusb | |||
3 | # Path to the V-USB library | 3 | # Path to the V-USB library |
4 | VUSB_PATH = $(LIB_PATH)/vusb | 4 | VUSB_PATH = $(LIB_PATH)/vusb |
5 | 5 | ||
6 | SRC += $(VUSB_DIR)/main.c \ | 6 | SRC += $(VUSB_DIR)/protocol.c \ |
7 | $(VUSB_DIR)/vusb.c \ | 7 | $(VUSB_DIR)/vusb.c \ |
8 | $(VUSB_DIR)/usb_util.c \ | 8 | $(VUSB_DIR)/usb_util.c \ |
9 | $(VUSB_PATH)/usbdrv/usbdrv.c \ | 9 | $(VUSB_PATH)/usbdrv/usbdrv.c \ |
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 | */ |
100 | static void setup_usb(void) { initForUsbConnectivity(); } | 100 | static void setup_usb(void) { initForUsbConnectivity(); } |
101 | 101 | ||
102 | /** \brief Main | 102 | uint16_t sof_timer = 0; |
103 | * | 103 | |
104 | * FIXME: Needs doc | 104 | void protocol_setup(void) { |
105 | */ | ||
106 | int main(void) __attribute__((weak)); | ||
107 | int 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 | |||
117 | void 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) { | 132 | void 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 | } |