Zephyr API 3.6.99
Loading...
Searching...
No Matches
USB host controller driver API

USB host controller (UHC) driver API . More...

Data Structures

struct  uhc_transfer
 UHC endpoint buffer info. More...
 
struct  uhc_event
 USB host controller event. More...
 
struct  uhc_device_caps
 USB host controller capabilities. More...
 
struct  uhc_data
 Common UHC driver data structure. More...
 

Macros

#define UHC_STATUS_INITIALIZED   0
 Controller is initialized by uhc_init()
 
#define UHC_STATUS_ENABLED   1
 Controller is enabled and all API functions are available.
 

Typedefs

typedef int(* uhc_event_cb_t) (const struct device *dev, const struct uhc_event *const event)
 Callback to submit UHC event to higher layer.
 

Enumerations

enum  uhc_control_stage { UHC_CONTROL_STAGE_SETUP = 0 , UHC_CONTROL_STAGE_DATA , UHC_CONTROL_STAGE_STATUS }
 USB control transfer stage. More...
 
enum  uhc_event_type {
  UHC_EVT_DEV_CONNECTED_LS , UHC_EVT_DEV_CONNECTED_FS , UHC_EVT_DEV_CONNECTED_HS , UHC_EVT_DEV_REMOVED ,
  UHC_EVT_RESETED , UHC_EVT_SUSPENDED , UHC_EVT_RESUMED , UHC_EVT_RWUP ,
  UHC_EVT_EP_REQUEST , UHC_EVT_ERROR
}
 USB host controller event types. More...
 

Functions

static bool uhc_is_initialized (const struct device *dev)
 Checks whether the controller is initialized.
 
static bool uhc_is_enabled (const struct device *dev)
 Checks whether the controller is enabled.
 
static int uhc_bus_reset (const struct device *dev)
 Reset USB bus.
 
static int uhc_sof_enable (const struct device *dev)
 Enable Start of Frame generator.
 
static int uhc_bus_suspend (const struct device *dev)
 Suspend USB bus.
 
static int uhc_bus_resume (const struct device *dev)
 Resume USB bus.
 
struct uhc_transferuhc_xfer_alloc (const struct device *dev, const uint8_t addr, const uint8_t ep, const uint8_t attrib, const uint16_t mps, const uint16_t timeout, void *const udev, void *const cb)
 Allocate UHC transfer.
 
struct uhc_transferuhc_xfer_alloc_with_buf (const struct device *dev, const uint8_t addr, const uint8_t ep, const uint8_t attrib, const uint16_t mps, const uint16_t timeout, void *const udev, void *const cb, size_t size)
 Allocate UHC transfer with buffer.
 
int uhc_xfer_free (const struct device *dev, struct uhc_transfer *const xfer)
 Free UHC transfer and any buffers.
 
int uhc_xfer_buf_add (const struct device *dev, struct uhc_transfer *const xfer, struct net_buf *buf)
 Add UHC transfer buffer.
 
struct net_bufuhc_xfer_buf_alloc (const struct device *dev, const size_t size)
 Allocate UHC transfer buffer.
 
void uhc_xfer_buf_free (const struct device *dev, struct net_buf *const buf)
 Free UHC request buffer.
 
int uhc_ep_enqueue (const struct device *dev, struct uhc_transfer *const xfer)
 Queue USB host controller transfer.
 
int uhc_ep_dequeue (const struct device *dev, struct uhc_transfer *const xfer)
 Remove a USB host controller transfers from queue.
 
int uhc_init (const struct device *dev, uhc_event_cb_t event_cb)
 Initialize USB host controller.
 
int uhc_enable (const struct device *dev)
 Enable USB host controller.
 
int uhc_disable (const struct device *dev)
 Disable USB host controller.
 
int uhc_shutdown (const struct device *dev)
 Poweroff USB host controller.
 
static struct uhc_device_caps uhc_caps (const struct device *dev)
 Get USB host controller capabilities.
 

Detailed Description

USB host controller (UHC) driver API .

Macro Definition Documentation

◆ UHC_STATUS_ENABLED

#define UHC_STATUS_ENABLED   1

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

Controller is enabled and all API functions are available.

◆ UHC_STATUS_INITIALIZED

#define UHC_STATUS_INITIALIZED   0

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

Controller is initialized by uhc_init()

Typedef Documentation

◆ uhc_event_cb_t

typedef int(* uhc_event_cb_t) (const struct device *dev, const struct uhc_event *const event)

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

Callback to submit UHC event to higher layer.

At the higher level, the event is to be inserted into a message queue.

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

◆ uhc_control_stage

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

USB control transfer stage.

Enumerator
UHC_CONTROL_STAGE_SETUP 
UHC_CONTROL_STAGE_DATA 
UHC_CONTROL_STAGE_STATUS 

◆ uhc_event_type

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

USB host controller event types.

Enumerator
UHC_EVT_DEV_CONNECTED_LS 

Low speed device connected.

UHC_EVT_DEV_CONNECTED_FS 

Full speed device connected.

UHC_EVT_DEV_CONNECTED_HS 

High speed device connected.

UHC_EVT_DEV_REMOVED 

Device (peripheral) removed.

UHC_EVT_RESETED 

Bus reset operation finished.

UHC_EVT_SUSPENDED 

Bus suspend operation finished.

UHC_EVT_RESUMED 

Bus resume operation finished.

UHC_EVT_RWUP 

Remote wakeup signal.

UHC_EVT_EP_REQUEST 

Endpoint request result event.

UHC_EVT_ERROR 

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

Function Documentation

◆ uhc_bus_reset()

static int uhc_bus_reset ( const struct device * dev)
inlinestatic

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

Reset USB bus.

Perform USB bus reset, controller may emit UHC_EVT_RESETED at the end of reset signaling.

Parameters
[in]devPointer to device struct of the driver instance
Returns
0 on success, all other values should be treated as error.
Return values
-EBUSYif the controller is already performing a bus operation

◆ uhc_bus_resume()

static int uhc_bus_resume ( const struct device * dev)
inlinestatic

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

Resume USB bus.

Signal resume for at least 20ms, emit UHC_EVT_RESUMED at the end of USB bus resume signaling. The SoF generator should subsequently start within 3ms.

Parameters
[in]devPointer to device struct of the driver instance
Returns
0 on success, all other values should be treated as error.
Return values
-EBUSYif the controller is already performing a bus operation

◆ uhc_bus_suspend()

static int uhc_bus_suspend ( const struct device * dev)
inlinestatic

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

Suspend USB bus.

Disable SOF generator and emit UHC_EVT_SUSPENDED event when USB bus is suspended.

Parameters
[in]devPointer to device struct of the driver instance
Returns
0 on success, all other values should be treated as error.
Return values
-EALREADYif already suspended

◆ uhc_caps()

static struct uhc_device_caps uhc_caps ( const struct device * dev)
inlinestatic

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

Get USB host controller capabilities.

Obtain the capabilities of the controller such as high speed (HS), and more.

Parameters
[in]devPointer to device struct of the driver instance
Returns
USB host controller capabilities.

◆ uhc_disable()

int uhc_disable ( const struct device * dev)

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

Disable USB host controller.

Disable enabled USB host controller.

Parameters
[in]devPointer to device struct of the driver instance
Returns
0 on success, all other values should be treated as error.
Return values
-EALREADYalready disabled

◆ uhc_enable()

int uhc_enable ( const struct device * dev)

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

Enable USB host controller.

Enable powered USB host controller and allow host stack to recognize and enumerate devices.

Parameters
[in]devPointer to device struct of the driver instance
Returns
0 on success, all other values should be treated as error.
Return values
-EPERMcontroller is not initialized
-EALREADYalready enabled

◆ uhc_ep_dequeue()

int uhc_ep_dequeue ( const struct device * dev,
struct uhc_transfer *const xfer )

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

Remove a USB host controller transfers from queue.

Not implemented yet.

Parameters
[in]devPointer to device struct of the driver instance
[in]xferPointer to UHC transfer
Returns
0 on success, all other values should be treated as error.
Return values
-EPERMcontroller is not initialized

◆ uhc_ep_enqueue()

int uhc_ep_enqueue ( const struct device * dev,
struct uhc_transfer *const xfer )

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

Queue USB host controller transfer.

Add transfer to the queue. If the queue is empty, the transfer can be claimed by the controller immediately.

Parameters
[in]devPointer to device struct of the driver instance
[in]xferPointer to UHC transfer
Returns
0 on success, all other values should be treated as error.
Return values
-EPERMcontroller is not initialized

◆ uhc_init()

int uhc_init ( const struct device * dev,
uhc_event_cb_t event_cb )

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

Initialize USB host controller.

Initialize USB host controller.

Parameters
[in]devPointer to device struct of the driver instance
[in]event_cbEvent callback from the higher layer (USB host stack)
Returns
0 on success, all other values should be treated as error.
Return values
-EINVALon parameter error (no callback is passed)
-EALREADYalready initialized

◆ uhc_is_enabled()

static bool uhc_is_enabled ( const struct device * dev)
inlinestatic

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

Checks whether the controller is enabled.

Parameters
[in]devPointer to device struct of the driver instance
Returns
true if controller is enabled, false otherwise

◆ uhc_is_initialized()

static bool uhc_is_initialized ( const struct device * dev)
inlinestatic

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

Checks whether the controller is initialized.

Parameters
[in]devPointer to device struct of the driver instance
Returns
true if controller is initialized, false otherwise

◆ uhc_shutdown()

int uhc_shutdown ( const struct device * dev)

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

Poweroff USB host controller.

Shut down the controller completely to reduce energy consumption or to change the role of the controller.

Parameters
[in]devPointer to device struct of the driver instance
Returns
0 on success, all other values should be treated as error.
Return values
-EALREADYcontroller is already uninitialized

◆ uhc_sof_enable()

static int uhc_sof_enable ( const struct device * dev)
inlinestatic

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

Enable Start of Frame generator.

Enable SOF generator.

Parameters
[in]devPointer to device struct of the driver instance
Returns
0 on success, all other values should be treated as error.
Return values
-EALREADYif already enabled

◆ uhc_xfer_alloc()

struct uhc_transfer * uhc_xfer_alloc ( const struct device * dev,
const uint8_t addr,
const uint8_t ep,
const uint8_t attrib,
const uint16_t mps,
const uint16_t timeout,
void *const udev,
void *const cb )

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

Allocate UHC transfer.

Allocate a new transfer from common transfer pool. Transfer has no buffer after allocation, but can be allocated and added from different pools.

Parameters
[in]devPointer to device struct of the driver instance
[in]addrDevice (peripheral) address
[in]epEndpoint address
[in]attribEndpoint attributes
[in]mpsMaximum packet size of the endpoint
[in]timeoutTimeout in number of frames
[in]udevOpaque pointer to USB device
[in]cbTransfer completion callback
Returns
pointer to allocated transfer or NULL on error.

◆ uhc_xfer_alloc_with_buf()

struct uhc_transfer * uhc_xfer_alloc_with_buf ( const struct device * dev,
const uint8_t addr,
const uint8_t ep,
const uint8_t attrib,
const uint16_t mps,
const uint16_t timeout,
void *const udev,
void *const cb,
size_t size )

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

Allocate UHC transfer with buffer.

Allocate a new transfer from common transfer pool with buffer.

Parameters
[in]devPointer to device struct of the driver instance
[in]addrDevice (peripheral) address
[in]epEndpoint address
[in]attribEndpoint attributes
[in]mpsMaximum packet size of the endpoint
[in]timeoutTimeout in number of frames
[in]udevOpaque pointer to USB device
[in]cbTransfer completion callback
[in]sizeSize of the buffer
Returns
pointer to allocated transfer or NULL on error.

◆ uhc_xfer_buf_add()

int uhc_xfer_buf_add ( const struct device * dev,
struct uhc_transfer *const xfer,
struct net_buf * buf )

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

Add UHC transfer buffer.

Add a previously allocated buffer to the transfer.

Parameters
[in]devPointer to device struct of the driver instance
[in]xferPointer to UHC transfer
[in]bufPointer to UHC request buffer
Returns
pointer to allocated request or NULL on error.

◆ uhc_xfer_buf_alloc()

struct net_buf * uhc_xfer_buf_alloc ( const struct device * dev,
const size_t size )

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

Allocate UHC transfer buffer.

Allocate a new buffer from common request buffer pool and assign it to the transfer if the xfer parameter is not NULL.

Parameters
[in]devPointer to device struct of the driver instance
[in]sizeSize of the request buffer
Returns
pointer to allocated request or NULL on error.

◆ uhc_xfer_buf_free()

void uhc_xfer_buf_free ( const struct device * dev,
struct net_buf *const buf )

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

Free UHC request buffer.

Put the buffer back into the request buffer pool.

Parameters
[in]devPointer to device struct of the driver instance
[in]bufPointer to UHC request buffer

◆ uhc_xfer_free()

int uhc_xfer_free ( const struct device * dev,
struct uhc_transfer *const xfer )

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

Free UHC transfer and any buffers.

Free any buffers and put the transfer back into the transfer pool.

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