Zephyr Project API 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
usbd.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
14#ifndef ZEPHYR_INCLUDE_USBD_H_
15#define ZEPHYR_INCLUDE_USBD_H_
16
17#include <zephyr/device.h>
18#include <zephyr/usb/bos.h>
19#include <zephyr/usb/usb_ch9.h>
20#include <zephyr/usb/usbd_msg.h>
23#include <zephyr/sys/slist.h>
24#include <zephyr/logging/log.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
40/* 1 if USB device stack is compiled with High-Speed support */
41#define USBD_SUPPORTS_HIGH_SPEED IS_EQ(CONFIG_USBD_MAX_SPEED, 1)
42
43/* Maximum bulk max packet size the stack supports */
44#define USBD_MAX_BULK_MPS COND_CODE_1(USBD_SUPPORTS_HIGH_SPEED, (512), (64))
45
46/*
47 * The length of the string descriptor (bLength) is calculated from the
48 * size of the two octets bLength and bDescriptorType plus the
49 * length of the UTF16LE string:
50 *
51 * bLength = 2 + bString_length
52 * bLength = 2 + sizeof(initializer_string) * 2 - 2
53 * bLength = sizeof(initializer_string) * 2
54 * Use this macro to determine the bLength of the string descriptor.
55 */
56#define USB_STRING_DESCRIPTOR_LENGTH(s) (sizeof(s) * 2)
57
58struct usbd_context;
59
63enum usbd_str_desc_utype {
64 USBD_DUT_STRING_LANG,
65 USBD_DUT_STRING_MANUFACTURER,
66 USBD_DUT_STRING_PRODUCT,
67 USBD_DUT_STRING_SERIAL_NUMBER,
68 USBD_DUT_STRING_CONFIG,
69 USBD_DUT_STRING_INTERFACE,
70};
71
72enum usbd_bos_desc_utype {
73 USBD_DUT_BOS_NONE,
74 USBD_DUT_BOS_VREQ,
75};
85 enum usbd_str_desc_utype utype : 8;
87 unsigned int ascii7 : 1;
89 unsigned int use_hwinfo : 1;
90};
91
131 int (*to_host)(const struct usbd_context *const ctx,
132 const struct usb_setup_packet *const setup,
133 struct net_buf *const buf);
135 int (*to_dev)(const struct usbd_context *const ctx,
136 const struct usb_setup_packet *const setup,
137 const struct net_buf *const buf);
138};
139
145 enum usbd_bos_desc_utype utype : 8;
146 union {
147 struct usbd_vreq_node *const vreq_nd;
148 };
149};
150
171
190
191/* TODO: Kconfig option USBD_NUMOF_INTERFACES_MAX? */
192#define USBD_NUMOF_INTERFACES_MAX 16U
193
205
206
226
238
244 unsigned int initialized : 1;
246 unsigned int enabled : 1;
248 unsigned int suspended : 1;
250 unsigned int rwup : 1;
252 unsigned int self_powered : 1;
255};
256
272typedef void (*usbd_msg_cb_t)(struct usbd_context *const ctx,
273 const struct usbd_msg *const msg);
274
307
317
319#define USBD_CCTX_REGISTERED 0
320
321struct usbd_class_data;
322
328 void (*feature_halt)(struct usbd_class_data *const c_data,
329 uint8_t ep, bool halted);
330
332 void (*update)(struct usbd_class_data *const c_data,
333 uint8_t iface, uint8_t alternate);
334
336 int (*control_to_dev)(struct usbd_class_data *const c_data,
337 const struct usb_setup_packet *const setup,
338 const struct net_buf *const buf);
339
341 int (*control_to_host)(struct usbd_class_data *const c_data,
342 const struct usb_setup_packet *const setup,
343 struct net_buf *const buf);
344
346 int (*request)(struct usbd_class_data *const c_data,
347 struct net_buf *buf, int err);
348
350 void (*suspended)(struct usbd_class_data *const c_data);
351
353 void (*resumed)(struct usbd_class_data *const c_data);
354
356 void (*sof)(struct usbd_class_data *const c_data);
357
359 void (*enable)(struct usbd_class_data *const c_data);
360
362 void (*disable)(struct usbd_class_data *const c_data);
363
365 int (*init)(struct usbd_class_data *const c_data);
366
368 void (*shutdown)(struct usbd_class_data *const c_data);
369
371 void *(*get_desc)(struct usbd_class_data *const c_data,
372 const enum usbd_speed speed);
373};
374
380 const char *name;
384 const struct usbd_class_api *api;
388 void *priv;
389};
390
399struct usbd_class_node {
401 sys_snode_t node;
403 struct usbd_class_data *const c_data;
407 uint32_t ep_assigned;
411 uint32_t ep_active;
413 uint32_t iface_bm;
416};
417
430static inline struct usbd_context *usbd_class_get_ctx(const struct usbd_class_data *const c_data)
431{
432 return c_data->uds_ctx;
433}
434
445static inline void *usbd_class_get_private(const struct usbd_class_data *const c_data)
446{
447 return c_data->priv;
448}
449
470#define USBD_DEVICE_DEFINE(device_name, udc_dev, vid, pid) \
471 static struct usb_device_descriptor \
472 fs_desc_##device_name = { \
473 .bLength = sizeof(struct usb_device_descriptor), \
474 .bDescriptorType = USB_DESC_DEVICE, \
475 .bcdUSB = sys_cpu_to_le16(USB_SRN_2_0), \
476 .bDeviceClass = USB_BCC_MISCELLANEOUS, \
477 .bDeviceSubClass = 2, \
478 .bDeviceProtocol = 1, \
479 .bMaxPacketSize0 = USB_CONTROL_EP_MPS, \
480 .idVendor = vid, \
481 .idProduct = pid, \
482 .bcdDevice = sys_cpu_to_le16(USB_BCD_DRN), \
483 .iManufacturer = 0, \
484 .iProduct = 0, \
485 .iSerialNumber = 0, \
486 .bNumConfigurations = 0, \
487 }; \
488 IF_ENABLED(USBD_SUPPORTS_HIGH_SPEED, ( \
489 static struct usb_device_descriptor \
490 hs_desc_##device_name = { \
491 .bLength = sizeof(struct usb_device_descriptor), \
492 .bDescriptorType = USB_DESC_DEVICE, \
493 .bcdUSB = sys_cpu_to_le16(USB_SRN_2_0), \
494 .bDeviceClass = USB_BCC_MISCELLANEOUS, \
495 .bDeviceSubClass = 2, \
496 .bDeviceProtocol = 1, \
497 .bMaxPacketSize0 = 64, \
498 .idVendor = vid, \
499 .idProduct = pid, \
500 .bcdDevice = sys_cpu_to_le16(USB_BCD_DRN), \
501 .iManufacturer = 0, \
502 .iProduct = 0, \
503 .iSerialNumber = 0, \
504 .bNumConfigurations = 0, \
505 }; \
506 )) \
507 static STRUCT_SECTION_ITERABLE(usbd_context, device_name) = { \
508 .name = STRINGIFY(device_name), \
509 .dev = udc_dev, \
510 .fs_desc = &fs_desc_##device_name, \
511 IF_ENABLED(USBD_SUPPORTS_HIGH_SPEED, ( \
512 .hs_desc = &hs_desc_##device_name, \
513 )) \
514 }
515
533#define USBD_CONFIGURATION_DEFINE(name, attrib, power, desc_nd) \
534 static struct usb_cfg_descriptor \
535 cfg_desc_##name = { \
536 .bLength = sizeof(struct usb_cfg_descriptor), \
537 .bDescriptorType = USB_DESC_CONFIGURATION, \
538 .wTotalLength = 0, \
539 .bNumInterfaces = 0, \
540 .bConfigurationValue = 1, \
541 .iConfiguration = 0, \
542 .bmAttributes = USB_SCD_RESERVED | (attrib), \
543 .bMaxPower = (power), \
544 }; \
545 BUILD_ASSERT((power) < 256, "Too much power"); \
546 static struct usbd_config_node name = { \
547 .desc = &cfg_desc_##name, \
548 .str_desc_nd = desc_nd, \
549 }
550
564#define USBD_DESC_LANG_DEFINE(name) \
565 static const uint16_t langid_##name = sys_cpu_to_le16(0x0409); \
566 static struct usbd_desc_node name = { \
567 .str = { \
568 .idx = 0, \
569 .utype = USBD_DUT_STRING_LANG, \
570 }, \
571 .ptr = &langid_##name, \
572 .bLength = sizeof(struct usb_string_descriptor), \
573 .bDescriptorType = USB_DESC_STRING, \
574 }
575
587#define USBD_DESC_STRING_DEFINE(d_name, d_string, d_utype) \
588 static const uint8_t ascii_##d_name[sizeof(d_string)] = d_string; \
589 static struct usbd_desc_node d_name = { \
590 .str = { \
591 .utype = d_utype, \
592 .ascii7 = true, \
593 }, \
594 .ptr = &ascii_##d_name, \
595 .bLength = USB_STRING_DESCRIPTOR_LENGTH(d_string), \
596 .bDescriptorType = USB_DESC_STRING, \
597 }
598
610#define USBD_DESC_MANUFACTURER_DEFINE(d_name, d_string) \
611 USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_MANUFACTURER)
612
624#define USBD_DESC_PRODUCT_DEFINE(d_name, d_string) \
625 USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_PRODUCT)
626
640#define USBD_DESC_SERIAL_NUMBER_DEFINE(d_name) \
641 BUILD_ASSERT(IS_ENABLED(CONFIG_HWINFO), "HWINFO not enabled"); \
642 static struct usbd_desc_node d_name = { \
643 .str = { \
644 .utype = USBD_DUT_STRING_SERIAL_NUMBER, \
645 .ascii7 = true, \
646 .use_hwinfo = true, \
647 }, \
648 .bDescriptorType = USB_DESC_STRING, \
649 }
650
660#define USBD_DESC_CONFIG_DEFINE(d_name, d_string) \
661 USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_CONFIG)
662
675#define USBD_DESC_BOS_DEFINE(name, len, subset) \
676 BUILD_ASSERT(IS_ENABLED(CONFIG_USBD_BOS_SUPPORT), \
677 "USB device BOS support is disabled"); \
678 static struct usbd_desc_node name = { \
679 .bos = { \
680 .utype = USBD_DUT_BOS_NONE, \
681 }, \
682 .ptr = subset, \
683 .bLength = len, \
684 .bDescriptorType = USB_DESC_BOS, \
685 }
686
697#define USBD_VREQUEST_DEFINE(name, vcode, vto_host, vto_dev) \
698 BUILD_ASSERT(IS_ENABLED(CONFIG_USBD_VREQ_SUPPORT), \
699 "USB device vendor request support is disabled"); \
700 static struct usbd_vreq_node name = { \
701 .code = vcode, \
702 .to_host = vto_host, \
703 .to_dev = vto_dev, \
704 }
705
725#define USBD_DESC_BOS_VREQ_DEFINE(name, len, subset, vcode, vto_host, vto_dev) \
726 BUILD_ASSERT(IS_ENABLED(CONFIG_USBD_BOS_SUPPORT), \
727 "USB device BOS support is disabled"); \
728 USBD_VREQUEST_DEFINE(vreq_nd_##name, vcode, vto_host, vto_dev); \
729 static struct usbd_desc_node name = { \
730 .bos = { \
731 .utype = USBD_DUT_BOS_VREQ, \
732 .vreq_nd = &vreq_nd_##name, \
733 }, \
734 .ptr = subset, \
735 .bLength = len, \
736 .bDescriptorType = USB_DESC_BOS, \
737 }
738
750#define USBD_DEFINE_CLASS(class_name, class_api, class_priv, class_v_reqs) \
751 static struct usbd_class_data class_name = { \
752 .name = STRINGIFY(class_name), \
753 .api = class_api, \
754 .v_reqs = class_v_reqs, \
755 .priv = class_priv, \
756 }; \
757 static STRUCT_SECTION_ITERABLE_ALTERNATE( \
758 usbd_class_fs, usbd_class_node, class_name##_fs) = { \
759 .c_data = &class_name, \
760 }; \
761 IF_ENABLED(USBD_SUPPORTS_HIGH_SPEED, ( \
762 static STRUCT_SECTION_ITERABLE_ALTERNATE( \
763 usbd_class_hs, usbd_class_node, class_name##_hs) = { \
764 .c_data = &class_name, \
765 } \
766 ))
767
773#define VENDOR_REQ_DEFINE(_reqs, _len) \
774 { \
775 .reqs = (const uint8_t *)(_reqs), \
776 .len = (_len), \
777 }
778
783#define USBD_VENDOR_REQ(_reqs...) \
784 VENDOR_REQ_DEFINE(((uint8_t []) { _reqs }), \
785 sizeof((uint8_t []) { _reqs }))
786
787
799 struct usbd_desc_node *dn);
800
808uint8_t usbd_str_desc_get_idx(const struct usbd_desc_node *const desc_nd);
809
817void usbd_remove_descriptor(struct usbd_desc_node *const desc_nd);
818
829 const enum usbd_speed speed,
830 struct usbd_config_node *cd);
831
854 const char *name,
855 const enum usbd_speed speed, uint8_t cfg);
856
889 const enum usbd_speed speed, uint8_t cfg,
890 const char *const blocklist[]);
891
907 const char *name,
908 const enum usbd_speed speed, uint8_t cfg);
909
923 const enum usbd_speed speed, uint8_t cfg);
924
933int usbd_msg_register_cb(struct usbd_context *const uds_ctx,
934 const usbd_msg_cb_t cb);
935
949int usbd_init(struct usbd_context *uds_ctx);
950
960int usbd_enable(struct usbd_context *uds_ctx);
961
971int usbd_disable(struct usbd_context *uds_ctx);
972
982int usbd_shutdown(struct usbd_context *const uds_ctx);
983
992int usbd_ep_set_halt(struct usbd_context *uds_ctx, uint8_t ep);
993
1002int usbd_ep_clear_halt(struct usbd_context *uds_ctx, uint8_t ep);
1003
1012bool usbd_ep_is_halted(struct usbd_context *uds_ctx, uint8_t ep);
1013
1025struct net_buf *usbd_ep_buf_alloc(const struct usbd_class_data *const c_data,
1026 const uint8_t ep, const size_t size);
1027
1038int usbd_ep_ctrl_enqueue(struct usbd_context *const uds_ctx,
1039 struct net_buf *const buf);
1040
1051int usbd_ep_enqueue(const struct usbd_class_data *const c_data,
1052 struct net_buf *const buf);
1053
1062int usbd_ep_dequeue(struct usbd_context *uds_ctx, const uint8_t ep);
1063
1074int usbd_ep_buf_free(struct usbd_context *uds_ctx, struct net_buf *buf);
1075
1083bool usbd_is_suspended(struct usbd_context *uds_ctx);
1084
1091
1101void usbd_self_powered(struct usbd_context *uds_ctx, const bool status);
1102
1110enum usbd_speed usbd_bus_speed(const struct usbd_context *const uds_ctx);
1111
1119enum usbd_speed usbd_caps_speed(const struct usbd_context *const uds_ctx);
1120
1130int usbd_device_set_bcd_usb(struct usbd_context *const uds_ctx,
1131 const enum usbd_speed speed, const uint16_t bcd);
1132
1141int usbd_device_set_vid(struct usbd_context *const uds_ctx,
1142 const uint16_t vid);
1143
1152int usbd_device_set_pid(struct usbd_context *const uds_ctx,
1153 const uint16_t pid);
1154
1164 const uint16_t bcd);
1165
1178 const enum usbd_speed speed,
1179 const uint8_t base_class,
1180 const uint8_t subclass, const uint8_t protocol);
1181
1192int usbd_config_attrib_rwup(struct usbd_context *const uds_ctx,
1193 const enum usbd_speed speed,
1194 const uint8_t cfg, const bool enable);
1195
1206int usbd_config_attrib_self(struct usbd_context *const uds_ctx,
1207 const enum usbd_speed speed,
1208 const uint8_t cfg, const bool enable);
1209
1220int usbd_config_maxpower(struct usbd_context *const uds_ctx,
1221 const enum usbd_speed speed,
1222 const uint8_t cfg, const uint8_t power);
1223
1236bool usbd_can_detect_vbus(struct usbd_context *const uds_ctx);
1237
1249int usbd_device_register_vreq(struct usbd_context *const uds_ctx,
1250 struct usbd_vreq_node *const vreq_nd);
1251
1256#ifdef __cplusplus
1257}
1258#endif
1259
1260#endif /* ZEPHYR_INCLUDE_USBD_H_ */
long atomic_t
Definition atomic_types.h:15
struct _dnode sys_dnode_t
Doubly-linked list node structure.
Definition dlist.h:54
struct _dnode sys_dlist_t
Doubly-linked list structure.
Definition dlist.h:50
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:49
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
int usbd_ep_clear_halt(struct usbd_context *uds_ctx, uint8_t ep)
Clear endpoint halt.
int usbd_register_all_classes(struct usbd_context *uds_ctx, const enum usbd_speed speed, uint8_t cfg, const char *const blocklist[])
Register all available USB class instances.
int usbd_device_set_vid(struct usbd_context *const uds_ctx, const uint16_t vid)
Set USB device descriptor value idVendor.
int usbd_ep_dequeue(struct usbd_context *uds_ctx, const uint8_t ep)
Remove all USB device controller requests from endpoint queue.
int usbd_ep_set_halt(struct usbd_context *uds_ctx, uint8_t ep)
Halt endpoint.
int usbd_enable(struct usbd_context *uds_ctx)
Enable the USB device support and registered class instances.
int usbd_unregister_class(struct usbd_context *uds_ctx, const char *name, const enum usbd_speed speed, uint8_t cfg)
Unregister an USB class instance.
int usbd_unregister_all_classes(struct usbd_context *uds_ctx, const enum usbd_speed speed, uint8_t cfg)
Unregister all available USB class instances.
int usbd_config_attrib_rwup(struct usbd_context *const uds_ctx, const enum usbd_speed speed, const uint8_t cfg, const bool enable)
Setup USB device configuration attribute Remote Wakeup.
void(* usbd_msg_cb_t)(struct usbd_context *const ctx, const struct usbd_msg *const msg)
Callback type definition for USB device message delivery.
Definition usbd.h:272
static void * usbd_class_get_private(const struct usbd_class_data *const c_data)
Get class implementation private data.
Definition usbd.h:445
int usbd_msg_register_cb(struct usbd_context *const uds_ctx, const usbd_msg_cb_t cb)
Register USB notification message callback.
usbd_speed
USB device speed.
Definition usbd.h:230
void usbd_remove_descriptor(struct usbd_desc_node *const desc_nd)
Remove USB string descriptor.
int usbd_add_descriptor(struct usbd_context *uds_ctx, struct usbd_desc_node *dn)
Add common USB descriptor.
int usbd_wakeup_request(struct usbd_context *uds_ctx)
Initiate the USB remote wakeup (TBD)
int usbd_shutdown(struct usbd_context *const uds_ctx)
Shutdown the USB device support.
int usbd_device_set_pid(struct usbd_context *const uds_ctx, const uint16_t pid)
Set USB device descriptor value idProduct.
int usbd_register_class(struct usbd_context *uds_ctx, const char *name, const enum usbd_speed speed, uint8_t cfg)
Register an USB class instance.
int usbd_config_maxpower(struct usbd_context *const uds_ctx, const enum usbd_speed speed, const uint8_t cfg, const uint8_t power)
Setup USB device configuration power consumption.
bool usbd_can_detect_vbus(struct usbd_context *const uds_ctx)
Check that the controller can detect the VBUS state change.
int usbd_add_configuration(struct usbd_context *uds_ctx, const enum usbd_speed speed, struct usbd_config_node *cd)
Add a USB device configuration.
bool usbd_is_suspended(struct usbd_context *uds_ctx)
Checks whether the USB device controller is suspended.
struct net_buf * usbd_ep_buf_alloc(const struct usbd_class_data *const c_data, const uint8_t ep, const size_t size)
Allocate buffer for USB device request.
int usbd_init(struct usbd_context *uds_ctx)
Initialize USB device.
int usbd_device_set_code_triple(struct usbd_context *const uds_ctx, const enum usbd_speed speed, const uint8_t base_class, const uint8_t subclass, const uint8_t protocol)
Set USB device descriptor code triple Base Class, SubClass, and Protocol.
int usbd_ep_buf_free(struct usbd_context *uds_ctx, struct net_buf *buf)
Free USB device request buffer.
int usbd_config_attrib_self(struct usbd_context *const uds_ctx, const enum usbd_speed speed, const uint8_t cfg, const bool enable)
Setup USB device configuration attribute Self-powered.
void usbd_self_powered(struct usbd_context *uds_ctx, const bool status)
Set the self-powered status of the USB device.
bool usbd_ep_is_halted(struct usbd_context *uds_ctx, uint8_t ep)
Checks whether the endpoint is halted.
usbd_ch9_state
USB device support middle layer runtime state.
Definition usbd.h:200
int usbd_ep_ctrl_enqueue(struct usbd_context *const uds_ctx, struct net_buf *const buf)
Queue USB device control request.
int usbd_disable(struct usbd_context *uds_ctx)
Disable the USB device support.
enum usbd_speed usbd_caps_speed(const struct usbd_context *const uds_ctx)
Get highest speed supported by the controller.
int usbd_ep_enqueue(const struct usbd_class_data *const c_data, struct net_buf *const buf)
Queue USB device request.
int usbd_device_register_vreq(struct usbd_context *const uds_ctx, struct usbd_vreq_node *const vreq_nd)
Register an USB vendor request with recipient device.
uint8_t usbd_str_desc_get_idx(const struct usbd_desc_node *const desc_nd)
Get USB string descriptor index from descriptor node.
enum usbd_speed usbd_bus_speed(const struct usbd_context *const uds_ctx)
Get actual device speed.
int usbd_device_set_bcd_usb(struct usbd_context *const uds_ctx, const enum usbd_speed speed, const uint16_t bcd)
Set USB device descriptor value bcdUSB.
#define USBD_NUMOF_INTERFACES_MAX
Definition usbd.h:192
static struct usbd_context * usbd_class_get_ctx(const struct usbd_class_data *const c_data)
Get the USB device runtime context under which the class is registered.
Definition usbd.h:430
int usbd_device_set_bcd_device(struct usbd_context *const uds_ctx, const uint16_t bcd)
Set USB device descriptor value bcdDevice.
@ USBD_SPEED_SS
Device supports or is connected to a super speed bus.
Definition usbd.h:236
@ USBD_SPEED_FS
Device supports or is connected to a full speed bus.
Definition usbd.h:232
@ USBD_SPEED_HS
Device supports or is connected to a high speed bus
Definition usbd.h:234
@ USBD_STATE_CONFIGURED
Definition usbd.h:203
@ USBD_STATE_DEFAULT
Definition usbd.h:201
@ USBD_STATE_ADDRESS
Definition usbd.h:202
state
Definition parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
Mutex Structure.
Definition kernel.h:3070
Network buffer representation.
Definition net_buf.h:1006
uint16_t size
Amount of data that this buffer can store.
Definition net_buf.h:1038
USB Setup Data packet defined in spec.
Definition usb_ch9.h:40
USBD BOS Device Capability descriptor data.
Definition usbd.h:143
enum usbd_bos_desc_utype utype
Descriptor usage type (not bDescriptorType)
Definition usbd.h:145
struct usbd_vreq_node *const vreq_nd
Definition usbd.h:147
Vendor Requests Table.
Definition usbd.h:311
const uint8_t * reqs
Array of vendor requests supported by the class.
Definition usbd.h:313
uint8_t len
Length of the array.
Definition usbd.h:315
USB device support middle layer runtime data.
Definition usbd.h:210
int ctrl_type
Control type, internally used for stage verification.
Definition usbd.h:214
uint8_t configuration
USB device stack selected configuration.
Definition usbd.h:220
uint32_t ep_halt
Halted endpoints bitmap.
Definition usbd.h:218
bool post_status
Post status stage work required, e.g.
Definition usbd.h:222
enum usbd_ch9_state state
Protocol state of the USB device stack.
Definition usbd.h:216
struct usb_setup_packet setup
Setup packet, up-to-date for the respective control request.
Definition usbd.h:212
uint8_t alternate[16U]
Array to track interfaces alternate settings.
Definition usbd.h:224
USB device support class instance API.
Definition usbd.h:326
void(* feature_halt)(struct usbd_class_data *const c_data, uint8_t ep, bool halted)
Feature halt state update handler.
Definition usbd.h:328
void(* update)(struct usbd_class_data *const c_data, uint8_t iface, uint8_t alternate)
Configuration update handler.
Definition usbd.h:332
void(* sof)(struct usbd_class_data *const c_data)
Start of Frame.
Definition usbd.h:356
void(* suspended)(struct usbd_class_data *const c_data)
USB power management handler suspended.
Definition usbd.h:350
void(* shutdown)(struct usbd_class_data *const c_data)
Shutdown of the class implementation.
Definition usbd.h:368
int(* request)(struct usbd_class_data *const c_data, struct net_buf *buf, int err)
Endpoint request completion event handler.
Definition usbd.h:346
int(* init)(struct usbd_class_data *const c_data)
Initialization of the class implementation.
Definition usbd.h:365
int(* control_to_dev)(struct usbd_class_data *const c_data, const struct usb_setup_packet *const setup, const struct net_buf *const buf)
USB control request handler to device.
Definition usbd.h:336
void(* enable)(struct usbd_class_data *const c_data)
Class associated configuration is selected.
Definition usbd.h:359
int(* control_to_host)(struct usbd_class_data *const c_data, const struct usb_setup_packet *const setup, struct net_buf *const buf)
USB control request handler to host.
Definition usbd.h:341
void(* resumed)(struct usbd_class_data *const c_data)
USB power management handler resumed.
Definition usbd.h:353
void(* disable)(struct usbd_class_data *const c_data)
Class associated configuration is disabled.
Definition usbd.h:362
USB device support class data.
Definition usbd.h:378
void * priv
Pointer to private data.
Definition usbd.h:388
struct usbd_context * uds_ctx
Pointer to USB device stack context structure.
Definition usbd.h:382
const struct usbd_cctx_vendor_req * v_reqs
Supported vendor request table, can be NULL.
Definition usbd.h:386
const struct usbd_class_api * api
Pointer to device support class API.
Definition usbd.h:384
const char * name
Name of the USB device class instance.
Definition usbd.h:380
Device configuration node.
Definition usbd.h:180
sys_snode_t node
slist node struct
Definition usbd.h:182
sys_slist_t class_list
List of registered classes (functions)
Definition usbd.h:188
struct usbd_desc_node * str_desc_nd
Optional pointer to string descriptor node.
Definition usbd.h:186
void * desc
Pointer to configuration descriptor.
Definition usbd.h:184
USB device support runtime context.
Definition usbd.h:281
void * fs_desc
Pointer to Full-Speed device descriptor.
Definition usbd.h:303
void * hs_desc
Pointer to High-Speed device descriptor.
Definition usbd.h:305
usbd_msg_cb_t msg_cb
Notification message recipient callback.
Definition usbd.h:289
struct usbd_status status
Status of the USB device support.
Definition usbd.h:301
sys_slist_t hs_configs
slist to manage High-Speed device configurations
Definition usbd.h:297
struct usbd_ch9_data ch9_data
Middle layer runtime data.
Definition usbd.h:291
const struct device * dev
Pointer to UDC device.
Definition usbd.h:287
sys_dlist_t vreqs
dlist to manage vendor requests with recipient device
Definition usbd.h:299
sys_slist_t fs_configs
slist to manage Full-Speed device configurations
Definition usbd.h:295
struct k_mutex mutex
Access mutex.
Definition usbd.h:285
const char * name
Name of the USB device.
Definition usbd.h:283
sys_dlist_t descriptors
slist to manage descriptors like string, BOS
Definition usbd.h:293
Descriptor node.
Definition usbd.h:157
uint8_t bDescriptorType
Descriptor type.
Definition usbd.h:169
sys_dnode_t node
slist node struct
Definition usbd.h:159
const void *const ptr
Opaque pointer to a descriptor payload.
Definition usbd.h:165
uint8_t bLength
Descriptor size in bytes.
Definition usbd.h:167
struct usbd_str_desc_data str
Definition usbd.h:161
struct usbd_bos_desc_data bos
Definition usbd.h:162
USB device message.
Definition usbd_msg.h:88
USB device support status.
Definition usbd.h:242
unsigned int rwup
USB remote wake-up feature is enabled.
Definition usbd.h:250
unsigned int enabled
USB device support is enabled.
Definition usbd.h:246
enum usbd_speed speed
USB device speed.
Definition usbd.h:254
unsigned int initialized
USB device support is initialized.
Definition usbd.h:244
unsigned int self_powered
USB device is self-powered.
Definition usbd.h:252
unsigned int suspended
USB device is suspended.
Definition usbd.h:248
Used internally to keep descriptors in order.
Definition usbd.h:81
uint8_t idx
Descriptor index, required for string descriptors.
Definition usbd.h:83
enum usbd_str_desc_utype utype
Descriptor usage type (not bDescriptorType)
Definition usbd.h:85
unsigned int use_hwinfo
Device stack obtains SerialNumber using the HWINFO API.
Definition usbd.h:89
unsigned int ascii7
The string descriptor is in ASCII7 format.
Definition usbd.h:87
USBD vendor request node.
Definition usbd.h:125
sys_dnode_t node
Node information for the dlist.
Definition usbd.h:127
const uint8_t code
Vendor code (bRequest value)
Definition usbd.h:129
int(* to_host)(const struct usbd_context *const ctx, const struct usb_setup_packet *const setup, struct net_buf *const buf)
Vendor request callback for device-to-host direction.
Definition usbd.h:131
int(* to_dev)(const struct usbd_context *const ctx, const struct usb_setup_packet *const setup, const struct net_buf *const buf)
Vendor request callback for host-to-device direction.
Definition usbd.h:135
Byte order helpers.
Buffers for USB device support.
USB Chapter 9 structures and definitions.
USB support message types and structure.