diff options
author | Damien George <damien.p.george@gmail.com> | 2017-09-22 10:28:56 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-09-22 10:28:56 +1000 |
commit | db7f4aa2cb5848942c421785770831bd9be7b9b6 (patch) | |
tree | c5ebefcba6fe7884c5f7a95e5568c04899e49e88 | |
parent | dbff0164b3ce7293d9de05c14fba6481c316c2e8 (diff) |
stm32/usbdev: Make device descriptor callbacks take a state pointer.
-rw-r--r-- | ports/stm32/usbd_desc.c | 20 | ||||
-rw-r--r-- | ports/stm32/usbdev/core/inc/usbd_def.h | 16 | ||||
-rw-r--r-- | ports/stm32/usbdev/core/src/usbd_ctlreq.c | 14 |
3 files changed, 26 insertions, 24 deletions
diff --git a/ports/stm32/usbd_desc.c b/ports/stm32/usbd_desc.c index 09e1608c8..8b8e7e7f0 100644 --- a/ports/stm32/usbd_desc.c +++ b/ports/stm32/usbd_desc.c @@ -111,7 +111,7 @@ void USBD_SetVIDPIDRelease(uint16_t vid, uint16_t pid, uint16_t device_release_n * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -STATIC uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { +STATIC uint8_t *USBD_DeviceDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) { *length = sizeof(hUSBDDeviceDesc); return hUSBDDeviceDesc; } @@ -122,7 +122,7 @@ STATIC uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -STATIC uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { +STATIC uint8_t *USBD_LangIDStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) { *length = sizeof(USBD_LangIDDesc); return USBD_LangIDDesc; } @@ -133,8 +133,8 @@ STATIC uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -STATIC uint8_t *USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - if(speed == 0) { +STATIC uint8_t *USBD_ProductStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) { + if (pdev->dev_speed == USBD_SPEED_HIGH) { USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length); } else { USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length); @@ -148,7 +148,7 @@ STATIC uint8_t *USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *len * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -STATIC uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { +STATIC uint8_t *USBD_ManufacturerStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) { USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); return USBD_StrDesc; } @@ -159,7 +159,7 @@ STATIC uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -STATIC uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { +STATIC uint8_t *USBD_SerialStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) { // This document: http://www.usb.org/developers/docs/devclass_docs/usbmassbulk_10.pdf // says that the serial number has to be at least 12 digits long and that // the last 12 digits need to be unique. It also stipulates that the valid @@ -189,8 +189,8 @@ STATIC uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -STATIC uint8_t *USBD_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - if(speed == USBD_SPEED_HIGH) { +STATIC uint8_t *USBD_ConfigStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) { + if (pdev->dev_speed == USBD_SPEED_HIGH) { USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length); } else { USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); @@ -204,8 +204,8 @@ STATIC uint8_t *USBD_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng * @param length: Pointer to data length variable * @retval Pointer to descriptor buffer */ -STATIC uint8_t *USBD_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { - if(speed == 0) { +STATIC uint8_t *USBD_InterfaceStrDescriptor(USBD_HandleTypeDef *pdev, uint16_t *length) { + if (pdev->dev_speed == USBD_SPEED_HIGH) { USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length); } else { USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length); diff --git a/ports/stm32/usbdev/core/inc/usbd_def.h b/ports/stm32/usbdev/core/inc/usbd_def.h index bd913a286..888d426ef 100644 --- a/ports/stm32/usbdev/core/inc/usbd_def.h +++ b/ports/stm32/usbdev/core/inc/usbd_def.h @@ -193,16 +193,18 @@ typedef enum { USBD_FAIL,
}USBD_StatusTypeDef;
+struct _USBD_HandleTypeDef;
+
/* USB Device descriptors structure */
typedef struct
{
- uint8_t *(*GetDeviceDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetLangIDStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetManufacturerStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetProductStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetSerialStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetConfigurationStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
- uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
+ uint8_t *(*GetDeviceDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetLangIDStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetManufacturerStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetProductStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetSerialStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetConfigurationStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
+ uint8_t *(*GetInterfaceStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint16_t *length);
} USBD_DescriptorsTypeDef;
/* USB Device handle structure */
diff --git a/ports/stm32/usbdev/core/src/usbd_ctlreq.c b/ports/stm32/usbdev/core/src/usbd_ctlreq.c index 15d9b6ec4..5fba322fa 100644 --- a/ports/stm32/usbdev/core/src/usbd_ctlreq.c +++ b/ports/stm32/usbdev/core/src/usbd_ctlreq.c @@ -330,7 +330,7 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , switch (req->wValue >> 8)
{
case USB_DESC_TYPE_DEVICE:
- pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetDeviceDescriptor(pdev, &len);
break;
case USB_DESC_TYPE_CONFIGURATION:
@@ -350,27 +350,27 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , switch ((uint8_t)(req->wValue))
{
case USBD_IDX_LANGID_STR:
- pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev, &len);
break;
case USBD_IDX_MFC_STR:
- pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev, &len);
break;
case USBD_IDX_PRODUCT_STR:
- pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetProductStrDescriptor(pdev, &len);
break;
case USBD_IDX_SERIAL_STR:
- pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev, &len);
break;
case USBD_IDX_CONFIG_STR:
- pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev, &len);
break;
case USBD_IDX_INTERFACE_STR:
- pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len);
+ pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev, &len);
break;
default:
|