summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2020-11-27 16:52:17 +0700
committerGitHub <[email protected]>2020-11-27 16:52:17 +0700
commit9f0f29cd403c4158f3d85892b23d638e4d34afec (patch)
treeabdada9a36f9472fc26877e4112440a2e3e46991
parent4a2baf400ea1ecf220b18352ec45dbe455741317 (diff)
parent8b34f2fca8f57a615f66773329fd238a9e416855 (diff)
Merge pull request #563 from hathach/add-esp32s2-suspend-wakeup
add bus suspend & resume support for esp32s2
-rw-r--r--examples/device/hid_composite_freertos/src/main.c7
-rw-r--r--src/portable/espressif/esp32s2/dcd_esp32s2.c22
-rw-r--r--src/portable/st/synopsys/dcd_synopsys.c6
3 files changed, 29 insertions, 6 deletions
diff --git a/examples/device/hid_composite_freertos/src/main.c b/examples/device/hid_composite_freertos/src/main.c
index de065ee64..83c68b515 100644
--- a/examples/device/hid_composite_freertos/src/main.c
+++ b/examples/device/hid_composite_freertos/src/main.c
@@ -58,7 +58,12 @@ StaticTimer_t blinky_tmdef;
TimerHandle_t blinky_tm;
// static task for usbd
-#define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2)
+#if CFG_TUSB_DEBUG
+ #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE)
+#else
+ #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2)
+#endif
+
StackType_t usb_device_stack[USBD_STACK_SIZE];
StaticTask_t usb_device_taskdef;
diff --git a/src/portable/espressif/esp32s2/dcd_esp32s2.c b/src/portable/espressif/esp32s2/dcd_esp32s2.c
index 58d92e728..cd66af805 100644
--- a/src/portable/espressif/esp32s2/dcd_esp32s2.c
+++ b/src/portable/espressif/esp32s2/dcd_esp32s2.c
@@ -218,6 +218,9 @@ void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
void dcd_remote_wakeup(uint8_t rhport)
{
(void)rhport;
+
+ // TODO must manually clear this bit after 1-15 ms
+ // USB0.DCTL |= USB_RMTWKUPSIG_M;
}
// connect by enabling internal pull-up resistor on D+/D-
@@ -670,6 +673,7 @@ static void handle_epin_ints(void)
static void _dcd_int_handler(void* arg)
{
(void) arg;
+ uint8_t const rhport = 0;
const uint32_t int_status = USB0.gintsts;
//const uint32_t int_msk = USB0.gintmsk;
@@ -695,7 +699,19 @@ static void _dcd_int_handler(void* arg)
// the end of reset.
USB0.gintsts = USB_ENUMDONE_M;
enum_done_processing();
- dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true);
+ dcd_event_bus_reset(rhport, TUSB_SPEED_FULL, true);
+ }
+
+ if(int_status & USB_USBSUSP_M)
+ {
+ USB0.gintsts = USB_USBSUSP_M;
+ dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
+ }
+
+ if(int_status & USB_WKUPINT_M)
+ {
+ USB0.gintsts = USB_WKUPINT_M;
+ dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
}
if (int_status & USB_OTGINT_M)
@@ -707,7 +723,7 @@ static void _dcd_int_handler(void* arg)
if (otg_int & USB_SESENDDET_M)
{
- dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true);
+ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
}
USB0.gotgint = otg_int;
@@ -716,7 +732,7 @@ static void _dcd_int_handler(void* arg)
#if USE_SOF
if (int_status & USB_SOF_M) {
USB0.gintsts = USB_SOF_M;
- dcd_event_bus_signal(0, DCD_EVENT_SOF, true); // do nothing actually
+ dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true); // do nothing actually
}
#endif
diff --git a/src/portable/st/synopsys/dcd_synopsys.c b/src/portable/st/synopsys/dcd_synopsys.c
index 9aeec79e6..35c814460 100644
--- a/src/portable/st/synopsys/dcd_synopsys.c
+++ b/src/portable/st/synopsys/dcd_synopsys.c
@@ -507,13 +507,16 @@ void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
void dcd_remote_wakeup(uint8_t rhport)
{
(void) rhport;
+
+ // TODO must manually clear this bit after 1-15 ms
+ // USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
+ // dev->DCTL |= USB_OTG_DCTL_RWUSIG;
}
void dcd_connect(uint8_t rhport)
{
(void) rhport;
USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
-
dev->DCTL &= ~USB_OTG_DCTL_SDIS;
}
@@ -521,7 +524,6 @@ void dcd_disconnect(uint8_t rhport)
{
(void) rhport;
USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
-
dev->DCTL |= USB_OTG_DCTL_SDIS;
}