diff options
Diffstat (limited to 'firmware/target/arm/usb-fw-pp502x.c')
-rw-r--r-- | firmware/target/arm/usb-fw-pp502x.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/firmware/target/arm/usb-fw-pp502x.c b/firmware/target/arm/usb-fw-pp502x.c index 883ca1e8e2..cf5a82f37c 100644 --- a/firmware/target/arm/usb-fw-pp502x.c +++ b/firmware/target/arm/usb-fw-pp502x.c | |||
@@ -177,6 +177,11 @@ void usb_attach(void) | |||
177 | usb_drv_attach(); | 177 | usb_drv_attach(); |
178 | } | 178 | } |
179 | 179 | ||
180 | static bool usb_pin_state(void) | ||
181 | { | ||
182 | return (USB_GPIO_INPUT_VAL & USB_GPIO_MASK) == USB_GPIO_VAL; | ||
183 | } | ||
184 | |||
180 | #ifdef USB_STATUS_BY_EVENT | 185 | #ifdef USB_STATUS_BY_EVENT |
181 | /* Cannot always tell power pin from USB pin */ | 186 | /* Cannot always tell power pin from USB pin */ |
182 | static int usb_status = USB_EXTRACTED; | 187 | static int usb_status = USB_EXTRACTED; |
@@ -197,10 +202,13 @@ void usb_insert_int(void) | |||
197 | timeout_register(&usb_oneshot, usb_timeout_event, HZ/5, val); | 202 | timeout_register(&usb_oneshot, usb_timeout_event, HZ/5, val); |
198 | } | 203 | } |
199 | 204 | ||
200 | /* Called during the bus reset interrupt when in detect mode */ | 205 | /* Called during the bus reset interrupt when in detect mode - filter for |
206 | * invalid bus reset when unplugging by checking the pin state. */ | ||
201 | void usb_drv_usb_detect_event(void) | 207 | void usb_drv_usb_detect_event(void) |
202 | { | 208 | { |
203 | usb_status_event(USB_INSERTED); | 209 | if(usb_pin_state()) { |
210 | usb_status_event(USB_INSERTED); | ||
211 | } | ||
204 | } | 212 | } |
205 | #endif /* USB_STATUS_BY_EVENT */ | 213 | #endif /* USB_STATUS_BY_EVENT */ |
206 | 214 | ||
@@ -221,8 +229,7 @@ int usb_detect(void) | |||
221 | #ifdef USB_STATUS_BY_EVENT | 229 | #ifdef USB_STATUS_BY_EVENT |
222 | return usb_status; | 230 | return usb_status; |
223 | #else | 231 | #else |
224 | return ((USB_GPIO_INPUT_VAL & USB_GPIO_MASK) == USB_GPIO_VAL) ? | 232 | return usb_pin_state() ? USB_INSERTED : USB_EXTRACTED; |
225 | USB_INSERTED : USB_EXTRACTED; | ||
226 | #endif | 233 | #endif |
227 | } | 234 | } |
228 | 235 | ||