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 @@ -129,10 +129,36 @@ struct usbh_class_data {
129
129
};
130
130
131
131
/**
132
+ * @cond INTERNAL_HIDDEN
133
+ *
134
+ * Variables used by the USB host stack but not exposed to the class
135
+ * through the class API.
132
136
*/
133
- #define USBH_DEFINE_CLASS (name ) \
134
- static STRUCT_SECTION_ITERABLE(usbh_class_data, name)
137
+ struct usbh_class_node {
138
+ /** Class information exposed to host class implementations (drivers). */
139
+ struct usbh_class_data * const c_data ;
140
+ };
141
+ /* @endcond */
135
142
143
+ /**
144
+ * @brief Define USB host support class data
145
+ *
146
+ * Macro defines class (function) data, as well as corresponding node
147
+ * structures used internally by the stack.
148
+ *
149
+ * @param class_name[in] Class name
150
+ * @param class_api[in] Pointer to struct usbh_class_api
151
+ * @param class_priv[in] Class private data
152
+ */
153
+ #define USBH_DEFINE_CLASS (class_name , class_api , class_priv ) \
154
+ static struct usbh_class_data class_data_##class_name = { \
155
+ .name = STRINGIFY(class_name), \
156
+ .api = class_api, \
157
+ .priv = class_priv, \
158
+ }; \
159
+ static STRUCT_SECTION_ITERABLE(usbh_class_node, class_name) = { \
160
+ .c_data = &class_data_##class_name, \
161
+ };
136
162
137
163
/**
138
164
* @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