summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-11-02 08:10:15 -0500
committerSolomon Peachy <pizza@shaftnet.org>2020-11-13 16:44:01 -0500
commit60f581e8f52fa0f7355b80b38fc2d57e78634ae4 (patch)
tree4051cf647a687fdf7c58e21010654d87e96a7aa1 /firmware
parentfc4fff0b819a492e57dde76020c5ec78e2f8f6cc (diff)
downloadrockbox-60f581e8f52fa0f7355b80b38fc2d57e78634ae4.tar.gz
rockbox-60f581e8f52fa0f7355b80b38fc2d57e78634ae4.tar.bz2
rockbox-60f581e8f52fa0f7355b80b38fc2d57e78634ae4.zip
usb: Add ability to prompt user about what to do upon usb insertion
v3: Add in config option v4: Bugfixes v5: Force a redraw upon exiting v6: keypress-in-chargeonly mode enables mass storage (and vice versa) v7: Fix bootloader builds v8: Update manual, and have bootloader respect keypresses v9: Change default to mass storage (ie no change in behavior) todo: * test-build dx50/dx90 * Switch from yes/no to proper menu? * prevent WPS progress bar from drawing over us Change-Id: I82e0ccb08497b7a5aa756ce77f1332ee963703a7 ... Change-Id: I7946cf240b18a4fa8ace5e25e1eb6e97b8b12d7c
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/usb.h10
-rw-r--r--firmware/target/hosted/ibasso/usb-ibasso.c2
-rw-r--r--firmware/target/hosted/ibasso/usb-ibasso.h20
-rw-r--r--firmware/usb.c80
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
#endif
};
+/* Supported usb modes. */
+enum
+{
+ USB_MODE_ASK = 0,
+ USB_MODE_MASS_STORAGE,
+ USB_MODE_CHARGE,
+ USB_MODE_ADB
+};
+
#ifdef HAVE_USB_POWER
/*allow people to define this in config-target.h if they need it*/
#if !defined(USBPOWER_BTN_IGNORE)
@@ -215,6 +224,7 @@ void usb_charging_maxcurrent_change(int maxcurrent);
/* returns the maximum allowed USB current, based on USB charging mode and state */
int usb_charging_maxcurrent(void);
#endif /* HAVE_USB_CHARGING_ENABLE */
+void usb_set_mode(int mode);
#endif /* HAVE_USB_POWER */
#ifdef HAVE_USBSTACK
/* 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)
DEBUGF("ERROR %s: No command processor available.", __func__);
}
-
/* Default at boot not known. */
static int _last_usb_mode = -1;
-
void ibasso_set_usb_mode(int mode)
{
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 @@
#ifndef _USB_DX50_H_
#define _USB_DX50_H_
-
-/* Supported usb modes. */
-enum ibasso_usb_mode
-{
- /*
- USB mass storage mode. On USB connection, Rockbox will terminate and the internel and
- external storage gets exported to the connected client.
- */
- USB_MODE_MASS_STORAGE = 0,
-
- /*
- Actually the same, since we to not have proper USB detection.
- Starts the adb server and enables adb connection over USB. Rockbox will continue to run.
- */
- USB_MODE_CHARGE,
- USB_MODE_ADB
-};
-
-
/*
Set the usb mode.
mode: ibasso_usb_mode
*/
void ibasso_set_usb_mode(int mode);
-
#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 @@
#include "logf.h"
#include "screendump.h"
+#ifndef BOOTLOADER
+#include "misc.h"
+#include "gui/yesno.h"
+#include "settings.h"
+#include "lang_enum.h"
+#include "gui/skin_engine/skin_engine.h"
+#endif
+
/* Conditions under which we want the entire driver */
#if !defined(BOOTLOADER) || \
(defined(HAVE_USBSTACK) && defined(HAVE_BOOTLOADER_USB_MODE)) || \
@@ -71,7 +79,7 @@ static int usb_mmc_countdown = 0;
#ifndef USB_EXTRA_STACK
# define USB_EXTRA_STACK 0x0 /*Define in firmware/export/config/[target].h*/
#endif
-static long usb_stack[(DEFAULT_STACK_SIZE + DUMP_BMP_LINESIZE + USB_EXTRA_STACK)/sizeof(long)];
+static long usb_stack[(DEFAULT_STACK_SIZE*2 + DUMP_BMP_LINESIZE + USB_EXTRA_STACK)/sizeof(long)];
static const char usb_thread_name[] = "usb";
static unsigned int usb_thread_entry = 0;
static bool usb_monitor_enabled = false;
@@ -87,7 +95,8 @@ static bool usb_host_present = false;
static int usb_num_acks_to_expect = 0;
static long usb_last_broadcast_tick = 0;
#ifdef HAVE_USB_POWER
-static bool usb_charging_only = false;
+static int usb_mode = USB_MODE_ASK;
+static int new_usbmode = USB_MODE_ASK;
#endif
static int usb_release_exclusive_storage(void);
@@ -130,17 +139,15 @@ static inline bool usb_do_screendump(void)
return false;
}
-/* Power (charging-only) button */
-static inline void usb_detect_charging_only(bool detect)
-{
#ifdef HAVE_USB_POWER
- if (detect)
- detect = button_status() & ~USBPOWER_BTN_IGNORE;
-
- usb_charging_only = detect;
+void usb_set_mode(int mode)
+{
+ usb_mode = mode;
+#if defined(DX50) || defined(DX90)
+ ibasso_set_usb_mode(mode);
#endif
- (void)detect;
}
+#endif
#ifdef USB_FIREWIRE_HANDLING
static inline bool usb_reboot_button(void)
@@ -201,7 +208,7 @@ static inline bool usb_configure_drivers(int for_state)
usb_attach(); /* Powered only: attach now. */
break;
/* USB_POWERED: */
-
+
case USB_INSERTED:
#ifdef USB_ENABLE_STORAGE
usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, true);
@@ -372,7 +379,7 @@ static void usb_set_host_present(bool present)
}
#ifdef HAVE_USB_POWER
- if (usb_charging_only)
+ if (new_usbmode == USB_MODE_CHARGE || new_usbmode == USB_MODE_ADB)
{
/* Only charging is desired */
usb_configure_drivers(USB_POWERED);
@@ -464,9 +471,49 @@ static void NORETURN_ATTR usb_thread(void)
}
usb_state = USB_POWERED;
+
usb_stack_enable(true);
- usb_detect_charging_only(true);
+ /* Power (charging-only) button */
+#ifdef HAVE_USB_POWER
+ switch (usb_mode) {
+ case USB_MODE_CHARGE:
+ case USB_MODE_ADB:
+ if (button_status() & ~USBPOWER_BTN_IGNORE)
+ new_usbmode = USB_MODE_MASS_STORAGE;
+ break;
+#ifndef BOOTLOADER
+ case USB_MODE_ASK:
+ new_usbmode = USB_MODE_ASK;
+ break;
+#endif
+ default:
+ case USB_MODE_MASS_STORAGE:
+ if (button_status() & ~USBPOWER_BTN_IGNORE)
+ new_usbmode = USB_MODE_CHARGE;
+ break;
+ }
+
+#ifndef BOOTLOADER
+ if (new_usbmode == USB_MODE_ASK)
+ {
+ push_current_activity(ACTIVITY_USBSCREEN);
+ if (yesno_pop(ID2P(LANG_ENTER_USB_STORAGE_MODE_QUERY)))
+ new_usbmode = USB_MODE_MASS_STORAGE;
+ else
+ new_usbmode = USB_MODE_CHARGE;
+ pop_current_activity();
+ /* Force full redraw */
+// queue_post(&button_queue, BUTTON_REDRAW, 0);
+// Alternative approach, as above is supposedly inadequate by design.
+ FOR_NB_SCREENS(i)
+ {
+ struct screen *screen = &screens[i];
+ screen->set_viewport(NULL);
+ }
+ }
+#endif
+#endif
#ifndef USB_DETECT_BY_REQUEST
usb_set_host_present(true);
@@ -493,8 +540,10 @@ static void NORETURN_ATTR usb_thread(void)
usb_slave_mode(false);
usb_state = USB_EXTRACTED;
+#ifdef HAVE_USB_POWER
+ new_usbmode = usb_mode;
+#endif
- usb_detect_charging_only(false);
usb_set_host_present(false);
break;
/* USB_EXTRACTED: */
@@ -597,7 +646,7 @@ static void usb_tick(void)
#ifdef USB_FIREWIRE_HANDLING
static int firewire_countdown = -1;
static int last_firewire_status = false;
-#endif
+#endif
if(usb_monitor_enabled)
{
@@ -814,4 +863,3 @@ void usb_wait_for_disconnect(struct event_queue *q)
(void)q;
}
#endif /* USB_NONE */
-