Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
udc.h File Reference

New USB device controller (UDC) driver API. More...

Go to the source code of this file.

Data Structures

struct  udc_device_caps
 USB device controller capabilities. More...
 
struct  udc_ep_caps
 USB device controller endpoint capabilities. More...
 
struct  udc_ep_stat
 USB device controller endpoint status. More...
 
struct  udc_ep_config
 USB device controller endpoint configuration. More...
 
struct  udc_event
 USB device controller event. More...
 
struct  udc_buf_info
 UDC endpoint buffer info. More...
 
struct  udc_api
 UDC driver API This is the mandatory API any USB device controller driver needs to expose with exception of: device_speed(), test_mode() are only required for HS controllers. More...
 
struct  udc_data
 Common UDC driver data structure. More...
 

Macros

#define UDC_STATUS_INITIALIZED   0
 Controller is initialized by udc_init() and can generate the VBUS events, if capable, but shall not be recognizable by host.
 
#define UDC_STATUS_ENABLED   1
 Controller is enabled and all API functions are available, controller is recognizable by host.
 
#define UDC_STATUS_SUSPENDED   2
 Controller is suspended by the host.
 

Typedefs

typedef int(* udc_event_cb_t) (const struct device *dev, const struct udc_event *const event)
 Callback to submit UDC event to higher layer.
 

Enumerations

enum  udc_mps0 { UDC_MPS0_8 , UDC_MPS0_16 , UDC_MPS0_32 , UDC_MPS0_64 }
 Maximum packet size of control endpoint supported by the controller. More...
 
enum  udc_bus_speed { UDC_BUS_UNKNOWN , UDC_BUS_SPEED_FS , UDC_BUS_SPEED_HS , UDC_BUS_SPEED_SS }
 USB device actual speed. More...
 
enum  udc_event_type {
  UDC_EVT_VBUS_READY , UDC_EVT_VBUS_REMOVED , UDC_EVT_RESUME , UDC_EVT_SUSPEND ,
  UDC_EVT_RESET , UDC_EVT_SOF , UDC_EVT_EP_REQUEST , UDC_EVT_ERROR
}
 USB device controller event types. More...
 

Functions

static bool udc_is_initialized (const struct device *dev)
 Checks whether the controller is initialized.
 
static bool udc_is_enabled (const struct device *dev)
 Checks whether the controller is enabled.
 
static bool udc_is_suspended (const struct device *dev)
 Checks whether the controller is suspended.
 
int udc_init (const struct device *dev, udc_event_cb_t event_cb, const void *const event_ctx)
 Initialize USB device controller.
 
int udc_enable (const struct device *dev)
 Enable USB device controller.
 
int udc_disable (const struct device *dev)
 Disable USB device controller.
 
int udc_shutdown (const struct device *dev)
 Poweroff USB device controller.
 
static struct udc_device_caps udc_caps (const struct device *dev)
 Get USB device controller capabilities.
 
enum udc_bus_speed udc_device_speed (const struct device *dev)
 Get actual USB device speed.
 
static int udc_set_address (const struct device *dev, const uint8_t addr)
 Set USB device address.
 
static int udc_test_mode (const struct device *dev, const uint8_t mode, const bool dryrun)
 Enable Test Mode.
 
static int udc_host_wakeup (const struct device *dev)
 Initiate host wakeup procedure.
 
int udc_ep_try_config (const struct device *dev, const uint8_t ep, const uint8_t attributes, uint16_t *const mps, const uint8_t interval)
 Try an endpoint configuration.
 
int udc_ep_enable (const struct device *dev, const uint8_t ep, const uint8_t attributes, const uint16_t mps, const uint8_t interval)
 Configure and enable endpoint.
 
int udc_ep_disable (const struct device *dev, const uint8_t ep)
 Disable endpoint.
 
int udc_ep_set_halt (const struct device *dev, const uint8_t ep)
 Halt endpoint.
 
int udc_ep_clear_halt (const struct device *dev, const uint8_t ep)
 Clear endpoint halt.
 
int udc_ep_enqueue (const struct device *dev, struct net_buf *const buf)
 Queue USB device controller request.
 
int udc_ep_dequeue (const struct device *dev, const uint8_t ep)
 Remove all USB device controller requests from endpoint queue.
 
struct net_bufudc_ep_buf_alloc (const struct device *dev, const uint8_t ep, const size_t size)
 Allocate UDC request buffer.
 
int udc_ep_buf_free (const struct device *dev, struct net_buf *const buf)
 Free UDC request buffer.
 
static void udc_ep_buf_set_zlp (struct net_buf *const buf)
 Set ZLP flag in requests metadata.
 
static struct udc_buf_infoudc_get_buf_info (const struct net_buf *const buf)
 Get requests metadata.
 
static const void * udc_get_event_ctx (const struct device *dev)
 Get pointer to higher layer context.
 
static uint16_t udc_mps_ep_size (const struct udc_ep_config *const cfg)
 Get endpoint size from UDC endpoint configuration.
 

Detailed Description

New USB device controller (UDC) driver API.

Macro Definition Documentation

◆ UDC_STATUS_ENABLED

#define UDC_STATUS_ENABLED   1

Controller is enabled and all API functions are available, controller is recognizable by host.

◆ UDC_STATUS_INITIALIZED

#define UDC_STATUS_INITIALIZED   0

Controller is initialized by udc_init() and can generate the VBUS events, if capable, but shall not be recognizable by host.

◆ UDC_STATUS_SUSPENDED

#define UDC_STATUS_SUSPENDED   2

Controller is suspended by the host.

Typedef Documentation

◆ udc_event_cb_t

typedef int(* udc_event_cb_t) (const struct device *dev, const struct udc_event *const event)

Callback to submit UDC event to higher layer.

At the higher level, the event is to be inserted into a message queue. (TBD) Maybe it is better to provide a pointer to k_msgq passed during initialization.

Parameters
[in]devPointer to device struct of the driver instance
[in]eventPoint to event structure
Returns
0 on success, all other values should be treated as error.

Enumeration Type Documentation

◆ udc_bus_speed

USB device actual speed.

Enumerator
UDC_BUS_UNKNOWN 

Device is probably not connected.

UDC_BUS_SPEED_FS 

Device is connected to a full speed bus.

UDC_BUS_SPEED_HS 

Device is connected to a high speed bus

UDC_BUS_SPEED_SS 

Device is connected to a super speed bus.

◆ udc_event_type

USB device controller event types.

Enumerator
UDC_EVT_VBUS_READY 

VBUS ready event.

Signals that VBUS is in stable condition.

UDC_EVT_VBUS_REMOVED 

VBUS removed event.

Signals that VBUS is below the valid range.

UDC_EVT_RESUME 

Device resume event.

UDC_EVT_SUSPEND 

Device suspended event.

UDC_EVT_RESET 

Port reset detected.

UDC_EVT_SOF 

Start of Frame event.

UDC_EVT_EP_REQUEST 

Endpoint request result event.

UDC_EVT_ERROR 

Non-correctable error event, requires attention from higher levels or application.

◆ udc_mps0

enum udc_mps0

Maximum packet size of control endpoint supported by the controller.

Enumerator
UDC_MPS0_8 
UDC_MPS0_16 
UDC_MPS0_32 
UDC_MPS0_64