From 957d7bd94246e2292256fc5869a3320363ab15d9 Mon Sep 17 00:00:00 2001 From: Mikko Polojarvi Date: Wed, 22 Jul 2015 16:17:03 +0300 Subject: [PATCH] Silicon Labs USB device support - Wonder, Leopard, Happy USB device support for Wonder, Leopard and Happy Gecko. See details on configuration etc on the previous commit. Known issue: USBAudio does not work reliably on Happy Gecko. --- .../TARGET_Silicon_Labs/src/em_usbdep.c | 28 +++++++++++++++++++ .../TARGET_Silicon_Labs/src/em_usbdint.c | 27 ++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/libraries/USBDevice/USBDevice/TARGET_Silicon_Labs/src/em_usbdep.c b/libraries/USBDevice/USBDevice/TARGET_Silicon_Labs/src/em_usbdep.c index 8b3755badb..ac87088dba 100644 --- a/libraries/USBDevice/USBDevice/TARGET_Silicon_Labs/src/em_usbdep.c +++ b/libraries/USBDevice/USBDevice/TARGET_Silicon_Labs/src/em_usbdep.c @@ -234,6 +234,33 @@ void USBDEP_Ep0Handler( USBD_Device_TypeDef *device ) static uint32_t xferred; static USB_XferCompleteCb_TypeDef callback; +#ifdef __MBED__ + + (void)xferred; + (void)status; + + ep = &device->ep[ 0 ]; + + if ( ( ep->state == D_EP_TRANSMITTING ) || ( ep->state == D_EP_RECEIVING ) ) + { + ep->state = D_EP_IDLE; + + if ( ep->xferCompleteCb ) + { + callback = ep->xferCompleteCb; + ep->xferCompleteCb = NULL; + callback( USB_STATUS_OK, ep->xferred, ep->remaining ); + } + + USBDHAL_ReenableEp0Setup(device); + } + else + { + device->callbacks->setupCmd(device->setup); + } + +#else + ep = &device->ep[ 0 ]; switch ( ep->state ) @@ -376,6 +403,7 @@ void USBDEP_Ep0Handler( USBD_Device_TypeDef *device ) ep->in = false; /* OUT for next SETUP */ break; } +#endif /* __MBED__ */ } #endif diff --git a/libraries/USBDevice/USBDevice/TARGET_Silicon_Labs/src/em_usbdint.c b/libraries/USBDevice/USBDevice/TARGET_Silicon_Labs/src/em_usbdint.c index 230e17e77c..00cf493aff 100644 --- a/libraries/USBDevice/USBDevice/TARGET_Silicon_Labs/src/em_usbdint.c +++ b/libraries/USBDevice/USBDevice/TARGET_Silicon_Labs/src/em_usbdint.c @@ -846,6 +846,32 @@ retry: } else /* ep0state != EP0_IDLE */ { +#ifdef __MBED__ + if ( ep->state == D_EP_RECEIVING ) + { + int xfer_size = ep->packetSize - (( USB->DOEP0TSIZ & _USB_DOEP0TSIZ_XFERSIZE_MASK ) + >> _USB_DOEP0TSIZ_XFERSIZE_SHIFT); + int setup_pkt_received = status & USB_DOEP0INT_SETUP; + + if ( (!setup_pkt_received && xfer_size == 0) || + (setup_pkt_received && xfer_size == 8) ) + { + /* Higher levels need to see the correct transfer amount for ZLPs */ + ep->remaining = 0; + ep->xferred = 0; + } + else + { + /* FIXME - does not work if actual read size > 56 */ + if ( setup_pkt_received ) xfer_size -= 8; + + ep->xferred = xfer_size; + ep->remaining -= xfer_size; + } + + USBDEP_Ep0Handler( dev ); + } +#else if ( ep->state == D_EP_RECEIVING ) { if ( ep->remaining > ep->packetSize ) @@ -864,6 +890,7 @@ retry: { USBDEP_Ep0Handler( dev ); } +#endif } } /* if ( status & USB_DOEP0INT_XFERCOMPL ) */