diff options
Diffstat (limited to 'firmware/usb.c')
-rw-r--r-- | firmware/usb.c | 80 |
1 files changed, 64 insertions, 16 deletions
diff --git a/firmware/usb.c b/firmware/usb.c index e0c0c45865..8443ffed3a 100644 --- a/firmware/usb.c +++ b/firmware/usb.c | |||
@@ -42,6 +42,14 @@ | |||
42 | #include "logf.h" | 42 | #include "logf.h" |
43 | #include "screendump.h" | 43 | #include "screendump.h" |
44 | 44 | ||
45 | #ifndef BOOTLOADER | ||
46 | #include "misc.h" | ||
47 | #include "gui/yesno.h" | ||
48 | #include "settings.h" | ||
49 | #include "lang_enum.h" | ||
50 | #include "gui/skin_engine/skin_engine.h" | ||
51 | #endif | ||
52 | |||
45 | /* Conditions under which we want the entire driver */ | 53 | /* Conditions under which we want the entire driver */ |
46 | #if !defined(BOOTLOADER) || \ | 54 | #if !defined(BOOTLOADER) || \ |
47 | (defined(HAVE_USBSTACK) && defined(HAVE_BOOTLOADER_USB_MODE)) || \ | 55 | (defined(HAVE_USBSTACK) && defined(HAVE_BOOTLOADER_USB_MODE)) || \ |
@@ -71,7 +79,7 @@ static int usb_mmc_countdown = 0; | |||
71 | #ifndef USB_EXTRA_STACK | 79 | #ifndef USB_EXTRA_STACK |
72 | # define USB_EXTRA_STACK 0x0 /*Define in firmware/export/config/[target].h*/ | 80 | # define USB_EXTRA_STACK 0x0 /*Define in firmware/export/config/[target].h*/ |
73 | #endif | 81 | #endif |
74 | static long usb_stack[(DEFAULT_STACK_SIZE + DUMP_BMP_LINESIZE + USB_EXTRA_STACK)/sizeof(long)]; | 82 | static long usb_stack[(DEFAULT_STACK_SIZE*2 + DUMP_BMP_LINESIZE + USB_EXTRA_STACK)/sizeof(long)]; |
75 | static const char usb_thread_name[] = "usb"; | 83 | static const char usb_thread_name[] = "usb"; |
76 | static unsigned int usb_thread_entry = 0; | 84 | static unsigned int usb_thread_entry = 0; |
77 | static bool usb_monitor_enabled = false; | 85 | static bool usb_monitor_enabled = false; |
@@ -87,7 +95,8 @@ static bool usb_host_present = false; | |||
87 | static int usb_num_acks_to_expect = 0; | 95 | static int usb_num_acks_to_expect = 0; |
88 | static long usb_last_broadcast_tick = 0; | 96 | static long usb_last_broadcast_tick = 0; |
89 | #ifdef HAVE_USB_POWER | 97 | #ifdef HAVE_USB_POWER |
90 | static bool usb_charging_only = false; | 98 | static int usb_mode = USB_MODE_ASK; |
99 | static int new_usbmode = USB_MODE_ASK; | ||
91 | #endif | 100 | #endif |
92 | 101 | ||
93 | static int usb_release_exclusive_storage(void); | 102 | static int usb_release_exclusive_storage(void); |
@@ -130,17 +139,15 @@ static inline bool usb_do_screendump(void) | |||
130 | return false; | 139 | return false; |
131 | } | 140 | } |
132 | 141 | ||
133 | /* Power (charging-only) button */ | ||
134 | static inline void usb_detect_charging_only(bool detect) | ||
135 | { | ||
136 | #ifdef HAVE_USB_POWER | 142 | #ifdef HAVE_USB_POWER |
137 | if (detect) | 143 | void usb_set_mode(int mode) |
138 | detect = button_status() & ~USBPOWER_BTN_IGNORE; | 144 | { |
139 | 145 | usb_mode = mode; | |
140 | usb_charging_only = detect; | 146 | #if defined(DX50) || defined(DX90) |
147 | ibasso_set_usb_mode(mode); | ||
141 | #endif | 148 | #endif |
142 | (void)detect; | ||
143 | } | 149 | } |
150 | #endif | ||
144 | 151 | ||
145 | #ifdef USB_FIREWIRE_HANDLING | 152 | #ifdef USB_FIREWIRE_HANDLING |
146 | static inline bool usb_reboot_button(void) | 153 | static inline bool usb_reboot_button(void) |
@@ -201,7 +208,7 @@ static inline bool usb_configure_drivers(int for_state) | |||
201 | usb_attach(); /* Powered only: attach now. */ | 208 | usb_attach(); /* Powered only: attach now. */ |
202 | break; | 209 | break; |
203 | /* USB_POWERED: */ | 210 | /* USB_POWERED: */ |
204 | 211 | ||
205 | case USB_INSERTED: | 212 | case USB_INSERTED: |
206 | #ifdef USB_ENABLE_STORAGE | 213 | #ifdef USB_ENABLE_STORAGE |
207 | usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, true); | 214 | usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, true); |
@@ -372,7 +379,7 @@ static void usb_set_host_present(bool present) | |||
372 | } | 379 | } |
373 | 380 | ||
374 | #ifdef HAVE_USB_POWER | 381 | #ifdef HAVE_USB_POWER |
375 | if (usb_charging_only) | 382 | if (new_usbmode == USB_MODE_CHARGE || new_usbmode == USB_MODE_ADB) |
376 | { | 383 | { |
377 | /* Only charging is desired */ | 384 | /* Only charging is desired */ |
378 | usb_configure_drivers(USB_POWERED); | 385 | usb_configure_drivers(USB_POWERED); |
@@ -464,9 +471,49 @@ static void NORETURN_ATTR usb_thread(void) | |||
464 | } | 471 | } |
465 | 472 | ||
466 | usb_state = USB_POWERED; | 473 | usb_state = USB_POWERED; |
474 | |||
467 | usb_stack_enable(true); | 475 | usb_stack_enable(true); |
468 | 476 | ||
469 | usb_detect_charging_only(true); | 477 | /* Power (charging-only) button */ |
478 | #ifdef HAVE_USB_POWER | ||
479 | switch (usb_mode) { | ||
480 | case USB_MODE_CHARGE: | ||
481 | case USB_MODE_ADB: | ||
482 | if (button_status() & ~USBPOWER_BTN_IGNORE) | ||
483 | new_usbmode = USB_MODE_MASS_STORAGE; | ||
484 | break; | ||
485 | #ifndef BOOTLOADER | ||
486 | case USB_MODE_ASK: | ||
487 | new_usbmode = USB_MODE_ASK; | ||
488 | break; | ||
489 | #endif | ||
490 | default: | ||
491 | case USB_MODE_MASS_STORAGE: | ||
492 | if (button_status() & ~USBPOWER_BTN_IGNORE) | ||
493 | new_usbmode = USB_MODE_CHARGE; | ||
494 | break; | ||
495 | } | ||
496 | |||
497 | #ifndef BOOTLOADER | ||
498 | if (new_usbmode == USB_MODE_ASK) | ||
499 | { | ||
500 | push_current_activity(ACTIVITY_USBSCREEN); | ||
501 | if (yesno_pop(ID2P(LANG_ENTER_USB_STORAGE_MODE_QUERY))) | ||
502 | new_usbmode = USB_MODE_MASS_STORAGE; | ||
503 | else | ||
504 | new_usbmode = USB_MODE_CHARGE; | ||
505 | pop_current_activity(); | ||
506 | /* Force full redraw */ | ||
507 | // queue_post(&button_queue, BUTTON_REDRAW, 0); | ||
508 | // Alternative approach, as above is supposedly inadequate by design. | ||
509 | FOR_NB_SCREENS(i) | ||
510 | { | ||
511 | struct screen *screen = &screens[i]; | ||
512 | screen->set_viewport(NULL); | ||
513 | } | ||
514 | } | ||
515 | #endif | ||
516 | #endif | ||
470 | 517 | ||
471 | #ifndef USB_DETECT_BY_REQUEST | 518 | #ifndef USB_DETECT_BY_REQUEST |
472 | usb_set_host_present(true); | 519 | usb_set_host_present(true); |
@@ -493,8 +540,10 @@ static void NORETURN_ATTR usb_thread(void) | |||
493 | usb_slave_mode(false); | 540 | usb_slave_mode(false); |
494 | 541 | ||
495 | usb_state = USB_EXTRACTED; | 542 | usb_state = USB_EXTRACTED; |
543 | #ifdef HAVE_USB_POWER | ||
544 | new_usbmode = usb_mode; | ||
545 | #endif | ||
496 | 546 | ||
497 | usb_detect_charging_only(false); | ||
498 | usb_set_host_present(false); | 547 | usb_set_host_present(false); |
499 | break; | 548 | break; |
500 | /* USB_EXTRACTED: */ | 549 | /* USB_EXTRACTED: */ |
@@ -597,7 +646,7 @@ static void usb_tick(void) | |||
597 | #ifdef USB_FIREWIRE_HANDLING | 646 | #ifdef USB_FIREWIRE_HANDLING |
598 | static int firewire_countdown = -1; | 647 | static int firewire_countdown = -1; |
599 | static int last_firewire_status = false; | 648 | static int last_firewire_status = false; |
600 | #endif | 649 | #endif |
601 | 650 | ||
602 | if(usb_monitor_enabled) | 651 | if(usb_monitor_enabled) |
603 | { | 652 | { |
@@ -814,4 +863,3 @@ void usb_wait_for_disconnect(struct event_queue *q) | |||
814 | (void)q; | 863 | (void)q; |
815 | } | 864 | } |
816 | #endif /* USB_NONE */ | 865 | #endif /* USB_NONE */ |
817 | |||