17 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
19 #if defined( USB_DEVICE )
27 static int ClearFeature ( USBD_Device_TypeDef *pDev );
28 static int GetConfiguration ( USBD_Device_TypeDef *pDev );
29 static int GetDescriptor ( USBD_Device_TypeDef *pDev );
30 static int GetInterface ( USBD_Device_TypeDef *pDev );
31 static int GetStatus ( USBD_Device_TypeDef *pDev );
32 static int SetAddress ( USBD_Device_TypeDef *pDev );
33 static int SetConfiguration ( USBD_Device_TypeDef *pDev );
34 static int SetFeature ( USBD_Device_TypeDef *pDev );
35 static int SetInterface ( USBD_Device_TypeDef *pDev );
37 static uint32_t txBuf;
39 int USBDCH9_SetupCmd( USBD_Device_TypeDef *device )
45 if ( device->callbacks->setupCmd )
47 status = device->callbacks->setupCmd( p );
62 status = GetStatus( device );
66 status = ClearFeature( device );
70 status = SetFeature( device );
74 status = SetAddress( device );
78 status = GetDescriptor( device );
82 status = GetConfiguration( device );
86 status = SetConfiguration( device );
90 status = GetInterface( device );
94 status = SetInterface( device );
107 static int ClearFeature( USBD_Device_TypeDef *pDev )
121 if ( ( p->
wIndex == 0 ) &&
130 pDev->remoteWakeupEnabled =
false;
137 ep = USBD_GetEpFromAddr( p->
wIndex & 0xFF );
140 if ( ( ep->num > 0 ) &&
144 retVal = USBDHAL_UnStallEp( ep );
152 static int GetConfiguration( USBD_Device_TypeDef *pDev )
156 uint8_t *pConfigValue = (uint8_t*)&txBuf;
158 if ( ( p->
wIndex != 0 ) ||
170 retVal =
USBD_Write( 0, pConfigValue, 1, NULL );
175 retVal =
USBD_Write( 0, &pDev->configurationValue, 1, NULL );
181 static int GetDescriptor( USBD_Device_TypeDef *pDev )
185 const void *data = NULL;
203 data = pDev->deviceDescriptor;
204 length = pDev->deviceDescriptor->bLength;
212 data = pDev->configDescriptor;
213 length = pDev->configDescriptor->wTotalLength;
217 if ( index < pDev->numberOfStrings )
236 static int GetInterface( USBD_Device_TypeDef *pDev )
240 uint8_t *pAlternateSetting = (uint8_t*)&txBuf;
244 if ( ( p->
wIndex >= pDev->numberOfInterfaces ) ||
255 *pAlternateSetting = 0;
256 retVal =
USBD_Write( 0, pAlternateSetting, 1, NULL );
262 static int GetStatus( USBD_Device_TypeDef *pDev )
267 uint16_t *pStatus = (uint16_t*)&txBuf;
269 if ( ( p->
wValue != 0 ) ||
279 if ( ( p->
wIndex == 0 ) &&
286 if ( pDev->remoteWakeupEnabled )
290 if ( pDev->callbacks->isSelfPowered != NULL )
292 if ( pDev->callbacks->isSelfPowered() )
313 ( p->
wIndex < pDev->numberOfInterfaces ) ) )
321 ep = USBD_GetEpFromAddr( p->
wIndex & 0xFF );
325 ( ep->num == 0 ) ) ||
329 retVal = USBDHAL_GetStallStatusEp( ep, pStatus );
342 static int SetAddress( USBD_Device_TypeDef *pDev )
347 if ( ( p->
wIndex != 0 ) ||
361 USBDHAL_SetAddr( p->
wValue );
371 USBDHAL_SetAddr( p->
wValue );
378 static int SetConfiguration( USBD_Device_TypeDef *pDev )
383 if ( ( p->
wIndex != 0 ) ||
385 ( (p->
wValue>>8) != 0 ) ||
393 if ( ( p->
wValue == 0 ) ||
394 ( p->
wValue == pDev->configDescriptor->bConfigurationValue ) )
396 pDev->configurationValue = p->
wValue;
397 if ( p->
wValue == pDev->configDescriptor->bConfigurationValue )
399 USBD_ActivateAllEps(
true );
408 if ( ( p->
wValue == 0 ) ||
409 ( p->
wValue == pDev->configDescriptor->bConfigurationValue ) )
411 pDev->configurationValue = p->
wValue;
420 USBD_ActivateAllEps(
false );
429 static int SetFeature( USBD_Device_TypeDef *pDev )
444 if ( ( p->
wIndex == 0 ) &&
452 pDev->remoteWakeupEnabled =
true;
459 ep = USBD_GetEpFromAddr( p->
wIndex & 0xFF );
462 if ( ( ep->num > 0 ) &&
466 retVal = USBDHAL_StallEp( ep );
468 ep->state = D_EP_IDLE;
471 ( ep->state != D_EP_IDLE ) &&
472 ( ep->xferCompleteCb ) )
474 callback = ep->xferCompleteCb;
475 ep->xferCompleteCb = NULL;
476 DEBUG_USB_API_PUTS(
"\nEP cb(), EP stalled" );
486 static int SetInterface( USBD_Device_TypeDef *pDev )
493 if ( ( p->
wIndex < pDev->numberOfInterfaces ) &&
500 USBD_ActivateAllEps(
false );
USB protocol stack library API for EFM32/EZR32.
#define SET_CONFIGURATION
#define USB_STRING_DESCRIPTOR
#define USB_SETUP_RECIPIENT_ENDPOINT
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define DEVICE_IS_SELFPOWERED
#define CONFIG_DESC_BM_REMOTEWAKEUP
#define GET_CONFIGURATION
USB Setup request package.
int(* USB_XferCompleteCb_TypeDef)(USB_Status_TypeDef status, uint32_t xferred, uint32_t remaining)
USB transfer callback function.
#define USB_DEVICE_DESCRIPTOR
USB protocol stack library API for EFM32/EZR32.
#define REMOTE_WAKEUP_ENABLED
#define USB_SETUP_RECIPIENT_DEVICE
#define USB_SETUP_RECIPIENT_INTERFACE
#define USB_SETUP_TYPE_STANDARD
int USBD_Write(int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback)
Start a write (IN) transfer on an endpoint.
#define CONFIG_DESC_BM_SELFPOWERED
#define USB_FEATURE_ENDPOINT_HALT
USB protocol stack library, low level USB peripheral access.
#define SL_MIN(a, b)
Macro for getting minimum value. No sideeffects, a and b are evaluated once only. ...
#define USB_CONFIG_DESCRIPTOR
#define USB_FEATURE_DEVICE_REMOTE_WAKEUP
USB protocol stack library, internal type definitions.