add usbd_get_port_speed api to use different config descriptors

This commit is contained in:
sakimisu
2022-11-18 22:26:09 +08:00
parent 9ef2988f6a
commit cf97d5276e
10 changed files with 91 additions and 2 deletions

View File

@@ -44,6 +44,15 @@ int usb_dc_deinit(void);
*/
int usbd_set_address(const uint8_t addr);
/**
* @brief Get USB device speed
*
* @param[in] port port index
*
* @return port speed, USB_SPEED_LOW or USB_SPEED_FULL or USB_SPEED_HIGH
*/
uint8_t usbd_get_port_speed(const uint8_t port);
/**
* @brief configure and enable endpoint.
*

View File

@@ -124,6 +124,11 @@ int usbd_set_address(const uint8_t address)
return 0;
}
uint8_t usbd_get_port_speed(const uint8_t port)
{
return USB_SPEED_FULL;
}
/**
* @brief Open endpoint
* @pre None

View File

@@ -99,6 +99,11 @@ int usbd_set_address(const uint8_t addr)
return 0;
}
uint8_t usbd_get_port_speed(const uint8_t port)
{
return USB_SPEED_FULL;
}
int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
{
uint8_t ep_idx = USB_EP_GET_IDX(ep_cfg->ep_addr);

View File

@@ -96,6 +96,11 @@ int usbd_set_address(const uint8_t addr)
return 0;
}
uint8_t usbd_get_port_speed(const uint8_t port)
{
return USB_SPEED_HIGH;
}
int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
{
uint8_t ep_idx = USB_EP_GET_IDX(ep_cfg->ep_addr);

View File

@@ -675,6 +675,23 @@ int usbd_set_address(const uint8_t addr)
return 0;
}
uint8_t usbd_get_port_speed(const uint8_t port)
{
uint8_t speed;
uint32_t DevEnumSpeed = USB_OTG_DEV->DSTS & USB_OTG_DSTS_ENUMSPD;
if (DevEnumSpeed == DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ) {
speed = USB_SPEED_HIGH;
} else if ((DevEnumSpeed == DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ) ||
(DevEnumSpeed == DSTS_ENUMSPD_FS_PHY_48MHZ)) {
speed = USB_SPEED_FULL;
} else {
speed = USB_SPEED_FULL;
}
return speed;
}
int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
{
uint8_t ep_idx = USB_EP_GET_IDX(ep_cfg->ep_addr);

View File

@@ -116,6 +116,11 @@ int usbd_set_address(const uint8_t addr)
return 0;
}
uint8_t usbd_get_port_speed(const uint8_t port)
{
return USB_SPEED_FULL;
}
int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
{
uint8_t ep_idx = USB_EP_GET_IDX(ep_cfg->ep_addr);

View File

@@ -87,6 +87,25 @@ int usbd_set_address(const uint8_t addr)
return 0;
}
uint8_t usbd_get_port_speed(const uint8_t port)
{
uint8_t speed;
speed = usb_get_port_speed(g_hpm_udc.handle->regs);
if (speed == 0x00) {
return USB_SPEED_FULL;
}
if (speed == 0x01) {
return USB_SPEED_LOW;
}
if (speed == 0x02) {
return USB_SPEED_HIGH;
}
return 0;
}
int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
{
usb_endpoint_config_t tmp_ep_cfg;

View File

@@ -268,6 +268,20 @@ int usbd_set_address(const uint8_t addr)
return 0;
}
uint8_t usbd_get_port_speed(const uint8_t port)
{
uint8_t speed;
if (HWREGB(USB_BASE + MUSB_POWER_OFFSET) & USB_POWER_HSMODE)
speed = USB_SPEED_HIGH;
else if (HWREGB(USB_BASE + MUSB_DEVCTL_OFFSET) & USB_DEVCTL_FSDEV)
speed = USB_SPEED_FULL;
else if (HWREGB(USB_BASE + MUSB_DEVCTL_OFFSET) & USB_DEVCTL_LSDEV)
speed = USB_SPEED_LOW;
return speed;
}
int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
{
uint16_t used = 0;

View File

@@ -189,6 +189,11 @@ int usbd_set_address(const uint8_t address)
return 0;
}
uint8_t usbd_get_port_speed(const uint8_t port)
{
return USB_SPEED_FULL;
}
/**
* @brief Open endpoint
* @pre None

View File

@@ -200,6 +200,11 @@ int usbd_set_address(const uint8_t addr)
return 0;
}
uint8_t usbd_get_port_speed(const uint8_t port)
{
return USB_SPEED_FULL;
}
int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
{
uint8_t ep_idx = USB_EP_GET_IDX(ep_cfg->ep_addr);