File tree Expand file tree Collapse file tree 4 files changed +65
-9
lines changed
Expand file tree Collapse file tree 4 files changed +65
-9
lines changed Original file line number Diff line number Diff line change @@ -135,10 +135,35 @@ struct usbh_class_data {
135135};
136136
137137/**
138+ * @cond INTERNAL_HIDDEN
138139 */
139- #define USBH_DEFINE_CLASS (name ) \
140- static STRUCT_SECTION_ITERABLE(usbh_class_data, name)
140+ struct usbh_class_node {
141+ /** System linked list node for registered classes */
142+ sys_snode_t node ;
143+ /** Node information for the slist. */
144+ struct usbh_class_data * const c_data ;
145+ };
146+ /* @endcond */
141147
148+ /**
149+ * @brief Define USB host support class data
150+ *
151+ * Macro defines class (function) data, as well as corresponding node
152+ * structures used internally by the stack.
153+ *
154+ * @param class_name[in] Class name
155+ * @param class_api[in] Pointer to struct usbh_class_api
156+ * @param class_priv[in] Class private data
157+ */
158+ #define USBH_DEFINE_CLASS (class_name , class_api , class_priv ) \
159+ static const struct usbh_class_data class_data_##class_name = { \
160+ .name = STRINGIFY(class_name), \
161+ .api = class_api, \
162+ .priv = class_priv, \
163+ }; \
164+ static STRUCT_SECTION_ITERABLE(usbh_class_node, class_name) = { \
165+ .c_data = &class_data_##class_name, \
166+ }; \
142167
143168/**
144169 * @brief Initialize the USB host support;
Original file line number Diff line number Diff line change @@ -5,9 +5,10 @@ zephyr_library()
55zephyr_library_include_directories(${CMAKE_CURRENT_SOURCE_DIR} )
66
77zephyr_library_sources(
8+ usbh_api.c
89 usbh_ch9.c
10+ usbh_class.c
911 usbh_core.c
10- usbh_api.c
1112 usbh_device.c
1213)
1314
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2025 Nordic Semiconductor ASA
3+ * Copyright 2025 NXP
4+ *
5+ * SPDX-License-Identifier: Apache-2.0
6+ */
7+
8+ #ifndef ZEPHYR_INCLUDE_USBD_CLASS_H
9+ #define ZEPHYR_INCLUDE_USBD_CLASS_H
10+
11+ #include <zephyr/usb/usbh.h>
12+
13+ /**
14+ * @brief Auto-register all compile-time defined class drivers
15+ */
16+ int usbh_register_all_classes (struct usbh_context * uhs_ctx );
17+
18+ /**
19+ * @brief Initialize registered class drivers
20+ */
21+ int usbh_init_registered_classes (struct usbh_context * uhs_ctx );
22+
23+ #endif /* ZEPHYR_INCLUDE_USBD_CLASS_H */
Original file line number Diff line number Diff line change 1010#include <zephyr/devicetree.h>
1111#include <zephyr/init.h>
1212#include <zephyr/sys/iterable_sections.h>
13+ #include <zephyr/usb/usbh.h>
1314
1415#include "usbh_internal.h"
1516#include "usbh_device.h"
17+ #include "usbh_class.h"
1618
1719#include <zephyr/logging/log.h>
1820LOG_MODULE_REGISTER (uhs , CONFIG_USBH_LOG_LEVEL );
@@ -193,13 +195,18 @@ int usbh_init_device_intl(struct usbh_context *const uhs_ctx)
193195 }
194196
195197 sys_dlist_init (& uhs_ctx -> udevs );
198+ sys_slist_init (& uhs_ctx -> class_list );
196199
197- STRUCT_SECTION_FOREACH (usbh_class_data , cdata ) {
198- /*
199- * For now, we have not implemented any class drivers,
200- * so just keep it as placeholder.
201- */
202- break ;
200+ ret = usbh_register_all_classes (uhs_ctx );
201+ if (ret != 0 ) {
202+ LOG_ERR ("Failed to auto-register class instances" );
203+ return ret ;
204+ }
205+
206+ ret = usbh_init_registered_classes (uhs_ctx );
207+ if (ret != 0 ) {
208+ LOG_ERR ("Failed to initialize all registered class instances" );
209+ return ret ;
203210 }
204211
205212 return 0 ;
You can’t perform that action at this time.
0 commit comments