Zephyr API Documentation
3.5.0
A Scalable Open Source RTOS
|
|
3.5.0 |
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_buf * | usbd_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_buf * | usbd_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. | |
New USB device stack core API.
#include <zephyr/usb/usbd.h>
#include <zephyr/usb/usbd.h>
#define USBD_CCTX_REGISTERED 0 |
#include <zephyr/usb/usbd.h>
USB Class instance registered flag.
#define USBD_CONFIGURATION_DEFINE | ( | name, | |
attrib, | |||
power | |||
) |
#include <zephyr/usb/usbd.h>
#define USBD_DEFINE_CLASS | ( | class_name, | |
class_api, | |||
class_data | |||
) |
#include <zephyr/usb/usbd.h>
#define USBD_DESC_LANG_DEFINE | ( | name | ) |
#include <zephyr/usb/usbd.h>
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.
name | Language string descriptor node identifier. |
#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.
d_name | String descriptor node identifier. |
d_string | ASCII7 encoded manufacturer string literal |
#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.
d_name | String descriptor node identifier. |
d_string | ASCII7 encoded product string literal |
#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.
d_name | String descriptor node identifier. |
d_string | ASCII7 encoded serial number string literal placeholder |
#define USBD_DESC_STRING_DEFINE | ( | d_name, | |
d_string, | |||
d_utype | |||
) |
#include <zephyr/usb/usbd.h>
#define USBD_DEVICE_DEFINE | ( | device_name, | |
uhc_dev, | |||
vid, | |||
pid | |||
) |
#include <zephyr/usb/usbd.h>
#define USBD_NUMOF_INTERFACES_MAX 16U |
#include <zephyr/usb/usbd.h>
#define USBD_VENDOR_REQ | ( | _reqs... | ) |
#include <zephyr/usb/usbd.h>
Helper to declare supported vendor requests.
_reqs | Variable number of vendor requests |
#define VENDOR_REQ_DEFINE | ( | _reqs, | |
_len | |||
) |
#include <zephyr/usb/usbd.h>
Helper to declare request table of usbd_cctx_vendor_req.
_reqs | Pointer to the vendor request field |
_len | Number of supported vendor requests |
enum 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 |
enum 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 |
int usbd_add_configuration | ( | struct usbd_contex * | uds_ctx, |
struct usbd_config_node * | cd | ||
) |
#include <zephyr/usb/usbd.h>
Add a USB device configuration.
[in] | uds_ctx | Pointer to USB device support context |
[in] | cd | Pointer to USB configuration node |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | dn | Pointer to USB descriptor node |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | cfg | Configuration number |
[in] | enable | Sets attribute if true, clears it otherwise |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | cfg | Configuration number |
[in] | enable | Sets attribute if true, clears it otherwise |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | cfg | Configuration number |
[in] | power | Maximum power consumption value (bMaxPower) |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | bcd | bcdUSB value |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | value | bDeviceClass value |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | pid | idProduct value |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | value | bDeviceProtocol value |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | value | bDeviceSubClass value |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | vid | idVendor value |
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.
[in] | uds_ctx | Pointer to USB device support context |
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.
[in] | uds_ctx | Pointer to USB device support context |
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.
[in] | c_nd | Pointer to USB device class node |
[in] | ep | Endpoint address |
[in] | size | Size of the request buffer |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | buf | Pointer to UDC request buffer |
int usbd_ep_clear_halt | ( | struct usbd_contex * | uds_ctx, |
uint8_t | ep | ||
) |
#include <zephyr/usb/usbd.h>
Clear endpoint halt.
[in] | uds_ctx | Pointer to USB device support context |
[in] | ep | Endpoint address |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | ep | Endpoint address |
[in] | size | Size of the request buffer |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | buf | Pointer to UDC request buffer |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | ep | Endpoint address |
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.
[in] | c_nd | Pointer to USB device class node |
[in] | buf | Pointer to UDC request buffer |
bool usbd_ep_is_halted | ( | struct usbd_contex * | uds_ctx, |
uint8_t | ep | ||
) |
#include <zephyr/usb/usbd.h>
Checks whether the endpoint is halted.
[in] | uds_ctx | Pointer to USB device support context |
[in] | ep | Endpoint address |
int usbd_ep_set_halt | ( | struct usbd_contex * | uds_ctx, |
uint8_t | ep | ||
) |
#include <zephyr/usb/usbd.h>
Halt endpoint.
[in] | uds_ctx | Pointer to USB device support context |
[in] | ep | Endpoint address |
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.
[in] | uds_ctx | Pointer to USB device support context |
bool usbd_is_suspended | ( | struct usbd_contex * | uds_ctx | ) |
#include <zephyr/usb/usbd.h>
Checks whether the USB device controller is suspended.
[in] | uds_ctx | Pointer to USB device support context |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | name | Class instance name |
[in] | cfg | Configuration value (similar to bConfigurationValue) |
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.
[in] | uds_ctx | Pointer to USB device support context |
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.
[in] | uds_ctx | Pointer to USB device support context |
[in] | name | Class instance name |
[in] | cfg | Configuration value (similar to bConfigurationValue) |
int usbd_wakeup_request | ( | struct usbd_contex * | uds_ctx | ) |
#include <zephyr/usb/usbd.h>
Initiate the USB remote wakeup (TBD)