mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-05-12 19:53:18 -04:00
Convert AMS target USB detection to event-based (no more polling in a tick). Seems well on my Clip v1 and Fuze v2.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29156 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
70b99e3e2c
commit
3f709eada2
2 changed files with 64 additions and 29 deletions
|
|
@ -721,15 +721,19 @@ Lyre prototype 1 */
|
|||
|
||||
#define HAVE_SEMAPHORE_OBJECTS
|
||||
|
||||
#if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_ARC
|
||||
#ifdef HAVE_USBSTACK
|
||||
#if CONFIG_USBOTG == USBOTG_ARC
|
||||
#define USB_STATUS_BY_EVENT
|
||||
#define USB_DETECT_BY_DRV
|
||||
#define INCLUDE_TIMEOUT_API
|
||||
#endif /* HAVE_USBSTACK && USBOTG_ARC */
|
||||
|
||||
#if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_AS3525
|
||||
#elif CONFIG_USBOTG == USBOTG_AS3525
|
||||
#define USB_STATUS_BY_EVENT
|
||||
#define USB_DETECT_BY_DRV
|
||||
#endif /* HAVE_USBSTACK && USBOTG_AS3525 */
|
||||
#elif CONFIG_USBOTG == USBOTG_AS3525v2
|
||||
#define USB_STATUS_BY_EVENT
|
||||
#define USB_DETECT_BY_CORE
|
||||
#endif /* CONFIG_USB == */
|
||||
#endif /* HAVE_USBSTACK */
|
||||
|
||||
#endif /* BOOTLOADER */
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,8 @@
|
|||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
#include "usb.h"
|
||||
#ifdef HAVE_USBSTACK
|
||||
#include "usb_core.h"
|
||||
|
|
@ -29,8 +28,40 @@
|
|||
#include "power.h"
|
||||
#include "as3525.h"
|
||||
|
||||
static bool bus_activity = 0;
|
||||
static bool connected = 0;
|
||||
static int usb_status = USB_EXTRACTED;
|
||||
|
||||
#if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB)
|
||||
/* Rebooting on USB plug can crash these players in a state where
|
||||
* hardware power off (pressing the power button) doesn't work anymore
|
||||
* TODO: Implement USB in rockbox for these players */
|
||||
#define USB_INSERT_INT_STATUS USB_EXTRACTED
|
||||
#undef USB_DETECT_BY_DRV
|
||||
#undef USB_DETECT_BY_CORE
|
||||
#undef USB_STATUS_BY_EVENT
|
||||
|
||||
#else /* !AS3525v2 */
|
||||
|
||||
#if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE)
|
||||
|
||||
#ifdef USB_STATUS_BY_EVENT
|
||||
#define USB_INSERT_INT_STATUS USB_INSERTED
|
||||
#define USB_INSERT_INT_EVENT USB_POWERED
|
||||
#define USB_REMOVE_INT_EVENT USB_UNPOWERED
|
||||
#else
|
||||
#define USB_INSERT_INT_STATUS USB_POWERED
|
||||
#endif /* USB_STATUS_BY_EVENT */
|
||||
|
||||
#else /* !USB_DETECT_BY_* */
|
||||
|
||||
#define USB_INSERT_INT_STATUS USB_INSERTED
|
||||
#ifdef USB_STATUS_BY_EVENT
|
||||
#define USB_INSERT_INT_EVENT USB_INSERTED
|
||||
#define USB_REMOVE_INT_EVENT USB_EXTRACTED
|
||||
#endif /* USB_STATUS_BY_EVENT */
|
||||
|
||||
#endif /* USB_DETECT_BY_* */
|
||||
|
||||
#endif /* AS3525v2 */
|
||||
|
||||
void usb_enable(bool on)
|
||||
{
|
||||
|
|
@ -46,36 +77,36 @@ void usb_enable(bool on)
|
|||
|
||||
void usb_insert_int(void)
|
||||
{
|
||||
connected = 1;
|
||||
usb_status = USB_INSERT_INT_STATUS;
|
||||
#ifdef USB_STATUS_BY_EVENT
|
||||
usb_status_event(USB_INSERT_INT_EVENT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void usb_remove_int(void)
|
||||
{
|
||||
connected = 0;
|
||||
bus_activity = 0;
|
||||
usb_status = USB_EXTRACTED;
|
||||
#ifdef USB_STATUS_BY_EVENT
|
||||
usb_status_event(USB_REMOVE_INT_EVENT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void usb_drv_usb_detect_event(void)
|
||||
{
|
||||
/* Bus activity seen */
|
||||
bus_activity = 1;
|
||||
#if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE)
|
||||
int oldstatus = disable_irq_save(); /* May come via USB thread */
|
||||
if (usb_status == USB_INSERT_INT_STATUS)
|
||||
{
|
||||
usb_status = USB_INSERTED;
|
||||
#ifdef USB_STATUS_BY_EVENT
|
||||
usb_status_event(USB_INSERTED);
|
||||
#endif
|
||||
}
|
||||
restore_irq(oldstatus);
|
||||
#endif /* USB_DETECT_BY_* */
|
||||
}
|
||||
|
||||
int usb_detect(void)
|
||||
{
|
||||
#if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB)
|
||||
/* Rebooting on USB plug can crash these players in a state where
|
||||
* hardware power off (pressing the power button) doesn't work anymore
|
||||
* TODO: Implement USB in rockbox for these players */
|
||||
return USB_EXTRACTED;
|
||||
#elif defined(USB_DETECT_BY_DRV)
|
||||
if(bus_activity && connected)
|
||||
return USB_INSERTED;
|
||||
else if(connected)
|
||||
return USB_POWERED;
|
||||
else
|
||||
return USB_UNPOWERED;
|
||||
#else
|
||||
return connected?USB_INSERTED:USB_EXTRACTED;
|
||||
#endif
|
||||
return usb_status;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue