File tree Expand file tree Collapse file tree 4 files changed +28
-0
lines changed
Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -561,6 +561,9 @@ bool tud_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
561561
562562 _usbd_rhport = rhport ;
563563
564+ // MCU specific pre-init
565+ tusb_pre_init_cb (rhport , TUSB_ROLE_DEVICE );
566+
564567 // Init device controller driver
565568 TU_ASSERT (dcd_init (rhport , rh_init ));
566569 dcd_int_enable (rhport );
@@ -580,6 +583,9 @@ bool tud_deinit(uint8_t rhport) {
580583 dcd_disconnect (rhport );
581584 TU_ASSERT (dcd_deinit (rhport ));
582585
586+ // MCU specific post-deinit
587+ tusb_post_deinit_cb (rhport , TUSB_ROLE_DEVICE );
588+
583589 // Deinit class drivers
584590 for (uint8_t i = 0 ; i < TOTAL_DRIVER_COUNT ; i ++ ) {
585591 usbd_class_driver_t const * driver = get_driver (i );
Original file line number Diff line number Diff line change @@ -522,6 +522,9 @@ bool tuh_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
522522 }
523523 }
524524
525+ // MCU specific pre-init
526+ tusb_pre_init_cb (rhport , TUSB_ROLE_HOST );
527+
525528 // Init host controller
526529 _usbh_data .controller_id = rhport ;
527530 TU_ASSERT (hcd_init (rhport , rh_init ));
@@ -540,6 +543,9 @@ bool tuh_deinit(uint8_t rhport) {
540543 TU_ASSERT (hcd_deinit (rhport ));
541544 _usbh_data .controller_id = TUSB_INDEX_INVALID_8 ;
542545
546+ // MCU specific post-deinit
547+ tusb_post_deinit_cb (rhport , TUSB_ROLE_HOST );
548+
543549 // "unplug" all devices on this rhport (hub_addr = 0, hub_port = 0)
544550 process_removed_device (rhport , 0 , 0 );
545551
Original file line number Diff line number Diff line change @@ -63,6 +63,16 @@ TU_ATTR_WEAK void* tusb_app_phys_to_virt(void *phys_addr) {
6363 return phys_addr ;
6464}
6565
66+ TU_ATTR_WEAK void tusb_pre_init_cb (uint8_t rhport , tusb_role_t role ) {
67+ (void ) rhport ;
68+ (void ) role ;
69+ }
70+
71+ TU_ATTR_WEAK void tusb_post_deinit_cb (uint8_t rhport , tusb_role_t role ) {
72+ (void ) rhport ;
73+ (void ) role ;
74+ }
75+
6676//--------------------------------------------------------------------+
6777// Public API
6878//--------------------------------------------------------------------+
Original file line number Diff line number Diff line change @@ -165,6 +165,12 @@ void tusb_int_handler(uint8_t rhport, bool in_isr);
165165// Deinit usb stack on roothub port
166166bool tusb_deinit (uint8_t rhport );
167167
168+ // Invoked before tusb_init() to allow MCU specific pre-initialization
169+ void tusb_pre_init_cb (uint8_t rhport , tusb_role_t role );
170+
171+ // Invoked after tusb_deinit() to allow MCU specific post-de-initialization
172+ void tusb_post_deinit_cb (uint8_t rhport , tusb_role_t role );
173+
168174#else
169175
170176#define tusb_init (...) (false)
You can’t perform that action at this time.
0 commit comments