Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thirdpin/libopencm3.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2018-07-26 02:12:18 +0300
committerKarl Palsson <karlp@tweak.net.au>2018-08-20 02:26:04 +0300
commite5b8a164a68cbd6bd566436e0de4c9082ef0a270 (patch)
treedf262e8b94505df5577372714703132092035085
parent01f33f47b720e3222dc8560a3f000745d5fa5006 (diff)
usb: st_usbfs_v2: support disconnect functionality
Originally suggested via https://github.com/libopencm3/libopencm3/pull/628
-rw-r--r--lib/stm32/st_usbfs_v2.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/lib/stm32/st_usbfs_v2.c b/lib/stm32/st_usbfs_v2.c
index f6a41783..f13134d4 100644
--- a/lib/stm32/st_usbfs_v2.c
+++ b/lib/stm32/st_usbfs_v2.c
@@ -26,21 +26,6 @@
#include "../usb/usb_private.h"
#include "common/st_usbfs_core.h"
-static usbd_device *st_usbfs_v2_usbd_init(void);
-
-const struct _usbd_driver st_usbfs_v2_usb_driver = {
- .init = st_usbfs_v2_usbd_init,
- .set_address = st_usbfs_set_address,
- .ep_setup = st_usbfs_ep_setup,
- .ep_reset = st_usbfs_endpoints_reset,
- .ep_stall_set = st_usbfs_ep_stall_set,
- .ep_stall_get = st_usbfs_ep_stall_get,
- .ep_nak_set = st_usbfs_ep_nak_set,
- .ep_write_packet = st_usbfs_ep_write_packet,
- .ep_read_packet = st_usbfs_ep_read_packet,
- .poll = st_usbfs_poll,
-};
-
/** Initialize the USB device controller hardware of the STM32. */
static usbd_device *st_usbfs_v2_usbd_init(void)
{
@@ -99,3 +84,28 @@ void st_usbfs_copy_from_pm(void *buf, const volatile void *vPM, uint16_t len)
*(uint8_t *) buf = *(uint8_t *) PM;
}
}
+
+static void st_usbfs_v2_disconnect(usbd_device *usbd_dev, bool disconnected)
+{
+ (void)usbd_dev;
+ uint16_t reg = GET_REG(USB_BCDR_REG);
+ if (disconnected) {
+ SET_REG(USB_BCDR_REG, reg | USB_BCDR_DPPU);
+ } else {
+ SET_REG(USB_BCDR_REG, reg & ~USB_BCDR_DPPU);
+ }
+}
+
+const struct _usbd_driver st_usbfs_v2_usb_driver = {
+ .init = st_usbfs_v2_usbd_init,
+ .set_address = st_usbfs_set_address,
+ .ep_setup = st_usbfs_ep_setup,
+ .ep_reset = st_usbfs_endpoints_reset,
+ .ep_stall_set = st_usbfs_ep_stall_set,
+ .ep_stall_get = st_usbfs_ep_stall_get,
+ .ep_nak_set = st_usbfs_ep_nak_set,
+ .ep_write_packet = st_usbfs_ep_write_packet,
+ .ep_read_packet = st_usbfs_ep_read_packet,
+ .disconnect = st_usbfs_v2_disconnect,
+ .poll = st_usbfs_poll,
+};