Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
USB Device Controller API

USB Device Controller API. More...

Data Structures

struct  usb_dc_ep_cfg_data
 USB Endpoint Configuration. More...
 

Typedefs

typedef void(* usb_dc_ep_callback) (uint8_t ep, enum usb_dc_ep_cb_status_code cb_status)
 Callback function signature for the USB Endpoint status.
 
typedef void(* usb_dc_status_callback) (enum usb_dc_status_code cb_status, const uint8_t *param)
 Callback function signature for the device.
 

Enumerations

enum  usb_dc_status_code {
  USB_DC_ERROR , USB_DC_RESET , USB_DC_CONNECTED , USB_DC_CONFIGURED ,
  USB_DC_DISCONNECTED , USB_DC_SUSPEND , USB_DC_RESUME , USB_DC_INTERFACE ,
  USB_DC_SET_HALT , USB_DC_CLEAR_HALT , USB_DC_SOF , USB_DC_UNKNOWN
}
 USB Driver Status Codes. More...
 
enum  usb_dc_ep_cb_status_code { USB_DC_EP_SETUP , USB_DC_EP_DATA_OUT , USB_DC_EP_DATA_IN }
 USB Endpoint Callback Status Codes. More...
 
enum  usb_dc_ep_transfer_type { USB_DC_EP_CONTROL = 0 , USB_DC_EP_ISOCHRONOUS , USB_DC_EP_BULK , USB_DC_EP_INTERRUPT }
 USB Endpoint Transfer Type. More...
 
enum  usb_dc_ep_synchronozation_type { USB_DC_EP_NO_SYNCHRONIZATION = (0U << 2U) , USB_DC_EP_ASYNCHRONOUS = (1U << 2U) , USB_DC_EP_ADAPTIVE = (2U << 2U) , USB_DC_EP_SYNCHRONOUS = (3U << 2U) }
 USB Endpoint Synchronization Type. More...
 

Functions

int usb_dc_attach (void)
 Attach USB for device connection.
 
int usb_dc_detach (void)
 Detach the USB device.
 
int usb_dc_reset (void)
 Reset the USB device.
 
int usb_dc_set_address (const uint8_t addr)
 Set USB device address.
 
void usb_dc_set_status_callback (const usb_dc_status_callback cb)
 Set USB device controller status callback.
 
int usb_dc_ep_check_cap (const struct usb_dc_ep_cfg_data *const cfg)
 check endpoint capabilities
 
int usb_dc_ep_configure (const struct usb_dc_ep_cfg_data *const cfg)
 Configure endpoint.
 
int usb_dc_ep_set_stall (const uint8_t ep)
 Set stall condition for the selected endpoint.
 
int usb_dc_ep_clear_stall (const uint8_t ep)
 Clear stall condition for the selected endpoint.
 
int usb_dc_ep_is_stalled (const uint8_t ep, uint8_t *const stalled)
 Check if the selected endpoint is stalled.
 
int usb_dc_ep_halt (const uint8_t ep)
 Halt the selected endpoint.
 
int usb_dc_ep_enable (const uint8_t ep)
 Enable the selected endpoint.
 
int usb_dc_ep_disable (const uint8_t ep)
 Disable the selected endpoint.
 
int usb_dc_ep_flush (const uint8_t ep)
 Flush the selected endpoint.
 
int usb_dc_ep_write (const uint8_t ep, const uint8_t *const data, const uint32_t data_len, uint32_t *const ret_bytes)
 Write data to the specified endpoint.
 
int usb_dc_ep_read (const uint8_t ep, uint8_t *const data, const uint32_t max_data_len, uint32_t *const read_bytes)
 Read data from the specified endpoint.
 
int usb_dc_ep_set_callback (const uint8_t ep, const usb_dc_ep_callback cb)
 Set callback function for the specified endpoint.
 
int usb_dc_ep_read_wait (uint8_t ep, uint8_t *data, uint32_t max_data_len, uint32_t *read_bytes)
 Read data from the specified endpoint.
 
int usb_dc_ep_read_continue (uint8_t ep)
 Continue reading data from the endpoint.
 
int usb_dc_ep_mps (uint8_t ep)
 Get endpoint max packet size.
 
int usb_dc_wakeup_request (void)
 Start the host wake up procedure.
 

Detailed Description

USB Device Controller API.

Typedef Documentation

◆ usb_dc_ep_callback

typedef void(* usb_dc_ep_callback) (uint8_t ep, enum usb_dc_ep_cb_status_code cb_status)

#include <include/zephyr/drivers/usb/usb_dc.h>

Callback function signature for the USB Endpoint status.

◆ usb_dc_status_callback

typedef void(* usb_dc_status_callback) (enum usb_dc_status_code cb_status, const uint8_t *param)

#include <include/zephyr/drivers/usb/usb_dc.h>

Callback function signature for the device.

Enumeration Type Documentation

◆ usb_dc_ep_cb_status_code

#include <include/zephyr/drivers/usb/usb_dc.h>

USB Endpoint Callback Status Codes.

Status Codes reported by the registered endpoint callback.

Enumerator
USB_DC_EP_SETUP 

SETUP received.

USB_DC_EP_DATA_OUT 

Out transaction on this EP, data is available for read.

USB_DC_EP_DATA_IN 

In transaction done on this EP.

◆ usb_dc_ep_synchronozation_type

#include <include/zephyr/drivers/usb/usb_dc.h>

USB Endpoint Synchronization Type.

Note
Valid only for Isochronous Endpoints
Enumerator
USB_DC_EP_NO_SYNCHRONIZATION 

No Synchronization.

USB_DC_EP_ASYNCHRONOUS 

Asynchronous.

USB_DC_EP_ADAPTIVE 

Adaptive.

USB_DC_EP_SYNCHRONOUS 

Synchronous.

◆ usb_dc_ep_transfer_type

#include <include/zephyr/drivers/usb/usb_dc.h>

USB Endpoint Transfer Type.

Enumerator
USB_DC_EP_CONTROL 

Control type endpoint.

USB_DC_EP_ISOCHRONOUS 

Isochronous type endpoint.

USB_DC_EP_BULK 

Bulk type endpoint.

USB_DC_EP_INTERRUPT 

Interrupt type endpoint

◆ usb_dc_status_code

#include <include/zephyr/drivers/usb/usb_dc.h>

USB Driver Status Codes.

Status codes reported by the registered device status callback.

Enumerator
USB_DC_ERROR 

USB error reported by the controller.

USB_DC_RESET 

USB reset.

USB_DC_CONNECTED 

USB connection established, hardware enumeration is completed.

USB_DC_CONFIGURED 

USB configuration done.

USB_DC_DISCONNECTED 

USB connection lost.

USB_DC_SUSPEND 

USB connection suspended by the HOST.

USB_DC_RESUME 

USB connection resumed by the HOST.

USB_DC_INTERFACE 

USB interface selected.

USB_DC_SET_HALT 

Set Feature ENDPOINT_HALT received.

USB_DC_CLEAR_HALT 

Clear Feature ENDPOINT_HALT received.

USB_DC_SOF 

Start of Frame received.

USB_DC_UNKNOWN 

Initial USB connection status.

Function Documentation

◆ usb_dc_attach()

int usb_dc_attach ( void  )

#include <include/zephyr/drivers/usb/usb_dc.h>

Attach USB for device connection.

Function to attach USB for device connection. Upon success, the USB PLL is enabled, and the USB device is now capable of transmitting and receiving on the USB bus and of generating interrupts.

Returns
0 on success, negative errno code on fail.

◆ usb_dc_detach()

int usb_dc_detach ( void  )

#include <include/zephyr/drivers/usb/usb_dc.h>

Detach the USB device.

Function to detach the USB device. Upon success, the USB hardware PLL is powered down and USB communication is disabled.

Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_check_cap()

int usb_dc_ep_check_cap ( const struct usb_dc_ep_cfg_data *const  cfg)

#include <include/zephyr/drivers/usb/usb_dc.h>

check endpoint capabilities

Function to check capabilities of an endpoint. usb_dc_ep_cfg_data structure provides the endpoint configuration parameters: endpoint address, endpoint maximum packet size and endpoint type. The driver should check endpoint capabilities and return 0 if the endpoint configuration is possible.

Parameters
[in]cfgEndpoint config
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_clear_stall()

int usb_dc_ep_clear_stall ( const uint8_t  ep)

#include <include/zephyr/drivers/usb/usb_dc.h>

Clear stall condition for the selected endpoint.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_configure()

int usb_dc_ep_configure ( const struct usb_dc_ep_cfg_data *const  cfg)

#include <include/zephyr/drivers/usb/usb_dc.h>

Configure endpoint.

Function to configure an endpoint. usb_dc_ep_cfg_data structure provides the endpoint configuration parameters: endpoint address, endpoint maximum packet size and endpoint type.

Parameters
[in]cfgEndpoint config
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_disable()

int usb_dc_ep_disable ( const uint8_t  ep)

#include <include/zephyr/drivers/usb/usb_dc.h>

Disable the selected endpoint.

Function to disable the selected endpoint. Upon success interrupts are disabled for the corresponding endpoint and the endpoint is no longer able for transmitting/receiving data.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_enable()

int usb_dc_ep_enable ( const uint8_t  ep)

#include <include/zephyr/drivers/usb/usb_dc.h>

Enable the selected endpoint.

Function to enable the selected endpoint. Upon success interrupts are enabled for the corresponding endpoint and the endpoint is ready for transmitting/receiving data.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_flush()

int usb_dc_ep_flush ( const uint8_t  ep)

#include <include/zephyr/drivers/usb/usb_dc.h>

Flush the selected endpoint.

This function flushes the FIFOs for the selected endpoint.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_halt()

int usb_dc_ep_halt ( const uint8_t  ep)

#include <include/zephyr/drivers/usb/usb_dc.h>

Halt the selected endpoint.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_is_stalled()

int usb_dc_ep_is_stalled ( const uint8_t  ep,
uint8_t *const  stalled 
)

#include <include/zephyr/drivers/usb/usb_dc.h>

Check if the selected endpoint is stalled.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
[out]stalledEndpoint stall status
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_mps()

int usb_dc_ep_mps ( uint8_t  ep)

#include <include/zephyr/drivers/usb/usb_dc.h>

Get endpoint max packet size.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
Returns
Endpoint max packet size (mps)

◆ usb_dc_ep_read()

int usb_dc_ep_read ( const uint8_t  ep,
uint8_t *const  data,
const uint32_t  max_data_len,
uint32_t *const  read_bytes 
)

#include <include/zephyr/drivers/usb/usb_dc.h>

Read data from the specified endpoint.

This function is called by the endpoint handler function, after an OUT interrupt has been received for that EP. The application must only call this function through the supplied usb_ep_callback function. This function clears the ENDPOINT NAK, if all data in the endpoint FIFO has been read, so as to accept more data from host.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
[in]dataPointer to data buffer to write to
[in]max_data_lenMax length of data to read
[out]read_bytesNumber of bytes read. If data is NULL and max_data_len is 0 the number of bytes available for read should be returned.
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_read_continue()

int usb_dc_ep_read_continue ( uint8_t  ep)

#include <include/zephyr/drivers/usb/usb_dc.h>

Continue reading data from the endpoint.

Clear the endpoint NAK and enable the endpoint to accept more data from the host. Usually called after usb_dc_ep_read_wait() when the consumer is fine to accept more data. Thus these calls together act as a flow control mechanism.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_read_wait()

int usb_dc_ep_read_wait ( uint8_t  ep,
uint8_t data,
uint32_t  max_data_len,
uint32_t read_bytes 
)

#include <include/zephyr/drivers/usb/usb_dc.h>

Read data from the specified endpoint.

This is similar to usb_dc_ep_read, the difference being that, it doesn't clear the endpoint NAKs so that the consumer is not bogged down by further upcalls till he is done with the processing of the data. The caller should reactivate ep by invoking usb_dc_ep_read_continue() do so.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
[in]dataPointer to data buffer to write to
[in]max_data_lenMax length of data to read
[out]read_bytesNumber of bytes read. If data is NULL and max_data_len is 0 the number of bytes available for read should be returned.
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_set_callback()

int usb_dc_ep_set_callback ( const uint8_t  ep,
const usb_dc_ep_callback  cb 
)

#include <include/zephyr/drivers/usb/usb_dc.h>

Set callback function for the specified endpoint.

Function to set callback function for notification of data received and available to application or transmit done on the selected endpoint, NULL if callback not required by application code. The callback status code is described by usb_dc_ep_cb_status_code.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
[in]cbCallback function
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_set_stall()

int usb_dc_ep_set_stall ( const uint8_t  ep)

#include <include/zephyr/drivers/usb/usb_dc.h>

Set stall condition for the selected endpoint.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
Returns
0 on success, negative errno code on fail.

◆ usb_dc_ep_write()

int usb_dc_ep_write ( const uint8_t  ep,
const uint8_t *const  data,
const uint32_t  data_len,
uint32_t *const  ret_bytes 
)

#include <include/zephyr/drivers/usb/usb_dc.h>

Write data to the specified endpoint.

This function is called to write data to the specified endpoint. The supplied usb_ep_callback function will be called when data is transmitted out.

Parameters
[in]epEndpoint address corresponding to the one listed in the device configuration table
[in]dataPointer to data to write
[in]data_lenLength of the data requested to write. This may be zero for a zero length status packet.
[out]ret_bytesBytes scheduled for transmission. This value may be NULL if the application expects all bytes to be written
Returns
0 on success, negative errno code on fail.

◆ usb_dc_reset()

int usb_dc_reset ( void  )

#include <include/zephyr/drivers/usb/usb_dc.h>

Reset the USB device.

This function returns the USB device and firmware back to it's initial state. N.B. the USB PLL is handled by the usb_detach function

Returns
0 on success, negative errno code on fail.

◆ usb_dc_set_address()

int usb_dc_set_address ( const uint8_t  addr)

#include <include/zephyr/drivers/usb/usb_dc.h>

Set USB device address.

Parameters
[in]addrDevice address
Returns
0 on success, negative errno code on fail.

◆ usb_dc_set_status_callback()

void usb_dc_set_status_callback ( const usb_dc_status_callback  cb)

#include <include/zephyr/drivers/usb/usb_dc.h>

Set USB device controller status callback.

Function to set USB device controller status callback. The registered callback is used to report changes in the status of the device controller. The status code are described by the usb_dc_status_code enumeration.

Parameters
[in]cbCallback function

◆ usb_dc_wakeup_request()

int usb_dc_wakeup_request ( void  )

#include <include/zephyr/drivers/usb/usb_dc.h>

Start the host wake up procedure.

Function to wake up the host if it's currently in sleep mode.

Returns
0 on success, negative errno code on fail.