1. Index: usb-as3525.c
  2. ===================================================================
  3. --- usb-as3525.c (revision 24590)
  4. +++ usb-as3525.c (working copy)
  5. @@ -28,6 +28,8 @@
  6. #include "usb-target.h"
  7. #include "power.h"
  8. #include "as3525.h"
  9. +#include "ascodec.h"
  10. +#include "thread.h"
  11.  
  12. #if defined(SANSA_CLIP)
  13. #define USB_DETECT_PIN 6
  14. @@ -39,6 +41,11 @@
  15. #define USB_DETECT_PIN 1
  16. #endif
  17.  
  18. +static long detect_stack[DEFAULT_STACK_SIZE/sizeof(long)];
  19. +static const char detect_thread_name[] = "usbdetect";
  20. +static unsigned int detect_thread_entry = 0;
  21. +static int detect_state = USB_EXTRACTED;
  22. +
  23. void usb_enable(bool on)
  24. {
  25. #ifdef HAVE_USBSTACK
  26. @@ -51,19 +58,26 @@
  27. #endif
  28. }
  29.  
  30. +static void detect_thread(void)
  31. +{
  32. + while(1)
  33. + {
  34. + if (ascodec_read(AS3514_IRQ_ENRD0) & (1<<3))
  35. + detect_state = USB_INSERTED;
  36. + else
  37. + detect_state = USB_EXTRACTED;
  38. + sleep(HZ/10);
  39. + }
  40. +}
  41. +
  42. void usb_init_device(void)
  43. {
  44. -#ifdef USB_DETECT_PIN
  45. - GPIOA_DIR &= ~(1 << USB_DETECT_PIN); /* set as input */
  46. -#endif
  47. + detect_thread_entry = create_thread(detect_thread, detect_stack,
  48. + sizeof(detect_stack), 0, detect_thread_name
  49. + IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU));
  50. }
  51.  
  52. int usb_detect(void)
  53. {
  54. -#ifdef USB_DETECT_PIN
  55. - if (GPIOA_PIN( USB_DETECT_PIN ))
  56. - return USB_INSERTED;
  57. - else
  58. -#endif
  59. - return USB_EXTRACTED;
  60. + return detect_state;
  61. }
  62.