summaryrefslogtreecommitdiff
path: root/firmware/usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/usb.c')
-rw-r--r--firmware/usb.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/firmware/usb.c b/firmware/usb.c
index bb19850cae..c7326c548b 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -135,6 +135,11 @@ static inline bool usb_do_screendump(void)
135 135
136 136
137#ifdef HAVE_USBSTACK 137#ifdef HAVE_USBSTACK
138/* Enable / disable USB when the stack is enabled - otherwise a noop */
139static inline void usb_stack_enable(bool enable)
140{
141 usb_enable(enable);
142}
138 143
139#ifdef HAVE_HOTSWAP 144#ifdef HAVE_HOTSWAP
140static inline void usb_handle_hotswap(long id) 145static inline void usb_handle_hotswap(long id)
@@ -222,7 +227,6 @@ static inline void usb_slave_mode(bool on)
222 } 227 }
223 else /* usb_state == USB_INSERTED (only!) */ 228 else /* usb_state == USB_INSERTED (only!) */
224 { 229 {
225 usb_enable(false);
226#ifdef HAVE_PRIORITY_SCHEDULING 230#ifdef HAVE_PRIORITY_SCHEDULING
227 thread_set_priority(thread_self(), PRIORITY_SYSTEM); 231 thread_set_priority(thread_self(), PRIORITY_SYSTEM);
228#endif 232#endif
@@ -254,6 +258,11 @@ void usb_signal_transfer_completion(
254 258
255#else /* !HAVE_USBSTACK */ 259#else /* !HAVE_USBSTACK */
256 260
261static inline void usb_stack_enable(bool enable)
262{
263 (void)enable;
264}
265
257#ifdef HAVE_HOTSWAP 266#ifdef HAVE_HOTSWAP
258static inline void usb_handle_hotswap(long id) 267static inline void usb_handle_hotswap(long id)
259{ 268{
@@ -403,6 +412,7 @@ static void usb_thread(void)
403 break; 412 break;
404 413
405 usb_state = USB_POWERED; 414 usb_state = USB_POWERED;
415 usb_stack_enable(true);
406#endif /* USB_DETECT_BY_CORE */ 416#endif /* USB_DETECT_BY_CORE */
407 417
408 if(usb_power_button()) 418 if(usb_power_button())
@@ -467,20 +477,19 @@ static void usb_thread(void)
467 break; 477 break;
468 478
469 usb_state = USB_POWERED; 479 usb_state = USB_POWERED;
470 usb_enable(true); 480 usb_stack_enable(true);
471 break; 481 break;
472 /* USB_POWERED: */ 482 /* USB_POWERED: */
473 483
474 case USB_UNPOWERED: 484 case USB_UNPOWERED:
475 if(usb_state == USB_POWERED)
476 usb_enable(false);
477 /* Fall-through - other legal states can be USB_INSERTED or
478 USB_SCREENDUMP */
479#endif /* USB_DETECT_BY_CORE */ 485#endif /* USB_DETECT_BY_CORE */
480 case USB_EXTRACTED: 486 case USB_EXTRACTED:
481 if(usb_state == USB_EXTRACTED) 487 if(usb_state == USB_EXTRACTED)
482 break; 488 break;
483 489
490 if(usb_state == USB_POWERED || usb_state == USB_INSERTED)
491 usb_stack_enable(false);
492
484 /* Only disable the USB slave mode if we really have enabled 493 /* Only disable the USB slave mode if we really have enabled
485 it. Some expected acks may not have been received. */ 494 it. Some expected acks may not have been received. */
486 if(usb_state == USB_INSERTED) 495 if(usb_state == USB_INSERTED)