summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/usb-as3525.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/usb-as3525.c')
-rw-r--r--firmware/target/arm/as3525/usb-as3525.c79
1 files changed, 55 insertions, 24 deletions
diff --git a/firmware/target/arm/as3525/usb-as3525.c b/firmware/target/arm/as3525/usb-as3525.c
index 5664eb2096..a6d5d3a245 100644
--- a/firmware/target/arm/as3525/usb-as3525.c
+++ b/firmware/target/arm/as3525/usb-as3525.c
@@ -18,9 +18,8 @@
* KIND, either express or implied.
*
****************************************************************************/
-
-#include <stdbool.h>
#include "config.h"
+#include "system.h"
#include "usb.h"
#ifdef HAVE_USBSTACK
#include "usb_core.h"
@@ -29,8 +28,40 @@
#include "power.h"
#include "as3525.h"
-static bool bus_activity = 0;
-static bool connected = 0;
+static int usb_status = USB_EXTRACTED;
+
+#if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB)
+/* Rebooting on USB plug can crash these players in a state where
+ * hardware power off (pressing the power button) doesn't work anymore
+ * TODO: Implement USB in rockbox for these players */
+#define USB_INSERT_INT_STATUS USB_EXTRACTED
+#undef USB_DETECT_BY_DRV
+#undef USB_DETECT_BY_CORE
+#undef USB_STATUS_BY_EVENT
+
+#else /* !AS3525v2 */
+
+#if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE)
+
+#ifdef USB_STATUS_BY_EVENT
+#define USB_INSERT_INT_STATUS USB_INSERTED
+#define USB_INSERT_INT_EVENT USB_POWERED
+#define USB_REMOVE_INT_EVENT USB_UNPOWERED
+#else
+#define USB_INSERT_INT_STATUS USB_POWERED
+#endif /* USB_STATUS_BY_EVENT */
+
+#else /* !USB_DETECT_BY_* */
+
+#define USB_INSERT_INT_STATUS USB_INSERTED
+#ifdef USB_STATUS_BY_EVENT
+#define USB_INSERT_INT_EVENT USB_INSERTED
+#define USB_REMOVE_INT_EVENT USB_EXTRACTED
+#endif /* USB_STATUS_BY_EVENT */
+
+#endif /* USB_DETECT_BY_* */
+
+#endif /* AS3525v2 */
void usb_enable(bool on)
{
@@ -46,36 +77,36 @@ void usb_enable(bool on)
void usb_insert_int(void)
{
- connected = 1;
+ usb_status = USB_INSERT_INT_STATUS;
+#ifdef USB_STATUS_BY_EVENT
+ usb_status_event(USB_INSERT_INT_EVENT);
+#endif
}
void usb_remove_int(void)
{
- connected = 0;
- bus_activity = 0;
+ usb_status = USB_EXTRACTED;
+#ifdef USB_STATUS_BY_EVENT
+ usb_status_event(USB_REMOVE_INT_EVENT);
+#endif
}
void usb_drv_usb_detect_event(void)
{
- /* Bus activity seen */
- bus_activity = 1;
+#if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE)
+ int oldstatus = disable_irq_save(); /* May come via USB thread */
+ if (usb_status == USB_INSERT_INT_STATUS)
+ {
+ usb_status = USB_INSERTED;
+#ifdef USB_STATUS_BY_EVENT
+ usb_status_event(USB_INSERTED);
+#endif
+ }
+ restore_irq(oldstatus);
+#endif /* USB_DETECT_BY_* */
}
int usb_detect(void)
{
-#if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB)
- /* Rebooting on USB plug can crash these players in a state where
- * hardware power off (pressing the power button) doesn't work anymore
- * TODO: Implement USB in rockbox for these players */
- return USB_EXTRACTED;
-#elif defined(USB_DETECT_BY_DRV)
- if(bus_activity && connected)
- return USB_INSERTED;
- else if(connected)
- return USB_POWERED;
- else
- return USB_UNPOWERED;
-#else
- return connected?USB_INSERTED:USB_EXTRACTED;
-#endif
+ return usb_status;
}