EFM32 Wonder Gecko Software Documentation
efm32wg-doc-4.2.1
|
USB DEVICE protocol stack, see USB device stack library page for detailed documentation.
. More...
Data Structures | |
struct | USBD_Init_TypeDef |
USB Device stack initialization structure. More... | |
struct | USBD_Callbacks_TypeDef |
USB Device stack callback structure. More... | |
Macros | |
#define | USB_PWRSAVE_MODE_OFF 0 |
#define | USB_PWRSAVE_MODE_ONSUSPEND 1 |
#define | USB_PWRSAVE_MODE_ONVBUSOFF 2 |
#define | USB_PWRSAVE_MODE_ENTEREM2 4 |
#define | USB_USBC_32kHz_CLK_LFXO 0 |
#define | USB_USBC_32kHz_CLK_LFRCO 1 |
Typedefs | |
typedef void(* | USBD_UsbResetCb_TypeDef) (void) |
USB Reset callback function. More... | |
typedef void(* | USBD_SofIntCb_TypeDef) (uint16_t sofNr) |
USB Start Of Frame (SOF) interrupt callback function. More... | |
typedef void(* | USBD_DeviceStateChangeCb_TypeDef) (USBD_State_TypeDef oldState, USBD_State_TypeDef newState) |
USB State change callback function. More... | |
typedef bool(* | USBD_IsSelfPoweredCb_TypeDef) (void) |
USB power mode callback function. More... | |
typedef int(* | USBD_SetupCmdCb_TypeDef) (const USB_Setup_TypeDef *setup) |
USB setup request callback function. More... | |
typedef struct USBD_Callbacks_TypeDef | USBD_Callbacks_TypeDef |
USB Device stack callback structure. More... | |
Enumerations | |
enum | USBD_State_TypeDef { USBD_STATE_NONE = 0, USBD_STATE_ATTACHED = 1, USBD_STATE_POWERED = 2, USBD_STATE_DEFAULT = 3, USBD_STATE_ADDRESSED = 4, USBD_STATE_CONFIGURED = 5, USBD_STATE_SUSPENDED = 6, USBD_STATE_LASTMARKER = 7 } |
USB device state enumerator. More... | |
Functions | |
void | USBD_AbortAllTransfers (void) |
Abort all pending transfers. More... | |
int | USBD_AbortTransfer (int epAddr) |
Abort a pending transfer on a specific endpoint. More... | |
void | USBD_Connect (void) |
Start USB device operation. More... | |
void | USBD_Disconnect (void) |
Stop USB device operation. More... | |
bool | USBD_EpIsBusy (int epAddr) |
Check if an endpoint is busy doing a transfer. More... | |
USBD_State_TypeDef | USBD_GetUsbState (void) |
Get current USB device state. More... | |
const char * | USBD_GetUsbStateName (USBD_State_TypeDef state) |
Get a string naming a device USB state. More... | |
int | USBD_Init (const USBD_Init_TypeDef *p) |
Initializes USB device hardware and internal protocol stack data structures, then connects the data-line (D+ or D-) pullup resistor to signal host that enumeration can begin. More... | |
int | USBD_Read (int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback) |
Start a read (OUT) transfer on an endpoint. More... | |
int | USBD_RemoteWakeup (void) |
Perform a remote wakeup signalling sequence. More... | |
bool | USBD_SafeToEnterEM2 (void) |
Check if it is ok to enter energy mode EM2. More... | |
int | USBD_StallEp (int epAddr) |
Set an endpoint in the stalled (halted) state. More... | |
void | USBD_Stop (void) |
Stop USB device stack operation. More... | |
int | USBD_UnStallEp (int epAddr) |
Reset stall state on a stalled (halted) endpoint. More... | |
int | USBD_Write (int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback) |
Start a write (IN) transfer on an endpoint. More... | |
#define USB_PWRSAVE_MODE_OFF 0 |
#define USB_PWRSAVE_MODE_ONSUSPEND 1 |
#define USB_PWRSAVE_MODE_ONVBUSOFF 2 |
#define USB_PWRSAVE_MODE_ENTEREM2 4 |
#define USB_USBC_32kHz_CLK_LFXO 0 |
#define USB_USBC_32kHz_CLK_LFRCO 1 |
typedef void(* USBD_UsbResetCb_TypeDef) (void) |
typedef void(* USBD_SofIntCb_TypeDef) (uint16_t sofNr) |
typedef void(* USBD_DeviceStateChangeCb_TypeDef) (USBD_State_TypeDef oldState, USBD_State_TypeDef newState) |
Called whenever the device change state.
[in] | oldState | The device USB state just leaved. See USBD_State_TypeDef. |
[in] | newState | New (the current) USB device state. See USBD_State_TypeDef. |
typedef bool(* USBD_IsSelfPoweredCb_TypeDef) (void) |
Called whenever the device stack needs to query if the device is currently self- or bus-powered. Typically when host has issued an GET_STATUS setup command.
typedef int(* USBD_SetupCmdCb_TypeDef) (const USB_Setup_TypeDef *setup) |
Called on each setup request received from host. This gives the application a possibility to extend or override standard requests, and to implement class or vendor specific requests. Return USB_STATUS_OK if the request is handled, return USB_STATUS_REQ_ERR if it is an illegal request or return USB_STATUS_REQ_UNHANDLED to pass the request on to the default request handler.
[in] | setup | Pointer to an USB setup packet. See USB_Setup_TypeDef. |
typedef struct USBD_Callbacks_TypeDef USBD_Callbacks_TypeDef |
Callback functions used by the device stack to signal events or query status to/from the application. See USBD_Init_TypeDef. Assign members to NULL if your application don't need a specific callback.
enum USBD_State_TypeDef |
void USBD_AbortAllTransfers | ( | void | ) |
Aborts transfers for all endpoints currently in use. Pending transfers on the default endpoint (EP0) are not aborted.
Definition at line 53 of file em_usbd.c.
References INT_Disable(), INT_Enable(), and USB_STATUS_EP_ABORTED.
int USBD_AbortTransfer | ( | int | epAddr | ) |
[in] | epAddr | The address of the endpoint to abort. |
Definition at line 67 of file em_usbd.c.
References INT_Disable(), INT_Enable(), USB_STATUS_EP_ABORTED, USB_STATUS_ILLEGAL, USB_STATUS_OK, USBD_STATE_ADDRESSED, and USBD_STATE_CONFIGURED.
void USBD_Connect | ( | void | ) |
Device operation is started by connecting a pullup resistor on the appropriate USB data line.
Definition at line 123 of file em_usbd.c.
References INT_Disable(), and INT_Enable().
void USBD_Disconnect | ( | void | ) |
Device operation is stopped by disconnecting the pullup resistor from the appropriate USB data line. Often referred to as a "soft" disconnect.
Definition at line 138 of file em_usbd.c.
References INT_Disable(), and INT_Enable().
Referenced by USBD_Stop().
bool USBD_EpIsBusy | ( | int | epAddr | ) |
[in] | epAddr | The address of the endpoint to check. |
Definition at line 155 of file em_usbd.c.
References USB_STATUS_ILLEGAL.
USBD_State_TypeDef USBD_GetUsbState | ( | void | ) |
Definition at line 179 of file em_usbd.c.
Referenced by USBD_Read(), and USBD_Write().
const char* USBD_GetUsbStateName | ( | USBD_State_TypeDef | state | ) |
[in] | state | Device USB state. See USBD_State_TypeDef. |
Definition at line 194 of file em_usbd.c.
References USBD_STATE_LASTMARKER.
int USBD_Init | ( | const USBD_Init_TypeDef * | p | ) |
[in] | p | Pointer to device initialization struct. See USBD_Init_TypeDef. |
Definition at line 218 of file em_usbd.c.
References _USB_DOEP0CTL_MPS_32B, _USB_DOEP0CTL_MPS_64B, USB_InterfaceDescriptor_TypeDef::bAlternateSetting, USB_EndpointDescriptor_TypeDef::bEndpointAddress, USB_InterfaceDescriptor_TypeDef::bInterfaceNumber, USB_EndpointDescriptor_TypeDef::bmAttributes, USB_DeviceDescriptor_TypeDef::bMaxPacketSize0, USBD_Init_TypeDef::bufferingMultiplier, USBD_Init_TypeDef::callbacks, CMU, CMU_ClockEnable(), CMU_ClockSelectGet(), CMU_ClockSelectSet(), CMU_HFCORECLKEN0_USB, CMU_HFCORECLKEN0_USBC, CMU_OscillatorEnable(), cmuClock_CORELE, cmuClock_HF, cmuClock_USBC, cmuOsc_LFRCO, cmuOsc_LFXO, cmuSelect_HFCLK, cmuSelect_HFXO, cmuSelect_LFRCO, cmuSelect_LFXO, CONFIG_DESC_BM_TRANSFERTYPE, USBD_Init_TypeDef::configDescriptor, USBD_Init_TypeDef::deviceDescriptor, INT_Disable(), INT_Enable(), USBD_Init_TypeDef::numberOfStrings, USBD_Init_TypeDef::stringDescriptors, USB, USB_ENDPOINT_DESCRIPTOR, USB_EPNUM_MASK, USB_EPTYPE_CTRL, USB_INTERFACE_DESCRIPTOR, USB_IRQn, USB_SETUP_DIR_MASK, USB_STATUS_ILLEGAL, USB_STATUS_OK, USBD_STATE_LASTMARKER, USBD_STATE_NONE, USBD_STATE_POWERED, USBTIMER_Init(), and USB_EndpointDescriptor_TypeDef::wMaxPacketSize.
int USBD_Read | ( | int | epAddr, |
void * | data, | ||
int | byteCount, | ||
USB_XferCompleteCb_TypeDef | callback | ||
) |
[in] | epAddr | Endpoint address. |
[in] | data | Pointer to transfer data buffer. |
[in] | byteCount | Transfer length. |
[in] | callback | Function to be called on transfer completion. Supply NULL if no callback is needed. See USB_XferCompleteCb_TypeDef. |
Definition at line 545 of file em_usbd.c.
References INT_Disable(), INT_Enable(), USB_STATUS_DEVICE_UNCONFIGURED, USB_STATUS_EP_BUSY, USB_STATUS_EP_STALLED, USB_STATUS_ILLEGAL, USB_STATUS_OK, USBD_GetUsbState(), and USBD_STATE_CONFIGURED.
Referenced by CDC_SetupCmd(), CDC_StateChangeEvent(), and HIDKBD_SetupCmd().
int USBD_RemoteWakeup | ( | void | ) |
Definition at line 631 of file em_usbd.c.
References INT_Disable(), INT_Enable(), USB_STATUS_ILLEGAL, USB_STATUS_OK, USBD_STATE_SUSPENDED, and USBTIMER_DelayMs().
bool USBD_SafeToEnterEM2 | ( | void | ) |
int USBD_StallEp | ( | int | epAddr | ) |
[in] | epAddr | The address of the endpoint to stall. |
Definition at line 708 of file em_usbd.c.
References INT_Disable(), INT_Enable(), USB_STATUS_ILLEGAL, and USB_STATUS_OK.
Referenced by MSDD_Handler().
void USBD_Stop | ( | void | ) |
The data-line pullup resistor is turned off, USB interrupts are disabled, and finally the USB pins are disabled.
Definition at line 747 of file em_usbd.c.
References CMU, CMU_HFCORECLKEN0_USB, CMU_HFCORECLKEN0_USBC, USB_IRQn, USBD_Disconnect(), and USBD_STATE_NONE.
int USBD_UnStallEp | ( | int | epAddr | ) |
[in] | epAddr | The address of the endpoint to un-stall. |
Definition at line 769 of file em_usbd.c.
References INT_Disable(), INT_Enable(), USB_STATUS_ILLEGAL, and USB_STATUS_OK.
Referenced by MSDD_SetupCmd().
int USBD_Write | ( | int | epAddr, |
void * | data, | ||
int | byteCount, | ||
USB_XferCompleteCb_TypeDef | callback | ||
) |
[in] | epAddr | Endpoint address. |
[in] | data | Pointer to transfer data buffer. This buffer must be WORD (4 byte) aligned. |
[in] | byteCount | Transfer length. |
[in] | callback | Function to be called on transfer completion. Supply NULL if no callback is needed. See USB_XferCompleteCb_TypeDef. |
Definition at line 820 of file em_usbd.c.
References INT_Disable(), INT_Enable(), USB_STATUS_DEVICE_UNCONFIGURED, USB_STATUS_EP_BUSY, USB_STATUS_EP_STALLED, USB_STATUS_ILLEGAL, USB_STATUS_OK, USBD_GetUsbState(), and USBD_STATE_CONFIGURED.
Referenced by CDC_SetupCmd(), HIDKBD_KeyboardEvent(), HIDKBD_SetupCmd(), and MSDD_SetupCmd().