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 USB Unicode bString is encoded in UTF16LE, which means it takes up
48 * twice the amount of bytes than the same string encoded in ASCII7.
49 * Use this macro to determine the length of the bString array.
50 *
51 * bString length without null character:
52 * bString_length = (sizeof(initializer_string) - 1) * 2
53 * or:
54 * bString_length = sizeof(initializer_string) * 2 - 2
55 */
56#define USB_BSTRING_LENGTH(s) (sizeof(s) * 2 - 2)
57
58/*
59 * The length of the string descriptor (bLength) is calculated from the
60 * size of the two octets bLength and bDescriptorType plus the
61 * length of the UTF16LE string:
62 *
63 * bLength = 2 + bString_length
64 * bLength = 2 + sizeof(initializer_string) * 2 - 2
65 * bLength = sizeof(initializer_string) * 2
66 * Use this macro to determine the bLength of the string descriptor.
67 */
68#define USB_STRING_DESCRIPTOR_LENGTH(s) (sizeof(s) * 2)
69
70struct usbd_context;
71
75enum usbd_str_desc_utype {
76 USBD_DUT_STRING_LANG,
77 USBD_DUT_STRING_MANUFACTURER,
78 USBD_DUT_STRING_PRODUCT,
79 USBD_DUT_STRING_SERIAL_NUMBER,
80 USBD_DUT_STRING_CONFIG,
81 USBD_DUT_STRING_INTERFACE,
82};
83
84enum usbd_bos_desc_utype {
85 USBD_DUT_BOS_NONE,
86 USBD_DUT_BOS_VREQ,
87};
97 enum usbd_str_desc_utype utype : 8;
99 unsigned int ascii7 : 1;
101 unsigned int use_hwinfo : 1;
102};
103
143 int (*to_host)(const struct usbd_context *const ctx,
144 const struct usb_setup_packet *const setup,
145 struct net_buf *const buf);
147 int (*to_dev)(const struct usbd_context *const ctx,
148 const struct usb_setup_packet *const setup,
149 const struct net_buf *const buf);
150};
151
157 enum usbd_bos_desc_utype utype : 8;
158 union {
159 struct usbd_vreq_node *const vreq_nd;
160 };
161};
162
183
202
203/* TODO: Kconfig option USBD_NUMOF_INTERFACES_MAX? */
204#define USBD_NUMOF_INTERFACES_MAX 16U
205
217
218
238
250
256 unsigned int initialized : 1;
258 unsigned int enabled : 1;
260 unsigned int suspended : 1;
262 unsigned int rwup : 1;
264 unsigned int self_powered : 1;
267};
268
284typedef void (*usbd_msg_cb_t)(struct usbd_context *const ctx,
285 const struct usbd_msg *const msg);
286
319
329
331#define USBD_CCTX_REGISTERED 0
332
333struct usbd_class_data;
334
340 void (*feature_halt)(struct usbd_class_data *const c_data,
341 uint8_t ep, bool halted);
342
344 void (*update)(struct usbd_class_data *const c_data,
345 uint8_t iface, uint8_t alternate);
346
348 int (*control_to_dev)(struct usbd_class_data *const c_data,
349 const struct usb_setup_packet *const setup,
350 const struct net_buf *const buf);
351
353 int (*control_to_host)(struct usbd_class_data *const c_data,
354 const struct usb_setup_packet *const setup,
355 struct net_buf *const buf);
356
358 int (*request)(struct usbd_class_data *const c_data,
359 struct net_buf *buf, int err);
360
362 void (*suspended)(struct usbd_class_data *const c_data);
363
365 void (*resumed)(struct usbd_class_data *const c_data);
366
368 void (*sof)(struct usbd_class_data *const c_data);
369
371 void (*enable)(struct usbd_class_data *const c_data);
372
374 void (*disable)(struct usbd_class_data *const c_data);
375
377 int (*init)(struct usbd_class_data *const c_data);
378
380 void (*shutdown)(struct usbd_class_data *const c_data);
381
383 void *(*get_desc)(struct usbd_class_data *const c_data,
384 const enum usbd_speed speed);
385};
386
392 const char *name;
396 const struct usbd_class_api *api;
400 void *priv;
401};
402
411struct usbd_class_node {
413 sys_snode_t node;
415 struct usbd_class_data *const c_data;
419 uint32_t ep_assigned;
423 uint32_t ep_active;
425 uint32_t iface_bm;
428};
429
442static inline struct usbd_context *usbd_class_get_ctx(const struct usbd_class_data *const c_data)
443{
444 return c_data->uds_ctx;
445}
446
457static inline void *usbd_class_get_private(const struct usbd_class_data *const c_data)
458{
459 return c_data->priv;
460}
461
482#define USBD_DEVICE_DEFINE(device_name, udc_dev, vid, pid) \
483 static struct usb_device_descriptor \
484 fs_desc_##device_name = { \
485 .bLength = sizeof(struct usb_device_descriptor), \
486 .bDescriptorType = USB_DESC_DEVICE, \
487 .bcdUSB = sys_cpu_to_le16(USB_SRN_2_0), \
488 .bDeviceClass = USB_BCC_MISCELLANEOUS, \
489 .bDeviceSubClass = 2, \
490 .bDeviceProtocol = 1, \
491 .bMaxPacketSize0 = USB_CONTROL_EP_MPS, \
492 .idVendor = vid, \
493 .idProduct = pid, \
494 .bcdDevice = sys_cpu_to_le16(USB_BCD_DRN), \
495 .iManufacturer = 0, \
496 .iProduct = 0, \
497 .iSerialNumber = 0, \
498 .bNumConfigurations = 0, \
499 }; \
500 IF_ENABLED(USBD_SUPPORTS_HIGH_SPEED, ( \
501 static struct usb_device_descriptor \
502 hs_desc_##device_name = { \
503 .bLength = sizeof(struct usb_device_descriptor), \
504 .bDescriptorType = USB_DESC_DEVICE, \
505 .bcdUSB = sys_cpu_to_le16(USB_SRN_2_0), \
506 .bDeviceClass = USB_BCC_MISCELLANEOUS, \
507 .bDeviceSubClass = 2, \
508 .bDeviceProtocol = 1, \
509 .bMaxPacketSize0 = 64, \
510 .idVendor = vid, \
511 .idProduct = pid, \
512 .bcdDevice = sys_cpu_to_le16(USB_BCD_DRN), \
513 .iManufacturer = 0, \
514 .iProduct = 0, \
515 .iSerialNumber = 0, \
516 .bNumConfigurations = 0, \
517 }; \
518 )) \
519 static STRUCT_SECTION_ITERABLE(usbd_context, device_name) = { \
520 .name = STRINGIFY(device_name), \
521 .dev = udc_dev, \
522 .fs_desc = &fs_desc_##device_name, \
523 IF_ENABLED(USBD_SUPPORTS_HIGH_SPEED, ( \
524 .hs_desc = &hs_desc_##device_name, \
525 )) \
526 }
527
545#define USBD_CONFIGURATION_DEFINE(name, attrib, power, desc_nd) \
546 static struct usb_cfg_descriptor \
547 cfg_desc_##name = { \
548 .bLength = sizeof(struct usb_cfg_descriptor), \
549 .bDescriptorType = USB_DESC_CONFIGURATION, \
550 .wTotalLength = 0, \
551 .bNumInterfaces = 0, \
552 .bConfigurationValue = 1, \
553 .iConfiguration = 0, \
554 .bmAttributes = USB_SCD_RESERVED | (attrib), \
555 .bMaxPower = (power), \
556 }; \
557 BUILD_ASSERT((power) < 256, "Too much power"); \
558 static struct usbd_config_node name = { \
559 .desc = &cfg_desc_##name, \
560 .str_desc_nd = desc_nd, \
561 }
562
576#define USBD_DESC_LANG_DEFINE(name) \
577 static uint16_t langid_##name = sys_cpu_to_le16(0x0409); \
578 static struct usbd_desc_node name = { \
579 .str = { \
580 .idx = 0, \
581 .utype = USBD_DUT_STRING_LANG, \
582 }, \
583 .ptr = &langid_##name, \
584 .bLength = sizeof(struct usb_string_descriptor), \
585 .bDescriptorType = USB_DESC_STRING, \
586 }
587
599#define USBD_DESC_STRING_DEFINE(d_name, d_string, d_utype) \
600 static uint8_t ascii_##d_name[USB_BSTRING_LENGTH(d_string)] = d_string; \
601 static struct usbd_desc_node d_name = { \
602 .str = { \
603 .utype = d_utype, \
604 .ascii7 = true, \
605 }, \
606 .ptr = &ascii_##d_name, \
607 .bLength = USB_STRING_DESCRIPTOR_LENGTH(d_string), \
608 .bDescriptorType = USB_DESC_STRING, \
609 }
610
622#define USBD_DESC_MANUFACTURER_DEFINE(d_name, d_string) \
623 USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_MANUFACTURER)
624
636#define USBD_DESC_PRODUCT_DEFINE(d_name, d_string) \
637 USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_PRODUCT)
638
649#define USBD_DESC_SERIAL_NUMBER_DEFINE(d_name) \
650 BUILD_ASSERT(IS_ENABLED(CONFIG_HWINFO), "HWINFO not enabled"); \
651 static struct usbd_desc_node d_name = { \
652 .str = { \
653 .utype = USBD_DUT_STRING_SERIAL_NUMBER, \
654 .ascii7 = true, \
655 .use_hwinfo = true, \
656 }, \
657 .bDescriptorType = USB_DESC_STRING, \
658 }
659
669#define USBD_DESC_CONFIG_DEFINE(d_name, d_string) \
670 USBD_DESC_STRING_DEFINE(d_name, d_string, USBD_DUT_STRING_CONFIG)
671
684#define USBD_DESC_BOS_DEFINE(name, len, subset) \
685 BUILD_ASSERT(IS_ENABLED(CONFIG_USBD_BOS_SUPPORT), \
686 "USB device BOS support is disabled"); \
687 static struct usbd_desc_node name = { \
688 .bos = { \
689 .utype = USBD_DUT_BOS_NONE, \
690 }, \
691 .ptr = subset, \
692 .bLength = len, \
693 .bDescriptorType = USB_DESC_BOS, \
694 }
695
706#define USBD_VREQUEST_DEFINE(name, vcode, vto_host, vto_dev) \
707 BUILD_ASSERT(IS_ENABLED(CONFIG_USBD_VREQ_SUPPORT), \
708 "USB device vendor request support is disabled"); \
709 static struct usbd_vreq_node name = { \
710 .code = vcode, \
711 .to_host = vto_host, \
712 .to_dev = vto_dev, \
713 }
714
734#define USBD_DESC_BOS_VREQ_DEFINE(name, len, subset, vcode, vto_host, vto_dev) \
735 BUILD_ASSERT(IS_ENABLED(CONFIG_USBD_BOS_SUPPORT), \
736 "USB device BOS support is disabled"); \
737 USBD_VREQUEST_DEFINE(vreq_nd_##name, vcode, vto_host, vto_dev); \
738 static struct usbd_desc_node name = { \
739 .bos = { \
740 .utype = USBD_DUT_BOS_VREQ, \
741 .vreq_nd = &vreq_nd_##name, \
742 }, \
743 .ptr = subset, \
744 .bLength = len, \
745 .bDescriptorType = USB_DESC_BOS, \
746 }
747
759#define USBD_DEFINE_CLASS(class_name, class_api, class_priv, class_v_reqs) \
760 static struct usbd_class_data class_name = { \
761 .name = STRINGIFY(class_name), \
762 .api = class_api, \
763 .v_reqs = class_v_reqs, \
764 .priv = class_priv, \
765 }; \
766 static STRUCT_SECTION_ITERABLE_ALTERNATE( \
767 usbd_class_fs, usbd_class_node, class_name##_fs) = { \
768 .c_data = &class_name, \
769 }; \
770 IF_ENABLED(USBD_SUPPORTS_HIGH_SPEED, ( \
771 static STRUCT_SECTION_ITERABLE_ALTERNATE( \
772 usbd_class_hs, usbd_class_node, class_name##_hs) = { \
773 .c_data = &class_name, \
774 } \
775 ))
776
782#define VENDOR_REQ_DEFINE(_reqs, _len) \
783 { \
784 .reqs = (const uint8_t *)(_reqs), \
785 .len = (_len), \
786 }
787
792#define USBD_VENDOR_REQ(_reqs...) \
793 VENDOR_REQ_DEFINE(((uint8_t []) { _reqs }), \
794 sizeof((uint8_t []) { _reqs }))
795
796
808 struct usbd_desc_node *dn);
809
817uint8_t usbd_str_desc_get_idx(const struct usbd_desc_node *const desc_nd);
818
826void usbd_remove_descriptor(struct usbd_desc_node *const desc_nd);
827
838 const enum usbd_speed speed,
839 struct usbd_config_node *cd);
840
863 const char *name,
864 const enum usbd_speed speed, uint8_t cfg);
865
898 const enum usbd_speed speed, uint8_t cfg,
899 const char *const blocklist[]);
900
916 const char *name,
917 const enum usbd_speed speed, uint8_t cfg);
918
932 const enum usbd_speed speed, uint8_t cfg);
933
942int usbd_msg_register_cb(struct usbd_context *const uds_ctx,
943 const usbd_msg_cb_t cb);
944
958int usbd_init(struct usbd_context *uds_ctx);
959
969int usbd_enable(struct usbd_context *uds_ctx);
970
980int usbd_disable(struct usbd_context *uds_ctx);
981
991int usbd_shutdown(struct usbd_context *const uds_ctx);
992
1001int usbd_ep_set_halt(struct usbd_context *uds_ctx, uint8_t ep);
1002
1011int usbd_ep_clear_halt(struct usbd_context *uds_ctx, uint8_t ep);
1012
1021bool usbd_ep_is_halted(struct usbd_context *uds_ctx, uint8_t ep);
1022
1034struct net_buf *usbd_ep_buf_alloc(const struct usbd_class_data *const c_data,
1035 const uint8_t ep, const size_t size);
1036
1047int usbd_ep_ctrl_enqueue(struct usbd_context *const uds_ctx,
1048 struct net_buf *const buf);
1049
1060int usbd_ep_enqueue(const struct usbd_class_data *const c_data,
1061 struct net_buf *const buf);
1062
1071int usbd_ep_dequeue(struct usbd_context *uds_ctx, const uint8_t ep);
1072
1083int usbd_ep_buf_free(struct usbd_context *uds_ctx, struct net_buf *buf);
1084
1092bool usbd_is_suspended(struct usbd_context *uds_ctx);
1093
1100
1110void usbd_self_powered(struct usbd_context *uds_ctx, const bool status);
1111
1119enum usbd_speed usbd_bus_speed(const struct usbd_context *const uds_ctx);
1120
1128enum usbd_speed usbd_caps_speed(const struct usbd_context *const uds_ctx);
1129
1139int usbd_device_set_bcd_usb(struct usbd_context *const uds_ctx,
1140 const enum usbd_speed speed, const uint16_t bcd);
1141
1150int usbd_device_set_vid(struct usbd_context *const uds_ctx,
1151 const uint16_t vid);
1152
1161int usbd_device_set_pid(struct usbd_context *const uds_ctx,
1162 const uint16_t pid);
1163
1173 const uint16_t bcd);
1174
1187 const enum usbd_speed speed,
1188 const uint8_t base_class,
1189 const uint8_t subclass, const uint8_t protocol);
1190
1201int usbd_config_attrib_rwup(struct usbd_context *const uds_ctx,
1202 const enum usbd_speed speed,
1203 const uint8_t cfg, const bool enable);
1204
1215int usbd_config_attrib_self(struct usbd_context *const uds_ctx,
1216 const enum usbd_speed speed,
1217 const uint8_t cfg, const bool enable);
1218
1229int usbd_config_maxpower(struct usbd_context *const uds_ctx,
1230 const enum usbd_speed speed,
1231 const uint8_t cfg, const uint8_t power);
1232
1245bool usbd_can_detect_vbus(struct usbd_context *const uds_ctx);
1246
1258int usbd_device_register_vreq(struct usbd_context *const uds_ctx,
1259 struct usbd_vreq_node *const vreq_nd);
1260
1265#ifdef __cplusplus
1266}
1267#endif
1268
1269#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:284
static void * usbd_class_get_private(const struct usbd_class_data *const c_data)
Get class implementation private data.
Definition usbd.h:457
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:242
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:212
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:204
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:442
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:248
@ USBD_SPEED_FS
Device supports or is connected to a full speed bus.
Definition usbd.h:244
@ USBD_SPEED_HS
Device supports or is connected to a high speed bus
Definition usbd.h:246
@ USBD_STATE_CONFIGURED
Definition usbd.h:215
@ USBD_STATE_DEFAULT
Definition usbd.h:213
@ USBD_STATE_ADDRESS
Definition usbd.h:214
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:155
enum usbd_bos_desc_utype utype
Descriptor usage type (not bDescriptorType)
Definition usbd.h:157
struct usbd_vreq_node *const vreq_nd
Definition usbd.h:159
Vendor Requests Table.
Definition usbd.h:323
const uint8_t * reqs
Array of vendor requests supported by the class.
Definition usbd.h:325
uint8_t len
Length of the array.
Definition usbd.h:327
USB device support middle layer runtime data.
Definition usbd.h:222
int ctrl_type
Control type, internally used for stage verification.
Definition usbd.h:226
uint8_t configuration
USB device stack selected configuration.
Definition usbd.h:232
uint32_t ep_halt
Halted endpoints bitmap.
Definition usbd.h:230
bool post_status
Post status stage work required, e.g.
Definition usbd.h:234
enum usbd_ch9_state state
Protocol state of the USB device stack.
Definition usbd.h:228
struct usb_setup_packet setup
Setup packet, up-to-date for the respective control request.
Definition usbd.h:224
uint8_t alternate[16U]
Array to track interfaces alternate settings.
Definition usbd.h:236
USB device support class instance API.
Definition usbd.h:338
void(* feature_halt)(struct usbd_class_data *const c_data, uint8_t ep, bool halted)
Feature halt state update handler.
Definition usbd.h:340
void(* update)(struct usbd_class_data *const c_data, uint8_t iface, uint8_t alternate)
Configuration update handler.
Definition usbd.h:344
void(* sof)(struct usbd_class_data *const c_data)
Start of Frame.
Definition usbd.h:368
void(* suspended)(struct usbd_class_data *const c_data)
USB power management handler suspended.
Definition usbd.h:362
void(* shutdown)(struct usbd_class_data *const c_data)
Shutdown of the class implementation.
Definition usbd.h:380
int(* request)(struct usbd_class_data *const c_data, struct net_buf *buf, int err)
Endpoint request completion event handler.
Definition usbd.h:358
int(* init)(struct usbd_class_data *const c_data)
Initialization of the class implementation.
Definition usbd.h:377
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:348
void(* enable)(struct usbd_class_data *const c_data)
Class associated configuration is selected.
Definition usbd.h:371
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:353
void(* resumed)(struct usbd_class_data *const c_data)
USB power management handler resumed.
Definition usbd.h:365
void(* disable)(struct usbd_class_data *const c_data)
Class associated configuration is disabled.
Definition usbd.h:374
USB device support class data.
Definition usbd.h:390
void * priv
Pointer to private data.
Definition usbd.h:400
struct usbd_context * uds_ctx
Pointer to USB device stack context structure.
Definition usbd.h:394
const struct usbd_cctx_vendor_req * v_reqs
Supported vendor request table, can be NULL.
Definition usbd.h:398
const struct usbd_class_api * api
Pointer to device support class API.
Definition usbd.h:396
const char * name
Name of the USB device class instance.
Definition usbd.h:392
Device configuration node.
Definition usbd.h:192
sys_snode_t node
slist node struct
Definition usbd.h:194
sys_slist_t class_list
List of registered classes (functions)
Definition usbd.h:200
struct usbd_desc_node * str_desc_nd
Optional pointer to string descriptor node.
Definition usbd.h:198
void * desc
Pointer to configuration descriptor.
Definition usbd.h:196
USB device support runtime context.
Definition usbd.h:293
void * fs_desc
Pointer to Full-Speed device descriptor.
Definition usbd.h:315
void * hs_desc
Pointer to High-Speed device descriptor.
Definition usbd.h:317
usbd_msg_cb_t msg_cb
Notification message recipient callback.
Definition usbd.h:301
struct usbd_status status
Status of the USB device support.
Definition usbd.h:313
sys_slist_t hs_configs
slist to manage High-Speed device configurations
Definition usbd.h:309
struct usbd_ch9_data ch9_data
Middle layer runtime data.
Definition usbd.h:303
const struct device * dev
Pointer to UDC device.
Definition usbd.h:299
sys_dlist_t vreqs
dlist to manage vendor requests with recipient device
Definition usbd.h:311
sys_slist_t fs_configs
slist to manage Full-Speed device configurations
Definition usbd.h:307
struct k_mutex mutex
Access mutex.
Definition usbd.h:297
const char * name
Name of the USB device.
Definition usbd.h:295
sys_dlist_t descriptors
slist to manage descriptors like string, BOS
Definition usbd.h:305
Descriptor node.
Definition usbd.h:169
uint8_t bDescriptorType
Descriptor type.
Definition usbd.h:181
sys_dnode_t node
slist node struct
Definition usbd.h:171
const void *const ptr
Opaque pointer to a descriptor payload.
Definition usbd.h:177
uint8_t bLength
Descriptor size in bytes.
Definition usbd.h:179
struct usbd_str_desc_data str
Definition usbd.h:173
struct usbd_bos_desc_data bos
Definition usbd.h:174
USB device message.
Definition usbd_msg.h:88
USB device support status.
Definition usbd.h:254
unsigned int rwup
USB remote wake-up feature is enabled.
Definition usbd.h:262
unsigned int enabled
USB device support is enabled.
Definition usbd.h:258
enum usbd_speed speed
USB device speed.
Definition usbd.h:266
unsigned int initialized
USB device support is initialized.
Definition usbd.h:256
unsigned int self_powered
USB device is self-powered.
Definition usbd.h:264
unsigned int suspended
USB device is suspended.
Definition usbd.h:260
Used internally to keep descriptors in order.
Definition usbd.h:93
uint8_t idx
Descriptor index, required for string descriptors.
Definition usbd.h:95
enum usbd_str_desc_utype utype
Descriptor usage type (not bDescriptorType)
Definition usbd.h:97
unsigned int use_hwinfo
Device stack obtains SerialNumber using the HWINFO API.
Definition usbd.h:101
unsigned int ascii7
The string descriptor is in ASCII7 format.
Definition usbd.h:99
USBD vendor request node.
Definition usbd.h:137
sys_dnode_t node
Node information for the dlist.
Definition usbd.h:139
const uint8_t code
Vendor code (bRequest value)
Definition usbd.h:141
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:143
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:147
Byte order helpers.
Buffers for USB device support.
USB Chapter 9 structures and definitions.
USB support message types and structure.