diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/export/usb.h | 10 | ||||
-rw-r--r-- | firmware/target/hosted/ibasso/usb-ibasso.c | 2 | ||||
-rw-r--r-- | firmware/target/hosted/ibasso/usb-ibasso.h | 20 | ||||
-rw-r--r-- | firmware/usb.c | 80 |
4 files changed, 74 insertions, 38 deletions
diff --git a/firmware/export/usb.h b/firmware/export/usb.h index b7b846d5b3..edc37bd5b6 100644 --- a/firmware/export/usb.h +++ b/firmware/export/usb.h | |||
@@ -131,6 +131,15 @@ enum | |||
131 | #endif | 131 | #endif |
132 | }; | 132 | }; |
133 | 133 | ||
134 | /* Supported usb modes. */ | ||
135 | enum | ||
136 | { | ||
137 | USB_MODE_ASK = 0, | ||
138 | USB_MODE_MASS_STORAGE, | ||
139 | USB_MODE_CHARGE, | ||
140 | USB_MODE_ADB | ||
141 | }; | ||
142 | |||
134 | #ifdef HAVE_USB_POWER | 143 | #ifdef HAVE_USB_POWER |
135 | /*allow people to define this in config-target.h if they need it*/ | 144 | /*allow people to define this in config-target.h if they need it*/ |
136 | #if !defined(USBPOWER_BTN_IGNORE) | 145 | #if !defined(USBPOWER_BTN_IGNORE) |
@@ -215,6 +224,7 @@ void usb_charging_maxcurrent_change(int maxcurrent); | |||
215 | /* returns the maximum allowed USB current, based on USB charging mode and state */ | 224 | /* returns the maximum allowed USB current, based on USB charging mode and state */ |
216 | int usb_charging_maxcurrent(void); | 225 | int usb_charging_maxcurrent(void); |
217 | #endif /* HAVE_USB_CHARGING_ENABLE */ | 226 | #endif /* HAVE_USB_CHARGING_ENABLE */ |
227 | void usb_set_mode(int mode); | ||
218 | #endif /* HAVE_USB_POWER */ | 228 | #endif /* HAVE_USB_POWER */ |
219 | #ifdef HAVE_USBSTACK | 229 | #ifdef HAVE_USBSTACK |
220 | /* USB driver call this function to notify that a transfer has completed */ | 230 | /* USB driver call this function to notify that a transfer has completed */ |
diff --git a/firmware/target/hosted/ibasso/usb-ibasso.c b/firmware/target/hosted/ibasso/usb-ibasso.c index e1b134e545..9af932f94f 100644 --- a/firmware/target/hosted/ibasso/usb-ibasso.c +++ b/firmware/target/hosted/ibasso/usb-ibasso.c | |||
@@ -60,11 +60,9 @@ static void usb_enable_mass_storage(void) | |||
60 | DEBUGF("ERROR %s: No command processor available.", __func__); | 60 | DEBUGF("ERROR %s: No command processor available.", __func__); |
61 | } | 61 | } |
62 | 62 | ||
63 | |||
64 | /* Default at boot not known. */ | 63 | /* Default at boot not known. */ |
65 | static int _last_usb_mode = -1; | 64 | static int _last_usb_mode = -1; |
66 | 65 | ||
67 | |||
68 | void ibasso_set_usb_mode(int mode) | 66 | void ibasso_set_usb_mode(int mode) |
69 | { | 67 | { |
70 | DEBUGF("DEBUG %s: _last_usb_mode: %d, mode: %d.", __func__, _last_usb_mode, mode); | 68 | DEBUGF("DEBUG %s: _last_usb_mode: %d, mode: %d.", __func__, _last_usb_mode, mode); |
diff --git a/firmware/target/hosted/ibasso/usb-ibasso.h b/firmware/target/hosted/ibasso/usb-ibasso.h index f509d43038..6cd31134b6 100644 --- a/firmware/target/hosted/ibasso/usb-ibasso.h +++ b/firmware/target/hosted/ibasso/usb-ibasso.h | |||
@@ -25,30 +25,10 @@ | |||
25 | #ifndef _USB_DX50_H_ | 25 | #ifndef _USB_DX50_H_ |
26 | #define _USB_DX50_H_ | 26 | #define _USB_DX50_H_ |
27 | 27 | ||
28 | |||
29 | /* Supported usb modes. */ | ||
30 | enum ibasso_usb_mode | ||
31 | { | ||
32 | /* | ||
33 | USB mass storage mode. On USB connection, Rockbox will terminate and the internel and | ||
34 | external storage gets exported to the connected client. | ||
35 | */ | ||
36 | USB_MODE_MASS_STORAGE = 0, | ||
37 | |||
38 | /* | ||
39 | Actually the same, since we to not have proper USB detection. | ||
40 | Starts the adb server and enables adb connection over USB. Rockbox will continue to run. | ||
41 | */ | ||
42 | USB_MODE_CHARGE, | ||
43 | USB_MODE_ADB | ||
44 | }; | ||
45 | |||
46 | |||
47 | /* | 28 | /* |
48 | Set the usb mode. | 29 | Set the usb mode. |
49 | mode: ibasso_usb_mode | 30 | mode: ibasso_usb_mode |
50 | */ | 31 | */ |
51 | void ibasso_set_usb_mode(int mode); | 32 | void ibasso_set_usb_mode(int mode); |
52 | 33 | ||
53 | |||
54 | #endif | 34 | #endif |
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 | |||