USB: Detect charging-only mode upon cable insert, not host detect.

Letting go of the button before the host is detected allows storage mode
to be entered even though a button was down when plugging. Sometimes the
host would try several times and the button would have to be held down
for several seconds to avoid a storage connection.

The adjustment wasn't made when switching to setup request host
detection.

Change-Id: Iab3bced5bfb1478d4d9a7baab2a2a1144afaf437
This commit is contained in:
Michael Sevakis 2013-05-22 02:04:29 -04:00
parent 39946a56d8
commit 7738660eff

View file

@ -84,6 +84,9 @@ static bool usb_hid = true;
static bool usb_host_present = false; static bool usb_host_present = false;
static int usb_num_acks_to_expect = 0; static int usb_num_acks_to_expect = 0;
static long usb_last_broadcast_tick = 0; static long usb_last_broadcast_tick = 0;
#ifdef HAVE_USB_POWER
static bool usb_charging_only = false;
#endif
#if defined(USB_FIREWIRE_HANDLING) \ #if defined(USB_FIREWIRE_HANDLING) \
|| (defined(HAVE_USBSTACK) && !defined(USE_ROCKBOX_USB)) || (defined(HAVE_USBSTACK) && !defined(USE_ROCKBOX_USB))
@ -127,13 +130,15 @@ static inline bool usb_do_screendump(void)
#endif /* HAVE_LCD_BITMAP */ #endif /* HAVE_LCD_BITMAP */
/* Power (charging-only) button */ /* Power (charging-only) button */
static inline bool usb_power_button(void) static inline void usb_detect_charging_only(bool detect)
{ {
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
return (button_status() & ~USBPOWER_BTN_IGNORE); if (detect)
#else detect = button_status() & ~USBPOWER_BTN_IGNORE;
return false;
usb_charging_only = detect;
#endif #endif
(void)detect;
} }
#ifdef USB_FIREWIRE_HANDLING #ifdef USB_FIREWIRE_HANDLING
@ -375,12 +380,14 @@ static void usb_set_host_present(bool present)
return; return;
} }
if(usb_power_button()) #ifdef HAVE_USB_POWER
if (usb_charging_only)
{ {
/* Only charging is desired */ /* Only charging is desired */
usb_configure_drivers(USB_POWERED); usb_configure_drivers(USB_POWERED);
return; return;
} }
#endif
if(!usb_configure_drivers(USB_INSERTED)) if(!usb_configure_drivers(USB_INSERTED))
return; /* Exclusive storage access not required */ return; /* Exclusive storage access not required */
@ -470,6 +477,8 @@ static void NORETURN_ATTR usb_thread(void)
usb_state = USB_POWERED; usb_state = USB_POWERED;
usb_stack_enable(true); usb_stack_enable(true);
usb_detect_charging_only(true);
#ifndef USB_DETECT_BY_REQUEST #ifndef USB_DETECT_BY_REQUEST
usb_set_host_present(true); usb_set_host_present(true);
#endif #endif
@ -496,6 +505,7 @@ static void NORETURN_ATTR usb_thread(void)
usb_state = USB_EXTRACTED; usb_state = USB_EXTRACTED;
usb_detect_charging_only(false);
usb_set_host_present(false); usb_set_host_present(false);
break; break;
/* USB_EXTRACTED: */ /* USB_EXTRACTED: */