@@ -43,6 +43,47 @@ static int usbh_event_carrier(const struct device *dev,
4343 return err ;
4444}
4545
46+ static void dev_connected_handler (struct usbh_contex * const ctx ,
47+ const struct uhc_event * const event )
48+ {
49+
50+ LOG_DBG ("Device connected event" );
51+ if (ctx -> root != NULL ) {
52+ LOG_ERR ("Device already connected" );
53+ usbh_device_free (ctx -> root );
54+ ctx -> root = NULL ;
55+ }
56+
57+ ctx -> root = usbh_device_alloc (ctx );
58+ if (ctx -> root == NULL ) {
59+ LOG_ERR ("Failed allocate new device" );
60+ return ;
61+ }
62+
63+ ctx -> root -> state = USB_STATE_DEFAULT ;
64+
65+ if (event -> type == UHC_EVT_DEV_CONNECTED_HS ) {
66+ ctx -> root -> speed = USB_SPEED_SPEED_HS ;
67+ } else {
68+ ctx -> root -> speed = USB_SPEED_SPEED_FS ;
69+ }
70+
71+ if (usbh_device_init (ctx -> root )) {
72+ LOG_ERR ("Failed to reset new USB device" );
73+ }
74+ }
75+
76+ static void dev_removed_handler (struct usbh_contex * const ctx )
77+ {
78+ if (ctx -> root != NULL ) {
79+ usbh_device_free (ctx -> root );
80+ ctx -> root = NULL ;
81+ LOG_DBG ("Device removed" );
82+ } else {
83+ LOG_DBG ("Spurious device removed event" );
84+ }
85+ }
86+
4687static int discard_ep_request (struct usbh_contex * const ctx ,
4788 struct uhc_transfer * const xfer )
4889{
@@ -63,12 +104,14 @@ static ALWAYS_INLINE int usbh_event_handler(struct usbh_contex *const ctx,
63104
64105 switch (event -> type ) {
65106 case UHC_EVT_DEV_CONNECTED_LS :
107+ LOG_ERR ("Low speed device not supported (connected event)" );
108+ break ;
66109 case UHC_EVT_DEV_CONNECTED_FS :
67110 case UHC_EVT_DEV_CONNECTED_HS :
68- LOG_DBG ( "Device connected event" );
111+ dev_connected_handler ( ctx , event );
69112 break ;
70113 case UHC_EVT_DEV_REMOVED :
71- LOG_DBG ( "Device removed event" );
114+ dev_removed_handler ( ctx );
72115 break ;
73116 case UHC_EVT_RESETED :
74117 LOG_DBG ("Bus reset" );
@@ -149,6 +192,8 @@ int usbh_init_device_intl(struct usbh_contex *const uhs_ctx)
149192 return ret ;
150193 }
151194
195+ sys_dlist_init (& uhs_ctx -> udevs );
196+
152197 STRUCT_SECTION_FOREACH (usbh_class_data , cdata ) {
153198 /*
154199 * For now, we have not implemented any class drivers,
0 commit comments