summaryrefslogtreecommitdiff
path: root/firmware/target/arm/usb-fw-pp502x.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/usb-fw-pp502x.c')
-rw-r--r--firmware/target/arm/usb-fw-pp502x.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/firmware/target/arm/usb-fw-pp502x.c b/firmware/target/arm/usb-fw-pp502x.c
index a41ef9a598..8a6d78675f 100644
--- a/firmware/target/arm/usb-fw-pp502x.c
+++ b/firmware/target/arm/usb-fw-pp502x.c
@@ -25,13 +25,13 @@
25 ****************************************************************************/ 25 ****************************************************************************/
26#include "config.h" 26#include "config.h"
27#include "system.h" 27#include "system.h"
28#include "usb-target.h"
28#include "usb.h" 29#include "usb.h"
29#include "button.h" 30#include "button.h"
30#include "ata.h" 31#include "ata.h"
31#include "string.h" 32#include "string.h"
32#include "usb_core.h" 33#include "usb_core.h"
33#include "usb_drv.h" 34#include "usb_drv.h"
34#include "usb-target.h"
35 35
36void usb_init_device(void) 36void usb_init_device(void)
37{ 37{
@@ -94,6 +94,31 @@ void usb_enable(bool on)
94 } 94 }
95} 95}
96 96
97void usb_attach(void)
98{
99#ifdef USB_DETECT_BY_DRV
100 usb_drv_attach();
101#else
102 usb_enable(true);
103#endif
104}
105
106#ifdef USB_DETECT_BY_DRV
107/* Cannot tell charger pin from USB pin */
108static int usb_status = USB_EXTRACTED;
109
110void usb_connect_event(bool inserted)
111{
112 usb_status = inserted ? USB_INSERTED : USB_EXTRACTED;
113 usb_status_event(inserted ? USB_POWERED : USB_UNPOWERED);
114}
115
116/* Called during the bus reset interrupt when in detect mode */
117void usb_drv_usb_detect_event(void)
118{
119 usb_status_event(USB_INSERTED);
120}
121#else /* !USB_DETECT_BY_DRV */
97static bool usb_pin_detect(void) 122static bool usb_pin_detect(void)
98{ 123{
99 bool retval = false; 124 bool retval = false;
@@ -110,12 +135,12 @@ static bool usb_pin_detect(void)
110 retval = true; 135 retval = true;
111 136
112#elif defined(SANSA_C200) 137#elif defined(SANSA_C200)
113 /* GPIO H bit 1 is usb detect */ 138 /* GPIO H bit 1 is usb/charger detect */
114 if (GPIOH_INPUT_VAL & 0x02) 139 if (GPIOH_INPUT_VAL & 0x02)
115 retval = true; 140 retval = true;
116 141
117#elif defined(SANSA_E200) 142#elif defined(SANSA_E200)
118 /* GPIO B bit 4 is usb detect */ 143 /* GPIO B bit 4 is usb/charger detect */
119 if (GPIOB_INPUT_VAL & 0x10) 144 if (GPIOB_INPUT_VAL & 0x10)
120 retval = true; 145 retval = true;
121 146
@@ -137,16 +162,32 @@ static bool usb_pin_detect(void)
137 162
138 return retval; 163 return retval;
139} 164}
165#endif /* USB_DETECT_BY_DRV */
140 166
141/* detect host or charger (INSERTED or POWERED) */ 167void usb_drv_int_enable(bool enable)
168{
169 /* enable/disable USB IRQ in CPU */
170 if(enable) {
171 CPU_INT_EN = USB_MASK;
172 }
173 else {
174 CPU_INT_DIS = USB_MASK;
175 }
176}
177
178/* detect host or charger (INSERTED or EXTRACTED) */
142int usb_detect(void) 179int usb_detect(void)
143{ 180{
181#ifdef USB_DETECT_BY_DRV
182 return usb_status;
183#else
144 if(usb_pin_detect()) { 184 if(usb_pin_detect()) {
145 return USB_INSERTED; 185 return USB_INSERTED;
146 } 186 }
147 else { 187 else {
148 return USB_EXTRACTED; 188 return USB_EXTRACTED;
149 } 189 }
190#endif
150} 191}
151 192
152#if defined(IPOD_COLOR) || defined(IPOD_4G) \ 193#if defined(IPOD_COLOR) || defined(IPOD_4G) \