26
26
extern "C" {
27
27
#endif
28
28
29
+ /**
30
+ * @brief Match flags for USB device identification
31
+ */
32
+ #define USBH_MATCH_DEVICE (1U << 0) /* Match device class code */
33
+ #define USBH_MATCH_INTFACE (1U << 1) /* Match interface code */
34
+
35
+ /* device signal value definitions */
36
+ #define USBH_DEVICE_CONNECTED 1
37
+ #define USBH_DEVICE_DISCONNECTED 2
38
+
29
39
/**
30
40
* @brief USB HOST Core Layer API
31
41
* @defgroup usb_host_core_api USB Host Core API
@@ -49,6 +59,8 @@ struct usbh_contex {
49
59
struct usb_device * root ;
50
60
/** Allocated device addresses bit array */
51
61
struct sys_bitarray * addr_ba ;
62
+ /** Registered classes */
63
+ sys_slist_t registered_classes ;
52
64
};
53
65
54
66
#define USBH_CONTROLLER_DEFINE (device_name , uhc_dev ) \
@@ -73,21 +85,60 @@ struct usbh_code_triple {
73
85
};
74
86
75
87
/**
76
- * @brief USB host class data and class instance API
88
+ * @brief USB device code table for device matching
89
+ */
90
+ struct usbh_device_code_table {
91
+ /** Match type for device identification */
92
+ uint32_t match_type ;
93
+ /** Vendor ID */
94
+ uint16_t vid ;
95
+ /** Product ID */
96
+ uint16_t pid ;
97
+ /** device's class code, subclass code, protocol code. */
98
+ struct usbh_code_triple device_code ;
99
+ /** USB interface class code */
100
+ uint8_t interface_class_code ;
101
+ /** USB interface subclass code */
102
+ uint8_t interface_subclass_code ;
103
+ /** USB interface protocol code */
104
+ uint8_t interface_protocol_code ;
105
+ };
106
+
107
+ /**
108
+ * @brief USB host speed
109
+ */
110
+ enum usbh_speed {
111
+ /** Host supports or is connected to a full speed bus */
112
+ USBH_SPEED_FS ,
113
+ /** Host supports or is connected to a high speed bus */
114
+ USBH_SPEED_HS ,
115
+ /** Host supports or is connected to a super speed bus */
116
+ USBH_SPEED_SS ,
117
+ };
118
+
119
+ /**
120
+ * @brief USB HOST Core Layer API
121
+ * @defgroup usb_host_core_api USB Host Core API
122
+ * @ingroup usb
123
+ * @{
77
124
*/
78
- struct usbh_class_data {
79
- /** Class code supported by this instance */
80
- struct usbh_code_triple code ;
81
125
126
+ /**
127
+ * @brief USB host class data and class instance API
128
+ */
129
+ struct usbh_class_api {
82
130
/** Initialization of the class implementation */
83
- /* int (*init)(struct usbh_contex *const uhs_ctx); */
131
+ int (* init )(struct usbh_contex * const uhs_ctx ,
132
+ struct usbh_class_data * cdata );
84
133
/** Request completion event handler */
85
134
int (* request )(struct usbh_contex * const uhs_ctx ,
86
135
struct uhc_transfer * const xfer , int err );
87
136
/** Device connected handler */
88
- int (* connected )(struct usbh_contex * const uhs_ctx );
137
+ int (* connected )(struct usb_device * udev ,
138
+ void * desc_start_addr , void * desc_end_addr , struct usbh_class_data * cdata );
89
139
/** Device removed handler */
90
- int (* removed )(struct usbh_contex * const uhs_ctx );
140
+ int (* removed )(struct usbh_contex * const uhs_ctx ,
141
+ struct usbh_class_data * cdata );
91
142
/** Bus remote wakeup handler */
92
143
int (* rwup )(struct usbh_contex * const uhs_ctx );
93
144
/** Bus suspended handler */
@@ -97,11 +148,46 @@ struct usbh_class_data {
97
148
};
98
149
99
150
/**
151
+ * @brief USB host class data and class instance API
100
152
*/
101
- #define USBH_DEFINE_CLASS (name ) \
102
- static STRUCT_SECTION_ITERABLE(usbh_class_data, name)
153
+ struct usbh_class_data {
154
+ /** System linked list node for registered classes */
155
+ sys_snode_t node ;
156
+ /** Name of the USB host class instance */
157
+ const char * name ;
158
+ /** Pointer to host support class API */
159
+ const struct usbh_class_api * api ;
160
+ /** Pointer to private data */
161
+ void * priv ;
162
+ /** Pointer to device code table for class matching */
163
+ const struct usbh_device_code_table * device_code_table ;
164
+ /** Number of items in device code table */
165
+ uint8_t table_items_count ;
166
+ /** Flag indicating if class has been matched to a device */
167
+ uint8_t class_matched ;
168
+ };
103
169
104
170
171
+ /**
172
+ * @brief Define USB host support class data
173
+ *
174
+ * Macro defines class (function) data, as well as corresponding node
175
+ * structures used internally by the stack.
176
+ *
177
+ * @param class_name Class name
178
+ * @param class_api Pointer to struct usbd_class_api
179
+ * @param class_priv Class private data
180
+ */
181
+ #define USBH_DEFINE_CLASS (class_name , class_api , class_priv , code_table , items_count ) \
182
+ static STRUCT_SECTION_ITERABLE(usbh_class_data, class_name) = { \
183
+ .name = STRINGIFY(class_name), \
184
+ .api = class_api, \
185
+ .priv = class_priv, \
186
+ .device_code_table = code_table, \
187
+ .table_items_count = items_count, \
188
+ .class_matched = 0, \
189
+ };
190
+
105
191
/**
106
192
* @brief Initialize the USB host support;
107
193
*
0 commit comments