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 {
135
135
};
136
136
137
137
/**
138
+ * @cond INTERNAL_HIDDEN
138
139
*/
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 */
141
147
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
+ }; \
142
167
143
168
/**
144
169
* @brief Initialize the USB host support;
Original file line number Diff line number Diff line change @@ -5,9 +5,10 @@ zephyr_library()
5
5
zephyr_library_include_directories(${CMAKE_CURRENT_SOURCE_DIR} )
6
6
7
7
zephyr_library_sources(
8
+ usbh_api.c
8
9
usbh_ch9.c
10
+ usbh_class.c
9
11
usbh_core.c
10
- usbh_api.c
11
12
usbh_device.c
12
13
)
13
14
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 10
10
#include <zephyr/devicetree.h>
11
11
#include <zephyr/init.h>
12
12
#include <zephyr/sys/iterable_sections.h>
13
+ #include <zephyr/usb/usbh.h>
13
14
14
15
#include "usbh_internal.h"
15
16
#include "usbh_device.h"
17
+ #include "usbh_class.h"
16
18
17
19
#include <zephyr/logging/log.h>
18
20
LOG_MODULE_REGISTER (uhs , CONFIG_USBH_LOG_LEVEL );
@@ -193,13 +195,18 @@ int usbh_init_device_intl(struct usbh_context *const uhs_ctx)
193
195
}
194
196
195
197
sys_dlist_init (& uhs_ctx -> udevs );
198
+ sys_slist_init (& uhs_ctx -> class_list );
196
199
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 ;
203
210
}
204
211
205
212
return 0 ;
You can’t perform that action at this time.
0 commit comments