diff options
| author | sakumisu <[email protected]> | 2022-09-24 23:23:34 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2022-09-24 23:23:34 +0800 |
| commit | cf2fa1503cdbff4007f1f0686f5bb2eed74cf801 (patch) | |
| tree | 729abf9fb3433a597e44c9a0b4802d6c53abf93b | |
| parent | 9ddfd6017c0a328a8d18b048eb9048f92d0b0e14 (diff) | |
add usb device deinit function
| -rw-r--r-- | core/usbd_core.c | 16 | ||||
| -rw-r--r-- | core/usbd_core.h | 1 |
2 files changed, 13 insertions, 4 deletions
diff --git a/core/usbd_core.c b/core/usbd_core.c index 1601cb0f..0abdba09 100644 --- a/core/usbd_core.c +++ b/core/usbd_core.c @@ -49,6 +49,7 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_cfg_priv { #ifdef CONFIG_USBDEV_TEST_MODE bool test_mode; #endif + uint8_t intf_offset; } usbd_core_cfg; usb_slist_t usbd_intf_head = USB_SLIST_OBJECT_INIT(usbd_intf_head); @@ -926,6 +927,7 @@ void usbd_event_ep_out_complete_handler(uint8_t ep, uint32_t nbytes) void usbd_desc_register(const uint8_t *desc) { usbd_core_cfg.descriptors = desc; + usbd_core_cfg.intf_offset = 0; } /* Register MS OS Descriptors version 1 */ @@ -947,11 +949,9 @@ void usbd_bos_desc_register(struct usb_bos_descriptor *desc) void usbd_add_interface(struct usbd_interface *intf) { - static uint8_t intf_offset = 0; - - intf->intf_num = intf_offset; + intf->intf_num = usbd_core_cfg.intf_offset; usb_slist_add_tail(&usbd_intf_head, &intf->list); - intf_offset++; + usbd_core_cfg.intf_offset++; } void usbd_add_endpoint(struct usbd_endpoint *ep) @@ -972,3 +972,11 @@ int usbd_initialize(void) { return usb_dc_init(); } + +int usbd_deinitialize(void) +{ + usbd_core_cfg.intf_offset = 0; + usb_slist_init(&usbd_intf_head); + usb_dc_deinit(); + return 0; +} diff --git a/core/usbd_core.h b/core/usbd_core.h index b56cc067..2583fc91 100644 --- a/core/usbd_core.h +++ b/core/usbd_core.h @@ -73,6 +73,7 @@ void usbd_add_endpoint(struct usbd_endpoint *ep); bool usb_device_is_configured(void); void usbd_configure_done_callback(void); int usbd_initialize(void); +int usbd_deinitialize(void); #ifdef __cplusplus } |
