diff options
| author | sakumisu <[email protected]> | 2024-07-08 21:50:00 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2024-07-08 21:54:39 +0800 |
| commit | 7fab3c29f09b4b7c8f3845023e1a482469ae400a (patch) | |
| tree | d24d6924e341ad3e51f7e05145befe5757c70b0e | |
| parent | 4f3a3f496e6bd6b14a473a15435fd7f7fbf9d826 (diff) | |
feat(port): implement usbd_ep_is_stalled api
| -rw-r--r-- | core/usbd_core.c | 24 | ||||
| -rw-r--r-- | port/bouffalolab/usb_dc_bl.c | 23 | ||||
| -rw-r--r-- | port/dwc2/usb_dc_dwc2.c | 12 | ||||
| -rw-r--r-- | port/fsdev/usb_dc_fsdev.c | 12 | ||||
| -rw-r--r-- | port/musb/usb_dc_musb.c | 20 |
5 files changed, 83 insertions, 8 deletions
diff --git a/core/usbd_core.c b/core/usbd_core.c index e072d8a2..0b7c5566 100644 --- a/core/usbd_core.c +++ b/core/usbd_core.c @@ -99,9 +99,9 @@ static bool is_device_configured(uint8_t busid) static bool usbd_set_endpoint(uint8_t busid, const struct usb_endpoint_descriptor *ep) { USB_LOG_DBG("Open ep:0x%02x type:%u mps:%u\r\n", - ep->bEndpointAddress, - USB_GET_ENDPOINT_TYPE(ep->bmAttributes), - USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize)); + ep->bEndpointAddress, + USB_GET_ENDPOINT_TYPE(ep->bmAttributes), + USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize)); if (ep->bEndpointAddress & 0x80) { g_usbd_core[busid].tx_msg[ep->bEndpointAddress & 0x7f].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize); @@ -126,8 +126,8 @@ static bool usbd_set_endpoint(uint8_t busid, const struct usb_endpoint_descripto static bool usbd_reset_endpoint(uint8_t busid, const struct usb_endpoint_descriptor *ep) { USB_LOG_DBG("Close ep:0x%02x type:%u\r\n", - ep->bEndpointAddress, - USB_GET_ENDPOINT_TYPE(ep->bmAttributes)); + ep->bEndpointAddress, + USB_GET_ENDPOINT_TYPE(ep->bmAttributes)); return usbd_ep_close(busid, ep->bEndpointAddress) == 0 ? true : false; } @@ -556,14 +556,16 @@ static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet * break; case USB_REQUEST_GET_CONFIGURATION: - *data = (uint8_t *)&g_usbd_core[busid].configuration; + (*data)[0] = g_usbd_core[busid].configuration; *len = 1; break; case USB_REQUEST_SET_CONFIGURATION: value &= 0xFF; - if (!usbd_set_configuration(busid, value, 0)) { + if (value == 0) { + g_usbd_core[busid].configuration = 0; + } else if (!usbd_set_configuration(busid, value, 0)) { ret = false; } else { g_usbd_core[busid].configuration = value; @@ -663,6 +665,7 @@ static bool usbd_std_endpoint_req_handler(uint8_t busid, struct usb_setup_packet { uint8_t ep = (uint8_t)setup->wIndex; bool ret = true; + uint8_t stalled; /* Only when device is configured, then endpoint requests can be valid. */ if (!is_device_configured(busid)) { @@ -671,7 +674,12 @@ static bool usbd_std_endpoint_req_handler(uint8_t busid, struct usb_setup_packet switch (setup->bRequest) { case USB_REQUEST_GET_STATUS: - (*data)[0] = 0x00; + usbd_ep_is_stalled(busid, ep, &stalled); + if (stalled) { + (*data)[0] = 0x01; + } else { + (*data)[0] = 0x00; + } (*data)[1] = 0x00; *len = 2; break; diff --git a/port/bouffalolab/usb_dc_bl.c b/port/bouffalolab/usb_dc_bl.c index 6f45329c..542297df 100644 --- a/port/bouffalolab/usb_dc_bl.c +++ b/port/bouffalolab/usb_dc_bl.c @@ -822,6 +822,29 @@ int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep) int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled) { + uint32_t regval; + + uint8_t ep_idx = USB_EP_GET_IDX(ep); + + if (ep_idx == 0) { + } else { + if (USB_EP_DIR_IS_OUT(ep)) { + regval = getreg32(BFLB_USB_BASE + USB_DEV_OUTMPS1_OFFSET + (ep_idx - 1) * 4); + if (regval & USB_STL_OEP1) { + *stalled = 1; + } else { + *stalled = 0; + } + } else { + regval = getreg32(BFLB_USB_BASE + USB_DEV_INMPS1_OFFSET + (ep_idx - 1) * 4); + if (regval & USB_STL_IEP1) { + *stalled = 1; + } else { + *stalled = 0; + } + } + } + return 0; } diff --git a/port/dwc2/usb_dc_dwc2.c b/port/dwc2/usb_dc_dwc2.c index 9dee5c1d..a3815534 100644 --- a/port/dwc2/usb_dc_dwc2.c +++ b/port/dwc2/usb_dc_dwc2.c @@ -834,8 +834,20 @@ int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep) int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled) { + uint8_t ep_idx = USB_EP_GET_IDX(ep); + if (USB_EP_DIR_IS_OUT(ep)) { + if(USB_OTG_OUTEP(ep_idx)->DOEPCTL & USB_OTG_DOEPCTL_STALL) { + *stalled = 1; + } else { + *stalled = 0; + } } else { + if(USB_OTG_INEP(ep_idx)->DIEPCTL & USB_OTG_DIEPCTL_STALL) { + *stalled = 1; + } else { + *stalled = 0; + } } return 0; } diff --git a/port/fsdev/usb_dc_fsdev.c b/port/fsdev/usb_dc_fsdev.c index b3bfb5c4..556126bd 100644 --- a/port/fsdev/usb_dc_fsdev.c +++ b/port/fsdev/usb_dc_fsdev.c @@ -255,8 +255,20 @@ int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep) int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled) { + uint8_t ep_idx = USB_EP_GET_IDX(ep); + if (USB_EP_DIR_IS_OUT(ep)) { + if (PCD_GET_EP_RX_STATUS(USB, ep_idx) & USB_EP_RX_STALL) { + *stalled = 1; + } else { + *stalled = 0; + } } else { + if (PCD_GET_EP_TX_STATUS(USB, ep_idx) & USB_EP_TX_STALL) { + *stalled = 1; + } else { + *stalled = 0; + } } return 0; } diff --git a/port/musb/usb_dc_musb.c b/port/musb/usb_dc_musb.c index d66ec39e..ae7b3a5a 100644 --- a/port/musb/usb_dc_musb.c +++ b/port/musb/usb_dc_musb.c @@ -501,6 +501,26 @@ int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep) int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled) { + uint8_t ep_idx = USB_EP_GET_IDX(ep); + uint8_t old_ep_idx; + + old_ep_idx = musb_get_active_ep(); + musb_set_active_ep(ep_idx); + + if (USB_EP_DIR_IS_OUT(ep)) { + if(HWREGB(USB_BASE + MUSB_IND_RXCSRL_OFFSET) & USB_RXCSRL1_STALLED) { + *stalled = 1; + } else { + *stalled = 0; + } + } else { + if(HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) & USB_TXCSRL1_STALLED) { + *stalled = 1; + } else { + *stalled = 0; + } + } + musb_set_active_ep(old_ep_idx); return 0; } |
