summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix "xq" Queißner <[email protected]>2023-01-02 17:09:45 +0100
committerhathach <[email protected]>2024-04-08 19:00:35 +0700
commit47c12a07f2edf927eaa685ee8c32b222271d770f (patch)
tree5b7ad8bd791604f89d188416930baf8364fea459 /src
parentbc10394e66f9658a696fee11d15cdc8ff1d66432 (diff)
Implements tuh_deinit() and tud_deinit() to uninitialize host/device mode.
Diffstat (limited to 'src')
-rw-r--r--src/device/dcd.h3
-rw-r--r--src/device/usbd.h5
-rw-r--r--src/portable/raspberrypi/rp2040/dcd_rp2040.c12
-rw-r--r--src/portable/raspberrypi/rp2040/hcd_rp2040.c8
4 files changed, 27 insertions, 1 deletions
diff --git a/src/device/dcd.h b/src/device/dcd.h
index 69c26bcf4..21f404e4f 100644
--- a/src/device/dcd.h
+++ b/src/device/dcd.h
@@ -122,6 +122,9 @@ void dcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) TU_ATTR_W
// Initialize controller to device mode
void dcd_init(uint8_t rhport);
+// Deinitialize controller, unset device mode.
+void dcd_deinit(uint8_t rhport);
+
// Interrupt Handler
void dcd_int_handler(uint8_t rhport);
diff --git a/src/device/usbd.h b/src/device/usbd.h
index 2e3987b99..a9350192b 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -37,9 +37,12 @@ extern "C" {
// Application API
//--------------------------------------------------------------------+
-// Init device stack
+// Init device stack on roothub port
bool tud_init (uint8_t rhport);
+// Deinit device stack on roothub port
+void tud_deinit(uint8_t rhport);
+
// Check if device stack is already initialized
bool tud_inited(void);
diff --git a/src/portable/raspberrypi/rp2040/dcd_rp2040.c b/src/portable/raspberrypi/rp2040/dcd_rp2040.c
index 5c564cb1c..ccc7ee102 100644
--- a/src/portable/raspberrypi/rp2040/dcd_rp2040.c
+++ b/src/portable/raspberrypi/rp2040/dcd_rp2040.c
@@ -407,6 +407,18 @@ void dcd_init(uint8_t rhport) {
dcd_connect(rhport);
}
+void dcd_deinit(uint8_t rhport) {
+ assert(rhport == 0);
+
+ dcd_disconnect(rhport);
+ reset_non_control_endpoints();
+ irq_remove_handler(USBCTRL_IRQ, dcd_rp2040_irq);
+
+ // reset usb hardware into initial state
+ reset_block(RESETS_RESET_USBCTRL_BITS);
+ unreset_block_wait(RESETS_RESET_USBCTRL_BITS);
+}
+
void dcd_int_enable(__unused uint8_t rhport) {
assert(rhport == 0);
irq_set_enabled(USBCTRL_IRQ, true);
diff --git a/src/portable/raspberrypi/rp2040/hcd_rp2040.c b/src/portable/raspberrypi/rp2040/hcd_rp2040.c
index b351a9a07..762753a25 100644
--- a/src/portable/raspberrypi/rp2040/hcd_rp2040.c
+++ b/src/portable/raspberrypi/rp2040/hcd_rp2040.c
@@ -409,6 +409,14 @@ bool hcd_init(uint8_t rhport)
return true;
}
+void hcd_deinit(uint8_t rhport) {
+ (void) rhport;
+
+ irq_remove_handler(USBCTRL_IRQ, hcd_rp2040_irq);
+ reset_block(RESETS_RESET_USBCTRL_BITS);
+ unreset_block_wait(RESETS_RESET_USBCTRL_BITS);
+}
+
void hcd_port_reset(uint8_t rhport)
{
(void) rhport;