diff options
-rw-r--r-- | firmware/export/config.h | 14 | ||||
-rw-r--r-- | firmware/target/arm/as3525/usb-as3525.c | 79 |
2 files changed, 64 insertions, 29 deletions
diff --git a/firmware/export/config.h b/firmware/export/config.h index f5ee003308..d59b259fb9 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h | |||
@@ -721,15 +721,19 @@ Lyre prototype 1 */ | |||
721 | 721 | ||
722 | #define HAVE_SEMAPHORE_OBJECTS | 722 | #define HAVE_SEMAPHORE_OBJECTS |
723 | 723 | ||
724 | #if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_ARC | 724 | #ifdef HAVE_USBSTACK |
725 | #if CONFIG_USBOTG == USBOTG_ARC | ||
725 | #define USB_STATUS_BY_EVENT | 726 | #define USB_STATUS_BY_EVENT |
726 | #define USB_DETECT_BY_DRV | 727 | #define USB_DETECT_BY_DRV |
727 | #define INCLUDE_TIMEOUT_API | 728 | #define INCLUDE_TIMEOUT_API |
728 | #endif /* HAVE_USBSTACK && USBOTG_ARC */ | 729 | #elif CONFIG_USBOTG == USBOTG_AS3525 |
729 | 730 | #define USB_STATUS_BY_EVENT | |
730 | #if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_AS3525 | ||
731 | #define USB_DETECT_BY_DRV | 731 | #define USB_DETECT_BY_DRV |
732 | #endif /* HAVE_USBSTACK && USBOTG_AS3525 */ | 732 | #elif CONFIG_USBOTG == USBOTG_AS3525v2 |
733 | #define USB_STATUS_BY_EVENT | ||
734 | #define USB_DETECT_BY_CORE | ||
735 | #endif /* CONFIG_USB == */ | ||
736 | #endif /* HAVE_USBSTACK */ | ||
733 | 737 | ||
734 | #endif /* BOOTLOADER */ | 738 | #endif /* BOOTLOADER */ |
735 | 739 | ||
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 @@ | |||
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | |||
22 | #include <stdbool.h> | ||
23 | #include "config.h" | 21 | #include "config.h" |
22 | #include "system.h" | ||
24 | #include "usb.h" | 23 | #include "usb.h" |
25 | #ifdef HAVE_USBSTACK | 24 | #ifdef HAVE_USBSTACK |
26 | #include "usb_core.h" | 25 | #include "usb_core.h" |
@@ -29,8 +28,40 @@ | |||
29 | #include "power.h" | 28 | #include "power.h" |
30 | #include "as3525.h" | 29 | #include "as3525.h" |
31 | 30 | ||
32 | static bool bus_activity = 0; | 31 | static int usb_status = USB_EXTRACTED; |
33 | static bool connected = 0; | 32 | |
33 | #if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB) | ||
34 | /* Rebooting on USB plug can crash these players in a state where | ||
35 | * hardware power off (pressing the power button) doesn't work anymore | ||
36 | * TODO: Implement USB in rockbox for these players */ | ||
37 | #define USB_INSERT_INT_STATUS USB_EXTRACTED | ||
38 | #undef USB_DETECT_BY_DRV | ||
39 | #undef USB_DETECT_BY_CORE | ||
40 | #undef USB_STATUS_BY_EVENT | ||
41 | |||
42 | #else /* !AS3525v2 */ | ||
43 | |||
44 | #if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE) | ||
45 | |||
46 | #ifdef USB_STATUS_BY_EVENT | ||
47 | #define USB_INSERT_INT_STATUS USB_INSERTED | ||
48 | #define USB_INSERT_INT_EVENT USB_POWERED | ||
49 | #define USB_REMOVE_INT_EVENT USB_UNPOWERED | ||
50 | #else | ||
51 | #define USB_INSERT_INT_STATUS USB_POWERED | ||
52 | #endif /* USB_STATUS_BY_EVENT */ | ||
53 | |||
54 | #else /* !USB_DETECT_BY_* */ | ||
55 | |||
56 | #define USB_INSERT_INT_STATUS USB_INSERTED | ||
57 | #ifdef USB_STATUS_BY_EVENT | ||
58 | #define USB_INSERT_INT_EVENT USB_INSERTED | ||
59 | #define USB_REMOVE_INT_EVENT USB_EXTRACTED | ||
60 | #endif /* USB_STATUS_BY_EVENT */ | ||
61 | |||
62 | #endif /* USB_DETECT_BY_* */ | ||
63 | |||
64 | #endif /* AS3525v2 */ | ||
34 | 65 | ||
35 | void usb_enable(bool on) | 66 | void usb_enable(bool on) |
36 | { | 67 | { |
@@ -46,36 +77,36 @@ void usb_enable(bool on) | |||
46 | 77 | ||
47 | void usb_insert_int(void) | 78 | void usb_insert_int(void) |
48 | { | 79 | { |
49 | connected = 1; | 80 | usb_status = USB_INSERT_INT_STATUS; |
81 | #ifdef USB_STATUS_BY_EVENT | ||
82 | usb_status_event(USB_INSERT_INT_EVENT); | ||
83 | #endif | ||
50 | } | 84 | } |
51 | 85 | ||
52 | void usb_remove_int(void) | 86 | void usb_remove_int(void) |
53 | { | 87 | { |
54 | connected = 0; | 88 | usb_status = USB_EXTRACTED; |
55 | bus_activity = 0; | 89 | #ifdef USB_STATUS_BY_EVENT |
90 | usb_status_event(USB_REMOVE_INT_EVENT); | ||
91 | #endif | ||
56 | } | 92 | } |
57 | 93 | ||
58 | void usb_drv_usb_detect_event(void) | 94 | void usb_drv_usb_detect_event(void) |
59 | { | 95 | { |
60 | /* Bus activity seen */ | 96 | #if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE) |
61 | bus_activity = 1; | 97 | int oldstatus = disable_irq_save(); /* May come via USB thread */ |
98 | if (usb_status == USB_INSERT_INT_STATUS) | ||
99 | { | ||
100 | usb_status = USB_INSERTED; | ||
101 | #ifdef USB_STATUS_BY_EVENT | ||
102 | usb_status_event(USB_INSERTED); | ||
103 | #endif | ||
104 | } | ||
105 | restore_irq(oldstatus); | ||
106 | #endif /* USB_DETECT_BY_* */ | ||
62 | } | 107 | } |
63 | 108 | ||
64 | int usb_detect(void) | 109 | int usb_detect(void) |
65 | { | 110 | { |
66 | #if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB) | 111 | return usb_status; |
67 | /* Rebooting on USB plug can crash these players in a state where | ||
68 | * hardware power off (pressing the power button) doesn't work anymore | ||
69 | * TODO: Implement USB in rockbox for these players */ | ||
70 | return USB_EXTRACTED; | ||
71 | #elif defined(USB_DETECT_BY_DRV) | ||
72 | if(bus_activity && connected) | ||
73 | return USB_INSERTED; | ||
74 | else if(connected) | ||
75 | return USB_POWERED; | ||
76 | else | ||
77 | return USB_UNPOWERED; | ||
78 | #else | ||
79 | return connected?USB_INSERTED:USB_EXTRACTED; | ||
80 | #endif | ||
81 | } | 112 | } |