Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
USB device core API

New USB device stack core API. More...

Data Structures

struct  usbd_desc_node
 Descriptor node. More...
 
struct  usbd_config_node
 Device configuration node. More...
 
struct  usbd_ch9_data
 USB device support middle layer runtime data. More...
 
struct  usbd_status
 USB device support status. More...
 
struct  usbd_contex
 USB device support runtime context. More...
 
struct  usbd_cctx_vendor_req
 Vendor Requests Table. More...
 
struct  usbd_class_api
 USB device support class instance API. More...
 
struct  usbd_class_data
 USB device support class data. More...
 
struct  usbd_class_node
 

Macros

#define USB_BSTRING_LENGTH(s)   (sizeof(s) * 2 - 2)
 
#define USB_STRING_DESCRIPTOR_LENGTH(s)   (sizeof(s) * 2)
 
#define USBD_NUMOF_INTERFACES_MAX   16U
 
#define USBD_CCTX_REGISTERED   0
 USB Class instance registered flag.
 
#define USBD_DEVICE_DEFINE(device_name, uhc_dev, vid, pid)
 
#define USBD_CONFIGURATION_DEFINE(name, attrib, power)
 
#define USBD_DESC_LANG_DEFINE(name)
 Create a string descriptor node and language string descriptor.
 
#define USBD_DESC_STRING_DEFINE(d_name, d_string, d_utype)
 
#define USBD_DESC_MANUFACTURER_DEFINE(d_name, d_string)    USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_MANUFACTURER)
 Create a string descriptor node and manufacturer string descriptor.
 
#define USBD_DESC_PRODUCT_DEFINE(d_name, d_string)    USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_PRODUCT)
 Create a string descriptor node and product string descriptor.
 
#define USBD_DESC_SERIAL_NUMBER_DEFINE(d_name, d_string)    USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_SERIAL_NUMBER)
 Create a string descriptor node and serial number string descriptor.
 
#define USBD_DEFINE_CLASS(class_name, class_api, class_data)
 
#define VENDOR_REQ_DEFINE(_reqs, _len)
 Helper to declare request table of usbd_cctx_vendor_req.
 
#define USBD_VENDOR_REQ(_reqs...)
 Helper to declare supported vendor requests.
 

Enumerations

enum  usbd_desc_usage_type {
  USBD_DUT_STRING_LANG , USBD_DUT_STRING_MANUFACTURER , USBD_DUT_STRING_PRODUCT , USBD_DUT_STRING_SERIAL_NUMBER ,
  USBD_DUT_STRING_INTERFACE
}
 
enum  usbd_ch9_state { USBD_STATE_DEFAULT = 0 , USBD_STATE_ADDRESS , USBD_STATE_CONFIGURED }
 USB device support middle layer runtime state. More...
 

Functions

int usbd_add_descriptor (struct usbd_contex *uds_ctx, struct usbd_desc_node *dn)
 Add common USB descriptor.
 
int usbd_add_configuration (struct usbd_contex *uds_ctx, struct usbd_config_node *cd)
 Add a USB device configuration.
 
int usbd_register_class (struct usbd_contex *uds_ctx, const char *name, uint8_t cfg)
 Register an USB class instance.
 
int usbd_unregister_class (struct usbd_contex *uds_ctx, const char *name, uint8_t cfg)
 Unregister an USB class instance.
 
int usbd_init (struct usbd_contex *uds_ctx)
 Initialize USB device.
 
int usbd_enable (struct usbd_contex *uds_ctx)
 Enable the USB device support and registered class instances.
 
int usbd_disable (struct usbd_contex *uds_ctx)
 Disable the USB device support.
 
int usbd_shutdown (struct usbd_contex *const uds_ctx)
 Shutdown the USB device support.
 
int usbd_ep_set_halt (struct usbd_contex *uds_ctx, uint8_t ep)
 Halt endpoint.
 
int usbd_ep_clear_halt (struct usbd_contex *uds_ctx, uint8_t ep)
 Clear endpoint halt.
 
bool usbd_ep_is_halted (struct usbd_contex *uds_ctx, uint8_t ep)
 Checks whether the endpoint is halted.
 
struct net_bufusbd_ep_ctrl_buf_alloc (struct usbd_contex *const uds_ctx, const uint8_t ep, const size_t size)
 Allocate buffer for USB device control request.
 
struct net_bufusbd_ep_buf_alloc (const struct usbd_class_node *const c_nd, const uint8_t ep, const size_t size)
 Allocate buffer for USB device request.
 
int usbd_ep_ctrl_enqueue (struct usbd_contex *const uds_ctx, struct net_buf *const buf)
 Queue USB device control request.
 
int usbd_ep_enqueue (const struct usbd_class_node *const c_nd, struct net_buf *const buf)
 Queue USB device request.
 
int usbd_ep_dequeue (struct usbd_contex *uds_ctx, const uint8_t ep)
 Remove all USB device controller requests from endpoint queue.
 
int usbd_ep_buf_free (struct usbd_contex *uds_ctx, struct net_buf *buf)
 Free USB device request buffer.
 
bool usbd_is_suspended (struct usbd_contex *uds_ctx)
 Checks whether the USB device controller is suspended.
 
int usbd_wakeup_request (struct usbd_contex *uds_ctx)
 Initiate the USB remote wakeup (TBD)
 
int usbd_device_set_bcd (struct usbd_contex *const uds_ctx, const uint16_t bcd)
 Set USB device descriptor value bcdUSB.
 
int usbd_device_set_vid (struct usbd_contex *const uds_ctx, const uint16_t vid)
 Set USB device descriptor value idVendor.
 
int usbd_device_set_pid (struct usbd_contex *const uds_ctx, const uint16_t pid)
 Set USB device descriptor value idProduct.
 
int usbd_device_set_class (struct usbd_contex *const uds_ctx, const uint8_t value)
 Set USB device descriptor value bDeviceClass.
 
int usbd_device_set_subclass (struct usbd_contex *const uds_ctx, const uint8_t value)
 Set USB device descriptor value bDeviceSubClass.
 
int usbd_device_set_proto (struct usbd_contex *const uds_ctx, const uint8_t value)
 Set USB device descriptor value bDeviceProtocol.
 
int usbd_config_attrib_rwup (struct usbd_contex *const uds_ctx, const uint8_t cfg, const bool enable)
 Setup USB device configuration attribute Remote Wakeup.
 
int usbd_config_attrib_self (struct usbd_contex *const uds_ctx, const uint8_t cfg, const bool enable)
 Setup USB device configuration attribute Self-powered.
 
int usbd_config_maxpower (struct usbd_contex *const uds_ctx, const uint8_t cfg, const uint8_t power)
 Setup USB device configuration power consumption.
 

Detailed Description

New USB device stack core API.

Macro Definition Documentation

◆ USB_BSTRING_LENGTH

#define USB_BSTRING_LENGTH (   s)    (sizeof(s) * 2 - 2)

#include <zephyr/usb/usbd.h>

◆ USB_STRING_DESCRIPTOR_LENGTH

#define USB_STRING_DESCRIPTOR_LENGTH (   s)    (sizeof(s) * 2)

#include <zephyr/usb/usbd.h>

◆ USBD_CCTX_REGISTERED

#define USBD_CCTX_REGISTERED   0

#include <zephyr/usb/usbd.h>

USB Class instance registered flag.

◆ USBD_CONFIGURATION_DEFINE

#define USBD_CONFIGURATION_DEFINE (   name,
  attrib,
  power 
)

#include <zephyr/usb/usbd.h>

Value:
static struct usb_cfg_descriptor \
cfg_desc_##name = { \
.bLength = sizeof(struct usb_cfg_descriptor), \
.wTotalLength = 0, \
.bNumInterfaces = 0, \
.bConfigurationValue = 1, \
.iConfiguration = 0, \
.bmAttributes = USB_SCD_RESERVED | (attrib), \
.bMaxPower = (power), \
}; \
BUILD_ASSERT((power) < 256, "Too much power"); \
static struct usbd_config_node name = { \
.desc = &cfg_desc_##name, \
}
USB Standard Configuration Descriptor defined in spec.
Definition: usb_ch9.h:167
uint8_t bLength
Definition: usb_ch9.h:168
uint8_t bMaxPower
Definition: usb_ch9.h:175
uint8_t bDescriptorType
Definition: usb_ch9.h:169
Device configuration node.
Definition: usbd.h:98
#define USB_SCD_RESERVED
USB Standard Configuration Descriptor Characteristics from Table 9-10.
Definition: usb_ch9.h:238
#define USB_DESC_CONFIGURATION
Definition: usb_ch9.h:110

◆ USBD_DEFINE_CLASS

#define USBD_DEFINE_CLASS (   class_name,
  class_api,
  class_data 
)

#include <zephyr/usb/usbd.h>

Value:
static STRUCT_SECTION_ITERABLE(usbd_class_node, class_name) = { \
.name = STRINGIFY(class_name), \
.api = class_api, \
.data = class_data, \
}
#define STRINGIFY(s)
Definition: common.h:134
#define STRUCT_SECTION_ITERABLE(struct_type, varname)
Defines a new element for an iterable section.
Definition: iterable_sections.h:216
Definition: usbd.h:270

◆ USBD_DESC_LANG_DEFINE

#define USBD_DESC_LANG_DEFINE (   name)

#include <zephyr/usb/usbd.h>

Value:
static struct usb_string_descriptor \
string_desc_##name = { \
.bLength = sizeof(struct usb_string_descriptor), \
.bString = sys_cpu_to_le16(0x0409), \
}; \
static struct usbd_desc_node name = { \
.idx = 0, \
.desc = &string_desc_##name, \
}
@ USBD_DUT_STRING_LANG
Definition: usbd.h:62
USB Unicode (UTF16LE) String Descriptor defined in spec.
Definition: usb_ch9.h:219
uint8_t bDescriptorType
Definition: usb_ch9.h:221
uint8_t bLength
Definition: usb_ch9.h:220
Descriptor node.
Definition: usbd.h:75
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition: byteorder.h:258
#define USB_DESC_STRING
Definition: usb_ch9.h:111

Create a string descriptor node and language string descriptor.

This macro defines a descriptor node and a string descriptor that, when added to the device context, is automatically used as the language string descriptor zero. Both descriptor node and descriptor are defined with static-storage-class specifier. Default and currently only supported language ID is 0x0409 English (United States). If string descriptors are used, it is necessary to add this descriptor as the first one to the USB device context.

Parameters
nameLanguage string descriptor node identifier.

◆ USBD_DESC_MANUFACTURER_DEFINE

#define USBD_DESC_MANUFACTURER_DEFINE (   d_name,
  d_string 
)     USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_MANUFACTURER)

#include <zephyr/usb/usbd.h>

Create a string descriptor node and manufacturer string descriptor.

This macro defines a descriptor node and a string descriptor that, when added to the device context, is automatically used as the manufacturer string descriptor. Both descriptor node and descriptor are defined with static-storage-class specifier.

Parameters
d_nameString descriptor node identifier.
d_stringASCII7 encoded manufacturer string literal

◆ USBD_DESC_PRODUCT_DEFINE

#define USBD_DESC_PRODUCT_DEFINE (   d_name,
  d_string 
)     USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_PRODUCT)

#include <zephyr/usb/usbd.h>

Create a string descriptor node and product string descriptor.

This macro defines a descriptor node and a string descriptor that, when added to the device context, is automatically used as the product string descriptor. Both descriptor node and descriptor are defined with static-storage-class specifier.

Parameters
d_nameString descriptor node identifier.
d_stringASCII7 encoded product string literal

◆ USBD_DESC_SERIAL_NUMBER_DEFINE

#define USBD_DESC_SERIAL_NUMBER_DEFINE (   d_name,
  d_string 
)     USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_SERIAL_NUMBER)

#include <zephyr/usb/usbd.h>

Create a string descriptor node and serial number string descriptor.

This macro defines a descriptor node and a string descriptor that, when added to the device context, is automatically used as the serial number string descriptor. The string literal parameter is used as a placeholder, the unique number is obtained from hwinfo. Both descriptor node and descriptor are defined with static-storage-class specifier.

Parameters
d_nameString descriptor node identifier.
d_stringASCII7 encoded serial number string literal placeholder

◆ USBD_DESC_STRING_DEFINE

#define USBD_DESC_STRING_DEFINE (   d_name,
  d_string,
  d_utype 
)

#include <zephyr/usb/usbd.h>

Value:
struct usb_string_descriptor_##d_name { \
uint8_t bLength; \
uint8_t bDescriptorType; \
uint8_t bString[USB_BSTRING_LENGTH(d_string)]; \
} __packed; \
static struct usb_string_descriptor_##d_name \
string_desc_##d_name = { \
.bLength = USB_STRING_DESCRIPTOR_LENGTH(d_string), \
.bDescriptorType = USB_DESC_STRING, \
.bString = d_string, \
}; \
static struct usbd_desc_node d_name = { \
.utype = d_utype, \
.desc = &string_desc_##d_name, \
}
#define USB_BSTRING_LENGTH(s)
Definition: usbd.h:46
#define USB_STRING_DESCRIPTOR_LENGTH(s)
Definition: usbd.h:58
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88

◆ USBD_DEVICE_DEFINE

#define USBD_DEVICE_DEFINE (   device_name,
  uhc_dev,
  vid,
  pid 
)

#include <zephyr/usb/usbd.h>

Value:
static struct usb_device_descriptor \
desc_##device_name = { \
.bLength = sizeof(struct usb_device_descriptor), \
.bDeviceClass = USB_BCC_MISCELLANEOUS, \
.bDeviceSubClass = 2, \
.bDeviceProtocol = 1, \
.bMaxPacketSize0 = USB_CONTROL_EP_MPS, \
.idVendor = vid, \
.idProduct = pid, \
.bcdDevice = sys_cpu_to_le16(USB_BCD_DRN), \
.iManufacturer = 0, \
.iProduct = 0, \
.iSerialNumber = 0, \
.bNumConfigurations = 0, \
}; \
static STRUCT_SECTION_ITERABLE(usbd_contex, device_name) = { \
.name = STRINGIFY(device_name), \
.dev = uhc_dev, \
.desc = &desc_##device_name, \
}
USB Standard Device Descriptor defined in spec.
Definition: usb_ch9.h:149
uint8_t bDescriptorType
Definition: usb_ch9.h:151
uint8_t bLength
Definition: usb_ch9.h:150
USB device support runtime context.
Definition: usbd.h:163
#define USB_SRN_2_0
Definition: usb_ch9.h:256
#define USB_BCD_DRN
USB Device release number (bcdDevice Descriptor field)
Definition: usb_ch9.h:262
#define USB_BCC_MISCELLANEOUS
Definition: usb_ch9.h:250
#define USB_CONTROL_EP_MPS
USB Control Endpoints maximum packet size (MPS)
Definition: usb_ch9.h:272
#define USB_DESC_DEVICE
Descriptor Types defined in spec.
Definition: usb_ch9.h:109

◆ USBD_NUMOF_INTERFACES_MAX

#define USBD_NUMOF_INTERFACES_MAX   16U

#include <zephyr/usb/usbd.h>

◆ USBD_VENDOR_REQ

#define USBD_VENDOR_REQ (   _reqs...)

#include <zephyr/usb/usbd.h>

Value:
VENDOR_REQ_DEFINE(((uint8_t []) { _reqs }), \
sizeof((uint8_t []) { _reqs }))
#define VENDOR_REQ_DEFINE(_reqs, _len)
Helper to declare request table of usbd_cctx_vendor_req.
Definition: usbd.h:420

Helper to declare supported vendor requests.

Parameters
_reqsVariable number of vendor requests

◆ VENDOR_REQ_DEFINE

#define VENDOR_REQ_DEFINE (   _reqs,
  _len 
)

#include <zephyr/usb/usbd.h>

Value:
{ \
.reqs = (const uint8_t *)(_reqs), \
.len = (_len), \
}

Helper to declare request table of usbd_cctx_vendor_req.

Parameters
_reqsPointer to the vendor request field
_lenNumber of supported vendor requests

Enumeration Type Documentation

◆ usbd_ch9_state

#include <zephyr/usb/usbd.h>

USB device support middle layer runtime state.

Part of USB device states without suspended and powered states, as it is better to track them separately.

Enumerator
USBD_STATE_DEFAULT 
USBD_STATE_ADDRESS 
USBD_STATE_CONFIGURED 

◆ usbd_desc_usage_type

#include <zephyr/usb/usbd.h>

Enumerator
USBD_DUT_STRING_LANG 
USBD_DUT_STRING_MANUFACTURER 
USBD_DUT_STRING_PRODUCT 
USBD_DUT_STRING_SERIAL_NUMBER 
USBD_DUT_STRING_INTERFACE 

Function Documentation

◆ usbd_add_configuration()

int usbd_add_configuration ( struct usbd_contex uds_ctx,
struct usbd_config_node cd 
)

#include <zephyr/usb/usbd.h>

Add a USB device configuration.

Parameters
[in]uds_ctxPointer to USB device support context
[in]cdPointer to USB configuration node
Returns
0 on success, other values on fail.

◆ usbd_add_descriptor()

int usbd_add_descriptor ( struct usbd_contex uds_ctx,
struct usbd_desc_node dn 
)

#include <zephyr/usb/usbd.h>

Add common USB descriptor.

Add common descriptor like string or bos.

Parameters
[in]uds_ctxPointer to USB device support context
[in]dnPointer to USB descriptor node
Returns
0 on success, other values on fail.

◆ usbd_config_attrib_rwup()

int usbd_config_attrib_rwup ( struct usbd_contex *const  uds_ctx,
const uint8_t  cfg,
const bool  enable 
)

#include <zephyr/usb/usbd.h>

Setup USB device configuration attribute Remote Wakeup.

Parameters
[in]uds_ctxPointer to USB device support context
[in]cfgConfiguration number
[in]enableSets attribute if true, clears it otherwise
Returns
0 on success, other values on fail.

◆ usbd_config_attrib_self()

int usbd_config_attrib_self ( struct usbd_contex *const  uds_ctx,
const uint8_t  cfg,
const bool  enable 
)

#include <zephyr/usb/usbd.h>

Setup USB device configuration attribute Self-powered.

Parameters
[in]uds_ctxPointer to USB device support context
[in]cfgConfiguration number
[in]enableSets attribute if true, clears it otherwise
Returns
0 on success, other values on fail.

◆ usbd_config_maxpower()

int usbd_config_maxpower ( struct usbd_contex *const  uds_ctx,
const uint8_t  cfg,
const uint8_t  power 
)

#include <zephyr/usb/usbd.h>

Setup USB device configuration power consumption.

Parameters
[in]uds_ctxPointer to USB device support context
[in]cfgConfiguration number
[in]powerMaximum power consumption value (bMaxPower)
Returns
0 on success, other values on fail.

◆ usbd_device_set_bcd()

int usbd_device_set_bcd ( struct usbd_contex *const  uds_ctx,
const uint16_t  bcd 
)

#include <zephyr/usb/usbd.h>

Set USB device descriptor value bcdUSB.

Parameters
[in]uds_ctxPointer to USB device support context
[in]bcdbcdUSB value
Returns
0 on success, other values on fail.

◆ usbd_device_set_class()

int usbd_device_set_class ( struct usbd_contex *const  uds_ctx,
const uint8_t  value 
)

#include <zephyr/usb/usbd.h>

Set USB device descriptor value bDeviceClass.

Parameters
[in]uds_ctxPointer to USB device support context
[in]valuebDeviceClass value
Returns
0 on success, other values on fail.

◆ usbd_device_set_pid()

int usbd_device_set_pid ( struct usbd_contex *const  uds_ctx,
const uint16_t  pid 
)

#include <zephyr/usb/usbd.h>

Set USB device descriptor value idProduct.

Parameters
[in]uds_ctxPointer to USB device support context
[in]pididProduct value
Returns
0 on success, other values on fail.

◆ usbd_device_set_proto()

int usbd_device_set_proto ( struct usbd_contex *const  uds_ctx,
const uint8_t  value 
)

#include <zephyr/usb/usbd.h>

Set USB device descriptor value bDeviceProtocol.

Parameters
[in]uds_ctxPointer to USB device support context
[in]valuebDeviceProtocol value
Returns
0 on success, other values on fail.

◆ usbd_device_set_subclass()

int usbd_device_set_subclass ( struct usbd_contex *const  uds_ctx,
const uint8_t  value 
)

#include <zephyr/usb/usbd.h>

Set USB device descriptor value bDeviceSubClass.

Parameters
[in]uds_ctxPointer to USB device support context
[in]valuebDeviceSubClass value
Returns
0 on success, other values on fail.

◆ usbd_device_set_vid()

int usbd_device_set_vid ( struct usbd_contex *const  uds_ctx,
const uint16_t  vid 
)

#include <zephyr/usb/usbd.h>

Set USB device descriptor value idVendor.

Parameters
[in]uds_ctxPointer to USB device support context
[in]vididVendor value
Returns
0 on success, other values on fail.

◆ usbd_disable()

int usbd_disable ( struct usbd_contex uds_ctx)

#include <zephyr/usb/usbd.h>

Disable the USB device support.

This function disables the USB device support.

Parameters
[in]uds_ctxPointer to USB device support context
Returns
0 on success, other values on fail.

◆ usbd_enable()

int usbd_enable ( struct usbd_contex uds_ctx)

#include <zephyr/usb/usbd.h>

Enable the USB device support and registered class instances.

This function enables the USB device support.

Parameters
[in]uds_ctxPointer to USB device support context
Returns
0 on success, other values on fail.

◆ usbd_ep_buf_alloc()

struct net_buf * usbd_ep_buf_alloc ( const struct usbd_class_node *const  c_nd,
const uint8_t  ep,
const size_t  size 
)

#include <zephyr/usb/usbd.h>

Allocate buffer for USB device request.

Allocate a new buffer from controller's driver buffer pool.

Parameters
[in]c_ndPointer to USB device class node
[in]epEndpoint address
[in]sizeSize of the request buffer
Returns
pointer to allocated request or NULL on error.

◆ usbd_ep_buf_free()

int usbd_ep_buf_free ( struct usbd_contex uds_ctx,
struct net_buf buf 
)

#include <zephyr/usb/usbd.h>

Free USB device request buffer.

Put the buffer back into the request buffer pool.

Parameters
[in]uds_ctxPointer to USB device support context
[in]bufPointer to UDC request buffer
Returns
0 on success, all other values should be treated as error.

◆ usbd_ep_clear_halt()

int usbd_ep_clear_halt ( struct usbd_contex uds_ctx,
uint8_t  ep 
)

#include <zephyr/usb/usbd.h>

Clear endpoint halt.

Parameters
[in]uds_ctxPointer to USB device support context
[in]epEndpoint address
Returns
0 on success, or error from udc_ep_clear_halt()

◆ usbd_ep_ctrl_buf_alloc()

struct net_buf * usbd_ep_ctrl_buf_alloc ( struct usbd_contex *const  uds_ctx,
const uint8_t  ep,
const size_t  size 
)

#include <zephyr/usb/usbd.h>

Allocate buffer for USB device control request.

Allocate a new buffer from controller's driver buffer pool.

Parameters
[in]uds_ctxPointer to USB device support context
[in]epEndpoint address
[in]sizeSize of the request buffer
Returns
pointer to allocated request or NULL on error.

◆ usbd_ep_ctrl_enqueue()

int usbd_ep_ctrl_enqueue ( struct usbd_contex *const  uds_ctx,
struct net_buf *const  buf 
)

#include <zephyr/usb/usbd.h>

Queue USB device control request.

Add control request to the queue.

Parameters
[in]uds_ctxPointer to USB device support context
[in]bufPointer to UDC request buffer
Returns
0 on success, all other values should be treated as error.

◆ usbd_ep_dequeue()

int usbd_ep_dequeue ( struct usbd_contex uds_ctx,
const uint8_t  ep 
)

#include <zephyr/usb/usbd.h>

Remove all USB device controller requests from endpoint queue.

Parameters
[in]uds_ctxPointer to USB device support context
[in]epEndpoint address
Returns
0 on success, or error from udc_ep_dequeue()

◆ usbd_ep_enqueue()

int usbd_ep_enqueue ( const struct usbd_class_node *const  c_nd,
struct net_buf *const  buf 
)

#include <zephyr/usb/usbd.h>

Queue USB device request.

Add request to the queue.

Parameters
[in]c_ndPointer to USB device class node
[in]bufPointer to UDC request buffer
Returns
0 on success, or error from udc_ep_enqueue()

◆ usbd_ep_is_halted()

bool usbd_ep_is_halted ( struct usbd_contex uds_ctx,
uint8_t  ep 
)

#include <zephyr/usb/usbd.h>

Checks whether the endpoint is halted.

Parameters
[in]uds_ctxPointer to USB device support context
[in]epEndpoint address
Returns
true if endpoint is halted, false otherwise

◆ usbd_ep_set_halt()

int usbd_ep_set_halt ( struct usbd_contex uds_ctx,
uint8_t  ep 
)

#include <zephyr/usb/usbd.h>

Halt endpoint.

Parameters
[in]uds_ctxPointer to USB device support context
[in]epEndpoint address
Returns
0 on success, or error from udc_ep_set_halt()

◆ usbd_init()

int usbd_init ( struct usbd_contex uds_ctx)

#include <zephyr/usb/usbd.h>

Initialize USB device.

Initialize USB device descriptors and configuration, initialize USB device controller. Class instances should be registered before they are involved. However, the stack should also initialize without registered instances, even if the host would complain about missing interfaces.

Parameters
[in]uds_ctxPointer to USB device support context
Returns
0 on success, other values on fail.

◆ usbd_is_suspended()

bool usbd_is_suspended ( struct usbd_contex uds_ctx)

#include <zephyr/usb/usbd.h>

Checks whether the USB device controller is suspended.

Parameters
[in]uds_ctxPointer to USB device support context
Returns
true if endpoint is halted, false otherwise

◆ usbd_register_class()

int usbd_register_class ( struct usbd_contex uds_ctx,
const char *  name,
uint8_t  cfg 
)

#include <zephyr/usb/usbd.h>

Register an USB class instance.

An USB class implementation can have one or more instances. To identify the instances we use device drivers API. Device names have a prefix derived from the name of the class, for example CDC_ACM for CDC ACM class instance, and can also be easily identified in the shell. Class instance can only be registered when the USB device stack is disabled. Registered instances are initialized at initialization of the USB device stack, and the interface descriptors of each instance are adapted to the whole context.

Parameters
[in]uds_ctxPointer to USB device support context
[in]nameClass instance name
[in]cfgConfiguration value (similar to bConfigurationValue)
Returns
0 on success, other values on fail.

◆ usbd_shutdown()

int usbd_shutdown ( struct usbd_contex *const  uds_ctx)

#include <zephyr/usb/usbd.h>

Shutdown the USB device support.

This function completely disables the USB device support.

Parameters
[in]uds_ctxPointer to USB device support context
Returns
0 on success, other values on fail.

◆ usbd_unregister_class()

int usbd_unregister_class ( struct usbd_contex uds_ctx,
const char *  name,
uint8_t  cfg 
)

#include <zephyr/usb/usbd.h>

Unregister an USB class instance.

USB class instance will be removed and will not appear on the next start of the stack. Instance can only be unregistered when the USB device stack is disabled.

Parameters
[in]uds_ctxPointer to USB device support context
[in]nameClass instance name
[in]cfgConfiguration value (similar to bConfigurationValue)
Returns
0 on success, other values on fail.

◆ usbd_wakeup_request()

int usbd_wakeup_request ( struct usbd_contex uds_ctx)

#include <zephyr/usb/usbd.h>

Initiate the USB remote wakeup (TBD)

Returns
0 on success, other values on fail.