mirror of
https://github.com/STMicroelectronics/stm32-mw-usb-device.git
synced 2026-02-09 04:25:36 -05:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a0a3521ac | ||
|
|
0b06460a43 | ||
|
|
7b5e6886d2 | ||
|
|
bd79085c18 | ||
|
|
dccc30a45a | ||
|
|
2022e75b01 | ||
|
|
555ce2b1f7 | ||
|
|
69fa8a86ad |
@@ -57,7 +57,10 @@ extern "C" {
|
|||||||
#define AUDIO_FS_BINTERVAL 0x01U
|
#define AUDIO_FS_BINTERVAL 0x01U
|
||||||
#endif /* AUDIO_FS_BINTERVAL */
|
#endif /* AUDIO_FS_BINTERVAL */
|
||||||
|
|
||||||
|
#ifndef AUDIO_OUT_EP
|
||||||
#define AUDIO_OUT_EP 0x01U
|
#define AUDIO_OUT_EP 0x01U
|
||||||
|
#endif /* AUDIO_OUT_EP */
|
||||||
|
|
||||||
#define USB_AUDIO_CONFIG_DESC_SIZ 0x6DU
|
#define USB_AUDIO_CONFIG_DESC_SIZ 0x6DU
|
||||||
#define AUDIO_INTERFACE_DESC_SIZE 0x09U
|
#define AUDIO_INTERFACE_DESC_SIZE 0x09U
|
||||||
#define USB_AUDIO_DESC_SIZ 0x09U
|
#define USB_AUDIO_DESC_SIZ 0x09U
|
||||||
@@ -166,6 +169,115 @@ typedef struct
|
|||||||
int8_t (*PeriodicTC)(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
int8_t (*PeriodicTC)(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||||
int8_t (*GetState)(void);
|
int8_t (*GetState)(void);
|
||||||
} USBD_AUDIO_ItfTypeDef;
|
} USBD_AUDIO_ItfTypeDef;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Audio Class specification release 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Table 4-2: Class-Specific AC Interface Header Descriptor */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint16_t bcdADC;
|
||||||
|
uint16_t wTotalLength;
|
||||||
|
uint8_t bInCollection;
|
||||||
|
uint8_t baInterfaceNr;
|
||||||
|
} __PACKED USBD_SpeakerIfDescTypeDef;
|
||||||
|
|
||||||
|
/* Table 4-3: Input Terminal Descriptor */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bTerminalID;
|
||||||
|
uint16_t wTerminalType;
|
||||||
|
uint8_t bAssocTerminal;
|
||||||
|
uint8_t bNrChannels;
|
||||||
|
uint16_t wChannelConfig;
|
||||||
|
uint8_t iChannelNames;
|
||||||
|
uint8_t iTerminal;
|
||||||
|
} __PACKED USBD_SpeakerInDescTypeDef;
|
||||||
|
|
||||||
|
/* USB Speaker Audio Feature Unit Descriptor */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bUnitID;
|
||||||
|
uint8_t bSourceID;
|
||||||
|
uint8_t bControlSize;
|
||||||
|
uint16_t bmaControls;
|
||||||
|
uint8_t iTerminal;
|
||||||
|
} __PACKED USBD_SpeakerFeatureDescTypeDef;
|
||||||
|
|
||||||
|
/* Table 4-4: Output Terminal Descriptor */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bTerminalID;
|
||||||
|
uint16_t wTerminalType;
|
||||||
|
uint8_t bAssocTerminal;
|
||||||
|
uint8_t bSourceID;
|
||||||
|
uint8_t iTerminal;
|
||||||
|
} __PACKED USBD_SpeakerOutDescTypeDef;
|
||||||
|
|
||||||
|
/* Table 4-19: Class-Specific AS Interface Descriptor */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bTerminalLink;
|
||||||
|
uint8_t bDelay;
|
||||||
|
uint16_t wFormatTag;
|
||||||
|
} __PACKED USBD_SpeakerStreamIfDescTypeDef;
|
||||||
|
|
||||||
|
/* USB Speaker Audio Type III Format Interface Descriptor */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bFormatType;
|
||||||
|
uint8_t bNrChannels;
|
||||||
|
uint8_t bSubFrameSize;
|
||||||
|
uint8_t bBitResolution;
|
||||||
|
uint8_t bSamFreqType;
|
||||||
|
uint8_t tSamFreq2;
|
||||||
|
uint8_t tSamFreq1;
|
||||||
|
uint8_t tSamFreq0;
|
||||||
|
} USBD_SpeakerIIIFormatIfDescTypeDef;
|
||||||
|
|
||||||
|
/* Table 4-17: Standard AC Interrupt Endpoint Descriptor */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bEndpointAddress;
|
||||||
|
uint8_t bmAttributes;
|
||||||
|
uint16_t wMaxPacketSize;
|
||||||
|
uint8_t bInterval;
|
||||||
|
uint8_t bRefresh;
|
||||||
|
uint8_t bSynchAddress;
|
||||||
|
} __PACKED USBD_SpeakerEndDescTypeDef;
|
||||||
|
|
||||||
|
/* Table 4-21: Class-Specific AS Isochronous Audio Data Endpoint Descriptor */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptor;
|
||||||
|
uint8_t bmAttributes;
|
||||||
|
uint8_t bLockDelayUnits;
|
||||||
|
uint16_t wLockDelay;
|
||||||
|
} __PACKED USBD_SpeakerEndStDescTypeDef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -197,6 +309,11 @@ uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
|||||||
USBD_AUDIO_ItfTypeDef *fops);
|
USBD_AUDIO_ItfTypeDef *fops);
|
||||||
|
|
||||||
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint32_t USBD_AUDIO_GetEpPcktSze(USBD_HandleTypeDef *pdev, uint8_t If, uint8_t Ep);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -99,6 +99,9 @@ EndBSPDependencies */
|
|||||||
#define AUDIO_PACKET_SZE(frq) \
|
#define AUDIO_PACKET_SZE(frq) \
|
||||||
(uint8_t)(((frq * 2U * 2U) / 1000U) & 0xFFU), (uint8_t)((((frq * 2U * 2U) / 1000U) >> 8) & 0xFFU)
|
(uint8_t)(((frq * 2U * 2U) / 1000U) & 0xFFU), (uint8_t)((((frq * 2U * 2U) / 1000U) >> 8) & 0xFFU)
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
#define AUDIO_PACKET_SZE_WORD(frq) (uint32_t)((((frq) * 2U * 2U)/1000U))
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -112,9 +115,10 @@ static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
|||||||
|
|
||||||
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req);
|
USBD_SetupReqTypedef *req);
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length);
|
static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length);
|
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
@@ -125,6 +129,7 @@ static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnu
|
|||||||
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
static void *USBD_AUDIO_GetAudioHeaderDesc(uint8_t *pConfDesc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -146,12 +151,20 @@ USBD_ClassTypeDef USBD_AUDIO =
|
|||||||
USBD_AUDIO_SOF,
|
USBD_AUDIO_SOF,
|
||||||
USBD_AUDIO_IsoINIncomplete,
|
USBD_AUDIO_IsoINIncomplete,
|
||||||
USBD_AUDIO_IsoOutIncomplete,
|
USBD_AUDIO_IsoOutIncomplete,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_AUDIO_GetCfgDesc,
|
USBD_AUDIO_GetCfgDesc,
|
||||||
USBD_AUDIO_GetCfgDesc,
|
USBD_AUDIO_GetCfgDesc,
|
||||||
USBD_AUDIO_GetCfgDesc,
|
USBD_AUDIO_GetCfgDesc,
|
||||||
USBD_AUDIO_GetDeviceQualifierDesc,
|
USBD_AUDIO_GetDeviceQualifierDesc,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB AUDIO device Configuration Descriptor */
|
/* USB AUDIO device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -167,7 +180,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
|||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
/* 09 byte*/
|
/* 09 byte*/
|
||||||
|
|
||||||
@@ -318,7 +331,9 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIE
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
static uint8_t AUDIOOutEpAdd = AUDIO_OUT_EP;
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -344,24 +359,30 @@ static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
if (haudio == NULL)
|
if (haudio == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pClassData = (void *)haudio;
|
pdev->pClassDataCmsit[pdev->classId] = (void *)haudio;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
AUDIOOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_ISOC, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].bInterval = AUDIO_HS_BINTERVAL;
|
pdev->ep_out[AUDIOOutEpAdd & 0xFU].bInterval = AUDIO_HS_BINTERVAL;
|
||||||
}
|
}
|
||||||
else /* LOW and FULL-speed endpoints */
|
else /* LOW and FULL-speed endpoints */
|
||||||
{
|
{
|
||||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].bInterval = AUDIO_FS_BINTERVAL;
|
pdev->ep_out[AUDIOOutEpAdd & 0xFU].bInterval = AUDIO_FS_BINTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, AUDIO_OUT_EP, USBD_EP_TYPE_ISOC, AUDIO_OUT_PACKET);
|
(void)USBD_LL_OpenEP(pdev, AUDIOOutEpAdd, USBD_EP_TYPE_ISOC, AUDIO_OUT_PACKET);
|
||||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[AUDIOOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
haudio->alt_setting = 0U;
|
haudio->alt_setting = 0U;
|
||||||
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
||||||
@@ -370,15 +391,15 @@ static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
haudio->rd_enable = 0U;
|
haudio->rd_enable = 0U;
|
||||||
|
|
||||||
/* Initialize the Audio output Hardware layer */
|
/* Initialize the Audio output Hardware layer */
|
||||||
if (((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->Init(USBD_AUDIO_FREQ,
|
if (((USBD_AUDIO_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init(USBD_AUDIO_FREQ,
|
||||||
AUDIO_DEFAULT_VOLUME,
|
AUDIO_DEFAULT_VOLUME,
|
||||||
0U) != 0U)
|
0U) != 0U)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive 1st packet */
|
/* Prepare Out endpoint to receive 1st packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, haudio->buffer,
|
(void)USBD_LL_PrepareReceive(pdev, AUDIOOutEpAdd, haudio->buffer,
|
||||||
AUDIO_OUT_PACKET);
|
AUDIO_OUT_PACKET);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
@@ -395,16 +416,22 @@ static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
AUDIOOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_ISOC, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_CloseEP(pdev, AUDIO_OUT_EP);
|
(void)USBD_LL_CloseEP(pdev, AUDIOOutEpAdd);
|
||||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 0U;
|
pdev->ep_out[AUDIOOutEpAdd & 0xFU].is_used = 0U;
|
||||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].bInterval = 0U;
|
pdev->ep_out[AUDIOOutEpAdd & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if (pdev->pClassData != NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
{
|
{
|
||||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0U);
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit(0U);
|
||||||
(void)USBD_free(pdev->pClassData);
|
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,7 +454,7 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (haudio == NULL)
|
if (haudio == NULL)
|
||||||
{
|
{
|
||||||
@@ -472,10 +499,17 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
case USB_REQ_GET_DESCRIPTOR:
|
case USB_REQ_GET_DESCRIPTOR:
|
||||||
if ((req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
if ((req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
||||||
{
|
{
|
||||||
pbuf = USBD_AUDIO_CfgDesc + 18;
|
pbuf = (uint8_t *)USBD_AUDIO_GetAudioHeaderDesc(pdev->pConfDesc);
|
||||||
len = MIN(USB_AUDIO_DESC_SIZ, req->wLength);
|
if (pbuf != NULL)
|
||||||
|
{
|
||||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
len = MIN(USB_AUDIO_DESC_SIZ, req->wLength);
|
||||||
|
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -530,7 +564,7 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)ret;
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_AUDIO_GetCfgDesc
|
* @brief USBD_AUDIO_GetCfgDesc
|
||||||
* return configuration descriptor
|
* return configuration descriptor
|
||||||
@@ -543,7 +577,7 @@ static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_AUDIO_CfgDesc;
|
return USBD_AUDIO_CfgDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @brief USBD_AUDIO_DataIn
|
* @brief USBD_AUDIO_DataIn
|
||||||
* handle data IN Stage
|
* handle data IN Stage
|
||||||
@@ -569,7 +603,7 @@ static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (haudio == NULL)
|
if (haudio == NULL)
|
||||||
{
|
{
|
||||||
@@ -582,7 +616,7 @@ static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (haudio->control.unit == AUDIO_OUT_STREAMING_CTRL)
|
if (haudio->control.unit == AUDIO_OUT_STREAMING_CTRL)
|
||||||
{
|
{
|
||||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->MuteCtl(haudio->control.data[0]);
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData[pdev->classId])->MuteCtl(haudio->control.data[0]);
|
||||||
haudio->control.cmd = 0U;
|
haudio->control.cmd = 0U;
|
||||||
haudio->control.len = 0U;
|
haudio->control.len = 0U;
|
||||||
}
|
}
|
||||||
@@ -628,12 +662,12 @@ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
|||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
uint32_t BufferSize = AUDIO_TOTAL_BUF_SIZE / 2U;
|
uint32_t BufferSize = AUDIO_TOTAL_BUF_SIZE / 2U;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
haudio->offset = offset;
|
haudio->offset = offset;
|
||||||
|
|
||||||
@@ -679,8 +713,8 @@ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
|||||||
|
|
||||||
if (haudio->offset == AUDIO_OFFSET_FULL)
|
if (haudio->offset == AUDIO_OFFSET_FULL)
|
||||||
{
|
{
|
||||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData[pdev->classId])->AudioCmd(&haudio->buffer[0],
|
||||||
BufferSize, AUDIO_CMD_PLAY);
|
BufferSize, AUDIO_CMD_PLAY);
|
||||||
haudio->offset = AUDIO_OFFSET_NONE;
|
haudio->offset = AUDIO_OFFSET_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -708,8 +742,19 @@ static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnu
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
UNUSED(pdev);
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
UNUSED(epnum);
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
/* Prepare Out endpoint to receive next audio packet */
|
||||||
|
(void)USBD_LL_PrepareReceive(pdev, epnum,
|
||||||
|
&haudio->buffer[haudio->wr_ptr],
|
||||||
|
AUDIO_OUT_PACKET);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -725,35 +770,40 @@ static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
uint16_t PacketSize;
|
uint16_t PacketSize;
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
|
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
AUDIOOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_ISOC, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (haudio == NULL)
|
if (haudio == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (epnum == AUDIO_OUT_EP)
|
if (epnum == AUDIOOutEpAdd)
|
||||||
{
|
{
|
||||||
/* Get received data packet length */
|
/* Get received data packet length */
|
||||||
PacketSize = (uint16_t)USBD_LL_GetRxDataSize(pdev, epnum);
|
PacketSize = (uint16_t)USBD_LL_GetRxDataSize(pdev, epnum);
|
||||||
|
|
||||||
/* Packet received Callback */
|
/* Packet received Callback */
|
||||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->PeriodicTC(&haudio->buffer[haudio->wr_ptr],
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData[pdev->classId])->PeriodicTC(&haudio->buffer[haudio->wr_ptr],
|
||||||
PacketSize, AUDIO_OUT_TC);
|
PacketSize, AUDIO_OUT_TC);
|
||||||
|
|
||||||
/* Increment the Buffer pointer or roll it back when all buffers are full */
|
/* Increment the Buffer pointer or roll it back when all buffers are full */
|
||||||
haudio->wr_ptr += PacketSize;
|
haudio->wr_ptr += PacketSize;
|
||||||
|
|
||||||
if (haudio->wr_ptr == AUDIO_TOTAL_BUF_SIZE)
|
if (haudio->wr_ptr >= AUDIO_TOTAL_BUF_SIZE)
|
||||||
{
|
{
|
||||||
/* All buffers are full: roll back */
|
/* All buffers are full: roll back */
|
||||||
haudio->wr_ptr = 0U;
|
haudio->wr_ptr = 0U;
|
||||||
|
|
||||||
if (haudio->offset == AUDIO_OFFSET_UNKNOWN)
|
if (haudio->offset == AUDIO_OFFSET_UNKNOWN)
|
||||||
{
|
{
|
||||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData[pdev->classId])->AudioCmd(&haudio->buffer[0],
|
||||||
AUDIO_TOTAL_BUF_SIZE / 2U,
|
AUDIO_TOTAL_BUF_SIZE / 2U,
|
||||||
AUDIO_CMD_START);
|
AUDIO_CMD_START);
|
||||||
haudio->offset = AUDIO_OFFSET_NONE;
|
haudio->offset = AUDIO_OFFSET_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -767,7 +817,7 @@ static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive next audio packet */
|
/* Prepare Out endpoint to receive next audio packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP,
|
(void)USBD_LL_PrepareReceive(pdev, AUDIOOutEpAdd,
|
||||||
&haudio->buffer[haudio->wr_ptr],
|
&haudio->buffer[haudio->wr_ptr],
|
||||||
AUDIO_OUT_PACKET);
|
AUDIO_OUT_PACKET);
|
||||||
}
|
}
|
||||||
@@ -785,7 +835,7 @@ static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (haudio == NULL)
|
if (haudio == NULL)
|
||||||
{
|
{
|
||||||
@@ -809,7 +859,7 @@ static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (haudio == NULL)
|
if (haudio == NULL)
|
||||||
{
|
{
|
||||||
@@ -827,7 +877,7 @@ static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
@@ -840,7 +890,7 @@ static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_AUDIO_DeviceQualifierDesc;
|
return USBD_AUDIO_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @brief USBD_AUDIO_RegisterInterface
|
* @brief USBD_AUDIO_RegisterInterface
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
@@ -855,10 +905,66 @@ uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/**
|
||||||
|
* @brief USBD_AUDIO_GetEpPcktSze
|
||||||
|
* @param pdev: device instance (reserved for future use)
|
||||||
|
* @param If: Interface number (reserved for future use)
|
||||||
|
* @param Ep: Endpoint number (reserved for future use)
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
uint32_t USBD_AUDIO_GetEpPcktSze(USBD_HandleTypeDef *pdev, uint8_t If, uint8_t Ep)
|
||||||
|
{
|
||||||
|
uint32_t mps;
|
||||||
|
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(If);
|
||||||
|
UNUSED(Ep);
|
||||||
|
|
||||||
|
mps = AUDIO_PACKET_SZE_WORD(USBD_AUDIO_FREQ);
|
||||||
|
|
||||||
|
/* Return the wMaxPacketSize value in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
|
||||||
|
return mps;
|
||||||
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_AUDIO_GetAudioHeaderDesc
|
||||||
|
* This function return the Audio descriptor
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param pConfDesc: pointer to Bos descriptor
|
||||||
|
* @retval pointer to the Audio AC Header descriptor
|
||||||
|
*/
|
||||||
|
static void *USBD_AUDIO_GetAudioHeaderDesc(uint8_t *pConfDesc)
|
||||||
|
{
|
||||||
|
USBD_ConfigDescTypeDef *desc = (USBD_ConfigDescTypeDef *)(void *)pConfDesc;
|
||||||
|
USBD_DescHeaderTypeDef *pdesc = (USBD_DescHeaderTypeDef *)(void *)pConfDesc;
|
||||||
|
uint8_t *pAudioDesc = 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 == AUDIO_INTERFACE_DESCRIPTOR_TYPE) &&
|
||||||
|
(pdesc->bDescriptorSubType == AUDIO_CONTROL_HEADER))
|
||||||
|
{
|
||||||
|
pAudioDesc = (uint8_t *)pdesc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pAudioDesc;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ extern USBD_ClassTypeDef USBD_BB;
|
|||||||
#if (USBD_CLASS_BOS_ENABLED == 1)
|
#if (USBD_CLASS_BOS_ENABLED == 1)
|
||||||
void *USBD_BB_GetCapDesc(USBD_HandleTypeDef *pdev, uint8_t *buf);
|
void *USBD_BB_GetCapDesc(USBD_HandleTypeDef *pdev, uint8_t *buf);
|
||||||
void *USBD_BB_GetAltModeDesc(USBD_HandleTypeDef *pdev, uint8_t *buf, uint8_t idx);
|
void *USBD_BB_GetAltModeDesc(USBD_HandleTypeDef *pdev, uint8_t *buf, uint8_t idx);
|
||||||
#endif
|
#endif /* (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ static uint8_t *USBD_BB_GetOtherSpeedCfgDesc(uint16_t *length);
|
|||||||
|
|
||||||
#if (USBD_CLASS_BOS_ENABLED == 1)
|
#if (USBD_CLASS_BOS_ENABLED == 1)
|
||||||
USBD_BB_DescHeader_t *USBD_BB_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
|
USBD_BB_DescHeader_t *USBD_BB_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
|
||||||
#endif
|
#endif /* USBD_CLASS_BOS_ENABLED */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ USBD_ClassTypeDef USBD_BB =
|
|||||||
USBD_BB_GetDeviceQualifierDesc,
|
USBD_BB_GetDeviceQualifierDesc,
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
NULL,
|
NULL,
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* USB Standard Device Qualifier Descriptor */
|
/* USB Standard Device Qualifier Descriptor */
|
||||||
@@ -154,7 +154,7 @@ __ALIGN_BEGIN static uint8_t USBD_BB_CfgDesc[USB_BB_CONFIG_DESC_SIZ] __ALIGN_EN
|
|||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
/* 09 */
|
/* 09 */
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ __ALIGN_BEGIN static uint8_t USBD_BB_OtherSpeedCfgDesc[USB_BB_CONFIG_DESC_SIZ]
|
|||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
/************** Descriptor of BillBoard interface ****************/
|
/************** Descriptor of BillBoard interface ****************/
|
||||||
@@ -420,7 +420,7 @@ void *USBD_BB_GetCapDesc(USBD_HandleTypeDef *pdev, uint8_t *pBosDesc)
|
|||||||
UNUSED(pdev);
|
UNUSED(pdev);
|
||||||
|
|
||||||
USBD_BB_DescHeader_t *pdesc = (USBD_BB_DescHeader_t *)(void *)pBosDesc;
|
USBD_BB_DescHeader_t *pdesc = (USBD_BB_DescHeader_t *)(void *)pBosDesc;
|
||||||
USBD_BosDescTypedef *desc = (USBD_BosDescTypedef *)(void *)pBosDesc;
|
USBD_BosDescTypeDef *desc = (USBD_BosDescTypeDef *)(void *)pBosDesc;
|
||||||
USBD_BosBBCapDescTypedef *pCapDesc = NULL;
|
USBD_BosBBCapDescTypedef *pCapDesc = NULL;
|
||||||
uint16_t ptr;
|
uint16_t ptr;
|
||||||
|
|
||||||
@@ -456,7 +456,7 @@ void *USBD_BB_GetAltModeDesc(USBD_HandleTypeDef *pdev, uint8_t *pBosDesc, uint8_
|
|||||||
UNUSED(pdev);
|
UNUSED(pdev);
|
||||||
|
|
||||||
USBD_BB_DescHeader_t *pdesc = (USBD_BB_DescHeader_t *)(void *)pBosDesc;
|
USBD_BB_DescHeader_t *pdesc = (USBD_BB_DescHeader_t *)(void *)pBosDesc;
|
||||||
USBD_BosDescTypedef *desc = (USBD_BosDescTypedef *)(void *)pBosDesc;
|
USBD_BosDescTypeDef *desc = (USBD_BosDescTypeDef *)(void *)pBosDesc;
|
||||||
USBD_BB_AltModeCapDescTypeDef *pAltModDesc = NULL;
|
USBD_BB_AltModeCapDescTypeDef *pAltModDesc = NULL;
|
||||||
uint8_t cnt = 0U;
|
uint8_t cnt = 0U;
|
||||||
uint16_t ptr;
|
uint16_t ptr;
|
||||||
@@ -485,7 +485,7 @@ void *USBD_BB_GetAltModeDesc(USBD_HandleTypeDef *pdev, uint8_t *pBosDesc, uint8_
|
|||||||
}
|
}
|
||||||
return (void *)pAltModDesc;
|
return (void *)pAltModDesc;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* USBD_CLASS_BOS_ENABLED */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -60,10 +60,12 @@ extern "C" {
|
|||||||
#define CCID_CMD_FS_BINTERVAL 0x10U
|
#define CCID_CMD_FS_BINTERVAL 0x10U
|
||||||
#endif /* CCID_CMD_FS_BINTERVAL */
|
#endif /* CCID_CMD_FS_BINTERVAL */
|
||||||
|
|
||||||
|
#ifndef CCID_CMD_PACKET_SIZE
|
||||||
|
#define CCID_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
||||||
|
#endif /* CCID_CMD_PACKET_SIZE */
|
||||||
|
|
||||||
#define CCID_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
#define CCID_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
||||||
#define CCID_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
#define CCID_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||||
#define CCID_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
|
||||||
|
|
||||||
#define USB_CCID_CONFIG_DESC_SIZ 93U
|
#define USB_CCID_CONFIG_DESC_SIZ 93U
|
||||||
#define CCID_DATA_HS_IN_PACKET_SIZE CCID_DATA_HS_MAX_PACKET_SIZE
|
#define CCID_DATA_HS_IN_PACKET_SIZE CCID_DATA_HS_MAX_PACKET_SIZE
|
||||||
@@ -101,28 +103,28 @@ extern "C" {
|
|||||||
|
|
||||||
#ifndef CCID_VOLTAGE_SUPP
|
#ifndef CCID_VOLTAGE_SUPP
|
||||||
#define CCID_VOLTAGE_SUPP 0x07U
|
#define CCID_VOLTAGE_SUPP 0x07U
|
||||||
#endif
|
#endif /* CCID_VOLTAGE_SUPP */
|
||||||
#ifndef USBD_CCID_PROTOCOL
|
#ifndef USBD_CCID_PROTOCOL
|
||||||
#define USBD_CCID_PROTOCOL 0x03U
|
#define USBD_CCID_PROTOCOL 0x03U
|
||||||
#endif
|
#endif /* USBD_CCID_PROTOCOL */
|
||||||
#ifndef USBD_CCID_DEFAULT_CLOCK_FREQ
|
#ifndef USBD_CCID_DEFAULT_CLOCK_FREQ
|
||||||
#define USBD_CCID_DEFAULT_CLOCK_FREQ 3600U
|
#define USBD_CCID_DEFAULT_CLOCK_FREQ 3600U
|
||||||
#endif
|
#endif /* USBD_CCID_DEFAULT_CLOCK_FREQ */
|
||||||
#ifndef USBD_CCID_MAX_CLOCK_FREQ
|
#ifndef USBD_CCID_MAX_CLOCK_FREQ
|
||||||
#define USBD_CCID_MAX_CLOCK_FREQ USBD_CCID_DEFAULT_CLOCK_FREQ
|
#define USBD_CCID_MAX_CLOCK_FREQ USBD_CCID_DEFAULT_CLOCK_FREQ
|
||||||
#endif
|
#endif /* USBD_CCID_MAX_CLOCK_FREQ */
|
||||||
#ifndef USBD_CCID_DEFAULT_DATA_RATE
|
#ifndef USBD_CCID_DEFAULT_DATA_RATE
|
||||||
#define USBD_CCID_DEFAULT_DATA_RATE 9677U
|
#define USBD_CCID_DEFAULT_DATA_RATE 9677U
|
||||||
#endif
|
#endif /* USBD_CCID_DEFAULT_DATA_RATE */
|
||||||
#ifndef USBD_CCID_MAX_DATA_RATE
|
#ifndef USBD_CCID_MAX_DATA_RATE
|
||||||
#define USBD_CCID_MAX_DATA_RATE USBD_CCID_DEFAULT_DATA_RATE
|
#define USBD_CCID_MAX_DATA_RATE USBD_CCID_DEFAULT_DATA_RATE
|
||||||
#endif
|
#endif /* USBD_CCID_MAX_DATA_RATE */
|
||||||
#ifndef USBD_CCID_MAX_INF_FIELD_SIZE
|
#ifndef USBD_CCID_MAX_INF_FIELD_SIZE
|
||||||
#define USBD_CCID_MAX_INF_FIELD_SIZE 254U
|
#define USBD_CCID_MAX_INF_FIELD_SIZE 254U
|
||||||
#endif
|
#endif /* USBD_CCID_MAX_INF_FIELD_SIZE */
|
||||||
#ifndef CCID_MAX_BLOCK_SIZE_HEADER
|
#ifndef CCID_MAX_BLOCK_SIZE_HEADER
|
||||||
#define CCID_MAX_BLOCK_SIZE_HEADER 271U
|
#define CCID_MAX_BLOCK_SIZE_HEADER 271U
|
||||||
#endif
|
#endif /* CCID_MAX_BLOCK_SIZE_HEADER */
|
||||||
|
|
||||||
#define TPDU_EXCHANGE 0x01U
|
#define TPDU_EXCHANGE 0x01U
|
||||||
#define SHORT_APDU_EXCHANGE 0x02U
|
#define SHORT_APDU_EXCHANGE 0x02U
|
||||||
@@ -131,20 +133,24 @@ extern "C" {
|
|||||||
|
|
||||||
#ifndef EXCHANGE_LEVEL_FEATURE
|
#ifndef EXCHANGE_LEVEL_FEATURE
|
||||||
#define EXCHANGE_LEVEL_FEATURE TPDU_EXCHANGE
|
#define EXCHANGE_LEVEL_FEATURE TPDU_EXCHANGE
|
||||||
#endif
|
#endif /* EXCHANGE_LEVEL_FEATURE */
|
||||||
|
|
||||||
#define CCID_ENDPOINT_DESC_SIZE 0x07U
|
#define CCID_ENDPOINT_DESC_SIZE 0x07U
|
||||||
|
|
||||||
#ifndef CCID_EP0_BUFF_SIZ
|
#ifndef CCID_EP0_BUFF_SIZ
|
||||||
#define CCID_EP0_BUFF_SIZ 64U
|
#define CCID_EP0_BUFF_SIZ 64U
|
||||||
#endif
|
#endif /* CCID_EP0_BUFF_SIZ */
|
||||||
|
|
||||||
#ifndef CCID_BULK_EPIN_SIZE
|
#ifndef CCID_BULK_EPIN_SIZE
|
||||||
#define CCID_BULK_EPIN_SIZE 64U
|
#define CCID_BULK_EPIN_SIZE 64U
|
||||||
#endif
|
#endif /* CCID_BULK_EPIN_SIZE */
|
||||||
|
|
||||||
#define CCID_INT_BUFF_SIZ 2U
|
#define CCID_INT_BUFF_SIZ 2U
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* CCID Class specification revision 1.1
|
||||||
|
* Command Pipe. Bulk Messages
|
||||||
|
*/
|
||||||
|
|
||||||
/* CCID Bulk Out Command definitions */
|
/* CCID Bulk Out Command definitions */
|
||||||
#define PC_TO_RDR_ICCPOWERON 0x62U
|
#define PC_TO_RDR_ICCPOWERON 0x62U
|
||||||
@@ -213,7 +219,6 @@ typedef struct
|
|||||||
uint8_t datatype;
|
uint8_t datatype;
|
||||||
} USBD_CCID_LineCodingTypeDef;
|
} USBD_CCID_LineCodingTypeDef;
|
||||||
|
|
||||||
#pragma pack(1)
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t bMessageType; /* Offset = 0*/
|
uint8_t bMessageType; /* Offset = 0*/
|
||||||
@@ -230,10 +235,8 @@ typedef struct
|
|||||||
or for a TPDU T=1 block is 259 bytes,
|
or for a TPDU T=1 block is 259 bytes,
|
||||||
or for a short APDU T=1 block is 261 bytes,
|
or for a short APDU T=1 block is 261 bytes,
|
||||||
or for an extended APDU T=1 block is 65544 bytes.*/
|
or for an extended APDU T=1 block is 65544 bytes.*/
|
||||||
} USBD_CCID_BulkOut_DataTypeDef;
|
} __PACKED USBD_CCID_BulkOut_DataTypeDef;
|
||||||
#pragma pack()
|
|
||||||
|
|
||||||
#pragma pack(1)
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t bMessageType; /* Offset = 0 */
|
uint8_t bMessageType; /* Offset = 0 */
|
||||||
@@ -245,8 +248,7 @@ typedef struct
|
|||||||
uint8_t bSpecific; /* Offset = 9 */
|
uint8_t bSpecific; /* Offset = 9 */
|
||||||
uint8_t abData[ABDATA_SIZE]; /* Offset = 10 */
|
uint8_t abData[ABDATA_SIZE]; /* Offset = 10 */
|
||||||
uint16_t u16SizeToSend;
|
uint16_t u16SizeToSend;
|
||||||
} USBD_CCID_BulkIn_DataTypeDef;
|
} __PACKED USBD_CCID_BulkIn_DataTypeDef;
|
||||||
#pragma pack()
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -262,6 +264,36 @@ typedef struct
|
|||||||
__IO uint8_t bSlot;
|
__IO uint8_t bSlot;
|
||||||
} USBD_CCID_ParamTypeDef;
|
} USBD_CCID_ParamTypeDef;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CCID Class specification revision 1.1
|
||||||
|
* Smart Card Device Class Descriptor Table
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint16_t bcdCCID;
|
||||||
|
uint8_t bMaxSlotIndex;
|
||||||
|
uint8_t bVoltageSupport;
|
||||||
|
uint32_t dwProtocols;
|
||||||
|
uint32_t dwDefaultClock;
|
||||||
|
uint32_t dwMaximumClock;
|
||||||
|
uint8_t bNumClockSupported;
|
||||||
|
uint32_t dwDataRate;
|
||||||
|
uint32_t dwMaxDataRate;
|
||||||
|
uint8_t bNumDataRatesSupported;
|
||||||
|
uint32_t dwMaxIFSD;
|
||||||
|
uint32_t dwSynchProtocols;
|
||||||
|
uint32_t dwMechanical;
|
||||||
|
uint32_t dwFeatures;
|
||||||
|
uint32_t dwMaxCCIDMessageLength;
|
||||||
|
uint8_t bClassGetResponse;
|
||||||
|
uint8_t bClassEnvelope;
|
||||||
|
uint16_t wLcdLayout;
|
||||||
|
uint8_t bPINSupport;
|
||||||
|
uint8_t bMaxCCIDBusySlots;
|
||||||
|
} __PACKED USBD_CCID_DescTypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ extern "C" {
|
|||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#ifndef __USBD_CCID_IF_H
|
#ifndef __USBD_CCID_IF_H
|
||||||
#include "usbd_ccid_if_template.h"
|
#include "usbd_ccid_if_template.h"
|
||||||
#endif
|
#endif /* __USBD_CCID_IF_H */
|
||||||
|
|
||||||
#ifndef __USBD_CCID_SC_IF_H
|
#ifndef __USBD_CCID_SC_IF_H
|
||||||
#include "usbd_ccid_sc_if_template.h"
|
#include "usbd_ccid_sc_if_template.h"
|
||||||
#endif
|
#endif /* __USBD_CCID_SC_IF_H */
|
||||||
|
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
@@ -54,6 +54,10 @@ extern "C" {
|
|||||||
positive number (1-127). For instance, if the CCID receives an ICC command to
|
positive number (1-127). For instance, if the CCID receives an ICC command to
|
||||||
an unimplemented slot, then the Slot Error register shall be set to 5 (index of bSlot field) */
|
an unimplemented slot, then the Slot Error register shall be set to 5 (index of bSlot field) */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CCID Class specification revision 1.1
|
||||||
|
*/
|
||||||
|
|
||||||
/* Following Parameters used in PC_to_RDR_XfrBlock */
|
/* Following Parameters used in PC_to_RDR_XfrBlock */
|
||||||
#define SLOTERROR_BAD_LENTGH 0x01U
|
#define SLOTERROR_BAD_LENTGH 0x01U
|
||||||
#define SLOTERROR_BAD_SLOT 0x05U
|
#define SLOTERROR_BAD_SLOT 0x05U
|
||||||
@@ -97,25 +101,25 @@ extern "C" {
|
|||||||
/* DEFAULT_FIDI_VALUE */
|
/* DEFAULT_FIDI_VALUE */
|
||||||
#ifndef DEFAULT_FIDI
|
#ifndef DEFAULT_FIDI
|
||||||
#define DEFAULT_FIDI 0x11U
|
#define DEFAULT_FIDI 0x11U
|
||||||
#endif
|
#endif /* DEFAULT_FIDI */
|
||||||
#ifndef DEFAULT_T01CONVCHECKSUM
|
#ifndef DEFAULT_T01CONVCHECKSUM
|
||||||
#define DEFAULT_T01CONVCHECKSUM 0x00U
|
#define DEFAULT_T01CONVCHECKSUM 0x00U
|
||||||
#endif
|
#endif /* DEFAULT_T01CONVCHECKSUM */
|
||||||
#ifndef DEFAULT_EXTRA_GUARDTIME
|
#ifndef DEFAULT_EXTRA_GUARDTIME
|
||||||
#define DEFAULT_EXTRA_GUARDTIME 0x00U
|
#define DEFAULT_EXTRA_GUARDTIME 0x00U
|
||||||
#endif
|
#endif /* DEFAULT_EXTRA_GUARDTIME */
|
||||||
#ifndef DEFAULT_WAITINGINTEGER
|
#ifndef DEFAULT_WAITINGINTEGER
|
||||||
#define DEFAULT_WAITINGINTEGER 0x0AU
|
#define DEFAULT_WAITINGINTEGER 0x0AU
|
||||||
#endif
|
#endif /* DEFAULT_WAITINGINTEGER */
|
||||||
#ifndef DEFAULT_CLOCKSTOP
|
#ifndef DEFAULT_CLOCKSTOP
|
||||||
#define DEFAULT_CLOCKSTOP 0x00U
|
#define DEFAULT_CLOCKSTOP 0x00U
|
||||||
#endif
|
#endif /* DEFAULT_CLOCKSTOP */
|
||||||
#ifndef DEFAULT_IFSC
|
#ifndef DEFAULT_IFSC
|
||||||
#define DEFAULT_IFSC 0x20U
|
#define DEFAULT_IFSC 0x20U
|
||||||
#endif
|
#endif /* DEFAULT_IFSC */
|
||||||
#ifndef DEFAULT_NAD
|
#ifndef DEFAULT_NAD
|
||||||
#define DEFAULT_NAD 0x00U
|
#define DEFAULT_NAD 0x00U
|
||||||
#endif
|
#endif /* DEFAULT_NAD */
|
||||||
|
|
||||||
/* Following Parameters used in PC_to_RDR_IccPowerOn */
|
/* Following Parameters used in PC_to_RDR_IccPowerOn */
|
||||||
#define VOLTAGE_SELECTION_AUTOMATIC 0xFFU
|
#define VOLTAGE_SELECTION_AUTOMATIC 0xFFU
|
||||||
@@ -151,10 +155,9 @@ Offset=6 bmCommandStatus 2 bits 0, 1, 2
|
|||||||
#define SIZE_OF_ATR 19U
|
#define SIZE_OF_ATR 19U
|
||||||
#else
|
#else
|
||||||
#define SIZE_OF_ATR 15U
|
#define SIZE_OF_ATR 15U
|
||||||
#endif
|
#endif /* (ATR_T01 == 0) */
|
||||||
|
|
||||||
/* defines for the CCID_CMD Layers */
|
/* defines for the CCID_CMD Layers */
|
||||||
#define LEN_RDR_TO_PC_SLOTSTATUS 10U
|
|
||||||
#define LEN_PROTOCOL_STRUCT_T0 5U
|
#define LEN_PROTOCOL_STRUCT_T0 5U
|
||||||
#define LEN_PROTOCOL_STRUCT_T1 7U
|
#define LEN_PROTOCOL_STRUCT_T1 7U
|
||||||
|
|
||||||
@@ -174,8 +177,8 @@ Offset=6 bmCommandStatus 2 bits 0, 1, 2
|
|||||||
|
|
||||||
#define CHK_PARAM_SLOT 0x01U
|
#define CHK_PARAM_SLOT 0x01U
|
||||||
#define CHK_PARAM_DWLENGTH 0x02U
|
#define CHK_PARAM_DWLENGTH 0x02U
|
||||||
#define CHK_PARAM_abRFU2 0x04U
|
#define CHK_PARAM_ABRFU2 0x04U
|
||||||
#define CHK_PARAM_abRFU3 0x08U
|
#define CHK_PARAM_ABRFU3 0x08U
|
||||||
#define CHK_PARAM_CARD_PRESENT 0x10U
|
#define CHK_PARAM_CARD_PRESENT 0x10U
|
||||||
#define CHK_PARAM_ABORT 0x20U
|
#define CHK_PARAM_ABORT 0x20U
|
||||||
#define CHK_ACTIVE_STATE 0x40U
|
#define CHK_ACTIVE_STATE 0x40U
|
||||||
@@ -207,7 +210,7 @@ void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef *
|
|||||||
void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus);
|
void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus);
|
||||||
void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus);
|
void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus);
|
||||||
uint8_t CCID_IsSlotStatusChange(USBD_HandleTypeDef *pdev);
|
uint8_t CCID_IsSlotStatusChange(USBD_HandleTypeDef *pdev);
|
||||||
uint8_t CCID_CmdAbort(uint8_t slot, uint8_t seq);
|
uint8_t CCID_CmdAbort(USBD_HandleTypeDef *pdev, uint8_t slot, uint8_t seq);
|
||||||
uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *dataPointer, uint16_t dataLen);
|
uint8_t *dataPointer, uint16_t dataLen);
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ extern "C" {
|
|||||||
|
|
||||||
#ifndef __USBD_CCID_SMARTCARD_H
|
#ifndef __USBD_CCID_SMARTCARD_H
|
||||||
#include "usbd_ccid_smartcard_template.h"
|
#include "usbd_ccid_smartcard_template.h"
|
||||||
#endif
|
#endif /* __USBD_CCID_SMARTCARD_H */
|
||||||
|
|
||||||
/* Exported defines ----------------------------------------------------------*/
|
/* Exported defines ----------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -49,11 +49,11 @@ extern "C" {
|
|||||||
#define BOTH_DIR 2U
|
#define BOTH_DIR 2U
|
||||||
|
|
||||||
/************ Value of the Interrupt transfer status to set ******************/
|
/************ Value of the Interrupt transfer status to set ******************/
|
||||||
#define IntrStatus_Complete 1U
|
#define INTRSTATUS_COMPLETE 1U
|
||||||
#define IntrStatus_Reset 0U
|
#define INTRSTATUS_RESET 0U
|
||||||
/************** slot change status *******************************************/
|
/************** slot change status *******************************************/
|
||||||
#define SlotStatus_Changed 1U
|
#define SLOTSTATUS_CHANGED 1U
|
||||||
#define SlotStatus_Reset 0U
|
#define SLOTSTATUS_RESET 0U
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
extern USBD_HandleTypeDef USBD_Device;
|
extern USBD_HandleTypeDef USBD_Device;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ extern "C" {
|
|||||||
|
|
||||||
#ifndef __USBD_CCID_SMARTCARD_H
|
#ifndef __USBD_CCID_SMARTCARD_H
|
||||||
#include "usbd_ccid_smartcard_template.h"
|
#include "usbd_ccid_smartcard_template.h"
|
||||||
#endif
|
#endif /* __USBD_CCID_SMARTCARD_H */
|
||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ extern "C" {
|
|||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#ifndef __USBD_CCID_IF_H
|
#ifndef __USBD_CCID_IF_H
|
||||||
#include "usbd_ccid_if_template.h"
|
#include "usbd_ccid_if_template.h"
|
||||||
#endif
|
#endif /* __USBD_CCID_IF_H */
|
||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
#define T0_PROTOCOL 0x00U /* T0 protocol */
|
#define T0_PROTOCOL 0x00U /* T0 protocol */
|
||||||
@@ -162,29 +162,29 @@ typedef enum
|
|||||||
/* Interface Byte structure - TA(i), TB(i), TC(i) and TD(i) ------------------*/
|
/* Interface Byte structure - TA(i), TB(i), TC(i) and TD(i) ------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t Status; /* The Presence of the Interface byte */
|
uint8_t Status; /* The Presence of the Interface byte */
|
||||||
uint8_t Value; /* The Value of the Interface byte */
|
uint8_t Value; /* The Value of the Interface byte */
|
||||||
} SC_InterfaceByte;
|
} SC_InterfaceByteTypeDef;
|
||||||
|
|
||||||
/* Protocol Level structure - ------------------------------------------------*/
|
/* Protocol Level structure - ------------------------------------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
SC_InterfaceByte InterfaceByte[MAX_INTERFACEBYTE]; /* The Values of the Interface byte TA(i), TB(i), TC(i)and TD(i) */
|
SC_InterfaceByteTypeDef InterfaceByte[MAX_INTERFACEBYTE]; /* The Values of the Interface byte
|
||||||
} SC_ProtocolLevel;
|
TA(i), TB(i), TC(i)and TD(i) */
|
||||||
|
} SC_ProtocolLevelTypeDef;
|
||||||
|
|
||||||
/* ATR structure - Answer To Reset -------------------------------------------*/
|
/* ATR structure - Answer To Reset -------------------------------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t TS; /* Bit Convention Direct/Indirect */
|
uint8_t TS; /* Bit Convention Direct/Indirect */
|
||||||
uint8_t T0; /* Each bit in the high nibble = Presence of the further interface byte;
|
uint8_t T0; /* Each bit in the high nibble = Presence of the further interface byte;
|
||||||
Low nibble = Number of historical byte */
|
Low nibble = Number of historical byte */
|
||||||
|
SC_ProtocolLevelTypeDef T[MAX_PROTOCOLLEVEL]; /* Setup array */
|
||||||
SC_ProtocolLevel T[MAX_PROTOCOLLEVEL]; /* Setup array */
|
uint8_t Historical[HIST_LENGTH]; /* Historical array */
|
||||||
uint8_t H[HIST_LENGTH]; /* Historical array */
|
uint8_t Tlength; /* Setup array dimension */
|
||||||
uint8_t Tlength; /* Setup array dimension */
|
uint8_t Hlength; /* Historical array dimension */
|
||||||
uint8_t Hlength; /* Historical array dimension */
|
|
||||||
uint8_t TCK;
|
uint8_t TCK;
|
||||||
} SC_ATR;
|
} SC_ATRTypeDef;
|
||||||
|
|
||||||
/* ADPU-Header command structure ---------------------------------------------*/
|
/* ADPU-Header command structure ---------------------------------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -193,7 +193,7 @@ typedef struct
|
|||||||
uint8_t INS; /* Operation code */
|
uint8_t INS; /* Operation code */
|
||||||
uint8_t P1; /* Selection Mode */
|
uint8_t P1; /* Selection Mode */
|
||||||
uint8_t P2; /* Selection Option */
|
uint8_t P2; /* Selection Option */
|
||||||
} SC_Header;
|
} SC_HeaderTypeDef;
|
||||||
|
|
||||||
/* ADPU-Body command structure -----------------------------------------------*/
|
/* ADPU-Body command structure -----------------------------------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -201,22 +201,22 @@ typedef struct
|
|||||||
uint8_t LC; /* Data field length */
|
uint8_t LC; /* Data field length */
|
||||||
uint8_t Data[LC_MAX]; /* Command parameters */
|
uint8_t Data[LC_MAX]; /* Command parameters */
|
||||||
uint8_t LE; /* Expected length of data to be returned */
|
uint8_t LE; /* Expected length of data to be returned */
|
||||||
} SC_Body;
|
} SC_BodyTypeDef;
|
||||||
|
|
||||||
/* ADPU Command structure ----------------------------------------------------*/
|
/* ADPU Command structure ----------------------------------------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
SC_Header Header;
|
SC_HeaderTypeDef Header;
|
||||||
SC_Body Body;
|
SC_BodyTypeDef Body;
|
||||||
} SC_ADPU_Commands;
|
} SC_ADPU_CommandsTypeDef;
|
||||||
|
|
||||||
/* SC response structure -----------------------------------------------------*/
|
/* SC response structure -----------------------------------------------------*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t Data[LC_MAX]; /* Data returned from the card */
|
uint8_t Data[LC_MAX]; /* Data returned from the card */
|
||||||
uint8_t SW1; /* Command Processing status */
|
uint8_t SW1; /* Command Processing status */
|
||||||
uint8_t SW2; /* Command Processing qualification */
|
uint8_t SW2; /* Command Processing qualification */
|
||||||
} SC_ADPU_Response;
|
} SC_ADPU_ResponseTypeDef;
|
||||||
|
|
||||||
/* SC Command Status -----------------------------------------------------*/
|
/* SC Command Status -----------------------------------------------------*/
|
||||||
typedef enum
|
typedef enum
|
||||||
@@ -255,7 +255,7 @@ typedef enum
|
|||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
/* APPLICATION LAYER ---------------------------------------------------------*/
|
/* APPLICATION LAYER ---------------------------------------------------------*/
|
||||||
void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Response *SC_Response);
|
void SC_Handler(SC_State *SCState, SC_ADPU_CommandsTypeDef *SC_ADPU, SC_ADPU_ResponseTypeDef *SC_Response);
|
||||||
void SC_PowerCmd(SCPowerState NewState);
|
void SC_PowerCmd(SCPowerState NewState);
|
||||||
void SC_ParityErrorHandler(void);
|
void SC_ParityErrorHandler(void);
|
||||||
void SC_PTSConfig(void);
|
void SC_PTSConfig(void);
|
||||||
@@ -266,11 +266,11 @@ void SC_SetState(SC_State scState);
|
|||||||
void SC_IOConfig(void);
|
void SC_IOConfig(void);
|
||||||
|
|
||||||
extern uint8_t SC_ATR_Table[40];
|
extern uint8_t SC_ATR_Table[40];
|
||||||
extern SC_ATR SC_A2R;
|
extern SC_ATRTypeDef SC_A2R;
|
||||||
extern SC_ADPU_Response SC_Response;
|
extern SC_ADPU_ResponseTypeDef SC_Response;
|
||||||
|
|
||||||
extern uint8_t ProtocolNUM_OUT;
|
extern uint8_t ProtocolNUM_OUT;
|
||||||
extern SC_ADPU_Commands SC_ADPU;
|
extern SC_ADPU_CommandsTypeDef SC_ADPU;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,11 +85,12 @@ static uint8_t USBD_CCID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
|||||||
static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev);
|
static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev);
|
||||||
static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pDst, uint16_t u8length);
|
uint8_t *pDst, uint16_t u8length);
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CCID_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CCID_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CCID_GetDeviceQualifierDescriptor(uint16_t *length);
|
static uint8_t *USBD_CCID_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -99,6 +100,10 @@ static uint8_t *USBD_CCID_GetDeviceQualifierDescriptor(uint16_t *length);
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static uint8_t CCIDInEpAdd = CCID_IN_EP;
|
||||||
|
static uint8_t CCIDOutEpAdd = CCID_OUT_EP;
|
||||||
|
static uint8_t CCIDCmdEpAdd = CCID_CMD_EP;
|
||||||
|
|
||||||
|
|
||||||
/* CCID interface class callbacks structure */
|
/* CCID interface class callbacks structure */
|
||||||
USBD_ClassTypeDef USBD_CCID =
|
USBD_ClassTypeDef USBD_CCID =
|
||||||
@@ -113,14 +118,23 @@ USBD_ClassTypeDef USBD_CCID =
|
|||||||
NULL, /*SOF */
|
NULL, /*SOF */
|
||||||
NULL, /*ISOIn*/
|
NULL, /*ISOIn*/
|
||||||
NULL, /*ISOOut*/
|
NULL, /*ISOOut*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_CCID_GetHSCfgDesc,
|
USBD_CCID_GetHSCfgDesc,
|
||||||
USBD_CCID_GetFSCfgDesc,
|
USBD_CCID_GetFSCfgDesc,
|
||||||
USBD_CCID_GetOtherSpeedCfgDesc,
|
USBD_CCID_GetOtherSpeedCfgDesc,
|
||||||
USBD_CCID_GetDeviceQualifierDescriptor,
|
USBD_CCID_GetDeviceQualifierDescriptor,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
|
||||||
/* USB CCID device Configuration Descriptor */
|
/* USB CCID device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CCID_CfgHSDesc[USB_CCID_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CCID_CfgDesc[USB_CCID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
/* Configuration Descriptor */
|
/* Configuration Descriptor */
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
@@ -134,7 +148,7 @@ __ALIGN_BEGIN static uint8_t USBD_CCID_CfgHSDesc[USB_CCID_CONFIG_DESC_SIZ] __ALI
|
|||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
/******************** CCID **** interface ********************/
|
/******************** CCID **** interface ********************/
|
||||||
@@ -144,112 +158,8 @@ __ALIGN_BEGIN static uint8_t USBD_CCID_CfgHSDesc[USB_CCID_CONFIG_DESC_SIZ] __ALI
|
|||||||
0x00, /* bAlternateSetting: Alternate setting */
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x03, /* bNumEndpoints: 3 endpoints used */
|
0x03, /* bNumEndpoints: 3 endpoints used */
|
||||||
USB_DEVICE_CLASS_CCID, /* bInterfaceClass: user's interface for CCID */
|
USB_DEVICE_CLASS_CCID, /* bInterfaceClass: user's interface for CCID */
|
||||||
0x00, /* bInterfaceSubClass : No subclass, can be changed but no description in USB 2.0 Spec */
|
0x00, /* bInterfaceSubClass : No subclass,
|
||||||
0x00, /* nInterfaceProtocol : None */
|
can be changed but no description in USB 2.0 Spec */
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/******************* CCID class descriptor ********************/
|
|
||||||
CCID_CLASS_DESC_SIZE, /* bLength: CCID Descriptor size */
|
|
||||||
CCID_DESC_TYPE, /* bDescriptorType: Functional Descriptor type. */
|
|
||||||
0x10, /* bcdCCID(LSB): CCID Class Spec release number (1.1) */
|
|
||||||
0x01, /* bcdCCID(MSB) */
|
|
||||||
|
|
||||||
0x00, /* bMaxSlotIndex :highest available slot on this device */
|
|
||||||
CCID_VOLTAGE_SUPP, /* bVoltageSupport: bVoltageSupport: 5v, 3v and 1.8v */
|
|
||||||
LOBYTE(USBD_CCID_PROTOCOL), /* dwProtocols: supports T=0 and T=1 */
|
|
||||||
HIBYTE(USBD_CCID_PROTOCOL),
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
LOBYTE(USBD_CCID_DEFAULT_CLOCK_FREQ), /* dwDefaultClock: 3.6Mhz */
|
|
||||||
HIBYTE(USBD_CCID_DEFAULT_CLOCK_FREQ),
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
LOBYTE(USBD_CCID_MAX_CLOCK_FREQ), /* dwMaximumClock */
|
|
||||||
HIBYTE(USBD_CCID_MAX_CLOCK_FREQ),
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, /* bNumClockSupported */
|
|
||||||
LOBYTE(USBD_CCID_DEFAULT_DATA_RATE), /* dwDataRate: 9677 bps */
|
|
||||||
HIBYTE(USBD_CCID_DEFAULT_DATA_RATE),
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
|
|
||||||
LOBYTE(USBD_CCID_MAX_DATA_RATE), /* dwMaxDataRate: */
|
|
||||||
HIBYTE(USBD_CCID_MAX_DATA_RATE),
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x35, /* bNumDataRatesSupported */
|
|
||||||
|
|
||||||
LOBYTE(USBD_CCID_MAX_INF_FIELD_SIZE), /* dwMaxIFSD: maximum IFSD supported for T=1 */
|
|
||||||
HIBYTE(USBD_CCID_MAX_INF_FIELD_SIZE),
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, /* dwSynchProtocols */
|
|
||||||
0x00, 0x00, 0x00, 0x00, /* dwMechanical: no special characteristics */
|
|
||||||
|
|
||||||
0xBA, 0x04, EXCHANGE_LEVEL_FEATURE, 0x00, /* dwFeatures */
|
|
||||||
LOBYTE(CCID_MAX_BLOCK_SIZE_HEADER), /* dwMaxCCIDMessageLength: Maximum block size + header*/
|
|
||||||
HIBYTE(CCID_MAX_BLOCK_SIZE_HEADER),
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, /* bClassGetResponse*/
|
|
||||||
0x00, /* bClassEnvelope */
|
|
||||||
0x00, 0x00, /* wLcdLayout : 0000h no LCD. */
|
|
||||||
0x03, /* bPINSupport : PIN verification and PIN modification */
|
|
||||||
0x01, /* bMaxCCIDBusySlots */
|
|
||||||
|
|
||||||
/******************** CCID Endpoints ********************/
|
|
||||||
CCID_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
|
|
||||||
CCID_IN_EP, /* Endpoint address (IN, address 1) */
|
|
||||||
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
|
|
||||||
|
|
||||||
LOBYTE(CCID_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
HIBYTE(CCID_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
0x00, /* Polling interval in milliseconds */
|
|
||||||
CCID_ENDPOINT_DESC_SIZE, /* Endpoint descriptor length = 7 */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* Endpoint descriptor type */
|
|
||||||
CCID_OUT_EP, /* Endpoint address (OUT, address 1) */
|
|
||||||
USBD_EP_TYPE_BULK, /* Bulk endpoint type */
|
|
||||||
|
|
||||||
LOBYTE(CCID_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
HIBYTE(CCID_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
0x00, /* Polling interval in milliseconds */
|
|
||||||
CCID_ENDPOINT_DESC_SIZE, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType:*/
|
|
||||||
CCID_CMD_EP, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
USBD_EP_TYPE_INTR, /* bmAttributes: Interrupt endpoint */
|
|
||||||
LOBYTE(CCID_CMD_PACKET_SIZE),
|
|
||||||
HIBYTE(CCID_CMD_PACKET_SIZE),
|
|
||||||
CCID_CMD_HS_BINTERVAL /* Polling interval in milliseconds */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* USB CCID device Configuration Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CCID_CfgFSDesc[USB_CCID_CONFIG_DESC_SIZ] __ALIGN_END =
|
|
||||||
{
|
|
||||||
/* Configuration Descriptor */
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
USB_CCID_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
|
||||||
0x00,
|
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
|
||||||
0x01, /* bConfigurationValue: */
|
|
||||||
0x00, /* iConfiguration: */
|
|
||||||
#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) */
|
|
||||||
|
|
||||||
/******************** CCID **** interface ********************/
|
|
||||||
CCID_INTERFACE_DESC_SIZE, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x03, /* bNumEndpoints: 3 endpoints used */
|
|
||||||
USB_DEVICE_CLASS_CCID, /* bInterfaceClass: user's interface for CCID */
|
|
||||||
0x00, /* bInterfaceSubClass : No subclass, can be changed but no description in USB 2.0 Spec */
|
|
||||||
0x00, /* nInterfaceProtocol : None */
|
0x00, /* nInterfaceProtocol : None */
|
||||||
0x00, /* iInterface */
|
0x00, /* iInterface */
|
||||||
|
|
||||||
@@ -343,7 +253,7 @@ __ALIGN_BEGIN static uint8_t USBD_CCID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -370,11 +280,19 @@ static uint8_t USBD_CCID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
if (hccid == NULL)
|
if (hccid == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pClassData = (void *)hccid;
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hccid;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CCIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CCIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CCIDCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Init the CCID parameters into a state where it can receive a new command message */
|
/* Init the CCID parameters into a state where it can receive a new command message */
|
||||||
hccid->USBD_CCID_Param.bAbortRequestFlag = 0U;
|
hccid->USBD_CCID_Param.bAbortRequestFlag = 0U;
|
||||||
@@ -384,23 +302,23 @@ static uint8_t USBD_CCID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
CCID_DATA_HS_MAX_PACKET_SIZE : CCID_DATA_FS_MAX_PACKET_SIZE;
|
CCID_DATA_HS_MAX_PACKET_SIZE : CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, CCID_IN_EP, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
(void)USBD_LL_OpenEP(pdev, CCIDInEpAdd, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
||||||
pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[CCIDInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, CCID_OUT_EP, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
(void)USBD_LL_OpenEP(pdev, CCIDOutEpAdd, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
||||||
pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[CCIDOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open INTR EP IN */
|
/* Open INTR EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, CCID_CMD_EP,
|
(void)USBD_LL_OpenEP(pdev, CCIDCmdEpAdd,
|
||||||
USBD_EP_TYPE_INTR, CCID_CMD_PACKET_SIZE);
|
USBD_EP_TYPE_INTR, CCID_CMD_PACKET_SIZE);
|
||||||
pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[CCIDCmdEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Init physical Interface components */
|
/* Init physical Interface components */
|
||||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->Init(pdev);
|
((USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init(pdev);
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP,
|
(void)USBD_LL_PrepareReceive(pdev, CCIDOutEpAdd,
|
||||||
hccid->data, hccid->MaxPcktLen);
|
hccid->data, hccid->MaxPcktLen);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
@@ -417,23 +335,31 @@ static uint8_t USBD_CCID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CCIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CCIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CCIDCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close EP IN */
|
/* Close EP IN */
|
||||||
(void)USBD_LL_CloseEP(pdev, CCID_IN_EP);
|
(void)USBD_LL_CloseEP(pdev, CCIDInEpAdd);
|
||||||
pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[CCIDInEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP OUT */
|
/* Close EP OUT */
|
||||||
(void)USBD_LL_CloseEP(pdev, CCID_OUT_EP);
|
(void)USBD_LL_CloseEP(pdev, CCIDOutEpAdd);
|
||||||
pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 0U;
|
pdev->ep_out[CCIDOutEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP Command */
|
/* Close EP Command */
|
||||||
(void)USBD_LL_CloseEP(pdev, CCID_CMD_EP);
|
(void)USBD_LL_CloseEP(pdev, CCIDCmdEpAdd);
|
||||||
pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[CCIDCmdEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if (pdev->pClassData != NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->DeInit(pdev);
|
((USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit(pdev);
|
||||||
(void)USBD_free(pdev->pClassData);
|
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,8 +375,8 @@ static uint8_t USBD_CCID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CCID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static uint8_t USBD_CCID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData;
|
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
uint8_t ifalt = 0U;
|
uint8_t ifalt = 0U;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
@@ -544,9 +470,15 @@ static uint8_t USBD_CCID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (epnum == (CCID_IN_EP & 0x7FU))
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CCIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CCIDCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (epnum == (CCIDInEpAdd & 0x7FU))
|
||||||
{
|
{
|
||||||
/* Filter the epnum by masking with 0x7f (mask of IN Direction) */
|
/* Filter the epnum by masking with 0x7f (mask of IN Direction) */
|
||||||
|
|
||||||
@@ -561,14 +493,14 @@ static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
|
|
||||||
/* Prepare EP to Receive Cmd */
|
/* Prepare EP to Receive Cmd */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP,
|
(void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP,
|
||||||
hccid->data, CCID_DATA_FS_MAX_PACKET_SIZE);
|
hccid->data, hccid->MaxPcktLen);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (epnum == (CCID_CMD_EP & 0x7FU))
|
else if (epnum == (CCIDCmdEpAdd & 0x7FU))
|
||||||
{
|
{
|
||||||
/* Filter the epnum by masking with 0x7f (mask of IN Direction) */
|
/* Filter the epnum by masking with 0x7f (mask of IN Direction) */
|
||||||
|
|
||||||
@@ -593,15 +525,20 @@ static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CCID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_CCID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint16_t CurrPcktLen;
|
uint16_t CurrPcktLen;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CCIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hccid == NULL)
|
if (hccid == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (epnum == CCID_OUT_EP)
|
if (epnum == CCIDOutEpAdd)
|
||||||
{
|
{
|
||||||
CurrPcktLen = (uint16_t)USBD_GetRxCount(pdev, epnum);
|
CurrPcktLen = (uint16_t)USBD_GetRxCount(pdev, epnum);
|
||||||
|
|
||||||
@@ -735,7 +672,7 @@ static uint8_t USBD_CCID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t errorCode;
|
uint8_t errorCode;
|
||||||
|
|
||||||
switch (hccid->UsbBlkOutData.bMessageType)
|
switch (hccid->UsbBlkOutData.bMessageType)
|
||||||
@@ -828,13 +765,13 @@ static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev)
|
|||||||
uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *dataPointer, uint16_t dataLen)
|
uint8_t *dataPointer, uint16_t dataLen)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData;
|
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
|
||||||
UNUSED(dataPointer);
|
UNUSED(dataPointer);
|
||||||
|
|
||||||
hccid->blkt_state = CCID_STATE_SEND_RESP;
|
hccid->blkt_state = CCID_STATE_SEND_RESP;
|
||||||
hccid->UsbMessageLength = hccid->UsbBlkInData.dwLength + (uint32_t)dataLen; /* Store for future use */
|
hccid->UsbMessageLength = (uint32_t)dataLen; /* Store for future use */
|
||||||
|
|
||||||
/* use the header declared size packet must be well formed */
|
/* use the header declared size packet must be well formed */
|
||||||
hCCIDitf->Response_SendData(pdev, (uint8_t *)&hccid->UsbBlkInData,
|
hCCIDitf->Response_SendData(pdev, (uint8_t *)&hccid->UsbBlkInData,
|
||||||
@@ -854,7 +791,7 @@ uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
|||||||
static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pDst, uint16_t u8length)
|
uint8_t *pDst, uint16_t u8length)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t *pdst = pDst;
|
uint8_t *pdst = pDst;
|
||||||
uint32_t Counter;
|
uint32_t Counter;
|
||||||
|
|
||||||
@@ -875,7 +812,12 @@ static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CCIDCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Check if there is change in Smartcard Slot status */
|
/* Check if there is change in Smartcard Slot status */
|
||||||
if (CCID_IsSlotStatusChange(pdev) != 0U)
|
if (CCID_IsSlotStatusChange(pdev) != 0U)
|
||||||
@@ -884,19 +826,20 @@ uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev)
|
|||||||
RDR_to_PC_NotifySlotChange(pdev);
|
RDR_to_PC_NotifySlotChange(pdev);
|
||||||
|
|
||||||
/* Set the Slot status */
|
/* Set the Slot status */
|
||||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->SetSlotStatus(pdev);
|
((USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId])->SetSlotStatus(pdev);
|
||||||
|
|
||||||
(void)USBD_LL_Transmit(pdev, CCID_CMD_EP, hccid->UsbIntData, 2U);
|
(void)USBD_LL_Transmit(pdev, CCIDCmdEpAdd, hccid->UsbIntData, 2U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Set the Slot status */
|
/* Set the Slot status */
|
||||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->SetSlotStatus(pdev);
|
((USBD_CCID_ItfTypeDef *)pdev->pUserData[pdev->classId])->SetSlotStatus(pdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CCID_GetHSCfgDesc
|
* @brief USBD_CCID_GetHSCfgDesc
|
||||||
* Return configuration descriptor
|
* Return configuration descriptor
|
||||||
@@ -905,8 +848,27 @@ uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CCID_CfgHSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_IN_EP);
|
||||||
return USBD_CCID_CfgHSDesc;
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_CMD_EP);
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CCID_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CCID_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CCID_CMD_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CCID_CfgDesc);
|
||||||
|
return USBD_CCID_CfgDesc;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CCID_GetFSCfgDesc
|
* @brief USBD_CCID_GetFSCfgDesc
|
||||||
@@ -916,8 +878,27 @@ static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CCID_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_IN_EP);
|
||||||
return USBD_CCID_CfgFSDesc;
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_CMD_EP);
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CCID_CMD_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CCID_CfgDesc);
|
||||||
|
return USBD_CCID_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -928,8 +909,27 @@ static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CCID_GetOtherSpeedCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CCID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CCID_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_IN_EP);
|
||||||
return USBD_CCID_CfgFSDesc;
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CCID_CfgDesc, CCID_CMD_EP);
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CCID_CMD_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CCID_CfgDesc);
|
||||||
|
return USBD_CCID_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -943,6 +943,7 @@ static uint8_t *USBD_CCID_GetDeviceQualifierDescriptor(uint16_t *length)
|
|||||||
*length = (uint16_t)(sizeof(USBD_CCID_DeviceQualifierDesc));
|
*length = (uint16_t)(sizeof(USBD_CCID_DeviceQualifierDesc));
|
||||||
return USBD_CCID_DeviceQualifierDesc;
|
return USBD_CCID_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CCID_RegisterInterface
|
* @brief USBD_CCID_RegisterInterface
|
||||||
@@ -958,7 +959,7 @@ uint8_t USBD_CCID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
/* Private macro -------------------------------------------------------------*/
|
/* Private macro -------------------------------------------------------------*/
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param_type);
|
static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param_type);
|
||||||
static void CCID_UpdateCommandStatus(uint8_t cmd_status, uint8_t icc_status);
|
static void CCID_UpdateCommandStatus(USBD_HandleTypeDef *pdev, uint8_t cmd_status, uint8_t icc_status);
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -42,10 +42,10 @@ static void CCID_UpdateCommandStatus(uint8_t cmd_status, uint8_t icc_status);
|
|||||||
uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Apply the ICC VCC
|
/* Apply the ICC VCC
|
||||||
Fills the Response buffer with ICC ATR
|
* Fills the Response buffer with ICC ATR
|
||||||
This Command is returned with RDR_to_PC_DataBlock();
|
* This Command is returned with RDR_to_PC_DataBlock();
|
||||||
*/
|
*/
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t voltage;
|
uint8_t voltage;
|
||||||
uint8_t sc_voltage = 0U;
|
uint8_t sc_voltage = 0U;
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
@@ -54,7 +54,7 @@ uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
|||||||
hccid->UsbBlkInData.dwLength = 0U; /* Reset Number of Bytes in abData */
|
hccid->UsbBlkInData.dwLength = 0U; /* Reset Number of Bytes in abData */
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
||||||
CHK_PARAM_abRFU2 | CHK_PARAM_CARD_PRESENT |
|
CHK_PARAM_ABRFU2 | CHK_PARAM_CARD_PRESENT |
|
||||||
CHK_PARAM_ABORT);
|
CHK_PARAM_ABORT);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
@@ -71,7 +71,7 @@ uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
|||||||
voltage = hccid->UsbBlkOutData.bSpecific_0;
|
voltage = hccid->UsbBlkOutData.bSpecific_0;
|
||||||
if (voltage >= VOLTAGE_SELECTION_1V8)
|
if (voltage >= VOLTAGE_SELECTION_1V8)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOTERROR_BAD_POWERSELECT; /* The Voltage specified is out of Spec */
|
return SLOTERROR_BAD_POWERSELECT; /* The Voltage specified is out of Spec */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Voltage requested from Host was 5V already*/
|
/* Voltage requested from Host was 5V already*/
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
} /* Voltage Selection was automatic */
|
} /* Voltage Selection was automatic */
|
||||||
@@ -128,7 +128,7 @@ uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
/* ATR is received, No Error Condition Found */
|
/* ATR is received, No Error Condition Found */
|
||||||
hccid->UsbBlkInData.dwLength = SIZE_OF_ATR;
|
hccid->UsbBlkInData.dwLength = SIZE_OF_ATR;
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
|
|
||||||
for (index = 0U; index < SIZE_OF_ATR; index++)
|
for (index = 0U; index < SIZE_OF_ATR; index++)
|
||||||
{
|
{
|
||||||
@@ -150,7 +150,7 @@ uint8_t PC_to_RDR_IccPowerOff(USBD_HandleTypeDef *pdev)
|
|||||||
/* The response to this command is the RDR_to_PC_SlotStatus*/
|
/* The response to this command is the RDR_to_PC_SlotStatus*/
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_abRFU3 |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_ABRFU3 |
|
||||||
CHK_PARAM_DWLENGTH);
|
CHK_PARAM_DWLENGTH);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
@@ -159,11 +159,11 @@ uint8_t PC_to_RDR_IccPowerOff(USBD_HandleTypeDef *pdev)
|
|||||||
/* Command is ok, Check for Card Presence */
|
/* Command is ok, Check for Card Presence */
|
||||||
if (SC_Detect() != 0U)
|
if (SC_Detect() != 0U)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_INACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_INACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_NO_ICC_PRESENT));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_NO_ICC_PRESENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Power OFF the card */
|
/* Power OFF the card */
|
||||||
@@ -183,13 +183,13 @@ uint8_t PC_to_RDR_GetSlotStatus(USBD_HandleTypeDef *pdev)
|
|||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
||||||
CHK_PARAM_CARD_PRESENT | CHK_PARAM_abRFU3);
|
CHK_PARAM_CARD_PRESENT | CHK_PARAM_ABRFU3);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOT_NO_ERROR;
|
return SLOT_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,13 +203,13 @@ uint8_t PC_to_RDR_GetSlotStatus(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_to_RDR_XfrBlock(USBD_HandleTypeDef *pdev)
|
uint8_t PC_to_RDR_XfrBlock(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint16_t expectedLength;
|
uint16_t expectedLength;
|
||||||
|
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||||
CHK_PARAM_abRFU3 | CHK_PARAM_ABORT | CHK_ACTIVE_STATE);
|
CHK_PARAM_ABRFU3 | CHK_PARAM_ABORT | CHK_ACTIVE_STATE);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
@@ -234,11 +234,11 @@ uint8_t PC_to_RDR_XfrBlock(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
error = SLOT_NO_ERROR;
|
error = SLOT_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,12 +257,12 @@ uint8_t PC_to_RDR_GetParameters(USBD_HandleTypeDef *pdev)
|
|||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
||||||
CHK_PARAM_CARD_PRESENT | CHK_PARAM_abRFU3);
|
CHK_PARAM_CARD_PRESENT | CHK_PARAM_ABRFU3);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
|
|
||||||
return SLOT_NO_ERROR;
|
return SLOT_NO_ERROR;
|
||||||
}
|
}
|
||||||
@@ -276,11 +276,11 @@ uint8_t PC_to_RDR_GetParameters(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev)
|
uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
|
||||||
CHK_PARAM_CARD_PRESENT | CHK_PARAM_abRFU3 |
|
CHK_PARAM_CARD_PRESENT | CHK_PARAM_ABRFU3 |
|
||||||
CHK_ACTIVE_STATE);
|
CHK_ACTIVE_STATE);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
@@ -302,11 +302,11 @@ uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
error = SLOT_NO_ERROR;
|
error = SLOT_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,11 +321,11 @@ uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev)
|
uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||||
CHK_PARAM_abRFU2 | CHK_ACTIVE_STATE);
|
CHK_PARAM_ABRFU2 | CHK_ACTIVE_STATE);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
@@ -345,7 +345,7 @@ uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)USBD_memcpy(&ProtocolData, (void const *)(&hccid->UsbBlkOutData.abData[0]),
|
(void)USBD_memcpy(&ProtocolData, (void const *)(&hccid->UsbBlkOutData.abData[0]),
|
||||||
@@ -355,11 +355,11 @@ uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
error = SLOT_NO_ERROR;
|
error = SLOT_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,12 +374,12 @@ uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev)
|
uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||||
CHK_PARAM_abRFU3 | CHK_PARAM_ABORT | CHK_ACTIVE_STATE);
|
CHK_PARAM_ABRFU3 | CHK_PARAM_ABORT | CHK_ACTIVE_STATE);
|
||||||
|
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
@@ -392,11 +392,11 @@ uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
@@ -410,11 +410,11 @@ uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev)
|
uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||||
CHK_PARAM_abRFU2 | CHK_PARAM_DWLENGTH | CHK_ACTIVE_STATE);
|
CHK_PARAM_ABRFU2 | CHK_PARAM_DWLENGTH | CHK_ACTIVE_STATE);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
@@ -424,7 +424,7 @@ uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev)
|
|||||||
01h Stops Clock in the state shown in the bClockStop field */
|
01h Stops Clock in the state shown in the bClockStop field */
|
||||||
if (hccid->UsbBlkOutData.bSpecific_0 > 1U)
|
if (hccid->UsbBlkOutData.bSpecific_0 > 1U)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOTERROR_BAD_CLOCKCOMMAND;
|
return SLOTERROR_BAD_CLOCKCOMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,11 +432,11 @@ uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
@@ -451,17 +451,17 @@ uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_to_RDR_Abort(USBD_HandleTypeDef *pdev)
|
uint8_t PC_to_RDR_Abort(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_abRFU3 |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_ABRFU3 |
|
||||||
CHK_PARAM_DWLENGTH);
|
CHK_PARAM_DWLENGTH);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
(void)CCID_CmdAbort(hccid->UsbBlkOutData.bSlot, hccid->UsbBlkOutData.bSeq);
|
(void)CCID_CmdAbort(pdev, hccid->UsbBlkOutData.bSlot, hccid->UsbBlkOutData.bSeq);
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOT_NO_ERROR;
|
return SLOT_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,13 +469,14 @@ uint8_t PC_to_RDR_Abort(USBD_HandleTypeDef *pdev)
|
|||||||
* @brief CCID_CmdAbort
|
* @brief CCID_CmdAbort
|
||||||
* Execute the Abort command from Bulk EP or from Control EP,
|
* Execute the Abort command from Bulk EP or from Control EP,
|
||||||
* This stops all Bulk transfers from host and ICC
|
* This stops all Bulk transfers from host and ICC
|
||||||
|
* @param pdev: device instance
|
||||||
* @param slot: slot number that host wants to abort
|
* @param slot: slot number that host wants to abort
|
||||||
* @param seq : Seq number for PC_to_RDR_Abort
|
* @param seq : Seq number for PC_to_RDR_Abort
|
||||||
* @retval status of the command execution
|
* @retval status of the command execution
|
||||||
*/
|
*/
|
||||||
uint8_t CCID_CmdAbort(uint8_t slot, uint8_t seq)
|
uint8_t CCID_CmdAbort(USBD_HandleTypeDef *pdev, uint8_t slot, uint8_t seq)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)(USBD_Device.pClassData);
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
uint8_t BSlot = hccid->USBD_CCID_Param.bSlot;
|
uint8_t BSlot = hccid->USBD_CCID_Param.bSlot;
|
||||||
/* This function is called for REQUEST_ABORT & PC_to_RDR_Abort */
|
/* This function is called for REQUEST_ABORT & PC_to_RDR_Abort */
|
||||||
@@ -483,7 +484,7 @@ uint8_t CCID_CmdAbort(uint8_t slot, uint8_t seq)
|
|||||||
if (slot >= CCID_NUMBER_OF_SLOTS)
|
if (slot >= CCID_NUMBER_OF_SLOTS)
|
||||||
{
|
{
|
||||||
/* error from CLASS_REQUEST*/
|
/* error from CLASS_REQUEST*/
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
||||||
return SLOTERROR_BAD_SLOT;
|
return SLOTERROR_BAD_SLOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,7 +518,7 @@ uint8_t CCID_CmdAbort(uint8_t slot, uint8_t seq)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev)
|
uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||||
@@ -531,7 +532,7 @@ uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev)
|
|||||||
/* Bit 0 is associated with bClassGetResponse
|
/* Bit 0 is associated with bClassGetResponse
|
||||||
Bit 1 is associated with bClassEnvelope */
|
Bit 1 is associated with bClassEnvelope */
|
||||||
|
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOTERROR_BAD_BMCHANGES;
|
return SLOTERROR_BAD_BMCHANGES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,11 +542,11 @@ uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
@@ -560,11 +561,11 @@ uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev)
|
uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||||
CHK_PARAM_abRFU2 | CHK_PARAM_DWLENGTH);
|
CHK_PARAM_ABRFU2 | CHK_PARAM_DWLENGTH);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
@@ -579,7 +580,7 @@ uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev)
|
|||||||
05h Unlock Card
|
05h Unlock Card
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOTERROR_BAD_BFUNCTION_MECHANICAL;
|
return SLOTERROR_BAD_BFUNCTION_MECHANICAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,11 +588,11 @@ uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
@@ -607,21 +608,21 @@ uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev)
|
uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
uint32_t clockFrequency;
|
uint32_t clockFrequency;
|
||||||
uint32_t dataRate;
|
uint32_t dataRate;
|
||||||
uint32_t temp;
|
uint32_t temp;
|
||||||
|
|
||||||
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_CARD_PRESENT |
|
||||||
CHK_PARAM_abRFU3);
|
CHK_PARAM_ABRFU3);
|
||||||
if (error != 0U)
|
if (error != 0U)
|
||||||
{
|
{
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
if (hccid->UsbBlkOutData.dwLength != 0x08U)
|
if (hccid->UsbBlkOutData.dwLength != 0x08U)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOTERROR_BAD_LENTGH;
|
return SLOTERROR_BAD_LENTGH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,7 +657,7 @@ uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev)
|
|||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
hccid->UsbBlkInData.dwLength = 0;
|
hccid->UsbBlkInData.dwLength = 0;
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -678,7 +679,7 @@ uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
(hccid->UsbBlkInData.abData[7]) = (uint8_t)((dataRate & 0xFF000000U) >> 24);
|
(hccid->UsbBlkInData.abData[7]) = (uint8_t)((dataRate & 0xFF000000U) >> 24);
|
||||||
|
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
@@ -693,7 +694,7 @@ uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev)
|
uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
uint8_t bBWI;
|
uint8_t bBWI;
|
||||||
uint16_t wLevelParameter;
|
uint16_t wLevelParameter;
|
||||||
@@ -717,7 +718,7 @@ uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev)
|
|||||||
/* TPDU level & short APDU level, wLevelParameter is RFU, = 0000h */
|
/* TPDU level & short APDU level, wLevelParameter is RFU, = 0000h */
|
||||||
if (wLevelParameter != 0U)
|
if (wLevelParameter != 0U)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
error = SLOTERROR_BAD_LEVELPARAMETER;
|
error = SLOTERROR_BAD_LEVELPARAMETER;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -730,11 +731,11 @@ uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (error != SLOT_NO_ERROR)
|
if (error != SLOT_NO_ERROR)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
@@ -754,7 +755,7 @@ uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void RDR_to_PC_DataBlock(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
void RDR_to_PC_DataBlock(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t length = CCID_RESPONSE_HEADER_SIZE;
|
uint32_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||||
|
|
||||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_DATABLOCK;
|
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_DATABLOCK;
|
||||||
@@ -786,8 +787,8 @@ void RDR_to_PC_DataBlock(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void RDR_to_PC_SlotStatus(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
void RDR_to_PC_SlotStatus(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
UNUSED(errorCode);
|
uint16_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||||
|
|
||||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_SLOTSTATUS;
|
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_SLOTSTATUS;
|
||||||
hccid->UsbBlkInData.dwLength = 0U;
|
hccid->UsbBlkInData.dwLength = 0U;
|
||||||
@@ -797,9 +798,12 @@ void RDR_to_PC_SlotStatus(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
|||||||
02h Clock stopped in state H
|
02h Clock stopped in state H
|
||||||
03h Clock stopped in an unknown state */
|
03h Clock stopped in an unknown state */
|
||||||
|
|
||||||
(void)USBD_CCID_Transfer_Data_Request(pdev, (uint8_t *)(&hccid->UsbBlkInData),
|
if (errorCode == SLOT_NO_ERROR)
|
||||||
LEN_RDR_TO_PC_SLOTSTATUS);
|
{
|
||||||
|
length += (uint16_t)hccid->UsbBlkInData.dwLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)USBD_CCID_Transfer_Data_Request(pdev, (uint8_t *)(&hccid->UsbBlkInData), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -813,7 +817,7 @@ void RDR_to_PC_SlotStatus(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void RDR_to_PC_Parameters(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
void RDR_to_PC_Parameters(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint16_t length = CCID_RESPONSE_HEADER_SIZE;
|
uint16_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||||
|
|
||||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_PARAMETERS;
|
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_PARAMETERS;
|
||||||
@@ -824,12 +828,12 @@ void RDR_to_PC_Parameters(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
|||||||
if (ProtocolNUM_OUT == 0x00U)
|
if (ProtocolNUM_OUT == 0x00U)
|
||||||
{
|
{
|
||||||
hccid->UsbBlkInData.dwLength = LEN_PROTOCOL_STRUCT_T0;
|
hccid->UsbBlkInData.dwLength = LEN_PROTOCOL_STRUCT_T0;
|
||||||
length += LEN_PROTOCOL_STRUCT_T0;
|
length += (uint16_t)hccid->UsbBlkInData.dwLength;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hccid->UsbBlkInData.dwLength = LEN_PROTOCOL_STRUCT_T1;
|
hccid->UsbBlkInData.dwLength = LEN_PROTOCOL_STRUCT_T1;
|
||||||
length += LEN_PROTOCOL_STRUCT_T1;
|
length += (uint16_t)hccid->UsbBlkInData.dwLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -867,7 +871,7 @@ void RDR_to_PC_Parameters(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void RDR_to_PC_Escape(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
void RDR_to_PC_Escape(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t length = CCID_RESPONSE_HEADER_SIZE;
|
uint32_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||||
|
|
||||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_ESCAPE;
|
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_ESCAPE;
|
||||||
@@ -893,7 +897,7 @@ void RDR_to_PC_Escape(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t length = CCID_RESPONSE_HEADER_SIZE;
|
uint32_t length = CCID_RESPONSE_HEADER_SIZE;
|
||||||
|
|
||||||
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_DATARATEANDCLOCKFREQUENCY;
|
hccid->UsbBlkInData.bMessageType = RDR_TO_PC_DATARATEANDCLOCKFREQUENCY;
|
||||||
@@ -917,7 +921,7 @@ void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef
|
|||||||
*/
|
*/
|
||||||
void RDR_to_PC_NotifySlotChange(USBD_HandleTypeDef *pdev)
|
void RDR_to_PC_NotifySlotChange(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hccid->UsbIntData[OFFSET_INT_BMESSAGETYPE] = RDR_TO_PC_NOTIFYSLOTCHANGE;
|
hccid->UsbIntData[OFFSET_INT_BMESSAGETYPE] = RDR_TO_PC_NOTIFYSLOTCHANGE;
|
||||||
|
|
||||||
@@ -948,7 +952,7 @@ void RDR_to_PC_NotifySlotChange(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus)
|
void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
hccid->SlotStatus.SlotStatus = slotStatus;
|
hccid->SlotStatus.SlotStatus = slotStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -961,7 +965,7 @@ void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus)
|
|||||||
*/
|
*/
|
||||||
void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus)
|
void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
hccid->SlotStatus.SlotStatusChange = changeStatus;
|
hccid->SlotStatus.SlotStatusChange = changeStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -973,20 +977,21 @@ void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus)
|
|||||||
*/
|
*/
|
||||||
uint8_t CCID_IsSlotStatusChange(USBD_HandleTypeDef *pdev)
|
uint8_t CCID_IsSlotStatusChange(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
return hccid->SlotStatus.SlotStatusChange;
|
return hccid->SlotStatus.SlotStatusChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief CCID_UpdateCommandStatus
|
* @brief CCID_UpdateCommandStatus
|
||||||
* Updates the variable for the BulkIn status
|
* Updates the variable for the BulkIn status
|
||||||
|
* @param pdev: device instance
|
||||||
* @param cmd_status : Command change status from the calling function
|
* @param cmd_status : Command change status from the calling function
|
||||||
* @param icc_status : Slot change status from the calling function
|
* @param icc_status : Slot change status from the calling function
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void CCID_UpdateCommandStatus(uint8_t cmd_status, uint8_t icc_status)
|
static void CCID_UpdateCommandStatus(USBD_HandleTypeDef *pdev, uint8_t cmd_status, uint8_t icc_status)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)USBD_Device.pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
hccid->UsbBlkInData.bStatus = (cmd_status | icc_status);
|
hccid->UsbBlkInData.bStatus = (cmd_status | icc_status);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -1000,7 +1005,7 @@ static void CCID_UpdateCommandStatus(uint8_t cmd_status, uint8_t icc_status)
|
|||||||
*/
|
*/
|
||||||
static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param_type)
|
static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param_type)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t parameter;
|
uint32_t parameter;
|
||||||
uint8_t GetState = SC_GetState();
|
uint8_t GetState = SC_GetState();
|
||||||
|
|
||||||
@@ -1019,7 +1024,7 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
|||||||
if (hccid->UsbBlkOutData.bSlot >= CCID_NUMBER_OF_SLOTS)
|
if (hccid->UsbBlkOutData.bSlot >= CCID_NUMBER_OF_SLOTS)
|
||||||
{
|
{
|
||||||
/* Slot requested is more than supported by Firmware */
|
/* Slot requested is more than supported by Firmware */
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
||||||
return SLOTERROR_BAD_SLOT;
|
return SLOTERROR_BAD_SLOT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1030,7 +1035,7 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
|||||||
if (SC_Detect() == 0U)
|
if (SC_Detect() == 0U)
|
||||||
{
|
{
|
||||||
/* Card is Not detected */
|
/* Card is Not detected */
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
|
||||||
return SLOTERROR_ICC_MUTE;
|
return SLOTERROR_ICC_MUTE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1040,30 +1045,30 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
|||||||
{
|
{
|
||||||
if (hccid->UsbBlkOutData.dwLength != 0U)
|
if (hccid->UsbBlkOutData.dwLength != 0U)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOTERROR_BAD_LENTGH;
|
return SLOTERROR_BAD_LENTGH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* abRFU 2 : Reserved for Future Use*/
|
/* abRFU 2 : Reserved for Future Use*/
|
||||||
if ((parameter & CHK_PARAM_abRFU2) != 0U)
|
if ((parameter & CHK_PARAM_ABRFU2) != 0U)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((hccid->UsbBlkOutData.bSpecific_1 != 0U) || (hccid->UsbBlkOutData.bSpecific_2 != 0U))
|
if ((hccid->UsbBlkOutData.bSpecific_1 != 0U) || (hccid->UsbBlkOutData.bSpecific_2 != 0U))
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOTERROR_BAD_ABRFU_2B; /* bSpecific_1 */
|
return SLOTERROR_BAD_ABRFU_2B; /* bSpecific_1 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((parameter & CHK_PARAM_abRFU3) != 0U)
|
if ((parameter & CHK_PARAM_ABRFU3) != 0U)
|
||||||
{
|
{
|
||||||
/* abRFU 3 : Reserved for Future Use*/
|
/* abRFU 3 : Reserved for Future Use*/
|
||||||
if ((hccid->UsbBlkOutData.bSpecific_0 != 0U) ||
|
if ((hccid->UsbBlkOutData.bSpecific_0 != 0U) ||
|
||||||
(hccid->UsbBlkOutData.bSpecific_1 != 0U) ||
|
(hccid->UsbBlkOutData.bSpecific_1 != 0U) ||
|
||||||
(hccid->UsbBlkOutData.bSpecific_2 != 0U))
|
(hccid->UsbBlkOutData.bSpecific_2 != 0U))
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
|
||||||
return SLOTERROR_BAD_ABRFU_3B;
|
return SLOTERROR_BAD_ABRFU_3B;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1072,7 +1077,7 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
|||||||
{
|
{
|
||||||
if (hccid->USBD_CCID_Param.bAbortRequestFlag != 0U)
|
if (hccid->USBD_CCID_Param.bAbortRequestFlag != 0U)
|
||||||
{
|
{
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
||||||
return SLOTERROR_CMD_ABORTED;
|
return SLOTERROR_CMD_ABORTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1085,7 +1090,7 @@ static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef *pdev, uint32_t param
|
|||||||
if ((GetState != (uint8_t)SC_ACTIVE_ON_T0) && (GetState != (uint8_t)SC_ACTIVE_ON_T1))
|
if ((GetState != (uint8_t)SC_ACTIVE_ON_T0) && (GetState != (uint8_t)SC_ACTIVE_ON_T1))
|
||||||
{
|
{
|
||||||
/* Check that from Lower Layers, the SmartCard come to known state */
|
/* Check that from Lower Layers, the SmartCard come to known state */
|
||||||
CCID_UpdateCommandStatus((BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
|
||||||
return SLOTERROR_HW_ERROR;
|
return SLOTERROR_HW_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,11 @@ USBD_CCID_ItfTypeDef USBD_CCID_If_fops =
|
|||||||
*/
|
*/
|
||||||
uint8_t CCID_Init(USBD_HandleTypeDef *pdev)
|
uint8_t CCID_Init(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#else
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* CCID Related Initialization */
|
/* CCID Related Initialization */
|
||||||
|
|
||||||
@@ -76,8 +80,11 @@ uint8_t CCID_Init(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t CCID_DeInit(USBD_HandleTypeDef *pdev)
|
uint8_t CCID_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#else
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
hccid->blkt_state = CCID_STATE_IDLE;
|
hccid->blkt_state = CCID_STATE_IDLE;
|
||||||
|
|
||||||
@@ -94,7 +101,12 @@ uint8_t CCID_DeInit(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t CCID_ControlReq(uint8_t req, uint8_t *pbuf, uint16_t *length)
|
static uint8_t CCID_ControlReq(uint8_t req, uint8_t *pbuf, uint16_t *length)
|
||||||
{
|
{
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)(USBD_Device.pClassData);
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)USBD_Device.pClassDataCmsit[USBD_Device.classId];
|
||||||
|
#else
|
||||||
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)USBD_Device.pClassData;
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
UNUSED(length);
|
UNUSED(length);
|
||||||
|
|
||||||
switch (req)
|
switch (req)
|
||||||
@@ -105,7 +117,7 @@ static uint8_t CCID_ControlReq(uint8_t req, uint8_t *pbuf, uint16_t *length)
|
|||||||
hccid->slot_nb = ((uint16_t) * pbuf & 0x0fU);
|
hccid->slot_nb = ((uint16_t) * pbuf & 0x0fU);
|
||||||
hccid->seq_nb = (((uint16_t) * pbuf & 0xf0U) >> 8);
|
hccid->seq_nb = (((uint16_t) * pbuf & 0xf0U) >> 8);
|
||||||
|
|
||||||
if (CCID_CmdAbort((uint8_t)hccid->slot_nb, (uint8_t)hccid->seq_nb) != 0U)
|
if (CCID_CmdAbort(&USBD_Device, (uint8_t)hccid->slot_nb, (uint8_t)hccid->seq_nb) != 0U)
|
||||||
{
|
{
|
||||||
/* If error is returned by lower layer :
|
/* If error is returned by lower layer :
|
||||||
Generally Slot# may not have matched */
|
Generally Slot# may not have matched */
|
||||||
@@ -238,7 +250,11 @@ static uint8_t CCID_Response_Process(void)
|
|||||||
uint8_t CCID_SetSlotStatus(USBD_HandleTypeDef *pdev)
|
uint8_t CCID_SetSlotStatus(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Get the CCID handler pointer */
|
/* Get the CCID handler pointer */
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#else
|
||||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if ((hccid->SlotStatus.SlotStatus) == 1U) /* Transfer Complete Status
|
if ((hccid->SlotStatus.SlotStatus) == 1U) /* Transfer Complete Status
|
||||||
of previous Interrupt transfer */
|
of previous Interrupt transfer */
|
||||||
|
|||||||
@@ -27,8 +27,8 @@
|
|||||||
static SC_State SCState = SC_POWER_OFF;
|
static SC_State SCState = SC_POWER_OFF;
|
||||||
|
|
||||||
/* APDU Transport Structures */
|
/* APDU Transport Structures */
|
||||||
SC_ADPU_Commands SC_ADPU;
|
SC_ADPU_CommandsTypeDef SC_ADPU;
|
||||||
SC_ADPU_Response SC_Response;
|
SC_ADPU_ResponseTypeDef SC_Response;
|
||||||
SC_Param_t SC_Param;
|
SC_Param_t SC_Param;
|
||||||
Protocol_01_DataTypeDef ProtocolData;
|
Protocol_01_DataTypeDef ProtocolData;
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ __IO uint8_t IMSI_Content[9] = {0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|||||||
static uint32_t D_Table[16] = {0, 1, 2, 4, 8, 16, 32, 64, 12, 20, 0, 0, 0, 0, 0, 0};
|
static uint32_t D_Table[16] = {0, 1, 2, 4, 8, 16, 32, 64, 12, 20, 0, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
/* Global variables definition and initialization ----------------------------*/
|
/* Global variables definition and initialization ----------------------------*/
|
||||||
SC_ATR SC_A2R;
|
SC_ATRTypeDef SC_A2R;
|
||||||
uint8_t SC_ATR_Table[40];
|
uint8_t SC_ATR_Table[40];
|
||||||
uint8_t ProtocolNUM_OUT;
|
uint8_t ProtocolNUM_OUT;
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ static void SC_Init(void);
|
|||||||
static void SC_DeInit(void);
|
static void SC_DeInit(void);
|
||||||
static void SC_AnswerReq(SC_State *SC_state, uint8_t *card, uint8_t length); /* Ask ATR */
|
static void SC_AnswerReq(SC_State *SC_state, uint8_t *card, uint8_t length); /* Ask ATR */
|
||||||
static uint8_t SC_decode_Answer2reset(uint8_t *card); /* Decode ATR */
|
static uint8_t SC_decode_Answer2reset(uint8_t *card); /* Decode ATR */
|
||||||
static void SC_SendData(SC_ADPU_Commands *SCADPU, SC_ADPU_Response *SC_ResponseStatus);
|
static void SC_SendData(SC_ADPU_CommandsTypeDef *SCADPU, SC_ADPU_ResponseTypeDef *SC_ResponseStatus);
|
||||||
/* static void SC_Reset(GPIO_PinState ResetState); */
|
/* static void SC_Reset(GPIO_PinState ResetState); */
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
@@ -77,9 +77,10 @@ static void SC_SendData(SC_ADPU_Commands *SCADPU, SC_ADPU_Response *SC_ResponseS
|
|||||||
* @param SC_Response: pointer to a SC_ADPU_Response structure which will be initialized.
|
* @param SC_Response: pointer to a SC_ADPU_Response structure which will be initialized.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Response *SC_Response)
|
void SC_Handler(SC_State *SCState, SC_ADPU_CommandsTypeDef *SC_ADPU, SC_ADPU_ResponseTypeDef *SC_Response)
|
||||||
{
|
{
|
||||||
uint32_t i, j;
|
uint32_t i;
|
||||||
|
uint32_t j;
|
||||||
|
|
||||||
switch (*SCState)
|
switch (*SCState)
|
||||||
{
|
{
|
||||||
@@ -110,7 +111,7 @@ void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Response *
|
|||||||
|
|
||||||
for (i = 0U; i < HIST_LENGTH; i++)
|
for (i = 0U; i < HIST_LENGTH; i++)
|
||||||
{
|
{
|
||||||
SC_A2R.H[i] = 0U;
|
SC_A2R.Historical[i] = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_A2R.Tlength = 0U;
|
SC_A2R.Tlength = 0U;
|
||||||
@@ -245,7 +246,7 @@ void SC_PTSConfig(void)
|
|||||||
* @param SC_Response: pointer to a SC_ADPU_Response structure which will be initialized.
|
* @param SC_Response: pointer to a SC_ADPU_Response structure which will be initialized.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void SC_SendData(SC_ADPU_Commands *SCADPU, SC_ADPU_Response *SC_ResponseStatus)
|
static void SC_SendData(SC_ADPU_CommandsTypeDef *SCADPU, SC_ADPU_ResponseTypeDef *SC_ResponseStatus)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
uint8_t SC_Command[5];
|
uint8_t SC_Command[5];
|
||||||
@@ -316,8 +317,11 @@ static void SC_AnswerReq(SC_State *SC_state, uint8_t *atr_buffer, uint8_t length
|
|||||||
*/
|
*/
|
||||||
static uint8_t SC_decode_Answer2reset(uint8_t *card)
|
static uint8_t SC_decode_Answer2reset(uint8_t *card)
|
||||||
{
|
{
|
||||||
uint32_t i, flag = 0U, protocol;
|
uint32_t i = 0U;
|
||||||
uint8_t index = 0U, level = 0U;
|
uint32_t flag = 0U;
|
||||||
|
uint32_t protocol;
|
||||||
|
uint8_t index = 0U;
|
||||||
|
uint8_t level = 0U;
|
||||||
|
|
||||||
/******************************TS/T0 Decode************************************/
|
/******************************TS/T0 Decode************************************/
|
||||||
index++;
|
index++;
|
||||||
@@ -391,7 +395,7 @@ static uint8_t SC_decode_Answer2reset(uint8_t *card)
|
|||||||
|
|
||||||
for (i = 0U; i < SC_A2R.Hlength; i++)
|
for (i = 0U; i < SC_A2R.Hlength; i++)
|
||||||
{
|
{
|
||||||
SC_A2R.H[i] = card[i + 2U + SC_A2R.Tlength];
|
SC_A2R.Historical[i] = card[i + 2U + SC_A2R.Tlength];
|
||||||
}
|
}
|
||||||
/*************************************TCK Decode*******************************/
|
/*************************************TCK Decode*******************************/
|
||||||
SC_A2R.TCK = card[SC_A2R.Hlength + 2U + SC_A2R.Tlength];
|
SC_A2R.TCK = card[SC_A2R.Hlength + 2U + SC_A2R.Tlength];
|
||||||
|
|||||||
@@ -40,9 +40,15 @@ extern "C" {
|
|||||||
/** @defgroup usbd_cdc_Exported_Defines
|
/** @defgroup usbd_cdc_Exported_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#ifndef CDC_IN_EP
|
||||||
#define CDC_IN_EP 0x81U /* EP1 for data IN */
|
#define CDC_IN_EP 0x81U /* EP1 for data IN */
|
||||||
|
#endif /* CDC_IN_EP */
|
||||||
|
#ifndef CDC_OUT_EP
|
||||||
#define CDC_OUT_EP 0x01U /* EP1 for data OUT */
|
#define CDC_OUT_EP 0x01U /* EP1 for data OUT */
|
||||||
|
#endif /* CDC_OUT_EP */
|
||||||
|
#ifndef CDC_CMD_EP
|
||||||
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
||||||
|
#endif /* CDC_CMD_EP */
|
||||||
|
|
||||||
#ifndef CDC_HS_BINTERVAL
|
#ifndef CDC_HS_BINTERVAL
|
||||||
#define CDC_HS_BINTERVAL 0x10U
|
#define CDC_HS_BINTERVAL 0x10U
|
||||||
@@ -52,10 +58,13 @@ extern "C" {
|
|||||||
#define CDC_FS_BINTERVAL 0x10U
|
#define CDC_FS_BINTERVAL 0x10U
|
||||||
#endif /* CDC_FS_BINTERVAL */
|
#endif /* CDC_FS_BINTERVAL */
|
||||||
|
|
||||||
|
#ifndef CDC_CMD_PACKET_SIZE
|
||||||
|
#define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
||||||
|
#endif /* CDC_CMD_PACKET_SIZE */
|
||||||
|
|
||||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||||
#define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
#define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
||||||
#define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
#define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||||
#define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
|
||||||
|
|
||||||
#define USB_CDC_CONFIG_DESC_SIZ 67U
|
#define USB_CDC_CONFIG_DESC_SIZ 67U
|
||||||
#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||||
@@ -148,12 +157,17 @@ extern USBD_ClassTypeDef USBD_CDC;
|
|||||||
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_ItfTypeDef *fops);
|
USBD_CDC_ItfTypeDef *fops);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||||
|
uint32_t length, uint8_t ClassId);
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId);
|
||||||
|
#else
|
||||||
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||||
uint32_t length);
|
uint32_t length);
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
||||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
|
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -105,13 +105,14 @@ static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re
|
|||||||
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
|
||||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length);
|
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -126,7 +127,7 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -149,113 +150,22 @@ USBD_ClassTypeDef USBD_CDC =
|
|||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_CDC_GetHSCfgDesc,
|
USBD_CDC_GetHSCfgDesc,
|
||||||
USBD_CDC_GetFSCfgDesc,
|
USBD_CDC_GetFSCfgDesc,
|
||||||
USBD_CDC_GetOtherSpeedCfgDesc,
|
USBD_CDC_GetOtherSpeedCfgDesc,
|
||||||
USBD_CDC_GetDeviceQualifierDescriptor,
|
USBD_CDC_GetDeviceQualifierDescriptor,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB CDC device Configuration Descriptor */
|
/* USB CDC device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
|
||||||
/* Configuration Descriptor */
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
|
||||||
0x00,
|
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
|
||||||
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) */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Interface Descriptor */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints: One endpoints used */
|
|
||||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
|
||||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
|
||||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Header Functional Descriptor */
|
|
||||||
0x05, /* bLength: Endpoint Descriptor size */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
|
||||||
0x10, /* bcdCDC: spec release number */
|
|
||||||
0x01,
|
|
||||||
|
|
||||||
/* Call Management Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
|
||||||
0x00, /* bmCapabilities: D0+D1 */
|
|
||||||
0x01, /* bDataInterface: 1 */
|
|
||||||
|
|
||||||
/* ACM Functional Descriptor */
|
|
||||||
0x04, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
|
||||||
0x02, /* bmCapabilities */
|
|
||||||
|
|
||||||
/* Union Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x06, /* bDescriptorSubtype: Union func desc */
|
|
||||||
0x00, /* bMasterInterface: Communication class interface */
|
|
||||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
|
||||||
|
|
||||||
/* Endpoint 2 Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_CMD_EP, /* bEndpointAddress */
|
|
||||||
0x03, /* bmAttributes: Interrupt */
|
|
||||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
|
||||||
CDC_HS_BINTERVAL, /* bInterval */
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Data class interface descriptor */
|
|
||||||
0x09, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
|
||||||
0x01, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints: Two endpoints used */
|
|
||||||
0x0A, /* bInterfaceClass: CDC */
|
|
||||||
0x00, /* bInterfaceSubClass */
|
|
||||||
0x00, /* bInterfaceProtocol */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Endpoint OUT Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_OUT_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
0x00, /* bInterval */
|
|
||||||
|
|
||||||
/* Endpoint IN Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_IN_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
0x00 /* bInterval */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* USB CDC device Configuration Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|
||||||
{
|
{
|
||||||
/* Configuration Descriptor */
|
/* Configuration Descriptor */
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
@@ -264,12 +174,13 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN
|
|||||||
0x00,
|
0x00,
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
0x02, /* bNumInterfaces: 2 interfaces */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
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)
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
@@ -352,102 +263,11 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN
|
|||||||
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||||
0x00 /* bInterval */
|
0x00 /* bInterval */
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
static uint8_t CDCInEpAdd = CDC_IN_EP;
|
||||||
{
|
static uint8_t CDCOutEpAdd = CDC_OUT_EP;
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
static uint8_t CDCCmdEpAdd = CDC_CMD_EP;
|
||||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
|
||||||
USB_CDC_CONFIG_DESC_SIZ,
|
|
||||||
0x00,
|
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
|
||||||
0x01, /* bConfigurationValue */
|
|
||||||
0x04, /* iConfiguration */
|
|
||||||
#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) */
|
|
||||||
|
|
||||||
/* Interface Descriptor */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
|
||||||
/* Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints: One endpoints used */
|
|
||||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
|
||||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
|
||||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Header Functional Descriptor */
|
|
||||||
0x05, /* bLength: Endpoint Descriptor size */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
|
||||||
0x10, /* bcdCDC: spec release number */
|
|
||||||
0x01,
|
|
||||||
|
|
||||||
/* Call Management Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
|
||||||
0x00, /* bmCapabilities */
|
|
||||||
0x01, /* bDataInterface */
|
|
||||||
|
|
||||||
/* ACM Functional Descriptor */
|
|
||||||
0x04, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
|
||||||
0x02, /* bmCapabilities */
|
|
||||||
|
|
||||||
/* Union Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x06, /* bDescriptorSubtype: Union func desc */
|
|
||||||
0x00, /* bMasterInterface: Communication class interface */
|
|
||||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
|
||||||
|
|
||||||
/* Endpoint 2 Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_CMD_EP, /* bEndpointAddress */
|
|
||||||
0x03, /* bmAttributes: Interrupt */
|
|
||||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
|
||||||
CDC_FS_BINTERVAL, /* bInterval */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/*Data class interface descriptor*/
|
|
||||||
0x09, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
|
||||||
0x01, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints: Two endpoints used */
|
|
||||||
0x0A, /* bInterfaceClass: CDC */
|
|
||||||
0x00, /* bInterfaceSubClass */
|
|
||||||
0x00, /* bInterfaceProtocol */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/*Endpoint OUT Descriptor*/
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_OUT_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
0x40, /* wMaxPacketSize */
|
|
||||||
0x00,
|
|
||||||
0x00, /* bInterval */
|
|
||||||
|
|
||||||
/*Endpoint IN Descriptor*/
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_IN_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
0x40, /* wMaxPacketSize */
|
|
||||||
0x00,
|
|
||||||
0x00 /* bInterval */
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -473,68 +293,85 @@ static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pClassData = (void *)hcdc;
|
(void)USBD_memset(hcdc, 0, sizeof(USBD_CDC_HandleTypeDef));
|
||||||
|
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hcdc;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CDCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, CDCInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_DATA_HS_IN_PACKET_SIZE);
|
CDC_DATA_HS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[CDCInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, CDCOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[CDCOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Set bInterval for CDC CMD Endpoint */
|
/* Set bInterval for CDC CMD Endpoint */
|
||||||
pdev->ep_in[CDC_CMD_EP & 0xFU].bInterval = CDC_HS_BINTERVAL;
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].bInterval = CDC_HS_BINTERVAL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, CDCInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_DATA_FS_IN_PACKET_SIZE);
|
CDC_DATA_FS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[CDCInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, CDCOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[CDCOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Set bInterval for CMD Endpoint */
|
/* Set bInterval for CMD Endpoint */
|
||||||
pdev->ep_in[CDC_CMD_EP & 0xFU].bInterval = CDC_FS_BINTERVAL;
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].bInterval = CDC_FS_BINTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open Command IN EP */
|
/* Open Command IN EP */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_CMD_EP, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
|
(void)USBD_LL_OpenEP(pdev, CDCCmdEpAdd, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
|
||||||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
hcdc->RxBuffer = NULL;
|
||||||
|
|
||||||
/* Init physical Interface components */
|
/* Init physical Interface components */
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||||
|
|
||||||
/* Init Xfer states */
|
/* Init Xfer states */
|
||||||
hcdc->TxState = 0U;
|
hcdc->TxState = 0U;
|
||||||
hcdc->RxState = 0U;
|
hcdc->RxState = 0U;
|
||||||
|
|
||||||
|
if (hcdc->RxBuffer == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,24 +389,33 @@ static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this CDC class instance */
|
||||||
|
CDCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
CDCCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close EP IN */
|
/* Close EP IN */
|
||||||
(void)USBD_LL_CloseEP(pdev, CDC_IN_EP);
|
(void)USBD_LL_CloseEP(pdev, CDCInEpAdd);
|
||||||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[CDCInEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP OUT */
|
/* Close EP OUT */
|
||||||
(void)USBD_LL_CloseEP(pdev, CDC_OUT_EP);
|
(void)USBD_LL_CloseEP(pdev, CDCOutEpAdd);
|
||||||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 0U;
|
pdev->ep_out[CDCOutEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close Command IN EP */
|
/* Close Command IN EP */
|
||||||
(void)USBD_LL_CloseEP(pdev, CDC_CMD_EP);
|
(void)USBD_LL_CloseEP(pdev, CDCCmdEpAdd);
|
||||||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].is_used = 0U;
|
||||||
pdev->ep_in[CDC_CMD_EP & 0xFU].bInterval = 0U;
|
pdev->ep_in[CDCCmdEpAdd & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if (pdev->pClassData != NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
(void)USBD_free(pdev->pClassData);
|
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,7 +432,7 @@ static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint8_t ifalt = 0U;
|
uint8_t ifalt = 0U;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
@@ -604,9 +450,9 @@ static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
{
|
{
|
||||||
if ((req->bmRequest & 0x80U) != 0U)
|
if ((req->bmRequest & 0x80U) != 0U)
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(req->bRequest,
|
||||||
(uint8_t *)hcdc->data,
|
(uint8_t *)hcdc->data,
|
||||||
req->wLength);
|
req->wLength);
|
||||||
|
|
||||||
len = MIN(CDC_REQ_MAX_DATA_SIZE, req->wLength);
|
len = MIN(CDC_REQ_MAX_DATA_SIZE, req->wLength);
|
||||||
(void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, len);
|
(void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, len);
|
||||||
@@ -621,8 +467,8 @@ static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(req->bRequest,
|
||||||
(uint8_t *)req, 0U);
|
(uint8_t *)req, 0U);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -692,18 +538,18 @@ static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
USBD_CDC_HandleTypeDef *hcdc;
|
USBD_CDC_HandleTypeDef *hcdc;
|
||||||
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
|
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if ((pdev->ep_in[epnum].total_length > 0U) &&
|
if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
|
||||||
((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
|
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U))
|
||||||
{
|
{
|
||||||
/* Update the packet total length */
|
/* Update the packet total length */
|
||||||
pdev->ep_in[epnum].total_length = 0U;
|
pdev->ep_in[epnum & 0xFU].total_length = 0U;
|
||||||
|
|
||||||
/* Send ZLP */
|
/* Send ZLP */
|
||||||
(void)USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
(void)USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||||
@@ -712,9 +558,9 @@ static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
{
|
{
|
||||||
hcdc->TxState = 0U;
|
hcdc->TxState = 0U;
|
||||||
|
|
||||||
if (((USBD_CDC_ItfTypeDef *)pdev->pUserData)->TransmitCplt != NULL)
|
if (((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->TransmitCplt(hcdc->TxBuffer, &hcdc->TxLength, epnum);
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt(hcdc->TxBuffer, &hcdc->TxLength, epnum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,9 +576,9 @@ static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
@@ -743,7 +589,7 @@ static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
/* USB data will be immediately processed, this allow next USB traffic being
|
/* USB data will be immediately processed, this allow next USB traffic being
|
||||||
NAKed till the end of the application Xfer */
|
NAKed till the end of the application Xfer */
|
||||||
|
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -756,24 +602,24 @@ static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
if ((pdev->pUserData[pdev->classId] != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(hcdc->CmdOpCode,
|
||||||
(uint8_t *)hcdc->data,
|
(uint8_t *)hcdc->data,
|
||||||
(uint16_t)hcdc->CmdLength);
|
(uint16_t)hcdc->CmdLength);
|
||||||
hcdc->CmdOpCode = 0xFFU;
|
hcdc->CmdOpCode = 0xFFU;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_GetFSCfgDesc
|
* @brief USBD_CDC_GetFSCfgDesc
|
||||||
* Return configuration descriptor
|
* Return configuration descriptor
|
||||||
@@ -782,9 +628,27 @@ static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CDC_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_IN_EP);
|
||||||
|
|
||||||
return USBD_CDC_CfgFSDesc;
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_CfgDesc);
|
||||||
|
return USBD_CDC_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -795,9 +659,27 @@ static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CDC_CfgHSDesc);
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_IN_EP);
|
||||||
|
|
||||||
return USBD_CDC_CfgHSDesc;
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_CfgDesc);
|
||||||
|
return USBD_CDC_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -808,9 +690,27 @@ static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CDC_OtherSpeedCfgDesc);
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_CfgDesc, CDC_IN_EP);
|
||||||
|
|
||||||
return USBD_CDC_OtherSpeedCfgDesc;
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CDC_CfgDesc);
|
||||||
|
return USBD_CDC_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -825,7 +725,7 @@ uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_CDC_DeviceQualifierDesc;
|
return USBD_CDC_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_RegisterInterface
|
* @brief USBD_CDC_RegisterInterface
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
@@ -840,22 +740,31 @@ uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_SetTxBuffer
|
* @brief USBD_CDC_SetTxBuffer
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param pbuff: Tx Buffer
|
* @param pbuff: Tx Buffer
|
||||||
* @param length: Tx Buffer length
|
* @param length: length of data to be sent
|
||||||
|
* @param ClassId: The Class ID
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuff, uint32_t length, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuff, uint32_t length)
|
uint8_t *pbuff, uint32_t length)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
@@ -876,7 +785,7 @@ uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
@@ -888,18 +797,32 @@ uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
|||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_TransmitPacket
|
* @brief USBD_CDC_TransmitPacket
|
||||||
* Transmit packet on IN endpoint
|
* Transmit packet on IN endpoint
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
|
* @param ClassId: The Class ID
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
USBD_StatusTypeDef ret = USBD_BUSY;
|
USBD_StatusTypeDef ret = USBD_BUSY;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CDCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, ClassId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
@@ -910,10 +833,10 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
|||||||
hcdc->TxState = 1U;
|
hcdc->TxState = 1U;
|
||||||
|
|
||||||
/* Update the packet total length */
|
/* Update the packet total length */
|
||||||
pdev->ep_in[CDC_IN_EP & 0xFU].total_length = hcdc->TxLength;
|
pdev->ep_in[CDCInEpAdd & 0xFU].total_length = hcdc->TxLength;
|
||||||
|
|
||||||
/* Transmit next packet */
|
/* Transmit next packet */
|
||||||
(void)USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer, hcdc->TxLength);
|
(void)USBD_LL_Transmit(pdev, CDCInEpAdd, hcdc->TxBuffer, hcdc->TxLength);
|
||||||
|
|
||||||
ret = USBD_OK;
|
ret = USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -929,9 +852,14 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CDCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
@@ -939,13 +867,13 @@ uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
|||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
(void)USBD_LL_PrepareReceive(pdev, CDCOutEpAdd, hcdc->RxBuffer,
|
||||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,6 +127,8 @@ static int8_t TEMPLATE_DeInit(void)
|
|||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||||
{
|
{
|
||||||
|
UNUSED(length);
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||||
|
|||||||
@@ -42,10 +42,15 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
/* Comment this define in order to disable the CDC ECM Notification pipe */
|
/* Comment this define in order to disable the CDC ECM Notification pipe */
|
||||||
|
|
||||||
|
#ifndef CDC_ECM_IN_EP
|
||||||
#define CDC_ECM_IN_EP 0x81U /* EP1 for data IN */
|
#define CDC_ECM_IN_EP 0x81U /* EP1 for data IN */
|
||||||
|
#endif /* CDC_ECM_IN_EP */
|
||||||
|
#ifndef CDC_ECM_OUT_EP
|
||||||
#define CDC_ECM_OUT_EP 0x01U /* EP1 for data OUT */
|
#define CDC_ECM_OUT_EP 0x01U /* EP1 for data OUT */
|
||||||
|
#endif /* CDC_ECM_OUT_EP */
|
||||||
|
#ifndef CDC_ECM_CMD_EP
|
||||||
#define CDC_ECM_CMD_EP 0x82U /* EP2 for CDC ECM commands */
|
#define CDC_ECM_CMD_EP 0x82U /* EP2 for CDC ECM commands */
|
||||||
|
#endif /* CDC_ECM_CMD_EP */
|
||||||
|
|
||||||
#ifndef CDC_ECM_CMD_ITF_NBR
|
#ifndef CDC_ECM_CMD_ITF_NBR
|
||||||
#define CDC_ECM_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
#define CDC_ECM_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
||||||
@@ -63,6 +68,10 @@ extern "C" {
|
|||||||
#define CDC_ECM_FS_BINTERVAL 0x10U
|
#define CDC_ECM_FS_BINTERVAL 0x10U
|
||||||
#endif /* CDC_ECM_FS_BINTERVAL */
|
#endif /* CDC_ECM_FS_BINTERVAL */
|
||||||
|
|
||||||
|
#ifndef CDC_ECM_CMD_PACKET_SIZE
|
||||||
|
#define CDC_ECM_CMD_PACKET_SIZE 16U /* Control Endpoint Packet size */
|
||||||
|
#endif /* CDC_ECM_CMD_PACKET_SIZE */
|
||||||
|
|
||||||
#ifndef USBD_SUPPORT_USER_STRING_DESC
|
#ifndef USBD_SUPPORT_USER_STRING_DESC
|
||||||
#define USBD_SUPPORT_USER_STRING_DESC 1U
|
#define USBD_SUPPORT_USER_STRING_DESC 1U
|
||||||
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
@@ -70,7 +79,6 @@ extern "C" {
|
|||||||
/* CDC_ECM Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
/* CDC_ECM Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||||
#define CDC_ECM_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
#define CDC_ECM_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
||||||
#define CDC_ECM_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
#define CDC_ECM_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||||
#define CDC_ECM_CMD_PACKET_SIZE 16U /* Control Endpoint Packet size */
|
|
||||||
|
|
||||||
#define CDC_ECM_CONFIG_DESC_SIZ 79U
|
#define CDC_ECM_CONFIG_DESC_SIZ 79U
|
||||||
|
|
||||||
@@ -172,6 +180,26 @@ typedef struct
|
|||||||
uint8_t data[8];
|
uint8_t data[8];
|
||||||
} USBD_CDC_ECM_NotifTypeDef;
|
} USBD_CDC_ECM_NotifTypeDef;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ECM Class specification revision 1.2
|
||||||
|
* Table 3: Ethernet Networking Functional Descriptor
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bFunctionLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubType;
|
||||||
|
uint8_t iMacAddress;
|
||||||
|
uint8_t bEthernetStatistics3;
|
||||||
|
uint8_t bEthernetStatistics2;
|
||||||
|
uint8_t bEthernetStatistics1;
|
||||||
|
uint8_t bEthernetStatistics0;
|
||||||
|
uint16_t wMaxSegmentSize;
|
||||||
|
uint16_t bNumberMCFiltes;
|
||||||
|
uint8_t bNumberPowerFiltes;
|
||||||
|
} __PACKED USBD_ECMFuncDescTypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t data[CDC_ECM_DATA_BUFFER_SIZE / 4U]; /* Force 32-bit alignment */
|
uint32_t data[CDC_ECM_DATA_BUFFER_SIZE / 4U]; /* Force 32-bit alignment */
|
||||||
@@ -193,12 +221,6 @@ typedef struct
|
|||||||
USBD_CDC_ECM_NotifTypeDef Req;
|
USBD_CDC_ECM_NotifTypeDef Req;
|
||||||
} USBD_CDC_ECM_HandleTypeDef;
|
} USBD_CDC_ECM_HandleTypeDef;
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
NETWORK_CONNECTION = 0x00,
|
|
||||||
RESPONSE_AVAILABLE = 0x01,
|
|
||||||
CONNECTION_SPEED_CHANGE = 0x2A
|
|
||||||
} USBD_CDC_ECM_NotifCodeTypeDef;
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Exported_Macros
|
/** @defgroup USBD_CORE_Exported_Macros
|
||||||
* @{
|
* @{
|
||||||
@@ -224,17 +246,21 @@ extern USBD_ClassTypeDef USBD_CDC_ECM;
|
|||||||
uint8_t USBD_CDC_ECM_RegisterInterface(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_ECM_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_ECM_ItfTypeDef *fops);
|
USBD_CDC_ECM_ItfTypeDef *fops);
|
||||||
|
|
||||||
uint8_t USBD_CDC_ECM_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
|
||||||
uint32_t length);
|
|
||||||
|
|
||||||
uint8_t USBD_CDC_ECM_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
uint8_t USBD_CDC_ECM_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
||||||
|
|
||||||
uint8_t USBD_CDC_ECM_ReceivePacket(USBD_HandleTypeDef *pdev);
|
uint8_t USBD_CDC_ECM_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId);
|
||||||
|
uint8_t USBD_CDC_ECM_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||||
|
uint32_t length, uint8_t ClassId);
|
||||||
|
#else
|
||||||
uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev);
|
uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||||
|
uint8_t USBD_CDC_ECM_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||||
|
uint32_t length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_ECM_NotifCodeTypeDef Notif,
|
USBD_CDC_NotifCodeTypeDef Notif,
|
||||||
uint16_t bVal, uint8_t *pData);
|
uint16_t bVal, uint8_t *pData);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ EndBSPDependencies */
|
|||||||
|
|
||||||
#ifndef __USBD_CDC_ECM_IF_H
|
#ifndef __USBD_CDC_ECM_IF_H
|
||||||
#include "usbd_cdc_ecm_if_template.h"
|
#include "usbd_cdc_ecm_if_template.h"
|
||||||
#endif
|
#endif /* __USBD_CDC_ECM_IF_H */
|
||||||
|
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
@@ -83,19 +83,20 @@ static uint8_t USBD_CDC_ECM_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
|||||||
static uint8_t USBD_CDC_ECM_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
static uint8_t USBD_CDC_ECM_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
static uint8_t USBD_CDC_ECM_Setup(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_ECM_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req);
|
USBD_SetupReqTypedef *req);
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_CDC_ECM_GetFSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_ECM_GetFSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CDC_ECM_GetHSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_ECM_GetHSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CDC_ECM_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_ECM_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CDC_ECM_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_ECM_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
static uint8_t *USBD_CDC_ECM_USRStringDescriptor(USBD_HandleTypeDef *pdev,
|
static uint8_t *USBD_CDC_ECM_USRStringDescriptor(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t index, uint16_t *length);
|
uint8_t index, uint16_t *length);
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
uint8_t *USBD_CDC_ECM_GetDeviceQualifierDescriptor(uint16_t *length);
|
uint8_t *USBD_CDC_ECM_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_ECM_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_ECM_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -110,7 +111,7 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_ECM_DeviceQualifierDesc[USB_LEN_DEV_QUALIF
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
static uint32_t ConnSpeedTab[2] = {CDC_ECM_CONNECT_SPEED_UPSTREAM,
|
static uint32_t ConnSpeedTab[2] = {CDC_ECM_CONNECT_SPEED_UPSTREAM,
|
||||||
CDC_ECM_CONNECT_SPEED_DOWNSTREAM
|
CDC_ECM_CONNECT_SPEED_DOWNSTREAM
|
||||||
};
|
};
|
||||||
@@ -137,129 +138,25 @@ USBD_ClassTypeDef USBD_CDC_ECM =
|
|||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_CDC_ECM_GetHSCfgDesc,
|
USBD_CDC_ECM_GetHSCfgDesc,
|
||||||
USBD_CDC_ECM_GetFSCfgDesc,
|
USBD_CDC_ECM_GetFSCfgDesc,
|
||||||
USBD_CDC_ECM_GetOtherSpeedCfgDesc,
|
USBD_CDC_ECM_GetOtherSpeedCfgDesc,
|
||||||
USBD_CDC_ECM_GetDeviceQualifierDescriptor,
|
USBD_CDC_ECM_GetDeviceQualifierDescriptor,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
USBD_CDC_ECM_USRStringDescriptor,
|
USBD_CDC_ECM_USRStringDescriptor,
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
};
|
};
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
|
||||||
/* USB CDC_ECM device Configuration Descriptor */
|
/* USB CDC_ECM device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_ECM_CfgHSDesc[] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_ECM_CfgDesc[] __ALIGN_END =
|
||||||
{
|
|
||||||
/* Configuration Descriptor */
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
LOBYTE(CDC_ECM_CONFIG_DESC_SIZ), /* wTotalLength:no of returned bytes */
|
|
||||||
HIBYTE(CDC_ECM_CONFIG_DESC_SIZ),
|
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
|
||||||
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) */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* IAD descriptor */
|
|
||||||
0x08, /* bLength */
|
|
||||||
0x0B, /* bDescriptorType */
|
|
||||||
0x00, /* bFirstInterface */
|
|
||||||
0x02, /* bInterfaceCount */
|
|
||||||
0x02, /* bFunctionClass (Wireless Controller) */
|
|
||||||
0x06, /* bFunctionSubClass */
|
|
||||||
0x00, /* bFunctionProtocol */
|
|
||||||
0x00, /* iFunction */
|
|
||||||
|
|
||||||
/* Interface Descriptor */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
CDC_ECM_CMD_ITF_NBR, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints: One endpoint used */
|
|
||||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
|
||||||
0x06, /* bInterfaceSubClass: Ethernet Control Model */
|
|
||||||
0x00, /* bInterfaceProtocol: No specific protocol required */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Header Functional Descriptor */
|
|
||||||
0x05, /* bLength: Endpoint Descriptor size */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x00, /* bDescriptorSubtype: Header functional descriptor */
|
|
||||||
0x10, /* bcd CDC_ECM: spec release number: 1.10 */
|
|
||||||
0x01,
|
|
||||||
|
|
||||||
/* CDC_ECM Functional Descriptor */
|
|
||||||
0x0D, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x0F, /* Ethernet Networking functional descriptor subtype */
|
|
||||||
CDC_ECM_MAC_STRING_INDEX, /* Device's MAC string index */
|
|
||||||
CDC_ECM_ETH_STATS_BYTE3, /* Ethernet statistics byte 3 (bitmap) */
|
|
||||||
CDC_ECM_ETH_STATS_BYTE2, /* Ethernet statistics byte 2 (bitmap) */
|
|
||||||
CDC_ECM_ETH_STATS_BYTE1, /* Ethernet statistics byte 1 (bitmap) */
|
|
||||||
CDC_ECM_ETH_STATS_BYTE0, /* Ethernet statistics byte 0 (bitmap) */
|
|
||||||
LOBYTE(CDC_ECM_ETH_MAX_SEGSZE),
|
|
||||||
HIBYTE(CDC_ECM_ETH_MAX_SEGSZE), /* wMaxSegmentSize: Ethernet Maximum Segment size, typically 1514 bytes */
|
|
||||||
LOBYTE(CDC_ECM_ETH_NBR_MACFILTERS),
|
|
||||||
HIBYTE(CDC_ECM_ETH_NBR_MACFILTERS), /* wNumberMCFilters: the number of multicast filters */
|
|
||||||
CDC_ECM_ETH_NBR_PWRFILTERS, /* bNumberPowerFilters: the number of wakeup power filters */
|
|
||||||
|
|
||||||
/* Union Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x06, /* bDescriptorSubtype: Union functional descriptor */
|
|
||||||
0x00, /* bMasterInterface: Communication class interface */
|
|
||||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
|
||||||
|
|
||||||
/* Communication Endpoint Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_ECM_CMD_EP, /* bEndpointAddress */
|
|
||||||
0x03, /* bmAttributes: Interrupt */
|
|
||||||
LOBYTE(CDC_ECM_CMD_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_ECM_CMD_PACKET_SIZE),
|
|
||||||
CDC_ECM_HS_BINTERVAL, /* bInterval */
|
|
||||||
|
|
||||||
/*----------------------*/
|
|
||||||
|
|
||||||
/* Data class interface descriptor */
|
|
||||||
0x09, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
|
||||||
CDC_ECM_COM_ITF_NBR, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints: Two endpoints used */
|
|
||||||
0x0A, /* bInterfaceClass: CDC */
|
|
||||||
0x00, /* bInterfaceSubClass */
|
|
||||||
0x00, /* bInterfaceProtocol */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Endpoint OUT Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_ECM_OUT_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(CDC_ECM_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_ECM_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
0x00, /* bInterval */
|
|
||||||
|
|
||||||
/* Endpoint IN Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_ECM_IN_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(CDC_ECM_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_ECM_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
0x00 /* bInterval */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* USB CDC_ECM device Configuration Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_ECM_CfgFSDesc[] __ALIGN_END =
|
|
||||||
{
|
{
|
||||||
/* Configuration Descriptor */
|
/* Configuration Descriptor */
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
@@ -268,12 +165,13 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_ECM_CfgFSDesc[] __ALIGN_END =
|
|||||||
HIBYTE(CDC_ECM_CONFIG_DESC_SIZ),
|
HIBYTE(CDC_ECM_CONFIG_DESC_SIZ),
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
0x02, /* bNumInterfaces: 2 interfaces */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
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)
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
@@ -368,115 +266,11 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_ECM_CfgFSDesc[] __ALIGN_END =
|
|||||||
HIBYTE(CDC_ECM_DATA_FS_MAX_PACKET_SIZE),
|
HIBYTE(CDC_ECM_DATA_FS_MAX_PACKET_SIZE),
|
||||||
0x00 /* bInterval */
|
0x00 /* bInterval */
|
||||||
} ;
|
} ;
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_ECM_OtherSpeedCfgDesc[] __ALIGN_END =
|
static uint8_t ECMInEpAdd = CDC_ECM_IN_EP;
|
||||||
{
|
static uint8_t ECMOutEpAdd = CDC_ECM_OUT_EP;
|
||||||
/* Configuration Descriptor */
|
static uint8_t ECMCmdEpAdd = CDC_ECM_CMD_EP;
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
LOBYTE(CDC_ECM_CONFIG_DESC_SIZ), /* wTotalLength */
|
|
||||||
HIBYTE(CDC_ECM_CONFIG_DESC_SIZ),
|
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
|
||||||
0x04, /* 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) */
|
|
||||||
|
|
||||||
/*--------------------------------------- ------------------------------------*/
|
|
||||||
/* IAD descriptor */
|
|
||||||
0x08, /* bLength */
|
|
||||||
0x0B, /* bDescriptorType */
|
|
||||||
0x00, /* bFirstInterface */
|
|
||||||
0x02, /* bInterfaceCount */
|
|
||||||
0x02, /* bFunctionClass (Wireless Controller) */
|
|
||||||
0x06, /* bFunctionSubClass */
|
|
||||||
0x00, /* bFunctionProtocol */
|
|
||||||
0x00, /* iFunction */
|
|
||||||
|
|
||||||
/* Interface Descriptor */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints: One endpoint used */
|
|
||||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
|
||||||
0x06, /* bInterfaceSubClass: Ethernet Control Model */
|
|
||||||
0x00, /* bInterfaceProtocol: No specific protocol required */
|
|
||||||
0x00, /* iInterface: */
|
|
||||||
|
|
||||||
/* Header Functional Descriptor */
|
|
||||||
0x05, /* bLength: Endpoint Descriptor size */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x00, /* bDescriptorSubtype: Header functional descriptor */
|
|
||||||
0x10, /* bcd CDC_ECM : spec release number: 1.20 */
|
|
||||||
0x01,
|
|
||||||
|
|
||||||
/* CDC_ECM Functional Descriptor */
|
|
||||||
0x0D, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x0F, /* Ethernet Networking functional descriptor subtype */
|
|
||||||
CDC_ECM_MAC_STRING_INDEX, /* Device's MAC string index */
|
|
||||||
CDC_ECM_ETH_STATS_BYTE3, /* Ethernet statistics byte 3 (bitmap) */
|
|
||||||
CDC_ECM_ETH_STATS_BYTE2, /* Ethernet statistics byte 2 (bitmap) */
|
|
||||||
CDC_ECM_ETH_STATS_BYTE1, /* Ethernet statistics byte 1 (bitmap) */
|
|
||||||
CDC_ECM_ETH_STATS_BYTE0, /* Ethernet statistics byte 0 (bitmap) */
|
|
||||||
LOBYTE(CDC_ECM_ETH_MAX_SEGSZE),
|
|
||||||
HIBYTE(CDC_ECM_ETH_MAX_SEGSZE), /* wMaxSegmentSize: Ethernet Maximum Segment size, typically 1514 bytes */
|
|
||||||
LOBYTE(CDC_ECM_ETH_NBR_MACFILTERS),
|
|
||||||
HIBYTE(CDC_ECM_ETH_NBR_MACFILTERS), /* wNumberMCFilters: the number of multicast filters */
|
|
||||||
CDC_ECM_ETH_NBR_PWRFILTERS, /* bNumberPowerFilters: the number of wakeup power filters */
|
|
||||||
|
|
||||||
/* Union Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x06, /* bDescriptorSubtype: Union functional descriptor */
|
|
||||||
0x00, /* bMasterInterface: Communication class interface */
|
|
||||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
|
||||||
|
|
||||||
/* Communication Endpoint Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_ECM_CMD_EP, /* bEndpointAddress */
|
|
||||||
0x03, /* bmAttributes: Interrupt */
|
|
||||||
LOBYTE(CDC_ECM_CMD_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_ECM_CMD_PACKET_SIZE),
|
|
||||||
CDC_ECM_FS_BINTERVAL, /* bInterval */
|
|
||||||
|
|
||||||
/*----------------------*/
|
|
||||||
|
|
||||||
/* Data class interface descriptor */
|
|
||||||
0x09, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: interface */
|
|
||||||
0x01, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints: Two endpoints used */
|
|
||||||
0x0A, /* bInterfaceClass: CDC */
|
|
||||||
0x00, /* bInterfaceSubClass */
|
|
||||||
0x00, /* bInterfaceProtocol */
|
|
||||||
0x00, /* iInterface: */
|
|
||||||
|
|
||||||
/* Endpoint OUT Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_ECM_OUT_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
0x40, /* wMaxPacketSize */
|
|
||||||
0x00,
|
|
||||||
0x00, /* bInterval */
|
|
||||||
|
|
||||||
/* Endpoint IN Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_ECM_IN_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
0x40, /* wMaxPacketSize */
|
|
||||||
0x00,
|
|
||||||
0x00 /* bInterval */
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -499,57 +293,69 @@ static uint8_t USBD_CDC_ECM_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc;
|
USBD_CDC_ECM_HandleTypeDef *hcdc;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
ECMInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
ECMOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
ECMCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
hcdc = (USBD_CDC_ECM_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_ECM_HandleTypeDef));
|
hcdc = (USBD_CDC_ECM_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_ECM_HandleTypeDef));
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pClassData = (void *)hcdc;
|
(void)USBD_memset(hcdc, 0, sizeof(USBD_CDC_ECM_HandleTypeDef));
|
||||||
|
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hcdc;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_ECM_IN_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, ECMInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_ECM_DATA_HS_IN_PACKET_SIZE);
|
CDC_ECM_DATA_HS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CDC_ECM_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[ECMInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_ECM_OUT_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, ECMOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_ECM_DATA_HS_OUT_PACKET_SIZE);
|
CDC_ECM_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CDC_ECM_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[ECMOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Set bInterval for CDC ECM CMD Endpoint */
|
/* Set bInterval for CDC ECM CMD Endpoint */
|
||||||
pdev->ep_in[CDC_ECM_CMD_EP & 0xFU].bInterval = CDC_ECM_HS_BINTERVAL;
|
pdev->ep_in[ECMCmdEpAdd & 0xFU].bInterval = CDC_ECM_HS_BINTERVAL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_ECM_IN_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, ECMInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_ECM_DATA_FS_IN_PACKET_SIZE);
|
CDC_ECM_DATA_FS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CDC_ECM_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[ECMInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_ECM_OUT_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, ECMOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_ECM_DATA_FS_OUT_PACKET_SIZE);
|
CDC_ECM_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CDC_ECM_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[ECMOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Set bInterval for CDC ECM CMD Endpoint */
|
/* Set bInterval for CDC ECM CMD Endpoint */
|
||||||
pdev->ep_in[CDC_ECM_CMD_EP & 0xFU].bInterval = CDC_ECM_FS_BINTERVAL;
|
pdev->ep_in[ECMCmdEpAdd & 0xFU].bInterval = CDC_ECM_FS_BINTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open Command IN EP */
|
/* Open Command IN EP */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_ECM_CMD_EP, USBD_EP_TYPE_INTR, CDC_ECM_CMD_PACKET_SIZE);
|
(void)USBD_LL_OpenEP(pdev, ECMCmdEpAdd, USBD_EP_TYPE_INTR, CDC_ECM_CMD_PACKET_SIZE);
|
||||||
pdev->ep_in[CDC_ECM_CMD_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[ECMCmdEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
hcdc->RxBuffer = NULL;
|
||||||
|
|
||||||
/* Init physical Interface components */
|
/* Init physical Interface components */
|
||||||
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData)->Init();
|
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||||
|
|
||||||
/* Init Xfer states */
|
/* Init Xfer states */
|
||||||
hcdc->TxState = 0U;
|
hcdc->TxState = 0U;
|
||||||
@@ -558,10 +364,16 @@ static uint8_t USBD_CDC_ECM_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
hcdc->TxLength = 0U;
|
hcdc->TxLength = 0U;
|
||||||
hcdc->LinkStatus = 0U;
|
hcdc->LinkStatus = 0U;
|
||||||
hcdc->NotificationStatus = 0U;
|
hcdc->NotificationStatus = 0U;
|
||||||
hcdc->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? CDC_ECM_DATA_HS_MAX_PACKET_SIZE : CDC_ECM_DATA_FS_MAX_PACKET_SIZE;
|
hcdc->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? CDC_ECM_DATA_HS_MAX_PACKET_SIZE : \
|
||||||
|
CDC_ECM_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
|
||||||
|
if (hcdc->RxBuffer == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_ECM_OUT_EP, hcdc->RxBuffer, hcdc->MaxPcktLen);
|
(void)USBD_LL_PrepareReceive(pdev, ECMOutEpAdd, hcdc->RxBuffer, hcdc->MaxPcktLen);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -577,24 +389,32 @@ static uint8_t USBD_CDC_ECM_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
ECMInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
ECMOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
ECMCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close EP IN */
|
/* Close EP IN */
|
||||||
(void)USBD_LL_CloseEP(pdev, CDC_ECM_IN_EP);
|
(void)USBD_LL_CloseEP(pdev, ECMInEpAdd);
|
||||||
pdev->ep_in[CDC_ECM_IN_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[ECMInEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP OUT */
|
/* Close EP OUT */
|
||||||
(void)USBD_LL_CloseEP(pdev, CDC_ECM_OUT_EP);
|
(void)USBD_LL_CloseEP(pdev, ECMOutEpAdd);
|
||||||
pdev->ep_out[CDC_ECM_OUT_EP & 0xFU].is_used = 0U;
|
pdev->ep_out[ECMOutEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close Command IN EP */
|
/* Close Command IN EP */
|
||||||
(void)USBD_LL_CloseEP(pdev, CDC_ECM_CMD_EP);
|
(void)USBD_LL_CloseEP(pdev, ECMCmdEpAdd);
|
||||||
pdev->ep_in[CDC_ECM_CMD_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[ECMCmdEpAdd & 0xFU].is_used = 0U;
|
||||||
pdev->ep_in[CDC_ECM_CMD_EP & 0xFU].bInterval = 0U;
|
pdev->ep_in[ECMCmdEpAdd & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if (pdev->pClassData != NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,11 +428,10 @@ static uint8_t USBD_CDC_ECM_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_ECM_Setup(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_ECM_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
USBD_SetupReqTypedef *req)
|
|
||||||
{
|
{
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *) pdev->pClassData;
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *) pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_CDC_ECM_ItfTypeDef *EcmInterface = (USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData;
|
USBD_CDC_ECM_ItfTypeDef *EcmInterface = (USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
@@ -630,8 +449,7 @@ static uint8_t USBD_CDC_ECM_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
{
|
{
|
||||||
if ((req->bmRequest & 0x80U) != 0U)
|
if ((req->bmRequest & 0x80U) != 0U)
|
||||||
{
|
{
|
||||||
EcmInterface->Control(req->bRequest,
|
EcmInterface->Control(req->bRequest, (uint8_t *)hcdc->data, req->wLength);
|
||||||
(uint8_t *)hcdc->data, req->wLength);
|
|
||||||
|
|
||||||
len = MIN(CDC_ECM_DATA_BUFFER_SIZE, req->wLength);
|
len = MIN(CDC_ECM_DATA_BUFFER_SIZE, req->wLength);
|
||||||
(void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, len);
|
(void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, len);
|
||||||
@@ -713,21 +531,26 @@ static uint8_t USBD_CDC_ECM_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_ECM_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_CDC_ECM_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
|
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
ECMInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (epnum == (CDC_ECM_IN_EP & 0x7FU))
|
if (epnum == (ECMInEpAdd & 0x7FU))
|
||||||
{
|
{
|
||||||
if ((pdev->ep_in[epnum].total_length > 0U) &&
|
if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
|
||||||
((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
|
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U))
|
||||||
{
|
{
|
||||||
/* Update the packet total length */
|
/* Update the packet total length */
|
||||||
pdev->ep_in[epnum].total_length = 0U;
|
pdev->ep_in[epnum & 0xFU].total_length = 0U;
|
||||||
|
|
||||||
/* Send ZLP */
|
/* Send ZLP */
|
||||||
(void)USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
(void)USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||||
@@ -735,18 +558,18 @@ static uint8_t USBD_CDC_ECM_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
hcdc->TxState = 0U;
|
hcdc->TxState = 0U;
|
||||||
if (((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData)->TransmitCplt != NULL)
|
if (((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData)->TransmitCplt(hcdc->TxBuffer, &hcdc->TxLength, epnum);
|
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt(hcdc->TxBuffer,
|
||||||
|
&hcdc->TxLength, epnum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (epnum == (CDC_ECM_CMD_EP & 0x7FU))
|
else if (epnum == (ECMCmdEpAdd & 0x7FU))
|
||||||
{
|
{
|
||||||
if (hcdc->NotificationStatus != 0U)
|
if (hcdc->NotificationStatus != 0U)
|
||||||
{
|
{
|
||||||
(void)USBD_CDC_ECM_SendNotification(pdev, CONNECTION_SPEED_CHANGE,
|
(void)USBD_CDC_ECM_SendNotification(pdev, CONNECTION_SPEED_CHANGE, 0U, (uint8_t *)ConnSpeedTab);
|
||||||
0U, (uint8_t *)ConnSpeedTab);
|
|
||||||
|
|
||||||
hcdc->NotificationStatus = 0U;
|
hcdc->NotificationStatus = 0U;
|
||||||
}
|
}
|
||||||
@@ -768,15 +591,20 @@ static uint8_t USBD_CDC_ECM_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_ECM_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_CDC_ECM_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t CurrPcktLen;
|
uint32_t CurrPcktLen;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
ECMOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (epnum == CDC_ECM_OUT_EP)
|
if (epnum == ECMOutEpAdd)
|
||||||
{
|
{
|
||||||
/* Get the received data length */
|
/* Get the received data length */
|
||||||
CurrPcktLen = USBD_LL_GetRxDataSize(pdev, epnum);
|
CurrPcktLen = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||||
@@ -792,12 +620,12 @@ static uint8_t USBD_CDC_ECM_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
|
|
||||||
/* Process data by application (ie. copy to app buffer or notify user)
|
/* Process data by application (ie. copy to app buffer or notify user)
|
||||||
hcdc->RxLength must be reset to zero at the end of the call of this function */
|
hcdc->RxLength must be reset to zero at the end of the call of this function */
|
||||||
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData[pdev->classId])->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet in current/new frame */
|
/* Prepare Out endpoint to receive next packet in current/new frame */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_ECM_OUT_EP,
|
(void)USBD_LL_PrepareReceive(pdev, ECMOutEpAdd,
|
||||||
(uint8_t *)(hcdc->RxBuffer + hcdc->RxLength),
|
(uint8_t *)(hcdc->RxBuffer + hcdc->RxLength),
|
||||||
hcdc->MaxPcktLen);
|
hcdc->MaxPcktLen);
|
||||||
}
|
}
|
||||||
@@ -818,24 +646,24 @@ static uint8_t USBD_CDC_ECM_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_ECM_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_CDC_ECM_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
if ((pdev->pUserData[pdev->classId] != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||||
{
|
{
|
||||||
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(hcdc->CmdOpCode,
|
||||||
(uint8_t *)hcdc->data,
|
(uint8_t *)hcdc->data,
|
||||||
(uint16_t)hcdc->CmdLength);
|
(uint16_t)hcdc->CmdLength);
|
||||||
hcdc->CmdOpCode = 0xFFU;
|
hcdc->CmdOpCode = 0xFFU;
|
||||||
|
|
||||||
}
|
}
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_ECM_GetFSCfgDesc
|
* @brief USBD_CDC_ECM_GetFSCfgDesc
|
||||||
* Return configuration descriptor
|
* Return configuration descriptor
|
||||||
@@ -844,9 +672,27 @@ static uint8_t USBD_CDC_ECM_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_ECM_GetFSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CDC_ECM_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CDC_ECM_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_ECM_CfgDesc, CDC_ECM_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_ECM_CfgDesc, CDC_ECM_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_ECM_CfgDesc, CDC_ECM_IN_EP);
|
||||||
|
|
||||||
return USBD_CDC_ECM_CfgFSDesc;
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_ECM_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_ECM_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_ECM_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t) sizeof(USBD_CDC_ECM_CfgDesc);
|
||||||
|
return USBD_CDC_ECM_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -857,9 +703,27 @@ static uint8_t *USBD_CDC_ECM_GetFSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_ECM_GetHSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CDC_ECM_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t) sizeof(USBD_CDC_ECM_CfgHSDesc);
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_ECM_CfgDesc, CDC_ECM_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_ECM_CfgDesc, CDC_ECM_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_ECM_CfgDesc, CDC_ECM_IN_EP);
|
||||||
|
|
||||||
return USBD_CDC_ECM_CfgHSDesc;
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_ECM_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_ECM_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_ECM_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t) sizeof(USBD_CDC_ECM_CfgDesc);
|
||||||
|
return USBD_CDC_ECM_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -870,9 +734,27 @@ static uint8_t *USBD_CDC_ECM_GetHSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_ECM_GetOtherSpeedCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CDC_ECM_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CDC_ECM_OtherSpeedCfgDesc);
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_ECM_CfgDesc, CDC_ECM_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_ECM_CfgDesc, CDC_ECM_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_ECM_CfgDesc, CDC_ECM_IN_EP);
|
||||||
|
|
||||||
return USBD_CDC_ECM_OtherSpeedCfgDesc;
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_ECM_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_ECM_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_ECM_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t) sizeof(USBD_CDC_ECM_CfgDesc);
|
||||||
|
return USBD_CDC_ECM_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -887,7 +769,7 @@ uint8_t *USBD_CDC_ECM_GetDeviceQualifierDescriptor(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_CDC_ECM_DeviceQualifierDesc;
|
return USBD_CDC_ECM_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_ECM_RegisterInterface
|
* @brief USBD_CDC_ECM_RegisterInterface
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
@@ -902,7 +784,7 @@ uint8_t USBD_CDC_ECM_RegisterInterface(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -924,7 +806,10 @@ static uint8_t *USBD_CDC_ECM_USRStringDescriptor(USBD_HandleTypeDef *pdev, uint8
|
|||||||
/* Check if the requested string interface is supported */
|
/* Check if the requested string interface is supported */
|
||||||
if (index == CDC_ECM_MAC_STRING_INDEX)
|
if (index == CDC_ECM_MAC_STRING_INDEX)
|
||||||
{
|
{
|
||||||
USBD_GetString((uint8_t *)((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData)->pStrDesc, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)((USBD_CDC_ECM_ItfTypeDef *)pdev->pUserData[pdev->classId])->pStrDesc,
|
||||||
|
USBD_StrDesc,
|
||||||
|
length);
|
||||||
|
|
||||||
return USBD_StrDesc;
|
return USBD_StrDesc;
|
||||||
}
|
}
|
||||||
/* Not supported Interface Descriptor index */
|
/* Not supported Interface Descriptor index */
|
||||||
@@ -933,18 +818,25 @@ static uint8_t *USBD_CDC_ECM_USRStringDescriptor(USBD_HandleTypeDef *pdev, uint8
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_ECM_SetTxBuffer
|
* @brief USBD_CDC_ECM_SetTxBuffer
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param pbuff: Tx Buffer
|
* @param pbuff: Tx Buffer
|
||||||
* @param length: Tx Buffer length
|
* @param length: Tx Buffer length
|
||||||
|
* @param ClassId: The Class ID
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_ECM_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
uint8_t USBD_CDC_ECM_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length)
|
uint8_t USBD_CDC_ECM_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length)
|
||||||
{
|
{
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
@@ -966,7 +858,7 @@ uint8_t USBD_CDC_ECM_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint3
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_ECM_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
uint8_t USBD_CDC_ECM_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
||||||
{
|
{
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
@@ -978,18 +870,32 @@ uint8_t USBD_CDC_ECM_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
|||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_ECM_TransmitPacket
|
* @brief USBD_CDC_ECM_TransmitPacket
|
||||||
* Transmit packet on IN endpoint
|
* Transmit packet on IN endpoint
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
|
* @param ClassId: The Class ID
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
USBD_StatusTypeDef ret = USBD_BUSY;
|
USBD_StatusTypeDef ret = USBD_BUSY;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
ECMInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, ClassId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
@@ -1000,10 +906,10 @@ uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev)
|
|||||||
hcdc->TxState = 1U;
|
hcdc->TxState = 1U;
|
||||||
|
|
||||||
/* Update the packet total length */
|
/* Update the packet total length */
|
||||||
pdev->ep_in[CDC_ECM_IN_EP & 0xFU].total_length = hcdc->TxLength;
|
pdev->ep_in[ECMInEpAdd & 0xFU].total_length = hcdc->TxLength;
|
||||||
|
|
||||||
/* Transmit next packet */
|
/* Transmit next packet */
|
||||||
(void)USBD_LL_Transmit(pdev, CDC_ECM_IN_EP, hcdc->TxBuffer, hcdc->TxLength);
|
(void)USBD_LL_Transmit(pdev, ECMInEpAdd, hcdc->TxBuffer, hcdc->TxLength);
|
||||||
|
|
||||||
ret = USBD_OK;
|
ret = USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -1020,15 +926,20 @@ uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_ECM_ReceivePacket(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_CDC_ECM_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
ECMOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_ECM_OUT_EP, hcdc->RxBuffer, hcdc->MaxPcktLen);
|
(void)USBD_LL_PrepareReceive(pdev, ECMOutEpAdd, hcdc->RxBuffer, hcdc->MaxPcktLen);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -1043,12 +954,12 @@ uint8_t USBD_CDC_ECM_ReceivePacket(USBD_HandleTypeDef *pdev)
|
|||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_ECM_NotifCodeTypeDef Notif,
|
USBD_CDC_NotifCodeTypeDef Notif,
|
||||||
uint16_t bVal, uint8_t *pData)
|
uint16_t bVal, uint8_t *pData)
|
||||||
{
|
{
|
||||||
uint32_t Idx;
|
uint32_t Idx;
|
||||||
uint32_t ReqSize = 0U;
|
uint32_t ReqSize = 0U;
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_ECM_HandleTypeDef *hcdc = (USBD_CDC_ECM_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
@@ -1056,6 +967,11 @@ uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
ECMCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Initialize the request fields */
|
/* Initialize the request fields */
|
||||||
(hcdc->Req).bmRequest = CDC_ECM_BMREQUEST_TYPE_ECM;
|
(hcdc->Req).bmRequest = CDC_ECM_BMREQUEST_TYPE_ECM;
|
||||||
(hcdc->Req).bRequest = (uint8_t)Notif;
|
(hcdc->Req).bRequest = (uint8_t)Notif;
|
||||||
@@ -1109,7 +1025,7 @@ uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev,
|
|||||||
/* Transmit notification packet */
|
/* Transmit notification packet */
|
||||||
if (ReqSize != 0U)
|
if (ReqSize != 0U)
|
||||||
{
|
{
|
||||||
(void)USBD_LL_Transmit(pdev, CDC_ECM_CMD_EP, (uint8_t *)&hcdc->Req, ReqSize);
|
(void)USBD_LL_Transmit(pdev, ECMCmdEpAdd, (uint8_t *)&hcdc->Req, ReqSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint8_t)ret;
|
return (uint8_t)ret;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "usbd_cdc_ecm_if_template.h"
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Include here LwIP files if used
|
Include here LwIP files if used
|
||||||
@@ -32,13 +32,13 @@
|
|||||||
/* Received Data over USB are stored in this buffer */
|
/* Received Data over USB are stored in this buffer */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* ( __ICCARM__ ) */
|
||||||
__ALIGN_BEGIN static uint8_t UserRxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END;
|
__ALIGN_BEGIN static uint8_t UserRxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END;
|
||||||
|
|
||||||
/* Transmitted Data over CDC_ECM (CDC_ECM interface) are stored in this buffer */
|
/* Transmitted Data over CDC_ECM (CDC_ECM interface) are stored in this buffer */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* ( __ICCARM__ ) */
|
||||||
__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END;
|
__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END;
|
||||||
|
|
||||||
static uint8_t CDC_ECMInitialized = 0U;
|
static uint8_t CDC_ECMInitialized = 0U;
|
||||||
@@ -85,7 +85,11 @@ static int8_t CDC_ECM_Itf_Init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set Application Buffers */
|
/* Set Application Buffers */
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
(void)USBD_CDC_ECM_SetTxBuffer(&USBD_Device, UserTxBuffer, 0U, 0U);
|
||||||
|
#else
|
||||||
(void)USBD_CDC_ECM_SetTxBuffer(&USBD_Device, UserTxBuffer, 0U);
|
(void)USBD_CDC_ECM_SetTxBuffer(&USBD_Device, UserTxBuffer, 0U);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
(void)USBD_CDC_ECM_SetRxBuffer(&USBD_Device, UserRxBuffer);
|
(void)USBD_CDC_ECM_SetRxBuffer(&USBD_Device, UserRxBuffer);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@@ -99,7 +103,12 @@ static int8_t CDC_ECM_Itf_Init(void)
|
|||||||
*/
|
*/
|
||||||
static int8_t CDC_ECM_Itf_DeInit(void)
|
static int8_t CDC_ECM_Itf_DeInit(void)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *) \
|
||||||
|
(USBD_Device.pClassDataCmsit[USBD_Device.classId]);
|
||||||
|
#else
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(USBD_Device.pClassData);
|
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(USBD_Device.pClassData);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Notify application layer that link is down */
|
/* Notify application layer that link is down */
|
||||||
hcdc_cdc_ecm->LinkStatus = 0U;
|
hcdc_cdc_ecm->LinkStatus = 0U;
|
||||||
@@ -117,7 +126,12 @@ static int8_t CDC_ECM_Itf_DeInit(void)
|
|||||||
*/
|
*/
|
||||||
static int8_t CDC_ECM_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
static int8_t CDC_ECM_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *) \
|
||||||
|
(USBD_Device.pClassDataCmsit[USBD_Device.classId]);
|
||||||
|
#else
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(USBD_Device.pClassData);
|
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(USBD_Device.pClassData);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
@@ -188,7 +202,12 @@ static int8_t CDC_ECM_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
|||||||
static int8_t CDC_ECM_Itf_Receive(uint8_t *Buf, uint32_t *Len)
|
static int8_t CDC_ECM_Itf_Receive(uint8_t *Buf, uint32_t *Len)
|
||||||
{
|
{
|
||||||
/* Get the CDC_ECM handler pointer */
|
/* Get the CDC_ECM handler pointer */
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *) \
|
||||||
|
(USBD_Device.pClassDataCmsit[USBD_Device.classId]);
|
||||||
|
#else
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(USBD_Device.pClassData);
|
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(USBD_Device.pClassData);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Call Eth buffer processing */
|
/* Call Eth buffer processing */
|
||||||
hcdc_cdc_ecm->RxState = 1U;
|
hcdc_cdc_ecm->RxState = 1U;
|
||||||
@@ -230,9 +249,18 @@ static int8_t CDC_ECM_Itf_TransmitCplt(uint8_t *Buf, uint32_t *Len, uint8_t epnu
|
|||||||
static int8_t CDC_ECM_Itf_Process(USBD_HandleTypeDef *pdev)
|
static int8_t CDC_ECM_Itf_Process(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Get the CDC_ECM handler pointer */
|
/* Get the CDC_ECM handler pointer */
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
#else
|
||||||
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(pdev->pClassData);
|
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(pdev->pClassData);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if ((hcdc_cdc_ecm != NULL) && (hcdc_cdc_ecm->LinkStatus != 0U))
|
if (hcdc_cdc_ecm == NULL)
|
||||||
|
{
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hcdc_cdc_ecm->LinkStatus != 0U)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Read a received packet from the Ethernet buffers and send it
|
Read a received packet from the Ethernet buffers and send it
|
||||||
|
|||||||
@@ -40,10 +40,15 @@ extern "C" {
|
|||||||
/** @defgroup usbd_cdc_rndis_Exported_Defines
|
/** @defgroup usbd_cdc_rndis_Exported_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#ifndef CDC_RNDIS_IN_EP
|
||||||
#define CDC_RNDIS_IN_EP 0x81U /* EP1 for data IN */
|
#define CDC_RNDIS_IN_EP 0x81U /* EP1 for data IN */
|
||||||
|
#endif /* CDC_RNDIS_IN_EP */
|
||||||
|
#ifndef CDC_RNDIS_OUT_EP
|
||||||
#define CDC_RNDIS_OUT_EP 0x01U /* EP1 for data OUT */
|
#define CDC_RNDIS_OUT_EP 0x01U /* EP1 for data OUT */
|
||||||
|
#endif /* CDC_RNDIS_OUT_EP */
|
||||||
|
#ifndef CDC_RNDIS_CMD_EP
|
||||||
#define CDC_RNDIS_CMD_EP 0x82U /* EP2 for CDC_RNDIS commands */
|
#define CDC_RNDIS_CMD_EP 0x82U /* EP2 for CDC_RNDIS commands */
|
||||||
|
#endif /* CDC_RNDIS_CMD_EP */
|
||||||
|
|
||||||
#ifndef CDC_RNDIS_CMD_ITF_NBR
|
#ifndef CDC_RNDIS_CMD_ITF_NBR
|
||||||
#define CDC_RNDIS_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
#define CDC_RNDIS_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
||||||
@@ -61,12 +66,14 @@ extern "C" {
|
|||||||
#define CDC_RNDIS_FS_BINTERVAL 0x10U
|
#define CDC_RNDIS_FS_BINTERVAL 0x10U
|
||||||
#endif /* CDC_RNDIS_FS_BINTERVAL */
|
#endif /* CDC_RNDIS_FS_BINTERVAL */
|
||||||
|
|
||||||
|
#ifndef CDC_RNDIS_CMD_PACKET_SIZE
|
||||||
|
#define CDC_RNDIS_CMD_PACKET_SIZE 16U /* Control Endpoint Packet size */
|
||||||
|
#endif /* CDC_RNDIS_CMD_PACKET_SIZE */
|
||||||
|
|
||||||
/* CDC_RNDIS Endpoints parameters: you can fine tune these values
|
/* CDC_RNDIS Endpoints parameters: you can fine tune these values
|
||||||
depending on the needed baudrates and performance. */
|
depending on the needed baudrates and performance. */
|
||||||
#define CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
#define CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
||||||
#define CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
#define CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||||
#define CDC_RNDIS_CMD_PACKET_SIZE 16U /* Control Endpoint Packet size */
|
|
||||||
|
|
||||||
#define CDC_RNDIS_CONFIG_DESC_SIZ 75U
|
#define CDC_RNDIS_CONFIG_DESC_SIZ 75U
|
||||||
#define CDC_RNDIS_DATA_HS_IN_PACKET_SIZE CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE
|
#define CDC_RNDIS_DATA_HS_IN_PACKET_SIZE CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE
|
||||||
@@ -264,15 +271,6 @@ typedef struct
|
|||||||
__IO uint32_t PacketFilter;
|
__IO uint32_t PacketFilter;
|
||||||
} USBD_CDC_RNDIS_HandleTypeDef;
|
} USBD_CDC_RNDIS_HandleTypeDef;
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
NETWORK_CONNECTION = 0x00,
|
|
||||||
RESPONSE_AVAILABLE = 0x01,
|
|
||||||
CONNECTION_SPEED_CHANGE = 0x2A
|
|
||||||
} USBD_CDC_RNDIS_NotifCodeTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
/* Messages Sent by the Host ---------------------*/
|
/* Messages Sent by the Host ---------------------*/
|
||||||
|
|
||||||
/* Type define for a CDC_RNDIS Initialize command message */
|
/* Type define for a CDC_RNDIS Initialize command message */
|
||||||
@@ -497,16 +495,20 @@ extern USBD_ClassTypeDef USBD_CDC_RNDIS;
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_RNDIS_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
uint8_t USBD_CDC_RNDIS_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
||||||
uint8_t USBD_CDC_RNDIS_ReceivePacket(USBD_HandleTypeDef *pdev);
|
uint8_t USBD_CDC_RNDIS_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||||
uint8_t USBD_CDC_RNDIS_TransmitPacket(USBD_HandleTypeDef *pdev);
|
|
||||||
|
|
||||||
uint8_t USBD_CDC_RNDIS_RegisterInterface(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_RNDIS_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_RNDIS_ItfTypeDef *fops);
|
USBD_CDC_RNDIS_ItfTypeDef *fops);
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_RNDIS_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId);
|
||||||
|
uint8_t USBD_CDC_RNDIS_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *pbuff, uint32_t length, uint8_t ClassId);
|
||||||
|
#else
|
||||||
|
uint8_t USBD_CDC_RNDIS_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||||
uint8_t USBD_CDC_RNDIS_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_RNDIS_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuff, uint32_t length);
|
uint8_t *pbuff, uint32_t length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_RNDIS_NotifCodeTypeDef Notif,
|
USBD_CDC_NotifCodeTypeDef Notif,
|
||||||
uint16_t bVal, uint8_t *pData);
|
uint16_t bVal, uint8_t *pData);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
#ifndef __USBD_CDC_RNDIS_IF_H
|
#ifndef __USBD_CDC_RNDIS_IF_H
|
||||||
#include "usbd_cdc_rndis_if_template.h"
|
#include "usbd_cdc_rndis_if_template.h"
|
||||||
#endif
|
#endif /* __USBD_CDC_RNDIS_IF_H */
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
@@ -105,17 +105,18 @@ static uint8_t USBD_CDC_RNDIS_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
static uint8_t USBD_CDC_RNDIS_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_CDC_RNDIS_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_CDC_RNDIS_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_CDC_RNDIS_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_CDC_RNDIS_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
static uint8_t USBD_CDC_RNDIS_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_CDC_RNDIS_GetFSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_RNDIS_GetFSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CDC_RNDIS_GetHSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_RNDIS_GetHSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CDC_RNDIS_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_RNDIS_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CDC_RNDIS_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CDC_RNDIS_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
static uint8_t *USBD_CDC_RNDIS_USRStringDescriptor(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
static uint8_t *USBD_CDC_RNDIS_USRStringDescriptor(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
uint8_t *USBD_CDC_RNDIS_GetDeviceQualifierDescriptor(uint16_t *length);
|
uint8_t *USBD_CDC_RNDIS_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* CDC_RNDIS Internal messages parsing and construction functions */
|
/* CDC_RNDIS Internal messages parsing and construction functions */
|
||||||
static uint8_t USBD_CDC_RNDIS_MsgParsing(USBD_HandleTypeDef *pdev, uint8_t *RxBuff);
|
static uint8_t USBD_CDC_RNDIS_MsgParsing(USBD_HandleTypeDef *pdev, uint8_t *RxBuff);
|
||||||
@@ -129,6 +130,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessPacketMsg(USBD_HandleTypeDef *pdev, USBD_CD
|
|||||||
static uint8_t USBD_CDC_RNDIS_ProcessUnsupportedMsg(USBD_HandleTypeDef *pdev, USBD_CDC_RNDIS_CtrlMsgTypeDef *Msg);
|
static uint8_t USBD_CDC_RNDIS_ProcessUnsupportedMsg(USBD_HandleTypeDef *pdev, USBD_CDC_RNDIS_CtrlMsgTypeDef *Msg);
|
||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
USB_LEN_DEV_QUALIFIER_DESC,
|
USB_LEN_DEV_QUALIFIER_DESC,
|
||||||
@@ -142,7 +144,7 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_DeviceQualifierDesc[USB_LEN_DEV_QUAL
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
static uint8_t MAC_StrDesc[6] = {CDC_RNDIS_MAC_ADDR0, CDC_RNDIS_MAC_ADDR1, CDC_RNDIS_MAC_ADDR2,
|
static uint8_t MAC_StrDesc[6] = {CDC_RNDIS_MAC_ADDR0, CDC_RNDIS_MAC_ADDR1, CDC_RNDIS_MAC_ADDR2,
|
||||||
CDC_RNDIS_MAC_ADDR3, CDC_RNDIS_MAC_ADDR4, CDC_RNDIS_MAC_ADDR5
|
CDC_RNDIS_MAC_ADDR3, CDC_RNDIS_MAC_ADDR4, CDC_RNDIS_MAC_ADDR5
|
||||||
};
|
};
|
||||||
@@ -175,126 +177,25 @@ USBD_ClassTypeDef USBD_CDC_RNDIS =
|
|||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_CDC_RNDIS_GetHSCfgDesc,
|
USBD_CDC_RNDIS_GetHSCfgDesc,
|
||||||
USBD_CDC_RNDIS_GetFSCfgDesc,
|
USBD_CDC_RNDIS_GetFSCfgDesc,
|
||||||
USBD_CDC_RNDIS_GetOtherSpeedCfgDesc,
|
USBD_CDC_RNDIS_GetOtherSpeedCfgDesc,
|
||||||
USBD_CDC_RNDIS_GetDeviceQualifierDescriptor,
|
USBD_CDC_RNDIS_GetDeviceQualifierDescriptor,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
USBD_CDC_RNDIS_USRStringDescriptor,
|
USBD_CDC_RNDIS_USRStringDescriptor,
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
};
|
};
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB CDC_RNDIS device Configuration Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_CfgHSDesc[] __ALIGN_END =
|
|
||||||
{
|
|
||||||
/* Configuration Descriptor */
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
LOBYTE(CDC_RNDIS_CONFIG_DESC_SIZ), /* wTotalLength: Total size of the Config descriptor */
|
|
||||||
HIBYTE(CDC_RNDIS_CONFIG_DESC_SIZ),
|
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
|
||||||
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) */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/* IAD descriptor */
|
|
||||||
0x08, /* bLength */
|
|
||||||
0x0B, /* bDescriptorType */
|
|
||||||
0x00, /* bFirstInterface */
|
|
||||||
0x02, /* bInterfaceCount */
|
|
||||||
0xE0, /* bFunctionClass (Wireless Controller) */
|
|
||||||
0x01, /* bFunctionSubClass */
|
|
||||||
0x03, /* bFunctionProtocol */
|
|
||||||
0x00, /* iFunction */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/* Interface Descriptor */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
CDC_RNDIS_CMD_ITF_NBR, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints: One endpoint used */
|
|
||||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
|
||||||
0x02, /* bInterfaceSubClass:Abstract Control Model */
|
|
||||||
0xFF, /* bInterfaceProtocol: Common AT commands */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Header Functional Descriptor */
|
|
||||||
0x05, /* bLength: Endpoint Descriptor size */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x00, /* bDescriptorSubtype: Header functional descriptor */
|
|
||||||
0x10, /* bcdCDC: spec release number: 1.20 */
|
|
||||||
0x01,
|
|
||||||
|
|
||||||
/* Call Management Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
|
||||||
0x00, /* bmCapabilities: D0+D1 */
|
|
||||||
CDC_RNDIS_COM_ITF_NBR, /* bDataInterface: 1 */
|
|
||||||
|
|
||||||
/* ACM Functional Descriptor */
|
|
||||||
0x04, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
|
||||||
0x00, /* bmCapabilities */
|
|
||||||
|
|
||||||
/* Union Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x06, /* bDescriptorSubtype: Union functional descriptor */
|
|
||||||
CDC_RNDIS_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */
|
|
||||||
CDC_RNDIS_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */
|
|
||||||
|
|
||||||
/* Notification Endpoint Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_RNDIS_CMD_EP, /* bEndpointAddress */
|
|
||||||
0x03, /* bmAttributes: Interrupt */
|
|
||||||
LOBYTE(CDC_RNDIS_CMD_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_RNDIS_CMD_PACKET_SIZE),
|
|
||||||
CDC_RNDIS_HS_BINTERVAL, /* bInterval */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/* Data class interface descriptor */
|
|
||||||
0x09, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
|
||||||
CDC_RNDIS_COM_ITF_NBR, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints: Two endpoints used */
|
|
||||||
0x0A, /* bInterfaceClass: CDC */
|
|
||||||
0x00, /* bInterfaceSubClass */
|
|
||||||
0x00, /* bInterfaceProtocol */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Endpoint OUT Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_RNDIS_OUT_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
0x00, /* bInterval */
|
|
||||||
|
|
||||||
/* Endpoint IN Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_RNDIS_IN_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
|
||||||
HIBYTE(CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE),
|
|
||||||
0x00 /* bInterval */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* USB CDC device Configuration Descriptor */
|
/* USB CDC device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_CfgFSDesc[] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_CfgDesc[] __ALIGN_END =
|
||||||
{
|
{
|
||||||
/* Configuration Descriptor */
|
/* Configuration Descriptor */
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
@@ -303,12 +204,13 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_CfgFSDesc[] __ALIGN_END =
|
|||||||
HIBYTE(CDC_RNDIS_CONFIG_DESC_SIZ),
|
HIBYTE(CDC_RNDIS_CONFIG_DESC_SIZ),
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
0x02, /* bNumInterfaces: 2 interfaces */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
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)
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
@@ -400,114 +302,11 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_CfgFSDesc[] __ALIGN_END =
|
|||||||
HIBYTE(CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE),
|
HIBYTE(CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE),
|
||||||
0x00 /* bInterval */
|
0x00 /* bInterval */
|
||||||
} ;
|
} ;
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_RNDIS_OtherSpeedCfgDesc[] __ALIGN_END =
|
static uint8_t RNDISInEpAdd = CDC_RNDIS_IN_EP;
|
||||||
{
|
static uint8_t RNDISOutEpAdd = CDC_RNDIS_OUT_EP;
|
||||||
/* Configuration Descriptor */
|
static uint8_t RNDISCmdEpAdd = CDC_RNDIS_CMD_EP;
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
LOBYTE(CDC_RNDIS_CONFIG_DESC_SIZ), /* wTotalLength:no of returned bytes */
|
|
||||||
HIBYTE(CDC_RNDIS_CONFIG_DESC_SIZ),
|
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
|
||||||
0x04, /* 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) */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/* IAD descriptor */
|
|
||||||
0x08, /* bLength */
|
|
||||||
0x0B, /* bDescriptorType */
|
|
||||||
0x00, /* bFirstInterface */
|
|
||||||
0x02, /* bInterfaceCount */
|
|
||||||
0xE0, /* bFunctionClass (Wireless Controller) */
|
|
||||||
0x01, /* bFunctionSubClass */
|
|
||||||
0x03, /* bFunctionProtocol */
|
|
||||||
0x00, /* iFunction */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/* Interface Descriptor */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
CDC_RNDIS_CMD_ITF_NBR, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints: One endpoint used */
|
|
||||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
|
||||||
0x02, /* bInterfaceSubClass:Abstract Control Model */
|
|
||||||
0xFF, /* bInterfaceProtocol: Common AT commands */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Header Functional Descriptor */
|
|
||||||
0x05, /* bLength: Endpoint Descriptor size */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x00, /* bDescriptorSubtype: Header functional descriptor */
|
|
||||||
0x10, /* bcdCDC: spec release number: 1.20 */
|
|
||||||
0x01,
|
|
||||||
|
|
||||||
/* Call Management Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
|
||||||
0x00, /* bmCapabilities: D0+D1 */
|
|
||||||
CDC_RNDIS_COM_ITF_NBR, /* bDataInterface: 1 */
|
|
||||||
|
|
||||||
/* ACM Functional Descriptor */
|
|
||||||
0x04, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
|
||||||
0x00, /* bmCapabilities */
|
|
||||||
|
|
||||||
/* Union Functional Descriptor */
|
|
||||||
0x05, /* bFunctionLength */
|
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
|
||||||
0x06, /* bDescriptorSubtype: Union functional descriptor */
|
|
||||||
CDC_RNDIS_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */
|
|
||||||
CDC_RNDIS_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */
|
|
||||||
|
|
||||||
/* Communication Endpoint Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_RNDIS_CMD_EP, /* bEndpointAddress */
|
|
||||||
0x03, /* bmAttributes: Interrupt */
|
|
||||||
LOBYTE(CDC_RNDIS_CMD_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(CDC_RNDIS_CMD_PACKET_SIZE),
|
|
||||||
CDC_RNDIS_FS_BINTERVAL, /* bInterval */
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
/* Data class interface descriptor */
|
|
||||||
0x09, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
|
||||||
CDC_RNDIS_COM_ITF_NBR, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints: Two endpoints used */
|
|
||||||
0x0A, /* bInterfaceClass: CDC */
|
|
||||||
0x00, /* bInterfaceSubClass */
|
|
||||||
0x00, /* bInterfaceProtocol */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Endpoint OUT Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_RNDIS_OUT_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
0x40, /* wMaxPacketSize */
|
|
||||||
0x00,
|
|
||||||
0x00, /* bInterval */
|
|
||||||
|
|
||||||
/* Endpoint IN Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
CDC_RNDIS_IN_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
0x40, /* wMaxPacketSize */
|
|
||||||
0x00,
|
|
||||||
0x00 /* bInterval */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static const uint32_t CDC_RNDIS_SupportedOIDs[] =
|
static const uint32_t CDC_RNDIS_SupportedOIDs[] =
|
||||||
{
|
{
|
||||||
@@ -556,55 +355,67 @@ static uint8_t USBD_CDC_RNDIS_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_RNDIS_HandleTypeDef));
|
hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_RNDIS_HandleTypeDef));
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
RNDISInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
RNDISOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
RNDISCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pClassData = (void *)hcdc;
|
(void)USBD_memset(hcdc, 0, sizeof(USBD_CDC_RNDIS_HandleTypeDef));
|
||||||
|
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hcdc;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_RNDIS_IN_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, RNDISInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_RNDIS_DATA_HS_IN_PACKET_SIZE);
|
CDC_RNDIS_DATA_HS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CDC_RNDIS_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[RNDISInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_RNDIS_OUT_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, RNDISOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_RNDIS_DATA_HS_OUT_PACKET_SIZE);
|
CDC_RNDIS_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CDC_RNDIS_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[RNDISOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Set bInterval for CDC RNDIS CMD Endpoint */
|
/* Set bInterval for CDC RNDIS CMD Endpoint */
|
||||||
pdev->ep_in[CDC_RNDIS_CMD_EP & 0xFU].bInterval = CDC_RNDIS_HS_BINTERVAL;
|
pdev->ep_in[RNDISCmdEpAdd & 0xFU].bInterval = CDC_RNDIS_HS_BINTERVAL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_RNDIS_IN_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, RNDISInEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_RNDIS_DATA_FS_IN_PACKET_SIZE);
|
CDC_RNDIS_DATA_FS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CDC_RNDIS_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[RNDISInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_RNDIS_OUT_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, RNDISOutEpAdd, USBD_EP_TYPE_BULK,
|
||||||
CDC_RNDIS_DATA_FS_OUT_PACKET_SIZE);
|
CDC_RNDIS_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CDC_RNDIS_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[RNDISOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Set bInterval for CDC RNDIS CMD Endpoint */
|
/* Set bInterval for CDC RNDIS CMD Endpoint */
|
||||||
pdev->ep_in[CDC_RNDIS_CMD_EP & 0xFU].bInterval = CDC_RNDIS_FS_BINTERVAL;
|
pdev->ep_in[RNDISCmdEpAdd & 0xFU].bInterval = CDC_RNDIS_FS_BINTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open Command IN EP */
|
/* Open Command IN EP */
|
||||||
(void)USBD_LL_OpenEP(pdev, CDC_RNDIS_CMD_EP, USBD_EP_TYPE_INTR, CDC_RNDIS_CMD_PACKET_SIZE);
|
(void)USBD_LL_OpenEP(pdev, RNDISCmdEpAdd, USBD_EP_TYPE_INTR, CDC_RNDIS_CMD_PACKET_SIZE);
|
||||||
pdev->ep_in[CDC_RNDIS_CMD_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[RNDISCmdEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
hcdc->RxBuffer = NULL;
|
||||||
|
|
||||||
/* Init physical Interface components */
|
/* Init physical Interface components */
|
||||||
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->Init();
|
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||||
|
|
||||||
/* Init the CDC_RNDIS state */
|
/* Init the CDC_RNDIS state */
|
||||||
hcdc->State = CDC_RNDIS_STATE_BUS_INITIALIZED;
|
hcdc->State = CDC_RNDIS_STATE_BUS_INITIALIZED;
|
||||||
@@ -616,10 +427,16 @@ static uint8_t USBD_CDC_RNDIS_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
hcdc->TxLength = 0U;
|
hcdc->TxLength = 0U;
|
||||||
hcdc->LinkStatus = 0U;
|
hcdc->LinkStatus = 0U;
|
||||||
hcdc->NotificationStatus = 0U;
|
hcdc->NotificationStatus = 0U;
|
||||||
hcdc->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE : CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE;
|
hcdc->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE : \
|
||||||
|
CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
|
||||||
|
if (hcdc->RxBuffer == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_RNDIS_OUT_EP,
|
(void)USBD_LL_PrepareReceive(pdev, RNDISOutEpAdd,
|
||||||
hcdc->RxBuffer, hcdc->MaxPcktLen);
|
hcdc->RxBuffer, hcdc->MaxPcktLen);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
@@ -636,24 +453,32 @@ static uint8_t USBD_CDC_RNDIS_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
RNDISInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
RNDISOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
RNDISCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close EP IN */
|
/* Close EP IN */
|
||||||
(void)USBD_LL_CloseEP(pdev, CDC_RNDIS_IN_EP);
|
(void)USBD_LL_CloseEP(pdev, RNDISInEpAdd);
|
||||||
pdev->ep_in[CDC_RNDIS_IN_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[RNDISInEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP OUT */
|
/* Close EP OUT */
|
||||||
(void)USBD_LL_CloseEP(pdev, CDC_RNDIS_OUT_EP);
|
(void)USBD_LL_CloseEP(pdev, RNDISOutEpAdd);
|
||||||
pdev->ep_out[CDC_RNDIS_OUT_EP & 0xFU].is_used = 0U;
|
pdev->ep_out[RNDISOutEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close Command IN EP */
|
/* Close Command IN EP */
|
||||||
(void)USBD_LL_CloseEP(pdev, CDC_RNDIS_CMD_EP);
|
(void)USBD_LL_CloseEP(pdev, RNDISCmdEpAdd);
|
||||||
pdev->ep_in[CDC_RNDIS_CMD_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[RNDISCmdEpAdd & 0xFU].is_used = 0U;
|
||||||
pdev->ep_in[CDC_RNDIS_CMD_EP & 0xFU].bInterval = 0U;
|
pdev->ep_in[RNDISCmdEpAdd & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if (pdev->pClassData != NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,8 +495,8 @@ static uint8_t USBD_CDC_RNDIS_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
static uint8_t USBD_CDC_RNDIS_Setup(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_RNDIS_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_CDC_RNDIS_CtrlMsgTypeDef *Msg = (USBD_CDC_RNDIS_CtrlMsgTypeDef *)(void *)hcdc->data;
|
USBD_CDC_RNDIS_CtrlMsgTypeDef *Msg;
|
||||||
uint8_t ifalt = 0U;
|
uint8_t ifalt = 0U;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
@@ -681,6 +506,8 @@ static uint8_t USBD_CDC_RNDIS_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Msg = (USBD_CDC_RNDIS_CtrlMsgTypeDef *)(void *)hcdc->data;
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS :
|
||||||
@@ -703,9 +530,9 @@ static uint8_t USBD_CDC_RNDIS_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allow application layer to pre-process data or add own processing before sending response */
|
/* Allow application layer to pre-process data or add own processing before sending response */
|
||||||
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(req->bRequest,
|
||||||
(uint8_t *)hcdc->data,
|
(uint8_t *)hcdc->data,
|
||||||
req->wLength);
|
req->wLength);
|
||||||
/* Check if Response is ready */
|
/* Check if Response is ready */
|
||||||
if (hcdc->ResponseRdy != 0U)
|
if (hcdc->ResponseRdy != 0U)
|
||||||
{
|
{
|
||||||
@@ -738,8 +565,8 @@ static uint8_t USBD_CDC_RNDIS_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
so let application layer manage this case */
|
so let application layer manage this case */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData[pdev->classId])->Control(req->bRequest,
|
||||||
(uint8_t *)req, 0U);
|
(uint8_t *)req, 0U);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -809,14 +636,19 @@ static uint8_t USBD_CDC_RNDIS_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc;
|
||||||
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
|
PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef *)pdev->pData;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
RNDISInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (epnum == (CDC_RNDIS_IN_EP & 0x7FU))
|
if (epnum == (RNDISInEpAdd & 0x7FU))
|
||||||
{
|
{
|
||||||
if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
|
if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
|
||||||
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U))
|
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U))
|
||||||
@@ -831,13 +663,14 @@ static uint8_t USBD_CDC_RNDIS_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
{
|
{
|
||||||
hcdc->TxState = 0U;
|
hcdc->TxState = 0U;
|
||||||
|
|
||||||
if (((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->TransmitCplt != NULL)
|
if (((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->TransmitCplt(hcdc->TxBuffer, &hcdc->TxLength, epnum);
|
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData[pdev->classId])->TransmitCplt(hcdc->TxBuffer, \
|
||||||
|
&hcdc->TxLength, epnum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (epnum == (CDC_RNDIS_CMD_EP & 0x7FU))
|
else if (epnum == (RNDISCmdEpAdd & 0x7FU))
|
||||||
{
|
{
|
||||||
if (hcdc->NotificationStatus != 0U)
|
if (hcdc->NotificationStatus != 0U)
|
||||||
{
|
{
|
||||||
@@ -867,14 +700,18 @@ static uint8_t USBD_CDC_RNDIS_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc;
|
||||||
uint32_t CurrPcktLen;
|
uint32_t CurrPcktLen;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
RNDISOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (epnum == CDC_RNDIS_OUT_EP)
|
if (epnum == RNDISOutEpAdd)
|
||||||
{
|
{
|
||||||
/* Get the received data length */
|
/* Get the received data length */
|
||||||
CurrPcktLen = USBD_LL_GetRxDataSize(pdev, epnum);
|
CurrPcktLen = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||||
@@ -895,7 +732,7 @@ static uint8_t USBD_CDC_RNDIS_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet in current/new frame */
|
/* Prepare Out endpoint to receive next packet in current/new frame */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_RNDIS_OUT_EP,
|
(void)USBD_LL_PrepareReceive(pdev, RNDISOutEpAdd,
|
||||||
(uint8_t *)(hcdc->RxBuffer + hcdc->RxLength),
|
(uint8_t *)(hcdc->RxBuffer + hcdc->RxLength),
|
||||||
hcdc->MaxPcktLen);
|
hcdc->MaxPcktLen);
|
||||||
}
|
}
|
||||||
@@ -916,14 +753,14 @@ static uint8_t USBD_CDC_RNDIS_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_RNDIS_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_CDC_RNDIS_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
if ((pdev->pUserData[pdev->classId] != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||||
{
|
{
|
||||||
/* Check if the received command is SendEncapsulated command */
|
/* Check if the received command is SendEncapsulated command */
|
||||||
if (hcdc->CmdOpCode == CDC_RNDIS_SEND_ENCAPSULATED_COMMAND)
|
if (hcdc->CmdOpCode == CDC_RNDIS_SEND_ENCAPSULATED_COMMAND)
|
||||||
@@ -946,7 +783,7 @@ static uint8_t USBD_CDC_RNDIS_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_RNDIS_GetFSCfgDesc
|
* @brief USBD_CDC_RNDIS_GetFSCfgDesc
|
||||||
* Return configuration descriptor
|
* Return configuration descriptor
|
||||||
@@ -955,9 +792,27 @@ static uint8_t USBD_CDC_RNDIS_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_RNDIS_GetFSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CDC_RNDIS_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)(sizeof(USBD_CDC_RNDIS_CfgFSDesc));
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_RNDIS_CfgDesc, CDC_RNDIS_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_RNDIS_CfgDesc, CDC_RNDIS_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_RNDIS_CfgDesc, CDC_RNDIS_IN_EP);
|
||||||
|
|
||||||
return USBD_CDC_RNDIS_CfgFSDesc;
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_RNDIS_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)(sizeof(USBD_CDC_RNDIS_CfgDesc));
|
||||||
|
return USBD_CDC_RNDIS_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -968,9 +823,27 @@ static uint8_t *USBD_CDC_RNDIS_GetFSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_RNDIS_GetHSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CDC_RNDIS_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)(sizeof(USBD_CDC_RNDIS_CfgHSDesc));
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_RNDIS_CfgDesc, CDC_RNDIS_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_RNDIS_CfgDesc, CDC_RNDIS_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_RNDIS_CfgDesc, CDC_RNDIS_IN_EP);
|
||||||
|
|
||||||
return USBD_CDC_RNDIS_CfgHSDesc;
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_RNDIS_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)(sizeof(USBD_CDC_RNDIS_CfgDesc));
|
||||||
|
return USBD_CDC_RNDIS_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -981,9 +854,27 @@ static uint8_t *USBD_CDC_RNDIS_GetHSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_RNDIS_GetOtherSpeedCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CDC_RNDIS_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)(sizeof(USBD_CDC_RNDIS_OtherSpeedCfgDesc));
|
USBD_EpDescTypeDef *pEpCmdDesc = USBD_GetEpDesc(USBD_CDC_RNDIS_CfgDesc, CDC_RNDIS_CMD_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CDC_RNDIS_CfgDesc, CDC_RNDIS_OUT_EP);
|
||||||
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CDC_RNDIS_CfgDesc, CDC_RNDIS_IN_EP);
|
||||||
|
|
||||||
return USBD_CDC_RNDIS_OtherSpeedCfgDesc;
|
if (pEpCmdDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpCmdDesc->bInterval = CDC_RNDIS_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)(sizeof(USBD_CDC_RNDIS_CfgDesc));
|
||||||
|
return USBD_CDC_RNDIS_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -998,7 +889,7 @@ uint8_t *USBD_CDC_RNDIS_GetDeviceQualifierDescriptor(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_CDC_RNDIS_DeviceQualifierDesc;
|
return USBD_CDC_RNDIS_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_RNDIS_RegisterInterface
|
* @brief USBD_CDC_RNDIS_RegisterInterface
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
@@ -1013,7 +904,7 @@ uint8_t USBD_CDC_RNDIS_RegisterInterface(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -1035,7 +926,8 @@ static uint8_t *USBD_CDC_RNDIS_USRStringDescriptor(USBD_HandleTypeDef *pdev, uin
|
|||||||
/* Check if the requested string interface is supported */
|
/* Check if the requested string interface is supported */
|
||||||
if (index == CDC_RNDIS_MAC_STRING_INDEX)
|
if (index == CDC_RNDIS_MAC_STRING_INDEX)
|
||||||
{
|
{
|
||||||
USBD_GetString((uint8_t *)((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->pStrDesc, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData[pdev->classId])->pStrDesc, USBD_StrDesc,
|
||||||
|
length);
|
||||||
return USBD_StrDesc;
|
return USBD_StrDesc;
|
||||||
}
|
}
|
||||||
/* Not supported Interface Descriptor index */
|
/* Not supported Interface Descriptor index */
|
||||||
@@ -1046,16 +938,25 @@ static uint8_t *USBD_CDC_RNDIS_USRStringDescriptor(USBD_HandleTypeDef *pdev, uin
|
|||||||
}
|
}
|
||||||
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_RNDIS_SetTxBuffer
|
* @brief USBD_CDC_RNDIS_SetTxBuffer
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param pbuff: Tx Buffer
|
* @param pbuff: Tx Buffer
|
||||||
* @param length: Tx Buffer length
|
* @param length: Tx Buffer length
|
||||||
|
* @param ClassId: The Class ID
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_RNDIS_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
uint8_t USBD_CDC_RNDIS_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length)
|
uint8_t USBD_CDC_RNDIS_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length)
|
||||||
{
|
{
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
|
||||||
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
@@ -1077,7 +978,7 @@ uint8_t USBD_CDC_RNDIS_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff, uin
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_RNDIS_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
uint8_t USBD_CDC_RNDIS_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
||||||
{
|
{
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
@@ -1094,20 +995,32 @@ uint8_t USBD_CDC_RNDIS_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
|||||||
* @brief USBD_CDC_RNDIS_TransmitPacket
|
* @brief USBD_CDC_RNDIS_TransmitPacket
|
||||||
* Transmit packet on IN endpoint
|
* Transmit packet on IN endpoint
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
|
* @param ClassId: The Class ID
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CDC_RNDIS_TransmitPacket(USBD_HandleTypeDef *pdev, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
uint8_t USBD_CDC_RNDIS_TransmitPacket(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_CDC_RNDIS_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
USBD_CDC_RNDIS_PacketMsgTypeDef *PacketMsg;
|
USBD_CDC_RNDIS_PacketMsgTypeDef *PacketMsg;
|
||||||
USBD_StatusTypeDef ret = USBD_BUSY;
|
USBD_StatusTypeDef ret = USBD_BUSY;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
RNDISInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, ClassId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
|
||||||
PacketMsg = (USBD_CDC_RNDIS_PacketMsgTypeDef *)(void *)hcdc->TxBuffer;
|
PacketMsg = (USBD_CDC_RNDIS_PacketMsgTypeDef *)(void *)hcdc->TxBuffer;
|
||||||
|
|
||||||
if (hcdc->TxState == 0U)
|
if (hcdc->TxState == 0U)
|
||||||
@@ -1129,10 +1042,10 @@ uint8_t USBD_CDC_RNDIS_TransmitPacket(USBD_HandleTypeDef *pdev)
|
|||||||
PacketMsg->Reserved = 0U;
|
PacketMsg->Reserved = 0U;
|
||||||
|
|
||||||
/* Update the packet total length */
|
/* Update the packet total length */
|
||||||
pdev->ep_in[CDC_RNDIS_IN_EP & 0xFU].total_length = hcdc->TxLength;
|
pdev->ep_in[RNDISInEpAdd & 0xFU].total_length = hcdc->TxLength;
|
||||||
|
|
||||||
/* Transmit next packet */
|
/* Transmit next packet */
|
||||||
(void)USBD_LL_Transmit(pdev, CDC_RNDIS_IN_EP, hcdc->TxBuffer, hcdc->TxLength);
|
(void)USBD_LL_Transmit(pdev, RNDISInEpAdd, hcdc->TxBuffer, hcdc->TxLength);
|
||||||
|
|
||||||
ret = USBD_OK;
|
ret = USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -1151,15 +1064,20 @@ uint8_t USBD_CDC_RNDIS_ReceivePacket(USBD_HandleTypeDef *pdev)
|
|||||||
{
|
{
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
RNDISOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CDC_RNDIS_OUT_EP,
|
(void)USBD_LL_PrepareReceive(pdev, RNDISOutEpAdd,
|
||||||
hcdc->RxBuffer, hcdc->MaxPcktLen);
|
hcdc->RxBuffer, hcdc->MaxPcktLen);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
@@ -1176,12 +1094,12 @@ uint8_t USBD_CDC_RNDIS_ReceivePacket(USBD_HandleTypeDef *pdev)
|
|||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_RNDIS_NotifCodeTypeDef Notif,
|
USBD_CDC_NotifCodeTypeDef Notif,
|
||||||
uint16_t bVal, uint8_t *pData)
|
uint16_t bVal, uint8_t *pData)
|
||||||
{
|
{
|
||||||
uint32_t Idx;
|
uint32_t Idx;
|
||||||
uint16_t ReqSize = 0U;
|
uint16_t ReqSize = 0U;
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
|
||||||
UNUSED(bVal);
|
UNUSED(bVal);
|
||||||
@@ -1192,6 +1110,11 @@ uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
RNDISCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Initialize the request fields */
|
/* Initialize the request fields */
|
||||||
(hcdc->Req).bmRequest = CDC_RNDIS_BMREQUEST_TYPE_RNDIS;
|
(hcdc->Req).bmRequest = CDC_RNDIS_BMREQUEST_TYPE_RNDIS;
|
||||||
(hcdc->Req).bRequest = (uint8_t)Notif;
|
(hcdc->Req).bRequest = (uint8_t)Notif;
|
||||||
@@ -1219,7 +1142,7 @@ uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev,
|
|||||||
/* Transmit notification packet */
|
/* Transmit notification packet */
|
||||||
if (ReqSize != 0U)
|
if (ReqSize != 0U)
|
||||||
{
|
{
|
||||||
(void)USBD_LL_Transmit(pdev, CDC_RNDIS_CMD_EP, (uint8_t *)&hcdc->Req, ReqSize);
|
(void)USBD_LL_Transmit(pdev, RNDISCmdEpAdd, (uint8_t *)&hcdc->Req, ReqSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint8_t)ret;
|
return (uint8_t)ret;
|
||||||
@@ -1293,7 +1216,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessInitMsg(USBD_HandleTypeDef *pdev,
|
|||||||
USBD_CDC_RNDIS_InitMsgTypeDef *Msg)
|
USBD_CDC_RNDIS_InitMsgTypeDef *Msg)
|
||||||
{
|
{
|
||||||
/* Get the CDC_RNDIS handle pointer */
|
/* Get the CDC_RNDIS handle pointer */
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* Get and format the Msg input */
|
/* Get and format the Msg input */
|
||||||
USBD_CDC_RNDIS_InitMsgTypeDef *InitMessage = (USBD_CDC_RNDIS_InitMsgTypeDef *)Msg;
|
USBD_CDC_RNDIS_InitMsgTypeDef *InitMessage = (USBD_CDC_RNDIS_InitMsgTypeDef *)Msg;
|
||||||
@@ -1358,7 +1281,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessHaltMsg(USBD_HandleTypeDef *pdev,
|
|||||||
USBD_CDC_RNDIS_HaltMsgTypeDef *Msg)
|
USBD_CDC_RNDIS_HaltMsgTypeDef *Msg)
|
||||||
{
|
{
|
||||||
/* Get the CDC_RNDIS handle pointer */
|
/* Get the CDC_RNDIS handle pointer */
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hcdc == NULL)
|
if (hcdc == NULL)
|
||||||
{
|
{
|
||||||
@@ -1387,7 +1310,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessKeepAliveMsg(USBD_HandleTypeDef *pdev,
|
|||||||
USBD_CDC_RNDIS_KpAliveMsgTypeDef *Msg)
|
USBD_CDC_RNDIS_KpAliveMsgTypeDef *Msg)
|
||||||
{
|
{
|
||||||
/* Get the CDC_RNDIS handle pointer */
|
/* Get the CDC_RNDIS handle pointer */
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* Use same Msg input buffer as response buffer */
|
/* Use same Msg input buffer as response buffer */
|
||||||
USBD_CDC_RNDIS_KpAliveCpltMsgTypeDef *InitResponse = (USBD_CDC_RNDIS_KpAliveCpltMsgTypeDef *)(void *)Msg;
|
USBD_CDC_RNDIS_KpAliveCpltMsgTypeDef *InitResponse = (USBD_CDC_RNDIS_KpAliveCpltMsgTypeDef *)(void *)Msg;
|
||||||
@@ -1437,7 +1360,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessQueryMsg(USBD_HandleTypeDef *pdev,
|
|||||||
USBD_CDC_RNDIS_QueryMsgTypeDef *Msg)
|
USBD_CDC_RNDIS_QueryMsgTypeDef *Msg)
|
||||||
{
|
{
|
||||||
/* Get the CDC_RNDIS handle pointer */
|
/* Get the CDC_RNDIS handle pointer */
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* Use same Msg input buffer as response buffer */
|
/* Use same Msg input buffer as response buffer */
|
||||||
USBD_CDC_RNDIS_QueryCpltMsgTypeDef *QueryResponse = (USBD_CDC_RNDIS_QueryCpltMsgTypeDef *)(void *)Msg;
|
USBD_CDC_RNDIS_QueryCpltMsgTypeDef *QueryResponse = (USBD_CDC_RNDIS_QueryCpltMsgTypeDef *)(void *)Msg;
|
||||||
@@ -1529,7 +1452,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessQueryMsg(USBD_HandleTypeDef *pdev,
|
|||||||
|
|
||||||
case OID_GEN_CURRENT_PACKET_FILTER:
|
case OID_GEN_CURRENT_PACKET_FILTER:
|
||||||
QueryResponse->InfoBufLength = sizeof(uint32_t);
|
QueryResponse->InfoBufLength = sizeof(uint32_t);
|
||||||
QueryResponse->InfoBuf[0] = 0xFFFFFFU; /* USBD_CDC_RNDIS_DEVICE.packetFilter; */
|
QueryResponse->InfoBuf[0] = 0xFFFFFFU; /* USBD_CDC_RNDIS_DEVICE.packetFilter */
|
||||||
QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS;
|
QueryResponse->Status = CDC_RNDIS_STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1582,7 +1505,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessSetMsg(USBD_HandleTypeDef *pdev,
|
|||||||
USBD_CDC_RNDIS_SetMsgTypeDef *Msg)
|
USBD_CDC_RNDIS_SetMsgTypeDef *Msg)
|
||||||
{
|
{
|
||||||
/* Get the CDC_RNDIS handle pointer */
|
/* Get the CDC_RNDIS handle pointer */
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* Get and format the Msg input */
|
/* Get and format the Msg input */
|
||||||
USBD_CDC_RNDIS_SetMsgTypeDef *SetMessage = (USBD_CDC_RNDIS_SetMsgTypeDef *)Msg;
|
USBD_CDC_RNDIS_SetMsgTypeDef *SetMessage = (USBD_CDC_RNDIS_SetMsgTypeDef *)Msg;
|
||||||
@@ -1645,7 +1568,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessResetMsg(USBD_HandleTypeDef *pdev,
|
|||||||
/* Get and format the Msg input */
|
/* Get and format the Msg input */
|
||||||
USBD_CDC_RNDIS_ResetMsgTypeDef *ResetMessage = (USBD_CDC_RNDIS_ResetMsgTypeDef *)Msg;
|
USBD_CDC_RNDIS_ResetMsgTypeDef *ResetMessage = (USBD_CDC_RNDIS_ResetMsgTypeDef *)Msg;
|
||||||
/* Get the CDC_RNDIS handle pointer */
|
/* Get the CDC_RNDIS handle pointer */
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
/* Use same Msg input buffer as response buffer */
|
/* Use same Msg input buffer as response buffer */
|
||||||
USBD_CDC_RNDIS_ResetCpltMsgTypeDef *ResetResponse = (USBD_CDC_RNDIS_ResetCpltMsgTypeDef *)(void *)Msg;
|
USBD_CDC_RNDIS_ResetCpltMsgTypeDef *ResetResponse = (USBD_CDC_RNDIS_ResetCpltMsgTypeDef *)(void *)Msg;
|
||||||
|
|
||||||
@@ -1693,10 +1616,11 @@ static uint8_t USBD_CDC_RNDIS_ProcessResetMsg(USBD_HandleTypeDef *pdev,
|
|||||||
static uint8_t USBD_CDC_RNDIS_ProcessPacketMsg(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_RNDIS_ProcessPacketMsg(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_RNDIS_PacketMsgTypeDef *Msg)
|
USBD_CDC_RNDIS_PacketMsgTypeDef *Msg)
|
||||||
{
|
{
|
||||||
uint32_t tmp1, tmp2;
|
uint32_t tmp1;
|
||||||
|
uint32_t tmp2;
|
||||||
|
|
||||||
/* Get the CDC_RNDIS handle pointer */
|
/* Get the CDC_RNDIS handle pointer */
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* Get and format the Msg input */
|
/* Get and format the Msg input */
|
||||||
USBD_CDC_RNDIS_PacketMsgTypeDef *PacketMsg = (USBD_CDC_RNDIS_PacketMsgTypeDef *)Msg;
|
USBD_CDC_RNDIS_PacketMsgTypeDef *PacketMsg = (USBD_CDC_RNDIS_PacketMsgTypeDef *)Msg;
|
||||||
@@ -1721,7 +1645,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessPacketMsg(USBD_HandleTypeDef *pdev,
|
|||||||
hcdc->RxLength = PacketMsg->DataLength;
|
hcdc->RxLength = PacketMsg->DataLength;
|
||||||
|
|
||||||
/* Process data by application */
|
/* Process data by application */
|
||||||
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
((USBD_CDC_RNDIS_ItfTypeDef *)pdev->pUserData[pdev->classId])->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -1738,7 +1662,7 @@ static uint8_t USBD_CDC_RNDIS_ProcessUnsupportedMsg(USBD_HandleTypeDef *pdev,
|
|||||||
USBD_CDC_RNDIS_CtrlMsgTypeDef *Msg)
|
USBD_CDC_RNDIS_CtrlMsgTypeDef *Msg)
|
||||||
{
|
{
|
||||||
/* Get the CDC_RNDIS handle pointer */
|
/* Get the CDC_RNDIS handle pointer */
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassData;
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc = (USBD_CDC_RNDIS_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* Use same Msg input buffer as response buffer */
|
/* Use same Msg input buffer as response buffer */
|
||||||
USBD_CDC_RNDIS_StsChangeMsgTypeDef *Response = (USBD_CDC_RNDIS_StsChangeMsgTypeDef *)(void *)Msg;
|
USBD_CDC_RNDIS_StsChangeMsgTypeDef *Response = (USBD_CDC_RNDIS_StsChangeMsgTypeDef *)(void *)Msg;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#include "ethernetif.h"
|
#include "ethernetif.h"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "main.h"
|
#include "usbd_cdc_rndis_if_template.h"
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
@@ -39,13 +39,13 @@
|
|||||||
/* Received Data over USB are stored in this buffer */
|
/* Received Data over USB are stored in this buffer */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
__ALIGN_BEGIN uint8_t UserRxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END;
|
__ALIGN_BEGIN uint8_t UserRxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END;
|
||||||
|
|
||||||
/* Transmitted Data over CDC_RNDIS (CDC_RNDIS interface) are stored in this buffer */
|
/* Transmitted Data over CDC_RNDIS (CDC_RNDIS interface) are stored in this buffer */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END;
|
__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END;
|
||||||
|
|
||||||
static uint8_t CDC_RNDISInitialized = 0U;
|
static uint8_t CDC_RNDISInitialized = 0U;
|
||||||
@@ -95,7 +95,11 @@ static int8_t CDC_RNDIS_Itf_Init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set Application Buffers */
|
/* Set Application Buffers */
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
(void)USBD_CDC_RNDIS_SetTxBuffer(&USBD_Device, UserTxBuffer, 0U, 0U);
|
||||||
|
#else
|
||||||
(void)USBD_CDC_RNDIS_SetTxBuffer(&USBD_Device, UserTxBuffer, 0U);
|
(void)USBD_CDC_RNDIS_SetTxBuffer(&USBD_Device, UserTxBuffer, 0U);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
(void)USBD_CDC_RNDIS_SetRxBuffer(&USBD_Device, UserRxBuffer);
|
(void)USBD_CDC_RNDIS_SetRxBuffer(&USBD_Device, UserRxBuffer);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
@@ -109,7 +113,12 @@ static int8_t CDC_RNDIS_Itf_Init(void)
|
|||||||
*/
|
*/
|
||||||
static int8_t CDC_RNDIS_Itf_DeInit(void)
|
static int8_t CDC_RNDIS_Itf_DeInit(void)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *) \
|
||||||
|
(USBD_Device.pClassDataCmsit[USBD_Device.classId]);
|
||||||
|
#else
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(USBD_Device.pClassData);
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(USBD_Device.pClassData);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Add your code here
|
Add your code here
|
||||||
@@ -131,7 +140,12 @@ static int8_t CDC_RNDIS_Itf_DeInit(void)
|
|||||||
*/
|
*/
|
||||||
static int8_t CDC_RNDIS_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
static int8_t CDC_RNDIS_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *) \
|
||||||
|
(USBD_Device.pClassDataCmsit[USBD_Device.classId]);
|
||||||
|
#else
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(USBD_Device.pClassData);
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(USBD_Device.pClassData);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
@@ -174,7 +188,12 @@ static int8_t CDC_RNDIS_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
|||||||
static int8_t CDC_RNDIS_Itf_Receive(uint8_t *Buf, uint32_t *Len)
|
static int8_t CDC_RNDIS_Itf_Receive(uint8_t *Buf, uint32_t *Len)
|
||||||
{
|
{
|
||||||
/* Get the CDC_RNDIS handler pointer */
|
/* Get the CDC_RNDIS handler pointer */
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *) \
|
||||||
|
(USBD_Device.pClassDataCmsit[USBD_Device.classId]);
|
||||||
|
#else
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(USBD_Device.pClassData);
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(USBD_Device.pClassData);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Call Eth buffer processing */
|
/* Call Eth buffer processing */
|
||||||
hcdc_cdc_rndis->RxState = 1U;
|
hcdc_cdc_rndis->RxState = 1U;
|
||||||
@@ -217,9 +236,18 @@ static int8_t CDC_RNDIS_Itf_TransmitCplt(uint8_t *Buf, uint32_t *Len, uint8_t ep
|
|||||||
static int8_t CDC_RNDIS_Itf_Process(USBD_HandleTypeDef *pdev)
|
static int8_t CDC_RNDIS_Itf_Process(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Get the CDC_RNDIS handler pointer */
|
/* Get the CDC_RNDIS handler pointer */
|
||||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(pdev->pClassData);
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
#else
|
||||||
|
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(pdev->pClassData);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if ((hcdc_cdc_rndis != NULL) && (hcdc_cdc_rndis->LinkStatus != 0U))
|
if (hcdc_cdc_rndis == NULL)
|
||||||
|
{
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hcdc_cdc_rndis->LinkStatus != 0U)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Add your code here
|
Add your code here
|
||||||
|
|||||||
289
Class/CompositeBuilder/Inc/usbd_composite_builder.h
Normal file
289
Class/CompositeBuilder/Inc/usbd_composite_builder.h
Normal file
@@ -0,0 +1,289 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_composite_builder.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header for the usbd_composite_builder.c file
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 STMicroelectronics.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
|
* in the root directory of this software component.
|
||||||
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||||
|
#ifndef __USBD_COMPOSITE_BUILDER_H__
|
||||||
|
#define __USBD_COMPOSITE_BUILDER_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_ioreq.h"
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_HID == 1U
|
||||||
|
#include "usbd_hid.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_HID */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_MSC == 1U
|
||||||
|
#include "usbd_msc.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_MSC */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_CDC == 1U
|
||||||
|
#include "usbd_cdc.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_CDC */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_DFU == 1U
|
||||||
|
#include "usbd_dfu.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_DFU */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_RNDIS == 1U
|
||||||
|
#include "usbd_cdc_rndis.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_RNDIS */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_CDC_ECM == 1U
|
||||||
|
#include "usbd_cdc_ecm.h"
|
||||||
|
|
||||||
|
#ifndef __USBD_CDC_ECM_IF_H
|
||||||
|
#include "usbd_cdc_ecm_if_template.h"
|
||||||
|
#endif /* __USBD_CDC_ECM_IF_H */
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_CDC_ECM */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_AUDIO == 1
|
||||||
|
#include "usbd_audio.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_AUDIO */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_CUSTOMHID == 1
|
||||||
|
#include "usbd_customhid.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_CUSTOMHID */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_VIDEO == 1
|
||||||
|
#include "usbd_video.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_VIDEO */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_PRINTER == 1
|
||||||
|
#include "usbd_printer.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_PRINTER */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_CCID == 1U
|
||||||
|
#include "usbd_ccid.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_CCID */
|
||||||
|
|
||||||
|
#if USBD_CMPSIT_ACTIVATE_MTP == 1U
|
||||||
|
#include "usbd_mtp.h"
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_MTP */
|
||||||
|
|
||||||
|
/* Private defines -----------------------------------------------------------*/
|
||||||
|
/* By default all classes are deactivated, in order to activate a class
|
||||||
|
define its value to zero */
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_HID
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_HID 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_HID */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_MSC
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_MSC 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_MSC */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_DFU
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_DFU 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_DFU */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_CDC
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_CDC 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_CDC */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_CDC_ECM
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_CDC_ECM 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_CDC_ECM */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_RNDIS
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_RNDIS 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_RNDIS */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_AUDIO
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_AUDIO 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_AUDIO */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_CUSTOMHID
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_CUSTOMHID 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_CUSTOMHID */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_VIDEO
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_VIDEO 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_VIDEO */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_PRINTER
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_PRINTER 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_PRINTER */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_CCID
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_CCID 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_CCID */
|
||||||
|
|
||||||
|
#ifndef USBD_CMPSIT_ACTIVATE_MTP
|
||||||
|
#define USBD_CMPSIT_ACTIVATE_MTP 0U
|
||||||
|
#endif /* USBD_CMPSIT_ACTIVATE_MTP */
|
||||||
|
|
||||||
|
|
||||||
|
/* This is the maximum supported configuration descriptor size
|
||||||
|
User may define this value in usbd_conf.h in order to optimize footprint */
|
||||||
|
#ifndef USBD_CMPST_MAX_CONFDESC_SZ
|
||||||
|
#define USBD_CMPST_MAX_CONFDESC_SZ 300U
|
||||||
|
#endif /* USBD_CMPST_MAX_CONFDESC_SZ */
|
||||||
|
|
||||||
|
#ifndef USBD_CONFIG_STR_DESC_IDX
|
||||||
|
#define USBD_CONFIG_STR_DESC_IDX 4U
|
||||||
|
#endif /* USBD_CONFIG_STR_DESC_IDX */
|
||||||
|
|
||||||
|
/* Exported types ------------------------------------------------------------*/
|
||||||
|
/* USB Iad descriptors structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bFirstInterface;
|
||||||
|
uint8_t bInterfaceCount;
|
||||||
|
uint8_t bFunctionClass;
|
||||||
|
uint8_t bFunctionSubClass;
|
||||||
|
uint8_t bFunctionProtocol;
|
||||||
|
uint8_t iFunction;
|
||||||
|
} USBD_IadDescTypeDef;
|
||||||
|
|
||||||
|
/* USB interface descriptors structure */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bInterfaceNumber;
|
||||||
|
uint8_t bAlternateSetting;
|
||||||
|
uint8_t bNumEndpoints;
|
||||||
|
uint8_t bInterfaceClass;
|
||||||
|
uint8_t bInterfaceSubClass;
|
||||||
|
uint8_t bInterfaceProtocol;
|
||||||
|
uint8_t iInterface;
|
||||||
|
} USBD_IfDescTypeDef;
|
||||||
|
|
||||||
|
#if (USBD_CMPSIT_ACTIVATE_CDC == 1) || (USBD_CMPSIT_ACTIVATE_RNDIS == 1) || (USBD_CMPSIT_ACTIVATE_CDC_ECM == 1)
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* CDC Class specification revision 1.2
|
||||||
|
* Table 15: Class-Specific Descriptor Header Format
|
||||||
|
*/
|
||||||
|
/* Header Functional Descriptor */
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint16_t bcdCDC;
|
||||||
|
} __PACKED USBD_CDCHeaderFuncDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
/* Call Management Functional Descriptor */
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bmCapabilities;
|
||||||
|
uint8_t bDataInterface;
|
||||||
|
} USBD_CDCCallMgmFuncDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
/* ACM Functional Descriptor */
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bmCapabilities;
|
||||||
|
} USBD_CDCACMFuncDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* CDC Class specification revision 1.2
|
||||||
|
* Table 16: Union Interface Functional Descriptor
|
||||||
|
*/
|
||||||
|
/* Union Functional Descriptor */
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bMasterInterface;
|
||||||
|
uint8_t bSlaveInterface;
|
||||||
|
} USBD_CDCUnionFuncDescTypeDef;
|
||||||
|
|
||||||
|
#endif /* (USBD_CMPSIT_ACTIVATE_CDC == 1) || (USBD_CMPSIT_ACTIVATE_RNDIS == 1) || (USBD_CMPSIT_ACTIVATE_CDC_ECM == 1)*/
|
||||||
|
|
||||||
|
extern USBD_ClassTypeDef USBD_CMPSIT;
|
||||||
|
|
||||||
|
/* Exported functions prototypes ---------------------------------------------*/
|
||||||
|
uint8_t USBD_CMPSIT_AddToConfDesc(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CMPSIT_AddClass(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_ClassTypeDef *pclass,
|
||||||
|
USBD_CompositeClassTypeDef class,
|
||||||
|
uint8_t cfgidx);
|
||||||
|
|
||||||
|
uint32_t USBD_CMPSIT_SetClassID(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_CompositeClassTypeDef Class,
|
||||||
|
uint32_t Instance);
|
||||||
|
|
||||||
|
uint32_t USBD_CMPSIT_GetClassID(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_CompositeClassTypeDef Class,
|
||||||
|
uint32_t Instance);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
uint8_t USBD_CMPST_ClearConfDesc(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
/* Private macro -----------------------------------------------------------*/
|
||||||
|
#define __USBD_CMPSIT_SET_EP(epadd, eptype, epsize, HSinterval, FSinterval) \
|
||||||
|
do { \
|
||||||
|
/* Append Endpoint descriptor to Configuration descriptor */ \
|
||||||
|
pEpDesc = ((USBD_EpDescTypeDef*)((uint32_t)pConf + *Sze)); \
|
||||||
|
pEpDesc->bLength = (uint8_t)sizeof(USBD_EpDescTypeDef); \
|
||||||
|
pEpDesc->bDescriptorType = USB_DESC_TYPE_ENDPOINT; \
|
||||||
|
pEpDesc->bEndpointAddress = (epadd); \
|
||||||
|
pEpDesc->bmAttributes = (eptype); \
|
||||||
|
pEpDesc->wMaxPacketSize = (uint16_t)(epsize); \
|
||||||
|
if(speed == (uint8_t)USBD_SPEED_HIGH) \
|
||||||
|
{ \
|
||||||
|
pEpDesc->bInterval = HSinterval; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
pEpDesc->bInterval = FSinterval; \
|
||||||
|
} \
|
||||||
|
*Sze += (uint32_t)sizeof(USBD_EpDescTypeDef); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
#define __USBD_CMPSIT_SET_IF(ifnum, alt, eps, class, subclass, protocol, istring) \
|
||||||
|
do { \
|
||||||
|
/* Interface Descriptor */ \
|
||||||
|
pIfDesc = ((USBD_IfDescTypeDef*)((uint32_t)pConf + *Sze)); \
|
||||||
|
pIfDesc->bLength = (uint8_t)sizeof(USBD_IfDescTypeDef); \
|
||||||
|
pIfDesc->bDescriptorType = USB_DESC_TYPE_INTERFACE; \
|
||||||
|
pIfDesc->bInterfaceNumber = ifnum; \
|
||||||
|
pIfDesc->bAlternateSetting = alt; \
|
||||||
|
pIfDesc->bNumEndpoints = eps; \
|
||||||
|
pIfDesc->bInterfaceClass = class; \
|
||||||
|
pIfDesc->bInterfaceSubClass = subclass; \
|
||||||
|
pIfDesc->bInterfaceProtocol = protocol; \
|
||||||
|
pIfDesc->iInterface = istring; \
|
||||||
|
*Sze += (uint32_t)sizeof(USBD_IfDescTypeDef); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __USBD_COMPOSITE_BUILDER_H__ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
1884
Class/CompositeBuilder/Src/usbd_composite_builder.c
Normal file
1884
Class/CompositeBuilder/Src/usbd_composite_builder.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -40,17 +40,21 @@ extern "C" {
|
|||||||
/** @defgroup USBD_CUSTOM_HID_Exported_Defines
|
/** @defgroup USBD_CUSTOM_HID_Exported_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#ifndef CUSTOM_HID_EPIN_ADDR
|
||||||
#define CUSTOM_HID_EPIN_ADDR 0x81U
|
#define CUSTOM_HID_EPIN_ADDR 0x81U
|
||||||
|
#endif /* CUSTOM_HID_EPIN_ADDR */
|
||||||
|
|
||||||
#ifndef CUSTOM_HID_EPIN_SIZE
|
#ifndef CUSTOM_HID_EPIN_SIZE
|
||||||
#define CUSTOM_HID_EPIN_SIZE 0x02U
|
#define CUSTOM_HID_EPIN_SIZE 0x02U
|
||||||
#endif
|
#endif /* CUSTOM_HID_EPIN_SIZE */
|
||||||
|
|
||||||
|
#ifndef CUSTOM_HID_EPOUT_ADDR
|
||||||
#define CUSTOM_HID_EPOUT_ADDR 0x01U
|
#define CUSTOM_HID_EPOUT_ADDR 0x01U
|
||||||
|
#endif /* CUSTOM_HID_EPOUT_ADDR */
|
||||||
|
|
||||||
#ifndef CUSTOM_HID_EPOUT_SIZE
|
#ifndef CUSTOM_HID_EPOUT_SIZE
|
||||||
#define CUSTOM_HID_EPOUT_SIZE 0x02U
|
#define CUSTOM_HID_EPOUT_SIZE 0x02U
|
||||||
#endif
|
#endif /* CUSTOM_HID_EPOUT_SIZE*/
|
||||||
|
|
||||||
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U
|
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U
|
||||||
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
||||||
@@ -99,10 +103,22 @@ typedef enum
|
|||||||
typedef struct _USBD_CUSTOM_HID_Itf
|
typedef struct _USBD_CUSTOM_HID_Itf
|
||||||
{
|
{
|
||||||
uint8_t *pReport;
|
uint8_t *pReport;
|
||||||
|
#ifdef USBD_CUSTOMHID_REPORT_DESC_SIZE_ENABLED
|
||||||
|
uint16_t wReportDescLen;
|
||||||
|
#endif /* USBD_CUSTOMHID_REPORT_DESC_SIZE_ENABLED */
|
||||||
int8_t (* Init)(void);
|
int8_t (* Init)(void);
|
||||||
int8_t (* DeInit)(void);
|
int8_t (* DeInit)(void);
|
||||||
|
#ifdef USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED
|
||||||
|
int8_t (* OutEvent)(uint8_t *report_buffer);
|
||||||
|
#else
|
||||||
int8_t (* OutEvent)(uint8_t event_idx, uint8_t state);
|
int8_t (* OutEvent)(uint8_t event_idx, uint8_t state);
|
||||||
|
#endif /* USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED */
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
|
||||||
|
int8_t (* CtrlReqComplete)(uint8_t request, uint16_t wLength);
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
|
||||||
|
uint8_t *(* GetReport)(uint16_t *ReportLength);
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||||
} USBD_CUSTOM_HID_ItfTypeDef;
|
} USBD_CUSTOM_HID_ItfTypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -114,6 +130,23 @@ typedef struct
|
|||||||
uint32_t IsReportAvailable;
|
uint32_t IsReportAvailable;
|
||||||
CUSTOM_HID_StateTypeDef state;
|
CUSTOM_HID_StateTypeDef state;
|
||||||
} USBD_CUSTOM_HID_HandleTypeDef;
|
} USBD_CUSTOM_HID_HandleTypeDef;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* HID Class specification version 1.1
|
||||||
|
* 6.2.1 HID Descriptor
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorTypeCHID;
|
||||||
|
uint16_t bcdCUSTOM_HID;
|
||||||
|
uint8_t bCountryCode;
|
||||||
|
uint8_t bNumDescriptors;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint16_t wItemLength;
|
||||||
|
} __PACKED USBD_DescTypeDef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -141,9 +174,13 @@ extern USBD_ClassTypeDef USBD_CUSTOM_HID;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *report, uint16_t len, uint8_t ClassId);
|
||||||
|
#else
|
||||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *report, uint16_t len);
|
uint8_t *report, uint16_t len);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev);
|
uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
|
|||||||
@@ -91,12 +91,12 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqType
|
|||||||
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length);
|
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -117,27 +117,36 @@ USBD_ClassTypeDef USBD_CUSTOM_HID =
|
|||||||
NULL, /*SOF */
|
NULL, /*SOF */
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_CUSTOM_HID_GetHSCfgDesc,
|
USBD_CUSTOM_HID_GetHSCfgDesc,
|
||||||
USBD_CUSTOM_HID_GetFSCfgDesc,
|
USBD_CUSTOM_HID_GetFSCfgDesc,
|
||||||
USBD_CUSTOM_HID_GetOtherSpeedCfgDesc,
|
USBD_CUSTOM_HID_GetOtherSpeedCfgDesc,
|
||||||
USBD_CUSTOM_HID_GetDeviceQualifierDesc,
|
USBD_CUSTOM_HID_GetDeviceQualifierDesc,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB CUSTOM_HID device FS Configuration Descriptor */
|
/* USB CUSTOM_HID device FS Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
LOBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */
|
||||||
0x00,
|
HIBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ),
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
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)
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
/************** Descriptor of CUSTOM HID interface ****************/
|
/************** Descriptor of CUSTOM HID interface ****************/
|
||||||
@@ -158,10 +167,11 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DES
|
|||||||
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /* bCountryCode: Hardware target country */
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors
|
||||||
|
to follow */
|
||||||
0x22, /* bDescriptorType */
|
0x22, /* bDescriptorType */
|
||||||
USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
|
||||||
/******************** Descriptor of Custom HID endpoints ********************/
|
/******************** Descriptor of Custom HID endpoints ********************/
|
||||||
/* 27 */
|
/* 27 */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
@@ -169,8 +179,8 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DES
|
|||||||
|
|
||||||
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPIN_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
LOBYTE(CUSTOM_HID_EPIN_SIZE), /* wMaxPacketSize: 2 Bytes max */
|
||||||
0x00,
|
HIBYTE(CUSTOM_HID_EPIN_SIZE),
|
||||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
|
|
||||||
@@ -178,133 +188,12 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DES
|
|||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
LOBYTE(CUSTOM_HID_EPOUT_SIZE), /* wMaxPacketSize: 2 Bytes max */
|
||||||
0x00,
|
HIBYTE(CUSTOM_HID_EPOUT_SIZE),
|
||||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 41 */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* USB CUSTOM_HID device HS Configuration Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgHSDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
|
||||||
{
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
|
||||||
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) */
|
|
||||||
|
|
||||||
/************** Descriptor of CUSTOM HID interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: CUSTOM_HID */
|
|
||||||
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of CUSTOM_HID *************************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
|
||||||
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
|
||||||
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
|
||||||
0x01,
|
|
||||||
0x00, /* bCountryCode: Hardware target country */
|
|
||||||
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
|
||||||
0x22, /* bDescriptorType */
|
|
||||||
USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Custom HID endpoints ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType */
|
|
||||||
|
|
||||||
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
CUSTOM_HID_EPIN_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
|
||||||
0x00,
|
|
||||||
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
|
||||||
0x00,
|
|
||||||
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 41 */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* USB CUSTOM_HID device Other Speed Configuration Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
|
||||||
{
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
|
||||||
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) */
|
|
||||||
|
|
||||||
/************** Descriptor of CUSTOM HID interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: CUSTOM_HID */
|
|
||||||
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of CUSTOM_HID *************************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
|
||||||
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
|
||||||
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
|
||||||
0x01,
|
|
||||||
0x00, /* bCountryCode: Hardware target country */
|
|
||||||
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
|
||||||
0x22, /* bDescriptorType */
|
|
||||||
USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Custom HID endpoints ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
|
|
||||||
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
CUSTOM_HID_EPIN_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
|
||||||
0x00,
|
|
||||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
|
||||||
0x00,
|
|
||||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 41 */
|
/* 41 */
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* USB CUSTOM_HID device Configuration Descriptor */
|
/* USB CUSTOM_HID device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALIGN_END =
|
||||||
@@ -315,12 +204,14 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALI
|
|||||||
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /* bCountryCode: Hardware target country */
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors
|
||||||
|
to follow */
|
||||||
0x22, /* bDescriptorType */
|
0x22, /* bDescriptorType */
|
||||||
USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -335,7 +226,10 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUA
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
static uint8_t CUSTOMHIDInEpAdd = CUSTOM_HID_EPIN_ADDR;
|
||||||
|
static uint8_t CUSTOMHIDOutEpAdd = CUSTOM_HID_EPOUT_ADDR;
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -360,42 +254,56 @@ static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
if (hhid == NULL)
|
if (hhid == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pClassData = (void *)hhid;
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hhid;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
|
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
|
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||||
}
|
}
|
||||||
else /* LOW and FULL-speed endpoints */
|
else /* LOW and FULL-speed endpoints */
|
||||||
{
|
{
|
||||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
|
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
|
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, CUSTOM_HID_EPIN_ADDR, USBD_EP_TYPE_INTR,
|
(void)USBD_LL_OpenEP(pdev, CUSTOMHIDInEpAdd, USBD_EP_TYPE_INTR,
|
||||||
CUSTOM_HID_EPIN_SIZE);
|
CUSTOM_HID_EPIN_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
if (USBD_CUSTOMHID_OUTREPORT_BUF_SIZE < CUSTOM_HID_EPOUT_SIZE)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, CUSTOM_HID_EPOUT_ADDR, USBD_EP_TYPE_INTR,
|
(void)USBD_LL_OpenEP(pdev, CUSTOMHIDOutEpAdd, USBD_EP_TYPE_INTR,
|
||||||
CUSTOM_HID_EPOUT_SIZE);
|
CUSTOM_HID_EPOUT_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 1U;
|
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
hhid->state = CUSTOM_HID_IDLE;
|
hhid->state = CUSTOM_HID_IDLE;
|
||||||
|
|
||||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->Init();
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||||
|
|
||||||
|
#ifndef USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED
|
||||||
/* Prepare Out endpoint to receive 1st packet */
|
/* Prepare Out endpoint to receive 1st packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
|
(void)USBD_LL_PrepareReceive(pdev, CUSTOMHIDOutEpAdd, hhid->Report_buf,
|
||||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||||
|
#endif /* USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED */
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -411,21 +319,28 @@ static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close CUSTOM_HID EP IN */
|
/* Close CUSTOM_HID EP IN */
|
||||||
(void)USBD_LL_CloseEP(pdev, CUSTOM_HID_EPIN_ADDR);
|
(void)USBD_LL_CloseEP(pdev, CUSTOMHIDInEpAdd);
|
||||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].is_used = 0U;
|
||||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].bInterval = 0U;
|
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* Close CUSTOM_HID EP OUT */
|
/* Close CUSTOM_HID EP OUT */
|
||||||
(void)USBD_LL_CloseEP(pdev, CUSTOM_HID_EPOUT_ADDR);
|
(void)USBD_LL_CloseEP(pdev, CUSTOMHIDOutEpAdd);
|
||||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 0U;
|
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].is_used = 0U;
|
||||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].bInterval = 0U;
|
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* Free allocated memory */
|
/* Free allocated memory */
|
||||||
if (pdev->pClassData != NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,8 +357,11 @@ static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint16_t len = 0U;
|
uint16_t len = 0U;
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
|
||||||
|
uint16_t ReportLength = 0U;
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||||
uint8_t *pbuf = NULL;
|
uint8_t *pbuf = NULL;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
@@ -475,10 +393,67 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CUSTOM_HID_REQ_SET_REPORT:
|
case CUSTOM_HID_REQ_SET_REPORT:
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
|
||||||
|
if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL)
|
||||||
|
{
|
||||||
|
/* Let the application decide when to enable EP0 to receive the next report */
|
||||||
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete(req->bRequest,
|
||||||
|
req->wLength);
|
||||||
|
}
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||||
|
#ifndef USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED
|
||||||
|
|
||||||
|
if (req->wLength > USBD_CUSTOMHID_OUTREPORT_BUF_SIZE)
|
||||||
|
{
|
||||||
|
/* Stall EP0 */
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
return USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
hhid->IsReportAvailable = 1U;
|
hhid->IsReportAvailable = 1U;
|
||||||
(void)USBD_CtlPrepareRx(pdev, hhid->Report_buf,
|
|
||||||
MIN(req->wLength, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE));
|
(void)USBD_CtlPrepareRx(pdev, hhid->Report_buf, req->wLength);
|
||||||
|
#endif /* USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED */
|
||||||
break;
|
break;
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
|
||||||
|
case CUSTOM_HID_REQ_GET_REPORT:
|
||||||
|
if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->GetReport != NULL)
|
||||||
|
{
|
||||||
|
ReportLength = req->wLength;
|
||||||
|
|
||||||
|
/* Get report data buffer */
|
||||||
|
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->GetReport(&ReportLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((pbuf != NULL) && (ReportLength != 0U))
|
||||||
|
{
|
||||||
|
len = MIN(ReportLength, req->wLength);
|
||||||
|
|
||||||
|
/* Send the report data over EP0 */
|
||||||
|
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
|
||||||
|
if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL)
|
||||||
|
{
|
||||||
|
/* Let the application decide what to do, keep EP0 data phase in NAK state and
|
||||||
|
use USBD_CtlSendData() when data become available or stall the EP0 data phase */
|
||||||
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete(req->bRequest,
|
||||||
|
req->wLength);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Stall EP0 if no data available */
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* Stall EP0 if no data available */
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError(pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
@@ -506,7 +481,7 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
if ((req->wValue >> 8) == CUSTOM_HID_REPORT_DESC)
|
if ((req->wValue >> 8) == CUSTOM_HID_REPORT_DESC)
|
||||||
{
|
{
|
||||||
len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE, req->wLength);
|
len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE, req->wLength);
|
||||||
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport;
|
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->pReport;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -517,7 +492,15 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
if (pbuf != NULL)
|
||||||
|
{
|
||||||
|
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE:
|
case USB_REQ_GET_INTERFACE:
|
||||||
@@ -567,26 +550,37 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
|||||||
* Send CUSTOM_HID Report
|
* Send CUSTOM_HID Report
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param buff: pointer to report
|
* @param buff: pointer to report
|
||||||
|
* @param ClassId: The Class ID
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t *report, uint16_t len, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *report, uint16_t len)
|
uint8_t *report, uint16_t len)
|
||||||
{
|
{
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
if (hhid == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get Endpoint IN address allocated for this class instance */
|
||||||
|
CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, ClassId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
if (hhid->state == CUSTOM_HID_IDLE)
|
if (hhid->state == CUSTOM_HID_IDLE)
|
||||||
{
|
{
|
||||||
hhid->state = CUSTOM_HID_BUSY;
|
hhid->state = CUSTOM_HID_BUSY;
|
||||||
(void)USBD_LL_Transmit(pdev, CUSTOM_HID_EPIN_ADDR, report, len);
|
(void)USBD_LL_Transmit(pdev, CUSTOMHIDInEpAdd, report, len);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -595,7 +589,7 @@ uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CUSTOM_HID_GetFSCfgDesc
|
* @brief USBD_CUSTOM_HID_GetFSCfgDesc
|
||||||
* return FS configuration descriptor
|
* return FS configuration descriptor
|
||||||
@@ -605,9 +599,23 @@ uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPIN_ADDR);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPOUT_ADDR);
|
||||||
|
|
||||||
return USBD_CUSTOM_HID_CfgFSDesc;
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CUSTOM_HID_EPIN_SIZE;
|
||||||
|
pEpInDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CUSTOM_HID_EPOUT_SIZE;
|
||||||
|
pEpOutDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgDesc);
|
||||||
|
return USBD_CUSTOM_HID_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -619,9 +627,23 @@ static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgHSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPIN_ADDR);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPOUT_ADDR);
|
||||||
|
|
||||||
return USBD_CUSTOM_HID_CfgHSDesc;
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CUSTOM_HID_EPIN_SIZE;
|
||||||
|
pEpInDesc->bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CUSTOM_HID_EPOUT_SIZE;
|
||||||
|
pEpOutDesc->bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgDesc);
|
||||||
|
return USBD_CUSTOM_HID_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -633,10 +655,25 @@ static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_OtherSpeedCfgDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPIN_ADDR);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPOUT_ADDR);
|
||||||
|
|
||||||
return USBD_CUSTOM_HID_OtherSpeedCfgDesc;
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = CUSTOM_HID_EPIN_SIZE;
|
||||||
|
pEpInDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = CUSTOM_HID_EPOUT_SIZE;
|
||||||
|
pEpOutDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgDesc);
|
||||||
|
return USBD_CUSTOM_HID_CfgDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CUSTOM_HID_DataIn
|
* @brief USBD_CUSTOM_HID_DataIn
|
||||||
@@ -651,7 +688,7 @@ static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
|
|
||||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||||
be caused by a new transfer before the end of the previous transfer */
|
be caused by a new transfer before the end of the previous transfer */
|
||||||
((USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData)->state = CUSTOM_HID_IDLE;
|
((USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = CUSTOM_HID_IDLE;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -668,17 +705,22 @@ static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
UNUSED(epnum);
|
UNUSED(epnum);
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* USB data will be immediately processed, this allow next USB traffic being
|
/* USB data will be immediately processed, this allow next USB traffic being
|
||||||
NAKed till the end of the application processing */
|
NAKed till the end of the application processing */
|
||||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0],
|
|
||||||
hhid->Report_buf[1]);
|
#ifdef USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED
|
||||||
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->OutEvent(hhid->Report_buf);
|
||||||
|
#else
|
||||||
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->OutEvent(hhid->Report_buf[0],
|
||||||
|
hhid->Report_buf[1]);
|
||||||
|
#endif /* USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED */
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -694,15 +736,20 @@ uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev)
|
|||||||
{
|
{
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get OUT Endpoint address allocated for this class instance */
|
||||||
|
CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* Resume USB Out process */
|
/* Resume USB Out process */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
|
(void)USBD_LL_PrepareReceive(pdev, CUSTOMHIDOutEpAdd, hhid->Report_buf,
|
||||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
@@ -717,7 +764,7 @@ uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hhid == NULL)
|
if (hhid == NULL)
|
||||||
{
|
{
|
||||||
@@ -726,14 +773,19 @@ static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
if (hhid->IsReportAvailable == 1U)
|
if (hhid->IsReportAvailable == 1U)
|
||||||
{
|
{
|
||||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0],
|
#ifdef USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED
|
||||||
hhid->Report_buf[1]);
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->OutEvent(hhid->Report_buf);
|
||||||
|
#else
|
||||||
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->OutEvent(hhid->Report_buf[0],
|
||||||
|
hhid->Report_buf[1]);
|
||||||
|
#endif /* USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED */
|
||||||
hhid->IsReportAvailable = 0U;
|
hhid->IsReportAvailable = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
@@ -746,7 +798,7 @@ static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_CUSTOM_HID_DeviceQualifierDesc;
|
return USBD_CUSTOM_HID_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CUSTOM_HID_RegisterInterface
|
* @brief USBD_CUSTOM_HID_RegisterInterface
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
@@ -761,7 +813,7 @@ uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,14 +32,39 @@ EndBSPDependencies */
|
|||||||
|
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_Init(void);
|
static int8_t TEMPLATE_CUSTOM_HID_Init(void);
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_DeInit(void);
|
static int8_t TEMPLATE_CUSTOM_HID_DeInit(void);
|
||||||
|
#ifdef USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED
|
||||||
|
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t *report_buffer);
|
||||||
|
#else
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state);
|
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state);
|
||||||
|
#endif /* USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED */
|
||||||
|
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
|
||||||
|
static int8_t TEMPLATE_CUSTOM_HID_CtrlReqComplete(uint8_t request, uint16_t wLength);
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||||
|
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
|
||||||
|
static uint8_t *TEMPLATE_CUSTOM_HID_GetReport(uint16_t *ReportLength);
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
extern USBD_HandleTypeDef USBD_Device;
|
||||||
|
|
||||||
|
__ALIGN_BEGIN static uint8_t TEMPLATE_CUSTOM_HID_ReportDesc[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END = {0};
|
||||||
|
|
||||||
USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops =
|
USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops =
|
||||||
{
|
{
|
||||||
TEMPLATE_CUSTOM_HID_ReportDesc,
|
TEMPLATE_CUSTOM_HID_ReportDesc,
|
||||||
|
#ifdef USBD_CUSTOMHID_REPORT_DESC_SIZE_ENABLED
|
||||||
|
USBD_CUSTOM_HID_REPORT_DESC_SIZE,
|
||||||
|
#endif /* USBD_CUSTOMHID_REPORT_DESC_SIZE_ENABLED */
|
||||||
TEMPLATE_CUSTOM_HID_Init,
|
TEMPLATE_CUSTOM_HID_Init,
|
||||||
TEMPLATE_CUSTOM_HID_DeInit,
|
TEMPLATE_CUSTOM_HID_DeInit,
|
||||||
TEMPLATE_CUSTOM_HID_OutEvent,
|
TEMPLATE_CUSTOM_HID_OutEvent,
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
|
||||||
|
TEMPLATE_CUSTOM_HID_CtrlReqComplete,
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
|
||||||
|
TEMPLATE_CUSTOM_HID_GetReport,
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
@@ -77,14 +102,71 @@ static int8_t TEMPLATE_CUSTOM_HID_DeInit(void)
|
|||||||
* @param state: event state
|
* @param state: event state
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED
|
||||||
|
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t *report_buffer)
|
||||||
|
{
|
||||||
|
UNUSED(report_buffer);
|
||||||
|
#else
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state)
|
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state)
|
||||||
{
|
{
|
||||||
UNUSED(event_idx);
|
UNUSED(event_idx);
|
||||||
UNUSED(state);
|
UNUSED(state);
|
||||||
|
#endif /* USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED */
|
||||||
|
|
||||||
/* Start next USB packet transfer once data processing is completed */
|
/* Start next USB packet transfer once data processing is completed */
|
||||||
USBD_CUSTOM_HID_ReceivePacket(&USBD_Device);
|
if (USBD_CUSTOM_HID_ReceivePacket(&USBD_Device) != (uint8_t)USBD_OK)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
|
||||||
|
/**
|
||||||
|
* @brief TEMPLATE_CUSTOM_HID_CtrlReqComplete
|
||||||
|
* Manage the CUSTOM HID control request complete
|
||||||
|
* @param request: control request
|
||||||
|
* @param wLength: request wLength
|
||||||
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
|
*/
|
||||||
|
static int8_t TEMPLATE_CUSTOM_HID_CtrlReqComplete(uint8_t request, uint16_t wLength)
|
||||||
|
{
|
||||||
|
UNUSED(wLength);
|
||||||
|
|
||||||
|
switch (request)
|
||||||
|
{
|
||||||
|
case CUSTOM_HID_REQ_SET_REPORT:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CUSTOM_HID_REQ_GET_REPORT:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
|
||||||
|
/**
|
||||||
|
* @brief TEMPLATE_CUSTOM_HID_GetReport
|
||||||
|
* Manage the CUSTOM HID control Get Report request
|
||||||
|
* @param event_idx: event index
|
||||||
|
* @param state: event state
|
||||||
|
* @retval return pointer to HID report
|
||||||
|
*/
|
||||||
|
static uint8_t *TEMPLATE_CUSTOM_HID_GetReport(uint16_t *ReportLength)
|
||||||
|
{
|
||||||
|
UNUSED(ReportLength);
|
||||||
|
uint8_t *pbuff = NULL;
|
||||||
|
|
||||||
|
return (pbuff);
|
||||||
|
}
|
||||||
|
#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||||
|
|||||||
@@ -52,11 +52,21 @@ extern "C" {
|
|||||||
#define USBD_DFU_APP_DEFAULT_ADD 0x08008000U /* The first sector (32 KB) is reserved for DFU code */
|
#define USBD_DFU_APP_DEFAULT_ADD 0x08008000U /* The first sector (32 KB) is reserved for DFU code */
|
||||||
#endif /* USBD_DFU_APP_DEFAULT_ADD */
|
#endif /* USBD_DFU_APP_DEFAULT_ADD */
|
||||||
|
|
||||||
|
#ifndef USBD_DFU_BM_ATTRIBUTES
|
||||||
|
#define USBD_DFU_BM_ATTRIBUTES 0x0BU
|
||||||
|
#endif /* USBD_DFU_BM_ATTRIBUTES */
|
||||||
|
|
||||||
|
#ifndef USBD_DFU_DETACH_TIMEOUT
|
||||||
|
#define USBD_DFU_DETACH_TIMEOUT 0xFFU
|
||||||
|
#endif /* USBD_DFU_DETACH_TIMEOUT */
|
||||||
|
|
||||||
#define USB_DFU_CONFIG_DESC_SIZ (18U + (9U * USBD_DFU_MAX_ITF_NUM))
|
#define USB_DFU_CONFIG_DESC_SIZ (18U + (9U * USBD_DFU_MAX_ITF_NUM))
|
||||||
#define USB_DFU_DESC_SIZ 9U
|
#define USB_DFU_DESC_SIZ 9U
|
||||||
|
|
||||||
#define DFU_DESCRIPTOR_TYPE 0x21U
|
#define DFU_DESCRIPTOR_TYPE 0x21U
|
||||||
|
|
||||||
|
#define DFU_VENDOR_CMD_MAX 32U
|
||||||
|
|
||||||
|
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/* DFU Requests DFU states */
|
/* DFU Requests DFU states */
|
||||||
@@ -114,9 +124,15 @@ extern "C" {
|
|||||||
/* Other defines */
|
/* Other defines */
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/* Bit Detach capable = bit 3 in bmAttributes field */
|
/* Bit Detach capable = bit 3 in bmAttributes field */
|
||||||
#define DFU_DETACH_MASK (1U << 4)
|
#define DFU_DETACH_MASK (1U << 3)
|
||||||
|
#define DFU_MANIFEST_MASK (1U << 2)
|
||||||
#define DFU_STATUS_DEPTH 6U
|
#define DFU_STATUS_DEPTH 6U
|
||||||
|
|
||||||
|
#define IS_DFU_DOWNLOAD 0x0DFDFU
|
||||||
|
#define IS_DFU_UPLOAD 0x1DFDFU
|
||||||
|
#define IS_DFU_SETADDRESSPOINTER 0x2DFDFU
|
||||||
|
#define IS_DFU_PHY_ADDRESS 0x3DFDFU
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
DFU_DETACH = 0U,
|
DFU_DETACH = 0U,
|
||||||
@@ -167,6 +183,7 @@ typedef struct
|
|||||||
uint32_t wblock_num;
|
uint32_t wblock_num;
|
||||||
uint32_t wlength;
|
uint32_t wlength;
|
||||||
uint32_t data_ptr;
|
uint32_t data_ptr;
|
||||||
|
uint32_t app_addr_ptr;
|
||||||
uint32_t alt_setting;
|
uint32_t alt_setting;
|
||||||
|
|
||||||
uint8_t dev_status[DFU_STATUS_DEPTH];
|
uint8_t dev_status[DFU_STATUS_DEPTH];
|
||||||
@@ -184,7 +201,29 @@ typedef struct
|
|||||||
uint16_t (* Write)(uint8_t *src, uint8_t *dest, uint32_t Len);
|
uint16_t (* Write)(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||||
uint8_t *(* Read)(uint8_t *src, uint8_t *dest, uint32_t Len);
|
uint8_t *(* Read)(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||||
uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
|
uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
uint16_t (* GetVendorCMD)(uint8_t *cmd, uint8_t *cmdlength);
|
||||||
|
uint16_t (* VendorDownloadCMD)(uint8_t *pbuf, uint32_t BlockNumber, uint32_t wlength, uint32_t *status);
|
||||||
|
uint16_t (* VendorUploadCMD)(uint32_t Add, uint32_t BlockNumber, uint32_t *status);
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
|
uint16_t (* VendorCheck)(uint8_t *pbuf, uint32_t ReqType, uint32_t *status);
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||||
|
uint16_t (* LeaveDFU)(uint32_t Add);
|
||||||
|
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||||
} USBD_DFU_MediaTypeDef;
|
} USBD_DFU_MediaTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bmAttributes;
|
||||||
|
uint16_t wDetachTimeout;
|
||||||
|
uint16_t wTransferSze;
|
||||||
|
uint16_t bcdDFUVersion;
|
||||||
|
} __PACKED USBD_DFUFuncDescTypeDef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -104,13 +104,15 @@ static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
|||||||
static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev);
|
static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev);
|
||||||
static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev);
|
static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_DFU_GetCfgDesc(uint16_t *length);
|
static uint8_t *USBD_DFU_GetCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length);
|
static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev,
|
static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t index, uint16_t *length);
|
uint8_t index, uint16_t *length);
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
@@ -120,6 +122,7 @@ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev);
|
|||||||
static void DFU_GetState(USBD_HandleTypeDef *pdev);
|
static void DFU_GetState(USBD_HandleTypeDef *pdev);
|
||||||
static void DFU_Abort(USBD_HandleTypeDef *pdev);
|
static void DFU_Abort(USBD_HandleTypeDef *pdev);
|
||||||
static void DFU_Leave(USBD_HandleTypeDef *pdev);
|
static void DFU_Leave(USBD_HandleTypeDef *pdev);
|
||||||
|
static void *USBD_DFU_GetDfuFuncDesc(uint8_t *pConfDesc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -141,15 +144,23 @@ USBD_ClassTypeDef USBD_DFU =
|
|||||||
USBD_DFU_SOF,
|
USBD_DFU_SOF,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_DFU_GetCfgDesc,
|
USBD_DFU_GetCfgDesc,
|
||||||
USBD_DFU_GetCfgDesc,
|
USBD_DFU_GetCfgDesc,
|
||||||
USBD_DFU_GetCfgDesc,
|
USBD_DFU_GetCfgDesc,
|
||||||
USBD_DFU_GetDeviceQualifierDesc,
|
USBD_DFU_GetDeviceQualifierDesc,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
USBD_DFU_GetUsrStringDesc
|
USBD_DFU_GetUsrStringDesc
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB DFU device Configuration Descriptor */
|
/* USB DFU device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_DFU_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_DFU_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -159,12 +170,13 @@ __ALIGN_BEGIN static uint8_t USBD_DFU_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_E
|
|||||||
0x00,
|
0x00,
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x02, /* iConfiguration: Index of string descriptor describing the configuration */
|
0x02, /* iConfiguration: Index of string descriptor
|
||||||
|
describing the configuration */
|
||||||
#if (USBD_SELF_POWERED == 1U)
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
/* 09 */
|
/* 09 */
|
||||||
|
|
||||||
@@ -235,6 +247,7 @@ __ALIGN_BEGIN static uint8_t USBD_DFU_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -262,11 +275,12 @@ static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
if (hdfu == NULL)
|
if (hdfu == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pClassData = (void *)hdfu;
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hdfu;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hdfu->alt_setting = 0U;
|
hdfu->alt_setting = 0U;
|
||||||
hdfu->data_ptr = USBD_DFU_APP_DEFAULT_ADD;
|
hdfu->data_ptr = USBD_DFU_APP_DEFAULT_ADD;
|
||||||
@@ -284,7 +298,7 @@ static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
hdfu->dev_status[5] = 0U;
|
hdfu->dev_status[5] = 0U;
|
||||||
|
|
||||||
/* Initialize Hardware layer */
|
/* Initialize Hardware layer */
|
||||||
if (((USBD_DFU_MediaTypeDef *)pdev->pUserData)->Init() != USBD_OK)
|
if (((USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId])->Init() != USBD_OK)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
@@ -293,7 +307,7 @@ static uint8_t USBD_DFU_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_DFU_Init
|
* @brief USBD_DFU_DeInit
|
||||||
* De-Initialize the DFU layer
|
* De-Initialize the DFU layer
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
@@ -304,12 +318,12 @@ static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
USBD_DFU_HandleTypeDef *hdfu;
|
USBD_DFU_HandleTypeDef *hdfu;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
hdfu->wblock_num = 0U;
|
hdfu->wblock_num = 0U;
|
||||||
hdfu->wlength = 0U;
|
hdfu->wlength = 0U;
|
||||||
|
|
||||||
@@ -318,8 +332,9 @@ static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
hdfu->dev_status[4] = DFU_STATE_IDLE;
|
hdfu->dev_status[4] = DFU_STATE_IDLE;
|
||||||
|
|
||||||
/* DeInit physical Interface components and Hardware Layer */
|
/* DeInit physical Interface components and Hardware Layer */
|
||||||
((USBD_DFU_MediaTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
@@ -334,10 +349,10 @@ static uint8_t USBD_DFU_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
uint8_t *pbuf = NULL;
|
uint8_t *pbuf;
|
||||||
uint16_t len = 0U;
|
uint16_t len;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if (hdfu == NULL)
|
||||||
@@ -403,11 +418,19 @@ static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re
|
|||||||
case USB_REQ_GET_DESCRIPTOR:
|
case USB_REQ_GET_DESCRIPTOR:
|
||||||
if ((req->wValue >> 8) == DFU_DESCRIPTOR_TYPE)
|
if ((req->wValue >> 8) == DFU_DESCRIPTOR_TYPE)
|
||||||
{
|
{
|
||||||
pbuf = USBD_DFU_CfgDesc + (9U * (USBD_DFU_MAX_ITF_NUM + 1U));
|
pbuf = (uint8_t *)USBD_DFU_GetDfuFuncDesc(pdev->pConfDesc);
|
||||||
len = MIN(USB_DFU_DESC_SIZ, req->wLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
if (pbuf != NULL)
|
||||||
|
{
|
||||||
|
len = MIN(USB_DFU_DESC_SIZ, req->wLength);
|
||||||
|
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = USBD_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE:
|
case USB_REQ_GET_INTERFACE:
|
||||||
@@ -462,7 +485,7 @@ static uint8_t USBD_DFU_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re
|
|||||||
return (uint8_t)ret;
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_DFU_GetCfgDesc
|
* @brief USBD_DFU_GetCfgDesc
|
||||||
* return configuration descriptor
|
* return configuration descriptor
|
||||||
@@ -475,7 +498,7 @@ static uint8_t *USBD_DFU_GetCfgDesc(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_DFU_CfgDesc;
|
return USBD_DFU_CfgDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_DFU_EP0_RxReady
|
* @brief USBD_DFU_EP0_RxReady
|
||||||
@@ -489,6 +512,7 @@ static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_DFU_EP0_TxReady
|
* @brief USBD_DFU_EP0_TxReady
|
||||||
* handle EP0 TRx Ready event
|
* handle EP0 TRx Ready event
|
||||||
@@ -498,9 +522,13 @@ static uint8_t USBD_DFU_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_SetupReqTypedef req;
|
USBD_SetupReqTypedef req;
|
||||||
|
uint32_t app_addr_ptr;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData;
|
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U) || (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
|
uint32_t VendorStatus = 0U;
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if (hdfu == NULL)
|
||||||
{
|
{
|
||||||
@@ -518,11 +546,43 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
|||||||
{
|
{
|
||||||
/* Nothing to do */
|
/* Nothing to do */
|
||||||
}
|
}
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Vendor specific DFU CMD */
|
||||||
|
if (DfuInterface->VendorDownloadCMD(hdfu->buffer.d8, hdfu->wblock_num,
|
||||||
|
hdfu->wlength, &VendorStatus) != USBD_OK)
|
||||||
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
|
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
}
|
}
|
||||||
else if (hdfu->wlength == 5U)
|
else if (hdfu->wlength == 5U)
|
||||||
{
|
{
|
||||||
if (hdfu->buffer.d8[0] == DFU_CMD_SETADDRESSPOINTER)
|
if (hdfu->buffer.d8[0] == DFU_CMD_SETADDRESSPOINTER)
|
||||||
{
|
{
|
||||||
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
|
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_SETADDRESSPOINTER, &VendorStatus) != USBD_OK)
|
||||||
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
|
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
|
||||||
hdfu->data_ptr = hdfu->buffer.d8[1];
|
hdfu->data_ptr = hdfu->buffer.d8[1];
|
||||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[2] << 8;
|
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[2] << 8;
|
||||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[3] << 16;
|
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[3] << 16;
|
||||||
@@ -530,30 +590,114 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
else if (hdfu->buffer.d8[0] == DFU_CMD_ERASE)
|
else if (hdfu->buffer.d8[0] == DFU_CMD_ERASE)
|
||||||
{
|
{
|
||||||
hdfu->data_ptr = hdfu->buffer.d8[1];
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[2] << 8;
|
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_DOWNLOAD, &VendorStatus) != USBD_OK)
|
||||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[3] << 16;
|
|
||||||
hdfu->data_ptr += (uint32_t)hdfu->buffer.d8[4] << 24;
|
|
||||||
|
|
||||||
if (DfuInterface->Erase(hdfu->data_ptr) != USBD_OK)
|
|
||||||
{
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
|
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
|
||||||
|
app_addr_ptr = hdfu->buffer.d8[1];
|
||||||
|
app_addr_ptr += (uint32_t)hdfu->buffer.d8[2] << 8;
|
||||||
|
app_addr_ptr += (uint32_t)hdfu->buffer.d8[3] << 16;
|
||||||
|
app_addr_ptr += (uint32_t)hdfu->buffer.d8[4] << 24;
|
||||||
|
|
||||||
|
if (DfuInterface->Erase(app_addr_ptr) != USBD_OK)
|
||||||
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
|
hdfu->dev_status[0] = DFU_ERROR_VENDOR;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Vendor specific DFU CMD */
|
||||||
|
if (DfuInterface->VendorDownloadCMD(hdfu->buffer.d8, hdfu->wblock_num,
|
||||||
|
hdfu->wlength, &VendorStatus) != USBD_OK)
|
||||||
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
|
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
if (hdfu->wlength > 0U)
|
||||||
|
{
|
||||||
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
|
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_DOWNLOAD, &VendorStatus) != USBD_OK)
|
||||||
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
|
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
|
||||||
|
/* Vendor specific DFU CMD */
|
||||||
|
if (DfuInterface->VendorDownloadCMD(hdfu->buffer.d8, hdfu->wblock_num,
|
||||||
|
hdfu->wlength, &VendorStatus) != USBD_OK)
|
||||||
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
|
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
/* Reset the block number */
|
||||||
|
hdfu->wblock_num = 0U;
|
||||||
|
|
||||||
|
/* Call the error management function (command will be NAKed) */
|
||||||
|
req.bmRequest = 0U;
|
||||||
|
req.wLength = 1U;
|
||||||
|
USBD_CtlError(pdev, &req);
|
||||||
}
|
}
|
||||||
}
|
#else
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Reset the global length and block number */
|
/* Reset the global length and block number */
|
||||||
hdfu->wlength = 0U;
|
hdfu->wlength = 0U;
|
||||||
hdfu->wblock_num = 0U;
|
hdfu->wblock_num = 0U;
|
||||||
|
|
||||||
/* Call the error management function (command will be NAKed) */
|
/* Call the error management function (command will be NAKed) */
|
||||||
req.bmRequest = 0U;
|
req.bmRequest = 0U;
|
||||||
req.wLength = 1U;
|
req.wLength = 1U;
|
||||||
USBD_CtlError(pdev, &req);
|
USBD_CtlError(pdev, &req);
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Regular Download Command */
|
/* Regular Download Command */
|
||||||
@@ -561,12 +705,33 @@ static uint8_t USBD_DFU_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
|||||||
{
|
{
|
||||||
if (hdfu->wblock_num > 1U)
|
if (hdfu->wblock_num > 1U)
|
||||||
{
|
{
|
||||||
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
|
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_DOWNLOAD, &VendorStatus) != USBD_OK)
|
||||||
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
|
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
|
||||||
/* Decode the required address */
|
/* Decode the required address */
|
||||||
addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr;
|
addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr;
|
||||||
|
|
||||||
/* Perform the write operation */
|
/* Perform the write operation */
|
||||||
if (DfuInterface->Write(hdfu->buffer.d8, (uint8_t *)addr, hdfu->wlength) != USBD_OK)
|
if (DfuInterface->Write(hdfu->buffer.d8, (uint8_t *)addr, hdfu->wlength) != USBD_OK)
|
||||||
{
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
|
hdfu->dev_status[0] = DFU_ERROR_VENDOR;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -609,7 +774,7 @@ static uint8_t USBD_DFU_SOF(USBD_HandleTypeDef *pdev)
|
|||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
@@ -622,6 +787,7 @@ static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_DFU_DeviceQualifierDesc;
|
return USBD_DFU_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_DFU_GetUsrStringDesc
|
* @brief USBD_DFU_GetUsrStringDesc
|
||||||
@@ -635,7 +801,7 @@ static uint8_t *USBD_DFU_GetDeviceQualifierDesc(uint16_t *length)
|
|||||||
static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length)
|
static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length)
|
||||||
{
|
{
|
||||||
static uint8_t USBD_StrDesc[255];
|
static uint8_t USBD_StrDesc[255];
|
||||||
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData;
|
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
|
||||||
/* Check if the requested string interface is supported */
|
/* Check if the requested string interface is supported */
|
||||||
if (index <= (USBD_IDX_INTERFACE_STR + USBD_DFU_MAX_ITF_NUM))
|
if (index <= (USBD_IDX_INTERFACE_STR + USBD_DFU_MAX_ITF_NUM))
|
||||||
@@ -646,10 +812,11 @@ static uint8_t *USBD_DFU_GetUsrStringDesc(USBD_HandleTypeDef *pdev, uint8_t inde
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Not supported Interface Descriptor index */
|
/* Not supported Interface Descriptor index */
|
||||||
|
*length = 0U;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_RegisterStorage
|
* @brief USBD_MSC_RegisterStorage
|
||||||
@@ -665,7 +832,7 @@ uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -682,9 +849,10 @@ uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_DFUFuncDescTypeDef *pDfuFunc = (USBD_DFUFuncDescTypeDef *)USBD_DFU_GetDfuFuncDesc(pdev->pConfDesc);
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if ((hdfu == NULL) || (pDfuFunc == NULL))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -708,7 +876,7 @@ static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check the detach capability in the DFU functional descriptor */
|
/* Check the detach capability in the DFU functional descriptor */
|
||||||
if (((USBD_DFU_CfgDesc[12U + (9U * USBD_DFU_MAX_ITF_NUM)]) & DFU_DETACH_MASK) != 0U)
|
if ((pDfuFunc->bmAttributes & DFU_DETACH_MASK) != 0U)
|
||||||
{
|
{
|
||||||
/* Perform an Attach-Detach operation on USB bus */
|
/* Perform an Attach-Detach operation on USB bus */
|
||||||
(void)USBD_Stop(pdev);
|
(void)USBD_Stop(pdev);
|
||||||
@@ -730,7 +898,12 @@ static void DFU_Detach(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
*/
|
*/
|
||||||
static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
|
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
uint32_t VendorStatus = 0U;
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if (hdfu == NULL)
|
||||||
{
|
{
|
||||||
@@ -763,15 +936,30 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
/* 0 Data DNLOAD request */
|
/* 0 Data DNLOAD request */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* End of DNLOAD operation*/
|
/* End of DNLOAD operation */
|
||||||
if ((hdfu->dev_state == DFU_STATE_DNLOAD_IDLE) || (hdfu->dev_state == DFU_STATE_IDLE))
|
if ((hdfu->dev_state == DFU_STATE_DNLOAD_IDLE) || (hdfu->dev_state == DFU_STATE_IDLE))
|
||||||
{
|
{
|
||||||
hdfu->manif_state = DFU_MANIFEST_IN_PROGRESS;
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
|
if (DfuInterface->VendorCheck(hdfu->buffer.d8, IS_DFU_SETADDRESSPOINTER, &VendorStatus) != USBD_OK)
|
||||||
hdfu->dev_status[1] = 0U;
|
{
|
||||||
hdfu->dev_status[2] = 0U;
|
/* Update the state machine */
|
||||||
hdfu->dev_status[3] = 0U;
|
hdfu->dev_state = DFU_STATE_ERROR;
|
||||||
hdfu->dev_status[4] = hdfu->dev_state;
|
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
{
|
||||||
|
hdfu->manif_state = DFU_MANIFEST_IN_PROGRESS;
|
||||||
|
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -790,10 +978,17 @@ static void DFU_Download(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
*/
|
*/
|
||||||
static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData;
|
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
uint8_t *phaddr;
|
uint8_t *phaddr;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
|
uint32_t CmdLength;
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
uint32_t VendorStatus = 0U;
|
||||||
|
uint8_t VendorCmdLength = 0U;
|
||||||
|
uint8_t VendorCmdBuffer[DFU_VENDOR_CMD_MAX];
|
||||||
|
uint8_t idx;
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if (hdfu == NULL)
|
||||||
{
|
{
|
||||||
@@ -825,8 +1020,24 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
hdfu->buffer.d8[1] = DFU_CMD_SETADDRESSPOINTER;
|
hdfu->buffer.d8[1] = DFU_CMD_SETADDRESSPOINTER;
|
||||||
hdfu->buffer.d8[2] = DFU_CMD_ERASE;
|
hdfu->buffer.d8[2] = DFU_CMD_ERASE;
|
||||||
|
|
||||||
|
CmdLength = 3U;
|
||||||
|
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
if (DfuInterface->GetVendorCMD != NULL)
|
||||||
|
{
|
||||||
|
(void)DfuInterface->GetVendorCMD(VendorCmdBuffer, (uint8_t *)&VendorCmdLength);
|
||||||
|
|
||||||
|
for (idx = 0U; idx < MIN(VendorCmdLength, DFU_VENDOR_CMD_MAX); idx++)
|
||||||
|
{
|
||||||
|
hdfu->buffer.d8[idx + 3U] = VendorCmdBuffer[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
CmdLength += MIN(VendorCmdLength, DFU_VENDOR_CMD_MAX);
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
|
|
||||||
/* Send the status data over EP0 */
|
/* Send the status data over EP0 */
|
||||||
(void)USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->buffer.d8[0])), 3U);
|
(void)USBD_CtlSendData(pdev, (uint8_t *)(&(hdfu->buffer.d8[0])), CmdLength);
|
||||||
}
|
}
|
||||||
else if (hdfu->wblock_num > 1U)
|
else if (hdfu->wblock_num > 1U)
|
||||||
{
|
{
|
||||||
@@ -837,13 +1048,48 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
hdfu->dev_status[3] = 0U;
|
hdfu->dev_status[3] = 0U;
|
||||||
hdfu->dev_status[4] = hdfu->dev_state;
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
|
||||||
addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr;
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
/* Vendor specific DFU CMD */
|
||||||
|
if (DfuInterface->VendorUploadCMD(hdfu->data_ptr, hdfu->wblock_num, &VendorStatus) != USBD_OK)
|
||||||
|
{
|
||||||
|
/* Update the state machine */
|
||||||
|
hdfu->dev_state = DFU_ERROR_STALLEDPKT;
|
||||||
|
hdfu->dev_status[0] = (uint8_t)VendorStatus;
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
|
||||||
/* Return the physical address where data are stored */
|
/* Call the error management function (command will be NAKed) */
|
||||||
phaddr = DfuInterface->Read((uint8_t *)addr, hdfu->buffer.d8, hdfu->wlength);
|
USBD_CtlError(pdev, req);
|
||||||
|
}
|
||||||
|
|
||||||
/* Send the status data over EP0 */
|
if (VendorStatus == IS_DFU_PHY_ADDRESS)
|
||||||
(void)USBD_CtlSendData(pdev, phaddr, hdfu->wlength);
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
|
{
|
||||||
|
addr = ((hdfu->wblock_num - 2U) * USBD_DFU_XFER_SIZE) + hdfu->data_ptr;
|
||||||
|
|
||||||
|
/* Return the physical address where data are stored */
|
||||||
|
phaddr = DfuInterface->Read((uint8_t *)addr, hdfu->buffer.d8, hdfu->wlength);
|
||||||
|
|
||||||
|
if (phaddr == NULL)
|
||||||
|
{
|
||||||
|
hdfu->dev_state = DFU_ERROR_STALLEDPKT;
|
||||||
|
|
||||||
|
hdfu->dev_status[1] = 0U;
|
||||||
|
hdfu->dev_status[2] = 0U;
|
||||||
|
hdfu->dev_status[3] = 0U;
|
||||||
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
|
||||||
|
/* Call the error management function (command will be NAKed) */
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Send the status data over EP0 */
|
||||||
|
(void)USBD_CtlSendData(pdev, phaddr, hdfu->wlength);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else /* unsupported hdfu->wblock_num */
|
else /* unsupported hdfu->wblock_num */
|
||||||
{
|
{
|
||||||
@@ -854,7 +1100,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
hdfu->dev_status[3] = 0U;
|
hdfu->dev_status[3] = 0U;
|
||||||
hdfu->dev_status[4] = hdfu->dev_state;
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
|
|
||||||
/* Call the error management function (command will be NAKed */
|
/* Call the error management function (command will be NAKed) */
|
||||||
USBD_CtlError(pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -864,7 +1110,7 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
hdfu->wlength = 0U;
|
hdfu->wlength = 0U;
|
||||||
hdfu->wblock_num = 0U;
|
hdfu->wblock_num = 0U;
|
||||||
|
|
||||||
/* Call the error management function (command will be NAKed */
|
/* Call the error management function (command will be NAKed) */
|
||||||
USBD_CtlError(pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -888,10 +1134,11 @@ static void DFU_Upload(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
*/
|
*/
|
||||||
static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData;
|
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
USBD_DFUFuncDescTypeDef *pDfuFunc = (USBD_DFUFuncDescTypeDef *)USBD_DFU_GetDfuFuncDesc(pdev->pConfDesc);
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if ((hdfu == NULL) || (DfuInterface == NULL) || (pDfuFunc == NULL))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -917,7 +1164,7 @@ static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
|||||||
DfuInterface->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status);
|
DfuInterface->GetStatus(hdfu->data_ptr, DFU_MEDIA_PROGRAM, hdfu->dev_status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* (hdfu->wlength==0)*/
|
else /* (hdfu->wlength == 0U) */
|
||||||
{
|
{
|
||||||
hdfu->dev_state = DFU_STATE_DNLOAD_IDLE;
|
hdfu->dev_state = DFU_STATE_DNLOAD_IDLE;
|
||||||
|
|
||||||
@@ -933,7 +1180,7 @@ static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
|||||||
{
|
{
|
||||||
hdfu->dev_state = DFU_STATE_MANIFEST;
|
hdfu->dev_state = DFU_STATE_MANIFEST;
|
||||||
|
|
||||||
hdfu->dev_status[1] = 1U; /*bwPollTimeout = 1ms*/
|
hdfu->dev_status[1] = 1U; /* bwPollTimeout = 1ms */
|
||||||
hdfu->dev_status[2] = 0U;
|
hdfu->dev_status[2] = 0U;
|
||||||
hdfu->dev_status[3] = 0U;
|
hdfu->dev_status[3] = 0U;
|
||||||
hdfu->dev_status[4] = hdfu->dev_state;
|
hdfu->dev_status[4] = hdfu->dev_state;
|
||||||
@@ -941,7 +1188,7 @@ static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) &&
|
if ((hdfu->manif_state == DFU_MANIFEST_COMPLETE) &&
|
||||||
(((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U) != 0U))
|
((pDfuFunc->bmAttributes & DFU_MANIFEST_MASK) != 0U))
|
||||||
{
|
{
|
||||||
hdfu->dev_state = DFU_STATE_IDLE;
|
hdfu->dev_state = DFU_STATE_IDLE;
|
||||||
|
|
||||||
@@ -969,7 +1216,7 @@ static void DFU_GetStatus(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static void DFU_ClearStatus(USBD_HandleTypeDef *pdev)
|
static void DFU_ClearStatus(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if (hdfu == NULL)
|
||||||
{
|
{
|
||||||
@@ -1007,7 +1254,7 @@ static void DFU_ClearStatus(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static void DFU_GetState(USBD_HandleTypeDef *pdev)
|
static void DFU_GetState(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if (hdfu == NULL)
|
||||||
{
|
{
|
||||||
@@ -1026,7 +1273,7 @@ static void DFU_GetState(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static void DFU_Abort(USBD_HandleTypeDef *pdev)
|
static void DFU_Abort(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if (hdfu == NULL)
|
||||||
{
|
{
|
||||||
@@ -1060,16 +1307,18 @@ static void DFU_Abort(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassData;
|
USBD_DFU_HandleTypeDef *hdfu = (USBD_DFU_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_DFU_MediaTypeDef *DfuInterface = (USBD_DFU_MediaTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
USBD_DFUFuncDescTypeDef *pDfuFunc = (USBD_DFUFuncDescTypeDef *)USBD_DFU_GetDfuFuncDesc(pdev->pConfDesc);
|
||||||
|
|
||||||
if (hdfu == NULL)
|
if ((hdfu == NULL) || (DfuInterface == NULL) || (pDfuFunc == NULL))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdfu->manif_state = DFU_MANIFEST_COMPLETE;
|
hdfu->manif_state = DFU_MANIFEST_COMPLETE;
|
||||||
|
|
||||||
if (((USBD_DFU_CfgDesc[(11U + (9U * USBD_DFU_MAX_ITF_NUM))]) & 0x04U) != 0U)
|
if ((pDfuFunc->bmAttributes & DFU_MANIFEST_MASK) != 0U)
|
||||||
{
|
{
|
||||||
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
|
hdfu->dev_state = DFU_STATE_MANIFEST_SYNC;
|
||||||
|
|
||||||
@@ -1091,13 +1340,50 @@ static void DFU_Leave(USBD_HandleTypeDef *pdev)
|
|||||||
/* Disconnect the USB device */
|
/* Disconnect the USB device */
|
||||||
(void)USBD_Stop(pdev);
|
(void)USBD_Stop(pdev);
|
||||||
|
|
||||||
|
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||||
|
/* Jump should be ensured by user application */
|
||||||
|
DfuInterface->LeaveDFU(hdfu->data_ptr);
|
||||||
|
#else
|
||||||
/* Generate system reset to allow jumping to the user code */
|
/* Generate system reset to allow jumping to the user code */
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
|
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||||
|
|
||||||
/* The next instructions will not be reached (system reset) */
|
/* The next instructions will not be reached (system reset) */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USBD_DFU_GetDfuFuncDesc
|
||||||
|
* This function return the DFU descriptor
|
||||||
|
* @param pdev: device instance
|
||||||
|
* @param pConfDesc: pointer to Bos descriptor
|
||||||
|
* @retval pointer to the DFU descriptor
|
||||||
|
*/
|
||||||
|
static void *USBD_DFU_GetDfuFuncDesc(uint8_t *pConfDesc)
|
||||||
|
{
|
||||||
|
USBD_ConfigDescTypeDef *desc = (USBD_ConfigDescTypeDef *)(void *)pConfDesc;
|
||||||
|
USBD_DescHeaderTypeDef *pdesc = (USBD_DescHeaderTypeDef *)(void *)pConfDesc;
|
||||||
|
uint8_t *pDfuDesc = 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 == DFU_DESCRIPTOR_TYPE)
|
||||||
|
{
|
||||||
|
pDfuDesc = (uint8_t *)pdesc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pDfuDesc;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -38,6 +38,17 @@ uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len);
|
|||||||
uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len);
|
uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||||
uint16_t MEM_If_DeInit(void);
|
uint16_t MEM_If_DeInit(void);
|
||||||
uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer);
|
uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer);
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
uint16_t MEM_If_GetVendorCMD(uint8_t *cmd, uint8_t *cmdlength);
|
||||||
|
uint16_t MEM_If_VendorDownloadCMD(uint8_t *pbuf, uint32_t BlockNumber, uint32_t wlength, uint32_t *status);
|
||||||
|
uint16_t MEM_If_VendorUploadCMD(uint32_t Add, uint32_t BlockNumber, uint32_t *status);
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
|
uint16_t MEM_If_VendorCheck(uint8_t *pbuf, uint32_t ReqType, uint32_t *status);
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||||
|
uint16_t MEM_If_LeaveDFU(uint32_t Add);
|
||||||
|
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||||
|
|
||||||
USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
|
USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
|
||||||
{
|
{
|
||||||
@@ -48,8 +59,19 @@ USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
|
|||||||
MEM_If_Write,
|
MEM_If_Write,
|
||||||
MEM_If_Read,
|
MEM_If_Read,
|
||||||
MEM_If_GetStatus,
|
MEM_If_GetStatus,
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
MEM_If_GetVendorCMD,
|
||||||
|
MEM_If_VendorDownloadCMD,
|
||||||
|
MEM_If_VendorUploadCMD,
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
|
MEM_If_VendorCheck,
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||||
|
MEM_If_LeaveDFU
|
||||||
|
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MEM_If_Init
|
* @brief MEM_If_Init
|
||||||
* Memory initialization routine.
|
* Memory initialization routine.
|
||||||
@@ -80,6 +102,8 @@ uint16_t MEM_If_DeInit(void)
|
|||||||
*/
|
*/
|
||||||
uint16_t MEM_If_Erase(uint32_t Add)
|
uint16_t MEM_If_Erase(uint32_t Add)
|
||||||
{
|
{
|
||||||
|
UNUSED(Add);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +116,10 @@ uint16_t MEM_If_Erase(uint32_t Add)
|
|||||||
*/
|
*/
|
||||||
uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len)
|
uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len)
|
||||||
{
|
{
|
||||||
|
UNUSED(src);
|
||||||
|
UNUSED(dest);
|
||||||
|
UNUSED(Len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,8 +132,12 @@ uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len)
|
|||||||
*/
|
*/
|
||||||
uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len)
|
uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len)
|
||||||
{
|
{
|
||||||
|
UNUSED(src);
|
||||||
|
UNUSED(dest);
|
||||||
|
UNUSED(Len);
|
||||||
|
|
||||||
/* Return a valid address to avoid HardFault */
|
/* Return a valid address to avoid HardFault */
|
||||||
return (uint8_t *)(0);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,6 +149,9 @@ uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len)
|
|||||||
*/
|
*/
|
||||||
uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer)
|
uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer)
|
||||||
{
|
{
|
||||||
|
UNUSED(Add);
|
||||||
|
UNUSED(buffer);
|
||||||
|
|
||||||
switch (Cmd)
|
switch (Cmd)
|
||||||
{
|
{
|
||||||
case DFU_MEDIA_PROGRAM:
|
case DFU_MEDIA_PROGRAM:
|
||||||
@@ -131,3 +166,85 @@ uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (USBD_DFU_VENDOR_CMD_ENABLED == 1U)
|
||||||
|
/**
|
||||||
|
* @brief Get supported vendor specific commands
|
||||||
|
* @param pointer to supported vendor commands
|
||||||
|
* @param pointer to length of supported vendor commands
|
||||||
|
* @retval 0 if operation is successful
|
||||||
|
*/
|
||||||
|
uint16_t MEM_If_GetVendorCMD(uint8_t *cmd, uint8_t *cmdlength)
|
||||||
|
{
|
||||||
|
UNUSED(cmd);
|
||||||
|
UNUSED(cmdlength);
|
||||||
|
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Vendor specific download commands
|
||||||
|
* @param pbuf DFU data buffer
|
||||||
|
* @param BlockNumber DFU memory block number
|
||||||
|
* @param wLength DFU request length
|
||||||
|
* @param pointer to DFU status
|
||||||
|
* @retval 0 if operation is successful
|
||||||
|
*/
|
||||||
|
uint16_t MEM_If_VendorDownloadCMD(uint8_t *pbuf, uint32_t BlockNumber, uint32_t wlength, uint32_t *status)
|
||||||
|
{
|
||||||
|
UNUSED(pbuf);
|
||||||
|
UNUSED(BlockNumber);
|
||||||
|
UNUSED(wlength);
|
||||||
|
UNUSED(status);
|
||||||
|
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Vendor specific upload commands
|
||||||
|
* @param Add memory Address
|
||||||
|
* @param BlockNumber DFU memory block number
|
||||||
|
* @param pointer to DFU status
|
||||||
|
* @retval 0 if operation is successful
|
||||||
|
*/
|
||||||
|
uint16_t MEM_If_VendorUploadCMD(uint32_t Add, uint32_t BlockNumber, uint32_t *status)
|
||||||
|
{
|
||||||
|
UNUSED(Add);
|
||||||
|
UNUSED(BlockNumber);
|
||||||
|
UNUSED(status);
|
||||||
|
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_CMD_ENABLED */
|
||||||
|
|
||||||
|
#if (USBD_DFU_VENDOR_CHECK_ENABLED == 1U)
|
||||||
|
/**
|
||||||
|
* @brief Vendor memory check
|
||||||
|
* @param pbuf DFU data buffer
|
||||||
|
* @param ReqType IS_DFU_SETADDRESSPOINTER/DOWNLOAD/UPLOAD
|
||||||
|
* @param pointer to DFU status
|
||||||
|
* @retval 0 if operation is successful
|
||||||
|
*/
|
||||||
|
uint16_t MEM_If_VendorCheck(uint8_t *pbuf, uint32_t ReqType, uint32_t *status)
|
||||||
|
{
|
||||||
|
UNUSED(pbuf);
|
||||||
|
UNUSED(ReqType);
|
||||||
|
UNUSED(status);
|
||||||
|
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_CHECK_ENABLED */
|
||||||
|
|
||||||
|
#if (USBD_DFU_VENDOR_EXIT_ENABLED == 1U)
|
||||||
|
/**
|
||||||
|
* @brief Vendor Leave DFU
|
||||||
|
* @param Application address
|
||||||
|
* @retval 0 if operation is successful
|
||||||
|
*/
|
||||||
|
uint16_t MEM_If_LeaveDFU(uint32_t Add)
|
||||||
|
{
|
||||||
|
UNUSED(Add);
|
||||||
|
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
#endif /* USBD_DFU_VENDOR_EXIT_ENABLED */
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ extern "C" {
|
|||||||
/** @defgroup USBD_HID_Exported_Defines
|
/** @defgroup USBD_HID_Exported_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#ifndef HID_EPIN_ADDR
|
||||||
#define HID_EPIN_ADDR 0x81U
|
#define HID_EPIN_ADDR 0x81U
|
||||||
|
#endif /* HID_EPIN_ADDR */
|
||||||
#define HID_EPIN_SIZE 0x04U
|
#define HID_EPIN_SIZE 0x04U
|
||||||
|
|
||||||
#define USB_HID_CONFIG_DESC_SIZ 34U
|
#define USB_HID_CONFIG_DESC_SIZ 34U
|
||||||
@@ -58,14 +60,14 @@ extern "C" {
|
|||||||
#define HID_FS_BINTERVAL 0x0AU
|
#define HID_FS_BINTERVAL 0x0AU
|
||||||
#endif /* HID_FS_BINTERVAL */
|
#endif /* HID_FS_BINTERVAL */
|
||||||
|
|
||||||
#define HID_REQ_SET_PROTOCOL 0x0BU
|
#define USBD_HID_REQ_SET_PROTOCOL 0x0BU
|
||||||
#define HID_REQ_GET_PROTOCOL 0x03U
|
#define USBD_HID_REQ_GET_PROTOCOL 0x03U
|
||||||
|
|
||||||
#define HID_REQ_SET_IDLE 0x0AU
|
#define USBD_HID_REQ_SET_IDLE 0x0AU
|
||||||
#define HID_REQ_GET_IDLE 0x02U
|
#define USBD_HID_REQ_GET_IDLE 0x02U
|
||||||
|
|
||||||
#define HID_REQ_SET_REPORT 0x09U
|
#define USBD_HID_REQ_SET_REPORT 0x09U
|
||||||
#define HID_REQ_GET_REPORT 0x01U
|
#define USBD_HID_REQ_GET_REPORT 0x01U
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -76,9 +78,9 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
HID_IDLE = 0,
|
USBD_HID_IDLE = 0,
|
||||||
HID_BUSY,
|
USBD_HID_BUSY,
|
||||||
} HID_StateTypeDef;
|
} USBD_HID_StateTypeDef;
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -86,8 +88,25 @@ typedef struct
|
|||||||
uint32_t Protocol;
|
uint32_t Protocol;
|
||||||
uint32_t IdleState;
|
uint32_t IdleState;
|
||||||
uint32_t AltSetting;
|
uint32_t AltSetting;
|
||||||
HID_StateTypeDef state;
|
USBD_HID_StateTypeDef state;
|
||||||
} USBD_HID_HandleTypeDef;
|
} USBD_HID_HandleTypeDef;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* HID Class specification version 1.1
|
||||||
|
* 6.2.1 HID Descriptor
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint16_t bcdHID;
|
||||||
|
uint8_t bCountryCode;
|
||||||
|
uint8_t bNumDescriptors;
|
||||||
|
uint8_t bHIDDescriptorType;
|
||||||
|
uint16_t wItemLength;
|
||||||
|
} __PACKED USBD_HIDDescTypeDef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -115,7 +134,11 @@ extern USBD_ClassTypeDef USBD_HID;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len, uint8_t ClassId);
|
||||||
|
#else
|
||||||
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len);
|
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev);
|
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -91,12 +91,12 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
|||||||
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length);
|
static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -117,14 +117,22 @@ USBD_ClassTypeDef USBD_HID =
|
|||||||
NULL, /* SOF */
|
NULL, /* SOF */
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_HID_GetHSCfgDesc,
|
USBD_HID_GetHSCfgDesc,
|
||||||
USBD_HID_GetFSCfgDesc,
|
USBD_HID_GetFSCfgDesc,
|
||||||
USBD_HID_GetOtherSpeedCfgDesc,
|
USBD_HID_GetOtherSpeedCfgDesc,
|
||||||
USBD_HID_GetDeviceQualifierDesc,
|
USBD_HID_GetDeviceQualifierDesc,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB HID device FS Configuration Descriptor */
|
/* USB HID device FS Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
@@ -132,12 +140,13 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN
|
|||||||
0x00,
|
0x00,
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
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)
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xE0, /* bmAttributes: Bus Powered according to user configuration */
|
0xE0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0xA0, /* bmAttributes: Bus Powered according to user configuration */
|
0xA0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
/************** Descriptor of Joystick Mouse interface ****************/
|
||||||
@@ -174,111 +183,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN
|
|||||||
HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/* USB HID device HS Configuration Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_HID_CfgHSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
|
||||||
{
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
|
||||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
|
||||||
#if (USBD_SELF_POWERED == 1U)
|
|
||||||
0xE0, /* bmAttributes: Bus Powered according to user configuration */
|
|
||||||
#else
|
|
||||||
0xA0, /* bmAttributes: Bus Powered according to user configuration */
|
|
||||||
#endif
|
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
|
||||||
|
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
|
|
||||||
0x11, /* bcdHID: HID Class Spec release number */
|
|
||||||
0x01,
|
|
||||||
0x00, /* bCountryCode: Hardware target country */
|
|
||||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
|
||||||
0x22, /* bDescriptorType */
|
|
||||||
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
|
|
||||||
HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_EPIN_SIZE, /* wMaxPacketSize: 4 Bytes max */
|
|
||||||
0x00,
|
|
||||||
HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* USB HID device Other Speed Configuration Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_HID_OtherSpeedCfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
|
||||||
{
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
|
||||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
|
||||||
#if (USBD_SELF_POWERED == 1U)
|
|
||||||
0xE0, /* bmAttributes: Bus Powered according to user configuration */
|
|
||||||
#else
|
|
||||||
0xA0, /* bmAttributes: Bus Powered according to user configuration */
|
|
||||||
#endif
|
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
|
||||||
|
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
|
||||||
/* 09 */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x01, /* bNumEndpoints */
|
|
||||||
0x03, /* bInterfaceClass: HID */
|
|
||||||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
|
||||||
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
|
||||||
0, /* iInterface: Index of string descriptor */
|
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
|
||||||
/* 18 */
|
|
||||||
0x09, /* bLength: HID Descriptor size */
|
|
||||||
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
|
|
||||||
0x11, /* bcdHID: HID Class Spec release number */
|
|
||||||
0x01,
|
|
||||||
0x00, /* bCountryCode: Hardware target country */
|
|
||||||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
|
||||||
0x22, /* bDescriptorType */
|
|
||||||
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
|
||||||
0x00,
|
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
|
||||||
/* 27 */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
|
||||||
|
|
||||||
HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
|
||||||
HID_EPIN_SIZE, /* wMaxPacketSize: 4 Bytes max */
|
|
||||||
0x00,
|
|
||||||
HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
|
||||||
/* 34 */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* USB HID device Configuration Descriptor */
|
/* USB HID device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END =
|
||||||
@@ -295,6 +200,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END =
|
|||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -309,6 +215,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -352,6 +259,8 @@ __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __
|
|||||||
0xC0 /* End Collection */
|
0xC0 /* End Collection */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static uint8_t HIDInEpAdd = HID_EPIN_ADDR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -377,26 +286,32 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
if (hhid == NULL)
|
if (hhid == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pClassData = (void *)hhid;
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hhid;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].bInterval = HID_HS_BINTERVAL;
|
pdev->ep_in[HIDInEpAdd & 0xFU].bInterval = HID_HS_BINTERVAL;
|
||||||
}
|
}
|
||||||
else /* LOW and FULL-speed endpoints */
|
else /* LOW and FULL-speed endpoints */
|
||||||
{
|
{
|
||||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].bInterval = HID_FS_BINTERVAL;
|
pdev->ep_in[HIDInEpAdd & 0xFU].bInterval = HID_FS_BINTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, HID_EPIN_ADDR, USBD_EP_TYPE_INTR, HID_EPIN_SIZE);
|
(void)USBD_LL_OpenEP(pdev, HIDInEpAdd, USBD_EP_TYPE_INTR, HID_EPIN_SIZE);
|
||||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
pdev->ep_in[HIDInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
hhid->state = HID_IDLE;
|
hhid->state = USBD_HID_IDLE;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -412,16 +327,21 @@ static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close HID EPs */
|
/* Close HID EPs */
|
||||||
(void)USBD_LL_CloseEP(pdev, HID_EPIN_ADDR);
|
(void)USBD_LL_CloseEP(pdev, HIDInEpAdd);
|
||||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
pdev->ep_in[HIDInEpAdd & 0xFU].is_used = 0U;
|
||||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].bInterval = 0U;
|
pdev->ep_in[HIDInEpAdd & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* Free allocated memory */
|
/* Free allocated memory */
|
||||||
if (pdev->pClassData != NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
{
|
{
|
||||||
(void)USBD_free(pdev->pClassData);
|
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
@@ -436,7 +356,7 @@ static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassData;
|
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint8_t *pbuf;
|
uint8_t *pbuf;
|
||||||
@@ -452,19 +372,19 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re
|
|||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS :
|
||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
case HID_REQ_SET_PROTOCOL:
|
case USBD_HID_REQ_SET_PROTOCOL:
|
||||||
hhid->Protocol = (uint8_t)(req->wValue);
|
hhid->Protocol = (uint8_t)(req->wValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HID_REQ_GET_PROTOCOL:
|
case USBD_HID_REQ_GET_PROTOCOL:
|
||||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U);
|
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HID_REQ_SET_IDLE:
|
case USBD_HID_REQ_SET_IDLE:
|
||||||
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HID_REQ_GET_IDLE:
|
case USBD_HID_REQ_GET_IDLE:
|
||||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U);
|
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -552,28 +472,41 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re
|
|||||||
return (uint8_t)ret;
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_HID_SendReport
|
* @brief USBD_HID_SendReport
|
||||||
* Send HID Report
|
* Send HID Report
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param buff: pointer to report
|
* @param buff: pointer to report
|
||||||
|
* @param ClassId: The Class ID
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len, uint8_t ClassId)
|
||||||
|
{
|
||||||
|
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||||
|
#else
|
||||||
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len)
|
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len)
|
||||||
{
|
{
|
||||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassData;
|
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hhid == NULL)
|
if (hhid == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
HIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, ClassId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
if (hhid->state == HID_IDLE)
|
if (hhid->state == USBD_HID_IDLE)
|
||||||
{
|
{
|
||||||
hhid->state = HID_BUSY;
|
hhid->state = USBD_HID_BUSY;
|
||||||
(void)USBD_LL_Transmit(pdev, HID_EPIN_ADDR, report, len);
|
(void)USBD_LL_Transmit(pdev, HIDInEpAdd, report, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,6 +541,7 @@ uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev)
|
|||||||
return ((uint32_t)(polling_interval));
|
return ((uint32_t)(polling_interval));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_HID_GetCfgFSDesc
|
* @brief USBD_HID_GetCfgFSDesc
|
||||||
* return FS configuration descriptor
|
* return FS configuration descriptor
|
||||||
@@ -617,9 +551,15 @@ uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_HID_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpDesc = USBD_GetEpDesc(USBD_HID_CfgDesc, HID_EPIN_ADDR);
|
||||||
|
|
||||||
return USBD_HID_CfgFSDesc;
|
if (pEpDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpDesc->bInterval = HID_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_HID_CfgDesc);
|
||||||
|
return USBD_HID_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -631,9 +571,15 @@ static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_HID_CfgHSDesc);
|
USBD_EpDescTypeDef *pEpDesc = USBD_GetEpDesc(USBD_HID_CfgDesc, HID_EPIN_ADDR);
|
||||||
|
|
||||||
return USBD_HID_CfgHSDesc;
|
if (pEpDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpDesc->bInterval = HID_HS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_HID_CfgDesc);
|
||||||
|
return USBD_HID_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -645,10 +591,17 @@ static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_HID_OtherSpeedCfgDesc);
|
USBD_EpDescTypeDef *pEpDesc = USBD_GetEpDesc(USBD_HID_CfgDesc, HID_EPIN_ADDR);
|
||||||
|
|
||||||
return USBD_HID_OtherSpeedCfgDesc;
|
if (pEpDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpDesc->bInterval = HID_FS_BINTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_HID_CfgDesc);
|
||||||
|
return USBD_HID_CfgDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_HID_DataIn
|
* @brief USBD_HID_DataIn
|
||||||
@@ -662,12 +615,12 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
UNUSED(epnum);
|
UNUSED(epnum);
|
||||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||||
be caused by a new transfer before the end of the previous transfer */
|
be caused by a new transfer before the end of the previous transfer */
|
||||||
((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE;
|
((USBD_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = USBD_HID_IDLE;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
@@ -680,7 +633,7 @@ static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_HID_DeviceQualifierDesc;
|
return USBD_HID_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -54,9 +54,17 @@ extern "C" {
|
|||||||
#define BOT_RESET 0xFF
|
#define BOT_RESET 0xFF
|
||||||
#define USB_MSC_CONFIG_DESC_SIZ 32
|
#define USB_MSC_CONFIG_DESC_SIZ 32
|
||||||
|
|
||||||
|
#ifndef MSC_EPIN_ADDR
|
||||||
#define MSC_EPIN_ADDR 0x81U
|
#define MSC_EPIN_ADDR 0x81U
|
||||||
|
#endif /* MSC_EPIN_ADDR */
|
||||||
|
|
||||||
|
#ifndef MSC_EPOUT_ADDR
|
||||||
#define MSC_EPOUT_ADDR 0x01U
|
#define MSC_EPOUT_ADDR 0x01U
|
||||||
|
#endif /* MSC_EPOUT_ADDR */
|
||||||
|
|
||||||
|
#ifndef MSC_BOT_MAX_LUN
|
||||||
|
#define MSC_BOT_MAX_LUN 0x2U
|
||||||
|
#endif /* MSC_BOT_MAX_LUN */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -78,6 +86,13 @@ typedef struct _USBD_STORAGE
|
|||||||
|
|
||||||
} USBD_StorageTypeDef;
|
} USBD_StorageTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint16_t size;
|
||||||
|
uint32_t nbr;
|
||||||
|
uint32_t addr;
|
||||||
|
uint32_t len;
|
||||||
|
} USBD_MSC_BOT_LUN_TypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -95,13 +110,8 @@ typedef struct
|
|||||||
uint8_t scsi_sense_tail;
|
uint8_t scsi_sense_tail;
|
||||||
uint8_t scsi_medium_state;
|
uint8_t scsi_medium_state;
|
||||||
|
|
||||||
uint16_t scsi_blk_size;
|
USBD_MSC_BOT_LUN_TypeDef scsi_blk[MSC_BOT_MAX_LUN];
|
||||||
uint32_t scsi_blk_nbr;
|
} USBD_MSC_BOT_HandleTypeDef;
|
||||||
|
|
||||||
uint32_t scsi_blk_addr;
|
|
||||||
uint32_t scsi_blk_len;
|
|
||||||
}
|
|
||||||
USBD_MSC_BOT_HandleTypeDef;
|
|
||||||
|
|
||||||
/* Structure for MSC process */
|
/* Structure for MSC process */
|
||||||
extern USBD_ClassTypeDef USBD_MSC;
|
extern USBD_ClassTypeDef USBD_MSC;
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ typedef struct
|
|||||||
uint8_t bCBLength;
|
uint8_t bCBLength;
|
||||||
uint8_t CB[16];
|
uint8_t CB[16];
|
||||||
uint8_t ReservedForAlign;
|
uint8_t ReservedForAlign;
|
||||||
}
|
} USBD_MSC_BOT_CBWTypeDef;
|
||||||
USBD_MSC_BOT_CBWTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -97,8 +96,7 @@ typedef struct
|
|||||||
uint32_t dDataResidue;
|
uint32_t dDataResidue;
|
||||||
uint8_t bStatus;
|
uint8_t bStatus;
|
||||||
uint8_t ReservedForAlign[3];
|
uint8_t ReservedForAlign[3];
|
||||||
}
|
} USBD_MSC_BOT_CSWTypeDef;
|
||||||
USBD_MSC_BOT_CSWTypeDef;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -39,11 +39,13 @@ extern "C" {
|
|||||||
/** @defgroup USB_INFO_Exported_Defines
|
/** @defgroup USB_INFO_Exported_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define MODE_SENSE6_LEN 0x17U
|
#define MODE_SENSE6_LEN 0x04U
|
||||||
#define MODE_SENSE10_LEN 0x1BU
|
#define MODE_SENSE10_LEN 0x08U
|
||||||
#define LENGTH_INQUIRY_PAGE00 0x06U
|
#define LENGTH_INQUIRY_PAGE00 0x06U
|
||||||
#define LENGTH_INQUIRY_PAGE80 0x08U
|
#define LENGTH_INQUIRY_PAGE80 0x08U
|
||||||
#define LENGTH_FORMAT_CAPACITIES 0x14U
|
#define LENGTH_FORMAT_CAPACITIES 0x14U
|
||||||
|
#define DIAGNOSTIC_DATA_LEN 0x08U
|
||||||
|
#define LOG_PAGE_DATA_LEN 0x10U
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -74,6 +76,8 @@ extern uint8_t MSC_Page00_Inquiry_Data[LENGTH_INQUIRY_PAGE00];
|
|||||||
extern uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80];
|
extern uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80];
|
||||||
extern uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN];
|
extern uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN];
|
||||||
extern uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN];
|
extern uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN];
|
||||||
|
extern uint8_t MSC_Diagnostic_Data[DIAGNOSTIC_DATA_LEN];
|
||||||
|
extern uint8_t MSC_Log_Page_Data[LOG_PAGE_DATA_LEN];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -70,8 +70,10 @@ extern "C" {
|
|||||||
#define SCSI_VERIFY12 0xAFU
|
#define SCSI_VERIFY12 0xAFU
|
||||||
#define SCSI_VERIFY16 0x8FU
|
#define SCSI_VERIFY16 0x8FU
|
||||||
|
|
||||||
#define SCSI_SEND_DIAGNOSTIC 0x1DU
|
|
||||||
#define SCSI_READ_FORMAT_CAPACITIES 0x23U
|
#define SCSI_READ_FORMAT_CAPACITIES 0x23U
|
||||||
|
#define SCSI_RECEIVE_DIAGNOSTIC_RESULTS 0x1CU
|
||||||
|
#define SCSI_SEND_DIAGNOSTIC 0x1DU
|
||||||
|
#define SCSI_REPORT_LUNS 0xA0U
|
||||||
|
|
||||||
#define NO_SENSE 0U
|
#define NO_SENSE 0U
|
||||||
#define RECOVERED_ERROR 1U
|
#define RECOVERED_ERROR 1U
|
||||||
@@ -82,15 +84,14 @@ extern "C" {
|
|||||||
#define UNIT_ATTENTION 6U
|
#define UNIT_ATTENTION 6U
|
||||||
#define DATA_PROTECT 7U
|
#define DATA_PROTECT 7U
|
||||||
#define BLANK_CHECK 8U
|
#define BLANK_CHECK 8U
|
||||||
#define VENDOR_SPECIFIC 9U
|
#define MSC_VENDOR_SPECIFIC 9U
|
||||||
#define COPY_ABORTED 10U
|
#define COPY_ABORTED 10U
|
||||||
#define ABORTED_COMMAND 11U
|
#define ABORTED_COMMAND 11U
|
||||||
#define VOLUME_OVERFLOW 13U
|
#define VOLUME_OVERFLOW 13U
|
||||||
#define MISCOMPARE 14U
|
#define MISCOMPARE 14U
|
||||||
|
|
||||||
|
|
||||||
#define INVALID_CDB 0x20U
|
#define INVALID_CDB 0x20U
|
||||||
#define INVALID_FIELED_IN_COMMAND 0x24U
|
#define INVALID_FIELD_IN_COMMAND 0x24U
|
||||||
#define PARAMETER_LIST_LENGTH_ERROR 0x1AU
|
#define PARAMETER_LIST_LENGTH_ERROR 0x1AU
|
||||||
#define INVALID_FIELD_IN_PARAMETER_LIST 0x26U
|
#define INVALID_FIELD_IN_PARAMETER_LIST 0x26U
|
||||||
#define ADDRESS_OUT_OF_RANGE 0x21U
|
#define ADDRESS_OUT_OF_RANGE 0x21U
|
||||||
|
|||||||
@@ -86,11 +86,12 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
|||||||
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length);
|
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length);
|
||||||
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length);
|
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length);
|
||||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length);
|
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length);
|
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -113,62 +114,24 @@ USBD_ClassTypeDef USBD_MSC =
|
|||||||
NULL, /*SOF */
|
NULL, /*SOF */
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_MSC_GetHSCfgDesc,
|
USBD_MSC_GetHSCfgDesc,
|
||||||
USBD_MSC_GetFSCfgDesc,
|
USBD_MSC_GetFSCfgDesc,
|
||||||
USBD_MSC_GetOtherSpeedCfgDesc,
|
USBD_MSC_GetOtherSpeedCfgDesc,
|
||||||
USBD_MSC_GetDeviceQualifierDescriptor,
|
USBD_MSC_GetDeviceQualifierDescriptor,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* USB Mass storage device Configuration Descriptor */
|
/* USB Mass storage device Configuration Descriptor */
|
||||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
#ifndef USE_USBD_COMPOSITE
|
||||||
__ALIGN_BEGIN static uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|
||||||
{
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
USB_MSC_CONFIG_DESC_SIZ,
|
|
||||||
|
|
||||||
0x00,
|
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
|
||||||
0x01, /* bConfigurationValue */
|
|
||||||
0x04, /* iConfiguration */
|
|
||||||
#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) */
|
|
||||||
|
|
||||||
/******************** Mass Storage interface ********************/
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
0x04, /* bDescriptorType: */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints */
|
|
||||||
0x08, /* bInterfaceClass: MSC Class */
|
|
||||||
0x06, /* bInterfaceSubClass : SCSI transparent */
|
|
||||||
0x50, /* nInterfaceProtocol */
|
|
||||||
0x05, /* iInterface */
|
|
||||||
/******************** Mass Storage Endpoints ********************/
|
|
||||||
0x07, /* Endpoint descriptor length = 7 */
|
|
||||||
0x05, /* Endpoint descriptor type */
|
|
||||||
MSC_EPIN_ADDR, /* Endpoint address (IN, address 1) */
|
|
||||||
0x02, /* Bulk endpoint type */
|
|
||||||
LOBYTE(MSC_MAX_HS_PACKET),
|
|
||||||
HIBYTE(MSC_MAX_HS_PACKET),
|
|
||||||
0x00, /* Polling interval in milliseconds */
|
|
||||||
|
|
||||||
0x07, /* Endpoint descriptor length = 7 */
|
|
||||||
0x05, /* Endpoint descriptor type */
|
|
||||||
MSC_EPOUT_ADDR, /* Endpoint address (OUT, address 1) */
|
|
||||||
0x02, /* Bulk endpoint type */
|
|
||||||
LOBYTE(MSC_MAX_HS_PACKET),
|
|
||||||
HIBYTE(MSC_MAX_HS_PACKET),
|
|
||||||
0x00 /* Polling interval in milliseconds */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* USB Mass storage device Configuration Descriptor */
|
/* USB Mass storage device Configuration Descriptor */
|
||||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
@@ -182,7 +145,7 @@ __ALIGN_BEGIN static uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIG
|
|||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
/******************** Mass Storage interface ********************/
|
/******************** Mass Storage interface ********************/
|
||||||
@@ -213,51 +176,6 @@ __ALIGN_BEGIN static uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIG
|
|||||||
0x00 /* Polling interval in milliseconds */
|
0x00 /* Polling interval in milliseconds */
|
||||||
};
|
};
|
||||||
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|
||||||
{
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
|
||||||
USB_MSC_CONFIG_DESC_SIZ,
|
|
||||||
|
|
||||||
0x00,
|
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
|
||||||
0x01, /* bConfigurationValue */
|
|
||||||
0x04, /* iConfiguration */
|
|
||||||
#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) */
|
|
||||||
|
|
||||||
/******************** Mass Storage interface ********************/
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
0x04, /* bDescriptorType */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints */
|
|
||||||
0x08, /* bInterfaceClass: MSC Class */
|
|
||||||
0x06, /* bInterfaceSubClass : SCSI transparent command set */
|
|
||||||
0x50, /* nInterfaceProtocol */
|
|
||||||
0x05, /* iInterface */
|
|
||||||
/******************** Mass Storage Endpoints ********************/
|
|
||||||
0x07, /* Endpoint descriptor length = 7 */
|
|
||||||
0x05, /* Endpoint descriptor type */
|
|
||||||
MSC_EPIN_ADDR, /* Endpoint address (IN, address 1) */
|
|
||||||
0x02, /* Bulk endpoint type */
|
|
||||||
0x40,
|
|
||||||
0x00,
|
|
||||||
0x00, /* Polling interval in milliseconds */
|
|
||||||
|
|
||||||
0x07, /* Endpoint descriptor length = 7 */
|
|
||||||
0x05, /* Endpoint descriptor type */
|
|
||||||
MSC_EPOUT_ADDR, /* Endpoint address (OUT, address 1) */
|
|
||||||
0x02, /* Bulk endpoint type */
|
|
||||||
0x40,
|
|
||||||
0x00,
|
|
||||||
0x00 /* Polling interval in milliseconds */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -272,6 +190,11 @@ __ALIGN_BEGIN static uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
uint8_t MSCInEpAdd = MSC_EPIN_ADDR;
|
||||||
|
uint8_t MSCOutEpAdd = MSC_EPOUT_ADDR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -297,31 +220,38 @@ uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pClassData = (void *)hmsc;
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hmsc;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
(void)USBD_LL_OpenEP(pdev, MSCOutEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
||||||
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U;
|
pdev->ep_out[MSCOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
(void)USBD_LL_OpenEP(pdev, MSCInEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
||||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
pdev->ep_in[MSCInEpAdd & 0xFU].is_used = 1U;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
(void)USBD_LL_OpenEP(pdev, MSCOutEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
||||||
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U;
|
pdev->ep_out[MSCOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
(void)USBD_LL_OpenEP(pdev, MSCInEpAdd, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
||||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
pdev->ep_in[MSCInEpAdd & 0xFU].is_used = 1U;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init the BOT layer */
|
/* Init the BOT layer */
|
||||||
@@ -341,21 +271,28 @@ uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close MSC EPs */
|
/* Close MSC EPs */
|
||||||
(void)USBD_LL_CloseEP(pdev, MSC_EPOUT_ADDR);
|
(void)USBD_LL_CloseEP(pdev, MSCOutEpAdd);
|
||||||
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 0U;
|
pdev->ep_out[MSCOutEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP IN */
|
/* Close EP IN */
|
||||||
(void)USBD_LL_CloseEP(pdev, MSC_EPIN_ADDR);
|
(void)USBD_LL_CloseEP(pdev, MSCInEpAdd);
|
||||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 0U;
|
pdev->ep_in[MSCInEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Free MSC Class Resources */
|
/* Free MSC Class Resources */
|
||||||
if (pdev->pClassData != NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
{
|
{
|
||||||
/* De-Init the BOT layer */
|
/* De-Init the BOT layer */
|
||||||
MSC_BOT_DeInit(pdev);
|
MSC_BOT_DeInit(pdev);
|
||||||
|
|
||||||
(void)USBD_free(pdev->pClassData);
|
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,10 +307,17 @@ uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
uint32_t max_lun;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
@@ -389,7 +333,8 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
if ((req->wValue == 0U) && (req->wLength == 1U) &&
|
if ((req->wValue == 0U) && (req->wLength == 1U) &&
|
||||||
((req->bmRequest & 0x80U) == 0x80U))
|
((req->bmRequest & 0x80U) == 0x80U))
|
||||||
{
|
{
|
||||||
hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun();
|
max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetMaxLun();
|
||||||
|
hmsc->max_lun = (max_lun > MSC_BOT_MAX_LUN) ? MSC_BOT_MAX_LUN : max_lun;
|
||||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->max_lun, 1U);
|
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->max_lun, 1U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -515,7 +460,7 @@ uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_GetHSCfgDesc
|
* @brief USBD_MSC_GetHSCfgDesc
|
||||||
* return configuration descriptor
|
* return configuration descriptor
|
||||||
@@ -524,9 +469,21 @@ uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length)
|
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_MSC_CfgHSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPIN_ADDR);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPOUT_ADDR);
|
||||||
|
|
||||||
return USBD_MSC_CfgHSDesc;
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = MSC_MAX_HS_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = MSC_MAX_HS_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_MSC_CfgDesc);
|
||||||
|
return USBD_MSC_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -537,9 +494,21 @@ uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length)
|
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_MSC_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPIN_ADDR);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPOUT_ADDR);
|
||||||
|
|
||||||
return USBD_MSC_CfgFSDesc;
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = MSC_MAX_FS_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = MSC_MAX_FS_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_MSC_CfgDesc);
|
||||||
|
return USBD_MSC_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -550,9 +519,21 @@ uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length)
|
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_MSC_OtherSpeedCfgDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPIN_ADDR);
|
||||||
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_MSC_CfgDesc, MSC_EPOUT_ADDR);
|
||||||
|
|
||||||
return USBD_MSC_OtherSpeedCfgDesc;
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = MSC_MAX_FS_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = MSC_MAX_FS_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t)sizeof(USBD_MSC_CfgDesc);
|
||||||
|
return USBD_MSC_CfgDesc;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
@@ -566,7 +547,7 @@ uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length)
|
|||||||
|
|
||||||
return USBD_MSC_DeviceQualifierDesc;
|
return USBD_MSC_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_RegisterStorage
|
* @brief USBD_MSC_RegisterStorage
|
||||||
* @param fops: storage callback
|
* @param fops: storage callback
|
||||||
@@ -579,7 +560,7 @@ uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, USBD_StorageTypeDef *
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ EndBSPDependencies */
|
|||||||
/** @defgroup MSC_BOT_Private_Variables
|
/** @defgroup MSC_BOT_Private_Variables
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
extern uint8_t MSCInEpAdd;
|
||||||
|
extern uint8_t MSCOutEpAdd;
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -96,7 +97,13 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
|||||||
*/
|
*/
|
||||||
void MSC_BOT_Init(USBD_HandleTypeDef *pdev)
|
void MSC_BOT_Init(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -110,13 +117,13 @@ void MSC_BOT_Init(USBD_HandleTypeDef *pdev)
|
|||||||
hmsc->scsi_sense_head = 0U;
|
hmsc->scsi_sense_head = 0U;
|
||||||
hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED;
|
hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED;
|
||||||
|
|
||||||
((USBD_StorageTypeDef *)pdev->pUserData)->Init(0U);
|
((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Init(0U);
|
||||||
|
|
||||||
(void)USBD_LL_FlushEP(pdev, MSC_EPOUT_ADDR);
|
(void)USBD_LL_FlushEP(pdev, MSCOutEpAdd);
|
||||||
(void)USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR);
|
(void)USBD_LL_FlushEP(pdev, MSCInEpAdd);
|
||||||
|
|
||||||
/* Prepare EP to Receive First BOT Cmd */
|
/* Prepare EP to Receive First BOT Cmd */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw,
|
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw,
|
||||||
USBD_BOT_CBW_LENGTH);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +135,13 @@ void MSC_BOT_Init(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev)
|
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -138,11 +151,11 @@ void MSC_BOT_Reset(USBD_HandleTypeDef *pdev)
|
|||||||
hmsc->bot_state = USBD_BOT_IDLE;
|
hmsc->bot_state = USBD_BOT_IDLE;
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
|
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
|
||||||
|
|
||||||
(void)USBD_LL_ClearStallEP(pdev, MSC_EPIN_ADDR);
|
(void)USBD_LL_ClearStallEP(pdev, MSCInEpAdd);
|
||||||
(void)USBD_LL_ClearStallEP(pdev, MSC_EPOUT_ADDR);
|
(void)USBD_LL_ClearStallEP(pdev, MSCOutEpAdd);
|
||||||
|
|
||||||
/* Prepare EP to Receive First BOT Cmd */
|
/* Prepare EP to Receive First BOT Cmd */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw,
|
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw,
|
||||||
USBD_BOT_CBW_LENGTH);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +167,7 @@ void MSC_BOT_Reset(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev)
|
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc != NULL)
|
if (hmsc != NULL)
|
||||||
{
|
{
|
||||||
@@ -173,7 +186,7 @@ void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
{
|
{
|
||||||
UNUSED(epnum);
|
UNUSED(epnum);
|
||||||
|
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -209,7 +222,7 @@ void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
{
|
{
|
||||||
UNUSED(epnum);
|
UNUSED(epnum);
|
||||||
|
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -242,7 +255,13 @@ void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev)
|
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -252,9 +271,9 @@ static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev)
|
|||||||
hmsc->csw.dTag = hmsc->cbw.dTag;
|
hmsc->csw.dTag = hmsc->cbw.dTag;
|
||||||
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
|
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
|
||||||
|
|
||||||
if ((USBD_LL_GetRxDataSize(pdev, MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) ||
|
if ((USBD_LL_GetRxDataSize(pdev, MSCOutEpAdd) != USBD_BOT_CBW_LENGTH) ||
|
||||||
(hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) ||
|
(hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) ||
|
||||||
(hmsc->cbw.bLUN > 1U) || (hmsc->cbw.bCBLength < 1U) ||
|
(hmsc->cbw.bLUN > hmsc->max_lun) || (hmsc->cbw.bCBLength < 1U) ||
|
||||||
(hmsc->cbw.bCBLength > 16U))
|
(hmsc->cbw.bCBLength > 16U))
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
||||||
@@ -310,20 +329,28 @@ static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len)
|
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
uint32_t length = MIN(hmsc->cbw.dDataLength, len);
|
uint32_t length;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
length = MIN(hmsc->cbw.dDataLength, len);
|
||||||
|
|
||||||
hmsc->csw.dDataResidue -= len;
|
hmsc->csw.dDataResidue -= len;
|
||||||
hmsc->csw.bStatus = USBD_CSW_CMD_PASSED;
|
hmsc->csw.bStatus = USBD_CSW_CMD_PASSED;
|
||||||
hmsc->bot_state = USBD_BOT_SEND_DATA;
|
hmsc->bot_state = USBD_BOT_SEND_DATA;
|
||||||
|
|
||||||
(void)USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, pbuf, length);
|
(void)USBD_LL_Transmit(pdev, MSCInEpAdd, pbuf, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -335,7 +362,13 @@ static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t
|
|||||||
*/
|
*/
|
||||||
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status)
|
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -346,11 +379,11 @@ void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status)
|
|||||||
hmsc->csw.bStatus = CSW_Status;
|
hmsc->csw.bStatus = CSW_Status;
|
||||||
hmsc->bot_state = USBD_BOT_IDLE;
|
hmsc->bot_state = USBD_BOT_IDLE;
|
||||||
|
|
||||||
(void)USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, (uint8_t *)&hmsc->csw,
|
(void)USBD_LL_Transmit(pdev, MSCInEpAdd, (uint8_t *)&hmsc->csw,
|
||||||
USBD_BOT_CSW_LENGTH);
|
USBD_BOT_CSW_LENGTH);
|
||||||
|
|
||||||
/* Prepare EP to Receive next Cmd */
|
/* Prepare EP to Receive next Cmd */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw,
|
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, (uint8_t *)&hmsc->cbw,
|
||||||
USBD_BOT_CBW_LENGTH);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,7 +396,13 @@ void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status)
|
|||||||
|
|
||||||
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev)
|
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -374,15 +413,15 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev)
|
|||||||
(hmsc->cbw.dDataLength != 0U) &&
|
(hmsc->cbw.dDataLength != 0U) &&
|
||||||
(hmsc->bot_status == USBD_BOT_STATUS_NORMAL))
|
(hmsc->bot_status == USBD_BOT_STATUS_NORMAL))
|
||||||
{
|
{
|
||||||
(void)USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR);
|
(void)USBD_LL_StallEP(pdev, MSCOutEpAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
(void)USBD_LL_StallEP(pdev, MSCInEpAdd);
|
||||||
|
|
||||||
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR)
|
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR)
|
||||||
{
|
{
|
||||||
(void)USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
(void)USBD_LL_StallEP(pdev, MSCInEpAdd);
|
||||||
(void)USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR);
|
(void)USBD_LL_StallEP(pdev, MSCOutEpAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -396,7 +435,13 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -405,8 +450,8 @@ void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
|
|
||||||
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) /* Bad CBW Signature */
|
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) /* Bad CBW Signature */
|
||||||
{
|
{
|
||||||
(void)USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
(void)USBD_LL_StallEP(pdev, MSCInEpAdd);
|
||||||
(void)USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR);
|
(void)USBD_LL_StallEP(pdev, MSCOutEpAdd);
|
||||||
}
|
}
|
||||||
else if (((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY))
|
else if (((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -91,63 +91,46 @@ uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80] =
|
|||||||
/* USB Mass storage sense 6 Data */
|
/* USB Mass storage sense 6 Data */
|
||||||
uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN] =
|
uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN] =
|
||||||
{
|
{
|
||||||
0x22,
|
0x03, /* MODE DATA LENGTH. The number of bytes that follow. */
|
||||||
0x00,
|
0x00, /* MEDIUM TYPE. 00h for SBC devices. */
|
||||||
0x00,
|
0x00, /* DEVICE-SPECIFIC PARAMETER. For SBC devices:
|
||||||
0x00,
|
* bit 7: WP. Set to 1 if the media is write-protected.
|
||||||
0x08,
|
* bits 6..5: reserved
|
||||||
0x12,
|
* bit 4: DPOFUA. Set to 1 if the device supports the DPO and FUA bits
|
||||||
0x00,
|
* bits 3..0: reserved */
|
||||||
0x00,
|
0x00 /* BLOCK DESCRIPTOR LENGTH */
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* USB Mass storage sense 10 Data */
|
/* USB Mass storage sense 10 Data */
|
||||||
uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN] =
|
uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN] =
|
||||||
{
|
{
|
||||||
0x00,
|
0x00, /* MODE DATA LENGTH MSB. */
|
||||||
0x26,
|
0x06, /* MODE DATA LENGTH LSB. The number of bytes that follow. */
|
||||||
0x00,
|
0x00, /* MEDIUM TYPE. 00h for SBC devices. */
|
||||||
0x00,
|
0x00, /* DEVICE-SPECIFIC PARAMETER. For SBC devices:
|
||||||
0x00,
|
* bit 7: WP. Set to 1 if the media is write-protected.
|
||||||
0x00,
|
* bits 6..5: reserved
|
||||||
0x00,
|
* bit 4: DPOFUA. Set to 1 if the device supports the DPO and FUA bits
|
||||||
0x00,
|
* bits 3..0: reserved */
|
||||||
0x08,
|
0x00, /* LONGLBA Set to zero */
|
||||||
0x12,
|
0x00, /* Reserved */
|
||||||
0x00,
|
0x00, /* BLOCK DESCRIPTOR LENGTH MSB. */
|
||||||
0x00,
|
0x00 /* BLOCK DESCRIPTOR LENGTH LSB. */
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint8_t MSC_Diagnostic_Data[DIAGNOSTIC_DATA_LEN] =
|
||||||
|
{
|
||||||
|
0x00, /* Byte 0: ADDITIONAL LENGTH (MSB) */
|
||||||
|
0x00, /* Byte 1: ADDITIONAL LENGTH (LSB) */
|
||||||
|
0x00, /* Byte 2: FRU CODE (most probable) */
|
||||||
|
0x00, /* Byte 3: FRU CODE */
|
||||||
|
0x00, /* Byte 4: FRU CODE */
|
||||||
|
0x00, /* Byte 5: FRU CODE (least probable) */
|
||||||
|
0x00, /* Byte 6: ERROR CODE (MSB) */
|
||||||
|
0x00, /* Byte 7: ERROR CODE (LSB) */
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ EndBSPDependencies */
|
|||||||
/** @defgroup MSC_SCSI_Private_Variables
|
/** @defgroup MSC_SCSI_Private_Variables
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
extern uint8_t MSCInEpAdd;
|
||||||
|
extern uint8_t MSCOutEpAdd;
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -91,6 +92,8 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||||
static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||||
|
static int8_t SCSI_ReportLuns(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||||
|
static int8_t SCSI_ReceiveDiagnosticResults(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||||
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||||
uint32_t blk_offset, uint32_t blk_nbr);
|
uint32_t blk_offset, uint32_t blk_nbr);
|
||||||
|
|
||||||
@@ -120,7 +123,7 @@ static int8_t SCSI_UpdateBotData(USBD_MSC_BOT_HandleTypeDef *hmsc,
|
|||||||
int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd)
|
int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd)
|
||||||
{
|
{
|
||||||
int8_t ret;
|
int8_t ret;
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -189,9 +192,16 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd)
|
|||||||
ret = SCSI_Verify10(pdev, lun, cmd);
|
ret = SCSI_Verify10(pdev, lun, cmd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SCSI_REPORT_LUNS:
|
||||||
|
ret = SCSI_ReportLuns(pdev, lun, cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCSI_RECEIVE_DIAGNOSTIC_RESULTS:
|
||||||
|
ret = SCSI_ReceiveDiagnosticResults(pdev, lun, cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB);
|
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB);
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_ERROR;
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -210,7 +220,7 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd)
|
|||||||
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
UNUSED(params);
|
UNUSED(params);
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -232,7 +242,7 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
hmsc->bot_state = USBD_BOT_NO_DATA;
|
hmsc->bot_state = USBD_BOT_NO_DATA;
|
||||||
@@ -256,7 +266,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
{
|
{
|
||||||
uint8_t *pPage;
|
uint8_t *pPage;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -282,14 +292,16 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
else /* Request Not supported */
|
else /* Request Not supported */
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST,
|
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST,
|
||||||
INVALID_FIELED_IN_COMMAND);
|
INVALID_FIELD_IN_COMMAND);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pPage = (uint8_t *) & ((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
|
|
||||||
|
pPage = (uint8_t *) & ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId]) \
|
||||||
|
->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
|
||||||
len = (uint16_t)pPage[4] + 5U;
|
len = (uint16_t)pPage[4] + 5U;
|
||||||
|
|
||||||
if (params[4] <= len)
|
if (params[4] <= len)
|
||||||
@@ -315,14 +327,16 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||||||
{
|
{
|
||||||
UNUSED(params);
|
UNUSED(params);
|
||||||
int8_t ret;
|
int8_t ret;
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size);
|
ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &p_scsi_blk->nbr,
|
||||||
|
&p_scsi_blk->size);
|
||||||
|
|
||||||
if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED))
|
if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED))
|
||||||
{
|
{
|
||||||
@@ -330,20 +344,19 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hmsc->bot_data[0] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 24);
|
hmsc->bot_data[0] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 24);
|
||||||
hmsc->bot_data[1] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 16);
|
hmsc->bot_data[1] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 16);
|
||||||
hmsc->bot_data[2] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 8);
|
hmsc->bot_data[2] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 8);
|
||||||
hmsc->bot_data[3] = (uint8_t)(hmsc->scsi_blk_nbr - 1U);
|
hmsc->bot_data[3] = (uint8_t)(p_scsi_blk->nbr - 1U);
|
||||||
|
|
||||||
hmsc->bot_data[4] = (uint8_t)(hmsc->scsi_blk_size >> 24);
|
hmsc->bot_data[4] = (uint8_t)(p_scsi_blk->size >> 24);
|
||||||
hmsc->bot_data[5] = (uint8_t)(hmsc->scsi_blk_size >> 16);
|
hmsc->bot_data[5] = (uint8_t)(p_scsi_blk->size >> 16);
|
||||||
hmsc->bot_data[6] = (uint8_t)(hmsc->scsi_blk_size >> 8);
|
hmsc->bot_data[6] = (uint8_t)(p_scsi_blk->size >> 8);
|
||||||
hmsc->bot_data[7] = (uint8_t)(hmsc->scsi_blk_size);
|
hmsc->bot_data[7] = (uint8_t)(p_scsi_blk->size);
|
||||||
|
|
||||||
hmsc->bot_data_length = 8U;
|
hmsc->bot_data_length = 8U;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -357,16 +370,18 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||||||
static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
UNUSED(params);
|
UNUSED(params);
|
||||||
uint8_t idx;
|
uint32_t idx;
|
||||||
int8_t ret;
|
int8_t ret;
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size);
|
ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &p_scsi_blk->nbr,
|
||||||
|
&p_scsi_blk->size);
|
||||||
|
|
||||||
if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED))
|
if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED))
|
||||||
{
|
{
|
||||||
@@ -384,15 +399,15 @@ static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||||||
hmsc->bot_data[idx] = 0U;
|
hmsc->bot_data[idx] = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
hmsc->bot_data[4] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 24);
|
hmsc->bot_data[4] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 24);
|
||||||
hmsc->bot_data[5] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 16);
|
hmsc->bot_data[5] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 16);
|
||||||
hmsc->bot_data[6] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 8);
|
hmsc->bot_data[6] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 8);
|
||||||
hmsc->bot_data[7] = (uint8_t)(hmsc->scsi_blk_nbr - 1U);
|
hmsc->bot_data[7] = (uint8_t)(p_scsi_blk->nbr - 1U);
|
||||||
|
|
||||||
hmsc->bot_data[8] = (uint8_t)(hmsc->scsi_blk_size >> 24);
|
hmsc->bot_data[8] = (uint8_t)(p_scsi_blk->size >> 24);
|
||||||
hmsc->bot_data[9] = (uint8_t)(hmsc->scsi_blk_size >> 16);
|
hmsc->bot_data[9] = (uint8_t)(p_scsi_blk->size >> 16);
|
||||||
hmsc->bot_data[10] = (uint8_t)(hmsc->scsi_blk_size >> 8);
|
hmsc->bot_data[10] = (uint8_t)(p_scsi_blk->size >> 8);
|
||||||
hmsc->bot_data[11] = (uint8_t)(hmsc->scsi_blk_size);
|
hmsc->bot_data[11] = (uint8_t)(p_scsi_blk->size);
|
||||||
|
|
||||||
hmsc->bot_data_length = ((uint32_t)params[10] << 24) |
|
hmsc->bot_data_length = ((uint32_t)params[10] << 24) |
|
||||||
((uint32_t)params[11] << 16) |
|
((uint32_t)params[11] << 16) |
|
||||||
@@ -417,14 +432,14 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uin
|
|||||||
uint32_t blk_nbr;
|
uint32_t blk_nbr;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
int8_t ret;
|
int8_t ret;
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size);
|
ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &blk_nbr, &blk_size);
|
||||||
|
|
||||||
if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED))
|
if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED))
|
||||||
{
|
{
|
||||||
@@ -464,7 +479,7 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uin
|
|||||||
static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
UNUSED(lun);
|
UNUSED(lun);
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint16_t len = MODE_SENSE6_LEN;
|
uint16_t len = MODE_SENSE6_LEN;
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
@@ -472,6 +487,16 @@ static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *pa
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check If media is write-protected */
|
||||||
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0)
|
||||||
|
{
|
||||||
|
MSC_Mode_Sense6_data[2] |= (0x1U << 7); /* Set the WP (write protection) bit */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MSC_Mode_Sense10_data[2] &= ~(0x1U << 7); /* Clear the WP (write protection) bit */
|
||||||
|
}
|
||||||
|
|
||||||
if (params[4] <= len)
|
if (params[4] <= len)
|
||||||
{
|
{
|
||||||
len = params[4];
|
len = params[4];
|
||||||
@@ -493,7 +518,7 @@ static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *pa
|
|||||||
static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
UNUSED(lun);
|
UNUSED(lun);
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint16_t len = MODE_SENSE10_LEN;
|
uint16_t len = MODE_SENSE10_LEN;
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
@@ -501,6 +526,16 @@ static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *p
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check If media is write-protected */
|
||||||
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0)
|
||||||
|
{
|
||||||
|
MSC_Mode_Sense10_data[3] |= (0x1U << 7); /* Set the WP (write protection) bit */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MSC_Mode_Sense10_data[3] &= ~(0x1U << 7); /* Clear the WP (write protection) bit */
|
||||||
|
}
|
||||||
|
|
||||||
if (params[8] <= len)
|
if (params[8] <= len)
|
||||||
{
|
{
|
||||||
len = params[8];
|
len = params[8];
|
||||||
@@ -523,7 +558,7 @@ static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
|
|||||||
{
|
{
|
||||||
UNUSED(lun);
|
UNUSED(lun);
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -580,7 +615,7 @@ static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
|
|||||||
void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t ASC)
|
void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t ASC)
|
||||||
{
|
{
|
||||||
UNUSED(lun);
|
UNUSED(lun);
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -609,7 +644,7 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t
|
|||||||
static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
UNUSED(lun);
|
UNUSED(lun);
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -618,7 +653,7 @@ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||||||
|
|
||||||
if ((hmsc->scsi_medium_state == SCSI_MEDIUM_LOCKED) && ((params[4] & 0x3U) == 2U))
|
if ((hmsc->scsi_medium_state == SCSI_MEDIUM_LOCKED) && ((params[4] & 0x3U) == 2U))
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELD_IN_COMMAND);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -655,7 +690,7 @@ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
|||||||
static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
UNUSED(lun);
|
UNUSED(lun);
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -686,7 +721,8 @@ static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun,
|
|||||||
*/
|
*/
|
||||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -709,27 +745,26 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
p_scsi_blk->addr = ((uint32_t)params[2] << 24) |
|
||||||
((uint32_t)params[3] << 16) |
|
((uint32_t)params[3] << 16) |
|
||||||
((uint32_t)params[4] << 8) |
|
((uint32_t)params[4] << 8) |
|
||||||
(uint32_t)params[5];
|
(uint32_t)params[5];
|
||||||
|
|
||||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8];
|
p_scsi_blk->len = ((uint32_t)params[7] << 8) | (uint32_t)params[8];
|
||||||
|
|
||||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
if (SCSI_CheckAddressRange(pdev, lun, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||||
hmsc->scsi_blk_len) < 0)
|
|
||||||
{
|
{
|
||||||
return -1; /* error */
|
return -1; /* error */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cases 4,5 : Hi <> Dn */
|
/* cases 4,5 : Hi <> Dn */
|
||||||
if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size))
|
if (hmsc->cbw.dDataLength != (p_scsi_blk->len * p_scsi_blk->size))
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -752,7 +787,8 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
|||||||
*/
|
*/
|
||||||
static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -774,30 +810,29 @@ static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
p_scsi_blk->addr = ((uint32_t)params[2] << 24) |
|
||||||
((uint32_t)params[3] << 16) |
|
((uint32_t)params[3] << 16) |
|
||||||
((uint32_t)params[4] << 8) |
|
((uint32_t)params[4] << 8) |
|
||||||
(uint32_t)params[5];
|
(uint32_t)params[5];
|
||||||
|
|
||||||
hmsc->scsi_blk_len = ((uint32_t)params[6] << 24) |
|
p_scsi_blk->len = ((uint32_t)params[6] << 24) |
|
||||||
((uint32_t)params[7] << 16) |
|
((uint32_t)params[7] << 16) |
|
||||||
((uint32_t)params[8] << 8) |
|
((uint32_t)params[8] << 8) |
|
||||||
(uint32_t)params[9];
|
(uint32_t)params[9];
|
||||||
|
|
||||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
if (SCSI_CheckAddressRange(pdev, lun, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||||
hmsc->scsi_blk_len) < 0)
|
|
||||||
{
|
{
|
||||||
return -1; /* error */
|
return -1; /* error */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cases 4,5 : Hi <> Dn */
|
/* cases 4,5 : Hi <> Dn */
|
||||||
if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size))
|
if (hmsc->cbw.dDataLength != (p_scsi_blk->len * p_scsi_blk->size))
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -820,7 +855,8 @@ static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
|||||||
*/
|
*/
|
||||||
static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
@@ -828,6 +864,11 @@ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||||
{
|
{
|
||||||
if (hmsc->cbw.dDataLength == 0U)
|
if (hmsc->cbw.dDataLength == 0U)
|
||||||
@@ -844,35 +885,34 @@ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether Media is ready */
|
/* Check whether Media is ready */
|
||||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check If media is write-protected */
|
/* Check If media is write-protected */
|
||||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsWriteProtected(lun) != 0)
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED);
|
SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
p_scsi_blk->addr = ((uint32_t)params[2] << 24) |
|
||||||
((uint32_t)params[3] << 16) |
|
((uint32_t)params[3] << 16) |
|
||||||
((uint32_t)params[4] << 8) |
|
((uint32_t)params[4] << 8) |
|
||||||
(uint32_t)params[5];
|
(uint32_t)params[5];
|
||||||
|
|
||||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) |
|
p_scsi_blk->len = ((uint32_t)params[7] << 8) |
|
||||||
(uint32_t)params[8];
|
(uint32_t)params[8];
|
||||||
|
|
||||||
/* check if LBA address is in the right range */
|
/* check if LBA address is in the right range */
|
||||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
if (SCSI_CheckAddressRange(pdev, lun, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||||
hmsc->scsi_blk_len) < 0)
|
|
||||||
{
|
{
|
||||||
return -1; /* error */
|
return -1; /* error */
|
||||||
}
|
}
|
||||||
|
|
||||||
len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
len = p_scsi_blk->len * p_scsi_blk->size;
|
||||||
|
|
||||||
/* cases 3,11,13 : Hn,Ho <> D0 */
|
/* cases 3,11,13 : Hn,Ho <> D0 */
|
||||||
if (hmsc->cbw.dDataLength != len)
|
if (hmsc->cbw.dDataLength != len)
|
||||||
@@ -885,7 +925,7 @@ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
|
|
||||||
/* Prepare EP to receive first data packet */
|
/* Prepare EP to receive first data packet */
|
||||||
hmsc->bot_state = USBD_BOT_DATA_OUT;
|
hmsc->bot_state = USBD_BOT_DATA_OUT;
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len);
|
||||||
}
|
}
|
||||||
else /* Write Process ongoing */
|
else /* Write Process ongoing */
|
||||||
{
|
{
|
||||||
@@ -905,13 +945,18 @@ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
*/
|
*/
|
||||||
static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||||
{
|
{
|
||||||
@@ -929,7 +974,7 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether Media is ready */
|
/* Check whether Media is ready */
|
||||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||||
hmsc->bot_state = USBD_BOT_NO_DATA;
|
hmsc->bot_state = USBD_BOT_NO_DATA;
|
||||||
@@ -937,31 +982,30 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check If media is write-protected */
|
/* Check If media is write-protected */
|
||||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsWriteProtected(lun) != 0)
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED);
|
SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED);
|
||||||
hmsc->bot_state = USBD_BOT_NO_DATA;
|
hmsc->bot_state = USBD_BOT_NO_DATA;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
p_scsi_blk->addr = ((uint32_t)params[2] << 24) |
|
||||||
((uint32_t)params[3] << 16) |
|
((uint32_t)params[3] << 16) |
|
||||||
((uint32_t)params[4] << 8) |
|
((uint32_t)params[4] << 8) |
|
||||||
(uint32_t)params[5];
|
(uint32_t)params[5];
|
||||||
|
|
||||||
hmsc->scsi_blk_len = ((uint32_t)params[6] << 24) |
|
p_scsi_blk->len = ((uint32_t)params[6] << 24) |
|
||||||
((uint32_t)params[7] << 16) |
|
((uint32_t)params[7] << 16) |
|
||||||
((uint32_t)params[8] << 8) |
|
((uint32_t)params[8] << 8) |
|
||||||
(uint32_t)params[9];
|
(uint32_t)params[9];
|
||||||
|
|
||||||
/* check if LBA address is in the right range */
|
/* check if LBA address is in the right range */
|
||||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
if (SCSI_CheckAddressRange(pdev, lun, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||||
hmsc->scsi_blk_len) < 0)
|
|
||||||
{
|
{
|
||||||
return -1; /* error */
|
return -1; /* error */
|
||||||
}
|
}
|
||||||
|
|
||||||
len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
len = p_scsi_blk->len * p_scsi_blk->size;
|
||||||
|
|
||||||
/* cases 3,11,13 : Hn,Ho <> D0 */
|
/* cases 3,11,13 : Hn,Ho <> D0 */
|
||||||
if (hmsc->cbw.dDataLength != len)
|
if (hmsc->cbw.dDataLength != len)
|
||||||
@@ -974,7 +1018,7 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
|
|
||||||
/* Prepare EP to receive first data packet */
|
/* Prepare EP to receive first data packet */
|
||||||
hmsc->bot_state = USBD_BOT_DATA_OUT;
|
hmsc->bot_state = USBD_BOT_DATA_OUT;
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len);
|
||||||
}
|
}
|
||||||
else /* Write Process ongoing */
|
else /* Write Process ongoing */
|
||||||
{
|
{
|
||||||
@@ -994,7 +1038,8 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
|||||||
*/
|
*/
|
||||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
@@ -1003,11 +1048,11 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *para
|
|||||||
|
|
||||||
if ((params[1] & 0x02U) == 0x02U)
|
if ((params[1] & 0x02U) == 0x02U)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELD_IN_COMMAND);
|
||||||
return -1; /* Error, Verify Mode Not supported*/
|
return -1; /* Error, Verify Mode Not supported*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0)
|
if (SCSI_CheckAddressRange(pdev, lun, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||||
{
|
{
|
||||||
return -1; /* error */
|
return -1; /* error */
|
||||||
}
|
}
|
||||||
@@ -1017,6 +1062,90 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *para
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SCSI_ReportLuns12
|
||||||
|
* Process ReportLuns command
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static int8_t SCSI_ReportLuns(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
|
{
|
||||||
|
USBD_MSC_BOT_HandleTypeDef *hmsc;
|
||||||
|
uint32_t lun_list_length;
|
||||||
|
uint32_t total_length;
|
||||||
|
uint8_t lun_idx;
|
||||||
|
|
||||||
|
UNUSED(lun);
|
||||||
|
UNUSED(params);
|
||||||
|
|
||||||
|
/* Define the report LUNs buffer Each LUN entry is 8 bytes */
|
||||||
|
static uint8_t lun_report[8U * (MSC_BOT_MAX_LUN + 1U)];
|
||||||
|
|
||||||
|
hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
if (hmsc == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize the report LUNs buffer */
|
||||||
|
(void)USBD_memset(lun_report, 0, sizeof(lun_report));
|
||||||
|
|
||||||
|
/* Set the LUN list length in the first 4 bytes */
|
||||||
|
lun_list_length = 8U * (hmsc->max_lun + 1U);
|
||||||
|
lun_report[0] = (uint8_t)(lun_list_length >> 24);
|
||||||
|
lun_report[1] = (uint8_t)(lun_list_length >> 16);
|
||||||
|
lun_report[2] = (uint8_t)(lun_list_length >> 8);
|
||||||
|
lun_report[3] = (uint8_t)(lun_list_length & 0xFFU);
|
||||||
|
|
||||||
|
/* Update the LUN list */
|
||||||
|
for (lun_idx = 0U; lun_idx <= hmsc->max_lun; lun_idx++)
|
||||||
|
{
|
||||||
|
/* LUN identifier is placed at the second byte of each 8-byte entry */
|
||||||
|
lun_report[(8U * (lun_idx + 1U)) + 1U] = lun_idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate the total length of the report LUNs buffer */
|
||||||
|
total_length = lun_list_length + 8U;
|
||||||
|
|
||||||
|
/* Update the BOT data with the report LUNs buffer */
|
||||||
|
(void)SCSI_UpdateBotData(hmsc, lun_report, (uint16_t)total_length);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SCSI_ReceiveDiagnosticResults
|
||||||
|
* Process SCSI_Receive Diagnostic Results command
|
||||||
|
* @param lun: Logical unit number
|
||||||
|
* @param params: Command parameters
|
||||||
|
* @retval status
|
||||||
|
*/
|
||||||
|
static int8_t SCSI_ReceiveDiagnosticResults(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||||
|
{
|
||||||
|
UNUSED(lun);
|
||||||
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
uint16_t allocation_length;
|
||||||
|
|
||||||
|
/* Extract the allocation length from the CDB */
|
||||||
|
allocation_length = (((uint16_t)params[3] << 8) | (uint16_t)params[4]);
|
||||||
|
|
||||||
|
if (allocation_length == 0U)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure the allocation length does not exceed the diagnostic data length */
|
||||||
|
if (allocation_length > DIAGNOSTIC_DATA_LEN)
|
||||||
|
{
|
||||||
|
allocation_length = DIAGNOSTIC_DATA_LEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send the diagnostic data to the host */
|
||||||
|
(void)SCSI_UpdateBotData(hmsc, MSC_Diagnostic_Data, allocation_length);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SCSI_CheckAddressRange
|
* @brief SCSI_CheckAddressRange
|
||||||
* Check address range
|
* Check address range
|
||||||
@@ -1028,14 +1157,15 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *para
|
|||||||
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||||
uint32_t blk_offset, uint32_t blk_nbr)
|
uint32_t blk_offset, uint32_t blk_nbr)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr)
|
if ((blk_offset + blk_nbr) > p_scsi_blk->nbr)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE);
|
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1052,33 +1182,41 @@ static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
|||||||
*/
|
*/
|
||||||
static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun)
|
static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
|
uint32_t len;
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len = p_scsi_blk->len * p_scsi_blk->size;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
len = MIN(len, MSC_MEDIA_PACKET);
|
len = MIN(len, MSC_MEDIA_PACKET);
|
||||||
|
|
||||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun, hmsc->bot_data,
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Read(lun, hmsc->bot_data,
|
||||||
hmsc->scsi_blk_addr,
|
p_scsi_blk->addr,
|
||||||
(len / hmsc->scsi_blk_size)) < 0)
|
(len / p_scsi_blk->size)) < 0)
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR);
|
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, hmsc->bot_data, len);
|
(void)USBD_LL_Transmit(pdev, MSCInEpAdd, hmsc->bot_data, len);
|
||||||
|
|
||||||
hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size);
|
p_scsi_blk->addr += (len / p_scsi_blk->size);
|
||||||
hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size);
|
p_scsi_blk->len -= (len / p_scsi_blk->size);
|
||||||
|
|
||||||
/* case 6 : Hi = Di */
|
/* case 6 : Hi = Di */
|
||||||
hmsc->csw.dDataResidue -= len;
|
hmsc->csw.dDataResidue -= len;
|
||||||
|
|
||||||
if (hmsc->scsi_blk_len == 0U)
|
if (p_scsi_blk->len == 0U)
|
||||||
{
|
{
|
||||||
hmsc->bot_state = USBD_BOT_LAST_DATA_IN;
|
hmsc->bot_state = USBD_BOT_LAST_DATA_IN;
|
||||||
}
|
}
|
||||||
@@ -1094,40 +1232,47 @@ static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun)
|
|||||||
*/
|
*/
|
||||||
static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun)
|
static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||||
|
uint32_t len;
|
||||||
|
|
||||||
if (hmsc == NULL)
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
len = p_scsi_blk->len * p_scsi_blk->size;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
len = MIN(len, MSC_MEDIA_PACKET);
|
len = MIN(len, MSC_MEDIA_PACKET);
|
||||||
|
|
||||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun, hmsc->bot_data,
|
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Write(lun, hmsc->bot_data, p_scsi_blk->addr,
|
||||||
hmsc->scsi_blk_addr,
|
(len / p_scsi_blk->size)) < 0)
|
||||||
(len / hmsc->scsi_blk_size)) < 0)
|
|
||||||
{
|
{
|
||||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, WRITE_FAULT);
|
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, WRITE_FAULT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size);
|
p_scsi_blk->addr += (len / p_scsi_blk->size);
|
||||||
hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size);
|
p_scsi_blk->len -= (len / p_scsi_blk->size);
|
||||||
|
|
||||||
/* case 12 : Ho = Do */
|
/* case 12 : Ho = Do */
|
||||||
hmsc->csw.dDataResidue -= len;
|
hmsc->csw.dDataResidue -= len;
|
||||||
|
|
||||||
if (hmsc->scsi_blk_len == 0U)
|
if (p_scsi_blk->len == 0U)
|
||||||
{
|
{
|
||||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len = MIN((hmsc->scsi_blk_len * hmsc->scsi_blk_size), MSC_MEDIA_PACKET);
|
len = MIN((p_scsi_blk->len * p_scsi_blk->size), MSC_MEDIA_PACKET);
|
||||||
|
|
||||||
/* Prepare EP to Receive next packet */
|
/* Prepare EP to Receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -86,87 +86,103 @@ USBD_StorageTypeDef USBD_MSC_Template_fops =
|
|||||||
STORAGE_Inquirydata,
|
STORAGE_Inquirydata,
|
||||||
|
|
||||||
};
|
};
|
||||||
/*******************************************************************************
|
|
||||||
* Function Name : Read_Memory
|
/**
|
||||||
* Description : Handle the Read operation from the microSD card.
|
* @brief Initializes the storage unit (medium)
|
||||||
* Input : None.
|
* @param lun: Logical unit number
|
||||||
* Output : None.
|
* @retval Status (0 : OK / -1 : Error)
|
||||||
* Return : None.
|
*/
|
||||||
*******************************************************************************/
|
|
||||||
int8_t STORAGE_Init(uint8_t lun)
|
int8_t STORAGE_Init(uint8_t lun)
|
||||||
{
|
{
|
||||||
|
UNUSED(lun);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/**
|
||||||
* Function Name : Read_Memory
|
* @brief Returns the medium capacity.
|
||||||
* Description : Handle the Read operation from the STORAGE card.
|
* @param lun: Logical unit number
|
||||||
* Input : None.
|
* @param block_num: Number of total block number
|
||||||
* Output : None.
|
* @param block_size: Block size
|
||||||
* Return : None.
|
* @retval Status (0: OK / -1: Error)
|
||||||
*******************************************************************************/
|
*/
|
||||||
int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
||||||
{
|
{
|
||||||
|
UNUSED(lun);
|
||||||
|
|
||||||
*block_num = STORAGE_BLK_NBR;
|
*block_num = STORAGE_BLK_NBR;
|
||||||
*block_size = STORAGE_BLK_SIZ;
|
*block_size = STORAGE_BLK_SIZ;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
|
||||||
* Function Name : Read_Memory
|
/**
|
||||||
* Description : Handle the Read operation from the STORAGE card.
|
* @brief Checks whether the medium is ready.
|
||||||
* Input : None.
|
* @param lun: Logical unit number
|
||||||
* Output : None.
|
* @retval Status (0: OK / -1: Error)
|
||||||
* Return : None.
|
*/
|
||||||
*******************************************************************************/
|
|
||||||
int8_t STORAGE_IsReady(uint8_t lun)
|
int8_t STORAGE_IsReady(uint8_t lun)
|
||||||
{
|
{
|
||||||
|
UNUSED(lun);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/**
|
||||||
* Function Name : Read_Memory
|
* @brief Checks whether the medium is write protected.
|
||||||
* Description : Handle the Read operation from the STORAGE card.
|
* @param lun: Logical unit number
|
||||||
* Input : None.
|
* @retval Status (0: write enabled / -1: otherwise)
|
||||||
* Output : None.
|
*/
|
||||||
* Return : None.
|
|
||||||
*******************************************************************************/
|
|
||||||
int8_t STORAGE_IsWriteProtected(uint8_t lun)
|
int8_t STORAGE_IsWriteProtected(uint8_t lun)
|
||||||
{
|
{
|
||||||
|
UNUSED(lun);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/**
|
||||||
* Function Name : Read_Memory
|
* @brief Reads data from the medium.
|
||||||
* Description : Handle the Read operation from the STORAGE card.
|
* @param lun: Logical unit number
|
||||||
* Input : None.
|
* @param buf: data buffer
|
||||||
* Output : None.
|
* @param blk_addr: Logical block address
|
||||||
* Return : None.
|
* @param blk_len: Blocks number
|
||||||
*******************************************************************************/
|
* @retval Status (0: OK / -1: Error)
|
||||||
|
*/
|
||||||
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf,
|
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf,
|
||||||
uint32_t blk_addr, uint16_t blk_len)
|
uint32_t blk_addr, uint16_t blk_len)
|
||||||
{
|
{
|
||||||
|
UNUSED(lun);
|
||||||
|
UNUSED(buf);
|
||||||
|
UNUSED(blk_addr);
|
||||||
|
UNUSED(blk_len);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*******************************************************************************
|
|
||||||
* Function Name : Write_Memory
|
/**
|
||||||
* Description : Handle the Write operation to the STORAGE card.
|
* @brief Writes data into the medium.
|
||||||
* Input : None.
|
* @param lun: Logical unit number
|
||||||
* Output : None.
|
* @param buf: data buffer
|
||||||
* Return : None.
|
* @param blk_addr: Logical block address
|
||||||
*******************************************************************************/
|
* @param blk_len: Blocks number
|
||||||
|
* @retval Status (0 : OK / -1 : Error)
|
||||||
|
*/
|
||||||
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf,
|
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf,
|
||||||
uint32_t blk_addr, uint16_t blk_len)
|
uint32_t blk_addr, uint16_t blk_len)
|
||||||
{
|
{
|
||||||
|
UNUSED(lun);
|
||||||
|
UNUSED(buf);
|
||||||
|
UNUSED(blk_addr);
|
||||||
|
UNUSED(blk_len);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
/*******************************************************************************
|
|
||||||
* Function Name : Write_Memory
|
/**
|
||||||
* Description : Handle the Write operation to the STORAGE card.
|
* @brief Returns the Max Supported LUNs.
|
||||||
* Input : None.
|
* @param None
|
||||||
* Output : None.
|
* @retval Lun(s) number
|
||||||
* Return : None.
|
*/
|
||||||
*******************************************************************************/
|
|
||||||
int8_t STORAGE_GetMaxLun(void)
|
int8_t STORAGE_GetMaxLun(void)
|
||||||
{
|
{
|
||||||
return (STORAGE_LUN_NBR - 1);
|
return (STORAGE_LUN_NBR - 1);
|
||||||
|
|||||||
@@ -41,10 +41,15 @@ extern "C" {
|
|||||||
/** @defgroup USBD_MTP_Exported_Defines
|
/** @defgroup USBD_MTP_Exported_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#ifndef MTP_IN_EP
|
||||||
#define MTP_IN_EP 0x81U /* EP1 for data IN */
|
#define MTP_IN_EP 0x81U /* EP1 for data IN */
|
||||||
|
#endif /* MTP_IN_EP */
|
||||||
|
#ifndef MTP_OUT_EP
|
||||||
#define MTP_OUT_EP 0x01U /* EP1 for data OUT */
|
#define MTP_OUT_EP 0x01U /* EP1 for data OUT */
|
||||||
|
#endif /* MTP_OUT_EP */
|
||||||
|
#ifndef MTP_CMD_EP
|
||||||
#define MTP_CMD_EP 0x82U /* EP2 for MTP commands */
|
#define MTP_CMD_EP 0x82U /* EP2 for MTP commands */
|
||||||
|
#endif /* MTP_CMD_EP */
|
||||||
|
|
||||||
#ifndef MTP_CMD_ITF_NBR
|
#ifndef MTP_CMD_ITF_NBR
|
||||||
#define MTP_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
#define MTP_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
||||||
@@ -62,9 +67,12 @@ extern "C" {
|
|||||||
#define MTP_FS_BINTERVAL 0x10U
|
#define MTP_FS_BINTERVAL 0x10U
|
||||||
#endif /* MTP_FS_BINTERVAL */
|
#endif /* MTP_FS_BINTERVAL */
|
||||||
|
|
||||||
|
#ifndef MTP_CMD_PACKET_SIZE
|
||||||
|
#define MTP_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
||||||
|
#endif /* MTP_CMD_PACKET_SIZE */
|
||||||
|
|
||||||
#define MTP_DATA_MAX_HS_PACKET_SIZE 512U
|
#define MTP_DATA_MAX_HS_PACKET_SIZE 512U
|
||||||
#define MTP_DATA_MAX_FS_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
#define MTP_DATA_MAX_FS_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||||
#define MTP_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
|
||||||
|
|
||||||
#define MTP_MEDIA_PACKET 512U
|
#define MTP_MEDIA_PACKET 512U
|
||||||
#define MTP_CONT_HEADER_SIZE 12U
|
#define MTP_CONT_HEADER_SIZE 12U
|
||||||
@@ -117,6 +125,11 @@ extern "C" {
|
|||||||
#define MTP_RESPONSE_SPECIFICATION_BY_GROUP_UNSUPPORTED 0xA807U
|
#define MTP_RESPONSE_SPECIFICATION_BY_GROUP_UNSUPPORTED 0xA807U
|
||||||
#define MTP_RESPONSE_OBJECT_PROP_NOT_SUPPORTED 0xA80AU
|
#define MTP_RESPONSE_OBJECT_PROP_NOT_SUPPORTED 0xA80AU
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MTP Class specification Revision 1.1
|
||||||
|
* Appendix A. Object Formats
|
||||||
|
*/
|
||||||
|
|
||||||
/* MTP Object format codes */
|
/* MTP Object format codes */
|
||||||
#define MTP_OBJ_FORMAT_UNDEFINED 0x3000U
|
#define MTP_OBJ_FORMAT_UNDEFINED 0x3000U
|
||||||
#define MTP_OBJ_FORMAT_ASSOCIATION 0x3001U
|
#define MTP_OBJ_FORMAT_ASSOCIATION 0x3001U
|
||||||
@@ -220,7 +233,7 @@ typedef struct
|
|||||||
uint32_t Param3;
|
uint32_t Param3;
|
||||||
uint32_t Param4;
|
uint32_t Param4;
|
||||||
uint32_t Param5;
|
uint32_t Param5;
|
||||||
} MTP_OperationsTypedef;
|
} MTP_OperationsTypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -235,7 +248,7 @@ typedef struct
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint32_t Storage_id;
|
uint32_t Storage_id;
|
||||||
uint16_t ObjectFormat;
|
uint16_t ObjectFormat;
|
||||||
@@ -270,7 +283,7 @@ typedef struct
|
|||||||
MTP_ResponsePhaseTypeDef MTP_ResponsePhase;
|
MTP_ResponsePhaseTypeDef MTP_ResponsePhase;
|
||||||
MTP_SessionStateTypeDef MTP_SessionState;
|
MTP_SessionStateTypeDef MTP_SessionState;
|
||||||
MTP_RECEIVE_DATA_STATUS RECEIVE_DATA_STATUS;
|
MTP_RECEIVE_DATA_STATUS RECEIVE_DATA_STATUS;
|
||||||
MTP_OperationsTypedef OperationsContainer;
|
MTP_OperationsTypeDef OperationsContainer;
|
||||||
MTP_GenericContainerTypeDef GenericContainer;
|
MTP_GenericContainerTypeDef GenericContainer;
|
||||||
} USBD_MTP_HandleTypeDef;
|
} USBD_MTP_HandleTypeDef;
|
||||||
|
|
||||||
|
|||||||
@@ -37,25 +37,25 @@ extern "C" {
|
|||||||
#define SUPP_EVENTS_LEN (uint8_t)((uint8_t)sizeof(SuppEvents) / 2U)
|
#define SUPP_EVENTS_LEN (uint8_t)((uint8_t)sizeof(SuppEvents) / 2U)
|
||||||
#else
|
#else
|
||||||
#define SUPP_EVENTS_LEN 0U
|
#define SUPP_EVENTS_LEN 0U
|
||||||
#endif
|
#endif /* USBD_MTP_EVENTS_SUPPORTED */
|
||||||
|
|
||||||
#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1
|
#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1
|
||||||
#define VEND_EXT_DESC_LEN (sizeof(VendExtDesc) / 2U)
|
#define VEND_EXT_DESC_LEN (sizeof(VendExtDesc) / 2U)
|
||||||
#else
|
#else
|
||||||
#define VEND_EXT_DESC_LEN 0U
|
#define VEND_EXT_DESC_LEN 0U
|
||||||
#endif
|
#endif /* USBD_MTP_VEND_EXT_DESC_SUPPORTED */
|
||||||
|
|
||||||
#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1
|
#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1
|
||||||
#define SUPP_CAPT_FORMAT_LEN (uint8_t)((uint8_t)sizeof(SuppCaptFormat) / 2U)
|
#define SUPP_CAPT_FORMAT_LEN (uint8_t)((uint8_t)sizeof(SuppCaptFormat) / 2U)
|
||||||
#else
|
#else
|
||||||
#define SUPP_CAPT_FORMAT_LEN 0U
|
#define SUPP_CAPT_FORMAT_LEN 0U
|
||||||
#endif
|
#endif /* USBD_MTP_CAPTURE_FORMAT_SUPPORTED */
|
||||||
|
|
||||||
#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1
|
#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1
|
||||||
#define SUPP_DEVICE_PROP_LEN (uint8_t)((uint8_t)sizeof(DevicePropSupp) / 2U)
|
#define SUPP_DEVICE_PROP_LEN (uint8_t)((uint8_t)sizeof(DevicePropSupp) / 2U)
|
||||||
#else
|
#else
|
||||||
#define SUPP_DEVICE_PROP_LEN 0U
|
#define SUPP_DEVICE_PROP_LEN 0U
|
||||||
#endif
|
#endif /* USBD_MTP_DEVICE_PROP_SUPPORTED */
|
||||||
|
|
||||||
#define MTP_IF_SCRATCH_BUFF_SZE 1024U
|
#define MTP_IF_SCRATCH_BUFF_SZE 1024U
|
||||||
|
|
||||||
@@ -73,7 +73,8 @@ static const uint16_t VendExtDesc[] = {'m', 'i', 'c', 'r', 'o', 's', 'o', 'f', '
|
|||||||
}; /* last 2 bytes must be 0*/
|
}; /* last 2 bytes must be 0*/
|
||||||
/*SerialNbr shall be 32 character hexadecimal string for legacy compatibility reasons */
|
/*SerialNbr shall be 32 character hexadecimal string for legacy compatibility reasons */
|
||||||
static const uint16_t SerialNbr[] = {'0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0',
|
static const uint16_t SerialNbr[] = {'0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0',
|
||||||
'1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', 0
|
'1', '0', '0', '0', '0', '1', '0', '0', '0', '0', '1', '0', '0', '0',
|
||||||
|
'0', '1', '0', '0', 0
|
||||||
}; /* last 2 bytes must be 0*/
|
}; /* last 2 bytes must be 0*/
|
||||||
static const uint16_t DeviceVers[] = {'V', '1', '.', '0', '0', 0}; /* last 2 bytes must be 0*/
|
static const uint16_t DeviceVers[] = {'V', '1', '.', '0', '0', 0}; /* last 2 bytes must be 0*/
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ extern "C" {
|
|||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#ifndef __USBD_MTP_IF_H
|
#ifndef __USBD_MTP_IF_H
|
||||||
#include "usbd_mtp_if_template.h"
|
#include "usbd_mtp_if_template.h"
|
||||||
#endif
|
#endif /* __USBD_MTP_IF_H */
|
||||||
#include "usbd_mtp.h"
|
#include "usbd_mtp.h"
|
||||||
|
|
||||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||||
@@ -43,6 +43,12 @@ extern "C" {
|
|||||||
/** @defgroup USBD_MTP_OPT_Exported_Defines
|
/** @defgroup USBD_MTP_OPT_Exported_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MTP Class specification Revision 1.1
|
||||||
|
* Appendix B. Object Properties
|
||||||
|
*/
|
||||||
|
|
||||||
/* MTP OBJECT PROPERTIES supported*/
|
/* MTP OBJECT PROPERTIES supported*/
|
||||||
#define MTP_OB_PROP_STORAGE_ID 0xDC01U
|
#define MTP_OB_PROP_STORAGE_ID 0xDC01U
|
||||||
#define MTP_OB_PROP_OBJECT_FORMAT 0xDC02U
|
#define MTP_OB_PROP_OBJECT_FORMAT 0xDC02U
|
||||||
@@ -231,6 +237,11 @@ extern "C" {
|
|||||||
#define MTP_EVENT_OBJECTPROPDESCCHANGED 0xC802U
|
#define MTP_EVENT_OBJECTPROPDESCCHANGED 0xC802U
|
||||||
#define MTP_EVENT_OBJECTREFERENCESCHANGED 0xC803U
|
#define MTP_EVENT_OBJECTREFERENCESCHANGED 0xC803U
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MTP Class specification Revision 1.1
|
||||||
|
* Appendix D. Operations
|
||||||
|
*/
|
||||||
|
|
||||||
/* Operations code */
|
/* Operations code */
|
||||||
#define MTP_OP_GET_DEVICE_INFO 0x1001U
|
#define MTP_OP_GET_DEVICE_INFO 0x1001U
|
||||||
#define MTP_OP_OPEN_SESSION 0x1002U
|
#define MTP_OP_OPEN_SESSION 0x1002U
|
||||||
@@ -267,6 +278,11 @@ extern "C" {
|
|||||||
#define MTP_OP_GETSERVICECAPABILITIES 0x9303U
|
#define MTP_OP_GETSERVICECAPABILITIES 0x9303U
|
||||||
#define MTP_OP_GETSERVICEPROPDESC 0x9304U
|
#define MTP_OP_GETSERVICEPROPDESC 0x9304U
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MTP Class specification Revision 1.1
|
||||||
|
* Appendix C. Device Properties
|
||||||
|
*/
|
||||||
|
|
||||||
/* MTP device properties code*/
|
/* MTP device properties code*/
|
||||||
#define MTP_DEV_PROP_UNDEFINED 0x5000U
|
#define MTP_DEV_PROP_UNDEFINED 0x5000U
|
||||||
#define MTP_DEV_PROP_BATTERY_LEVEL 0x5001U
|
#define MTP_DEV_PROP_BATTERY_LEVEL 0x5001U
|
||||||
@@ -327,22 +343,22 @@ extern "C" {
|
|||||||
#define FREE_SPACE_IN_OBJ_NOT_USED 0xFFFFFFFFU
|
#define FREE_SPACE_IN_OBJ_NOT_USED 0xFFFFFFFFU
|
||||||
|
|
||||||
/* MTP storage type */
|
/* MTP storage type */
|
||||||
#define MTP_STORAGE_UNDEFINED 0U
|
#define MTP_STORAGE_UNDEFINED 0U
|
||||||
#define MTP_STORAGE_FIXED_ROM 0x0001U
|
#define MTP_STORAGE_FIXED_ROM 0x0001U
|
||||||
#define MTP_STORAGE_REMOVABLE_ROM 0x0002U
|
#define MTP_STORAGE_REMOVABLE_ROM 0x0002U
|
||||||
#define MTP_STORAGE_FIXED_RAM 0x0003U
|
#define MTP_STORAGE_FIXED_RAM 0x0003U
|
||||||
#define MTP_STORAGE_REMOVABLE_RAM 0x0004U
|
#define MTP_STORAGE_REMOVABLE_RAM 0x0004U
|
||||||
|
|
||||||
/* MTP file system type */
|
/* MTP file system type */
|
||||||
#define MTP_FILESYSTEM_UNDEFINED 0U
|
#define MTP_FILESYSTEM_UNDEFINED 0U
|
||||||
#define MTP_FILESYSTEM_GENERIC_FLAT 0x0001U
|
#define MTP_FILESYSTEM_GENERIC_FLAT 0x0001U
|
||||||
#define MTP_FILESYSTEM_GENERIC_HIERARCH 0x0002U
|
#define MTP_FILESYSTEM_GENERIC_HIERARCH 0x0002U
|
||||||
#define MTP_FILESYSTEM_DCF 0x0003U
|
#define MTP_FILESYSTEM_DCF 0x0003U
|
||||||
|
|
||||||
/* MTP access capability */
|
/* MTP access capability */
|
||||||
#define MTP_ACCESS_CAP_RW 0U /* read write */
|
#define MTP_ACCESS_CAP_RW 0U /* read write */
|
||||||
#define MTP_ACCESS_CAP_RO_WITHOUT_DEL 0x0001U
|
#define MTP_ACCESS_CAP_RO_WITHOUT_DEL 0x0001U
|
||||||
#define MTP_ACCESS_CAP_RO_WITH_DEL 0x0002U
|
#define MTP_ACCESS_CAP_RO_WITH_DEL 0x0002U
|
||||||
|
|
||||||
/* MTP standard data types supported */
|
/* MTP standard data types supported */
|
||||||
#define MTP_DATATYPE_INT8 0x0001U
|
#define MTP_DATATYPE_INT8 0x0001U
|
||||||
@@ -411,24 +427,31 @@ extern "C" {
|
|||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const uint16_t SuppOP[] = { MTP_OP_GET_DEVICE_INFO, MTP_OP_OPEN_SESSION, MTP_OP_CLOSE_SESSION, MTP_OP_GET_STORAGE_IDS, MTP_OP_GET_STORAGE_INFO,
|
static const uint16_t SuppOP[] = { MTP_OP_GET_DEVICE_INFO, MTP_OP_OPEN_SESSION, MTP_OP_CLOSE_SESSION,
|
||||||
MTP_OP_GET_NUM_OBJECTS, MTP_OP_GET_OBJECT_HANDLES, MTP_OP_GET_OBJECT_INFO, MTP_OP_GET_OBJECT, MTP_OP_DELETE_OBJECT,
|
MTP_OP_GET_STORAGE_IDS, MTP_OP_GET_STORAGE_INFO, MTP_OP_GET_NUM_OBJECTS,
|
||||||
MTP_OP_SEND_OBJECT_INFO, MTP_OP_SEND_OBJECT, MTP_OP_GET_DEVICE_PROP_DESC, MTP_OP_GET_DEVICE_PROP_VALUE,
|
MTP_OP_GET_OBJECT_HANDLES, MTP_OP_GET_OBJECT_INFO, MTP_OP_GET_OBJECT,
|
||||||
MTP_OP_SET_OBJECT_PROP_VALUE, MTP_OP_GET_OBJECT_PROP_VALUE, MTP_OP_GET_OBJECT_PROPS_SUPPORTED, MTP_OP_GET_OBJECT_PROPLIST,
|
MTP_OP_DELETE_OBJECT, MTP_OP_SEND_OBJECT_INFO, MTP_OP_SEND_OBJECT,
|
||||||
|
MTP_OP_GET_DEVICE_PROP_DESC, MTP_OP_GET_DEVICE_PROP_VALUE,
|
||||||
|
MTP_OP_SET_OBJECT_PROP_VALUE, MTP_OP_GET_OBJECT_PROP_VALUE,
|
||||||
|
MTP_OP_GET_OBJECT_PROPS_SUPPORTED, MTP_OP_GET_OBJECT_PROPLIST,
|
||||||
MTP_OP_GET_OBJECT_PROP_DESC, MTP_OP_GET_OBJECT_PROP_REFERENCES
|
MTP_OP_GET_OBJECT_PROP_DESC, MTP_OP_GET_OBJECT_PROP_REFERENCES
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t SuppEvents[] = {MTP_EVENT_OBJECTADDED};
|
static const uint16_t SuppEvents[] = {MTP_EVENT_OBJECTADDED};
|
||||||
static const uint16_t SuppImgFormat[] = {MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_TEXT, MTP_OBJ_FORMAT_ASSOCIATION, MTP_OBJ_FORMAT_EXECUTABLE, MTP_OBJ_FORMAT_WAV,
|
static const uint16_t SuppImgFormat[] = {MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_TEXT, MTP_OBJ_FORMAT_ASSOCIATION,
|
||||||
MTP_OBJ_FORMAT_MP3, MTP_OBJ_FORMAT_EXIF_JPEG, MTP_OBJ_FORMAT_MPEG, MTP_OBJ_FORMAT_MP4_CONTAINER,
|
MTP_OBJ_FORMAT_EXECUTABLE, MTP_OBJ_FORMAT_WAV, MTP_OBJ_FORMAT_MP3,
|
||||||
MTP_OBJ_FORMAT_WINDOWS_IMAGE_FORMAT, MTP_OBJ_FORMAT_PNG, MTP_OBJ_FORMAT_WMA, MTP_OBJ_FORMAT_WMV
|
MTP_OBJ_FORMAT_EXIF_JPEG, MTP_OBJ_FORMAT_MPEG, MTP_OBJ_FORMAT_MP4_CONTAINER,
|
||||||
|
MTP_OBJ_FORMAT_WINDOWS_IMAGE_FORMAT, MTP_OBJ_FORMAT_PNG, MTP_OBJ_FORMAT_WMA,
|
||||||
|
MTP_OBJ_FORMAT_WMV
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t SuppCaptFormat[] = {MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_ASSOCIATION, MTP_OBJ_FORMAT_TEXT};
|
static const uint16_t SuppCaptFormat[] = {MTP_OBJ_FORMAT_UNDEFINED, MTP_OBJ_FORMAT_ASSOCIATION, MTP_OBJ_FORMAT_TEXT};
|
||||||
|
|
||||||
/* required for all object format : storageID, objectFormat, ObjectCompressedSize, persistent unique object identifier, name*/
|
/* required for all object format : storageID, objectFormat, ObjectCompressedSize,
|
||||||
static const uint16_t ObjectPropSupp[] = {MTP_OB_PROP_STORAGE_ID, MTP_OB_PROP_OBJECT_FORMAT, MTP_OB_PROP_OBJECT_SIZE, MTP_OB_PROP_OBJ_FILE_NAME,
|
persistent unique object identifier, name*/
|
||||||
MTP_OB_PROP_PARENT_OBJECT, MTP_OB_PROP_NAME, MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN, MTP_OB_PROP_PROTECTION_STATUS
|
static const uint16_t ObjectPropSupp[] = {MTP_OB_PROP_STORAGE_ID, MTP_OB_PROP_OBJECT_FORMAT, MTP_OB_PROP_OBJECT_SIZE,
|
||||||
|
MTP_OB_PROP_OBJ_FILE_NAME, MTP_OB_PROP_PARENT_OBJECT, MTP_OB_PROP_NAME,
|
||||||
|
MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN, MTP_OB_PROP_PROTECTION_STATUS
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t DevicePropSupp[] = {MTP_DEV_PROP_DEVICE_FRIENDLY_NAME, MTP_DEV_PROP_BATTERY_LEVEL};
|
static const uint16_t DevicePropSupp[] = {MTP_DEV_PROP_DEVICE_FRIENDLY_NAME, MTP_DEV_PROP_BATTERY_LEVEL};
|
||||||
@@ -444,7 +467,7 @@ typedef struct
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint8_t FileName_len;
|
uint8_t FileName_len;
|
||||||
uint16_t FileName[MAX_FILE_NAME];
|
uint16_t FileName[MAX_FILE_NAME];
|
||||||
@@ -461,7 +484,7 @@ typedef struct
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint32_t ObjectPropSupp_len;
|
uint32_t ObjectPropSupp_len;
|
||||||
uint16_t ObjectPropSupp[SUPP_OBJ_PROP_LEN];
|
uint16_t ObjectPropSupp[SUPP_OBJ_PROP_LEN];
|
||||||
@@ -472,7 +495,7 @@ __packed typedef struct
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint16_t StorageType;
|
uint16_t StorageType;
|
||||||
uint16_t FilesystemType;
|
uint16_t FilesystemType;
|
||||||
@@ -501,7 +524,7 @@ typedef union
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint16_t ObjectPropertyCode;
|
uint16_t ObjectPropertyCode;
|
||||||
uint16_t DataType;
|
uint16_t DataType;
|
||||||
@@ -516,7 +539,7 @@ __packed typedef struct
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint32_t ObjectHandle;
|
uint32_t ObjectHandle;
|
||||||
uint16_t PropertyCode;
|
uint16_t PropertyCode;
|
||||||
@@ -528,7 +551,7 @@ __packed typedef struct
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint32_t MTP_Properties_len;
|
uint32_t MTP_Properties_len;
|
||||||
MTP_PropertiesTypedef MTP_Properties[SUPP_OBJ_PROP_LEN];
|
MTP_PropertiesTypedef MTP_Properties[SUPP_OBJ_PROP_LEN];
|
||||||
@@ -539,7 +562,7 @@ __packed typedef struct
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint32_t ref_len;
|
uint32_t ref_len;
|
||||||
uint32_t ref[1];
|
uint32_t ref[1];
|
||||||
@@ -549,7 +572,7 @@ __packed typedef struct
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint16_t DevicePropertyCode;
|
uint16_t DevicePropertyCode;
|
||||||
uint16_t DataType;
|
uint16_t DataType;
|
||||||
@@ -566,7 +589,7 @@ __packed typedef struct
|
|||||||
typedef __PACKED_STRUCT
|
typedef __PACKED_STRUCT
|
||||||
#else
|
#else
|
||||||
__packed typedef struct
|
__packed typedef struct
|
||||||
#endif
|
#endif /* __GNUC__ */
|
||||||
{
|
{
|
||||||
uint16_t StandardVersion;
|
uint16_t StandardVersion;
|
||||||
uint32_t VendorExtensionID;
|
uint32_t VendorExtensionID;
|
||||||
@@ -574,22 +597,22 @@ __packed typedef struct
|
|||||||
uint8_t VendorExtensionDesc_len;
|
uint8_t VendorExtensionDesc_len;
|
||||||
#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1
|
#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1
|
||||||
uint16_t VendorExtensionDesc[VEND_EXT_DESC_LEN];
|
uint16_t VendorExtensionDesc[VEND_EXT_DESC_LEN];
|
||||||
#endif
|
#endif /* USBD_MTP_VEND_EXT_DESC_SUPPORTED */
|
||||||
uint16_t FunctionalMode;
|
uint16_t FunctionalMode;
|
||||||
uint32_t OperationsSupported_len;
|
uint32_t OperationsSupported_len;
|
||||||
uint16_t OperationsSupported[SUPP_OP_LEN];
|
uint16_t OperationsSupported[SUPP_OP_LEN];
|
||||||
uint32_t EventsSupported_len;
|
uint32_t EventsSupported_len;
|
||||||
#if USBD_MTP_EVENTS_SUPPORTED == 1
|
#if USBD_MTP_EVENTS_SUPPORTED == 1
|
||||||
uint16_t EventsSupported[SUPP_EVENTS_LEN];
|
uint16_t EventsSupported[SUPP_EVENTS_LEN];
|
||||||
#endif
|
#endif /* USBD_MTP_EVENTS_SUPPORTED */
|
||||||
uint32_t DevicePropertiesSupported_len;
|
uint32_t DevicePropertiesSupported_len;
|
||||||
#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1
|
#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1
|
||||||
uint16_t DevicePropertiesSupported[SUPP_DEVICE_PROP_LEN];
|
uint16_t DevicePropertiesSupported[SUPP_DEVICE_PROP_LEN];
|
||||||
#endif
|
#endif /* USBD_MTP_DEVICE_PROP_SUPPORTED */
|
||||||
uint32_t CaptureFormats_len;
|
uint32_t CaptureFormats_len;
|
||||||
#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1
|
#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1
|
||||||
uint16_t CaptureFormats[SUPP_CAPT_FORMAT_LEN];
|
uint16_t CaptureFormats[SUPP_CAPT_FORMAT_LEN];
|
||||||
#endif
|
#endif /* USBD_MTP_CAPTURE_FORMAT_SUPPORTED */
|
||||||
uint32_t ImageFormats_len;
|
uint32_t ImageFormats_len;
|
||||||
uint16_t ImageFormats[SUPP_IMG_FORMAT_LEN];
|
uint16_t ImageFormats[SUPP_IMG_FORMAT_LEN];
|
||||||
uint8_t Manufacturer_len;
|
uint8_t Manufacturer_len;
|
||||||
|
|||||||
@@ -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_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_MTP_DataOut(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_GetHSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_MTP_GetFSCfgDesc(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_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_MTP_GetDeviceQualifierDescriptor(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, /*SOF */
|
||||||
NULL, /*ISOIn*/
|
NULL, /*ISOIn*/
|
||||||
NULL, /*ISOOut*/
|
NULL, /*ISOOut*/
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_MTP_GetHSCfgDesc,
|
USBD_MTP_GetHSCfgDesc,
|
||||||
USBD_MTP_GetFSCfgDesc,
|
USBD_MTP_GetFSCfgDesc,
|
||||||
USBD_MTP_GetOtherSpeedCfgDesc,
|
USBD_MTP_GetOtherSpeedCfgDesc,
|
||||||
USBD_MTP_GetDeviceQualifierDescriptor,
|
USBD_MTP_GetDeviceQualifierDescriptor,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
|
|
||||||
/* USB MTP device Configuration Descriptor */
|
/* 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 */
|
/* Configuration Descriptor */
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
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),
|
HIBYTE(MTP_CONFIG_DESC_SIZ),
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
0x00, /* iConfiguration: Index of string descriptor
|
||||||
#if (USBD_SELF_POWERED == 1U)
|
describing the configuration */
|
||||||
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 */
|
|
||||||
#if (USBD_SELF_POWERED == 1U)
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||||
|
|
||||||
/******************** MTP **** interface ********************/
|
/******************** MTP **** interface ********************/
|
||||||
@@ -245,6 +202,11 @@ __ALIGN_BEGIN static uint8_t USBD_MTP_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
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)
|
if (hmtp == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setup the pClassData pointer */
|
/* 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, (uint8_t)pdev->classId);
|
||||||
|
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MTPCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
|
||||||
/* Initialize all variables */
|
/* Initialize all variables */
|
||||||
(void)USBD_memset(hmtp, 0, sizeof(USBD_MTP_HandleTypeDef));
|
(void)USBD_memset(hmtp, 0, sizeof(USBD_MTP_HandleTypeDef));
|
||||||
|
|
||||||
/* Setup the max packet size according to selected speed */
|
/* 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 */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, MTP_IN_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
(void)USBD_LL_OpenEP(pdev, MTPInEpAdd, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||||
pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[MTPInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, MTP_OUT_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
(void)USBD_LL_OpenEP(pdev, MTPOutEpAdd, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||||
pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[MTPOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open INTR EP IN */
|
/* Open INTR EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, MTP_CMD_EP, USBD_EP_TYPE_INTR, MTP_CMD_PACKET_SIZE);
|
(void)USBD_LL_OpenEP(pdev, MTPCmdEpAdd, USBD_EP_TYPE_INTR, MTP_CMD_PACKET_SIZE);
|
||||||
pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[MTPCmdEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Init the MTP layer */
|
/* Init the MTP layer */
|
||||||
(void)USBD_MTP_STORAGE_Init(pdev);
|
(void)USBD_MTP_STORAGE_Init(pdev);
|
||||||
@@ -312,25 +290,33 @@ static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(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, (uint8_t)pdev->classId);
|
||||||
|
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
MTPCmdEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close EP IN */
|
/* Close EP IN */
|
||||||
(void)USBD_LL_CloseEP(pdev, MTP_IN_EP);
|
(void)USBD_LL_CloseEP(pdev, MTPInEpAdd);
|
||||||
pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[MTPInEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP OUT */
|
/* Close EP OUT */
|
||||||
(void)USBD_LL_CloseEP(pdev, MTP_OUT_EP);
|
(void)USBD_LL_CloseEP(pdev, MTPOutEpAdd);
|
||||||
pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 0U;
|
pdev->ep_out[MTPOutEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP Command */
|
/* Close EP Command */
|
||||||
(void)USBD_LL_CloseEP(pdev, MTP_CMD_EP);
|
(void)USBD_LL_CloseEP(pdev, MTPCmdEpAdd);
|
||||||
pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[MTPCmdEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* De-Init the MTP layer */
|
|
||||||
(void)USBD_MTP_STORAGE_DeInit(pdev);
|
|
||||||
|
|
||||||
/* Free MTP Class Resources */
|
/* 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;
|
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)
|
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;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
uint16_t len = 0U;
|
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, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hmtp == NULL)
|
if (hmtp == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
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 */
|
/* Stop low layer file system operations if any */
|
||||||
USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE);
|
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;
|
break;
|
||||||
|
|
||||||
case MTP_REQ_GET_DEVICE_STATUS:
|
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)
|
static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
UNUSED(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;
|
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, (uint8_t)pdev->classId);
|
||||||
|
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (epnum == (MTPInEpAdd & 0x7FU))
|
||||||
{
|
{
|
||||||
switch (hmtp->MTP_ResponsePhase)
|
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 */
|
/* prepare to receive next operation */
|
||||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
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;
|
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MTP_READ_DATA :
|
case MTP_READ_DATA :
|
||||||
(void)USBD_MTP_STORAGE_ReadData(pdev);
|
(void)USBD_MTP_STORAGE_ReadData(pdev);
|
||||||
|
|
||||||
/* prepare to receive next operation */
|
/* prepare to receive next operation */
|
||||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
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;
|
break;
|
||||||
|
|
||||||
case MTP_PHASE_IDLE :
|
case MTP_PHASE_IDLE :
|
||||||
/* prepare to receive next operation */
|
/* prepare to receive next operation */
|
||||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
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;
|
break;
|
||||||
default:
|
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)
|
static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
UNUSED(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;
|
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, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
(void)USBD_MTP_STORAGE_ReceiveOpt(pdev);
|
(void)USBD_MTP_STORAGE_ReceiveOpt(pdev);
|
||||||
|
|
||||||
switch (hmtp->MTP_ResponsePhase)
|
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 */
|
/* prepare endpoint to receive operations */
|
||||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
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;
|
break;
|
||||||
|
|
||||||
case MTP_PHASE_IDLE :
|
case MTP_PHASE_IDLE :
|
||||||
/* prepare to receive next operation */
|
/* prepare to receive next operation */
|
||||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -559,7 +563,7 @@ static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MTP_GetHSCfgDesc
|
* @brief USBD_MTP_GetHSCfgDesc
|
||||||
* Return configuration descriptor
|
* 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)
|
static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_MTP_CfgHSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_IN_EP);
|
||||||
return USBD_MTP_CfgHSDesc;
|
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)
|
static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_IN_EP);
|
||||||
return USBD_MTP_CfgFSDesc;
|
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)
|
static uint8_t *USBD_MTP_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_MTP_CfgDesc, MTP_IN_EP);
|
||||||
return USBD_MTP_CfgFSDesc;
|
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));
|
*length = (uint16_t)(sizeof(USBD_MTP_DeviceQualifierDesc));
|
||||||
return USBD_MTP_DeviceQualifierDesc;
|
return USBD_MTP_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MTP_RegisterInterface
|
* @brief USBD_MTP_RegisterInterface
|
||||||
@@ -624,7 +686,7 @@ uint8_t USBD_MTP_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_MTP_ItfTypeDef
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ static uint32_t MTP_build_data_proplist(USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_CreateObjectHandle(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_CreateObjectHandle(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmtp->OperationsContainer.Param1 == 0U) /* Param1 == Session ID*/
|
if (hmtp->OperationsContainer.Param1 == 0U) /* Param1 == Session ID*/
|
||||||
{
|
{
|
||||||
@@ -104,12 +104,13 @@ void USBD_MTP_OPT_CreateObjectHandle(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetDeviceInfo(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetDeviceInfo(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hmtp->MTP_SessionState == MTP_SESSION_NOT_OPENED) /* no session opened */
|
if (hmtp->MTP_SessionState == MTP_SESSION_NOT_OPENED) /* no session opened */
|
||||||
{
|
{
|
||||||
/* if GetDevice Info called outside a session then SessionID and Transaction_ID shall be 0x00000000*/
|
/* if GetDevice Info called outside a session then SessionID and Transaction_ID shall be 0x00000000*/
|
||||||
if ((hmtp->OperationsContainer.Param1 == 0U) && (hmtp->OperationsContainer.trans_id == 0U)) /* Param1 == session ID*/
|
/* Param1 == session ID*/
|
||||||
|
if ((hmtp->OperationsContainer.Param1 == 0U) && (hmtp->OperationsContainer.trans_id == 0U))
|
||||||
{
|
{
|
||||||
hmtp->ResponseCode = MTP_RESPONSE_OK;
|
hmtp->ResponseCode = MTP_RESPONSE_OK;
|
||||||
}
|
}
|
||||||
@@ -147,7 +148,7 @@ void USBD_MTP_OPT_GetDeviceInfo(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetStorageIDS(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetStorageIDS(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_STORAGE_IDS;
|
hmtp->GenericContainer.code = MTP_OP_GET_STORAGE_IDS;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA;
|
hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA;
|
||||||
@@ -168,7 +169,7 @@ void USBD_MTP_OPT_GetStorageIDS(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetStorageInfo(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetStorageInfo(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_STORAGE_INFO;
|
hmtp->GenericContainer.code = MTP_OP_GET_STORAGE_INFO;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA;
|
hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA;
|
||||||
@@ -189,7 +190,7 @@ void USBD_MTP_OPT_GetStorageInfo(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetObjectHandle(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetObjectHandle(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_HANDLES;
|
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_HANDLES;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA;
|
hmtp->GenericContainer.type = MTP_CONT_TYPE_DATA;
|
||||||
@@ -210,7 +211,7 @@ void USBD_MTP_OPT_GetObjectHandle(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetObjectInfo(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetObjectInfo(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_INFO;
|
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_INFO;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
@@ -232,7 +233,7 @@ void USBD_MTP_OPT_GetObjectInfo(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetObjectReferences(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetObjectReferences(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROP_REFERENCES;
|
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROP_REFERENCES;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
@@ -254,7 +255,7 @@ void USBD_MTP_OPT_GetObjectReferences(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetObjectPropSupp(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetObjectPropSupp(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROPS_SUPPORTED;
|
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROPS_SUPPORTED;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
@@ -276,7 +277,7 @@ void USBD_MTP_OPT_GetObjectPropSupp(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetObjectPropDesc(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetObjectPropDesc(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROP_DESC;
|
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROP_DESC;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
@@ -298,7 +299,7 @@ void USBD_MTP_OPT_GetObjectPropDesc(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetObjectPropList(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetObjectPropList(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROPLIST;
|
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROPLIST;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
@@ -320,7 +321,7 @@ void USBD_MTP_OPT_GetObjectPropList(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetObjectPropValue(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetObjectPropValue(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROP_VALUE;
|
hmtp->GenericContainer.code = MTP_OP_GET_OBJECT_PROP_VALUE;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
@@ -342,8 +343,8 @@ void USBD_MTP_OPT_GetObjectPropValue(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetObject(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetObject(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
|
||||||
hmtp->GenericContainer.length = hmtpif->GetContainerLength(hmtp->OperationsContainer.Param1);
|
hmtp->GenericContainer.length = hmtpif->GetContainerLength(hmtp->OperationsContainer.Param1);
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
@@ -360,7 +361,7 @@ void USBD_MTP_OPT_GetObject(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_GetDevicePropDesc(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_GetDevicePropDesc(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hmtp->GenericContainer.code = MTP_OP_GET_DEVICE_PROP_DESC;
|
hmtp->GenericContainer.code = MTP_OP_GET_DEVICE_PROP_DESC;
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
@@ -382,8 +383,8 @@ void USBD_MTP_OPT_GetDevicePropDesc(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_SendObject(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len)
|
void USBD_MTP_OPT_SendObject(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
static uint32_t tmp = 0U;
|
static uint32_t tmp = 0U;
|
||||||
|
|
||||||
switch (hmtp->RECEIVE_DATA_STATUS)
|
switch (hmtp->RECEIVE_DATA_STATUS)
|
||||||
@@ -443,8 +444,8 @@ void USBD_MTP_OPT_SendObject(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_SendObjectInfo(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len)
|
void USBD_MTP_OPT_SendObjectInfo(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
MTP_ObjectInfoTypeDef ObjectInfo;
|
MTP_ObjectInfoTypeDef ObjectInfo;
|
||||||
uint8_t dataLength = offsetof(MTP_ObjectInfoTypeDef, Filename);
|
uint8_t dataLength = offsetof(MTP_ObjectInfoTypeDef, Filename);
|
||||||
uint8_t *tmp;
|
uint8_t *tmp;
|
||||||
@@ -516,8 +517,8 @@ void USBD_MTP_OPT_SendObjectInfo(USBD_HandleTypeDef *pdev, uint8_t *buff, uint3
|
|||||||
*/
|
*/
|
||||||
void USBD_MTP_OPT_DeleteObject(USBD_HandleTypeDef *pdev)
|
void USBD_MTP_OPT_DeleteObject(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
|
||||||
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
hmtp->GenericContainer.trans_id = hmtp->OperationsContainer.trans_id;
|
||||||
hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE;
|
hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE;
|
||||||
@@ -534,8 +535,8 @@ void USBD_MTP_OPT_DeleteObject(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static void MTP_Get_PayloadContent(USBD_HandleTypeDef *pdev)
|
static void MTP_Get_PayloadContent(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
uint8_t *buffer = hmtp->GenericContainer.data;
|
uint8_t *buffer = hmtp->GenericContainer.data;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t n_idx;
|
uint32_t n_idx;
|
||||||
@@ -744,7 +745,7 @@ static void MTP_Get_DeviceInfo(void)
|
|||||||
*/
|
*/
|
||||||
static void MTP_Get_StorageInfo(USBD_HandleTypeDef *pdev)
|
static void MTP_Get_StorageInfo(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
|
||||||
MTP_StorageInfo.StorageType = MTP_STORAGE_REMOVABLE_RAM;
|
MTP_StorageInfo.StorageType = MTP_STORAGE_REMOVABLE_RAM;
|
||||||
MTP_StorageInfo.FilesystemType = MTP_FILESYSTEM_GENERIC_FLAT;
|
MTP_StorageInfo.FilesystemType = MTP_FILESYSTEM_GENERIC_FLAT;
|
||||||
@@ -764,8 +765,8 @@ static void MTP_Get_StorageInfo(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static void MTP_Get_ObjectHandle(USBD_HandleTypeDef *pdev)
|
static void MTP_Get_ObjectHandle(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
|
||||||
MTP_ObjectHandle.ObjectHandle_len = (uint32_t)(hmtpif->GetIdx(hmtp->OperationsContainer.Param3,
|
MTP_ObjectHandle.ObjectHandle_len = (uint32_t)(hmtpif->GetIdx(hmtp->OperationsContainer.Param3,
|
||||||
MTP_ObjectHandle.ObjectHandle));
|
MTP_ObjectHandle.ObjectHandle));
|
||||||
@@ -799,7 +800,7 @@ static void MTP_Get_ObjectPropSupp(void)
|
|||||||
*/
|
*/
|
||||||
static void MTP_Get_ObjectPropDesc(USBD_HandleTypeDef *pdev)
|
static void MTP_Get_ObjectPropDesc(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint16_t undef_format = MTP_OBJ_FORMAT_UNDEFINED;
|
uint16_t undef_format = MTP_OBJ_FORMAT_UNDEFINED;
|
||||||
uint32_t storageid = MTP_STORAGE_ID;
|
uint32_t storageid = MTP_STORAGE_ID;
|
||||||
|
|
||||||
@@ -896,8 +897,8 @@ static void MTP_Get_ObjectPropDesc(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *MTP_Get_ObjectPropValue(USBD_HandleTypeDef *pdev)
|
static uint8_t *MTP_Get_ObjectPropValue(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
static uint8_t buf[512];
|
static uint8_t buf[512];
|
||||||
|
|
||||||
/* Add all other supported object properties */
|
/* Add all other supported object properties */
|
||||||
@@ -950,8 +951,8 @@ static uint8_t *MTP_Get_ObjectPropValue(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static void MTP_Get_ObjectPropList(USBD_HandleTypeDef *pdev)
|
static void MTP_Get_ObjectPropList(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
uint16_t filename[255];
|
uint16_t filename[255];
|
||||||
uint32_t storageid = MTP_STORAGE_ID;
|
uint32_t storageid = MTP_STORAGE_ID;
|
||||||
uint32_t default_val = 0U;
|
uint32_t default_val = 0U;
|
||||||
@@ -990,7 +991,7 @@ static void MTP_Get_ObjectPropList(USBD_HandleTypeDef *pdev)
|
|||||||
/* MTP_FileName.FileName_len value shall be set before USBD_MTP_FS_GetObjectName */
|
/* MTP_FileName.FileName_len value shall be set before USBD_MTP_FS_GetObjectName */
|
||||||
MTP_FileName.FileName_len = hmtpif->GetObjectName_len(hmtp->OperationsContainer.Param1);
|
MTP_FileName.FileName_len = hmtpif->GetObjectName_len(hmtp->OperationsContainer.Param1);
|
||||||
hmtpif->GetObjectName(hmtp->OperationsContainer.Param1, MTP_FileName.FileName_len, filename);
|
hmtpif->GetObjectName(hmtp->OperationsContainer.Param1, MTP_FileName.FileName_len, filename);
|
||||||
(void)USBD_memcpy(MTP_FileName.FileName, filename, ((uint32_t)MTP_FileName.FileName_len * 2U) + 1U );
|
(void)USBD_memcpy(MTP_FileName.FileName, filename, ((uint32_t)MTP_FileName.FileName_len * 2U) + 1U);
|
||||||
MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&MTP_FileName;
|
MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&MTP_FileName;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1014,7 +1015,7 @@ static void MTP_Get_ObjectPropList(USBD_HandleTypeDef *pdev)
|
|||||||
/* MTP_FileName.FileName_len value shall be set before USBD_MTP_FS_GetObjectName */
|
/* MTP_FileName.FileName_len value shall be set before USBD_MTP_FS_GetObjectName */
|
||||||
MTP_FileName.FileName_len = hmtpif->GetObjectName_len(hmtp->OperationsContainer.Param1);
|
MTP_FileName.FileName_len = hmtpif->GetObjectName_len(hmtp->OperationsContainer.Param1);
|
||||||
hmtpif->GetObjectName(hmtp->OperationsContainer.Param1, MTP_FileName.FileName_len, filename);
|
hmtpif->GetObjectName(hmtp->OperationsContainer.Param1, MTP_FileName.FileName_len, filename);
|
||||||
(void)USBD_memcpy(MTP_FileName.FileName, filename, ((uint32_t)MTP_FileName.FileName_len * 2U) + 1U );
|
(void)USBD_memcpy(MTP_FileName.FileName, filename, ((uint32_t)MTP_FileName.FileName_len * 2U) + 1U);
|
||||||
MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&MTP_FileName;
|
MTP_PropertiesList.MTP_Properties[i].propval = (uint8_t *)&MTP_FileName;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1075,8 +1076,8 @@ static void MTP_Get_DevicePropDesc(void)
|
|||||||
*/
|
*/
|
||||||
static void MTP_Get_ObjectInfo(USBD_HandleTypeDef *pdev)
|
static void MTP_Get_ObjectInfo(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData;
|
USBD_MTP_ItfTypeDef *hmtpif = (USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint16_t filename[255];
|
uint16_t filename[255];
|
||||||
|
|
||||||
MTP_ObjectInfo.Storage_id = MTP_STORAGE_ID;
|
MTP_ObjectInfo.Storage_id = MTP_STORAGE_ID;
|
||||||
@@ -1126,7 +1127,7 @@ static void MTP_Get_StorageIDS(void)
|
|||||||
*/
|
*/
|
||||||
static uint32_t MTP_build_data_propdesc(USBD_HandleTypeDef *pdev, MTP_ObjectPropDescTypeDef def)
|
static uint32_t MTP_build_data_propdesc(USBD_HandleTypeDef *pdev, MTP_ObjectPropDescTypeDef def)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t DefValue_size = (MTP_FileName.FileName_len * 2U) + 1U;
|
uint8_t DefValue_size = (MTP_FileName.FileName_len * 2U) + 1U;
|
||||||
uint32_t dataLength = offsetof(MTP_ObjectPropDescTypeDef, DefValue);
|
uint32_t dataLength = offsetof(MTP_ObjectPropDescTypeDef, DefValue);
|
||||||
|
|
||||||
@@ -1185,7 +1186,7 @@ static uint32_t MTP_build_data_propdesc(USBD_HandleTypeDef *pdev, MTP_ObjectPro
|
|||||||
static uint32_t MTP_build_data_proplist(USBD_HandleTypeDef *pdev,
|
static uint32_t MTP_build_data_proplist(USBD_HandleTypeDef *pdev,
|
||||||
MTP_PropertiesListTypedef proplist, uint32_t idx)
|
MTP_PropertiesListTypedef proplist, uint32_t idx)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t propval_size = (MTP_FileName.FileName_len * 2U) + 1U;
|
uint8_t propval_size = (MTP_FileName.FileName_len * 2U) + 1U;
|
||||||
uint32_t dataLength;
|
uint32_t dataLength;
|
||||||
|
|
||||||
@@ -1248,7 +1249,7 @@ static uint32_t MTP_build_data_proplist(USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
static uint32_t MTP_build_data_ObjInfo(USBD_HandleTypeDef *pdev, MTP_ObjectInfoTypeDef objinfo)
|
static uint32_t MTP_build_data_ObjInfo(USBD_HandleTypeDef *pdev, MTP_ObjectInfoTypeDef objinfo)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t ObjInfo_len = offsetof(MTP_ObjectInfoTypeDef, Filename);
|
uint32_t ObjInfo_len = offsetof(MTP_ObjectInfoTypeDef, Filename);
|
||||||
|
|
||||||
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&objinfo, ObjInfo_len);
|
(void)USBD_memcpy(hmtp->GenericContainer.data, (const uint8_t *)&objinfo, ObjInfo_len);
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
/* Private macro -------------------------------------------------------------*/
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
extern uint8_t MTPInEpAdd;
|
||||||
|
extern uint8_t MTPOutEpAdd;
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
static MTP_DataLengthTypeDef MTP_DataLength;
|
static MTP_DataLengthTypeDef MTP_DataLength;
|
||||||
static MTP_READ_DATA_STATUS ReadDataStatus;
|
static MTP_READ_DATA_STATUS ReadDataStatus;
|
||||||
@@ -44,13 +47,17 @@ static uint8_t USBD_MTP_STORAGE_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_MTP_STORAGE_Init(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_MTP_STORAGE_Init(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Initialize the HW layyer of the file system */
|
/* Initialize the HW layyer of the file system */
|
||||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Init();
|
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||||
|
|
||||||
/* Prepare EP to Receive First Operation */
|
/* Prepare EP to Receive First Operation */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff,
|
(void)USBD_LL_PrepareReceive(pdev, MTPOutEpAdd, (uint8_t *)&hmtp->rx_buff,
|
||||||
hmtp->MaxPcktLen);
|
hmtp->MaxPcktLen);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
@@ -64,7 +71,7 @@ uint8_t USBD_MTP_STORAGE_Init(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
hmtp->MTP_SessionState = MTP_SESSION_NOT_OPENED;
|
hmtp->MTP_SessionState = MTP_SESSION_NOT_OPENED;
|
||||||
@@ -73,7 +80,7 @@ uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev)
|
|||||||
USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE);
|
USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE);
|
||||||
|
|
||||||
/* Free low layer file system resources */
|
/* Free low layer file system resources */
|
||||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->DeInit();
|
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -86,11 +93,20 @@ uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t *data_buff;
|
uint32_t *data_buff;
|
||||||
|
uint32_t buffer_size;
|
||||||
|
|
||||||
/* Get the data buffer pointer from the low layer interface */
|
/* Get the data buffer pointer from the low layer interface */
|
||||||
data_buff = ((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ScratchBuff;
|
data_buff = ((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->ScratchBuff;
|
||||||
|
|
||||||
|
/* Get Data Buffer Size */
|
||||||
|
buffer_size = ((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->ScratchBuffSze;
|
||||||
|
|
||||||
|
if ((data_buff == NULL) || (buffer_size < MTP_CONT_HEADER_SIZE))
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
switch (ReadDataStatus)
|
switch (ReadDataStatus)
|
||||||
{
|
{
|
||||||
@@ -98,16 +114,19 @@ uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev)
|
|||||||
/* Reset the data length */
|
/* Reset the data length */
|
||||||
MTP_DataLength.temp_length = 0U;
|
MTP_DataLength.temp_length = 0U;
|
||||||
|
|
||||||
/* Perform the low layer read operation on the scratch buffer */
|
|
||||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ReadData(hmtp->OperationsContainer.Param1,
|
|
||||||
(uint8_t *)data_buff, &MTP_DataLength);
|
|
||||||
|
|
||||||
/* Add the container header to the data buffer */
|
/* Add the container header to the data buffer */
|
||||||
(void)USBD_memcpy((uint8_t *)data_buff, (uint8_t *)&hmtp->GenericContainer, MTP_CONT_HEADER_SIZE);
|
(void)USBD_memcpy((uint8_t *)data_buff, (uint8_t *)&hmtp->GenericContainer, MTP_CONT_HEADER_SIZE);
|
||||||
|
|
||||||
|
/* Perform the low layer read operation on the scratch buffer
|
||||||
|
* first packet expected data length: MPS - MTP_CONT_HEADER_SIZE
|
||||||
|
*/
|
||||||
|
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->ReadData(hmtp->OperationsContainer.Param1,
|
||||||
|
(uint8_t *)data_buff +
|
||||||
|
MTP_CONT_HEADER_SIZE, &MTP_DataLength);
|
||||||
|
|
||||||
/* Start USB data transmission to the host */
|
/* Start USB data transmission to the host */
|
||||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff,
|
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff,
|
||||||
MTP_DataLength.readbytes + MTP_CONT_HEADER_SIZE);
|
MIN((MTP_DataLength.readbytes + MTP_CONT_HEADER_SIZE), buffer_size));
|
||||||
|
|
||||||
/* Check if this will be the last packet to send ? */
|
/* Check if this will be the last packet to send ? */
|
||||||
if (MTP_DataLength.readbytes < ((uint32_t)hmtp->MaxPcktLen - MTP_CONT_HEADER_SIZE))
|
if (MTP_DataLength.readbytes < ((uint32_t)hmtp->MaxPcktLen - MTP_CONT_HEADER_SIZE))
|
||||||
@@ -124,25 +143,25 @@ uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev)
|
|||||||
|
|
||||||
case READ_REST_OF_DATA:
|
case READ_REST_OF_DATA:
|
||||||
/* Perform the low layer read operation on the scratch buffer */
|
/* Perform the low layer read operation on the scratch buffer */
|
||||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ReadData(hmtp->OperationsContainer.Param1,
|
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->ReadData(hmtp->OperationsContainer.Param1,
|
||||||
(uint8_t *)data_buff, &MTP_DataLength);
|
(uint8_t *)data_buff, &MTP_DataLength);
|
||||||
|
|
||||||
/* Check if more data need to be sent */
|
/* Check if more data need to be sent */
|
||||||
if (MTP_DataLength.temp_length == MTP_DataLength.totallen)
|
if (MTP_DataLength.temp_length == MTP_DataLength.totallen)
|
||||||
{
|
{
|
||||||
/* Start USB data transmission to the host */
|
/* Start USB data transmission to the host */
|
||||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MTP_DataLength.readbytes);
|
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MIN(MTP_DataLength.readbytes, buffer_size));
|
||||||
|
|
||||||
/* Move to response phase */
|
/* Move to response phase */
|
||||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||||
|
|
||||||
/* Reset the stat machine */
|
/* Reset the state machine */
|
||||||
ReadDataStatus = READ_FIRST_DATA;
|
ReadDataStatus = READ_FIRST_DATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Start USB data transmission to the host */
|
/* Start USB data transmission to the host */
|
||||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MTP_DataLength.readbytes);
|
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MIN(MTP_DataLength.readbytes, buffer_size));
|
||||||
|
|
||||||
/* Keep the state machine into sending next packet of data */
|
/* Keep the state machine into sending next packet of data */
|
||||||
ReadDataStatus = READ_REST_OF_DATA;
|
ReadDataStatus = READ_REST_OF_DATA;
|
||||||
@@ -164,12 +183,13 @@ uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_MTP_STORAGE_SendContainer(USBD_HandleTypeDef *pdev, MTP_CONTAINER_TYPE CONT_TYPE)
|
uint8_t USBD_MTP_STORAGE_SendContainer(USBD_HandleTypeDef *pdev, MTP_CONTAINER_TYPE CONT_TYPE)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
switch (CONT_TYPE)
|
switch (CONT_TYPE)
|
||||||
{
|
{
|
||||||
case DATA_TYPE:
|
case DATA_TYPE:
|
||||||
/* send header + data : hmtp->ResponseLength = header size + data size */
|
/* send header + data : hmtp->ResponseLength = header size + data size */
|
||||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, hmtp->ResponseLength);
|
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, MIN(sizeof(MTP_GenericContainerTypeDef),
|
||||||
|
hmtp->ResponseLength));
|
||||||
break;
|
break;
|
||||||
case REP_TYPE:
|
case REP_TYPE:
|
||||||
/* send header without data */
|
/* send header without data */
|
||||||
@@ -178,7 +198,8 @@ uint8_t USBD_MTP_STORAGE_SendContainer(USBD_HandleTypeDef *pdev, MTP_CONTAINER_
|
|||||||
hmtp->GenericContainer.length = hmtp->ResponseLength;
|
hmtp->GenericContainer.length = hmtp->ResponseLength;
|
||||||
hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE;
|
hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE;
|
||||||
|
|
||||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, hmtp->ResponseLength);
|
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, MIN(sizeof(MTP_GenericContainerTypeDef),
|
||||||
|
hmtp->ResponseLength));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -194,9 +215,14 @@ uint8_t USBD_MTP_STORAGE_SendContainer(USBD_HandleTypeDef *pdev, MTP_CONTAINER_
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_MTP_STORAGE_ReceiveOpt(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_MTP_STORAGE_ReceiveOpt(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t *pMsgBuffer;
|
uint32_t *pMsgBuffer;
|
||||||
MTP_DataLength.rx_length = USBD_GetRxCount(pdev, MTP_OUT_EP);
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MTPOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
MTP_DataLength.rx_length = USBD_GetRxCount(pdev, MTPOutEpAdd);
|
||||||
|
|
||||||
switch (hmtp->RECEIVE_DATA_STATUS)
|
switch (hmtp->RECEIVE_DATA_STATUS)
|
||||||
{
|
{
|
||||||
case RECEIVE_REST_OF_DATA:
|
case RECEIVE_REST_OF_DATA:
|
||||||
@@ -233,7 +259,7 @@ uint8_t USBD_MTP_STORAGE_ReceiveOpt(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_MTP_STORAGE_ReceiveData(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_MTP_STORAGE_ReceiveData(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
switch (hmtp->RECEIVE_DATA_STATUS)
|
switch (hmtp->RECEIVE_DATA_STATUS)
|
||||||
{
|
{
|
||||||
case RECEIVE_COMMAND_DATA :
|
case RECEIVE_COMMAND_DATA :
|
||||||
@@ -297,7 +323,7 @@ uint8_t USBD_MTP_STORAGE_ReceiveData(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_MTP_STORAGE_DecodeOperations(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_MTP_STORAGE_DecodeOperations(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
switch (hmtp->OperationsContainer.code)
|
switch (hmtp->OperationsContainer.code)
|
||||||
{
|
{
|
||||||
case MTP_OP_GET_DEVICE_INFO:
|
case MTP_OP_GET_DEVICE_INFO:
|
||||||
@@ -398,15 +424,21 @@ static uint8_t USBD_MTP_STORAGE_DecodeOperations(USBD_HandleTypeDef *pdev)
|
|||||||
static uint8_t USBD_MTP_STORAGE_ReceiveContainer(USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_MTP_STORAGE_ReceiveContainer(USBD_HandleTypeDef *pdev,
|
||||||
uint32_t *pDst, uint32_t len)
|
uint32_t *pDst, uint32_t len)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint32_t Counter;
|
uint32_t Counter;
|
||||||
uint32_t *pdst = pDst;
|
uint32_t *pdst = pDst;
|
||||||
|
|
||||||
for (Counter = 0; Counter < len; Counter++)
|
if ((pDst == NULL) || (len > MTP_MEDIA_PACKET))
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Counter = 0U; Counter < len; Counter++)
|
||||||
{
|
{
|
||||||
*pdst = (hmtp->rx_buff[Counter]);
|
*pdst = (hmtp->rx_buff[Counter]);
|
||||||
pdst++;
|
pdst++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,7 +452,7 @@ static uint8_t USBD_MTP_STORAGE_ReceiveContainer(USBD_HandleTypeDef *pdev,
|
|||||||
void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev,
|
void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev,
|
||||||
MTP_ResponsePhaseTypeDef MTP_ResponsePhase)
|
MTP_ResponsePhaseTypeDef MTP_ResponsePhase)
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
|
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
|
||||||
ReadDataStatus = READ_FIRST_DATA;
|
ReadDataStatus = READ_FIRST_DATA;
|
||||||
@@ -428,11 +460,11 @@ void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev,
|
|||||||
|
|
||||||
if (MTP_ResponsePhase == MTP_RECEIVE_DATA)
|
if (MTP_ResponsePhase == MTP_RECEIVE_DATA)
|
||||||
{
|
{
|
||||||
((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Cancel(1U);
|
((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->Cancel(1U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Cancel(0U);
|
((USBD_MTP_ItfTypeDef *)pdev->pUserData[pdev->classId])->Cancel(0U);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,13 +476,14 @@ void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev,
|
|||||||
* @param len: Data Length
|
* @param len: Data Length
|
||||||
* @retval status value
|
* @retval status value
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_MTP_STORAGE_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf,
|
static uint8_t USBD_MTP_STORAGE_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf, uint32_t len)
|
||||||
uint32_t len)
|
|
||||||
{
|
{
|
||||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
#ifdef USE_USBD_COMPOSITE
|
||||||
uint32_t length = MIN(hmtp->GenericContainer.length, len);
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
MTPInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
(void)USBD_LL_Transmit(pdev, MTP_IN_EP, buf, length);
|
(void)USBD_LL_Transmit(pdev, MTPInEpAdd, buf, len);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,8 +113,7 @@ typedef struct
|
|||||||
|
|
||||||
__IO uint32_t TxState;
|
__IO uint32_t TxState;
|
||||||
__IO uint32_t RxState;
|
__IO uint32_t RxState;
|
||||||
}
|
} USBD_PRNT_HandleTypeDef;
|
||||||
USBD_PRNT_HandleTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -102,27 +102,13 @@ static uint8_t USBD_PRNT_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
|||||||
static uint8_t USBD_PRNT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_PRNT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_PRNT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_PRNT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_PRNT_GetFSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_PRNT_GetFSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_PRNT_GetHSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_PRNT_GetHSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_PRNT_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_PRNT_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_PRNT_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_PRNT_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
uint8_t *USBD_PRNT_GetDeviceQualifierDescriptor(uint16_t *length);
|
uint8_t *USBD_PRNT_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
/* USB Standard Device Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_PRNT_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
|
||||||
{
|
|
||||||
USB_LEN_DEV_QUALIFIER_DESC,
|
|
||||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
|
||||||
0x00,
|
|
||||||
0x02,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x40,
|
|
||||||
0x01,
|
|
||||||
0x00,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -144,14 +130,22 @@ USBD_ClassTypeDef USBD_PRNT =
|
|||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_PRNT_GetHSCfgDesc,
|
USBD_PRNT_GetHSCfgDesc,
|
||||||
USBD_PRNT_GetFSCfgDesc,
|
USBD_PRNT_GetFSCfgDesc,
|
||||||
USBD_PRNT_GetOtherSpeedCfgDesc,
|
USBD_PRNT_GetOtherSpeedCfgDesc,
|
||||||
USBD_PRNT_GetDeviceQualifierDescriptor,
|
USBD_PRNT_GetDeviceQualifierDescriptor,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB PRNT device Configuration Descriptor */
|
/* USB PRNT device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_PRNT_CfgHSDesc[] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_PRNT_CfgDesc[] __ALIGN_END =
|
||||||
{
|
{
|
||||||
/*Configuration Descriptor*/
|
/*Configuration Descriptor*/
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
@@ -165,56 +159,7 @@ __ALIGN_BEGIN static uint8_t USBD_PRNT_CfgHSDesc[] __ALIGN_END =
|
|||||||
0xC0, /* bmAttributes: Self Powered according to user configuration */
|
0xC0, /* bmAttributes: Self Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* MaxPower in mA */
|
|
||||||
|
|
||||||
/* Interface Descriptor */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints: 2 endpoints used */
|
|
||||||
0x07, /* bInterfaceClass: Communication Interface Class */
|
|
||||||
0x01, /* bInterfaceSubClass: Abstract Control Model */
|
|
||||||
USB_PRNT_BIDIRECTIONAL, /* bDeviceProtocol */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/* Endpoint IN Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
PRNT_IN_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(PRNT_DATA_HS_IN_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(PRNT_DATA_HS_IN_PACKET_SIZE),
|
|
||||||
0x00, /* bInterval */
|
|
||||||
|
|
||||||
/* Endpoint OUT Descriptor */
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
PRNT_OUT_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(PRNT_DATA_HS_OUT_PACKET_SIZE),/* wMaxPacketSize */
|
|
||||||
HIBYTE(PRNT_DATA_HS_OUT_PACKET_SIZE),
|
|
||||||
0x00 /* bInterval */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* USB PRNT device Configuration Descriptor */
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_PRNT_CfgFSDesc[] __ALIGN_END =
|
|
||||||
{
|
|
||||||
/*Configuration Descriptor*/
|
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
|
||||||
USB_PRNT_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
|
||||||
0x00,
|
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
|
||||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
|
||||||
#if (USBD_SELF_POWERED == 1U)
|
|
||||||
0xC0, /* bmAttributes: Self Powered according to user configuration */
|
|
||||||
#else
|
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
|
||||||
#endif
|
|
||||||
USBD_MAX_POWER, /* MaxPower in mA */
|
USBD_MAX_POWER, /* MaxPower in mA */
|
||||||
|
|
||||||
/*Interface Descriptor */
|
/*Interface Descriptor */
|
||||||
@@ -247,52 +192,24 @@ __ALIGN_BEGIN static uint8_t USBD_PRNT_CfgFSDesc[] __ALIGN_END =
|
|||||||
0x00 /* bInterval */
|
0x00 /* bInterval */
|
||||||
};
|
};
|
||||||
|
|
||||||
__ALIGN_BEGIN static uint8_t USBD_PRNT_OtherSpeedCfgDesc[] __ALIGN_END =
|
/* USB Standard Device Descriptor */
|
||||||
|
__ALIGN_BEGIN static uint8_t USBD_PRNT_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
/*Configuration Descriptor*/
|
USB_LEN_DEV_QUALIFIER_DESC,
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
0x00,
|
||||||
USB_PRNT_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
0x02,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x40,
|
||||||
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
0x01, /* bNumInterfaces: 1 interface */
|
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
|
||||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
|
||||||
#if (USBD_SELF_POWERED == 1U)
|
|
||||||
0xC0, /* bmAttributes: Self Powered according to user configuration */
|
|
||||||
#else
|
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
|
||||||
#endif
|
|
||||||
USBD_MAX_POWER, /* MaxPower in mA */
|
|
||||||
|
|
||||||
/*Interface Descriptor */
|
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
|
||||||
0x02, /* bNumEndpoints: 2 endpoints used */
|
|
||||||
0x07, /* bInterfaceClass: Communication Interface Class */
|
|
||||||
0x01, /* bInterfaceSubClass: Abstract Control Model */
|
|
||||||
USB_PRNT_BIDIRECTIONAL, /* bDeviceProtocol */
|
|
||||||
0x00, /* iInterface */
|
|
||||||
|
|
||||||
/*Endpoint IN Descriptor*/
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
PRNT_IN_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(PRNT_DATA_FS_IN_PACKET_SIZE), /* wMaxPacketSize */
|
|
||||||
HIBYTE(PRNT_DATA_FS_IN_PACKET_SIZE),
|
|
||||||
0x00, /* bInterval */
|
|
||||||
|
|
||||||
/*Endpoint OUT Descriptor*/
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
|
||||||
PRNT_OUT_EP, /* bEndpointAddress */
|
|
||||||
0x02, /* bmAttributes: Bulk */
|
|
||||||
LOBYTE(PRNT_DATA_FS_OUT_PACKET_SIZE),/* wMaxPacketSize */
|
|
||||||
HIBYTE(PRNT_DATA_FS_OUT_PACKET_SIZE),
|
|
||||||
0x00 /* bInterval */
|
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
static uint8_t PRNTInEpAdd = PRNT_IN_EP;
|
||||||
|
static uint8_t PRNTOutEpAdd = PRNT_OUT_EP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -315,16 +232,26 @@ static uint8_t USBD_PRNT_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
|
|
||||||
USBD_PRNT_HandleTypeDef *hPRNT;
|
USBD_PRNT_HandleTypeDef *hPRNT;
|
||||||
uint16_t mps;
|
uint16_t mps;
|
||||||
|
|
||||||
hPRNT = (USBD_PRNT_HandleTypeDef *)USBD_malloc(sizeof(USBD_PRNT_HandleTypeDef));
|
hPRNT = (USBD_PRNT_HandleTypeDef *)USBD_malloc(sizeof(USBD_PRNT_HandleTypeDef));
|
||||||
|
|
||||||
if (hPRNT == NULL)
|
if (hPRNT == NULL)
|
||||||
{
|
{
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
return (uint8_t)USBD_EMEM;
|
return (uint8_t)USBD_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(void)USBD_memset(hPRNT, 0, sizeof(USBD_PRNT_HandleTypeDef));
|
||||||
|
|
||||||
/* Setup the pClassData pointer */
|
/* Setup the pClassData pointer */
|
||||||
pdev->pClassData = (void *)hPRNT;
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hPRNT;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
PRNTInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
PRNTOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Setup the max packet size according to selected speed */
|
/* Setup the max packet size according to selected speed */
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
@@ -337,22 +264,29 @@ static uint8_t USBD_PRNT_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
(void)USBD_LL_OpenEP(pdev, PRNT_IN_EP, USBD_EP_TYPE_BULK, mps);
|
(void)USBD_LL_OpenEP(pdev, PRNTInEpAdd, USBD_EP_TYPE_BULK, mps);
|
||||||
|
|
||||||
/* Set endpoint as used */
|
/* Set endpoint as used */
|
||||||
pdev->ep_in[PRNT_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[PRNTInEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
(void)USBD_LL_OpenEP(pdev, PRNT_OUT_EP, USBD_EP_TYPE_BULK, mps);
|
(void)USBD_LL_OpenEP(pdev, PRNTOutEpAdd, USBD_EP_TYPE_BULK, mps);
|
||||||
|
|
||||||
/* Set endpoint as used */
|
/* Set endpoint as used */
|
||||||
pdev->ep_out[PRNT_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[PRNTOutEpAdd & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
hPRNT->RxBuffer = NULL;
|
||||||
|
|
||||||
/* Init physical Interface components */
|
/* Init physical Interface components */
|
||||||
((USBD_PRNT_ItfTypeDef *)pdev->pUserData)->Init();
|
((USBD_PRNT_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||||
|
|
||||||
|
if (hPRNT->RxBuffer == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, PRNT_OUT_EP, hPRNT->RxBuffer, mps);
|
(void)USBD_LL_PrepareReceive(pdev, PRNTOutEpAdd, hPRNT->RxBuffer, mps);
|
||||||
|
|
||||||
/* End of initialization phase */
|
/* End of initialization phase */
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
@@ -369,19 +303,26 @@ static uint8_t USBD_PRNT_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
PRNTInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
PRNTOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close EP IN */
|
/* Close EP IN */
|
||||||
(void)USBD_LL_CloseEP(pdev, PRNT_IN_EP);
|
(void)USBD_LL_CloseEP(pdev, PRNTInEpAdd);
|
||||||
pdev->ep_in[PRNT_IN_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[PRNTInEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP OUT */
|
/* Close EP OUT */
|
||||||
(void)USBD_LL_CloseEP(pdev, PRNT_OUT_EP);
|
(void)USBD_LL_CloseEP(pdev, PRNTOutEpAdd);
|
||||||
pdev->ep_out[PRNT_OUT_EP & 0xFU].is_used = 0U;
|
pdev->ep_out[PRNTOutEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if (pdev->pClassData != NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||||
{
|
{
|
||||||
((USBD_PRNT_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_PRNT_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
(void)USBD_free(pdev->pClassData);
|
(void)USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,8 +338,8 @@ static uint8_t USBD_PRNT_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_PRNT_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static uint8_t USBD_PRNT_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassData;
|
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
USBD_PRNT_ItfTypeDef *hPRNTitf = (USBD_PRNT_ItfTypeDef *)pdev->pUserData;
|
USBD_PRNT_ItfTypeDef *hPRNTitf = (USBD_PRNT_ItfTypeDef *)pdev->pUserData[pdev->classId];
|
||||||
|
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
@@ -495,7 +436,7 @@ static uint8_t USBD_PRNT_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_PRNT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_PRNT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassData;
|
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
PCD_HandleTypeDef *hpcd = pdev->pData;
|
PCD_HandleTypeDef *hpcd = pdev->pData;
|
||||||
|
|
||||||
if (hPRNT == NULL)
|
if (hPRNT == NULL)
|
||||||
@@ -503,11 +444,11 @@ static uint8_t USBD_PRNT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pdev->ep_in[epnum].total_length > 0U) &&
|
if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
|
||||||
((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
|
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U))
|
||||||
{
|
{
|
||||||
/* Update the packet total length */
|
/* Update the packet total length */
|
||||||
pdev->ep_in[epnum].total_length = 0U;
|
pdev->ep_in[epnum & 0xFU].total_length = 0U;
|
||||||
|
|
||||||
/* Send ZLP */
|
/* Send ZLP */
|
||||||
(void) USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
(void) USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||||
@@ -528,7 +469,7 @@ static uint8_t USBD_PRNT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_PRNT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_PRNT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassData;
|
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
if (hPRNT == NULL)
|
if (hPRNT == NULL)
|
||||||
{
|
{
|
||||||
@@ -540,11 +481,12 @@ static uint8_t USBD_PRNT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
|
|
||||||
/* USB data will be immediately processed, this allow next USB traffic being
|
/* USB data will be immediately processed, this allow next USB traffic being
|
||||||
NAKed till the end of the application Xfer */
|
NAKed till the end of the application Xfer */
|
||||||
((USBD_PRNT_ItfTypeDef *)pdev->pUserData)->Receive(hPRNT->RxBuffer, &hPRNT->RxLength);
|
((USBD_PRNT_ItfTypeDef *)pdev->pUserData[pdev->classId])->Receive(hPRNT->RxBuffer, &hPRNT->RxLength);
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_PRNT_GetFSCfgDesc
|
* @brief USBD_PRNT_GetFSCfgDesc
|
||||||
* Return configuration descriptor
|
* Return configuration descriptor
|
||||||
@@ -553,8 +495,21 @@ static uint8_t USBD_PRNT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_PRNT_GetFSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_PRNT_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t) sizeof(USBD_PRNT_CfgFSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_PRNT_CfgDesc, PRNT_IN_EP);
|
||||||
return USBD_PRNT_CfgFSDesc;
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_PRNT_CfgDesc, PRNT_OUT_EP);
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = PRNT_DATA_FS_IN_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = PRNT_DATA_FS_OUT_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t) sizeof(USBD_PRNT_CfgDesc);
|
||||||
|
return USBD_PRNT_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -565,8 +520,21 @@ static uint8_t *USBD_PRNT_GetFSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_PRNT_GetHSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_PRNT_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t) sizeof(USBD_PRNT_CfgHSDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_PRNT_CfgDesc, PRNT_IN_EP);
|
||||||
return USBD_PRNT_CfgHSDesc;
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_PRNT_CfgDesc, PRNT_OUT_EP);
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = PRNT_DATA_HS_IN_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = PRNT_DATA_HS_OUT_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t) sizeof(USBD_PRNT_CfgDesc);
|
||||||
|
return USBD_PRNT_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -577,8 +545,21 @@ static uint8_t *USBD_PRNT_GetHSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_PRNT_GetOtherSpeedCfgDesc(uint16_t *length)
|
static uint8_t *USBD_PRNT_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t) sizeof(USBD_PRNT_OtherSpeedCfgDesc);
|
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_PRNT_CfgDesc, PRNT_IN_EP);
|
||||||
return USBD_PRNT_OtherSpeedCfgDesc;
|
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_PRNT_CfgDesc, PRNT_OUT_EP);
|
||||||
|
|
||||||
|
if (pEpInDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpInDesc->wMaxPacketSize = PRNT_DATA_FS_IN_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pEpOutDesc != NULL)
|
||||||
|
{
|
||||||
|
pEpOutDesc->wMaxPacketSize = PRNT_DATA_FS_OUT_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*length = (uint16_t) sizeof(USBD_PRNT_CfgDesc);
|
||||||
|
return USBD_PRNT_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -592,6 +573,7 @@ uint8_t *USBD_PRNT_GetDeviceQualifierDescriptor(uint16_t *length)
|
|||||||
*length = (uint16_t)sizeof(USBD_PRNT_DeviceQualifierDesc);
|
*length = (uint16_t)sizeof(USBD_PRNT_DeviceQualifierDesc);
|
||||||
return USBD_PRNT_DeviceQualifierDesc;
|
return USBD_PRNT_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_PRNT_RegisterInterface
|
* @brief USBD_PRNT_RegisterInterface
|
||||||
@@ -608,7 +590,7 @@ uint8_t USBD_PRNT_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_PRNT_ItfTypeD
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Setup the fops pointer */
|
/* Setup the fops pointer */
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -621,7 +603,7 @@ uint8_t USBD_PRNT_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_PRNT_ItfTypeD
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_PRNT_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
uint8_t USBD_PRNT_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
||||||
{
|
{
|
||||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *) pdev->pClassData;
|
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *) pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
hPRNT->RxBuffer = pbuff;
|
hPRNT->RxBuffer = pbuff;
|
||||||
|
|
||||||
@@ -636,7 +618,13 @@ uint8_t USBD_PRNT_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_PRNT_ReceivePacket(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_PRNT_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassData;
|
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
PRNTInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
PRNTOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
if (hPRNT == NULL)
|
if (hPRNT == NULL)
|
||||||
{
|
{
|
||||||
@@ -646,18 +634,19 @@ uint8_t USBD_PRNT_ReceivePacket(USBD_HandleTypeDef *pdev)
|
|||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, PRNT_OUT_EP, hPRNT->RxBuffer,
|
(void)USBD_LL_PrepareReceive(pdev, PRNTOutEpAdd, hPRNT->RxBuffer,
|
||||||
PRNT_DATA_HS_OUT_PACKET_SIZE);
|
PRNT_DATA_HS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, PRNT_OUT_EP, hPRNT->RxBuffer,
|
(void)USBD_LL_PrepareReceive(pdev, PRNTOutEpAdd, hPRNT->RxBuffer,
|
||||||
PRNT_DATA_FS_OUT_PACKET_SIZE);
|
PRNT_DATA_FS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver =
|
|||||||
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
/* USB TEMPLATE device Configuration Descriptor */
|
/* USB TEMPLATE device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -146,7 +146,7 @@ __ALIGN_BEGIN static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ]
|
|||||||
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -252,12 +252,12 @@ static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief USBD_TEMPLATE_GetDeviceQualifierDesc
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor(uint16_t *length)
|
uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = (uint16_t)sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
*length = (uint16_t)sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
||||||
return USBD_TEMPLATE_DeviceQualifierDesc;
|
return USBD_TEMPLATE_DeviceQualifierDesc;
|
||||||
@@ -350,19 +350,6 @@ static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DeviceQualifierDescriptor
|
|
||||||
* return Device Qualifier descriptor
|
|
||||||
* @param length : pointer data length
|
|
||||||
* @retval pointer to descriptor buffer
|
|
||||||
*/
|
|
||||||
uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length)
|
|
||||||
{
|
|
||||||
*length = (uint16_t)sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
|
||||||
|
|
||||||
return USBD_TEMPLATE_DeviceQualifierDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ extern "C" {
|
|||||||
#define UVC_VERSION 0x0100U /* UVC 1.0 */
|
#define UVC_VERSION 0x0100U /* UVC 1.0 */
|
||||||
#else
|
#else
|
||||||
#define UVC_VERSION 0x0110U /* UVC 1.1 */
|
#define UVC_VERSION 0x0110U /* UVC 1.1 */
|
||||||
#endif
|
#endif /* UVC_1_0 */
|
||||||
|
|
||||||
/* bEndpointAddress in Endpoint Descriptor */
|
/* bEndpointAddress in Endpoint Descriptor */
|
||||||
#ifndef UVC_IN_EP
|
#ifndef UVC_IN_EP
|
||||||
#define UVC_IN_EP 0x81U
|
#define UVC_IN_EP 0x81U
|
||||||
#endif /* VIDEO_IN_EP */
|
#endif /* UVC_IN_EP */
|
||||||
|
|
||||||
/* These defines shall be updated in the usbd_conf.h file */
|
/* These defines shall be updated in the usbd_conf.h file */
|
||||||
#ifndef UVC_WIDTH
|
#ifndef UVC_WIDTH
|
||||||
@@ -110,15 +110,15 @@ extern "C" {
|
|||||||
|
|
||||||
#ifndef UVC_ISO_FS_MPS
|
#ifndef UVC_ISO_FS_MPS
|
||||||
#define UVC_ISO_FS_MPS 256U
|
#define UVC_ISO_FS_MPS 256U
|
||||||
#endif
|
#endif /* UVC_ISO_FS_MPS */
|
||||||
|
|
||||||
#ifndef UVC_ISO_HS_MPS
|
#ifndef UVC_ISO_HS_MPS
|
||||||
#define UVC_ISO_HS_MPS 512U
|
#define UVC_ISO_HS_MPS 512U
|
||||||
#endif
|
#endif /* UVC_ISO_HS_MPS */
|
||||||
|
|
||||||
#ifndef UVC_HEADER_PACKET_CNT
|
#ifndef UVC_HEADER_PACKET_CNT
|
||||||
#define UVC_HEADER_PACKET_CNT 0x01U
|
#define UVC_HEADER_PACKET_CNT 0x01U
|
||||||
#endif
|
#endif /* UVC_HEADER_PACKET_CNT */
|
||||||
|
|
||||||
|
|
||||||
#define UVC_REQ_READ_MASK 0x80U
|
#define UVC_REQ_READ_MASK 0x80U
|
||||||
@@ -130,7 +130,9 @@ extern "C" {
|
|||||||
#define UVC_CONFIG_DESC_SIZ (0x88U + 0x16U)
|
#define UVC_CONFIG_DESC_SIZ (0x88U + 0x16U)
|
||||||
#else
|
#else
|
||||||
#define UVC_CONFIG_DESC_SIZ 0x88U
|
#define UVC_CONFIG_DESC_SIZ 0x88U
|
||||||
#endif
|
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
|
||||||
|
|
||||||
|
#define USBD_VC_GIUD_FORMAT_SIZE 16U
|
||||||
|
|
||||||
#define UVC_TOTAL_BUF_SIZE 0x04U
|
#define UVC_TOTAL_BUF_SIZE 0x04U
|
||||||
|
|
||||||
@@ -147,10 +149,10 @@ extern "C" {
|
|||||||
|
|
||||||
#ifndef WBVAL
|
#ifndef WBVAL
|
||||||
#define WBVAL(x) ((x) & 0xFFU),(((x) >> 8) & 0xFFU)
|
#define WBVAL(x) ((x) & 0xFFU),(((x) >> 8) & 0xFFU)
|
||||||
#endif
|
#endif /* WBVAL */
|
||||||
#ifndef DBVAL
|
#ifndef DBVAL
|
||||||
#define DBVAL(x) ((x)& 0xFFU),(((x) >> 8) & 0xFFU),(((x)>> 16) & 0xFFU),(((x) >> 24) & 0xFFU)
|
#define DBVAL(x) ((x)& 0xFFU),(((x) >> 8) & 0xFFU),(((x)>> 16) & 0xFFU),(((x) >> 24) & 0xFFU)
|
||||||
#endif
|
#endif /* DBVAL */
|
||||||
|
|
||||||
/* Video Interface Protocol Codes */
|
/* Video Interface Protocol Codes */
|
||||||
#define PC_PROTOCOL_UNDEFINED 0x00U
|
#define PC_PROTOCOL_UNDEFINED 0x00U
|
||||||
@@ -182,7 +184,7 @@ extern "C" {
|
|||||||
#define VC_HEADER_SIZE (VIDEO_VS_IF_IN_HEADER_DESC_SIZE + \
|
#define VC_HEADER_SIZE (VIDEO_VS_IF_IN_HEADER_DESC_SIZE + \
|
||||||
VS_FORMAT_DESC_SIZE + \
|
VS_FORMAT_DESC_SIZE + \
|
||||||
VS_FRAME_DESC_SIZE)
|
VS_FRAME_DESC_SIZE)
|
||||||
#endif
|
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Video Class specification release 1.1
|
* Video Class specification release 1.1
|
||||||
@@ -363,32 +365,6 @@ typedef enum
|
|||||||
VIDEO_OFFSET_UNKNOWN,
|
VIDEO_OFFSET_UNKNOWN,
|
||||||
} VIDEO_OffsetTypeDef;
|
} VIDEO_OffsetTypeDef;
|
||||||
|
|
||||||
typedef struct _VIDEO_DescHeader
|
|
||||||
{
|
|
||||||
uint8_t bLength;
|
|
||||||
uint8_t bDescriptorType;
|
|
||||||
uint8_t bDescriptorSubType;
|
|
||||||
} USBD_VIDEO_DescHeader_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint8_t bLength;
|
|
||||||
uint8_t bDescriptorType;
|
|
||||||
uint8_t bDescriptorSubType;
|
|
||||||
uint8_t bFrameIndex;
|
|
||||||
uint8_t bmCapabilities;
|
|
||||||
uint16_t wWidth;
|
|
||||||
uint16_t wHeight;
|
|
||||||
uint32_t dwMinBitRate;
|
|
||||||
uint32_t dwMaxBitRate;
|
|
||||||
uint32_t dwMaxVideoFrameBufSize;
|
|
||||||
uint32_t dwDefaultFrameInterval;
|
|
||||||
uint8_t bFrameIntervalType;
|
|
||||||
uint32_t dwMinFrameInterval;
|
|
||||||
uint32_t dwMaxFrameInterval;
|
|
||||||
uint32_t dwFrameIntervalStep;
|
|
||||||
} __PACKED USBD_VIDEO_VSFrameDescTypeDef;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
@@ -401,7 +377,8 @@ typedef struct
|
|||||||
{
|
{
|
||||||
uint32_t interface;
|
uint32_t interface;
|
||||||
uint32_t uvc_state;
|
uint32_t uvc_state;
|
||||||
uint8_t buffer[UVC_TOTAL_BUF_SIZE];
|
uint32_t uvc_size;
|
||||||
|
uint8_t *uvc_buffer;
|
||||||
VIDEO_OffsetTypeDef offset;
|
VIDEO_OffsetTypeDef offset;
|
||||||
USBD_VIDEO_ControlTypeDef control;
|
USBD_VIDEO_ControlTypeDef control;
|
||||||
} USBD_VIDEO_HandleTypeDef;
|
} USBD_VIDEO_HandleTypeDef;
|
||||||
@@ -435,6 +412,130 @@ typedef struct
|
|||||||
uint8_t bMaxVersion;
|
uint8_t bMaxVersion;
|
||||||
} __PACKED USBD_VideoControlTypeDef;
|
} __PACKED USBD_VideoControlTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bInterfaceNumber;
|
||||||
|
uint8_t bAlternateSetting;
|
||||||
|
uint8_t bNumEndpoints;
|
||||||
|
uint8_t bInterfaceClass;
|
||||||
|
uint8_t bInterfaceSubClass;
|
||||||
|
uint8_t bInterfaceProtocol;
|
||||||
|
uint8_t iFunction;
|
||||||
|
} __PACKED USBD_StandardVCIfDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint16_t bcdUVC;
|
||||||
|
uint16_t wTotalLength;
|
||||||
|
uint32_t dwClockFrequency;
|
||||||
|
uint8_t baInterfaceNr;
|
||||||
|
uint8_t iTerminal;
|
||||||
|
} __PACKED USBD_specificVCInDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bTerminalID;
|
||||||
|
uint16_t wTerminalType;
|
||||||
|
uint8_t bAssocTerminal;
|
||||||
|
uint8_t iTerminal;
|
||||||
|
} __PACKED USBD_InputTerminalDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint8_t bTerminalID;
|
||||||
|
uint16_t wTerminalType;
|
||||||
|
uint8_t bAssocTerminal;
|
||||||
|
uint8_t bSourceID;
|
||||||
|
uint8_t iTerminal;
|
||||||
|
} __PACKED USBD_OutputTerminalDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubtype;
|
||||||
|
uint16_t bNumFormats;
|
||||||
|
uint8_t bVideoControlSize;
|
||||||
|
uint8_t bEndPointAddress;
|
||||||
|
uint8_t bmInfo;
|
||||||
|
uint8_t bTerminalLink;
|
||||||
|
uint8_t bStillCaptureMethod;
|
||||||
|
uint8_t bTriggerSupport;
|
||||||
|
uint8_t bTriggerUsage;
|
||||||
|
uint8_t bControlSize;
|
||||||
|
uint8_t bmaControls;
|
||||||
|
} __PACKED USBD_ClassSpecificVsHeaderDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubType;
|
||||||
|
uint8_t bFormatIndex;
|
||||||
|
uint8_t bNumFrameDescriptor;
|
||||||
|
#ifdef USBD_UVC_FORMAT_UNCOMPRESSED
|
||||||
|
uint8_t pGiudFormat[USBD_VC_GIUD_FORMAT_SIZE];
|
||||||
|
uint8_t bBitsPerPixel;
|
||||||
|
#else
|
||||||
|
uint8_t bmFlags;
|
||||||
|
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
|
||||||
|
uint8_t bDefaultFrameIndex;
|
||||||
|
uint8_t bAspectRatioX;
|
||||||
|
uint8_t bAspectRatioY;
|
||||||
|
uint8_t bInterlaceFlags;
|
||||||
|
uint8_t bCopyProtect;
|
||||||
|
} __PACKED USBD_PayloadFormatDescTypeDef;
|
||||||
|
|
||||||
|
#ifdef USBD_UVC_FORMAT_UNCOMPRESSED
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubType;
|
||||||
|
uint8_t bColorPrimarie;
|
||||||
|
uint8_t bTransferCharacteristics;
|
||||||
|
uint8_t bMatrixCoefficients;
|
||||||
|
} __PACKED USBD_ColorMatchingDescTypeDef;
|
||||||
|
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bEndpointAddress;
|
||||||
|
uint8_t bmAttributes;
|
||||||
|
uint16_t wMaxPacketSize;
|
||||||
|
uint8_t bInterval;
|
||||||
|
} __PACKED USBD_StandardVCDataEPDescTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t bLength;
|
||||||
|
uint8_t bDescriptorType;
|
||||||
|
uint8_t bDescriptorSubType;
|
||||||
|
uint8_t bFrameIndex;
|
||||||
|
uint8_t bmCapabilities;
|
||||||
|
uint16_t wWidth;
|
||||||
|
uint16_t wHeight;
|
||||||
|
uint32_t dwMinBitRate;
|
||||||
|
uint32_t dwMaxBitRate;
|
||||||
|
uint32_t dwMaxVideoFrameBufSize;
|
||||||
|
uint32_t dwDefaultFrameInterval;
|
||||||
|
uint8_t bFrameIntervalType;
|
||||||
|
uint32_t dwMinFrameInterval;
|
||||||
|
} __PACKED USBD_VIDEO_VSFrameDescTypeDef;
|
||||||
|
|
||||||
extern USBD_ClassTypeDef USBD_VIDEO;
|
extern USBD_ClassTypeDef USBD_VIDEO;
|
||||||
#define USBD_VIDEO_CLASS &USBD_VIDEO
|
#define USBD_VIDEO_CLASS &USBD_VIDEO
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -87,10 +87,14 @@
|
|||||||
static uint8_t USBD_VIDEO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
static uint8_t USBD_VIDEO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
static uint8_t USBD_VIDEO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
static uint8_t USBD_VIDEO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
static uint8_t USBD_VIDEO_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static uint8_t USBD_VIDEO_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static uint8_t *USBD_VIDEO_GetFSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_VIDEO_GetFSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_VIDEO_GetHSCfgDesc(uint16_t *length);
|
static uint8_t *USBD_VIDEO_GetHSCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_VIDEO_GetOtherSpeedCfgDesc(uint16_t *length);
|
static uint8_t *USBD_VIDEO_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_VIDEO_GetDeviceQualifierDesc(uint16_t *length);
|
static uint8_t *USBD_VIDEO_GetDeviceQualifierDesc(uint16_t *length);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
static uint8_t USBD_VIDEO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_VIDEO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_VIDEO_SOF(USBD_HandleTypeDef *pdev);
|
static uint8_t USBD_VIDEO_SOF(USBD_HandleTypeDef *pdev);
|
||||||
static uint8_t USBD_VIDEO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_VIDEO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
@@ -99,10 +103,11 @@ static uint8_t USBD_VIDEO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnu
|
|||||||
static void VIDEO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static void VIDEO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
static void VIDEO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static void VIDEO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
static USBD_VIDEO_DescHeader_t *USBD_VIDEO_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
|
#ifndef USE_USBD_COMPOSITE
|
||||||
static void *USBD_VIDEO_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr);
|
|
||||||
static void *USBD_VIDEO_GetVSFrameDesc(uint8_t *pConfDesc);
|
static void *USBD_VIDEO_GetVSFrameDesc(uint8_t *pConfDesc);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
static void *USBD_VIDEO_GetVideoHeaderDesc(uint8_t *pConfDesc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -124,10 +129,17 @@ USBD_ClassTypeDef USBD_VIDEO =
|
|||||||
USBD_VIDEO_SOF,
|
USBD_VIDEO_SOF,
|
||||||
USBD_VIDEO_IsoINIncomplete,
|
USBD_VIDEO_IsoINIncomplete,
|
||||||
NULL,
|
NULL,
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#else
|
||||||
USBD_VIDEO_GetHSCfgDesc,
|
USBD_VIDEO_GetHSCfgDesc,
|
||||||
USBD_VIDEO_GetFSCfgDesc,
|
USBD_VIDEO_GetFSCfgDesc,
|
||||||
USBD_VIDEO_GetOtherSpeedCfgDesc,
|
USBD_VIDEO_GetOtherSpeedCfgDesc,
|
||||||
USBD_VIDEO_GetDeviceQualifierDesc,
|
USBD_VIDEO_GetDeviceQualifierDesc,
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* USB VIDEO device Configuration Descriptor (same for all speeds thanks to user defines) */
|
/* USB VIDEO device Configuration Descriptor (same for all speeds thanks to user defines) */
|
||||||
@@ -140,12 +152,13 @@ __ALIGN_BEGIN static uint8_t USBD_VIDEO_CfgDesc[] __ALIGN_END =
|
|||||||
HIBYTE(UVC_CONFIG_DESC_SIZ),
|
HIBYTE(UVC_CONFIG_DESC_SIZ),
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
0x02, /* bNumInterfaces: 2 interfaces */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
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)
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#else
|
#else
|
||||||
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
USBD_MAX_POWER, /* bMaxPower in mA according to user configuration */
|
USBD_MAX_POWER, /* bMaxPower in mA according to user configuration */
|
||||||
|
|
||||||
/* Interface Association Descriptor */
|
/* Interface Association Descriptor */
|
||||||
@@ -182,8 +195,8 @@ __ALIGN_BEGIN static uint8_t USBD_VIDEO_CfgDesc[] __ALIGN_END =
|
|||||||
0xDC,
|
0xDC,
|
||||||
0x02,
|
0x02,
|
||||||
0x01, /* bInCollection: number of streaming interfaces */
|
0x01, /* bInCollection: number of streaming interfaces */
|
||||||
0x01, /* baInterfaceNr(1): VideoStreaming interface 1 is part of VC interface */
|
0x01, /* baInterfaceNr(1): VideoStreaming interface 1 is part
|
||||||
|
of VC interface */
|
||||||
/* Input Terminal Descriptor */
|
/* Input Terminal Descriptor */
|
||||||
VIDEO_IN_TERMINAL_DESC_SIZE, /* bLength: Input terminal descriptor size */
|
VIDEO_IN_TERMINAL_DESC_SIZE, /* bLength: Input terminal descriptor size */
|
||||||
CS_INTERFACE, /* bDescriptorType: INTERFACE */
|
CS_INTERFACE, /* bDescriptorType: INTERFACE */
|
||||||
@@ -248,8 +261,9 @@ __ALIGN_BEGIN static uint8_t USBD_VIDEO_CfgDesc[] __ALIGN_END =
|
|||||||
UVC_BITS_PER_PIXEL, /* bBitsPerPixel : Number of bits per pixel */
|
UVC_BITS_PER_PIXEL, /* bBitsPerPixel : Number of bits per pixel */
|
||||||
#else
|
#else
|
||||||
0x01, /* bmFlags: FixedSizeSamples */
|
0x01, /* bmFlags: FixedSizeSamples */
|
||||||
#endif
|
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
|
||||||
0x01, /* bDefaultFrameIndex: default frame used is frame 1 (only one frame used) */
|
0x01, /* bDefaultFrameIndex: default frame used is frame 1
|
||||||
|
(only one frame used) */
|
||||||
0x00, /* bAspectRatioX: not required by specification */
|
0x00, /* bAspectRatioX: not required by specification */
|
||||||
0x00, /* bAspectRatioY: not required by specification */
|
0x00, /* bAspectRatioY: not required by specification */
|
||||||
0x00, /* bInterlaceFlags: non interlaced stream */
|
0x00, /* bInterlaceFlags: non interlaced stream */
|
||||||
@@ -264,7 +278,7 @@ __ALIGN_BEGIN static uint8_t USBD_VIDEO_CfgDesc[] __ALIGN_END =
|
|||||||
0x00, /* bmCapabilities: no till image capture */
|
0x00, /* bmCapabilities: no till image capture */
|
||||||
#else
|
#else
|
||||||
0x02, /* bmCapabilities: fixed frame rate supported */
|
0x02, /* bmCapabilities: fixed frame rate supported */
|
||||||
#endif
|
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
|
||||||
WBVAL(UVC_WIDTH), /* wWidth: Image Frame Width */
|
WBVAL(UVC_WIDTH), /* wWidth: Image Frame Width */
|
||||||
WBVAL(UVC_HEIGHT), /* wHeight: Image Frame Height */
|
WBVAL(UVC_HEIGHT), /* wHeight: Image Frame Height */
|
||||||
DBVAL(UVC_MIN_BIT_RATE(UVC_CAM_FPS_FS)), /* dwMinBitRate: Minimum supported bit rate in bits/s */
|
DBVAL(UVC_MIN_BIT_RATE(UVC_CAM_FPS_FS)), /* dwMinBitRate: Minimum supported bit rate in bits/s */
|
||||||
@@ -282,7 +296,7 @@ __ALIGN_BEGIN static uint8_t USBD_VIDEO_CfgDesc[] __ALIGN_END =
|
|||||||
UVC_COLOR_PRIMARIE, /* bColorPrimarie: 1: BT.709, sRGB (default) */
|
UVC_COLOR_PRIMARIE, /* bColorPrimarie: 1: BT.709, sRGB (default) */
|
||||||
UVC_TFR_CHARACTERISTICS, /* bTransferCharacteristics: 1: BT.709 (default) */
|
UVC_TFR_CHARACTERISTICS, /* bTransferCharacteristics: 1: BT.709 (default) */
|
||||||
UVC_MATRIX_COEFFICIENTS, /* bMatrixCoefficients: 4: BT.601, (default) */
|
UVC_MATRIX_COEFFICIENTS, /* bMatrixCoefficients: 4: BT.601, (default) */
|
||||||
#endif
|
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
|
||||||
|
|
||||||
/* Standard VS Interface Descriptor = interface 1, alternate setting 1 = data transfer mode */
|
/* Standard VS Interface Descriptor = interface 1, alternate setting 1 = data transfer mode */
|
||||||
USB_IF_DESC_SIZE, /* bLength */
|
USB_IF_DESC_SIZE, /* bLength */
|
||||||
@@ -305,6 +319,7 @@ __ALIGN_BEGIN static uint8_t USBD_VIDEO_CfgDesc[] __ALIGN_END =
|
|||||||
0x01, /* bInterval: 1 frame interval */
|
0x01, /* bInterval: 1 frame interval */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_VIDEO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_VIDEO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
@@ -319,6 +334,9 @@ __ALIGN_BEGIN static uint8_t USBD_VIDEO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIE
|
|||||||
0x01,
|
0x01,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
static uint8_t VIDEOinEpAdd = UVC_IN_EP;
|
||||||
|
|
||||||
/* Video Commit data structure */
|
/* Video Commit data structure */
|
||||||
static USBD_VideoControlTypeDef video_Commit_Control =
|
static USBD_VideoControlTypeDef video_Commit_Control =
|
||||||
@@ -377,7 +395,7 @@ static USBD_VideoControlTypeDef video_Probe_Control =
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_VIDEO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
static uint8_t USBD_VIDEO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
USBD_VIDEO_HandleTypeDef *hVIDEO;
|
USBD_VIDEO_HandleTypeDef *hVIDEO;
|
||||||
|
|
||||||
@@ -391,26 +409,32 @@ static uint8_t USBD_VIDEO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Assign the pClassData pointer to the allocated structure */
|
/* Assign the pClassData pointer to the allocated structure */
|
||||||
pdev->pClassData = (void *)hVIDEO;
|
pdev->pClassDataCmsit[pdev->classId] = (void *)hVIDEO;
|
||||||
|
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
VIDEOinEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_ISOC, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
(void)USBD_LL_OpenEP(pdev, UVC_IN_EP, USBD_EP_TYPE_ISOC, UVC_ISO_HS_MPS);
|
(void)USBD_LL_OpenEP(pdev, VIDEOinEpAdd, USBD_EP_TYPE_ISOC, UVC_ISO_HS_MPS);
|
||||||
|
|
||||||
pdev->ep_in[UVC_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[VIDEOinEpAdd & 0xFU].is_used = 1U;
|
||||||
pdev->ep_in[UVC_IN_EP & 0xFU].maxpacket = UVC_ISO_HS_MPS;
|
pdev->ep_in[VIDEOinEpAdd & 0xFU].maxpacket = UVC_ISO_HS_MPS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(void)USBD_LL_OpenEP(pdev, UVC_IN_EP, USBD_EP_TYPE_ISOC, UVC_ISO_FS_MPS);
|
(void)USBD_LL_OpenEP(pdev, VIDEOinEpAdd, USBD_EP_TYPE_ISOC, UVC_ISO_FS_MPS);
|
||||||
|
|
||||||
pdev->ep_in[UVC_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[VIDEOinEpAdd & 0xFU].is_used = 1U;
|
||||||
pdev->ep_in[UVC_IN_EP & 0xFU].maxpacket = UVC_ISO_FS_MPS;
|
pdev->ep_in[VIDEOinEpAdd & 0xFU].maxpacket = UVC_ISO_FS_MPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init physical Interface components */
|
/* Init physical Interface components */
|
||||||
((USBD_VIDEO_ItfTypeDef *)pdev->pUserData)->Init();
|
((USBD_VIDEO_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||||
|
|
||||||
/* Init Xfer states */
|
/* Init Xfer states */
|
||||||
hVIDEO->interface = 0U;
|
hVIDEO->interface = 0U;
|
||||||
@@ -430,23 +454,29 @@ static uint8_t USBD_VIDEO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_VIDEO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
static uint8_t USBD_VIDEO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
UNUSED(cfgidx);
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
/* Check if the video structure pointer is valid */
|
/* Check if the video structure pointer is valid */
|
||||||
if (pdev->pClassData == NULL)
|
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||||
{
|
{
|
||||||
return (uint8_t)USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
VIDEOinEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_ISOC, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Close EP IN */
|
/* Close EP IN */
|
||||||
(void)USBD_LL_CloseEP(pdev, UVC_IN_EP);
|
(void)USBD_LL_CloseEP(pdev, VIDEOinEpAdd);
|
||||||
pdev->ep_in[UVC_IN_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[VIDEOinEpAdd & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
((USBD_VIDEO_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_VIDEO_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
|
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
|
|
||||||
/* Exit with no error code */
|
/* Exit with no error code */
|
||||||
@@ -460,13 +490,18 @@ static uint8_t USBD_VIDEO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_VIDEO_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static uint8_t USBD_VIDEO_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_VIDEO_HandleTypeDef *hVIDEO = (USBD_VIDEO_HandleTypeDef *) pdev->pClassData;
|
USBD_VIDEO_HandleTypeDef *hVIDEO = (USBD_VIDEO_HandleTypeDef *) pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t ret = (uint8_t)USBD_OK;
|
uint8_t ret = (uint8_t)USBD_OK;
|
||||||
uint16_t len = 0U;
|
|
||||||
uint8_t *pbuf = NULL;
|
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
|
uint16_t len;
|
||||||
|
uint8_t *pbuf;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
VIDEOinEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_ISOC, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
@@ -480,13 +515,16 @@ static uint8_t USBD_VIDEO_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
case UVC_GET_MAX:
|
case UVC_GET_MAX:
|
||||||
VIDEO_REQ_GetCurrent(pdev, req);
|
VIDEO_REQ_GetCurrent(pdev, req);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UVC_GET_RES:
|
case UVC_GET_RES:
|
||||||
case UVC_GET_LEN:
|
case UVC_GET_LEN:
|
||||||
case UVC_GET_INFO:
|
case UVC_GET_INFO:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UVC_SET_CUR:
|
case UVC_SET_CUR:
|
||||||
VIDEO_REQ_SetCurrent(pdev, req);
|
VIDEO_REQ_SetCurrent(pdev, req);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
(void) USBD_CtlError(pdev, req);
|
(void) USBD_CtlError(pdev, req);
|
||||||
ret = (uint8_t)USBD_FAIL;
|
ret = (uint8_t)USBD_FAIL;
|
||||||
@@ -513,10 +551,18 @@ static uint8_t USBD_VIDEO_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
case USB_REQ_GET_DESCRIPTOR:
|
case USB_REQ_GET_DESCRIPTOR:
|
||||||
if ((req->wValue >> 8) == CS_DEVICE)
|
if ((req->wValue >> 8) == CS_DEVICE)
|
||||||
{
|
{
|
||||||
pbuf = USBD_VIDEO_CfgDesc + 18;
|
pbuf = (uint8_t *)USBD_VIDEO_GetVideoHeaderDesc(pdev->pConfDesc);
|
||||||
len = MIN((uint16_t)USB_CONF_DESC_SIZE, (uint16_t)req->wLength);
|
if (pbuf != NULL)
|
||||||
|
{
|
||||||
|
len = MIN((uint16_t)USB_CONF_DESC_SIZE, (uint16_t)req->wLength);
|
||||||
|
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
ret = (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE :
|
case USB_REQ_GET_INTERFACE :
|
||||||
@@ -540,14 +586,14 @@ static uint8_t USBD_VIDEO_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
if (hVIDEO->interface == 1U)
|
if (hVIDEO->interface == 1U)
|
||||||
{
|
{
|
||||||
/* Start Streaming (First endpoint writing will be done on next SOF) */
|
/* Start Streaming (First endpoint writing will be done on next SOF) */
|
||||||
(void)USBD_LL_FlushEP(pdev, UVC_IN_EP);
|
(void)USBD_LL_FlushEP(pdev, VIDEOinEpAdd);
|
||||||
hVIDEO->uvc_state = UVC_PLAY_STATUS_READY;
|
hVIDEO->uvc_state = UVC_PLAY_STATUS_READY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Stop Streaming */
|
/* Stop Streaming */
|
||||||
hVIDEO->uvc_state = UVC_PLAY_STATUS_STOP;
|
hVIDEO->uvc_state = UVC_PLAY_STATUS_STOP;
|
||||||
(void)USBD_LL_FlushEP(pdev, UVC_IN_EP);
|
(void)USBD_LL_FlushEP(pdev, VIDEOinEpAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -592,20 +638,26 @@ static uint8_t USBD_VIDEO_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_VIDEO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_VIDEO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_VIDEO_HandleTypeDef *hVIDEO = (USBD_VIDEO_HandleTypeDef *) pdev->pClassData;
|
USBD_VIDEO_HandleTypeDef *hVIDEO = (USBD_VIDEO_HandleTypeDef *) pdev->pClassDataCmsit[pdev->classId];
|
||||||
static uint8_t packet[UVC_PACKET_SIZE + (UVC_HEADER_PACKET_CNT * 2U)] = {0x00U};
|
static uint8_t packet[UVC_PACKET_SIZE + (UVC_HEADER_PACKET_CNT * 2U)] = {0x00U};
|
||||||
static uint8_t *Pcktdata = packet;
|
static uint8_t *Pcktdata = packet;
|
||||||
static uint16_t PcktIdx = 0U;
|
static uint16_t PcktIdx = 0U;
|
||||||
static uint16_t PcktSze = UVC_PACKET_SIZE;
|
static uint16_t PcktSze = UVC_PACKET_SIZE;
|
||||||
static uint8_t payload_header[2] = {0x02U, 0x00U};
|
static uint8_t payload_header[2] = {0x02U, 0x00U};
|
||||||
uint8_t i = 0U;
|
uint8_t i = 0U;
|
||||||
uint32_t RemainData, DataOffset = 0U;
|
uint32_t RemainData = 0U;
|
||||||
|
uint32_t DataOffset = 0U;
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
VIDEOinEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_ISOC, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Check if the Streaming has already been started */
|
/* Check if the Streaming has already been started */
|
||||||
if (hVIDEO->uvc_state == UVC_PLAY_STATUS_STREAMING)
|
if (hVIDEO->uvc_state == UVC_PLAY_STATUS_STREAMING)
|
||||||
{
|
{
|
||||||
/* Get the current packet buffer, index and size from the application layer */
|
/* Get the current packet buffer, index and size from the application layer */
|
||||||
((USBD_VIDEO_ItfTypeDef *)pdev->pUserData)->Data(&Pcktdata, &PcktSze, &PcktIdx);
|
((USBD_VIDEO_ItfTypeDef *)pdev->pUserData[pdev->classId])->Data(&Pcktdata, &PcktSze, &PcktIdx);
|
||||||
|
|
||||||
/* Check if end of current image has been reached */
|
/* Check if end of current image has been reached */
|
||||||
if (PcktSze > 2U)
|
if (PcktSze > 2U)
|
||||||
@@ -624,9 +676,10 @@ static uint8_t USBD_VIDEO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
{
|
{
|
||||||
packet[((DataOffset + 0U) * i)] = payload_header[0];
|
packet[((DataOffset + 0U) * i)] = payload_header[0];
|
||||||
packet[((DataOffset + 0U) * i) + 1U] = payload_header[1];
|
packet[((DataOffset + 0U) * i) + 1U] = payload_header[1];
|
||||||
if (RemainData > pdev->ep_in[UVC_IN_EP & 0xFU].maxpacket)
|
|
||||||
|
if (RemainData > pdev->ep_in[VIDEOinEpAdd & 0xFU].maxpacket)
|
||||||
{
|
{
|
||||||
DataOffset = pdev->ep_in[UVC_IN_EP & 0xFU].maxpacket;
|
DataOffset = pdev->ep_in[VIDEOinEpAdd & 0xFU].maxpacket;
|
||||||
(void)USBD_memcpy((packet + ((DataOffset + 0U) * i) + 2U),
|
(void)USBD_memcpy((packet + ((DataOffset + 0U) * i) + 2U),
|
||||||
Pcktdata + ((DataOffset - 2U) * i), (DataOffset - 2U));
|
Pcktdata + ((DataOffset - 2U) * i), (DataOffset - 2U));
|
||||||
|
|
||||||
@@ -649,9 +702,12 @@ static uint8_t USBD_VIDEO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
packet[1] = payload_header[1];
|
packet[1] = payload_header[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hVIDEO->uvc_buffer = (uint8_t *)&packet;
|
||||||
|
hVIDEO->uvc_size = (uint32_t)PcktSze;
|
||||||
|
|
||||||
/* Transmit the packet on Endpoint */
|
/* Transmit the packet on Endpoint */
|
||||||
(void)USBD_LL_Transmit(pdev, (uint8_t)(epnum | 0x80U),
|
(void)USBD_LL_Transmit(pdev, (uint8_t)(epnum | 0x80U),
|
||||||
(uint8_t *)&packet, (uint32_t)PcktSze);
|
hVIDEO->uvc_buffer, hVIDEO->uvc_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exit with no error code */
|
/* Exit with no error code */
|
||||||
@@ -666,14 +722,22 @@ static uint8_t USBD_VIDEO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_VIDEO_SOF(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_VIDEO_SOF(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_VIDEO_HandleTypeDef *hVIDEO = (USBD_VIDEO_HandleTypeDef *) pdev->pClassData;
|
USBD_VIDEO_HandleTypeDef *hVIDEO = (USBD_VIDEO_HandleTypeDef *) pdev->pClassDataCmsit[pdev->classId];
|
||||||
uint8_t payload[2] = {0x02U, 0x00U};
|
uint8_t payload[2] = {0x02U, 0x00U};
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
VIDEOinEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_ISOC, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/* Check if the Streaming has already been started by SetInterface AltSetting 1 */
|
/* Check if the Streaming has already been started by SetInterface AltSetting 1 */
|
||||||
if (hVIDEO->uvc_state == UVC_PLAY_STATUS_READY)
|
if (hVIDEO->uvc_state == UVC_PLAY_STATUS_READY)
|
||||||
{
|
{
|
||||||
|
hVIDEO->uvc_buffer = (uint8_t *)&payload;
|
||||||
|
hVIDEO->uvc_size = 2U;
|
||||||
|
|
||||||
/* Transmit the first packet indicating that Streaming is starting */
|
/* Transmit the first packet indicating that Streaming is starting */
|
||||||
(void)USBD_LL_Transmit(pdev, UVC_IN_EP, (uint8_t *)payload, 2U);
|
(void)USBD_LL_Transmit(pdev, VIDEOinEpAdd, hVIDEO->uvc_buffer, hVIDEO->uvc_size);
|
||||||
|
|
||||||
/* Enable Streaming state */
|
/* Enable Streaming state */
|
||||||
hVIDEO->uvc_state = UVC_PLAY_STATUS_STREAMING;
|
hVIDEO->uvc_state = UVC_PLAY_STATUS_STREAMING;
|
||||||
@@ -692,8 +756,17 @@ static uint8_t USBD_VIDEO_SOF(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_VIDEO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_VIDEO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
UNUSED(pdev);
|
USBD_VIDEO_HandleTypeDef *hVIDEO = (USBD_VIDEO_HandleTypeDef *) pdev->pClassDataCmsit[pdev->classId];
|
||||||
UNUSED(epnum);
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
/* Get the Endpoints addresses allocated for this class instance */
|
||||||
|
VIDEOinEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_ISOC, (uint8_t)pdev->classId);
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
|
if (epnum == (VIDEOinEpAdd & 0xFU))
|
||||||
|
{
|
||||||
|
(void)USBD_LL_Transmit(pdev, VIDEOinEpAdd, hVIDEO->uvc_buffer, hVIDEO->uvc_size);
|
||||||
|
}
|
||||||
|
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
@@ -708,7 +781,7 @@ static uint8_t USBD_VIDEO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnu
|
|||||||
static void VIDEO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void VIDEO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_VIDEO_HandleTypeDef *hVIDEO;
|
USBD_VIDEO_HandleTypeDef *hVIDEO;
|
||||||
hVIDEO = (USBD_VIDEO_HandleTypeDef *)(pdev->pClassData);
|
hVIDEO = (USBD_VIDEO_HandleTypeDef *)(pdev->pClassDataCmsit[pdev->classId]);
|
||||||
static __IO uint8_t EntityStatus[8] = {0};
|
static __IO uint8_t EntityStatus[8] = {0};
|
||||||
|
|
||||||
/* Reset buffer to zeros */
|
/* Reset buffer to zeros */
|
||||||
@@ -794,19 +867,18 @@ static void VIDEO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
*/
|
*/
|
||||||
static void VIDEO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void VIDEO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_VIDEO_HandleTypeDef *hVIDEO = (USBD_VIDEO_HandleTypeDef *)(pdev->pClassData);
|
|
||||||
|
|
||||||
/* Check that the request has control data */
|
/* Check that the request has control data */
|
||||||
if (req->wLength > 0U)
|
if (req->wLength > 0U)
|
||||||
{
|
{
|
||||||
/* Prepare the reception of the buffer over EP0 */
|
/* Prepare the reception of the buffer over EP0 */
|
||||||
if (LOBYTE(req->wValue) == (uint8_t)VS_PROBE_CONTROL)
|
if (req->wValue == (uint16_t)VS_PROBE_CONTROL)
|
||||||
{
|
{
|
||||||
/* Probe Request */
|
/* Probe Request */
|
||||||
(void) USBD_CtlPrepareRx(pdev, (uint8_t *)&video_Probe_Control,
|
(void) USBD_CtlPrepareRx(pdev, (uint8_t *)&video_Probe_Control,
|
||||||
MIN(req->wLength, sizeof(USBD_VideoControlTypeDef)));
|
MIN(req->wLength, sizeof(USBD_VideoControlTypeDef)));
|
||||||
}
|
}
|
||||||
else if (LOBYTE(req->wValue) == (uint8_t)VS_COMMIT_CONTROL)
|
else if (req->wValue == (uint16_t)VS_COMMIT_CONTROL)
|
||||||
{
|
{
|
||||||
/* Commit Request */
|
/* Commit Request */
|
||||||
(void) USBD_CtlPrepareRx(pdev, (uint8_t *)&video_Commit_Control,
|
(void) USBD_CtlPrepareRx(pdev, (uint8_t *)&video_Commit_Control,
|
||||||
@@ -814,13 +886,12 @@ static void VIDEO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Prepare the reception of the buffer over EP0 */
|
(void)USBD_LL_StallEP(pdev, 0x80U);
|
||||||
(void) USBD_CtlPrepareRx(pdev, hVIDEO->control.data,
|
|
||||||
MIN(req->wLength, USB_MAX_EP0_SIZE));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef USE_USBD_COMPOSITE
|
||||||
/**
|
/**
|
||||||
* @brief USBD_VIDEO_GetFSCfgDesc
|
* @brief USBD_VIDEO_GetFSCfgDesc
|
||||||
* return configuration descriptor
|
* return configuration descriptor
|
||||||
@@ -829,7 +900,7 @@ static void VIDEO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_VIDEO_GetFSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_VIDEO_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
USBD_EpDescTypedef *pEpDesc = USBD_VIDEO_GetEpDesc(USBD_VIDEO_CfgDesc, UVC_IN_EP);
|
USBD_EpDescTypeDef *pEpDesc = USBD_GetEpDesc(USBD_VIDEO_CfgDesc, VIDEOinEpAdd);
|
||||||
USBD_VIDEO_VSFrameDescTypeDef *pVSFrameDesc = USBD_VIDEO_GetVSFrameDesc(USBD_VIDEO_CfgDesc);
|
USBD_VIDEO_VSFrameDescTypeDef *pVSFrameDesc = USBD_VIDEO_GetVSFrameDesc(USBD_VIDEO_CfgDesc);
|
||||||
|
|
||||||
if (pEpDesc != NULL)
|
if (pEpDesc != NULL)
|
||||||
@@ -857,7 +928,7 @@ static uint8_t *USBD_VIDEO_GetFSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_VIDEO_GetHSCfgDesc(uint16_t *length)
|
static uint8_t *USBD_VIDEO_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
USBD_EpDescTypedef *pEpDesc = USBD_VIDEO_GetEpDesc(USBD_VIDEO_CfgDesc, UVC_IN_EP);
|
USBD_EpDescTypeDef *pEpDesc = USBD_GetEpDesc(USBD_VIDEO_CfgDesc, VIDEOinEpAdd);
|
||||||
USBD_VIDEO_VSFrameDescTypeDef *pVSFrameDesc = USBD_VIDEO_GetVSFrameDesc(USBD_VIDEO_CfgDesc);
|
USBD_VIDEO_VSFrameDescTypeDef *pVSFrameDesc = USBD_VIDEO_GetVSFrameDesc(USBD_VIDEO_CfgDesc);
|
||||||
|
|
||||||
if (pEpDesc != NULL)
|
if (pEpDesc != NULL)
|
||||||
@@ -885,7 +956,7 @@ static uint8_t *USBD_VIDEO_GetHSCfgDesc(uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
static uint8_t *USBD_VIDEO_GetOtherSpeedCfgDesc(uint16_t *length)
|
static uint8_t *USBD_VIDEO_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
USBD_EpDescTypedef *pEpDesc = USBD_VIDEO_GetEpDesc(USBD_VIDEO_CfgDesc, UVC_IN_EP);
|
USBD_EpDescTypeDef *pEpDesc = USBD_GetEpDesc(USBD_VIDEO_CfgDesc, VIDEOinEpAdd);
|
||||||
USBD_VIDEO_VSFrameDescTypeDef *pVSFrameDesc = USBD_VIDEO_GetVSFrameDesc(USBD_VIDEO_CfgDesc);
|
USBD_VIDEO_VSFrameDescTypeDef *pVSFrameDesc = USBD_VIDEO_GetVSFrameDesc(USBD_VIDEO_CfgDesc);
|
||||||
|
|
||||||
if (pEpDesc != NULL)
|
if (pEpDesc != NULL)
|
||||||
@@ -917,23 +988,6 @@ static uint8_t *USBD_VIDEO_GetDeviceQualifierDesc(uint16_t *length)
|
|||||||
return USBD_VIDEO_DeviceQualifierDesc;
|
return USBD_VIDEO_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief USBD_VIDEO_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
|
|
||||||
*/
|
|
||||||
static USBD_VIDEO_DescHeader_t *USBD_VIDEO_GetNextDesc(uint8_t *pbuf, uint16_t *ptr)
|
|
||||||
{
|
|
||||||
USBD_VIDEO_DescHeader_t *pnext = (USBD_VIDEO_DescHeader_t *)(void *)pbuf;
|
|
||||||
|
|
||||||
*ptr += pnext->bLength;
|
|
||||||
pnext = (USBD_VIDEO_DescHeader_t *)(void *)(pbuf + pnext->bLength);
|
|
||||||
|
|
||||||
return (pnext);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_VIDEO_GetVSFrameDesc
|
* @brief USBD_VIDEO_GetVSFrameDesc
|
||||||
* This function return the Video Endpoint descriptor
|
* This function return the Video Endpoint descriptor
|
||||||
@@ -943,8 +997,8 @@ static USBD_VIDEO_DescHeader_t *USBD_VIDEO_GetNextDesc(uint8_t *pbuf, uint16_t *
|
|||||||
*/
|
*/
|
||||||
static void *USBD_VIDEO_GetVSFrameDesc(uint8_t *pConfDesc)
|
static void *USBD_VIDEO_GetVSFrameDesc(uint8_t *pConfDesc)
|
||||||
{
|
{
|
||||||
USBD_VIDEO_DescHeader_t *pdesc = (USBD_VIDEO_DescHeader_t *)(void *)pConfDesc;
|
USBD_DescHeaderTypeDef *pdesc = (USBD_DescHeaderTypeDef *)(void *)pConfDesc;
|
||||||
USBD_ConfigDescTypedef *desc = (USBD_ConfigDescTypedef *)(void *)pConfDesc;
|
USBD_ConfigDescTypeDef *desc = (USBD_ConfigDescTypeDef *)(void *)pConfDesc;
|
||||||
USBD_VIDEO_VSFrameDescTypeDef *pVSFrameDesc = NULL;
|
USBD_VIDEO_VSFrameDescTypeDef *pVSFrameDesc = NULL;
|
||||||
uint16_t ptr;
|
uint16_t ptr;
|
||||||
|
|
||||||
@@ -954,7 +1008,7 @@ static void *USBD_VIDEO_GetVSFrameDesc(uint8_t *pConfDesc)
|
|||||||
|
|
||||||
while (ptr < desc->wTotalLength)
|
while (ptr < desc->wTotalLength)
|
||||||
{
|
{
|
||||||
pdesc = USBD_VIDEO_GetNextDesc((uint8_t *)pdesc, &ptr);
|
pdesc = USBD_GetNextDesc((uint8_t *)pdesc, &ptr);
|
||||||
|
|
||||||
if (((pdesc->bDescriptorSubType == VS_FRAME_MJPEG) ||
|
if (((pdesc->bDescriptorSubType == VS_FRAME_MJPEG) ||
|
||||||
(pdesc->bDescriptorSubType == VS_FRAME_UNCOMPRESSED)) &&
|
(pdesc->bDescriptorSubType == VS_FRAME_UNCOMPRESSED)) &&
|
||||||
@@ -968,20 +1022,20 @@ static void *USBD_VIDEO_GetVSFrameDesc(uint8_t *pConfDesc)
|
|||||||
|
|
||||||
return (void *)pVSFrameDesc;
|
return (void *)pVSFrameDesc;
|
||||||
}
|
}
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_VIDEO_GetEpDesc
|
* @brief USBD_VIDEO_GetVideoHeaderDesc
|
||||||
* This function return the Video Endpoint descriptor
|
* This function return the Video Header descriptor
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param pConfDesc: pointer to Bos descriptor
|
* @param pConfDesc: pointer to Bos descriptor
|
||||||
* @param EpAddr: endpoint address
|
* @retval pointer to the Video Header descriptor
|
||||||
* @retval pointer to video endpoint descriptor
|
|
||||||
*/
|
*/
|
||||||
static void *USBD_VIDEO_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr)
|
static void *USBD_VIDEO_GetVideoHeaderDesc(uint8_t *pConfDesc)
|
||||||
{
|
{
|
||||||
USBD_VIDEO_DescHeader_t *pdesc = (USBD_VIDEO_DescHeader_t *)(void *)pConfDesc;
|
USBD_ConfigDescTypeDef *desc = (USBD_ConfigDescTypeDef *)(void *)pConfDesc;
|
||||||
USBD_ConfigDescTypedef *desc = (USBD_ConfigDescTypedef *)(void *)pConfDesc;
|
USBD_DescHeaderTypeDef *pdesc = (USBD_DescHeaderTypeDef *)(void *)pConfDesc;
|
||||||
USBD_EpDescTypedef *pEpDesc = NULL;
|
uint8_t *pVideoDesc = NULL;
|
||||||
uint16_t ptr;
|
uint16_t ptr;
|
||||||
|
|
||||||
if (desc->wTotalLength > desc->bLength)
|
if (desc->wTotalLength > desc->bLength)
|
||||||
@@ -990,25 +1044,16 @@ static void *USBD_VIDEO_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr)
|
|||||||
|
|
||||||
while (ptr < desc->wTotalLength)
|
while (ptr < desc->wTotalLength)
|
||||||
{
|
{
|
||||||
pdesc = USBD_VIDEO_GetNextDesc((uint8_t *)pdesc, &ptr);
|
pdesc = USBD_GetNextDesc((uint8_t *)pdesc, &ptr);
|
||||||
|
if ((pdesc->bDescriptorType == CS_INTERFACE) &&
|
||||||
if (pdesc->bDescriptorType == USB_DESC_TYPE_ENDPOINT)
|
(pdesc->bDescriptorSubType == VC_HEADER))
|
||||||
{
|
{
|
||||||
pEpDesc = (USBD_EpDescTypedef *)(void *)pdesc;
|
pVideoDesc = (uint8_t *)pdesc;
|
||||||
|
break;
|
||||||
if (pEpDesc->bEndpointAddress == EpAddr)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pEpDesc = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return pVideoDesc;
|
||||||
return (void *)pEpDesc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1026,7 +1071,7 @@ uint8_t USBD_VIDEO_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_VIDEO_ItfT
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Assign the FOPS pointer */
|
/* Assign the FOPS pointer */
|
||||||
pdev->pUserData = fops;
|
pdev->pUserData[pdev->classId] = fops;
|
||||||
|
|
||||||
/* Exit with no error code */
|
/* Exit with no error code */
|
||||||
return (uint8_t)USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
|
|||||||
@@ -234,14 +234,16 @@ static int8_t VIDEO_Itf_Data(uint8_t **pbuf, uint16_t *psize, uint16_t *pcktidx)
|
|||||||
*psize = (uint16_t)UVC_PACKET_SIZE;
|
*psize = (uint16_t)UVC_PACKET_SIZE;
|
||||||
|
|
||||||
/* Get the pointer to the next packet to be transmitted */
|
/* Get the pointer to the next packet to be transmitted */
|
||||||
*pbuf = (uint8_t *)(*(ImagePtr + img_count) + (packet_index * ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)))));
|
*pbuf = (uint8_t *)(*(ImagePtr + img_count) + \
|
||||||
|
(packet_index * ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)))));
|
||||||
}
|
}
|
||||||
else if ((packet_index == packet_count))
|
else if ((packet_index == packet_count))
|
||||||
{
|
{
|
||||||
if (packet_remainder != 0U)
|
if (packet_remainder != 0U)
|
||||||
{
|
{
|
||||||
/* Get the pointer to the next packet to be transmitted */
|
/* Get the pointer to the next packet to be transmitted */
|
||||||
*pbuf = (uint8_t *)(*(ImagePtr + img_count) + (packet_index * ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)))));
|
*pbuf = (uint8_t *)(*(ImagePtr + img_count) + \
|
||||||
|
(packet_index * ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)))));
|
||||||
|
|
||||||
/* Set the current packet size */
|
/* Set the current packet size */
|
||||||
*psize = (uint16_t)(packet_remainder + (UVC_HEADER_PACKET_CNT * 2U));
|
*psize = (uint16_t)(packet_remainder + (UVC_HEADER_PACKET_CNT * 2U));
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ extern "C" {
|
|||||||
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
||||||
#define USBD_SELF_POWERED 1U
|
#define USBD_SELF_POWERED 1U
|
||||||
#define USBD_DEBUG_LEVEL 2U
|
#define USBD_DEBUG_LEVEL 2U
|
||||||
|
/* #define USBD_USER_REGISTER_CALLBACK 1U */
|
||||||
|
|
||||||
/* ECM, RNDIS, DFU Class Config */
|
/* ECM, RNDIS, DFU Class Config */
|
||||||
#define USBD_SUPPORT_USER_STRING_DESC 1U
|
#define USBD_SUPPORT_USER_STRING_DESC 1U
|
||||||
@@ -64,6 +65,8 @@ extern "C" {
|
|||||||
#define USBD_CDC_INTERVAL 2000U
|
#define USBD_CDC_INTERVAL 2000U
|
||||||
|
|
||||||
/* DFU Class Config */
|
/* DFU Class Config */
|
||||||
|
/* #define USBD_DFU_VENDOR_CMD_ENABLED 1U */
|
||||||
|
/* #define USBD_DFU_VENDOR_EXIT_ENABLED 1U */
|
||||||
#define USBD_DFU_MAX_ITF_NUM 1U
|
#define USBD_DFU_MAX_ITF_NUM 1U
|
||||||
#define USBD_DFU_XFERS_IZE 1024U
|
#define USBD_DFU_XFERS_IZE 1024U
|
||||||
|
|
||||||
@@ -76,6 +79,13 @@ extern "C" {
|
|||||||
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U
|
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U
|
||||||
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U
|
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U
|
||||||
|
|
||||||
|
/* #define USBD_CUSTOMHID_REPORT_DESC_SIZE_ENABLED */
|
||||||
|
/* #define USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||||
|
/* #define USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED */
|
||||||
|
/* #define USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED */
|
||||||
|
/* #define USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||||
|
/* #define USBD_CUSTOMHID_REPORT_BUFFER_EVENT_ENABLED */
|
||||||
|
|
||||||
/* VIDEO Class Config */
|
/* VIDEO Class Config */
|
||||||
#define UVC_1_1 /* #define UVC_1_0 */
|
#define UVC_1_1 /* #define UVC_1_0 */
|
||||||
|
|
||||||
@@ -90,7 +100,7 @@ extern "C" {
|
|||||||
#define UVC_COLOR_PRIMARIE 0x01U
|
#define UVC_COLOR_PRIMARIE 0x01U
|
||||||
#define UVC_TFR_CHARACTERISTICS 0x01U
|
#define UVC_TFR_CHARACTERISTICS 0x01U
|
||||||
#define UVC_MATRIX_COEFFICIENTS 0x04U
|
#define UVC_MATRIX_COEFFICIENTS 0x04U
|
||||||
#endif
|
#endif /* USBD_UVC_FORMAT_UNCOMPRESSED */
|
||||||
|
|
||||||
/* Video Stream frame width and height */
|
/* Video Stream frame width and height */
|
||||||
#define UVC_WIDTH 176U
|
#define UVC_WIDTH 176U
|
||||||
@@ -140,7 +150,7 @@ extern "C" {
|
|||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define USBD_UsrLog(...) do {} while (0)
|
#define USBD_UsrLog(...) do {} while (0)
|
||||||
#endif
|
#endif /* (USBD_DEBUG_LEVEL > 0U) */
|
||||||
|
|
||||||
#if (USBD_DEBUG_LEVEL > 1U)
|
#if (USBD_DEBUG_LEVEL > 1U)
|
||||||
|
|
||||||
@@ -151,7 +161,7 @@ extern "C" {
|
|||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define USBD_ErrLog(...) do {} while (0)
|
#define USBD_ErrLog(...) do {} while (0)
|
||||||
#endif
|
#endif /* (USBD_DEBUG_LEVEL > 1U) */
|
||||||
|
|
||||||
#if (USBD_DEBUG_LEVEL > 2U)
|
#if (USBD_DEBUG_LEVEL > 2U)
|
||||||
#define USBD_DbgLog(...) do { \
|
#define USBD_DbgLog(...) do { \
|
||||||
@@ -161,7 +171,7 @@ extern "C" {
|
|||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define USBD_DbgLog(...) do {} while (0)
|
#define USBD_DbgLog(...) do {} while (0)
|
||||||
#endif
|
#endif /* (USBD_DEBUG_LEVEL > 2U) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -86,6 +86,20 @@ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
|
|||||||
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
USBD_StatusTypeDef USBD_RegisterDevStateCallback(USBD_HandleTypeDef *pdev, USBD_DevStateCallbackTypeDef pUserCallback);
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
|
|
||||||
|
#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, uint8_t ClassId);
|
||||||
|
#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_RunTestMode(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
@@ -128,11 +142,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,
|
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
uint8_t *pbuf, uint32_t size);
|
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);
|
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
uint32_t USBD_LL_GetRxDataSize(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_LL_Delay(uint32_t Delay);
|
||||||
|
|
||||||
|
void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr);
|
||||||
|
USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -52,6 +52,24 @@ extern "C" {
|
|||||||
#define USBD_MAX_NUM_CONFIGURATION 1U
|
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||||
#endif /* USBD_MAX_NUM_CONFIGURATION */
|
#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
|
#ifndef USBD_LPM_ENABLED
|
||||||
#define USBD_LPM_ENABLED 0U
|
#define USBD_LPM_ENABLED 0U
|
||||||
#endif /* USBD_LPM_ENABLED */
|
#endif /* USBD_LPM_ENABLED */
|
||||||
@@ -159,6 +177,14 @@ extern "C" {
|
|||||||
#define USBD_EP_TYPE_BULK 0x02U
|
#define USBD_EP_TYPE_BULK 0x02U
|
||||||
#define USBD_EP_TYPE_INTR 0x03U
|
#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 iConfiguration;
|
||||||
uint8_t bmAttributes;
|
uint8_t bmAttributes;
|
||||||
uint8_t bMaxPower;
|
uint8_t bMaxPower;
|
||||||
} USBD_ConfigDescTypedef;
|
} __PACKED USBD_ConfigDescTypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -195,7 +221,7 @@ typedef struct
|
|||||||
uint8_t bDescriptorType;
|
uint8_t bDescriptorType;
|
||||||
uint16_t wTotalLength;
|
uint16_t wTotalLength;
|
||||||
uint8_t bNumDeviceCaps;
|
uint8_t bNumDeviceCaps;
|
||||||
} USBD_BosDescTypedef;
|
} USBD_BosDescTypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -205,7 +231,14 @@ typedef struct
|
|||||||
uint8_t bmAttributes;
|
uint8_t bmAttributes;
|
||||||
uint16_t wMaxPacketSize;
|
uint16_t wMaxPacketSize;
|
||||||
uint8_t bInterval;
|
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;
|
struct _USBD_HandleTypeDef;
|
||||||
|
|
||||||
@@ -230,7 +263,7 @@ typedef struct _Device_cb
|
|||||||
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
} USBD_ClassTypeDef;
|
} USBD_ClassTypeDef;
|
||||||
|
|
||||||
@@ -263,23 +296,67 @@ typedef struct
|
|||||||
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
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))
|
#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||||
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
#endif
|
#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
} USBD_DescriptorsTypeDef;
|
} USBD_DescriptorsTypeDef;
|
||||||
|
|
||||||
/* USB Device handle structure */
|
/* USB Device handle structure */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t status;
|
|
||||||
uint32_t total_length;
|
uint32_t total_length;
|
||||||
uint32_t rem_length;
|
uint32_t rem_length;
|
||||||
uint32_t maxpacket;
|
uint32_t bInterval;
|
||||||
uint16_t is_used;
|
uint16_t maxpacket;
|
||||||
uint16_t bInterval;
|
uint8_t status;
|
||||||
|
uint8_t is_used;
|
||||||
|
uint8_t *pbuffer;
|
||||||
} USBD_EndpointTypeDef;
|
} 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 */
|
/* USB Device handle structure */
|
||||||
typedef struct _USBD_HandleTypeDef
|
typedef struct _USBD_HandleTypeDef
|
||||||
{
|
{
|
||||||
@@ -302,14 +379,40 @@ typedef struct _USBD_HandleTypeDef
|
|||||||
|
|
||||||
USBD_SetupReqTypedef request;
|
USBD_SetupReqTypedef request;
|
||||||
USBD_DescriptorsTypeDef *pDesc;
|
USBD_DescriptorsTypeDef *pDesc;
|
||||||
USBD_ClassTypeDef *pClass;
|
USBD_ClassTypeDef *pClass[USBD_MAX_SUPPORTED_CLASS];
|
||||||
void *pClassData;
|
void *pClassData;
|
||||||
void *pUserData;
|
void *pClassDataCmsit[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
void *pUserData[USBD_MAX_SUPPORTED_CLASS];
|
||||||
void *pData;
|
void *pData;
|
||||||
void *pBosDesc;
|
void *pBosDesc;
|
||||||
void *pConfDesc;
|
void *pConfDesc;
|
||||||
|
uint32_t classId;
|
||||||
|
uint32_t NumClasses;
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS];
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
void (* DevStateCallback)(uint8_t dev_state, uint8_t cfgidx); /*!< User Notification callback */
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
} USBD_HandleTypeDef;
|
} USBD_HandleTypeDef;
|
||||||
|
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
typedef void (*USBD_DevStateCallbackTypeDef)(uint8_t dev_state, uint8_t cfgidx); /*!< pointer to User callback function */
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
|
|
||||||
|
/* 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;
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -321,7 +424,9 @@ typedef struct _USBD_HandleTypeDef
|
|||||||
*/
|
*/
|
||||||
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
|
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
|
||||||
{
|
{
|
||||||
uint16_t _SwapVal, _Byte1, _Byte2;
|
uint16_t _SwapVal;
|
||||||
|
uint16_t _Byte1;
|
||||||
|
uint16_t _Byte2;
|
||||||
uint8_t *_pbuff = addr;
|
uint8_t *_pbuff = addr;
|
||||||
|
|
||||||
_Byte1 = *(uint8_t *)_pbuff;
|
_Byte1 = *(uint8_t *)_pbuff;
|
||||||
@@ -335,19 +440,19 @@ __STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
|
|||||||
|
|
||||||
#ifndef LOBYTE
|
#ifndef LOBYTE
|
||||||
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
|
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
|
||||||
#endif
|
#endif /* LOBYTE */
|
||||||
|
|
||||||
#ifndef HIBYTE
|
#ifndef HIBYTE
|
||||||
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
||||||
#endif
|
#endif /* HIBYTE */
|
||||||
|
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
#endif
|
#endif /* MIN */
|
||||||
|
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
#endif
|
#endif /* MAX */
|
||||||
|
|
||||||
#if defined ( __GNUC__ )
|
#if defined ( __GNUC__ )
|
||||||
#ifndef __weak
|
#ifndef __weak
|
||||||
|
|||||||
@@ -25,6 +25,10 @@
|
|||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
|
/*
|
||||||
|
* User to provide a unique ID to define the USB device serial number
|
||||||
|
* The use of UID_BASE register can be considered as an example
|
||||||
|
*/
|
||||||
#define DEVICE_ID1 (UID_BASE)
|
#define DEVICE_ID1 (UID_BASE)
|
||||||
#define DEVICE_ID2 (UID_BASE + 0x4U)
|
#define DEVICE_ID2 (UID_BASE + 0x4U)
|
||||||
#define DEVICE_ID3 (UID_BASE + 0x8U)
|
#define DEVICE_ID3 (UID_BASE + 0x8U)
|
||||||
@@ -43,7 +47,7 @@
|
|||||||
#define USBD_BB_URL_STR_DESC (uint8_t *)"www.st.com"
|
#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_ALTMODE0_STR_DESC (uint8_t *)"STM32 Alternate0 Mode"
|
||||||
#define USBD_BB_ALTMODE1_STR_DESC (uint8_t *)"STM32 Alternate1 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
|
#define USB_SIZ_STRING_SERIAL 0x1AU
|
||||||
|
|
||||||
@@ -51,7 +55,7 @@
|
|||||||
#define USB_SIZ_BOS_DESC 0x0CU
|
#define USB_SIZ_BOS_DESC 0x0CU
|
||||||
#elif (USBD_CLASS_BOS_ENABLED == 1)
|
#elif (USBD_CLASS_BOS_ENABLED == 1)
|
||||||
#define USB_SIZ_BOS_DESC 0x5DU
|
#define USB_SIZ_BOS_DESC 0x5DU
|
||||||
#endif
|
#endif /* USBD_LPM_ENABLED */
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
|
|||||||
@@ -233,6 +233,22 @@ uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
|||||||
return 0U;
|
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.
|
* @brief Static single allocation.
|
||||||
* @param size: Size of allocated memory
|
* @param size: Size of allocated memory
|
||||||
@@ -240,6 +256,7 @@ uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
|||||||
*/
|
*/
|
||||||
void *USBD_static_malloc(uint32_t size)
|
void *USBD_static_malloc(uint32_t size)
|
||||||
{
|
{
|
||||||
|
UNUSED(size);
|
||||||
static uint32_t mem[(sizeof(USBD_HID_HandleTypeDef) / 4) + 1]; /* On 32-bit boundary */
|
static uint32_t mem[(sizeof(USBD_HID_HandleTypeDef) / 4) + 1]; /* On 32-bit boundary */
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
@@ -251,7 +268,7 @@ void *USBD_static_malloc(uint32_t size)
|
|||||||
*/
|
*/
|
||||||
void USBD_static_free(void *p)
|
void USBD_static_free(void *p)
|
||||||
{
|
{
|
||||||
|
UNUSED(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,9 @@
|
|||||||
#include "usbd_ctlreq.h"
|
#include "usbd_ctlreq.h"
|
||||||
#include "usbd_ioreq.h"
|
#include "usbd_ioreq.h"
|
||||||
|
|
||||||
|
#ifdef USE_USBD_COMPOSITE
|
||||||
|
#include "usbd_composite_builder.h"
|
||||||
|
#endif /* USE_USBD_COMPOSITE */
|
||||||
|
|
||||||
/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY
|
/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY
|
||||||
* @{
|
* @{
|
||||||
@@ -43,7 +46,9 @@
|
|||||||
/** @defgroup USBD_REQ_Private_Defines
|
/** @defgroup USBD_REQ_Private_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
#ifndef USBD_MAX_STR_DESC_SIZ
|
||||||
|
#define USBD_MAX_STR_DESC_SIZ 64U
|
||||||
|
#endif /* USBD_MAX_STR_DESC_SIZ */
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -104,7 +109,7 @@ USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS:
|
case USB_REQ_TYPE_CLASS:
|
||||||
case USB_REQ_TYPE_VENDOR:
|
case USB_REQ_TYPE_VENDOR:
|
||||||
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
|
ret = (USBD_StatusTypeDef)pdev->pClass[pdev->classId]->Setup(pdev, req);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_TYPE_STANDARD:
|
case USB_REQ_TYPE_STANDARD:
|
||||||
@@ -162,6 +167,7 @@ USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
uint8_t idx;
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
@@ -176,7 +182,27 @@ USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
|
|
||||||
if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
|
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))
|
if ((req->wLength == 0U) && (ret == USBD_OK))
|
||||||
{
|
{
|
||||||
@@ -214,14 +240,26 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
{
|
{
|
||||||
USBD_EndpointTypeDef *pep;
|
USBD_EndpointTypeDef *pep;
|
||||||
uint8_t ep_addr;
|
uint8_t ep_addr;
|
||||||
|
uint8_t idx;
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
|
||||||
ep_addr = LOBYTE(req->wIndex);
|
ep_addr = LOBYTE(req->wIndex);
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS:
|
case USB_REQ_TYPE_CLASS:
|
||||||
case USB_REQ_TYPE_VENDOR:
|
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;
|
break;
|
||||||
|
|
||||||
case USB_REQ_TYPE_STANDARD:
|
case USB_REQ_TYPE_STANDARD:
|
||||||
@@ -284,7 +322,18 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
(void)USBD_LL_ClearStallEP(pdev, ep_addr);
|
(void)USBD_LL_ClearStallEP(pdev, ep_addr);
|
||||||
}
|
}
|
||||||
(void)USBD_CtlSendStatus(pdev);
|
(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;
|
break;
|
||||||
|
|
||||||
@@ -374,7 +423,7 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
* Handle Get Descriptor requests
|
* Handle Get Descriptor requests
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param req: usb request
|
* @param req: usb request
|
||||||
* @retval status
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
@@ -396,7 +445,7 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
|||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1U) */
|
||||||
case USB_DESC_TYPE_DEVICE:
|
case USB_DESC_TYPE_DEVICE:
|
||||||
pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
|
pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
|
||||||
break;
|
break;
|
||||||
@@ -404,12 +453,30 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
|||||||
case USB_DESC_TYPE_CONFIGURATION:
|
case USB_DESC_TYPE_CONFIGURATION:
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
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;
|
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
|
||||||
}
|
}
|
||||||
else
|
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;
|
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -491,33 +558,43 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
#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
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
{
|
|
||||||
USBD_CtlError(pdev, req);
|
|
||||||
err++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (USBD_CLASS_USER_STRING_DESC == 1U)
|
#if (USBD_CLASS_USER_STRING_DESC == 1U)
|
||||||
if (pdev->pDesc->GetUserStrDescriptor != NULL)
|
if (pdev->pDesc->GetUserStrDescriptor != NULL)
|
||||||
{
|
{
|
||||||
pbuf = pdev->pDesc->GetUserStrDescriptor(pdev->dev_speed, (req->wValue), &len);
|
pbuf = pdev->pDesc->GetUserStrDescriptor(pdev->dev_speed, LOBYTE(req->wValue), &len);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError(pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
err++;
|
err++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||||
|
|
||||||
#if ((USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U))
|
#if ((USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U))
|
||||||
USBD_CtlError(pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
err++;
|
err++;
|
||||||
#endif
|
#endif /* (USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U) */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -525,7 +602,16 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
|||||||
case USB_DESC_TYPE_DEVICE_QUALIFIER:
|
case USB_DESC_TYPE_DEVICE_QUALIFIER:
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -537,7 +623,16 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
|||||||
case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION:
|
case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION:
|
||||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
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;
|
pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -582,7 +677,7 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *r
|
|||||||
* Set device address
|
* Set device address
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param req: usb request
|
* @param req: usb request
|
||||||
* @retval status
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void USBD_SetAddress(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
@@ -650,11 +745,19 @@ static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReq
|
|||||||
if (ret != USBD_OK)
|
if (ret != USBD_OK)
|
||||||
{
|
{
|
||||||
USBD_CtlError(pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
|
pdev->dev_state = USBD_STATE_ADDRESSED;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(void)USBD_CtlSendStatus(pdev);
|
(void)USBD_CtlSendStatus(pdev);
|
||||||
pdev->dev_state = USBD_STATE_CONFIGURED;
|
pdev->dev_state = USBD_STATE_CONFIGURED;
|
||||||
|
|
||||||
|
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||||
|
if (pdev->DevStateCallback != NULL)
|
||||||
|
{
|
||||||
|
pdev->DevStateCallback(USBD_STATE_CONFIGURED, cfgidx);
|
||||||
|
}
|
||||||
|
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -713,7 +816,7 @@ static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReq
|
|||||||
* Handle Get device configuration request
|
* Handle Get device configuration request
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param req: usb request
|
* @param req: usb request
|
||||||
* @retval status
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
@@ -747,7 +850,7 @@ static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
* Handle Get Status request
|
* Handle Get Status request
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param req: usb request
|
* @param req: usb request
|
||||||
* @retval status
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
@@ -766,7 +869,7 @@ static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
pdev->dev_config_status = USB_CONFIG_SELF_POWERED;
|
pdev->dev_config_status = USB_CONFIG_SELF_POWERED;
|
||||||
#else
|
#else
|
||||||
pdev->dev_config_status = 0U;
|
pdev->dev_config_status = 0U;
|
||||||
#endif
|
#endif /* USBD_SELF_POWERED */
|
||||||
|
|
||||||
if (pdev->dev_remote_wakeup != 0U)
|
if (pdev->dev_remote_wakeup != 0U)
|
||||||
{
|
{
|
||||||
@@ -788,7 +891,7 @@ static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
* Handle Set device feature request
|
* Handle Set device feature request
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param req: usb request
|
* @param req: usb request
|
||||||
* @retval status
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
@@ -797,6 +900,15 @@ static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
pdev->dev_remote_wakeup = 1U;
|
pdev->dev_remote_wakeup = 1U;
|
||||||
(void)USBD_CtlSendStatus(pdev);
|
(void)USBD_CtlSendStatus(pdev);
|
||||||
}
|
}
|
||||||
|
else if (req->wValue == USB_FEATURE_TEST_MODE)
|
||||||
|
{
|
||||||
|
pdev->dev_test_mode = (uint8_t)(req->wIndex >> 8);
|
||||||
|
(void)USBD_CtlSendStatus(pdev);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
USBD_CtlError(pdev, req);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -805,7 +917,7 @@ static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
* Handle clear device feature request
|
* Handle clear device feature request
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param req: usb request
|
* @param req: usb request
|
||||||
* @retval status
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
@@ -831,8 +943,8 @@ static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
/**
|
/**
|
||||||
* @brief USBD_ParseSetupRequest
|
* @brief USBD_ParseSetupRequest
|
||||||
* Copy buffer into setup structure
|
* Copy buffer into setup structure
|
||||||
* @param pdev: device instance
|
|
||||||
* @param req: usb request
|
* @param req: usb request
|
||||||
|
* @param pdata: setup data pointer
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata)
|
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata)
|
||||||
@@ -892,7 +1004,7 @@ void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pdesc = desc;
|
pdesc = desc;
|
||||||
*len = ((uint16_t)USBD_GetLen(pdesc) * 2U) + 2U;
|
*len = MIN(USBD_MAX_STR_DESC_SIZ, ((uint16_t)USBD_GetLen(pdesc) * 2U) + 2U);
|
||||||
|
|
||||||
unicode[idx] = *(uint8_t *)len;
|
unicode[idx] = *(uint8_t *)len;
|
||||||
idx++;
|
idx++;
|
||||||
|
|||||||
@@ -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))
|
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||||
uint8_t *USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
#endif
|
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
USBD_DescriptorsTypeDef Class_Desc =
|
USBD_DescriptorsTypeDef Class_Desc =
|
||||||
@@ -65,18 +65,18 @@ USBD_DescriptorsTypeDef Class_Desc =
|
|||||||
USBD_Class_ConfigStrDescriptor,
|
USBD_Class_ConfigStrDescriptor,
|
||||||
USBD_Class_InterfaceStrDescriptor,
|
USBD_Class_InterfaceStrDescriptor,
|
||||||
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
USBD_CLASS_UserStrDescriptor,
|
USBD_Class_UserStrDescriptor,
|
||||||
#endif
|
#endif /* USB_CLASS_USER_STRING_DESC */
|
||||||
|
|
||||||
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||||
USBD_USR_BOSDescriptor,
|
USBD_USR_BOSDescriptor,
|
||||||
#endif
|
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
0x12, /* bLength */
|
0x12, /* bLength */
|
||||||
@@ -86,7 +86,7 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
|||||||
in order to support BOS Desc */
|
in order to support BOS Desc */
|
||||||
#else
|
#else
|
||||||
0x00, /* bcdUSB */
|
0x00, /* bcdUSB */
|
||||||
#endif
|
#endif /* (USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||||
0x02,
|
0x02,
|
||||||
0x00, /* bDeviceClass */
|
0x00, /* bDeviceClass */
|
||||||
0x00, /* bDeviceSubClass */
|
0x00, /* bDeviceSubClass */
|
||||||
@@ -109,7 +109,7 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
|||||||
#if (USBD_LPM_ENABLED == 1)
|
#if (USBD_LPM_ENABLED == 1)
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
0x5,
|
0x5,
|
||||||
@@ -126,13 +126,13 @@ __ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
|||||||
0x0,
|
0x0,
|
||||||
0x0
|
0x0
|
||||||
};
|
};
|
||||||
#endif
|
#endif /* USBD_LPM_ENABLED */
|
||||||
|
|
||||||
/* USB Device Billboard BOS descriptor Template */
|
/* USB Device Billboard BOS descriptor Template */
|
||||||
#if (USBD_CLASS_BOS_ENABLED == 1)
|
#if (USBD_CLASS_BOS_ENABLED == 1)
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
0x05, /* bLength */
|
0x05, /* bLength */
|
||||||
@@ -155,14 +155,16 @@ __ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
|||||||
0x34, /* bLength */
|
0x34, /* bLength */
|
||||||
0x10, /* bDescriptorType: DEVICE CAPABILITY Type */
|
0x10, /* bDescriptorType: DEVICE CAPABILITY Type */
|
||||||
0x0D, /* bDevCapabilityType: BILLBOARD_CAPABILITY */
|
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
|
USBD_BB_URL_STRING_INDEX, /* iAddtionalInfoURL: Index of string descriptor providing a URL where the user
|
||||||
detailed information about the product and the various Alternate Modes it supports */
|
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
|
0x02, /* bNumberOfAlternateModes: Number of Alternate modes supported. The
|
||||||
maximum value that this field can be set to is MAX_NUM_ALT_MODE. */
|
maximum value that this field can be set to is MAX_NUM_ALT_MODE. */
|
||||||
|
|
||||||
0x00, /* bPreferredAlternateMode: Index of the preferred Alternate Mode. System
|
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 */
|
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 */
|
0x10, /* bDescriptorType: Device Descriptor Type */
|
||||||
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
|
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
|
||||||
0x00, /* bIndex: Index of Alternate Mode described in the Billboard Capability Desc */
|
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 */
|
0x08, /* bLength */
|
||||||
0x10, /* bDescriptorType: Device Descriptor Type */
|
0x10, /* bDescriptorType: Device Descriptor Type */
|
||||||
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
|
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
|
||||||
0x01, /* bIndex: Index of Alternate Mode described in the Billboard Capability Desc */
|
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 */
|
/* USB Standard Device Descriptor */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
USB_LEN_LANGID_STR_DESC,
|
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 */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
|
__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
|
||||||
{
|
{
|
||||||
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 */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif /* __ICCARM__ */
|
||||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
@@ -370,7 +374,9 @@ uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *le
|
|||||||
*/
|
*/
|
||||||
static void Get_SerialNum(void)
|
static void Get_SerialNum(void)
|
||||||
{
|
{
|
||||||
uint32_t deviceserial0, deviceserial1, deviceserial2;
|
uint32_t deviceserial0;
|
||||||
|
uint32_t deviceserial1;
|
||||||
|
uint32_t deviceserial2;
|
||||||
|
|
||||||
deviceserial0 = *(uint32_t *)DEVICE_ID1;
|
deviceserial0 = *(uint32_t *)DEVICE_ID1;
|
||||||
deviceserial1 = *(uint32_t *)DEVICE_ID2;
|
deviceserial1 = *(uint32_t *)DEVICE_ID2;
|
||||||
@@ -399,7 +405,7 @@ uint8_t *USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
|||||||
*length = sizeof(USBD_BOSDesc);
|
*length = sizeof(USBD_BOSDesc);
|
||||||
return (uint8_t *)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)
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
@@ -416,7 +422,7 @@ uint8_t *USBD_Class_UserStrDescriptor(USBD_SpeedTypeDef speed, uint8_t idx, uint
|
|||||||
|
|
||||||
return USBD_StrDesc;
|
return USBD_StrDesc;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* USBD_CLASS_USER_STRING_DESC */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -89,12 +89,13 @@ USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
|||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_DATA_IN;
|
pdev->ep0_state = USBD_EP0_DATA_IN;
|
||||||
pdev->ep_in[0].total_length = len;
|
pdev->ep_in[0].total_length = len;
|
||||||
|
pdev->ep_in[0].pbuffer = pbuf;
|
||||||
|
|
||||||
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||||
pdev->ep_in[0].rem_length = 0U;
|
pdev->ep_in[0].rem_length = 0U;
|
||||||
#else
|
#else
|
||||||
pdev->ep_in[0].rem_length = len;
|
pdev->ep_in[0].rem_length = len;
|
||||||
#endif
|
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
|
||||||
|
|
||||||
/* Start the transfer */
|
/* Start the transfer */
|
||||||
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||||
@@ -133,12 +134,13 @@ USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
|||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
||||||
pdev->ep_out[0].total_length = len;
|
pdev->ep_out[0].total_length = len;
|
||||||
|
pdev->ep_out[0].pbuffer = pbuf;
|
||||||
|
|
||||||
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||||
pdev->ep_out[0].rem_length = 0U;
|
pdev->ep_out[0].rem_length = 0U;
|
||||||
#else
|
#else
|
||||||
pdev->ep_out[0].rem_length = len;
|
pdev->ep_out[0].rem_length = len;
|
||||||
#endif
|
#endif /* USBD_AVOID_PACKET_SPLIT_MPS */
|
||||||
|
|
||||||
/* Start the transfer */
|
/* Start the transfer */
|
||||||
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||||
|
|||||||
86
LICENSE.txt
86
LICENSE.txt
@@ -1,86 +0,0 @@
|
|||||||
This software component is provided to you as part of a software package and
|
|
||||||
applicable license terms are in the Package_license file. If you received this
|
|
||||||
software component outside of a package or without applicable license terms,
|
|
||||||
the terms of the SLA0044 license shall apply and are fully reproduced below:
|
|
||||||
|
|
||||||
SLA0044 Rev5/February 2018
|
|
||||||
|
|
||||||
Software license agreement
|
|
||||||
|
|
||||||
ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT
|
|
||||||
|
|
||||||
BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE
|
|
||||||
OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS
|
|
||||||
INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES
|
|
||||||
(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON
|
|
||||||
BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES
|
|
||||||
TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT.
|
|
||||||
|
|
||||||
Under STMicroelectronics’ intellectual property rights, the redistribution,
|
|
||||||
reproduction and use in source and binary forms of the software or any part
|
|
||||||
thereof, with or without modification, are permitted provided that the following
|
|
||||||
conditions are met:
|
|
||||||
|
|
||||||
1. Redistribution of source code (modified or not) must retain any copyright
|
|
||||||
notice, this list of conditions and the disclaimer set forth below as items 10
|
|
||||||
and 11.
|
|
||||||
|
|
||||||
2. Redistributions in binary form, except as embedded into microcontroller or
|
|
||||||
microprocessor device manufactured by or for STMicroelectronics or a software
|
|
||||||
update for such device, must reproduce any copyright notice provided with the
|
|
||||||
binary code, this list of conditions, and the disclaimer set forth below as
|
|
||||||
items 10 and 11, in documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
3. Neither the name of STMicroelectronics nor the names of other contributors to
|
|
||||||
this software may be used to endorse or promote products derived from this
|
|
||||||
software or part thereof without specific written permission.
|
|
||||||
|
|
||||||
4. This software or any part thereof, including modifications and/or derivative
|
|
||||||
works of this software, must be used and execute solely and exclusively on or in
|
|
||||||
combination with a microcontroller or microprocessor device manufactured by or
|
|
||||||
for STMicroelectronics.
|
|
||||||
|
|
||||||
5. No use, reproduction or redistribution of this software partially or totally
|
|
||||||
may be done in any manner that would subject this software to any Open Source
|
|
||||||
Terms. “Open Source Terms” shall mean any open source license which requires as
|
|
||||||
part of distribution of software that the source code of such software is
|
|
||||||
distributed therewith or otherwise made available, or open source license that
|
|
||||||
substantially complies with the Open Source definition specified at
|
|
||||||
www.opensource.org and any other comparable open source license such as for
|
|
||||||
example GNU General Public License (GPL), Eclipse Public License (EPL), Apache
|
|
||||||
Software License, BSD license or MIT license.
|
|
||||||
|
|
||||||
6. STMicroelectronics has no obligation to provide any maintenance, support or
|
|
||||||
updates for the software.
|
|
||||||
|
|
||||||
7. The software is and will remain the exclusive property of STMicroelectronics
|
|
||||||
and its licensors. The recipient will not take any action that jeopardizes
|
|
||||||
STMicroelectronics and its licensors' proprietary rights or acquire any rights
|
|
||||||
in the software, except the limited rights specified hereunder.
|
|
||||||
|
|
||||||
8. The recipient shall comply with all applicable laws and regulations affecting
|
|
||||||
the use of the software or any part thereof including any applicable export
|
|
||||||
control law or regulation.
|
|
||||||
|
|
||||||
9. Redistribution and use of this software or any part thereof other than as
|
|
||||||
permitted under this license is void and will automatically terminate your
|
|
||||||
rights under this license.
|
|
||||||
|
|
||||||
10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE
|
|
||||||
DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL
|
|
||||||
STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
||||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
||||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
||||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER
|
|
||||||
EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY
|
|
||||||
RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY.
|
|
||||||
|
|
||||||
32
README.md
32
README.md
@@ -1,29 +1,31 @@
|
|||||||
# Middleware USB Device MCU Component
|
# Middleware USB Device MCU Component
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
**STM32Cube** is an STMicroelectronics original initiative to ease the developers life by reducing efforts, time and cost.
|
**STM32Cube** is an STMicroelectronics original initiative to ease developers' life by reducing efforts, time and cost.
|
||||||
|
|
||||||
**STM32Cube** covers the overall STM32 products portfolio. It includes a comprehensive embedded software platform, delivered for each STM32 series.
|
**STM32Cube** covers the overall STM32 products portfolio. It includes a comprehensive embedded software platform delivered for each STM32 series.
|
||||||
* The CMSIS modules (core and device) corresponding to the ARM(tm) core implemented in this STM32 product.
|
* The CMSIS modules (core and device) corresponding to the ARM(tm) core implemented in this STM32 product.
|
||||||
* The STM32 HAL-LL drivers : an abstraction drivers layer, the API ensuring maximized portability across the STM32 portfolio.
|
* The STM32 HAL-LL drivers, an abstraction layer offering a set of APIs ensuring maximized portability across the STM32 portfolio.
|
||||||
* The BSP Drivers of each evaluation or demonstration board provided by this STM32 series.
|
* The BSP drivers of each evaluation, demonstration or nucleo board provided for this STM32 series.
|
||||||
* A consistent set of middlewares components such as RTOS, USB, FatFS, Graphics, STM32_TouchSensing_Library...
|
* A consistent set of middleware libraries such as RTOS, USB, FatFS, graphics, touch sensing library...
|
||||||
* A full set of software projects (basic examples, applications or demonstrations) for each board provided by this STM32 series.
|
* A full set of software projects (basic examples, applications, and demonstrations) for each board provided for this STM32 series.
|
||||||
|
|
||||||
Two models of publication are proposed for the STM32Cube embedded software:
|
Two models of publication are proposed for the STM32Cube embedded software:
|
||||||
* The monolithic **MCU Package** : all STM32Cube software modules of one STM32 series are present (Drivers, Middlewares, Projects, Utilities) in the repo (usual name **STM32Cubexx**, xx corresponding to the STM32 series).
|
* The monolithic **MCU Package**: all STM32Cube software modules of one STM32 series are present (Drivers, Middleware, Projects, Utilities) in the repository (usual name **STM32Cubexx**, xx corresponding to the STM32 series).
|
||||||
* The **MCU component** : progressively from November 2019, each STM32Cube software module being part of the STM32Cube MCU Package, will be delivered as an individual repo, allowing the user to select and get only the required software functions.
|
* The **MCU component**: each STM32Cube software module being part of the STM32Cube MCU Package, is delivered as an individual repository, allowing the user to select and get only the required software functions.
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
This **stm32_mw_usb_device** MCU component repository is one element **common to all** STM32Cube MCU embedded software packages, providing the **USB Device MCU Middleware** part.
|
This **stm32_mw_usb_device** MCU component repository is one element **common to all** STM32Cube MCU embedded software packages, providing the **USB Device MCU Middleware** part.
|
||||||
|
|
||||||
## License
|
It represents ST offer to ensure the support of USB Devices on STM32 MCUs.
|
||||||
|
It includes two main modules:
|
||||||
Copyright (c) 2015 STMicroelectronics.
|
* **Core** module for the USB device standard peripheral control APIs. It includes the files ensuring USB 2.0 standard code implementation for an USB device.
|
||||||
|
These files’ APIs will be called within every USB device application regardless of the desired functionality.
|
||||||
This software component is licensed by ST under Ultimate Liberty license SLA0044, the "License". You may not use this file except in compliance with this license. You may obtain a copy of the license [here](https://www.st.com/SLA0044).
|
* **Class** module for the commonly supported classes APIs. it includes the files including different USB device classes. All STM32 USB classes are implemented according to the USB 2.0 and every class’s specifications. These files’ APIs will be called within USB device applications according to the desired functionality.
|
||||||
|
|
||||||
## Release note
|
## Release note
|
||||||
|
|
||||||
@@ -31,6 +33,4 @@ Details about the content of this release are available in the release note [her
|
|||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
If you have any issue with the **software content** of this repository, you can file an issue [here](https://github.com/STMicroelectronics/stm32_mw_usb_device/issues/new/choose).
|
Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) guide.
|
||||||
|
|
||||||
For any other question related to the product, the tools, the environment, you can submit a topic to the [ST Community](https://community.st.com/s/).
|
|
||||||
2664
Release_Notes.html
2664
Release_Notes.html
File diff suppressed because it is too large
Load Diff
BIN
_htmresc/favicon.png
Normal file
BIN
_htmresc/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
1711
_htmresc/mini-st.css
Normal file
1711
_htmresc/mini-st.css
Normal file
File diff suppressed because it is too large
Load Diff
BIN
_htmresc/st_logo_2020.png
Normal file
BIN
_htmresc/st_logo_2020.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.3 KiB |
Reference in New Issue
Block a user