diff options
Diffstat (limited to 'firmware/usb.c')
-rw-r--r-- | firmware/usb.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/firmware/usb.c b/firmware/usb.c index d749e1e860..a7b19eb065 100644 --- a/firmware/usb.c +++ b/firmware/usb.c | |||
@@ -84,6 +84,9 @@ static bool usb_hid = true; | |||
84 | static bool usb_host_present = false; | 84 | static bool usb_host_present = false; |
85 | static int usb_num_acks_to_expect = 0; | 85 | static int usb_num_acks_to_expect = 0; |
86 | static long usb_last_broadcast_tick = 0; | 86 | static long usb_last_broadcast_tick = 0; |
87 | #ifdef HAVE_USB_POWER | ||
88 | static bool usb_charging_only = false; | ||
89 | #endif | ||
87 | 90 | ||
88 | #if defined(USB_FIREWIRE_HANDLING) \ | 91 | #if defined(USB_FIREWIRE_HANDLING) \ |
89 | || (defined(HAVE_USBSTACK) && !defined(USE_ROCKBOX_USB)) | 92 | || (defined(HAVE_USBSTACK) && !defined(USE_ROCKBOX_USB)) |
@@ -127,13 +130,15 @@ static inline bool usb_do_screendump(void) | |||
127 | #endif /* HAVE_LCD_BITMAP */ | 130 | #endif /* HAVE_LCD_BITMAP */ |
128 | 131 | ||
129 | /* Power (charging-only) button */ | 132 | /* Power (charging-only) button */ |
130 | static inline bool usb_power_button(void) | 133 | static inline void usb_detect_charging_only(bool detect) |
131 | { | 134 | { |
132 | #ifdef HAVE_USB_POWER | 135 | #ifdef HAVE_USB_POWER |
133 | return (button_status() & ~USBPOWER_BTN_IGNORE); | 136 | if (detect) |
134 | #else | 137 | detect = button_status() & ~USBPOWER_BTN_IGNORE; |
135 | return false; | 138 | |
139 | usb_charging_only = detect; | ||
136 | #endif | 140 | #endif |
141 | (void)detect; | ||
137 | } | 142 | } |
138 | 143 | ||
139 | #ifdef USB_FIREWIRE_HANDLING | 144 | #ifdef USB_FIREWIRE_HANDLING |
@@ -375,12 +380,14 @@ static void usb_set_host_present(bool present) | |||
375 | return; | 380 | return; |
376 | } | 381 | } |
377 | 382 | ||
378 | if(usb_power_button()) | 383 | #ifdef HAVE_USB_POWER |
384 | if (usb_charging_only) | ||
379 | { | 385 | { |
380 | /* Only charging is desired */ | 386 | /* Only charging is desired */ |
381 | usb_configure_drivers(USB_POWERED); | 387 | usb_configure_drivers(USB_POWERED); |
382 | return; | 388 | return; |
383 | } | 389 | } |
390 | #endif | ||
384 | 391 | ||
385 | if(!usb_configure_drivers(USB_INSERTED)) | 392 | if(!usb_configure_drivers(USB_INSERTED)) |
386 | return; /* Exclusive storage access not required */ | 393 | return; /* Exclusive storage access not required */ |
@@ -470,6 +477,8 @@ static void NORETURN_ATTR usb_thread(void) | |||
470 | usb_state = USB_POWERED; | 477 | usb_state = USB_POWERED; |
471 | usb_stack_enable(true); | 478 | usb_stack_enable(true); |
472 | 479 | ||
480 | usb_detect_charging_only(true); | ||
481 | |||
473 | #ifndef USB_DETECT_BY_REQUEST | 482 | #ifndef USB_DETECT_BY_REQUEST |
474 | usb_set_host_present(true); | 483 | usb_set_host_present(true); |
475 | #endif | 484 | #endif |
@@ -496,6 +505,7 @@ static void NORETURN_ATTR usb_thread(void) | |||
496 | 505 | ||
497 | usb_state = USB_EXTRACTED; | 506 | usb_state = USB_EXTRACTED; |
498 | 507 | ||
508 | usb_detect_charging_only(false); | ||
499 | usb_set_host_present(false); | 509 | usb_set_host_present(false); |
500 | break; | 510 | break; |
501 | /* USB_EXTRACTED: */ | 511 | /* USB_EXTRACTED: */ |