A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://arm-software.github.io/CMSIS_5/Driver/html/group__usbd__interface__gr.html below:

USB Device Interface

Driver API for USB Device Peripheral (Driver_USBD.h) More...

Driver API for USB Device Peripheral (Driver_USBD.h)

USB Device API

The header file Driver_USBD.h defines the API for the USB Device Driver interface used by middleware components. The driver implementation itself is a typical part of the Device Family Pack, which provides entry points to the interface as function pointers in the struct ARM_DRIVER_USBD. This structure can be available several times in each interface to control multiple USBD interfaces.

Header file Driver_USBD.h also defines callback routines that can be categorized as device event callbacks and endpoint event callbacks. Callbacks are called by the driver, in interrupt context when an appropriate event occurs, to signal device related events (USBD Device Events) and endpoint related events (USBD Endpoint Events).

USB Device Function Call Sequence

To use the USBD driver invoke the API functions in the following order:

Access structure of the USB Device Driver.

The functions of the USB Device driver are accessed by function pointers. Refer to Common Driver Functions for overview information.

Each instance of an USBD provides such an access struct. The instance is indicated by a postfix in the symbol name of the access struct, for example:

A configuration setting in the middleware allows connecting the middleware to a specific driver instance Driver_USBDn. The default is 0, which connects a middleware to the first instance of a driver.

Note
The struct must remain unchanged.
int32_t(* ReadSetupPacket)(uint8_t *setup)

Pointer to ARM_USBD_ReadSetupPacket : Read setup packet received over Control Endpoint.

int32_t(* EndpointConfigure)(uint8_t ep_addr, uint8_t ep_type, uint16_t ep_max_packet_size)

Pointer to ARM_USBD_EndpointConfigure : Configure USB Endpoint.

int32_t(* EndpointStall)(uint8_t ep_addr, bool stall)

Pointer to ARM_USBD_EndpointStall : Set/Clear Stall for USB Endpoint.

int32_t(* EndpointTransfer)(uint8_t ep_addr, uint8_t *data, uint32_t num)

Pointer to ARM_USBD_EndpointTransfer : Read data from or Write data to USB Endpoint.

struct ARM_USBD_CAPABILITIES

USB Device Driver Capabilities.

A USB Device driver can be implemented with different capabilities. The data fields of this structure encode the capabilities implemented by this driver.

Returned by:

Note
The struct must remain unchanged.
Data Fields uint32_t vbus_detection: 1 VBUS detection. uint32_t event_vbus_on: 1 Signal VBUS On event. uint32_t event_vbus_off: 1 Signal VBUS Off event. uint32_t reserved: 29 Reserved (must be zero)

USB Device State.

This structure stores information about the state of the USB Device. The data fields encode the established speed, whether the device is powered and active.

Returned by:

Data Fields uint32_t vbus: 1 USB Device VBUS flag. uint32_t speed: 2 USB Device speed setting (ARM_USB_SPEED_xxx) uint32_t active: 1 USB Device active flag. uint32_t reserved: 28 ARM_USBD_SignalDeviceEvent_t ARM_USBD_SignalEndpointEvent_t

Get driver version.

Returns
ARM_DRIVER_VERSION

The function ARM_USBD_GetVersion returns version information of the driver implementation in ARM_DRIVER_VERSION

Example:

void setup_usbd (void) {

drv_info = &Driver_USBD0;

if

(version.

api

< 0x10A) {

return;

}

}

Get driver capabilities.

Returns
ARM_USBD_CAPABILITIES

The function ARM_USBD_GetCapabilities returns information about capabilities in this driver implementation. The data fields of the structure ARM_USBD_CAPABILITIES encode various capabilities, for example if the hardware can create signal events using the ARM_USBD_SignalDeviceEvent callback function.

Example:

void read_capabilities (void) {

drv_info = &Driver_USBD0;

}

Initialize USB Device Interface.

Parameters
Returns
Status Error Codes

The function ARM_USBD_Initialize initializes the USB Device interface. It is called when the middleware component starts operation.

The function performs the following operations:

The parameter cb_device_event is a pointer to the ARM_USBD_SignalDeviceEvent callback function; use a NULL pointer when no device callback signals are required.
The parameter cb_endpoint_event is a pointer to the ARM_USBD_SignalEndpointEvent callback function.

Example:

int32_t ARM_USBD_Uninitialize ( void  )

De-initialize USB Device Interface.

Returns
Status Error Codes

The function ARM_USBD_Uninitialize de-initializes the resources of USBD interface.

It is called when the middleware component stops operation and releases the software resources used by the interface.

Control USB Device Interface Power.

Parameters
Returns
Status Error Codes

The function ARM_USBD_PowerControl operates the power modes of the USB Device interface.

The parameter state sets the operation and can have the following values:

Refer to Function Call Sequence for more information.

int32_t ARM_USBD_DeviceConnect ( void  )

Connect USB Device.

Returns
Status Error Codes

The function ARM_USBD_DeviceConnect signals to the host that the device is connected.

int32_t ARM_USBD_DeviceDisconnect ( void  )

Disconnect USB Device.

Returns
Status Error Codes

The function ARM_USBD_DeviceDisconnect signals to the host that the device is disconnected.

Get current USB Device State.

Returns
Device State ARM_USBD_STATE

Retrieves the current USB device state.

int32_t ARM_USBD_DeviceRemoteWakeup ( void  )

Trigger USB Remote Wakeup.

Returns
Status Error Codes

The function ARM_USBD_DeviceRemoteWakeup signals remote wakeup to the host.

int32_t ARM_USBD_DeviceSetAddress ( uint8_t  dev_addr )

Set USB Device Address.

Parameters
[in] dev_addr Device Address
Returns
Status Error Codes

Assigns an address to the device.

Note
This function is called after status stage of the Set Address request (after IN packet in status stage was sent with the old address).
int32_t ARM_USBD_ReadSetupPacket ( uint8_t *  setup )

Read setup packet received over Control Endpoint.

Parameters
[out] setup Pointer to buffer for setup packet
Returns
Status Error Codes

The function ARM_USBD_ReadSetupPacket reads the last SETUP packet (8 bytes) that was received over Control Endpoint (Endpoint 0) which is indicated by ARM_USBD_EVENT_SETUP event.

See also:

int32_t ARM_USBD_EndpointConfigure ( uint8_t  ep_addr, uint8_t  ep_type, uint16_t  ep_max_packet_size  )

Configure USB Endpoint.

Parameters
[in] ep_addr Endpoint Address [in] ep_type Endpoint Type (ARM_USB_ENDPOINT_xxx) [in] ep_max_packet_size Endpoint Maximum Packet Size
Returns
Status Error Codes

The function ARM_USBD_EndpointConfigure configures an endpoint for transfers.

int32_t ARM_USBD_EndpointUnconfigure ( uint8_t  ep_addr )

Unconfigure USB Endpoint.

Parameters
[in] ep_addr Endpoint Address
Returns
Status Error Codes

The function ARM_USBD_EndpointUnconfigure de-configures the specified endpoint.

The parameter ep_addr specifies the endpoint address.

int32_t ARM_USBD_EndpointStall ( uint8_t  ep_addr, bool  stall  )

Set/Clear Stall for USB Endpoint.

Parameters
[in] ep_addr Endpoint Address [in] stall Operation
Returns
Status Error Codes

The function ARM_USBD_EndpointStall sets or clears stall condition for the specified endpoint.

The parameter ep_addr specifies the endpoint address.
The parameter stall is a boolean parameter.

int32_t ARM_USBD_EndpointTransfer ( uint8_t  ep_addr, uint8_t *  data, uint32_t  num  )

Read data from or Write data to USB Endpoint.

Parameters
[in] ep_addr Endpoint Address [out] data Pointer to buffer for data to read or with data to write [in] num Number of data bytes to transfer
Returns
Status Error Codes

The function ARM_USBD_EndpointTransfer reads from or writes data to an USB Endpoint.

The parameter ep_addr specifies the endpoint address.
The parameter data is a buffer for data to read or data to write.
The parameter num is the number of bytes to transfer (must be multiple of endpoint maximum packet size for Read transfers).

The function is non-blocking and returns as soon as the driver starts the operation on the specified endpoint. During the operation it is not allowed to call this function again on the same endpoint. Also the data buffer must stay allocated and the contents of data must not be modified.

Direction in the endpoint address specifies the type of transfer:

Endpoint Read is finished when the requested number of data bytes have been received or when a short packet or ZLP (Zero-Length Packet) has been received. Completion of operation is indicated by ARM_USBD_EVENT_OUT event. Number of successfully received data bytes can be retrieved by calling ARM_USBD_EndpointTransferGetResult.

Endpoint Write is finished when the requested number of data bytes have been sent. Completion of operation is indicated by ARM_USBD_EVENT_IN event. Number of successfully sent data bytes can be retrieved by calling ARM_USBD_EndpointTransferGetResult.

Transfer operation can be aborted by calling ARM_USBD_EndpointTransferAbort.

uint32_t ARM_USBD_EndpointTransferGetResult ( uint8_t  ep_addr )

Get result of USB Endpoint transfer.

Parameters
[in] ep_addr Endpoint Address
Returns
number of successfully transferred data bytes

The function ARM_USBD_EndpointTransferGetResult returns the number of successfully transferred data bytes started by ARM_USBD_EndpointTransfer.

The parameter ep_addr specifies the endpoint address.

int32_t ARM_USBD_EndpointTransferAbort ( uint8_t  ep_addr )

Abort current USB Endpoint transfer.

Parameters
[in] ep_addr Endpoint Address
Returns
Status Error Codes

The function ARM_USBD_EndpointTransferAbort aborts the transfer to an endpoint started by ARM_USBD_EndpointTransfer.

The parameter ep_addr specifies the endpoint address.

uint16_t ARM_USBD_GetFrameNumber ( void  )

Get current USB Frame Number.

Returns
Frame Number

Retrieves the sequential 11-bit frame number of the last Start of Frame (SOF) packet.

void ARM_USBD_SignalDeviceEvent ( uint32_t  event )

Signal USB Device Event.

Parameters
Returns
none

The function ARM_USBD_SignalDeviceEvent is a callback function registered by the function ARM_USBD_Initialize.

The parameter event indicates one or more events that occurred during driver operation. Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.

Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the data fields of the structure ARM_USBD_CAPABILITIES, which can be retrieved with the function ARM_USBD_GetCapabilities.

The following events can be generated:

void ARM_USBD_SignalEndpointEvent ( uint8_t  ep_addr, uint32_t  event  )

Signal USB Endpoint Event.

Parameters
[in] ep_addr Endpoint Address [in] event USBD Endpoint Events
Returns
none

The function ARM_USBD_SignalEndpointEvent is a callback function registered by the function ARM_USBD_Initialize.

The argument ep_addr specifies the endpoint.
The parameter event indicates one or more events that occurred during driver operation. Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.

The following events can be generated:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4