aboutsummaryrefslogtreecommitdiff
path: root/lib/usb
diff options
context:
space:
mode:
authorMike Smith2012-01-02 21:06:48 -0800
committerPiotr Esden-Tempski2012-02-12 15:00:08 -0800
commit7da1967056c1cdba2b37c57015451224605a8a65 (patch)
tree8b5846ab49223b28c2e517ba2e28f0520aaadcec /lib/usb
parent5310cd1b57066fe4b359db1d304fd1bb688feee3 (diff)
Add an interface for soft disconnection, and hook it up in the F107 driver.
Diffstat (limited to 'lib/usb')
-rw-r--r--lib/usb/usb.c7
-rw-r--r--lib/usb/usb_f107.c11
-rw-r--r--lib/usb/usb_private.h1
3 files changed, 19 insertions, 0 deletions
diff --git a/lib/usb/usb.c b/lib/usb/usb.c
index e15f5b2..abb870e 100644
--- a/lib/usb/usb.c
+++ b/lib/usb/usb.c
@@ -108,6 +108,13 @@ void usbd_poll(void)
_usbd_device.driver->poll();
}
+void usbd_disconnect(bool disconnected)
+{
+ /* not all drivers support disconnection */
+ if (_usbd_device.driver->disconnect)
+ _usbd_device.driver->disconnect(disconnected);
+}
+
void usbd_ep_setup(u8 addr, u8 type, u16 max_size, void (*callback)(u8 ep))
{
_usbd_device.driver->ep_setup(addr, type, max_size, callback);
diff --git a/lib/usb/usb_f107.c b/lib/usb/usb_f107.c
index 0797cba..1cd3eec 100644
--- a/lib/usb/usb_f107.c
+++ b/lib/usb/usb_f107.c
@@ -42,6 +42,7 @@ static void stm32f107_ep_nak_set(u8 addr, u8 nak);
static u16 stm32f107_ep_write_packet(u8 addr, const void *buf, u16 len);
static u16 stm32f107_ep_read_packet(u8 addr, void *buf, u16 len);
static void stm32f107_poll(void);
+static void stm32f107_disconnect(bool disconnected);
/*
* We keep a backup copy of the out endpoint size registers to restore them
@@ -60,6 +61,7 @@ const struct _usbd_driver stm32f107_usb_driver = {
.ep_write_packet = stm32f107_ep_write_packet,
.ep_read_packet = stm32f107_ep_read_packet,
.poll = stm32f107_poll,
+ .disconnect = stm32f107_disconnect,
};
/** Initialize the USB device controller hardware of the STM32. */
@@ -376,3 +378,12 @@ static void stm32f107_poll(void)
OTG_FS_GINTSTS = OTG_FS_GINTSTS_SOF;
}
}
+
+static void stm32f107_disconnect(bool disconnected)
+{
+ if (disconnected) {
+ OTG_FS_DCTL |= OTG_FS_DCTL_SDIS;
+ } else {
+ OTG_FS_DCTL &= ~OTG_FS_DCTL_SDIS;
+ }
+} \ No newline at end of file
diff --git a/lib/usb/usb_private.h b/lib/usb/usb_private.h
index 39716b5..5b367fb 100644
--- a/lib/usb/usb_private.h
+++ b/lib/usb/usb_private.h
@@ -84,6 +84,7 @@ struct _usbd_driver {
u16 (*ep_write_packet)(u8 addr, const void *buf, u16 len);
u16 (*ep_read_packet)(u8 addr, void *buf, u16 len);
void (*poll)(void);
+ void (*disconnect)(bool disconnected);
};
#define _usbd_hw_init() _usbd_device.driver->init()