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

@@ -87,11 +87,13 @@ static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
#ifndef USE_USBD_COMPOSITE
static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length);
static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length);
static uint8_t *USBD_MTP_GetOtherSpeedCfgDesc(uint16_t *length);
static uint8_t *USBD_MTP_GetDeviceQualifierDescriptor(uint16_t *length);
#endif /* USE_USBD_COMPOSITE */
/**
* @}
@@ -115,14 +117,23 @@ USBD_ClassTypeDef USBD_MTP =
NULL, /*SOF */
NULL, /*ISOIn*/
NULL, /*ISOOut*/
#ifdef USE_USBD_COMPOSITE
NULL,
NULL,
NULL,
NULL,
#else
USBD_MTP_GetHSCfgDesc,
USBD_MTP_GetFSCfgDesc,
USBD_MTP_GetOtherSpeedCfgDesc,
USBD_MTP_GetDeviceQualifierDescriptor,
#endif /* USE_USBD_COMPOSITE */
};
#ifndef USE_USBD_COMPOSITE
/* USB MTP device Configuration Descriptor */
__ALIGN_BEGIN static uint8_t USBD_MTP_CfgHSDesc[MTP_CONFIG_DESC_SIZ] __ALIGN_END =
__ALIGN_BEGIN static uint8_t USBD_MTP_CfgDesc[MTP_CONFIG_DESC_SIZ] __ALIGN_END =
{
/* Configuration Descriptor */
0x09, /* bLength: Configuration Descriptor size */
@@ -131,67 +142,13 @@ __ALIGN_BEGIN static uint8_t USBD_MTP_CfgHSDesc[MTP_CONFIG_DESC_SIZ] __ALIGN_END
HIBYTE(MTP_CONFIG_DESC_SIZ),
0x01, /* bNumInterfaces: 1 interface */
0x01, /* bConfigurationValue: Configuration value */
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
#if (USBD_SELF_POWERED == 1U)
0xC0, /* bmAttributes: Bus Powered according to user configuration */
#else
0x80, /* bmAttributes: Bus Powered according to user configuration */
#endif
USBD_MAX_POWER, /* MaxPower (mA) */
/******************** MTP **** interface ********************/
MTP_INTERFACE_DESC_SIZE, /* bLength: Interface Descriptor size */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
MTP_CMD_ITF_NBR, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x03, /* bNumEndpoints: */
USB_MTP_INTRERFACE_CLASS, /* bInterfaceClass: bInterfaceClass: user's interface for MTP */
USB_MTP_INTRERFACE_SUB_CLASS, /* bInterfaceSubClass:Abstract Control Model */
USB_MTP_INTRERFACE_PROTOCOL, /* bInterfaceProtocol: Common AT commands */
0x00, /* iInterface: */
/******************** MTP Endpoints ********************/
MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
MTP_IN_EP, /* Endpoint address (IN, address 1) */
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
LOBYTE(MTP_DATA_MAX_HS_PACKET_SIZE),
HIBYTE(MTP_DATA_MAX_HS_PACKET_SIZE),
0x00, /* Polling interval in milliseconds */
MTP_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
MTP_OUT_EP, /* Endpoint address (OUT, address 1) */
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
LOBYTE(MTP_DATA_MAX_HS_PACKET_SIZE),
HIBYTE(MTP_DATA_MAX_HS_PACKET_SIZE),
0x00, /* Polling interval in milliseconds */
MTP_ENDPOINT_DESC_SIZE, /* bLength: Endpoint Descriptor size */
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType:*/
MTP_CMD_EP, /* bEndpointAddress: Endpoint Address (IN) */
USBD_EP_TYPE_INTR, /* bmAttributes: Interrupt endpoint */
LOBYTE(MTP_CMD_PACKET_SIZE),
HIBYTE(MTP_CMD_PACKET_SIZE),
MTP_HS_BINTERVAL /* Polling interval in milliseconds */
};
/* USB MTP device Configuration Descriptor */
__ALIGN_BEGIN static uint8_t USBD_MTP_CfgFSDesc[MTP_CONFIG_DESC_SIZ] __ALIGN_END =
{
/* Configuration Descriptor */
0x09, /* bLength: Configuration Descriptor size */
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
LOBYTE(MTP_CONFIG_DESC_SIZ), /* wTotalLength: Total size of the Config descriptor */
HIBYTE(MTP_CONFIG_DESC_SIZ),
0x01, /* bNumInterfaces: 1 interface */
0x01, /* bConfigurationValue: Configuration value */
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
0x00, /* iConfiguration: Index of string descriptor
describing the configuration */
#if (USBD_SELF_POWERED == 1U)
0xC0, /* bmAttributes: Bus Powered according to user configuration */
#else
0x80, /* bmAttributes: Bus Powered according to user configuration */
#endif
#endif /* USBD_SELF_POWERED */
USBD_MAX_POWER, /* MaxPower (mA) */
/******************** MTP **** interface ********************/
@@ -245,6 +202,11 @@ __ALIGN_BEGIN static uint8_t USBD_MTP_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
0x01,
0x00,
};
#endif /* USE_USBD_COMPOSITE */
uint8_t MTPInEpAdd = MTP_IN_EP;
uint8_t MTPOutEpAdd = MTP_OUT_EP;
uint8_t MTPCmdEpAdd = MTP_CMD_EP;
/**
* @}
@@ -270,30 +232,46 @@ static uint8_t USBD_MTP_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
if (hmtp == NULL)
{
pdev->pClassData = NULL;
pdev->pClassDataCmsit[pdev->classId] = NULL;
return (uint8_t)USBD_EMEM;
}
/* Setup the pClassData pointer */
pdev->pClassData = (void *)hmtp;
pdev->pClassDataCmsit[pdev->classId] = (void *)hmtp;
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
#ifdef USE_USBD_COMPOSITE
/* Get the Endpoints addresses allocated for this class instance */
MTPInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK);
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK);
MTPCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR);
#endif /* USE_USBD_COMPOSITE */
/* Initialize all variables */
(void)USBD_memset(hmtp, 0, sizeof(USBD_MTP_HandleTypeDef));
/* Setup the max packet size according to selected speed */
hmtp->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? MTP_DATA_MAX_HS_PACKET_SIZE : MTP_DATA_MAX_FS_PACKET_SIZE;
if (pdev->dev_speed == USBD_SPEED_HIGH)
{
hmtp->MaxPcktLen = MTP_DATA_MAX_HS_PACKET_SIZE;
}
else
{
hmtp->MaxPcktLen = MTP_DATA_MAX_FS_PACKET_SIZE;
}
/* Open EP IN */
(void)USBD_LL_OpenEP(pdev, MTP_IN_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 1U;
(void)USBD_LL_OpenEP(pdev, MTPInEpAdd, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
pdev->ep_in[MTPInEpAdd & 0xFU].is_used = 1U;
/* Open EP OUT */
(void)USBD_LL_OpenEP(pdev, MTP_OUT_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 1U;
(void)USBD_LL_OpenEP(pdev, MTPOutEpAdd, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
pdev->ep_out[MTPOutEpAdd & 0xFU].is_used = 1U;
/* Open INTR EP IN */
(void)USBD_LL_OpenEP(pdev, MTP_CMD_EP, USBD_EP_TYPE_INTR, MTP_CMD_PACKET_SIZE);
pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 1U;
(void)USBD_LL_OpenEP(pdev, MTPCmdEpAdd, USBD_EP_TYPE_INTR, MTP_CMD_PACKET_SIZE);
pdev->ep_in[MTPCmdEpAdd & 0xFU].is_used = 1U;
/* Init the MTP layer */
(void)USBD_MTP_STORAGE_Init(pdev);
@@ -312,25 +290,33 @@ static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
UNUSED(cfgidx);
#ifdef USE_USBD_COMPOSITE
/* Get the Endpoints addresses allocated for this MTP class instance */
MTPInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK);
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK);
MTPCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR);
#endif /* USE_USBD_COMPOSITE */
/* Close EP IN */
(void)USBD_LL_CloseEP(pdev, MTP_IN_EP);
pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 0U;
(void)USBD_LL_CloseEP(pdev, MTPInEpAdd);
pdev->ep_in[MTPInEpAdd & 0xFU].is_used = 0U;
/* Close EP OUT */
(void)USBD_LL_CloseEP(pdev, MTP_OUT_EP);
pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 0U;
(void)USBD_LL_CloseEP(pdev, MTPOutEpAdd);
pdev->ep_out[MTPOutEpAdd & 0xFU].is_used = 0U;
/* Close EP Command */
(void)USBD_LL_CloseEP(pdev, MTP_CMD_EP);
pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 0U;
/* De-Init the MTP layer */
(void)USBD_MTP_STORAGE_DeInit(pdev);
(void)USBD_LL_CloseEP(pdev, MTPCmdEpAdd);
pdev->ep_in[MTPCmdEpAdd & 0xFU].is_used = 0U;
/* Free MTP Class Resources */
if (pdev->pClassData != NULL)
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
{
(void)USBD_free(pdev->pClassData);
/* De-Init the MTP layer */
(void)USBD_MTP_STORAGE_DeInit(pdev);
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
pdev->pClassDataCmsit[pdev->classId] = NULL;
pdev->pClassData = NULL;
}
@@ -346,10 +332,15 @@ static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
*/
static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
USBD_StatusTypeDef ret = USBD_OK;
uint16_t len = 0U;
#ifdef USE_USBD_COMPOSITE
/* Get the Endpoints addresses allocated for this MTP class instance */
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK);
#endif /* USE_USBD_COMPOSITE */
if (hmtp == NULL)
{
return (uint8_t)USBD_FAIL;
@@ -373,7 +364,7 @@ static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re
/* Stop low layer file system operations if any */
USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE);
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, hmtp->MaxPcktLen);
(void)USBD_LL_PrepareReceive(pdev, MTPOutEpAdd, (uint8_t *)&hmtp->rx_buff, hmtp->MaxPcktLen);
break;
case MTP_REQ_GET_DEVICE_STATUS:
@@ -464,10 +455,16 @@ static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re
static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
{
UNUSED(epnum);
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
uint16_t len;
if (epnum == (MTP_IN_EP & 0x7FU))
#ifdef USE_USBD_COMPOSITE
/* Get the Endpoints addresses allocated for this MTP class instance */
MTPInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK);
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK);
#endif /* USE_USBD_COMPOSITE */
if (epnum == (MTPInEpAdd & 0x7FU))
{
switch (hmtp->MTP_ResponsePhase)
{
@@ -477,22 +474,24 @@ static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
/* prepare to receive next operation */
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
(void)USBD_LL_PrepareReceive(pdev, MTPOutEpAdd, (uint8_t *)&hmtp->rx_buff, len);
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
break;
case MTP_READ_DATA :
(void)USBD_MTP_STORAGE_ReadData(pdev);
/* prepare to receive next operation */
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
(void)USBD_LL_PrepareReceive(pdev, MTP_IN_EP, (uint8_t *)&hmtp->rx_buff, len);
(void)USBD_LL_PrepareReceive(pdev, MTPInEpAdd, (uint8_t *)&hmtp->rx_buff, len);
break;
case MTP_PHASE_IDLE :
/* prepare to receive next operation */
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
(void)USBD_LL_PrepareReceive(pdev, MTPOutEpAdd, (uint8_t *)&hmtp->rx_buff, len);
break;
default:
@@ -512,9 +511,14 @@ static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
{
UNUSED(epnum);
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
uint16_t len;
#ifdef USE_USBD_COMPOSITE
/* Get the Endpoints addresses allocated for this MTP class instance */
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK);
#endif /* USE_USBD_COMPOSITE */
(void)USBD_MTP_STORAGE_ReceiveOpt(pdev);
switch (hmtp->MTP_ResponsePhase)
@@ -542,14 +546,14 @@ static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
/* prepare endpoint to receive operations */
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
(void)USBD_LL_PrepareReceive(pdev, MTPOutEpAdd, (uint8_t *)&hmtp->rx_buff, len);
break;
case MTP_PHASE_IDLE :
/* prepare to receive next operation */
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
(void)USBD_LL_PrepareReceive(pdev, MTPOutEpAdd, (uint8_t *)&hmtp->rx_buff, len);
break;
default:
@@ -559,7 +563,7 @@ static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
return (uint8_t)USBD_OK;
}
#ifndef USE_USBD_COMPOSITE
/**
* @brief USBD_MTP_GetHSCfgDesc
* Return configuration descriptor
@@ -569,8 +573,27 @@ static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
*/
static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length)
{
*length = (uint16_t)sizeof(USBD_MTP_CfgHSDesc);
return USBD_MTP_CfgHSDesc;
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_IN_EP);
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_OUT_EP);
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_CMD_EP);
if (pEpInDesc != NULL)
{
pEpInDesc->wMaxPacketSize = MTP_DATA_MAX_HS_PACKET_SIZE;
}
if (pEpOutDesc != NULL)
{
pEpOutDesc->wMaxPacketSize = MTP_DATA_MAX_HS_PACKET_SIZE;
}
if (pEpCmdDesc != NULL)
{
pEpCmdDesc->bInterval = MTP_HS_BINTERVAL;
}
*length = (uint16_t)sizeof(USBD_MTP_CfgDesc);
return USBD_MTP_CfgDesc;
}
/**
@@ -582,8 +605,27 @@ static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length)
*/
static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length)
{
*length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc);
return USBD_MTP_CfgFSDesc;
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_IN_EP);
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_OUT_EP);
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_CMD_EP);
if (pEpInDesc != NULL)
{
pEpInDesc->wMaxPacketSize = MTP_DATA_MAX_FS_PACKET_SIZE;
}
if (pEpOutDesc != NULL)
{
pEpOutDesc->wMaxPacketSize = MTP_DATA_MAX_FS_PACKET_SIZE;
}
if (pEpCmdDesc != NULL)
{
pEpCmdDesc->bInterval = MTP_FS_BINTERVAL;
}
*length = (uint16_t)sizeof(USBD_MTP_CfgDesc);
return USBD_MTP_CfgDesc;
}
/**
@@ -595,8 +637,27 @@ static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length)
*/
static uint8_t *USBD_MTP_GetOtherSpeedCfgDesc(uint16_t *length)
{
*length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc);
return USBD_MTP_CfgFSDesc;
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_IN_EP);
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_OUT_EP);
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_CMD_EP);
if (pEpInDesc != NULL)
{
pEpInDesc->wMaxPacketSize = MTP_DATA_MAX_FS_PACKET_SIZE;
}
if (pEpOutDesc != NULL)
{
pEpOutDesc->wMaxPacketSize = MTP_DATA_MAX_FS_PACKET_SIZE;
}
if (pEpCmdDesc != NULL)
{
pEpCmdDesc->bInterval = MTP_FS_BINTERVAL;
}
*length = (uint16_t)sizeof(USBD_MTP_CfgDesc);
return USBD_MTP_CfgDesc;
}
/**
@@ -610,6 +671,7 @@ static uint8_t *USBD_MTP_GetDeviceQualifierDescriptor(uint16_t *length)
*length = (uint16_t)(sizeof(USBD_MTP_DeviceQualifierDesc));
return USBD_MTP_DeviceQualifierDesc;
}
#endif /* USE_USBD_COMPOSITE */
/**
* @brief USBD_MTP_RegisterInterface
@@ -624,7 +686,7 @@ uint8_t USBD_MTP_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_MTP_ItfTypeDef
return (uint8_t)USBD_FAIL;
}
pdev->pUserData = fops;
pdev->pUserData[pdev->classId] = fops;
return (uint8_t)USBD_OK;
}