Index: usb-as3525.c
===================================================================
--- usb-as3525.c (revision 24590)
+++ usb-as3525.c (working copy)
@@ -28,6 +28,8 @@
#include "usb-target.h"
#include "power.h"
#include "as3525.h"
+#include "ascodec.h"
+#include "thread.h"
#if defined(SANSA_CLIP)
#define USB_DETECT_PIN 6
@@ -39,6 +41,11 @@
#define USB_DETECT_PIN 1
#endif
+static long detect_stack[DEFAULT_STACK_SIZE/sizeof(long)];
+static const char detect_thread_name[] = "usbdetect";
+static unsigned int detect_thread_entry = 0;
+static int detect_state = USB_EXTRACTED;
+
void usb_enable(bool on)
{
#ifdef HAVE_USBSTACK
@@ -51,19 +58,26 @@
#endif
}
+static void detect_thread(void)
+{
+ while(1)
+ {
+ if (ascodec_read(AS3514_IRQ_ENRD0) & (1<<3))
+ detect_state = USB_INSERTED;
+ else
+ detect_state = USB_EXTRACTED;
+ sleep(HZ/10);
+ }
+}
+
void usb_init_device(void)
{
-#ifdef USB_DETECT_PIN
- GPIOA_DIR &= ~(1 << USB_DETECT_PIN); /* set as input */
-#endif
+ detect_thread_entry = create_thread(detect_thread, detect_stack,
+ sizeof(detect_stack), 0, detect_thread_name
+ IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU));
}
int usb_detect(void)
{
-#ifdef USB_DETECT_PIN
- if (GPIOA_PIN( USB_DETECT_PIN ))
- return USB_INSERTED;
- else
-#endif
- return USB_EXTRACTED;
+ return detect_state;
}