File tree Expand file tree Collapse file tree 4 files changed +39
-10
lines changed Expand file tree Collapse file tree 4 files changed +39
-10
lines changed Original file line number Diff line number Diff line change @@ -133,10 +133,36 @@ struct usbh_class_data {
133
133
};
134
134
135
135
/**
136
+ * @cond INTERNAL_HIDDEN
137
+ *
138
+ * Variables used by the USB host stack but not exposed to the class
139
+ * through the class API.
136
140
*/
137
- #define USBH_DEFINE_CLASS (name ) \
138
- static STRUCT_SECTION_ITERABLE(usbh_class_data, name)
141
+ struct usbh_class_node {
142
+ /** Class information exposed to host class implementations (drivers). */
143
+ struct usbh_class_data * const c_data ;
144
+ };
145
+ /* @endcond */
139
146
147
+ /**
148
+ * @brief Define USB host support class data
149
+ *
150
+ * Macro defines class (function) data, as well as corresponding node
151
+ * structures used internally by the stack.
152
+ *
153
+ * @param class_name[in] Class name
154
+ * @param class_api[in] Pointer to struct usbh_class_api
155
+ * @param class_priv[in] Class private data
156
+ */
157
+ #define USBH_DEFINE_CLASS (class_name , class_api , class_priv ) \
158
+ static struct usbh_class_data class_data_##class_name = { \
159
+ .name = STRINGIFY(class_name), \
160
+ .api = class_api, \
161
+ .priv = class_priv, \
162
+ }; \
163
+ static STRUCT_SECTION_ITERABLE(usbh_class_node, class_name) = { \
164
+ .c_data = &class_data_##class_name, \
165
+ };
140
166
141
167
/**
142
168
* @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 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_api.h"
16
18
17
19
#include <zephyr/logging/log.h>
18
20
LOG_MODULE_REGISTER (uhs , CONFIG_USBH_LOG_LEVEL );
@@ -194,12 +196,12 @@ int usbh_init_device_intl(struct usbh_context *const uhs_ctx)
194
196
195
197
sys_dlist_init (& uhs_ctx -> udevs );
196
198
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 ;
199
+ STRUCT_SECTION_FOREACH (usbh_class_node , c_node ) {
200
+ ret = usbh_class_init ( c_node -> c_data , uhs_ctx );
201
+ if ( ret != 0 ) {
202
+ LOG_ERR ( "Failed to initialize all registered class instances" );
203
+ return ret ;
204
+ }
203
205
}
204
206
205
207
return 0 ;
Original file line number Diff line number Diff line change 1
1
#include < zephyr/linker/iterable_sections.h>
2
2
3
3
ITERABLE_SECTION_RAM (usbh_context, Z_LINK_ITERABLE_SUBALIGN)
4
- ITERABLE_SECTION_RAM(usbh_class_data , Z_LINK_ITERABLE_SUBALIGN)
4
+ ITERABLE_SECTION_RAM(usbh_class_node , Z_LINK_ITERABLE_SUBALIGN)
You can’t perform that action at this time.
0 commit comments