diff options
-rw-r--r-- | chip/stm32/usb.c | 35 | ||||
-rw-r--r-- | include/usb_descriptor.h | 5 |
2 files changed, 35 insertions, 5 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c index ad1e76d65b..fae1e26297 100644 --- a/chip/stm32/usb.c +++ b/chip/stm32/usb.c @@ -101,7 +101,10 @@ static int desc_left; static const uint8_t *desc_ptr; /* interface that should handle the next tx transaction */ static uint8_t iface_next = USB_IFACE_COUNT; - +#ifdef CONFIG_USB_REMOTE_WAKEUP +/* remote wake up feature enabled */ +static int remote_wakeup_enabled; +#endif void usb_read_setup_packet(usb_uint *buffer, struct usb_setup_packet *packet) { @@ -196,14 +199,35 @@ static void ep0_rx(void) desc_left ? 0 : EP_STATUS_OUT); /* send the null OUT transaction if the transfer is complete */ } else if (req == (USB_DIR_IN | (USB_REQ_GET_STATUS << 8))) { - uint16_t zero = 0; + uint16_t data = 0; /* Get status */ - memcpy_to_usbram(EP0_BUF_TX_SRAM_ADDR, (void *)&zero, 2); +#ifdef CONFIG_USB_SELF_POWERED + data |= USB_REQ_GET_STATUS_SELF_POWERED; +#endif +#ifdef CONFIG_USB_REMOTE_WAKEUP + if (remote_wakeup_enabled) + data |= USB_REQ_GET_STATUS_REMOTE_WAKEUP; +#endif + memcpy_to_usbram(EP0_BUF_TX_SRAM_ADDR, (void *)&data, 2); btable_ep[0].tx_count = 2; STM32_TOGGLE_EP(0, EP_TX_RX_MASK, EP_TX_RX_VALID, EP_STATUS_OUT /*null OUT transaction */); } else if ((req & 0xff) == USB_DIR_OUT) { switch (req >> 8) { + case USB_REQ_SET_FEATURE: + case USB_REQ_CLEAR_FEATURE: +#ifdef CONFIG_USB_REMOTE_WAKEUP + if (ep0_buf_rx[1] == + USB_REQ_FEATURE_DEVICE_REMOTE_WAKEUP) { + remote_wakeup_enabled = + ((req >> 8) == USB_REQ_SET_FEATURE); + btable_ep[0].tx_count = 0; + STM32_TOGGLE_EP(0, EP_TX_RX_MASK, + EP_TX_RX_VALID, 0); + break; + } +#endif + goto unknown_req; case USB_REQ_SET_ADDRESS: /* set the address after we got IN packet handshake */ set_addr = ep0_buf_rx[1] & 0xff; @@ -335,8 +359,9 @@ static void usb_resume(void) #ifdef CONFIG_USB_REMOTE_WAKEUP void usb_wake(void) { - if (!(STM32_USB_CNTR & STM32_USB_CNTR_FSUSP)) { - /* USB is already woken up, nothing to do. */ + if (!remote_wakeup_enabled || + !(STM32_USB_CNTR & STM32_USB_CNTR_FSUSP)) { + /* USB wake not enabled, or already woken up, nothing to do. */ return; } diff --git a/include/usb_descriptor.h b/include/usb_descriptor.h index 7cb64e35aa..c2df5f53f9 100644 --- a/include/usb_descriptor.h +++ b/include/usb_descriptor.h @@ -214,8 +214,13 @@ struct usb_endpoint_descriptor { /* Standard requests for bRequest field in a SETUP packet. */ #define USB_REQ_GET_STATUS 0x00 +#define USB_REQ_GET_STATUS_SELF_POWERED (1 << 0) +#define USB_REQ_GET_STATUS_REMOTE_WAKEUP (1 << 1) #define USB_REQ_CLEAR_FEATURE 0x01 #define USB_REQ_SET_FEATURE 0x03 +#define USB_REQ_FEATURE_ENDPOINT_HALT 0x0000 +#define USB_REQ_FEATURE_DEVICE_REMOTE_WAKEUP 0x0001 +#define USB_REQ_FEATURE_TEST_MODE 0x0002 #define USB_REQ_SET_ADDRESS 0x05 #define USB_REQ_GET_DESCRIPTOR 0x06 #define USB_REQ_SET_DESCRIPTOR 0x07 |