diff options
Diffstat (limited to 'bootloader')
-rw-r--r-- | bootloader/sansaconnect.c | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/bootloader/sansaconnect.c b/bootloader/sansaconnect.c index c5dbca717d..a60fa71800 100644 --- a/bootloader/sansaconnect.c +++ b/bootloader/sansaconnect.c | |||
@@ -172,6 +172,49 @@ static void clear_recoverzap(void) | |||
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | static void handle_usb(int connect_timeout) | ||
176 | { | ||
177 | long end_tick = 0; | ||
178 | |||
179 | if (usb_detect() != USB_INSERTED) | ||
180 | { | ||
181 | return; | ||
182 | } | ||
183 | |||
184 | usb_init(); | ||
185 | usb_start_monitoring(); | ||
186 | |||
187 | printf("USB: Connecting"); | ||
188 | |||
189 | if (connect_timeout != TIMEOUT_BLOCK) | ||
190 | { | ||
191 | end_tick = current_tick + connect_timeout; | ||
192 | } | ||
193 | |||
194 | while (usb_detect() == USB_INSERTED) | ||
195 | { | ||
196 | if (button_get_w_tmo(HZ/2) == SYS_USB_CONNECTED) | ||
197 | { | ||
198 | printf("Bootloader USB mode"); | ||
199 | usb_acknowledge(SYS_USB_CONNECTED_ACK); | ||
200 | while (button_get_w_tmo(HZ/2) != SYS_USB_DISCONNECTED) | ||
201 | { | ||
202 | storage_spin(); | ||
203 | } | ||
204 | break; | ||
205 | } | ||
206 | |||
207 | if (connect_timeout != TIMEOUT_BLOCK && | ||
208 | TIME_AFTER(current_tick, end_tick)) | ||
209 | { | ||
210 | printf("USB: Timed out"); | ||
211 | break; | ||
212 | } | ||
213 | } | ||
214 | |||
215 | usb_close(); | ||
216 | } | ||
217 | |||
175 | extern void show_logo(void); | 218 | extern void show_logo(void); |
176 | 219 | ||
177 | void main(void) | 220 | void main(void) |
@@ -203,12 +246,8 @@ void main(void) | |||
203 | reset_screen(); | 246 | reset_screen(); |
204 | show_logo(); | 247 | show_logo(); |
205 | 248 | ||
206 | btn = button_read_device(); | ||
207 | |||
208 | printf("Rockbox boot loader"); | 249 | printf("Rockbox boot loader"); |
209 | printf("Version %s", rbversion); | 250 | printf("Version %s", rbversion); |
210 | usb_init(); | ||
211 | usb_start_monitoring(); | ||
212 | 251 | ||
213 | clear_recoverzap(); | 252 | clear_recoverzap(); |
214 | 253 | ||
@@ -218,21 +257,14 @@ void main(void) | |||
218 | 257 | ||
219 | filesystem_init(); | 258 | filesystem_init(); |
220 | 259 | ||
221 | if (usb_detect() == USB_INSERTED) | 260 | handle_usb(2*HZ); |
222 | { | ||
223 | usb_enable(true); | ||
224 | while (usb_detect() == USB_INSERTED) | ||
225 | { | ||
226 | sleep(HZ); | ||
227 | storage_spin(); | ||
228 | } | ||
229 | usb_enable(false); | ||
230 | } | ||
231 | 261 | ||
232 | ret = disk_mount_all(); | 262 | ret = disk_mount_all(); |
233 | if (ret <= 0) | 263 | if (ret <= 0) |
234 | error(EDISK, ret, true); | 264 | error(EDISK, ret, true); |
235 | 265 | ||
266 | btn = button_read_device(); | ||
267 | |||
236 | if (btn & BUTTON_PREV) | 268 | if (btn & BUTTON_PREV) |
237 | { | 269 | { |
238 | printf("Loading OF firmware..."); | 270 | printf("Loading OF firmware..."); |