Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(usbd): Added tud_teardown() #27

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/device/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,31 @@ bool tud_init (uint8_t rhport)
return true;
}

bool tud_teardown (uint8_t rhport)
{
// skip if nothing to teardown
if ( !tud_inited() ) return true;

TU_LOG(USBD_DBG, "USBD teardown on controller %u\r\n", rhport);

// Disable interrupt
dcd_int_disable(rhport);

// Disable class devices
for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++)
{
usbd_class_driver_t const * driver = get_driver(i);
TU_ASSERT(driver);
TU_LOG(USBD_DBG, "%s reset\r\n", driver->name);
driver->reset(rhport);
}

// clean port
_usbd_rhport = RHPORT_INVALID;

return true;
}

static void configuration_reset(uint8_t rhport)
{
for ( uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++ )
Expand Down
3 changes: 3 additions & 0 deletions src/device/usbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ bool tud_init (uint8_t rhport);
// Check if device stack is already initialized
bool tud_inited(void);

// Teardown device stack
bool tud_teardown (uint8_t rhport);

// Task function should be called in main/rtos loop, extended version of tud_task()
// - timeout_ms: millisecond to wait, zero = no wait, 0xFFFFFFFF = wait forever
// - in_isr: if function is called in ISR
Expand Down
17 changes: 17 additions & 0 deletions src/tusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ bool tusb_init(void)
return true;
}

// Teardown device/host stack
bool tusb_teardown(void)
{
#if CFG_TUD_ENABLED && defined(TUD_OPT_RHPORT)
// teardown device stack CFG_TUSB_RHPORTx_MODE must be defined
TU_ASSERT ( tud_teardown(TUD_OPT_RHPORT) );
#endif

#if CFG_TUH_ENABLED && defined(TUH_OPT_RHPORT)
// teardown host stack CFG_TUSB_RHPORTx_MODE must be defined
// not implemented
return false;
#endif

return true;
}

bool tusb_inited(void)
{
bool ret = false;
Expand Down
4 changes: 2 additions & 2 deletions src/tusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ bool tusb_init(void);
// Check if stack is initialized
bool tusb_inited(void);

// TODO
// bool tusb_teardown(void);
// Teardown device/host stack
bool tusb_teardown(void);

#ifdef __cplusplus
}
Expand Down
Loading