2626extern "C" {
2727#endif
2828
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+
2939/**
3040 * @brief USB HOST Core Layer API
3141 * @defgroup usb_host_core_api USB Host Core API
@@ -49,6 +59,8 @@ struct usbh_contex {
4959 struct usb_device * root ;
5060 /** Allocated device addresses bit array */
5161 struct sys_bitarray * addr_ba ;
62+ /** Registered classes */
63+ sys_slist_t registered_classes ;
5264};
5365
5466#define USBH_CONTROLLER_DEFINE (device_name , uhc_dev ) \
@@ -73,21 +85,60 @@ struct usbh_code_triple {
7385};
7486
7587/**
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+ * @{
77124 */
78- struct usbh_class_data {
79- /** Class code supported by this instance */
80- struct usbh_code_triple code ;
81125
126+ /**
127+ * @brief USB host class data and class instance API
128+ */
129+ struct usbh_class_api {
82130 /** 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 );
84133 /** Request completion event handler */
85134 int (* request )(struct usbh_contex * const uhs_ctx ,
86135 struct uhc_transfer * const xfer , int err );
87136 /** 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 );
89139 /** 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 );
91142 /** Bus remote wakeup handler */
92143 int (* rwup )(struct usbh_contex * const uhs_ctx );
93144 /** Bus suspended handler */
@@ -97,11 +148,46 @@ struct usbh_class_data {
97148};
98149
99150/**
151+ * @brief USB host class data and class instance API
100152 */
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+ };
103169
104170
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+
105191/**
106192 * @brief Initialize the USB host support;
107193 *
0 commit comments