summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-03-30 14:47:11 +0700
committerhathach <[email protected]>2019-03-30 14:47:11 +0700
commitb28cc6ddb11ef233b6e6ee25b4a305b4b76cc03c (patch)
treede6623830676a997c9328f8996151537c30f5d6f /src
parentcabf6abb4f49648ad6eb1f9cb54bfad131f457b7 (diff)
added dcd_remote_wakeup() stub for all ports
Diffstat (limited to 'src')
-rw-r--r--src/device/usbd.c2
-rw-r--r--src/device/usbd.h11
-rw-r--r--src/portable/microchip/samd21/dcd_samd21.c34
-rw-r--r--src/portable/microchip/samd51/dcd_samd51.c5
-rw-r--r--src/portable/nordic/nrf5x/dcd_nrf5x.c5
-rw-r--r--src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c37
-rw-r--r--src/portable/nxp/lpc17_40/dcd_lpc17_40.c6
-rw-r--r--src/portable/nxp/lpc18_43/dcd_lpc18_43.c5
-rw-r--r--src/portable/st/stm32f3/dcd_stm32f3.c8
-rw-r--r--src/portable/st/stm32f4/dcd_stm32f4.c5
10 files changed, 95 insertions, 23 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index f90c6b4df..dde98939f 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -189,7 +189,7 @@ void tud_set_self_powered(bool self_powered)
bool tud_remote_wakeup(void)
{
// only wake up host if this feature is enabled
- if (_usbd_dev.remote_wakeup_en ) dcd_remote_wakeup(TUD_OPT_RHPORT);
+ if (_usbd_dev.suspended && _usbd_dev.remote_wakeup_en ) dcd_remote_wakeup(TUD_OPT_RHPORT);
return _usbd_dev.remote_wakeup_en;
}
diff --git a/src/device/usbd.h b/src/device/usbd.h
index ebf166821..27bfe305b 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -59,12 +59,19 @@ extern tud_desc_set_t tud_desc_set;
//--------------------------------------------------------------------+
// Application API
//--------------------------------------------------------------------+
-bool tud_mounted(void);
+
+// Task function should be called in main/rtos loop
void tud_task (void);
-bool tud_remote_wakeup(void);
+// Check if device is connected and configured
+bool tud_mounted(void);
+
+// Tell stack that device is self or bus powered (default = bus)
void tud_set_self_powered(bool self_powered);
+// Remote wake up host, only if suspended and enabled by host
+bool tud_remote_wakeup(void);
+
//--------------------------------------------------------------------+
// Application Callbacks (WEAK is optional)
//--------------------------------------------------------------------+
diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c
index a340c888d..39d59486d 100644
--- a/src/portable/microchip/samd21/dcd_samd21.c
+++ b/src/portable/microchip/samd21/dcd_samd21.c
@@ -110,6 +110,18 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
(void) rhport;
(void) config_num;
// Nothing to do
+
+#if 0
+ // Enable suspend to detect disconnection
+ // TODO need to distinguish Suspend vs Disconnect
+ USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTENCLR_SUSPEND;
+ USB->DEVICE.INTENSET.reg |= USB_DEVICE_INTENSET_SUSPEND;
+#endif
+}
+
+void dcd_remote_wakeup(uint8_t rhport)
+{
+ (void) rhport;
}
/*------------------------------------------------------------------*/
@@ -290,13 +302,14 @@ void maybe_transfer_complete(void) {
}
}
-void USB_Handler(void) {
- uint32_t int_status = USB->DEVICE.INTFLAG.reg;
+void USB_Handler(void)
+{
+ uint32_t int_status = USB->DEVICE.INTFLAG.reg & USB->DEVICE.INTENSET.reg;
/*------------- Interrupt Processing -------------*/
if ( int_status & USB_DEVICE_INTFLAG_EORST )
{
- USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTENCLR_EORST;
+ USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_EORST;
bus_reset();
dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true);
}
@@ -307,6 +320,21 @@ void USB_Handler(void) {
dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
}
+#if 0
+ if ( int_status & USB_DEVICE_INTFLAG_SUSPEND )
+ {
+ USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SUSPEND;
+
+ // disable interrupt to prevent it continue to trigger
+ USB->DEVICE.INTENCLR.reg = USB_DEVICE_INTENCLR_SUSPEND;
+
+ // TODO need to distinguish Suspend vs Disconnect
+ // reset address to 0, force host to re-enumerate after resume
+ USB->DEVICE.DADD.reg = 0;
+ dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true);
+ }
+#endif
+
// Setup packet received.
maybe_handle_setup_packet();
diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c
index 13250c38c..a1702b056 100644
--- a/src/portable/microchip/samd51/dcd_samd51.c
+++ b/src/portable/microchip/samd51/dcd_samd51.c
@@ -117,6 +117,11 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
// Nothing to do
}
+void dcd_remote_wakeup(uint8_t rhport)
+{
+ (void) rhport;
+}
+
/*------------------------------------------------------------------*/
/* DCD Endpoint port
*------------------------------------------------------------------*/
diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c
index e7e9ae016..452f25292 100644
--- a/src/portable/nordic/nrf5x/dcd_nrf5x.c
+++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c
@@ -216,6 +216,11 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
NRF_USBD->INTENSET = USBD_INTEN_USBEVENT_Msk;
}
+void dcd_remote_wakeup(uint8_t rhport)
+{
+ (void) rhport;
+}
+
//--------------------------------------------------------------------+
// Endpoint API
//--------------------------------------------------------------------+
diff --git a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c
index f01bed1c9..fff29d5eb 100644
--- a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c
+++ b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c
@@ -126,22 +126,31 @@ static inline uint8_t ep_addr2id(uint8_t endpoint_addr)
//--------------------------------------------------------------------+
// CONTROLLER API
//--------------------------------------------------------------------+
-void dcd_int_enable(uint8_t rhport)
+void dcd_init(uint8_t rhport)
{
(void) rhport;
- NVIC_EnableIRQ(USB0_IRQn);
+
+ LPC_USB->EPLISTSTART = (uint32_t) _dcd.ep;
+ LPC_USB->DATABUFSTART = SRAM_REGION;
+
+ LPC_USB->INTSTAT = LPC_USB->INTSTAT; // clear all pending interrupt
+ LPC_USB->INTEN = INT_DEVICE_STATUS_MASK;
+ LPC_USB->DEVCMDSTAT |= CMDSTAT_DEVICE_ENABLE_MASK | CMDSTAT_DEVICE_CONNECT_MASK |
+ CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK;
+
+ NVIC_ClearPendingIRQ(USB0_IRQn);
}
-void dcd_int_disable(uint8_t rhport)
+void dcd_int_enable(uint8_t rhport)
{
(void) rhport;
- NVIC_DisableIRQ(USB0_IRQn);
+ NVIC_EnableIRQ(USB0_IRQn);
}
-void dcd_set_config(uint8_t rhport, uint8_t config_num)
+void dcd_int_disable(uint8_t rhport)
{
(void) rhport;
- (void) config_num;
+ NVIC_DisableIRQ(USB0_IRQn);
}
void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
@@ -153,19 +162,15 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
LPC_USB->DEVCMDSTAT |= dev_addr;
}
-void dcd_init(uint8_t rhport)
+void dcd_set_config(uint8_t rhport, uint8_t config_num)
{
(void) rhport;
+ (void) config_num;
+}
- LPC_USB->EPLISTSTART = (uint32_t) _dcd.ep;
- LPC_USB->DATABUFSTART = SRAM_REGION;
-
- LPC_USB->INTSTAT = LPC_USB->INTSTAT; // clear all pending interrupt
- LPC_USB->INTEN = INT_DEVICE_STATUS_MASK;
- LPC_USB->DEVCMDSTAT |= CMDSTAT_DEVICE_ENABLE_MASK | CMDSTAT_DEVICE_CONNECT_MASK |
- CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK;
-
- NVIC_EnableIRQ(USB0_IRQn);
+void dcd_remote_wakeup(uint8_t rhport)
+{
+ (void) rhport;
}
//--------------------------------------------------------------------+
diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
index 5da18d52b..30252f56d 100644
--- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
+++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c
@@ -185,7 +185,6 @@ void dcd_init(uint8_t rhport)
// USB IRQ priority should be set by application previously
NVIC_ClearPendingIRQ(USB_IRQn);
- NVIC_EnableIRQ(USB_IRQn);
}
void dcd_int_enable(uint8_t rhport)
@@ -215,6 +214,11 @@ void dcd_set_config(uint8_t rhport, uint8_t config_num)
sie_write(SIE_CMDCODE_CONFIGURE_DEVICE, 1, 1);
}
+void dcd_remote_wakeup(uint8_t rhport)
+{
+ (void) rhport;
+}
+
//--------------------------------------------------------------------+
// CONTROL HELPER
//--------------------------------------------------------------------+
diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c
index b272a143e..5c2d27d92 100644
--- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c
+++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c
@@ -161,6 +161,11 @@ void dcd_set_config(uint8_t rhport, uint8_t config_num)
// nothing to do
}
+void dcd_remote_wakeup(uint8_t rhport)
+{
+ (void) rhport;
+}
+
//--------------------------------------------------------------------+
// HELPER
//--------------------------------------------------------------------+
diff --git a/src/portable/st/stm32f3/dcd_stm32f3.c b/src/portable/st/stm32f3/dcd_stm32f3.c
index 41f82891b..023037474 100644
--- a/src/portable/st/stm32f3/dcd_stm32f3.c
+++ b/src/portable/st/stm32f3/dcd_stm32f3.c
@@ -55,6 +55,14 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
void dcd_set_config (uint8_t rhport, uint8_t config_num)
{}
+void dcd_remote_wakeup(uint8_t rhport)
+{
+ (void) rhport;
+}
+
+//--------------------------------------------------------------------+
+// Endpoint API
+//--------------------------------------------------------------------+
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
{
return false;
diff --git a/src/portable/st/stm32f4/dcd_stm32f4.c b/src/portable/st/stm32f4/dcd_stm32f4.c
index f0d6e7d58..f7128344d 100644
--- a/src/portable/st/stm32f4/dcd_stm32f4.c
+++ b/src/portable/st/stm32f4/dcd_stm32f4.c
@@ -194,6 +194,11 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
// Nothing to do
}
+void dcd_remote_wakeup(uint8_t rhport)
+{
+ (void) rhport;
+}
+
/*------------------------------------------------------------------*/
/* DCD Endpoint port
*------------------------------------------------------------------*/