Release v2.10.0

This commit is contained in:
slimih
2021-09-16 17:30:01 +01:00
parent 06808a92fe
commit 69fa8a86ad
60 changed files with 6008 additions and 2759 deletions

View File

@@ -90,7 +90,7 @@ extern "C" {
#define UVC_COLOR_PRIMARIE 0x01U
#define UVC_TFR_CHARACTERISTICS 0x01U
#define UVC_MATRIX_COEFFICIENTS 0x04U
#endif
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
/* Video Stream frame width and height */
#define UVC_WIDTH 176U
@@ -140,7 +140,7 @@ extern "C" {
} while (0)
#else
#define USBD_UsrLog(...) do {} while (0)
#endif
#endif /* (USBD_DEBUG_LEVEL > 0U) */
#if (USBD_DEBUG_LEVEL > 1U)
@@ -151,7 +151,7 @@ extern "C" {
} while (0)
#else
#define USBD_ErrLog(...) do {} while (0)
#endif
#endif /* (USBD_DEBUG_LEVEL > 1U) */
#if (USBD_DEBUG_LEVEL > 2U)
#define USBD_DbgLog(...) do { \
@@ -161,7 +161,7 @@ extern "C" {
} while (0)
#else
#define USBD_DbgLog(...) do {} while (0)
#endif
#endif /* (USBD_DEBUG_LEVEL > 2U) */
/**
* @}

View File

@@ -87,6 +87,17 @@ USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
#ifdef USE_USBD_COMPOSITE
USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass,
USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr);
USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev);
uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type);
#endif /* USE_USBD_COMPOSITE */
uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index);
uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index);
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
@@ -128,11 +139,18 @@ USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
uint8_t *pbuf, uint32_t size);
#ifdef USBD_HS_TESTMODE_ENABLE
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode);
#endif /* USBD_HS_TESTMODE_ENABLE */
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
void USBD_LL_Delay(uint32_t Delay);
void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr);
USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
/**
* @}
*/

View File

@@ -52,6 +52,24 @@ extern "C" {
#define USBD_MAX_NUM_CONFIGURATION 1U
#endif /* USBD_MAX_NUM_CONFIGURATION */
#ifdef USE_USBD_COMPOSITE
#ifndef USBD_MAX_SUPPORTED_CLASS
#define USBD_MAX_SUPPORTED_CLASS 4U
#endif /* USBD_MAX_SUPPORTED_CLASS */
#else
#ifndef USBD_MAX_SUPPORTED_CLASS
#define USBD_MAX_SUPPORTED_CLASS 1U
#endif /* USBD_MAX_SUPPORTED_CLASS */
#endif /* USE_USBD_COMPOSITE */
#ifndef USBD_MAX_CLASS_ENDPOINTS
#define USBD_MAX_CLASS_ENDPOINTS 5U
#endif /* USBD_MAX_CLASS_ENDPOINTS */
#ifndef USBD_MAX_CLASS_INTERFACES
#define USBD_MAX_CLASS_INTERFACES 5U
#endif /* USBD_MAX_CLASS_INTERFACES */
#ifndef USBD_LPM_ENABLED
#define USBD_LPM_ENABLED 0U
#endif /* USBD_LPM_ENABLED */
@@ -159,6 +177,14 @@ extern "C" {
#define USBD_EP_TYPE_BULK 0x02U
#define USBD_EP_TYPE_INTR 0x03U
#ifdef USE_USBD_COMPOSITE
#define USBD_EP_IN 0x80U
#define USBD_EP_OUT 0x00U
#define USBD_FUNC_DESCRIPTOR_TYPE 0x24U
#define USBD_DESC_SUBTYPE_ACM 0x0FU
#define USBD_DESC_ECM_BCD_LOW 0x00U
#define USBD_DESC_ECM_BCD_HIGH 0x10U
#endif /* USE_USBD_COMPOSITE */
/**
* @}
*/
@@ -187,7 +213,7 @@ typedef struct
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
} USBD_ConfigDescTypedef;
} __PACKED USBD_ConfigDescTypeDef;
typedef struct
{
@@ -195,7 +221,7 @@ typedef struct
uint8_t bDescriptorType;
uint16_t wTotalLength;
uint8_t bNumDeviceCaps;
} USBD_BosDescTypedef;
} USBD_BosDescTypeDef;
typedef struct
{
@@ -205,7 +231,14 @@ typedef struct
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
} __PACKED USBD_EpDescTypedef;
} __PACKED USBD_EpDescTypeDef;
typedef struct
{
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
} USBD_DescHeaderTypeDef;
struct _USBD_HandleTypeDef;
@@ -230,7 +263,7 @@ typedef struct _Device_cb
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
#endif
#endif /* USBD_SUPPORT_USER_STRING_DESC */
} USBD_ClassTypeDef;
@@ -263,10 +296,10 @@ typedef struct
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
#if (USBD_CLASS_USER_STRING_DESC == 1)
uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
#endif
#endif /* USBD_CLASS_USER_STRING_DESC */
#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1))
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
#endif
#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1) */
} USBD_DescriptorsTypeDef;
/* USB Device handle structure */
@@ -280,6 +313,49 @@ typedef struct
uint16_t bInterval;
} USBD_EndpointTypeDef;
#ifdef USE_USBD_COMPOSITE
typedef enum
{
CLASS_TYPE_NONE = 0,
CLASS_TYPE_HID = 1,
CLASS_TYPE_CDC = 2,
CLASS_TYPE_MSC = 3,
CLASS_TYPE_DFU = 4,
CLASS_TYPE_CHID = 5,
CLASS_TYPE_AUDIO = 6,
CLASS_TYPE_ECM = 7,
CLASS_TYPE_RNDIS = 8,
CLASS_TYPE_MTP = 9,
CLASS_TYPE_VIDEO = 10,
CLASS_TYPE_PRINTER = 11,
CLASS_TYPE_CCID = 12,
} USBD_CompositeClassTypeDef;
/* USB Device handle structure */
typedef struct
{
uint8_t add;
uint8_t type;
uint8_t size;
uint8_t is_used;
} USBD_EPTypeDef;
/* USB Device handle structure */
typedef struct
{
USBD_CompositeClassTypeDef ClassType;
uint32_t ClassId;
uint32_t Active;
uint32_t NumEps;
USBD_EPTypeDef Eps[USBD_MAX_CLASS_ENDPOINTS];
uint8_t *EpAdd;
uint32_t NumIf;
uint8_t Ifs[USBD_MAX_CLASS_INTERFACES];
uint32_t CurrPcktSze;
} USBD_CompositeElementTypeDef;
#endif /* USE_USBD_COMPOSITE */
/* USB Device handle structure */
typedef struct _USBD_HandleTypeDef
{
@@ -302,14 +378,33 @@ typedef struct _USBD_HandleTypeDef
USBD_SetupReqTypedef request;
USBD_DescriptorsTypeDef *pDesc;
USBD_ClassTypeDef *pClass;
USBD_ClassTypeDef *pClass[USBD_MAX_SUPPORTED_CLASS];
void *pClassData;
void *pUserData;
void *pClassDataCmsit[USBD_MAX_SUPPORTED_CLASS];
void *pUserData[USBD_MAX_SUPPORTED_CLASS];
void *pData;
void *pBosDesc;
void *pConfDesc;
uint32_t classId;
uint32_t NumClasses;
#ifdef USE_USBD_COMPOSITE
USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS];
#endif /* USE_USBD_COMPOSITE */
} USBD_HandleTypeDef;
/* USB Device endpoint direction */
typedef enum
{
OUT = 0x00,
IN = 0x80,
} USBD_EPDirectionTypeDef;
typedef enum
{
NETWORK_CONNECTION = 0x00,
RESPONSE_AVAILABLE = 0x01,
CONNECTION_SPEED_CHANGE = 0x2A
} USBD_CDC_NotifCodeTypeDef;
/**
* @}
*/
@@ -335,19 +430,19 @@ __STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
#ifndef LOBYTE
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
#endif
#endif /* LOBYTE */
#ifndef HIBYTE
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
#endif
#endif /* HIBYTE */
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#endif /* MIN */
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#endif /* MAX */
#if defined ( __GNUC__ )
#ifndef __weak

View File

@@ -43,7 +43,7 @@
#define USBD_BB_URL_STR_DESC (uint8_t *)"www.st.com"
#define USBD_BB_ALTMODE0_STR_DESC (uint8_t *)"STM32 Alternate0 Mode"
#define USBD_BB_ALTMODE1_STR_DESC (uint8_t *)"STM32 Alternate1 Mode"
#endif
#endif /* USBD_CLASS_USER_STRING_DESC */
#define USB_SIZ_STRING_SERIAL 0x1AU
@@ -51,7 +51,7 @@
#define USB_SIZ_BOS_DESC 0x0CU
#elif (USBD_CLASS_BOS_ENABLED == 1)
#define USB_SIZ_BOS_DESC 0x5DU
#endif
#endif /* USBD_LPM_ENABLED */
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

View File

@@ -233,6 +233,22 @@ uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
return 0U;
}
#ifdef USBD_HS_TESTMODE_ENABLE
/**
* @brief Set High speed Test mode.
* @param pdev: Device handle
* @param testmode: test mode
* @retval USBD Status
*/
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode)
{
UNUSED(pdev);
UNUSED(testmode);
return USBD_OK;
}
#endif /* USBD_HS_TESTMODE_ENABLE */
/**
* @brief Static single allocation.
* @param size: Size of allocated memory

View File

@@ -19,6 +19,10 @@
/* Includes ------------------------------------------------------------------*/
#include "usbd_core.h"
#ifdef USE_USBD_COMPOSITE
#include "usbd_composite_builder.h"
#endif /* USE_USBD_COMPOSITE */
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
* @{
*/
@@ -95,13 +99,29 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev,
{
#if (USBD_DEBUG_LEVEL > 1U)
USBD_ErrLog("Invalid Device handle");
#endif
#endif /* (USBD_DEBUG_LEVEL > 1U) */
return USBD_FAIL;
}
/* Unlink previous class resources */
pdev->pClass = NULL;
pdev->pUserData = NULL;
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
/* Unlink previous class*/
pdev->pClass[i] = NULL;
pdev->pUserData[i] = NULL;
/* Set class as inactive */
pdev->tclasslist[i].Active = 0;
pdev->NumClasses = 0;
pdev->classId = 0;
}
#else
/* Unlink previous class*/
pdev->pClass[0] = NULL;
pdev->pUserData[0] = NULL;
#endif /* USE_USBD_COMPOSITE */
pdev->pConfDesc = NULL;
/* Assign USBD Descriptors */
@@ -136,13 +156,31 @@ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
/* Set Default State */
pdev->dev_state = USBD_STATE_DEFAULT;
/* Free Class Resources */
if (pdev->pClass != NULL)
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
pdev->pClass = NULL;
pdev->pUserData = NULL;
/* Check if current class is in use */
if ((pdev->tclasslist[i].Active) == 1U)
{
if (pdev->pClass[i] != NULL)
{
pdev->classId = i;
/* Free Class Resources */
pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config);
}
}
}
#else
/* Free Class Resources */
if (pdev->pClass[0] != NULL)
{
pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config);
}
pdev->pUserData[0] = NULL;
#endif /* USE_USBD_COMPOSITE */
/* Free Device descriptors resources */
pdev->pDesc = NULL;
@@ -169,29 +207,161 @@ USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDe
{
#if (USBD_DEBUG_LEVEL > 1U)
USBD_ErrLog("Invalid Class handle");
#endif
#endif /* (USBD_DEBUG_LEVEL > 1U) */
return USBD_FAIL;
}
/* link the class to the USB Device handle */
pdev->pClass = pclass;
pdev->pClass[0] = pclass;
/* Get Device Configuration Descriptor */
#ifdef USE_USB_HS
if (pdev->pClass->GetHSConfigDescriptor != NULL)
if (pdev->pClass[pdev->classId]->GetHSConfigDescriptor != NULL)
{
pdev->pConfDesc = (void *)pdev->pClass->GetHSConfigDescriptor(&len);
pdev->pConfDesc = (void *)pdev->pClass[pdev->classId]->GetHSConfigDescriptor(&len);
}
#else /* Default USE_USB_FS */
if (pdev->pClass->GetFSConfigDescriptor != NULL)
if (pdev->pClass[pdev->classId]->GetFSConfigDescriptor != NULL)
{
pdev->pConfDesc = (void *)pdev->pClass->GetFSConfigDescriptor(&len);
pdev->pConfDesc = (void *)pdev->pClass[pdev->classId]->GetFSConfigDescriptor(&len);
}
#endif /* USE_USB_FS */
/* Increment the NumClasses */
pdev->NumClasses ++;
return USBD_OK;
}
#ifdef USE_USBD_COMPOSITE
/**
* @brief USBD_RegisterClassComposite
* Link class driver to Device Core.
* @param pdev : Device Handle
* @param pclass: Class handle
* @param classtype: Class type
* @param EpAddr: Endpoint Address handle
* @retval USBD Status
*/
USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass,
USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr)
{
USBD_StatusTypeDef ret = USBD_OK;
uint16_t len = 0U;
if ((pdev->classId < USBD_MAX_SUPPORTED_CLASS) && (pdev->NumClasses < USBD_MAX_SUPPORTED_CLASS))
{
if ((uint32_t)pclass != 0U)
{
/* Link the class to the USB Device handle */
pdev->pClass[pdev->classId] = pclass;
ret = USBD_OK;
pdev->tclasslist[pdev->classId].EpAdd = EpAddr;
/* Call the composite class builder */
(void)USBD_CMPSIT_AddClass(pdev, pclass, classtype, 0);
/* Increment the ClassId for the next occurrence */
pdev->classId ++;
pdev->NumClasses ++;
}
else
{
#if (USBD_DEBUG_LEVEL > 1U)
USBD_ErrLog("Invalid Class handle");
#endif /* (USBD_DEBUG_LEVEL > 1U) */
ret = USBD_FAIL;
}
}
if (ret == USBD_OK)
{
/* Get Device Configuration Descriptor */
#ifdef USE_USB_HS
pdev->pConfDesc = USBD_CMPSIT.GetHSConfigDescriptor(&len);
#else /* Default USE_USB_FS */
pdev->pConfDesc = USBD_CMPSIT.GetFSConfigDescriptor(&len);
#endif /* USE_USB_FS */
}
return ret;
}
/**
* @brief USBD_UnRegisterClassComposite
* UnLink all composite class drivers from Device Core.
* @param pDevice : Device Handle
* @retval USBD Status
*/
USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef ret = USBD_FAIL;
uint8_t idx1;
uint8_t idx2;
/* Unroll all activated classes */
for (idx1 = 0; idx1 < pdev->NumClasses; idx1++)
{
/* Check if the class correspond to the requested type and if it is active */
if (pdev->tclasslist[idx1].Active == 1U)
{
/* Set the new class ID */
pdev->classId = idx1;
/* Free resources used by the selected class */
if (pdev->pClass[pdev->classId] != NULL)
{
/* Free Class Resources */
if (pdev->pClass[pdev->classId]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U)
{
#if (USBD_DEBUG_LEVEL > 1U)
USBD_ErrLog("Class DeInit didn't succeed!, can't unregister selected class");
#endif /* (USBD_DEBUG_LEVEL > 1U) */
ret = USBD_FAIL;
}
}
/* Free the class pointer */
pdev->pClass[pdev->classId] = NULL;
/* Free the class location in classes table and reset its parameters to zero */
pdev->tclasslist[pdev->classId].ClassType = CLASS_TYPE_NONE;
pdev->tclasslist[pdev->classId].ClassId = 0U;
pdev->tclasslist[pdev->classId].Active = 0U;
pdev->tclasslist[pdev->classId].NumEps = 0U;
pdev->tclasslist[pdev->classId].NumIf = 0U;
pdev->tclasslist[pdev->classId].CurrPcktSze = 0U;
for (idx2 = 0U; idx2 < USBD_MAX_CLASS_ENDPOINTS; idx2++)
{
pdev->tclasslist[pdev->classId].Eps[idx2].add = 0U;
pdev->tclasslist[pdev->classId].Eps[idx2].type = 0U;
pdev->tclasslist[pdev->classId].Eps[idx2].size = 0U;
pdev->tclasslist[pdev->classId].Eps[idx2].is_used = 0U;
}
for (idx2 = 0U; idx2 < USBD_MAX_CLASS_INTERFACES; idx2++)
{
pdev->tclasslist[pdev->classId].Ifs[idx2] = 0U;
}
}
}
/* Reset the configuration descriptor */
(void)USBD_CMPST_ClearConfDesc(pdev);
/* Reset the class ID and number of classes */
pdev->classId = 0U;
pdev->NumClasses = 0U;
return ret;
}
#endif /* USE_USBD_COMPOSITE */
/**
* @brief USBD_Start
* Start the USB Device Core.
@@ -200,6 +370,10 @@ USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDe
*/
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev)
{
#ifdef USE_USBD_COMPOSITE
pdev->classId = 0U;
#endif /* USE_USBD_COMPOSITE */
/* Start the low level driver */
return USBD_LL_Start(pdev);
}
@@ -216,11 +390,31 @@ USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev)
(void)USBD_LL_Stop(pdev);
/* Free Class Resources */
if (pdev->pClass != NULL)
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
(void)pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
/* Check if current class is in use */
if ((pdev->tclasslist[i].Active) == 1U)
{
if (pdev->pClass[i] != NULL)
{
pdev->classId = i;
/* Free Class Resources */
(void)pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config);
}
}
}
/* Reset the class ID */
pdev->classId = 0U;
#else
if (pdev->pClass[0] != NULL)
{
(void)pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config);
}
#endif /* USE_USBD_COMPOSITE */
return USBD_OK;
}
@@ -230,12 +424,21 @@ USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev)
* @param pdev: device instance
* @retval status
*/
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev)
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev)
{
#ifdef USBD_HS_TESTMODE_ENABLE
USBD_StatusTypeDef ret;
/* Run USB HS test mode */
ret = USBD_LL_SetTestMode(pdev, pdev->dev_test_mode);
return ret;
#else
/* Prevent unused argument compilation warning */
UNUSED(pdev);
return USBD_OK;
#endif /* USBD_HS_TESTMODE_ENABLE */
}
/**
@@ -248,13 +451,33 @@ USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev)
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
USBD_StatusTypeDef ret = USBD_FAIL;
USBD_StatusTypeDef ret = USBD_OK;
if (pdev->pClass != NULL)
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
/* Check if current class is in use */
if ((pdev->tclasslist[i].Active) == 1U)
{
if (pdev->pClass[i] != NULL)
{
pdev->classId = i;
/* Set configuration and Start the Class*/
if (pdev->pClass[i]->Init(pdev, cfgidx) != 0U)
{
ret = USBD_FAIL;
}
}
}
}
#else
if (pdev->pClass[0] != NULL)
{
/* Set configuration and Start the Class */
ret = (USBD_StatusTypeDef)pdev->pClass->Init(pdev, cfgidx);
ret = (USBD_StatusTypeDef)pdev->pClass[0]->Init(pdev, cfgidx);
}
#endif /* USE_USBD_COMPOSITE */
return ret;
}
@@ -268,13 +491,35 @@ USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
*/
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
/* Clear configuration and De-initialize the Class process */
if (pdev->pClass != NULL)
{
pdev->pClass->DeInit(pdev, cfgidx);
}
USBD_StatusTypeDef ret = USBD_OK;
return USBD_OK;
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
/* Check if current class is in use */
if ((pdev->tclasslist[i].Active) == 1U)
{
if (pdev->pClass[i] != NULL)
{
pdev->classId = i;
/* Clear configuration and De-initialize the Class process */
if (pdev->pClass[i]->DeInit(pdev, cfgidx) != 0U)
{
ret = USBD_FAIL;
}
}
}
}
#else
/* Clear configuration and De-initialize the Class process */
if (pdev->pClass[0]->DeInit(pdev, cfgidx) != 0U)
{
ret = USBD_FAIL;
}
#endif /* USE_USBD_COMPOSITE */
return ret;
}
@@ -328,7 +573,8 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
uint8_t epnum, uint8_t *pdata)
{
USBD_EndpointTypeDef *pep;
USBD_StatusTypeDef ret;
USBD_StatusTypeDef ret = USBD_OK;
uint8_t idx;
if (epnum == 0U)
{
@@ -344,11 +590,39 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
}
else
{
if (pdev->dev_state == USBD_STATE_CONFIGURED)
/* Find the class ID relative to the current request */
switch (pdev->request.bmRequest & 0x1FU)
{
if (pdev->pClass->EP0_RxReady != NULL)
case USB_REQ_RECIPIENT_DEVICE:
/* Device requests must be managed by the first instantiated class
(or duplicated by all classes for simplicity) */
idx = 0U;
break;
case USB_REQ_RECIPIENT_INTERFACE:
idx = USBD_CoreFindIF(pdev, LOBYTE(pdev->request.wIndex));
break;
case USB_REQ_RECIPIENT_ENDPOINT:
idx = USBD_CoreFindEP(pdev, LOBYTE(pdev->request.wIndex));
break;
default:
/* Back to the first class in case of doubt */
idx = 0U;
break;
}
if (idx < USBD_MAX_SUPPORTED_CLASS)
{
/* Setup the class ID and route the request to the relative class function */
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
pdev->pClass->EP0_RxReady(pdev);
if (pdev->pClass[idx]->EP0_RxReady != NULL)
{
pdev->classId = idx;
pdev->pClass[idx]->EP0_RxReady(pdev);
}
}
}
@@ -371,17 +645,24 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
}
else
{
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (pdev->pClass->DataOut != NULL)
{
ret = (USBD_StatusTypeDef)pdev->pClass->DataOut(pdev, epnum);
/* Get the class index relative to this interface */
idx = USBD_CoreFindEP(pdev, (epnum & 0x7FU));
if (ret != USBD_OK)
if (((uint16_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
{
/* Call the class data out function to manage the request */
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (pdev->pClass[idx]->DataOut != NULL)
{
return ret;
pdev->classId = idx;
ret = (USBD_StatusTypeDef)pdev->pClass[idx]->DataOut(pdev, epnum);
}
}
if (ret != USBD_OK)
{
return ret;
}
}
}
@@ -400,6 +681,7 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
{
USBD_EndpointTypeDef *pep;
USBD_StatusTypeDef ret;
uint8_t idx;
if (epnum == 0U)
{
@@ -433,9 +715,10 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
{
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (pdev->pClass->EP0_TxSent != NULL)
if (pdev->pClass[0]->EP0_TxSent != NULL)
{
pdev->pClass->EP0_TxSent(pdev);
pdev->classId = 0U;
pdev->pClass[0]->EP0_TxSent(pdev);
}
}
(void)USBD_LL_StallEP(pdev, 0x80U);
@@ -454,7 +737,7 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
#endif
}
if (pdev->dev_test_mode == 1U)
if (pdev->dev_test_mode != 0U)
{
(void)USBD_RunTestMode(pdev);
pdev->dev_test_mode = 0U;
@@ -462,15 +745,23 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
}
else
{
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (pdev->pClass->DataIn != NULL)
{
ret = (USBD_StatusTypeDef)pdev->pClass->DataIn(pdev, epnum);
/* Get the class index relative to this interface */
idx = USBD_CoreFindEP(pdev, ((uint8_t)epnum | 0x80U));
if (ret != USBD_OK)
if (((uint16_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
{
/* Call the class data out function to manage the request */
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (pdev->pClass[idx]->DataIn != NULL)
{
return ret;
pdev->classId = idx;
ret = (USBD_StatusTypeDef)pdev->pClass[idx]->DataIn(pdev, epnum);
if (ret != USBD_OK)
{
return ret;
}
}
}
}
@@ -488,24 +779,50 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef ret = USBD_OK;
/* Upon Reset call user call back */
pdev->dev_state = USBD_STATE_DEFAULT;
pdev->ep0_state = USBD_EP0_IDLE;
pdev->dev_config = 0U;
pdev->dev_remote_wakeup = 0U;
pdev->dev_test_mode = 0U;
if (pdev->pClass == NULL)
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
return USBD_FAIL;
}
if (pdev->pClassData != NULL)
{
if (pdev->pClass->DeInit != NULL)
/* Check if current class is in use */
if ((pdev->tclasslist[i].Active) == 1U)
{
(void)pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
if (pdev->pClass[i] != NULL)
{
pdev->classId = i;
/* Clear configuration and De-initialize the Class process*/
if (pdev->pClass[i]->DeInit != NULL)
{
if (pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config) != USBD_OK)
{
ret = USBD_FAIL;
}
}
}
}
}
#else
if (pdev->pClass[0] != NULL)
{
if (pdev->pClass[0]->DeInit != NULL)
{
if (pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config) != USBD_OK)
{
ret = USBD_FAIL;
}
}
}
#endif /* USE_USBD_COMPOSITE */
/* Open EP0 OUT */
(void)USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
@@ -519,7 +836,7 @@ USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
return USBD_OK;
return ret;
}
/**
@@ -577,17 +894,35 @@ USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
{
if (pdev->pClass == NULL)
{
return USBD_FAIL;
}
/* The SOF event can be distributed for all classes that support it */
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (pdev->pClass->SOF != NULL)
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
(void)pdev->pClass->SOF(pdev);
/* Check if current class is in use */
if ((pdev->tclasslist[i].Active) == 1U)
{
if (pdev->pClass[i] != NULL)
{
if (pdev->pClass[i]->SOF != NULL)
{
pdev->classId = i;
(void)pdev->pClass[i]->SOF(pdev);
}
}
}
}
#else
if (pdev->pClass[0] != NULL)
{
if (pdev->pClass[0]->SOF != NULL)
{
(void)pdev->pClass[0]->SOF(pdev);
}
}
#endif /* USE_USBD_COMPOSITE */
}
return USBD_OK;
@@ -602,16 +937,16 @@ USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev,
uint8_t epnum)
{
if (pdev->pClass == NULL)
if (pdev->pClass[pdev->classId] == NULL)
{
return USBD_FAIL;
}
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (pdev->pClass->IsoINIncomplete != NULL)
if (pdev->pClass[pdev->classId]->IsoINIncomplete != NULL)
{
(void)pdev->pClass->IsoINIncomplete(pdev, epnum);
(void)pdev->pClass[pdev->classId]->IsoINIncomplete(pdev, epnum);
}
}
@@ -627,16 +962,16 @@ USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev,
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev,
uint8_t epnum)
{
if (pdev->pClass == NULL)
if (pdev->pClass[pdev->classId] == NULL)
{
return USBD_FAIL;
}
if (pdev->dev_state == USBD_STATE_CONFIGURED)
{
if (pdev->pClass->IsoOUTIncomplete != NULL)
if (pdev->pClass[pdev->classId]->IsoOUTIncomplete != NULL)
{
(void)pdev->pClass->IsoOUTIncomplete(pdev, epnum);
(void)pdev->pClass[pdev->classId]->IsoOUTIncomplete(pdev, epnum);
}
}
@@ -665,16 +1000,210 @@ USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
*/
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
{
USBD_StatusTypeDef ret = USBD_OK;
/* Free Class Resources */
pdev->dev_state = USBD_STATE_DEFAULT;
if (pdev->pClass != NULL)
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
(void)pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
/* Check if current class is in use */
if ((pdev->tclasslist[i].Active) == 1U)
{
if (pdev->pClass[i] != NULL)
{
pdev->classId = i;
/* Clear configuration and De-initialize the Class process*/
if (pdev->pClass[i]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U)
{
ret = USBD_FAIL;
}
}
}
}
#else
if (pdev->pClass[0] != NULL)
{
if (pdev->pClass[0]->DeInit(pdev, (uint8_t)pdev->dev_config) != 0U)
{
ret = USBD_FAIL;
}
}
#endif /* USE_USBD_COMPOSITE */
return ret;
}
/**
* @brief USBD_CoreFindIF
* return the class index relative to the selected interface
* @param pdev: device instance
* @param index : selected interface number
* @retval index of the class using the selected interface number. OxFF if no class found.
*/
uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index)
{
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
/* Check if current class is in use */
if ((pdev->tclasslist[i].Active) == 1U)
{
/* Parse all interfaces listed in the current class */
for (uint32_t j = 0U; j < pdev->tclasslist[i].NumIf; j++)
{
/* Check if requested Interface matches the current class interface */
if (pdev->tclasslist[i].Ifs[j] == index)
{
if (pdev->pClass[i]->Setup != NULL)
{
return (uint8_t)i;
}
}
}
}
}
return USBD_OK;
return 0xFFU;
#else
UNUSED(pdev);
UNUSED(index);
return 0x00U;
#endif /* USE_USBD_COMPOSITE */
}
/**
* @brief USBD_CoreFindEP
* return the class index relative to the selected endpoint
* @param pdev: device instance
* @param index : selected endpoint number
* @retval index of the class using the selected endpoint number. 0xFF if no class found.
*/
uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index)
{
#ifdef USE_USBD_COMPOSITE
/* Parse the table of classes in use */
for (uint32_t i = 0U; i < USBD_MAX_SUPPORTED_CLASS; i++)
{
/* Check if current class is in use */
if ((pdev->tclasslist[i].Active) == 1U)
{
/* Parse all endpoints listed in the current class */
for (uint32_t j = 0U; j < pdev->tclasslist[i].NumEps; j++)
{
/* Check if requested endpoint matches the current class endpoint */
if (pdev->tclasslist[i].Eps[j].add == index)
{
if (pdev->pClass[i]->Setup != NULL)
{
return (uint8_t)i;
}
}
}
}
}
return 0xFFU;
#else
UNUSED(pdev);
UNUSED(index);
return 0x00U;
#endif /* USE_USBD_COMPOSITE */
}
#ifdef USE_USBD_COMPOSITE
/**
* @brief USBD_CoreGetEPAdd
* Get the endpoint address relative to a selected class
* @param pdev: device instance
* @param ep_dir: USBD_EP_IN or USBD_EP_OUT
* @param ep_type: USBD_EP_TYPE_CTRL, USBD_EP_TYPE_ISOC, USBD_EP_TYPE_BULK or USBD_EP_TYPE_INTR
* @retval Address of the selected endpoint or 0xFFU if no endpoint found.
*/
uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type)
{
uint8_t idx;
/* Find the EP address in the selected class table */
for (idx = 0; idx < pdev->tclasslist[pdev->classId].NumEps; idx++)
{
if (((pdev->tclasslist[pdev->classId].Eps[idx].add & USBD_EP_IN) == ep_dir) && \
(pdev->tclasslist[pdev->classId].Eps[idx].type == ep_type) && \
(pdev->tclasslist[pdev->classId].Eps[idx].is_used != 0U))
{
return (pdev->tclasslist[pdev->classId].Eps[idx].add);
}
}
/* If reaching this point, then no endpoint was found */
return 0xFFU;
}
#endif /* USE_USBD_COMPOSITE */
/**
* @brief USBD_GetEpDesc
* This function return the Endpoint descriptor
* @param pdev: device instance
* @param pConfDesc: pointer to Bos descriptor
* @param EpAddr: endpoint address
* @retval pointer to video endpoint descriptor
*/
void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr)
{
USBD_DescHeaderTypeDef *pdesc = (USBD_DescHeaderTypeDef *)(void *)pConfDesc;
USBD_ConfigDescTypeDef *desc = (USBD_ConfigDescTypeDef *)(void *)pConfDesc;
USBD_EpDescTypeDef *pEpDesc = NULL;
uint16_t ptr;
if (desc->wTotalLength > desc->bLength)
{
ptr = desc->bLength;
while (ptr < desc->wTotalLength)
{
pdesc = USBD_GetNextDesc((uint8_t *)pdesc, &ptr);
if (pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT)
{
pEpDesc = (USBD_EpDescTypeDef *)(void *)pdesc;
if (pEpDesc->bEndpointAddress == EpAddr)
{
break;
}
else
{
pEpDesc = NULL;
}
}
}
}
return (void *)pEpDesc;
}
/**
* @brief USBD_GetNextDesc
* This function return the next descriptor header
* @param buf: Buffer where the descriptor is available
* @param ptr: data pointer inside the descriptor
* @retval next header
*/
USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr)
{
USBD_DescHeaderTypeDef *pnext = (USBD_DescHeaderTypeDef *)(void *)pbuf;
*ptr += pnext->bLength;
pnext = (USBD_DescHeaderTypeDef *)(void *)(pbuf + pnext->bLength);
return (pnext);
}
/**
* @}
*/

View File

@@ -20,6 +20,9 @@
#include "usbd_ctlreq.h"
#include "usbd_ioreq.h"
#ifdef USE_USBD_COMPOSITE
#include "usbd_composite_builder.h"
#endif /* USE_USBD_COMPOSITE */
/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY
* @{
@@ -104,7 +107,7 @@ USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
{
case USB_REQ_TYPE_CLASS:
case USB_REQ_TYPE_VENDOR:
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
ret = (USBD_StatusTypeDef)pdev->pClass[pdev->classId]->Setup(pdev, req);
break;
case USB_REQ_TYPE_STANDARD:
@@ -162,6 +165,7 @@ USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
USBD_StatusTypeDef ret = USBD_OK;
uint8_t idx;
switch (req->bmRequest & USB_REQ_TYPE_MASK)
{
@@ -176,7 +180,27 @@ USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
{
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
/* Get the class index relative to this interface */
idx = USBD_CoreFindIF(pdev, LOBYTE(req->wIndex));
if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
{
/* Call the class data out function to manage the request */
if (pdev->pClass[idx]->Setup != NULL)
{
pdev->classId = idx;
ret = (USBD_StatusTypeDef)(pdev->pClass[idx]->Setup(pdev, req));
}
else
{
/* should never reach this condition */
ret = USBD_FAIL;
}
}
else
{
/* No relative interface found */
ret = USBD_FAIL;
}
if ((req->wLength == 0U) && (ret == USBD_OK))
{
@@ -214,14 +238,26 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
{
USBD_EndpointTypeDef *pep;
uint8_t ep_addr;
uint8_t idx;
USBD_StatusTypeDef ret = USBD_OK;
ep_addr = LOBYTE(req->wIndex);
switch (req->bmRequest & USB_REQ_TYPE_MASK)
{
case USB_REQ_TYPE_CLASS:
case USB_REQ_TYPE_VENDOR:
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
/* Get the class index relative to this endpoint */
idx = USBD_CoreFindEP(pdev, ep_addr);
if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
{
pdev->classId = idx;
/* Call the class data out function to manage the request */
if (pdev->pClass[idx]->Setup != NULL)
{
ret = (USBD_StatusTypeDef)pdev->pClass[idx]->Setup(pdev, req);
}
}
break;
case USB_REQ_TYPE_STANDARD:
@@ -284,7 +320,18 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
(void)USBD_LL_ClearStallEP(pdev, ep_addr);
}
(void)USBD_CtlSendStatus(pdev);
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
/* Get the class index relative to this interface */
idx = USBD_CoreFindEP(pdev, ep_addr);
if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
{
pdev->classId = idx;
/* Call the class data out function to manage the request */
if (pdev->pClass[idx]->Setup != NULL)
{
ret = (USBD_StatusTypeDef)(pdev->pClass[idx]->Setup(pdev, req));
}
}
}
break;
@@ -396,7 +443,7 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
err++;
}
break;
#endif
#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1U) */
case USB_DESC_TYPE_DEVICE:
pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
break;
@@ -404,12 +451,30 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
case USB_DESC_TYPE_CONFIGURATION:
if (pdev->dev_speed == USBD_SPEED_HIGH)
{
pbuf = pdev->pClass->GetHSConfigDescriptor(&len);
#ifdef USE_USBD_COMPOSITE
if ((uint8_t)(pdev->NumClasses) > 0U)
{
pbuf = (uint8_t *)USBD_CMPSIT.GetHSConfigDescriptor(&len);
}
else
#endif /* USE_USBD_COMPOSITE */
{
pbuf = (uint8_t *)pdev->pClass[0]->GetHSConfigDescriptor(&len);
}
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
}
else
{
pbuf = pdev->pClass->GetFSConfigDescriptor(&len);
#ifdef USE_USBD_COMPOSITE
if ((uint8_t)(pdev->NumClasses) > 0U)
{
pbuf = (uint8_t *)USBD_CMPSIT.GetFSConfigDescriptor(&len);
}
else
#endif /* USE_USBD_COMPOSITE */
{
pbuf = (uint8_t *)pdev->pClass[0]->GetFSConfigDescriptor(&len);
}
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
}
break;
@@ -491,16 +556,28 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
default:
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
if (pdev->pClass->GetUsrStrDescriptor != NULL)
pbuf = NULL;
for (uint32_t idx = 0U; (idx < pdev->NumClasses); idx++)
{
pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue), &len);
if (pdev->pClass[idx]->GetUsrStrDescriptor != NULL)
{
pdev->classId = idx;
pbuf = pdev->pClass[idx]->GetUsrStrDescriptor(pdev, LOBYTE(req->wValue), &len);
if (pbuf == NULL) /* This means that no class recognized the string index */
{
continue;
}
else
{
break;
}
}
}
else
{
USBD_CtlError(pdev, req);
err++;
}
#endif
#endif /* USBD_SUPPORT_USER_STRING_DESC */
#if (USBD_CLASS_USER_STRING_DESC == 1U)
if (pdev->pDesc->GetUserStrDescriptor != NULL)
@@ -512,12 +589,12 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
USBD_CtlError(pdev, req);
err++;
}
#endif
#endif /* USBD_SUPPORT_USER_STRING_DESC */
#if ((USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U))
USBD_CtlError(pdev, req);
err++;
#endif
#endif /* (USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U) */
break;
}
break;
@@ -525,7 +602,16 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
case USB_DESC_TYPE_DEVICE_QUALIFIER:
if (pdev->dev_speed == USBD_SPEED_HIGH)
{
pbuf = pdev->pClass->GetDeviceQualifierDescriptor(&len);
#ifdef USE_USBD_COMPOSITE
if ((uint8_t)(pdev->NumClasses) > 0U)
{
pbuf = (uint8_t *)USBD_CMPSIT.GetDeviceQualifierDescriptor(&len);
}
else
#endif /* USE_USBD_COMPOSITE */
{
pbuf = (uint8_t *)pdev->pClass[0]->GetDeviceQualifierDescriptor(&len);
}
}
else
{
@@ -537,7 +623,16 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION:
if (pdev->dev_speed == USBD_SPEED_HIGH)
{
pbuf = pdev->pClass->GetOtherSpeedConfigDescriptor(&len);
#ifdef USE_USBD_COMPOSITE
if ((uint8_t)(pdev->NumClasses) > 0U)
{
pbuf = (uint8_t *)USBD_CMPSIT.GetOtherSpeedConfigDescriptor(&len);
}
else
#endif /* USE_USBD_COMPOSITE */
{
pbuf = (uint8_t *)pdev->pClass[0]->GetOtherSpeedConfigDescriptor(&len);
}
pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION;
}
else
@@ -650,6 +745,7 @@ static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReq
if (ret != USBD_OK)
{
USBD_CtlError(pdev, req);
pdev->dev_state = USBD_STATE_ADDRESSED;
}
else
{
@@ -766,7 +862,7 @@ static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
pdev->dev_config_status = USB_CONFIG_SELF_POWERED;
#else
pdev->dev_config_status = 0U;
#endif
#endif /* USBD_SELF_POWERED */
if (pdev->dev_remote_wakeup != 0U)
{
@@ -797,6 +893,15 @@ static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
pdev->dev_remote_wakeup = 1U;
(void)USBD_CtlSendStatus(pdev);
}
else if (req->wValue == USB_FEATURE_TEST_MODE)
{
pdev->dev_test_mode = req->wIndex >> 8;
(void)USBD_CtlSendStatus(pdev);
}
else
{
USBD_CtlError(pdev, req);
}
}

View File

@@ -52,7 +52,7 @@ uint8_t *USBD_Class_UserStrDescriptor(USBD_SpeedTypeDef speed, uint8_t idx, uint
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
uint8_t *USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
#endif
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
/* Private variables ---------------------------------------------------------*/
USBD_DescriptorsTypeDef Class_Desc =
@@ -66,17 +66,17 @@ USBD_DescriptorsTypeDef Class_Desc =
USBD_Class_InterfaceStrDescriptor,
#if (USBD_CLASS_USER_STRING_DESC == 1)
USBD_CLASS_UserStrDescriptor,
#endif
#endif /* USB_CLASS_USER_STRING_DESC */
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
USBD_USR_BOSDescriptor,
#endif
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
};
/* USB Standard Device Descriptor */
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif /* __ICCARM__ */
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
{
0x12, /* bLength */
@@ -86,7 +86,7 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
in order to support BOS Desc */
#else
0x00, /* bcdUSB */
#endif
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
0x02,
0x00, /* bDeviceClass */
0x00, /* bDeviceSubClass */
@@ -109,7 +109,7 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
#if (USBD_LPM_ENABLED == 1)
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif /* __ICCARM__ */
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
{
0x5,
@@ -126,13 +126,13 @@ __ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
0x0,
0x0
};
#endif
#endif /* USBD_LPM_ENABLED */
/* USB Device Billboard BOS descriptor Template */
#if (USBD_CLASS_BOS_ENABLED == 1)
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif /* __ICCARM__ */
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
{
0x05, /* bLength */
@@ -155,14 +155,16 @@ __ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
0x34, /* bLength */
0x10, /* bDescriptorType: DEVICE CAPABILITY Type */
0x0D, /* bDevCapabilityType: BILLBOARD_CAPABILITY */
USBD_BB_URL_STRING_INDEX, /* iAddtionalInfoURL: Index of string descriptor providing a URL where the user can go to get more
detailed information about the product and the various Alternate Modes it supports */
USBD_BB_URL_STRING_INDEX, /* iAddtionalInfoURL: Index of string descriptor providing a URL where the user
can go to get more detailed information about the product and the various
Alternate Modes it supports */
0x02, /* bNumberOfAlternateModes: Number of Alternate modes supported. The
maximum value that this field can be set to is MAX_NUM_ALT_MODE. */
0x00, /* bPreferredAlternateMode: Index of the preferred Alternate Mode. System
software may use this information to provide the user with a better user experience. */
software may use this information to provide the user with a better
user experience. */
0x00, 0x00, /* VCONN Power needed by the adapter for full functionality 000b = 1W */
@@ -205,21 +207,23 @@ __ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
0x10, /* bDescriptorType: Device Descriptor Type */
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
0x00, /* bIndex: Index of Alternate Mode described in the Billboard Capability Desc */
0x10, 0x00, 0x00, 0x00, /* dwAlternateModeVdo: contents of the Mode VDO for the alternate mode identified by bIndex */
0x10, 0x00, 0x00, 0x00, /* dwAlternateModeVdo: contents of the Mode VDO for the alternate mode
identified by bIndex */
0x08, /* bLength */
0x10, /* bDescriptorType: Device Descriptor Type */
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
0x01, /* bIndex: Index of Alternate Mode described in the Billboard Capability Desc */
0x20, 0x00, 0x00, 0x00, /* dwAlternateModeVdo: contents of the Mode VDO for the alternate mode identified by bIndex */
0x20, 0x00, 0x00, 0x00, /* dwAlternateModeVdo: contents of the Mode VDO for the alternate mode
identified by bIndex */
};
#endif
#endif /* USBD_CLASS_BOS_ENABLED */
/* USB Standard Device Descriptor */
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif /* __ICCARM__ */
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
{
USB_LEN_LANGID_STR_DESC,
@@ -230,7 +234,7 @@ __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif /* __ICCARM__ */
__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
{
USB_SIZ_STRING_SERIAL,
@@ -239,7 +243,7 @@ __ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif /* __ICCARM__ */
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
/* Private functions ---------------------------------------------------------*/
@@ -399,7 +403,7 @@ uint8_t *USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
*length = sizeof(USBD_BOSDesc);
return (uint8_t *)USBD_BOSDesc;
}
#endif
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
#if (USBD_CLASS_USER_STRING_DESC == 1)
@@ -416,7 +420,7 @@ uint8_t *USBD_Class_UserStrDescriptor(USBD_SpeedTypeDef speed, uint8_t idx, uint
return USBD_StrDesc;
}
#endif
#endif /* USBD_CLASS_USER_STRING_DESC */
/**

View File

@@ -94,7 +94,7 @@ USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
pdev->ep_in[0].rem_length = 0U;
#else
pdev->ep_in[0].rem_length = len;
#endif
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
/* Start the transfer */
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
@@ -138,7 +138,7 @@ USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
pdev->ep_out[0].rem_length = 0U;
#else
pdev->ep_out[0].rem_length = len;
#endif
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
/* Start the transfer */
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);