mirror of
https://github.com/STMicroelectronics/stm32-mw-usb-device.git
synced 2026-02-09 04:25:36 -05:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06808a92fe | ||
|
|
5af065de85 | ||
|
|
60d163f271 | ||
|
|
d1a9b6baea | ||
|
|
edbaa3cd1d | ||
|
|
228c5c57ea |
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -50,6 +49,14 @@ extern "C" {
|
||||
#define USBD_MAX_NUM_INTERFACES 1U
|
||||
#endif /* USBD_AUDIO_FREQ */
|
||||
|
||||
#ifndef AUDIO_HS_BINTERVAL
|
||||
#define AUDIO_HS_BINTERVAL 0x01U
|
||||
#endif /* AUDIO_HS_BINTERVAL */
|
||||
|
||||
#ifndef AUDIO_FS_BINTERVAL
|
||||
#define AUDIO_FS_BINTERVAL 0x01U
|
||||
#endif /* AUDIO_FS_BINTERVAL */
|
||||
|
||||
#define AUDIO_OUT_EP 0x01U
|
||||
#define USB_AUDIO_CONFIG_DESC_SIZ 0x6DU
|
||||
#define AUDIO_INTERFACE_DESC_SIZE 0x09U
|
||||
@@ -91,6 +98,9 @@ extern "C" {
|
||||
|
||||
#define AUDIO_OUT_STREAMING_CTRL 0x02U
|
||||
|
||||
#define AUDIO_OUT_TC 0x01U
|
||||
#define AUDIO_IN_TC 0x02U
|
||||
|
||||
|
||||
#define AUDIO_OUT_PACKET (uint16_t)(((USBD_AUDIO_FREQ * 2U * 2U) / 1000U))
|
||||
#define AUDIO_DEFAULT_VOLUME 70U
|
||||
@@ -116,8 +126,7 @@ typedef enum
|
||||
AUDIO_OFFSET_HALF,
|
||||
AUDIO_OFFSET_FULL,
|
||||
AUDIO_OFFSET_UNKNOWN,
|
||||
}
|
||||
AUDIO_OffsetTypeDef;
|
||||
} AUDIO_OffsetTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -132,32 +141,29 @@ typedef struct
|
||||
uint8_t data[USB_MAX_EP0_SIZE];
|
||||
uint8_t len;
|
||||
uint8_t unit;
|
||||
}
|
||||
USBD_AUDIO_ControlTypeDef;
|
||||
|
||||
} USBD_AUDIO_ControlTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t alt_setting;
|
||||
uint8_t buffer[AUDIO_TOTAL_BUF_SIZE];
|
||||
AUDIO_OffsetTypeDef offset;
|
||||
uint8_t rd_enable;
|
||||
uint16_t rd_ptr;
|
||||
uint16_t wr_ptr;
|
||||
uint32_t alt_setting;
|
||||
uint8_t buffer[AUDIO_TOTAL_BUF_SIZE];
|
||||
AUDIO_OffsetTypeDef offset;
|
||||
uint8_t rd_enable;
|
||||
uint16_t rd_ptr;
|
||||
uint16_t wr_ptr;
|
||||
USBD_AUDIO_ControlTypeDef control;
|
||||
}
|
||||
USBD_AUDIO_HandleTypeDef;
|
||||
} USBD_AUDIO_HandleTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int8_t (*Init)(uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||
int8_t (*Init)(uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||
int8_t (*DeInit)(uint32_t options);
|
||||
int8_t (*AudioCmd)(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||
int8_t (*VolumeCtl)(uint8_t vol);
|
||||
int8_t (*MuteCtl)(uint8_t cmd);
|
||||
int8_t (*PeriodicTC)(uint8_t cmd);
|
||||
int8_t (*PeriodicTC)(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||
int8_t (*GetState)(void);
|
||||
} USBD_AUDIO_ItfTypeDef;
|
||||
/**
|
||||
@@ -178,8 +184,8 @@ typedef struct
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_AUDIO;
|
||||
#define USBD_AUDIO_CLASS &USBD_AUDIO
|
||||
extern USBD_ClassTypeDef USBD_AUDIO;
|
||||
#define USBD_AUDIO_CLASS &USBD_AUDIO
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -187,10 +193,10 @@ extern USBD_ClassTypeDef USBD_AUDIO;
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops);
|
||||
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops);
|
||||
|
||||
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
||||
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -207,5 +213,3 @@ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -41,5 +40,3 @@ extern USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops;
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_AUDIO_IF_TEMPLATE_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -4,6 +4,18 @@
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the Audio core functions.
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2015 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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
@@ -38,18 +50,6 @@
|
||||
*
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
@@ -93,10 +93,11 @@ EndBSPDependencies */
|
||||
/** @defgroup USBD_AUDIO_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
#define AUDIO_SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
#define AUDIO_SAMPLE_FREQ(frq) \
|
||||
(uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
|
||||
#define AUDIO_PACKET_SZE(frq) (uint8_t)(((frq * 2U * 2U)/1000U) & 0xFFU), \
|
||||
(uint8_t)((((frq * 2U * 2U)/1000U) >> 8) & 0xFFU)
|
||||
#define AUDIO_PACKET_SZE(frq) \
|
||||
(uint8_t)(((frq * 2U * 2U) / 1000U) & 0xFFU), (uint8_t)((((frq * 2U * 2U) / 1000U) >> 8) & 0xFFU)
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -133,7 +134,7 @@ static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_ClassTypeDef USBD_AUDIO =
|
||||
USBD_ClassTypeDef USBD_AUDIO =
|
||||
{
|
||||
USBD_AUDIO_Init,
|
||||
USBD_AUDIO_DeInit,
|
||||
@@ -157,13 +158,17 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
||||
/* Configuration 1 */
|
||||
0x09, /* bLength */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType */
|
||||
LOBYTE(USB_AUDIO_CONFIG_DESC_SIZ), /* wTotalLength 109 bytes*/
|
||||
LOBYTE(USB_AUDIO_CONFIG_DESC_SIZ), /* wTotalLength */
|
||||
HIBYTE(USB_AUDIO_CONFIG_DESC_SIZ),
|
||||
0x02, /* bNumInterfaces */
|
||||
0x01, /* bConfigurationValue */
|
||||
0x00, /* iConfiguration */
|
||||
0xC0, /* bmAttributes BUS Powred*/
|
||||
0x32, /* bMaxPower = 100 mA*/
|
||||
#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) */
|
||||
/* 09 byte*/
|
||||
|
||||
/* USB Speaker Standard interface descriptor */
|
||||
@@ -184,7 +189,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
||||
AUDIO_CONTROL_HEADER, /* bDescriptorSubtype */
|
||||
0x00, /* 1.00 */ /* bcdADC */
|
||||
0x01,
|
||||
0x27, /* wTotalLength = 39*/
|
||||
0x27, /* wTotalLength */
|
||||
0x00,
|
||||
0x01, /* bInCollection */
|
||||
0x01, /* baInterfaceNr */
|
||||
@@ -215,24 +220,24 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
||||
AUDIO_CONTROL_MUTE, /* bmaControls(0) */
|
||||
0, /* bmaControls(1) */
|
||||
0x00, /* iTerminal */
|
||||
/* 09 byte*/
|
||||
/* 09 byte */
|
||||
|
||||
/*USB Speaker Output Terminal Descriptor */
|
||||
/* USB Speaker Output Terminal Descriptor */
|
||||
0x09, /* bLength */
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_CONTROL_OUTPUT_TERMINAL, /* bDescriptorSubtype */
|
||||
0x03, /* bTerminalID */
|
||||
0x01, /* wTerminalType 0x0301*/
|
||||
0x01, /* wTerminalType 0x0301 */
|
||||
0x03,
|
||||
0x00, /* bAssocTerminal */
|
||||
0x02, /* bSourceID */
|
||||
0x00, /* iTerminal */
|
||||
/* 09 byte*/
|
||||
/* 09 byte */
|
||||
|
||||
/* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwith */
|
||||
/* Interface 1, Alternate Setting 0 */
|
||||
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
|
||||
/* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwidth */
|
||||
/* Interface 1, Alternate Setting 0 */
|
||||
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
|
||||
0x01, /* bInterfaceNumber */
|
||||
0x00, /* bAlternateSetting */
|
||||
0x00, /* bNumEndpoints */
|
||||
@@ -244,8 +249,8 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
||||
|
||||
/* USB Speaker Standard AS Interface Descriptor - Audio Streaming Operational */
|
||||
/* Interface 1, Alternate Setting 1 */
|
||||
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
|
||||
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
|
||||
0x01, /* bInterfaceNumber */
|
||||
0x01, /* bAlternateSetting */
|
||||
0x01, /* bNumEndpoints */
|
||||
@@ -261,7 +266,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
||||
AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */
|
||||
0x01, /* bTerminalLink */
|
||||
0x01, /* bDelay */
|
||||
0x01, /* wFormatTag AUDIO_FORMAT_PCM 0x0001*/
|
||||
0x01, /* wFormatTag AUDIO_FORMAT_PCM 0x0001 */
|
||||
0x00,
|
||||
/* 07 byte*/
|
||||
|
||||
@@ -269,26 +274,26 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
||||
0x0B, /* bLength */
|
||||
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_STREAMING_FORMAT_TYPE, /* bDescriptorSubtype */
|
||||
AUDIO_FORMAT_TYPE_I, /* bFormatType */
|
||||
AUDIO_FORMAT_TYPE_I, /* bFormatType */
|
||||
0x02, /* bNrChannels */
|
||||
0x02, /* bSubFrameSize : 2 Bytes per frame (16bits) */
|
||||
16, /* bBitResolution (16-bits per sample) */
|
||||
0x01, /* bSamFreqType only one frequency supported */
|
||||
AUDIO_SAMPLE_FREQ(USBD_AUDIO_FREQ), /* Audio sampling frequency coded on 3 bytes */
|
||||
AUDIO_SAMPLE_FREQ(USBD_AUDIO_FREQ), /* Audio sampling frequency coded on 3 bytes */
|
||||
/* 11 byte*/
|
||||
|
||||
/* Endpoint 1 - Standard Descriptor */
|
||||
AUDIO_STANDARD_ENDPOINT_DESC_SIZE, /* bLength */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType */
|
||||
AUDIO_OUT_EP, /* bEndpointAddress 1 out endpoint*/
|
||||
AUDIO_OUT_EP, /* bEndpointAddress 1 out endpoint */
|
||||
USBD_EP_TYPE_ISOC, /* bmAttributes */
|
||||
AUDIO_PACKET_SZE(USBD_AUDIO_FREQ), /* wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
|
||||
0x01, /* bInterval */
|
||||
AUDIO_FS_BINTERVAL, /* bInterval */
|
||||
0x00, /* bRefresh */
|
||||
0x00, /* bSynchAddress */
|
||||
/* 09 byte*/
|
||||
|
||||
/* Endpoint - Audio Streaming Descriptor*/
|
||||
/* Endpoint - Audio Streaming Descriptor */
|
||||
AUDIO_STREAMING_ENDPOINT_DESC_SIZE, /* bLength */
|
||||
AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||
AUDIO_ENDPOINT_GENERAL, /* bDescriptor */
|
||||
@@ -329,44 +334,54 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIE
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, AUDIO_OUT_EP, USBD_EP_TYPE_ISOC, AUDIO_OUT_PACKET);
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 1U;
|
||||
UNUSED(cfgidx);
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
|
||||
/* Allocate Audio structure */
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_AUDIO_HandleTypeDef));
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *)USBD_malloc(sizeof(USBD_AUDIO_HandleTypeDef));
|
||||
|
||||
if (pdev->pClassData == NULL)
|
||||
if (haudio == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
haudio->alt_setting = 0U;
|
||||
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
||||
haudio->wr_ptr = 0U;
|
||||
haudio->rd_ptr = 0U;
|
||||
haudio->rd_enable = 0U;
|
||||
|
||||
/* Initialize the Audio output Hardware layer */
|
||||
if (((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->Init(USBD_AUDIO_FREQ,
|
||||
AUDIO_DEFAULT_VOLUME,
|
||||
0U) != 0)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Prepare Out endpoint to receive 1st packet */
|
||||
USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, haudio->buffer,
|
||||
AUDIO_OUT_PACKET);
|
||||
pdev->pClassData = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
pdev->pClassData = (void *)haudio;
|
||||
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].bInterval = AUDIO_HS_BINTERVAL;
|
||||
}
|
||||
else /* LOW and FULL-speed endpoints */
|
||||
{
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].bInterval = AUDIO_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
/* Open EP OUT */
|
||||
(void)USBD_LL_OpenEP(pdev, AUDIO_OUT_EP, USBD_EP_TYPE_ISOC, AUDIO_OUT_PACKET);
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 1U;
|
||||
|
||||
haudio->alt_setting = 0U;
|
||||
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
||||
haudio->wr_ptr = 0U;
|
||||
haudio->rd_ptr = 0U;
|
||||
haudio->rd_enable = 0U;
|
||||
|
||||
/* Initialize the Audio output Hardware layer */
|
||||
if (((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->Init(USBD_AUDIO_FREQ,
|
||||
AUDIO_DEFAULT_VOLUME,
|
||||
0U) != 0U)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Prepare Out endpoint to receive 1st packet */
|
||||
(void)USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, haudio->buffer,
|
||||
AUDIO_OUT_PACKET);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -376,22 +391,24 @@ static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_CloseEP(pdev, AUDIO_OUT_EP);
|
||||
(void)USBD_LL_CloseEP(pdev, AUDIO_OUT_EP);
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 0U;
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].bInterval = 0U;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0U);
|
||||
USBD_free(pdev->pClassData);
|
||||
(void)USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -401,20 +418,25 @@ static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
uint16_t len;
|
||||
uint8_t *pbuf;
|
||||
uint16_t status_info = 0U;
|
||||
uint8_t ret = USBD_OK;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (haudio == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
@@ -438,7 +460,7 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -453,14 +475,14 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
pbuf = USBD_AUDIO_CfgDesc + 18;
|
||||
len = MIN(USB_AUDIO_DESC_SIZ, req->wLength);
|
||||
|
||||
USBD_CtlSendData(pdev, pbuf, len);
|
||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&haudio->alt_setting, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&haudio->alt_setting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -469,7 +491,7 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES)
|
||||
@@ -478,7 +500,7 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
/* Call the error management function (command will be NAKed */
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
@@ -490,6 +512,9 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
@@ -502,20 +527,19 @@ static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_GetCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length)
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_AUDIO_CfgDesc);
|
||||
*length = (uint16_t)sizeof(USBD_AUDIO_CfgDesc);
|
||||
|
||||
return USBD_AUDIO_CfgDesc;
|
||||
}
|
||||
@@ -527,10 +551,13 @@ static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(epnum);
|
||||
|
||||
/* Only OUT data are processed */
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,10 +566,15 @@ static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (haudio == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
if (haudio->control.cmd == AUDIO_REQ_SET_CUR)
|
||||
{
|
||||
@@ -556,7 +588,7 @@ static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_AUDIO_EP0_TxReady
|
||||
@@ -564,10 +596,12 @@ static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
|
||||
/* Only OUT control data are processed */
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_AUDIO_SOF
|
||||
@@ -575,28 +609,37 @@ static uint8_t USBD_AUDIO_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
UNUSED(pdev);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_SOF
|
||||
* handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @param offset: audio offset
|
||||
* @retval status
|
||||
*/
|
||||
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
{
|
||||
uint32_t cmd = 0U;
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
uint32_t BufferSize = AUDIO_TOTAL_BUF_SIZE / 2U;
|
||||
|
||||
haudio->offset = offset;
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
haudio->offset = offset;
|
||||
|
||||
if (haudio->rd_enable == 1U)
|
||||
{
|
||||
haudio->rd_ptr += (uint16_t)(AUDIO_TOTAL_BUF_SIZE / 2U);
|
||||
haudio->rd_ptr += (uint16_t)BufferSize;
|
||||
|
||||
if (haudio->rd_ptr == AUDIO_TOTAL_BUF_SIZE)
|
||||
{
|
||||
@@ -609,13 +652,13 @@ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
{
|
||||
if ((haudio->rd_ptr - haudio->wr_ptr) < AUDIO_OUT_PACKET)
|
||||
{
|
||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U + 4U;
|
||||
BufferSize += 4U;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((haudio->rd_ptr - haudio->wr_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||
{
|
||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U;
|
||||
BufferSize -= 4U;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -623,13 +666,13 @@ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
{
|
||||
if ((haudio->wr_ptr - haudio->rd_ptr) < AUDIO_OUT_PACKET)
|
||||
{
|
||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U;
|
||||
BufferSize -= 4U;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((haudio->wr_ptr - haudio->rd_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||
{
|
||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U + 4U;
|
||||
BufferSize += 4U;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -637,8 +680,7 @@ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
if (haudio->offset == AUDIO_OFFSET_FULL)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||
cmd,
|
||||
AUDIO_CMD_PLAY);
|
||||
BufferSize, AUDIO_CMD_PLAY);
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
}
|
||||
}
|
||||
@@ -650,9 +692,12 @@ void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
return USBD_OK;
|
||||
UNUSED(pdev);
|
||||
UNUSED(epnum);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_AUDIO_IsoOutIncomplete
|
||||
@@ -661,9 +706,12 @@ static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epn
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
return USBD_OK;
|
||||
UNUSED(pdev);
|
||||
UNUSED(epnum);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_AUDIO_DataOut
|
||||
@@ -672,16 +720,29 @@ static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t ep
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
uint16_t PacketSize;
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (haudio == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
if (epnum == AUDIO_OUT_EP)
|
||||
{
|
||||
/* Increment the Buffer pointer or roll it back when all buffers are full */
|
||||
/* Get received data packet length */
|
||||
PacketSize = (uint16_t)USBD_LL_GetRxDataSize(pdev, epnum);
|
||||
|
||||
haudio->wr_ptr += AUDIO_OUT_PACKET;
|
||||
/* Packet received Callback */
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->PeriodicTC(&haudio->buffer[haudio->wr_ptr],
|
||||
PacketSize, AUDIO_OUT_TC);
|
||||
|
||||
/* Increment the Buffer pointer or roll it back when all buffers are full */
|
||||
haudio->wr_ptr += PacketSize;
|
||||
|
||||
if (haudio->wr_ptr == AUDIO_TOTAL_BUF_SIZE)
|
||||
{
|
||||
@@ -706,82 +767,97 @@ static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
}
|
||||
|
||||
/* Prepare Out endpoint to receive next audio packet */
|
||||
USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, &haudio->buffer[haudio->wr_ptr],
|
||||
AUDIO_OUT_PACKET);
|
||||
(void)USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP,
|
||||
&haudio->buffer[haudio->wr_ptr],
|
||||
AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_Req_GetCurrent
|
||||
* Handles the GET_CUR Audio control request.
|
||||
* @param pdev: instance
|
||||
* @param pdev: device instance
|
||||
* @param req: setup class request
|
||||
* @retval status
|
||||
*/
|
||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
memset(haudio->control.data, 0, 64U);
|
||||
if (haudio == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
(void)USBD_memset(haudio->control.data, 0, USB_MAX_EP0_SIZE);
|
||||
|
||||
/* Send the current mute state */
|
||||
USBD_CtlSendData(pdev, haudio->control.data, req->wLength);
|
||||
(void)USBD_CtlSendData(pdev, haudio->control.data,
|
||||
MIN(req->wLength, USB_MAX_EP0_SIZE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO_Req_SetCurrent
|
||||
* Handles the SET_CUR Audio control request.
|
||||
* @param pdev: instance
|
||||
* @param pdev: device instance
|
||||
* @param req: setup class request
|
||||
* @retval status
|
||||
*/
|
||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (req->wLength)
|
||||
if (haudio == NULL)
|
||||
{
|
||||
/* Prepare the reception of the buffer over EP0 */
|
||||
USBD_CtlPrepareRx(pdev, haudio->control.data, req->wLength);
|
||||
return;
|
||||
}
|
||||
|
||||
if (req->wLength != 0U)
|
||||
{
|
||||
haudio->control.cmd = AUDIO_REQ_SET_CUR; /* Set the request value */
|
||||
haudio->control.len = (uint8_t)req->wLength; /* Set the request data length */
|
||||
haudio->control.len = (uint8_t)MIN(req->wLength, USB_MAX_EP0_SIZE); /* Set the request data length */
|
||||
haudio->control.unit = HIBYTE(req->wIndex); /* Set the request target unit */
|
||||
|
||||
/* Prepare the reception of the buffer over EP0 */
|
||||
(void)USBD_CtlPrepareRx(pdev, haudio->control.data, haudio->control.len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length)
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_AUDIO_DeviceQualifierDesc);
|
||||
*length = (uint16_t)sizeof(USBD_AUDIO_DeviceQualifierDesc);
|
||||
|
||||
return USBD_AUDIO_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_AUDIO_RegisterInterface
|
||||
* @param fops: Audio interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops)
|
||||
* @brief USBD_AUDIO_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: Audio interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops)
|
||||
{
|
||||
if (fops != NULL)
|
||||
if (fops == NULL)
|
||||
{
|
||||
pdev->pUserData = fops;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
pdev->pUserData = fops;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
@@ -796,5 +872,3 @@ uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -70,7 +69,7 @@ static int8_t TEMPLATE_DeInit(uint32_t options);
|
||||
static int8_t TEMPLATE_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||
static int8_t TEMPLATE_VolumeCtl(uint8_t vol);
|
||||
static int8_t TEMPLATE_MuteCtl(uint8_t cmd);
|
||||
static int8_t TEMPLATE_PeriodicTC(uint8_t cmd);
|
||||
static int8_t TEMPLATE_PeriodicTC(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||
static int8_t TEMPLATE_GetState(void);
|
||||
|
||||
USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops =
|
||||
@@ -94,6 +93,10 @@ USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops =
|
||||
*/
|
||||
static int8_t TEMPLATE_Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options)
|
||||
{
|
||||
UNUSED(AudioFreq);
|
||||
UNUSED(Volume);
|
||||
UNUSED(options);
|
||||
|
||||
/*
|
||||
Add your initialization code here
|
||||
*/
|
||||
@@ -108,6 +111,8 @@ static int8_t TEMPLATE_Init(uint32_t AudioFreq, uint32_t Volume, uint32_t optio
|
||||
*/
|
||||
static int8_t TEMPLATE_DeInit(uint32_t options)
|
||||
{
|
||||
UNUSED(options);
|
||||
|
||||
/*
|
||||
Add your deinitialization code here
|
||||
*/
|
||||
@@ -125,6 +130,10 @@ static int8_t TEMPLATE_DeInit(uint32_t options)
|
||||
*/
|
||||
static int8_t TEMPLATE_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd)
|
||||
{
|
||||
UNUSED(pbuf);
|
||||
UNUSED(size);
|
||||
UNUSED(cmd);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -135,6 +144,8 @@ static int8_t TEMPLATE_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd)
|
||||
*/
|
||||
static int8_t TEMPLATE_VolumeCtl(uint8_t vol)
|
||||
{
|
||||
UNUSED(vol);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -145,6 +156,8 @@ static int8_t TEMPLATE_VolumeCtl(uint8_t vol)
|
||||
*/
|
||||
static int8_t TEMPLATE_MuteCtl(uint8_t cmd)
|
||||
{
|
||||
UNUSED(cmd);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -153,8 +166,12 @@ static int8_t TEMPLATE_MuteCtl(uint8_t cmd)
|
||||
* @param cmd
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_PeriodicTC(uint8_t cmd)
|
||||
static int8_t TEMPLATE_PeriodicTC(uint8_t *pbuf, uint32_t size, uint8_t cmd)
|
||||
{
|
||||
UNUSED(pbuf);
|
||||
UNUSED(size);
|
||||
UNUSED(cmd);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -179,5 +196,3 @@ static int8_t TEMPLATE_GetState(void)
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
160
Class/BillBoard/Inc/usbd_billboard.h
Normal file
160
Class/BillBoard/Inc/usbd_billboard.h
Normal file
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_billboard.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for the usbd_billboard.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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 __USB_BB_H
|
||||
#define __USB_BB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
#include "usbd_desc.h"
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_BB
|
||||
* @brief This file is the Header file for usbd_billboard.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_BB_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define USB_BB_CONFIG_DESC_SIZ 18U
|
||||
|
||||
#ifndef USB_BB_MAX_NUM_ALT_MODE
|
||||
#define USB_BB_MAX_NUM_ALT_MODE 0x2U
|
||||
#endif /* USB_BB_MAX_NUM_ALT_MODE */
|
||||
|
||||
#ifndef USBD_BB_IF_STRING_INDEX
|
||||
#define USBD_BB_IF_STRING_INDEX 0x10U
|
||||
#endif /* USBD_BB_IF_STRING_INDEX */
|
||||
|
||||
|
||||
#define USBD_BILLBOARD_CAPABILITY 0x0DU
|
||||
#define USBD_BILLBOARD_ALTMODE_CAPABILITY 0x0FU
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
typedef struct _BB_DescHeader
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDevCapabilityType;
|
||||
}
|
||||
USBD_BB_DescHeader_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t wSVID;
|
||||
uint8_t bAlternateMode;
|
||||
uint8_t iAlternateModeString;
|
||||
} USBD_BB_AltModeTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDevCapabilityType;
|
||||
uint8_t bIndex;
|
||||
uint32_t dwAlternateModeVdo;
|
||||
} USBD_BB_AltModeCapDescTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDevCapabilityType;
|
||||
uint8_t iAddtionalInfoURL;
|
||||
uint8_t bNbrOfAltModes;
|
||||
uint8_t bPreferredAltMode;
|
||||
uint16_t VconnPwr;
|
||||
uint8_t bmConfigured[32];
|
||||
uint16_t bcdVersion;
|
||||
uint8_t bAdditionalFailureInfo;
|
||||
uint8_t bReserved;
|
||||
USBD_BB_AltModeTypeDef wSVID[USB_BB_MAX_NUM_ALT_MODE];
|
||||
} USBD_BosBBCapDescTypedef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UNSPECIFIED_ERROR = 0,
|
||||
CONFIGURATION_NOT_ATTEMPTED,
|
||||
CONFIGURATION_UNSUCCESSFUL,
|
||||
CONFIGURATION_SUCCESSFUL,
|
||||
} BB_AltModeState;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_BB;
|
||||
#define USBD_BB_CLASS &USBD_BB
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if (USBD_CLASS_BOS_ENABLED == 1)
|
||||
void *USBD_BB_GetCapDesc(USBD_HandleTypeDef *pdev, uint8_t *buf);
|
||||
void *USBD_BB_GetAltModeDesc(USBD_HandleTypeDef *pdev, uint8_t *buf, uint8_t idx);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_BB_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
502
Class/BillBoard/Src/usbd_billboard.c
Normal file
502
Class/BillBoard/Src/usbd_billboard.c
Normal file
@@ -0,0 +1,502 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_billboard.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the high layer firmware functions to manage the
|
||||
* following functionalities of the USB BillBoard Class:
|
||||
* - Initialization and Configuration of high and low layer
|
||||
* - Enumeration as BillBoard Device
|
||||
* - Error management
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* BillBoard Class Description
|
||||
* ===================================================================
|
||||
* This module manages the BillBoard class V1.2.1 following the "Device Class Definition
|
||||
* for BillBoard Devices (BB) Version R1.2.1 Sept 08, 2016".
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Enumeration as an USB BillBoard device
|
||||
* - Enumeration & management of BillBoard device supported alternate modes
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_billboard.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_BB
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_BB_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_BB_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_BB_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_BB_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static uint8_t USBD_BB_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_BB_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_BB_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_BB_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_BB_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_BB_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t *USBD_BB_GetCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_BB_GetDeviceQualifierDesc(uint16_t *length);
|
||||
static uint8_t *USBD_BB_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
|
||||
#if (USBD_CLASS_BOS_ENABLED == 1)
|
||||
USBD_BB_DescHeader_t *USBD_BB_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_BB_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
USBD_ClassTypeDef USBD_BB =
|
||||
{
|
||||
USBD_BB_Init, /* Init */
|
||||
USBD_BB_DeInit, /* DeInit */
|
||||
USBD_BB_Setup, /* Setup */
|
||||
NULL, /* EP0_TxSent */
|
||||
USBD_BB_EP0_RxReady, /* EP0_RxReady */
|
||||
USBD_BB_DataIn, /* DataIn */
|
||||
USBD_BB_DataOut, /* DataOut */
|
||||
NULL, /* SOF */
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_BB_GetCfgDesc,
|
||||
USBD_BB_GetCfgDesc,
|
||||
USBD_BB_GetOtherSpeedCfgDesc,
|
||||
USBD_BB_GetDeviceQualifierDesc,
|
||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||
NULL,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* USB Standard Device Qualifier Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_BB_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC, /* bLength */
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER, /* bDescriptorType */
|
||||
0x01, /* bcdUSB */
|
||||
0x20,
|
||||
0x11, /* bDeviceClass */
|
||||
0x00, /* bDeviceSubClass */
|
||||
0x00, /* bDeviceProtocol */
|
||||
0x40, /* bMaxPacketSize0 */
|
||||
0x01, /* bNumConfigurations */
|
||||
0x00, /* bReserved */
|
||||
};
|
||||
|
||||
/* USB device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_BB_CfgDesc[USB_BB_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_BB_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
||||
0x00,
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
USBD_IDX_CONFIG_STR, /* 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) */
|
||||
/* 09 */
|
||||
|
||||
/************** Descriptor of BillBoard interface ****************/
|
||||
/* 09 */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x00, /* bNumEndpoints */
|
||||
0x11, /* bInterfaceClass: billboard */
|
||||
0x00, /* bInterfaceSubClass */
|
||||
0x00, /* nInterfaceProtocol */
|
||||
USBD_BB_IF_STRING_INDEX, /* iInterface: Index of string descriptor */
|
||||
};
|
||||
|
||||
/* USB device Other Speed Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_BB_OtherSpeedCfgDesc[USB_BB_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
||||
USB_BB_CONFIG_DESC_SIZ,
|
||||
0x00,
|
||||
0x01, /* bNumInterfaces: 1 interface */
|
||||
0x01, /* bConfigurationValue */
|
||||
USBD_IDX_CONFIG_STR, /* 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) */
|
||||
|
||||
/************** Descriptor of BillBoard interface ****************/
|
||||
/* 09 */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x00, /* bNumEndpoints*/
|
||||
0x11, /* bInterfaceClass: billboard */
|
||||
0x00, /* bInterfaceSubClass */
|
||||
0x00, /* nInterfaceProtocol */
|
||||
USBD_BB_IF_STRING_INDEX, /* iInterface: Index of string descriptor */
|
||||
} ;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_BB_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_Init
|
||||
* Initialize the BB interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_BB_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
/* Prevent unused argument compilation warning */
|
||||
UNUSED(pdev);
|
||||
UNUSED(cfgidx);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_Init
|
||||
* DeInitialize the BB layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_BB_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
/* Prevent unused argument compilation warning */
|
||||
UNUSED(pdev);
|
||||
UNUSED(cfgidx);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_Setup
|
||||
* Handle the BB specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_BB_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
uint16_t status_info = 0U;
|
||||
uint16_t AltSetting = 0U;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
break;
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&AltSetting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_DataIn
|
||||
* Data sent on non-control IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_BB_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
/* Prevent unused argument compilation warning */
|
||||
UNUSED(pdev);
|
||||
UNUSED(epnum);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_BB_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
/* Prevent unused argument compilation warning */
|
||||
UNUSED(pdev);
|
||||
UNUSED(epnum);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_EP0_RxReady
|
||||
* Handle EP0 Rx Ready event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_BB_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Prevent unused argument compilation warning */
|
||||
UNUSED(pdev);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_GetCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_BB_GetCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_BB_CfgDesc);
|
||||
return USBD_BB_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_GetOtherSpeedCfgDesc
|
||||
* return other speed configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_BB_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_BB_OtherSpeedCfgDesc);
|
||||
return USBD_BB_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_BB_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_BB_DeviceQualifierDesc);
|
||||
return USBD_BB_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
|
||||
#if (USBD_CLASS_BOS_ENABLED == 1U)
|
||||
/**
|
||||
* @brief USBD_BB_GetNextDesc
|
||||
* This function return the next descriptor header
|
||||
* @param buf: Buffer where the descriptor is available
|
||||
* @param ptr: data pointer inside the descriptor
|
||||
* @retval next header
|
||||
*/
|
||||
USBD_BB_DescHeader_t *USBD_BB_GetNextDesc(uint8_t *pbuf, uint16_t *ptr)
|
||||
{
|
||||
USBD_BB_DescHeader_t *pnext = (USBD_BB_DescHeader_t *)(void *)pbuf;
|
||||
|
||||
*ptr += pnext->bLength;
|
||||
pnext = (USBD_BB_DescHeader_t *)(void *)(pbuf + pnext->bLength);
|
||||
|
||||
return (pnext);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_GetCapDesc
|
||||
* This function return the Billboard Capability descriptor
|
||||
* @param pdev: device instance
|
||||
* @param pBosDesc: pointer to Bos descriptor
|
||||
* @retval pointer to Billboard Capability descriptor
|
||||
*/
|
||||
void *USBD_BB_GetCapDesc(USBD_HandleTypeDef *pdev, uint8_t *pBosDesc)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
|
||||
USBD_BB_DescHeader_t *pdesc = (USBD_BB_DescHeader_t *)(void *)pBosDesc;
|
||||
USBD_BosDescTypedef *desc = (USBD_BosDescTypedef *)(void *)pBosDesc;
|
||||
USBD_BosBBCapDescTypedef *pCapDesc = NULL;
|
||||
uint16_t ptr;
|
||||
|
||||
if (desc->wTotalLength > desc->bLength)
|
||||
{
|
||||
ptr = desc->bLength;
|
||||
|
||||
while (ptr < desc->wTotalLength)
|
||||
{
|
||||
pdesc = USBD_BB_GetNextDesc((uint8_t *)pdesc, &ptr);
|
||||
|
||||
if (pdesc->bDevCapabilityType == USBD_BILLBOARD_CAPABILITY)
|
||||
{
|
||||
pCapDesc = (USBD_BosBBCapDescTypedef *)(void *)pdesc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (void *)pCapDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_BB_GetAltModeDesc
|
||||
* This function return the Billboard Alternate Mode descriptor
|
||||
* @param pdev: device instance
|
||||
* @param pBosDesc: pointer to Bos descriptor
|
||||
* @param idx: Index of requested Alternate Mode descriptor
|
||||
* @retval pointer to Alternate Mode descriptor
|
||||
*/
|
||||
void *USBD_BB_GetAltModeDesc(USBD_HandleTypeDef *pdev, uint8_t *pBosDesc, uint8_t idx)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
|
||||
USBD_BB_DescHeader_t *pdesc = (USBD_BB_DescHeader_t *)(void *)pBosDesc;
|
||||
USBD_BosDescTypedef *desc = (USBD_BosDescTypedef *)(void *)pBosDesc;
|
||||
USBD_BB_AltModeCapDescTypeDef *pAltModDesc = NULL;
|
||||
uint8_t cnt = 0U;
|
||||
uint16_t ptr;
|
||||
|
||||
if (desc->wTotalLength > desc->bLength)
|
||||
{
|
||||
ptr = desc->bLength;
|
||||
|
||||
while (ptr < desc->wTotalLength)
|
||||
{
|
||||
pdesc = USBD_BB_GetNextDesc((uint8_t *)pdesc, &ptr);
|
||||
|
||||
if (pdesc->bDevCapabilityType == USBD_BILLBOARD_ALTMODE_CAPABILITY)
|
||||
{
|
||||
if (cnt == idx)
|
||||
{
|
||||
pAltModDesc = (USBD_BB_AltModeCapDescTypeDef *)(void *)pdesc;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (void *)pAltModDesc;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
343
Class/CCID/Inc/usbd_ccid.h
Normal file
343
Class/CCID/Inc/usbd_ccid.h
Normal file
@@ -0,0 +1,343 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ccid.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_ccid.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_CCID_H
|
||||
#define __USBD_CCID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup usbd_cdc
|
||||
* @brief This file is the Header file for usbd_ccid.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup usbd_cdc_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#ifndef CCID_IN_EP
|
||||
#define CCID_IN_EP 0x81U /* EP1 for data IN */
|
||||
#endif /* CCID_IN_EP */
|
||||
|
||||
#ifndef CCID_OUT_EP
|
||||
#define CCID_OUT_EP 0x01U /* EP1 for data OUT */
|
||||
#endif /* CCID_OUT_EP */
|
||||
|
||||
#ifndef CCID_CMD_EP
|
||||
#define CCID_CMD_EP 0x82U /* EP2 for CCID commands */
|
||||
#endif /* CCID_CMD_EP */
|
||||
|
||||
#ifndef CCID_CMD_HS_BINTERVAL
|
||||
#define CCID_CMD_HS_BINTERVAL 0x10U
|
||||
#endif /* CCID_CMD_HS_BINTERVAL */
|
||||
|
||||
#ifndef CCID_CMD_FS_BINTERVAL
|
||||
#define CCID_CMD_FS_BINTERVAL 0x10U
|
||||
#endif /* CCID_CMD_FS_BINTERVAL */
|
||||
|
||||
|
||||
#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_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
||||
|
||||
#define USB_CCID_CONFIG_DESC_SIZ 93U
|
||||
#define CCID_DATA_HS_IN_PACKET_SIZE CCID_DATA_HS_MAX_PACKET_SIZE
|
||||
#define CCID_DATA_HS_OUT_PACKET_SIZE CCID_DATA_HS_MAX_PACKET_SIZE
|
||||
|
||||
#define CCID_DATA_FS_IN_PACKET_SIZE CCID_DATA_FS_MAX_PACKET_SIZE
|
||||
#define CCID_DATA_FS_OUT_PACKET_SIZE CCID_DATA_FS_MAX_PACKET_SIZE
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* CCID definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
#define CCID_SEND_ENCAPSULATED_COMMAND 0x00U
|
||||
#define CCID_GET_ENCAPSULATED_RESPONSE 0x01U
|
||||
#define CCID_SET_COMM_FEATURE 0x02U
|
||||
#define CCID_GET_COMM_FEATURE 0x03U
|
||||
#define CCID_CLEAR_COMM_FEATURE 0x04U
|
||||
#define CCID_SET_LINE_CODING 0x20U
|
||||
#define CCID_GET_LINE_CODING 0x21U
|
||||
#define CCID_SET_CONTROL_LINE_STATE 0x22U
|
||||
#define CCID_SEND_BREAK 0x23U
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
#define REQUEST_ABORT 0x01U
|
||||
#define REQUEST_GET_CLOCK_FREQUENCIES 0x02U
|
||||
#define REQUEST_GET_DATA_RATES 0x03U
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* The Smart Card Device Class Descriptor definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
#define CCID_INTERFACE_DESC_SIZE 0x09U
|
||||
#define USB_DEVICE_CLASS_CCID 0x0BU
|
||||
#define CCID_CLASS_DESC_SIZE 0x36U
|
||||
#define CCID_DESC_TYPE 0x21U
|
||||
|
||||
#ifndef CCID_VOLTAGE_SUPP
|
||||
#define CCID_VOLTAGE_SUPP 0x07U
|
||||
#endif
|
||||
#ifndef USBD_CCID_PROTOCOL
|
||||
#define USBD_CCID_PROTOCOL 0x03U
|
||||
#endif
|
||||
#ifndef USBD_CCID_DEFAULT_CLOCK_FREQ
|
||||
#define USBD_CCID_DEFAULT_CLOCK_FREQ 3600U
|
||||
#endif
|
||||
#ifndef USBD_CCID_MAX_CLOCK_FREQ
|
||||
#define USBD_CCID_MAX_CLOCK_FREQ USBD_CCID_DEFAULT_CLOCK_FREQ
|
||||
#endif
|
||||
#ifndef USBD_CCID_DEFAULT_DATA_RATE
|
||||
#define USBD_CCID_DEFAULT_DATA_RATE 9677U
|
||||
#endif
|
||||
#ifndef USBD_CCID_MAX_DATA_RATE
|
||||
#define USBD_CCID_MAX_DATA_RATE USBD_CCID_DEFAULT_DATA_RATE
|
||||
#endif
|
||||
#ifndef USBD_CCID_MAX_INF_FIELD_SIZE
|
||||
#define USBD_CCID_MAX_INF_FIELD_SIZE 254U
|
||||
#endif
|
||||
#ifndef CCID_MAX_BLOCK_SIZE_HEADER
|
||||
#define CCID_MAX_BLOCK_SIZE_HEADER 271U
|
||||
#endif
|
||||
|
||||
#define TPDU_EXCHANGE 0x01U
|
||||
#define SHORT_APDU_EXCHANGE 0x02U
|
||||
#define EXTENDED_APDU_EXCHANGE 0x04U
|
||||
#define CHARACTER_EXCHANGE 0x00U
|
||||
|
||||
#ifndef EXCHANGE_LEVEL_FEATURE
|
||||
#define EXCHANGE_LEVEL_FEATURE TPDU_EXCHANGE
|
||||
#endif
|
||||
|
||||
#define CCID_ENDPOINT_DESC_SIZE 0x07U
|
||||
|
||||
#ifndef CCID_EP0_BUFF_SIZ
|
||||
#define CCID_EP0_BUFF_SIZ 64U
|
||||
#endif
|
||||
|
||||
#ifndef CCID_BULK_EPIN_SIZE
|
||||
#define CCID_BULK_EPIN_SIZE 64U
|
||||
#endif
|
||||
|
||||
#define CCID_INT_BUFF_SIZ 2U
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
/* CCID Bulk Out Command definitions */
|
||||
#define PC_TO_RDR_ICCPOWERON 0x62U
|
||||
#define PC_TO_RDR_ICCPOWEROFF 0x63U
|
||||
#define PC_TO_RDR_GETSLOTSTATUS 0x65U
|
||||
#define PC_TO_RDR_XFRBLOCK 0x6FU
|
||||
#define PC_TO_RDR_GETPARAMETERS 0x6CU
|
||||
#define PC_TO_RDR_RESETPARAMETERS 0x6DU
|
||||
#define PC_TO_RDR_SETPARAMETERS 0x61U
|
||||
#define PC_TO_RDR_ESCAPE 0x6BU
|
||||
#define PC_TO_RDR_ICCCLOCK 0x6EU
|
||||
#define PC_TO_RDR_T0APDU 0x6AU
|
||||
#define PC_TO_RDR_SECURE 0x69U
|
||||
#define PC_TO_RDR_MECHANICAL 0x71U
|
||||
#define PC_TO_RDR_ABORT 0x72U
|
||||
#define PC_TO_RDR_SETDATARATEANDCLOCKFREQUENCY 0x73U
|
||||
|
||||
/* CCID Bulk In Command definitions */
|
||||
#define RDR_TO_PC_DATABLOCK 0x80U
|
||||
#define RDR_TO_PC_SLOTSTATUS 0x81U
|
||||
#define RDR_TO_PC_PARAMETERS 0x82U
|
||||
#define RDR_TO_PC_ESCAPE 0x83U
|
||||
#define RDR_TO_PC_DATARATEANDCLOCKFREQUENCY 0x84U
|
||||
|
||||
/* CCID Interrupt In Command definitions */
|
||||
#define RDR_TO_PC_NOTIFYSLOTCHANGE 0x50U
|
||||
#define RDR_TO_PC_HARDWAREERROR 0x51U
|
||||
|
||||
/* Bulk-only Command Block Wrapper */
|
||||
#define ABDATA_SIZE 261U
|
||||
#define CCID_CMD_HEADER_SIZE 10U
|
||||
#define CCID_RESPONSE_HEADER_SIZE 10U
|
||||
|
||||
/* Number of SLOTS. For single card, this value is 1 */
|
||||
#define CCID_NUMBER_OF_SLOTS 1U
|
||||
|
||||
#define CARD_SLOT_FITTED 1U
|
||||
#define CARD_SLOT_REMOVED 0U
|
||||
|
||||
#define OFFSET_INT_BMESSAGETYPE 0x00U
|
||||
#define OFFSET_INT_BMSLOTICCSTATE 0x01U
|
||||
#define SLOT_ICC_PRESENT 0x01U
|
||||
/* LSb : (0b = no ICC present, 1b = ICC present) */
|
||||
#define SLOT_ICC_CHANGE 0x02U
|
||||
/* MSb : (0b = no change, 1b = change) */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate;
|
||||
uint8_t format;
|
||||
uint8_t paritytype;
|
||||
uint8_t datatype;
|
||||
} USBD_CCID_LineCodingTypeDef;
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bMessageType; /* Offset = 0*/
|
||||
uint32_t dwLength; /* Offset = 1, The length field (dwLength) is the length
|
||||
of the message not including the 10-byte header.*/
|
||||
uint8_t bSlot; /* Offset = 5*/
|
||||
uint8_t bSeq; /* Offset = 6*/
|
||||
uint8_t bSpecific_0; /* Offset = 7*/
|
||||
uint8_t bSpecific_1; /* Offset = 8*/
|
||||
uint8_t bSpecific_2; /* Offset = 9*/
|
||||
uint8_t abData [ABDATA_SIZE]; /* Offset = 10, For reference, the absolute
|
||||
maximum block size for a TPDU T=0 block is 260 bytes
|
||||
(5 bytes command; 255 bytes data),
|
||||
or for a TPDU T=1 block is 259 bytes,
|
||||
or for a short APDU T=1 block is 261 bytes,
|
||||
or for an extended APDU T=1 block is 65544 bytes.*/
|
||||
} USBD_CCID_BulkOut_DataTypeDef;
|
||||
#pragma pack()
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bMessageType; /* Offset = 0 */
|
||||
uint32_t dwLength; /* Offset = 1 */
|
||||
uint8_t bSlot; /* Offset = 5, Same as Bulk-OUT message */
|
||||
uint8_t bSeq; /* Offset = 6, Same as Bulk-OUT message */
|
||||
uint8_t bStatus; /* Offset = 7, Slot status as defined in section 6.2.6 */
|
||||
uint8_t bError; /* Offset = 8, Slot error as defined in section 6.2.6 */
|
||||
uint8_t bSpecific; /* Offset = 9 */
|
||||
uint8_t abData[ABDATA_SIZE]; /* Offset = 10 */
|
||||
uint16_t u16SizeToSend;
|
||||
} USBD_CCID_BulkIn_DataTypeDef;
|
||||
#pragma pack()
|
||||
|
||||
typedef struct
|
||||
{
|
||||
__IO uint8_t SlotStatus;
|
||||
__IO uint8_t SlotStatusChange;
|
||||
} USBD_CCID_SlotStatusTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
__IO uint8_t bAbortRequestFlag;
|
||||
__IO uint8_t bSeq;
|
||||
__IO uint8_t bSlot;
|
||||
} USBD_CCID_ParamTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t data[CCID_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32-bit alignment */
|
||||
uint32_t UsbMessageLength;
|
||||
uint8_t UsbIntData[CCID_CMD_PACKET_SIZE]; /* Buffer for the Interrupt In Data */
|
||||
uint32_t alt_setting;
|
||||
|
||||
USBD_CCID_BulkIn_DataTypeDef UsbBlkInData; /* Buffer for the Out Data */
|
||||
USBD_CCID_BulkOut_DataTypeDef UsbBlkOutData; /* Buffer for the In Data */
|
||||
USBD_CCID_SlotStatusTypeDef SlotStatus;
|
||||
USBD_CCID_ParamTypeDef USBD_CCID_Param;
|
||||
|
||||
__IO uint32_t MaxPcktLen;
|
||||
__IO uint8_t blkt_state; /* Bulk transfer state */
|
||||
|
||||
uint16_t slot_nb;
|
||||
uint16_t seq_nb;
|
||||
} USBD_CCID_HandleTypeDef;
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_CCID;
|
||||
#define USBD_CCID_CLASS &USBD_CCID
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
typedef struct _USBD_CCID_Itf
|
||||
{
|
||||
uint8_t (* Init)(USBD_HandleTypeDef *pdev);
|
||||
uint8_t (* DeInit)(USBD_HandleTypeDef *pdev);
|
||||
uint8_t (* Control)(uint8_t req, uint8_t *pbuf, uint16_t *length);
|
||||
uint8_t (* Response_SendData)(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len);
|
||||
uint8_t (* Send_Process)(uint8_t *Command, uint8_t *Data);
|
||||
uint8_t (* SetSlotStatus)(USBD_HandleTypeDef *pdev);
|
||||
} USBD_CCID_ItfTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_CCID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CCID_ItfTypeDef *fops);
|
||||
|
||||
uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CCID_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
219
Class/CCID/Inc/usbd_ccid_cmd.h
Normal file
219
Class/CCID/Inc/usbd_ccid_cmd.h
Normal file
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ccid_cmd.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_ccid_cmd.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_CCID_CMD_H
|
||||
#define __USBD_CCID_CMD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifndef __USBD_CCID_IF_H
|
||||
#include "usbd_ccid_if_template.h"
|
||||
#endif
|
||||
|
||||
#ifndef __USBD_CCID_SC_IF_H
|
||||
#include "usbd_ccid_sc_if_template.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
|
||||
/******************************************************************************/
|
||||
/* ERROR CODES for USB Bulk In Messages : bError */
|
||||
/******************************************************************************/
|
||||
|
||||
#define SLOT_NO_ERROR 0x81U
|
||||
#define SLOTERROR_UNKNOWN 0x82U
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
/* Index of not supported / incorrect message parameter : 7Fh to 01h */
|
||||
/* These Values are used for Return Types between Firmware Layers */
|
||||
/*
|
||||
Failure of a command
|
||||
The CCID cannot parse one parameter or the ICC is not supporting one parameter.
|
||||
Then the Slot Error register contains the index of the first bad parameter as a
|
||||
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) */
|
||||
|
||||
/* Following Parameters used in PC_to_RDR_XfrBlock */
|
||||
#define SLOTERROR_BAD_LENTGH 0x01U
|
||||
#define SLOTERROR_BAD_SLOT 0x05U
|
||||
#define SLOTERROR_BAD_POWERSELECT 0x07U
|
||||
#define SLOTERROR_BAD_PROTOCOLNUM 0x07U
|
||||
#define SLOTERROR_BAD_CLOCKCOMMAND 0x07U
|
||||
#define SLOTERROR_BAD_ABRFU_3B 0x07U
|
||||
#define SLOTERROR_BAD_BMCHANGES 0x07U
|
||||
#define SLOTERROR_BAD_BFUNCTION_MECHANICAL 0x07U
|
||||
#define SLOTERROR_BAD_ABRFU_2B 0x08U
|
||||
#define SLOTERROR_BAD_LEVELPARAMETER 0x08U
|
||||
#define SLOTERROR_BAD_FIDI 0x0AU
|
||||
#define SLOTERROR_BAD_T01CONVCHECKSUM 0x0BU
|
||||
#define SLOTERROR_BAD_GUARDTIME 0x0CU
|
||||
#define SLOTERROR_BAD_WAITINGINTEGER 0x0DU
|
||||
#define SLOTERROR_BAD_CLOCKSTOP 0x0EU
|
||||
#define SLOTERROR_BAD_IFSC 0x0FU
|
||||
#define SLOTERROR_BAD_NAD 0x10U
|
||||
#define SLOTERROR_BAD_DWLENGTH 0x08U
|
||||
|
||||
|
||||
/*---------- Table 6.2-2 Slot error register when bmCommandStatus = 1 */
|
||||
#define SLOTERROR_CMD_ABORTED 0xFFU
|
||||
#define SLOTERROR_ICC_MUTE 0xFEU
|
||||
#define SLOTERROR_XFR_PARITY_ERROR 0xFDU
|
||||
#define SLOTERROR_XFR_OVERRUN 0xFCU
|
||||
#define SLOTERROR_HW_ERROR 0xFBU
|
||||
#define SLOTERROR_BAD_ATR_TS 0xF8U
|
||||
#define SLOTERROR_BAD_ATR_TCK 0xF7U
|
||||
#define SLOTERROR_ICC_PROTOCOL_NOT_SUPPORTED 0xF6U
|
||||
#define SLOTERROR_ICC_CLASS_NOT_SUPPORTED 0xF5U
|
||||
#define SLOTERROR_PROCEDURE_BYTE_CONFLICT 0xF4U
|
||||
#define SLOTERROR_DEACTIVATED_PROTOCOL 0xF3U
|
||||
#define SLOTERROR_BUSY_WITH_AUTO_SEQUENCE 0xF2U
|
||||
#define SLOTERROR_PIN_TIMEOUT 0xF0U
|
||||
#define SLOTERROR_PIN_CANCELLED 0xEFU
|
||||
#define SLOTERROR_CMD_SLOT_BUSY 0xE0U
|
||||
#define SLOTERROR_CMD_NOT_SUPPORTED 0x00U
|
||||
|
||||
/* Following Parameters used in PC_to_RDR_ResetParameters */
|
||||
/* DEFAULT_FIDI_VALUE */
|
||||
#ifndef DEFAULT_FIDI
|
||||
#define DEFAULT_FIDI 0x11U
|
||||
#endif
|
||||
#ifndef DEFAULT_T01CONVCHECKSUM
|
||||
#define DEFAULT_T01CONVCHECKSUM 0x00U
|
||||
#endif
|
||||
#ifndef DEFAULT_EXTRA_GUARDTIME
|
||||
#define DEFAULT_EXTRA_GUARDTIME 0x00U
|
||||
#endif
|
||||
#ifndef DEFAULT_WAITINGINTEGER
|
||||
#define DEFAULT_WAITINGINTEGER 0x0AU
|
||||
#endif
|
||||
#ifndef DEFAULT_CLOCKSTOP
|
||||
#define DEFAULT_CLOCKSTOP 0x00U
|
||||
#endif
|
||||
#ifndef DEFAULT_IFSC
|
||||
#define DEFAULT_IFSC 0x20U
|
||||
#endif
|
||||
#ifndef DEFAULT_NAD
|
||||
#define DEFAULT_NAD 0x00U
|
||||
#endif
|
||||
|
||||
/* Following Parameters used in PC_to_RDR_IccPowerOn */
|
||||
#define VOLTAGE_SELECTION_AUTOMATIC 0xFFU
|
||||
#define VOLTAGE_SELECTION_3V 0x02U
|
||||
#define VOLTAGE_SELECTION_5V 0x01U
|
||||
#define VOLTAGE_SELECTION_1V8 0x03U
|
||||
|
||||
/*
|
||||
Offset=0 bmICCStatus 2 bit 0, 1, 2
|
||||
0 - An ICC is present and active (power is on and stable, RST is inactive)
|
||||
1 - An ICC is present and inactive (not activated or shut down by hardware error)
|
||||
2 - No ICC is present
|
||||
3 - RFU
|
||||
Offset=0 bmRFU 4 bits 0 RFU
|
||||
Offset=6 bmCommandStatus 2 bits 0, 1, 2
|
||||
0 - Processed without error
|
||||
1 - Failed (error code provided by the error register)
|
||||
2 - Time Extension is requested
|
||||
3 - RFU
|
||||
*/
|
||||
|
||||
#define BM_ICC_PRESENT_ACTIVE 0x00U
|
||||
#define BM_ICC_PRESENT_INACTIVE 0x01U
|
||||
#define BM_ICC_NO_ICC_PRESENT 0x02U
|
||||
|
||||
#define BM_COMMAND_STATUS_OFFSET 0x06U
|
||||
#define BM_COMMAND_STATUS_NO_ERROR 0x00U
|
||||
#define BM_COMMAND_STATUS_FAILED (0x01U << BM_COMMAND_STATUS_OFFSET)
|
||||
#define BM_COMMAND_STATUS_TIME_EXTN (0x02 << BM_COMMAND_STATUS_OFFSET)
|
||||
|
||||
|
||||
#if (ATR_T01 == 0)
|
||||
#define SIZE_OF_ATR 19U
|
||||
#else
|
||||
#define SIZE_OF_ATR 15U
|
||||
#endif
|
||||
|
||||
/* defines for the CCID_CMD Layers */
|
||||
#define LEN_RDR_TO_PC_SLOTSTATUS 10U
|
||||
#define LEN_PROTOCOL_STRUCT_T0 5U
|
||||
#define LEN_PROTOCOL_STRUCT_T1 7U
|
||||
|
||||
#define BPROTOCOL_NUM_T0 0U
|
||||
#define BPROTOCOL_NUM_T1 1U
|
||||
|
||||
/************************************************************************************/
|
||||
/* ERROR CODES for RDR_TO_PC_HARDWAREERROR Message : bHardwareErrorCode */
|
||||
/************************************************************************************/
|
||||
|
||||
#define HARDWAREERRORCODE_OVERCURRENT 0x01U
|
||||
#define HARDWAREERRORCODE_VOLTAGEERROR 0x02U
|
||||
#define HARDWAREERRORCODE_OVERCURRENT_IT 0x04U
|
||||
#define HARDWAREERRORCODE_VOLTAGEERROR_IT 0x08U
|
||||
|
||||
|
||||
|
||||
#define CHK_PARAM_SLOT 0x01U
|
||||
#define CHK_PARAM_DWLENGTH 0x02U
|
||||
#define CHK_PARAM_abRFU2 0x04U
|
||||
#define CHK_PARAM_abRFU3 0x08U
|
||||
#define CHK_PARAM_CARD_PRESENT 0x10U
|
||||
#define CHK_PARAM_ABORT 0x20U
|
||||
#define CHK_ACTIVE_STATE 0x40U
|
||||
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_to_RDR_IccPowerOff(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_to_RDR_GetSlotStatus(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_to_RDR_XfrBlock(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_to_RDR_GetParameters(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_to_RDR_ResetParameters(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_to_RDR_SetParameters(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_to_RDR_Escape(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_to_RDR_IccClock(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_to_RDR_Abort(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_TO_RDR_T0Apdu(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_TO_RDR_Mechanical(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_TO_RDR_SetDataRateAndClockFrequency(USBD_HandleTypeDef *pdev);
|
||||
uint8_t PC_TO_RDR_Secure(USBD_HandleTypeDef *pdev);
|
||||
|
||||
void RDR_to_PC_DataBlock(uint8_t errorCode, USBD_HandleTypeDef *pdev);
|
||||
void RDR_to_PC_NotifySlotChange(USBD_HandleTypeDef *pdev);
|
||||
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_Escape(uint8_t errorCode, USBD_HandleTypeDef *pdev);
|
||||
void RDR_to_PC_DataRateAndClockFrequency(uint8_t errorCode, USBD_HandleTypeDef *pdev);
|
||||
|
||||
void CCID_UpdSlotStatus(USBD_HandleTypeDef *pdev, uint8_t slotStatus);
|
||||
void CCID_UpdSlotChange(USBD_HandleTypeDef *pdev, uint8_t changeStatus);
|
||||
uint8_t CCID_IsSlotStatusChange(USBD_HandleTypeDef *pdev);
|
||||
uint8_t CCID_CmdAbort(uint8_t slot, uint8_t seq);
|
||||
uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *dataPointer, uint16_t dataLen);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CCID_CMD_H */
|
||||
76
Class/CCID/Inc/usbd_ccid_if_template.h
Normal file
76
Class/CCID/Inc/usbd_ccid_if_template.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ccid_if_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_ccid_if_template.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_CCID_IF_TEMPLATE_H
|
||||
#define __USBD_CCID_IF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ccid.h"
|
||||
#include "usbd_ccid_cmd.h"
|
||||
|
||||
#ifndef __USBD_CCID_SMARTCARD_H
|
||||
#include "usbd_ccid_smartcard_template.h"
|
||||
#endif
|
||||
|
||||
/* Exported defines ----------------------------------------------------------*/
|
||||
|
||||
/*****************************************************************************/
|
||||
/*********************** CCID Bulk Transfer State machine ********************/
|
||||
/*****************************************************************************/
|
||||
#define CCID_STATE_IDLE 0U
|
||||
#define CCID_STATE_DATA_OUT 1U
|
||||
#define CCID_STATE_RECEIVE_DATA 2U
|
||||
#define CCID_STATE_SEND_RESP 3U
|
||||
#define CCID_STATE_DATAIN 4U
|
||||
#define CCID_STATE_UNCORRECT_LENGTH 5U
|
||||
|
||||
#define DIR_IN 0U
|
||||
#define DIR_OUT 1U
|
||||
#define BOTH_DIR 2U
|
||||
|
||||
/************ Value of the Interrupt transfer status to set ******************/
|
||||
#define IntrStatus_Complete 1U
|
||||
#define IntrStatus_Reset 0U
|
||||
/************** slot change status *******************************************/
|
||||
#define SlotStatus_Changed 1U
|
||||
#define SlotStatus_Reset 0U
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
extern USBD_HandleTypeDef USBD_Device;
|
||||
|
||||
/* CCID Interface callback */
|
||||
extern USBD_CCID_ItfTypeDef USBD_CCID_If_fops;
|
||||
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CCID_IF_TEMPLATE_H */
|
||||
100
Class/CCID/Inc/usbd_ccid_sc_if_template.h
Normal file
100
Class/CCID/Inc/usbd_ccid_sc_if_template.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ccid_sc_if_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_ccid_sc_if_template.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_CCID_SC_IF_TEMPLATE_H
|
||||
#define __USBD_CCID_SC_IF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ccid.h"
|
||||
#include "usbd_ccid_cmd.h"
|
||||
|
||||
#ifndef __USBD_CCID_SMARTCARD_H
|
||||
#include "usbd_ccid_smartcard_template.h"
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t voltage; /* Voltage for the Card Already Selected */
|
||||
uint8_t USART_GuardTime;
|
||||
uint8_t SC_A2R_FiDi;
|
||||
uint8_t SC_hostFiDi;
|
||||
uint8_t USART_DefaultGuardTime;
|
||||
uint32_t USART_BaudRate;
|
||||
} SC_Param_t;
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bmFindexDindex;
|
||||
uint8_t bmTCCKST0;
|
||||
uint8_t bGuardTimeT0;
|
||||
uint8_t bWaitingIntegerT0;
|
||||
uint8_t bClockStop;
|
||||
uint8_t bIfsc;
|
||||
uint8_t bNad;
|
||||
} Protocol_01_DataTypeDef;
|
||||
#pragma pack()
|
||||
|
||||
extern Protocol_01_DataTypeDef ProtocolData;
|
||||
extern SC_Param_t SC_Param;
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#define MAX_EXTRA_GUARD_TIME (0xFF - DEFAULT_EXTRA_GUARDTIME)
|
||||
|
||||
/* Following macros are used for SC_XferBlock command */
|
||||
#define XFER_BLK_SEND_DATA 1U /* Command is for issuing the data */
|
||||
#define XFER_BLK_RECEIVE_DATA 2U /* Command is for receiving the data */
|
||||
#define XFER_BLK_NO_DATA 3U /* Command type is No data exchange */
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/* APPLICATION LAYER ---------------------------------------------------------*/
|
||||
void SC_Itf_InitParams(void);
|
||||
void SC_Itf_IccPowerOn(uint8_t voltage);
|
||||
void SC_Itf_IccPowerOff(void);
|
||||
uint8_t SC_GetState(void);
|
||||
uint8_t SC_Itf_XferBlock(uint8_t *ptrBlock, uint32_t blockLen,
|
||||
uint16_t expectedLen,
|
||||
USBD_CCID_BulkIn_DataTypeDef *CCID_BulkIn_Data);
|
||||
|
||||
uint8_t SC_Itf_SetParams(Protocol_01_DataTypeDef *pPtr, uint8_t T_01);
|
||||
uint8_t SC_Itf_Escape(uint8_t *escapePtr, uint32_t escapeLen,
|
||||
uint8_t *responseBuff, uint32_t *responseLen);
|
||||
|
||||
uint8_t SC_Itf_SetClock(uint8_t bClockCommand);
|
||||
uint8_t SC_Itf_T0Apdu(uint8_t bmChanges, uint8_t bClassGetResponse,
|
||||
uint8_t bClassEnvelope);
|
||||
|
||||
uint8_t SC_Itf_Mechanical(uint8_t bFunction);
|
||||
uint8_t SC_Itf_SetDataRateAndClockFrequency(uint32_t dwClockFrequency,
|
||||
uint32_t dwDataRate);
|
||||
|
||||
uint8_t SC_Itf_Secure(uint32_t dwLength, uint8_t bBWI, uint16_t wLevelParameter,
|
||||
uint8_t *pbuf, uint32_t *returnLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CCID_SC_IF_TEMPLATE_H */
|
||||
279
Class/CCID/Inc/usbd_ccid_smartcard_template.h
Normal file
279
Class/CCID/Inc/usbd_ccid_smartcard_template.h
Normal file
@@ -0,0 +1,279 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ccid_smartcard_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_ccid_smartcard_template.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_CCID_SMARTCARD_TEMPLATE_H
|
||||
#define __USBD_CCID_SMARTCARD_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifndef __USBD_CCID_IF_H
|
||||
#include "usbd_ccid_if_template.h"
|
||||
#endif
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define T0_PROTOCOL 0x00U /* T0 protocol */
|
||||
#define T1_PROTOCOL 0x01U /* T1 protocol */
|
||||
#define DIRECT 0x3BU /* Direct bit convention */
|
||||
#define INDIRECT 0x3FU /* Indirect bit convention */
|
||||
#define SETUP_LENGTH 20U
|
||||
#define HIST_LENGTH 20U
|
||||
|
||||
#define SC_TRANSMIT_TIMEOUT 200U /* Direction to transmit */
|
||||
#define MAX_PROTOCOLLEVEL 7U /* Maximum levels of protocol */
|
||||
#define MAX_INTERFACEBYTE 4U /* Maximum number of interface bytes per protocol */
|
||||
#define LC_MAX 24U
|
||||
#define SC_RECEIVE_TIMEOUT 0x8000U /* Direction to reader */
|
||||
|
||||
/* T=1 protocol constants */
|
||||
#define T1_I_BLOCK 0x00U /* PCB (I-block: b8 = 0) */
|
||||
#define T1_R_BLOCK 0x80U /* PCB (R-block: b8 b7 = 10) */
|
||||
#define T1_S_BLOCK 0xC0U /* PCB (S-block: b8 b7 = 11) */
|
||||
|
||||
/* I block */
|
||||
#define T1_I_SEQ_SHIFT 6U /* N(S) position (bit 7) */
|
||||
|
||||
/* R block */
|
||||
#define T1_IS_ERROR(pcb) ((pcb) & 0x0FU)
|
||||
#define T1_EDC_ERROR 0x01U /* [b6..b1] = 0-N(R)-0001 */
|
||||
#define T1_OTHER_ERROR 0x02U /* [b6..b1] = 0-N(R)-0010 */
|
||||
#define T1_R_SEQ_SHIFT 4U /* N(R) position (b5) */
|
||||
|
||||
/* S block */
|
||||
#define T1_S_RESPONSE 0x20U /* If response: set bit b6, if request reset b6 in PCB S-Block */
|
||||
#define T1_S_RESYNC 0x00U /* RESYNCH: b6->b1: 000000 of PCB S-Block */
|
||||
#define T1_S_IFS 0x01U /* IFS: b6->b1: 000001 of PCB S-Block */
|
||||
#define T1_S_ABORT 0x02U /* ABORT: b6->b1: 000010 of PCB S-Block */
|
||||
#define T1_S_WTX 0x03U /* WTX: b6->b1: 000011 of PCB S-Block */
|
||||
|
||||
#define NAD 0U /* NAD byte position in the block */
|
||||
#define PCB 1U /* PCB byte position in the block */
|
||||
#define LEN 2U /* LEN byte position in the block */
|
||||
#define DATA 3U /* The position of the first byte of INF field in the block */
|
||||
|
||||
/* Modifiable parameters */
|
||||
#define SAD 0x0U /* Source address: reader (allowed values 0 -> 7) */
|
||||
#define DAD 0x0U /* Destination address: card (allowed values 0 -> 7) */
|
||||
#define IFSD_VALUE 254U /* Max length of INF field Supported by the reader */
|
||||
#define SC_FILE_SIZE 0x100U /* File size */
|
||||
#define SC_FILE_ID 0x0001U /* File identifier */
|
||||
#define SC_CLASS 0x00U
|
||||
|
||||
/* Constant parameters */
|
||||
#define INS_SELECT_FILE 0xA4U /* Select file instruction */
|
||||
#define INS_READ_FILE 0xB0U /* Read file instruction */
|
||||
#define INS_WRITE_FILE 0xD6U /* Write file instruction */
|
||||
#define TRAILER_LENGTH 2U /* Trailer length (SW1 and SW2: 2 bytes) */
|
||||
|
||||
#define SC_T1_RECEIVE_SUCCESS 0U
|
||||
#define SC_T1_BWT_TIMEOUT 1U
|
||||
#define SC_T1_CWT_TIMEOUT 2U
|
||||
|
||||
#define DEFAULT_FIDI_VALUE 0x11U
|
||||
#define PPS_REQUEST 0xFFU
|
||||
|
||||
/* SC Tree Structure -----------------------------------------------------------
|
||||
MasterFile
|
||||
________|___________
|
||||
| | |
|
||||
System UserData Note
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* SC ADPU Command: Operation Code -------------------------------------------*/
|
||||
#define SC_CLA_NAME 0x00U
|
||||
|
||||
/*------------------------ Data Area Management Commands ---------------------*/
|
||||
#define SC_SELECT_FILE 0xA4U
|
||||
#define SC_GET_RESPONCE 0xC0U
|
||||
#define SC_STATUS 0xF2U
|
||||
#define SC_UPDATE_BINARY 0xD6U
|
||||
#define SC_READ_BINARY 0xB0U
|
||||
#define SC_WRITE_BINARY 0xD0U
|
||||
#define SC_UPDATE_RECORD 0xDCU
|
||||
#define SC_READ_RECORD 0xB2U
|
||||
|
||||
/*-------------------------- Administrative Commands -------------------------*/
|
||||
#define SC_CREATE_FILE 0xE0U
|
||||
|
||||
/*-------------------------- Safety Management Commands ----------------------*/
|
||||
#define SC_VERIFY 0x20U
|
||||
#define SC_CHANGE 0x24U
|
||||
#define SC_DISABLE 0x26U
|
||||
#define SC_ENABLE 0x28U
|
||||
#define SC_UNBLOCK 0x2CU
|
||||
#define SC_EXTERNAL_AUTH 0x82U
|
||||
#define SC_GET_CHALLENGE 0x84U
|
||||
|
||||
/*-------------------------- Smartcard Interface Byte-------------------------*/
|
||||
#define SC_INTERFACEBYTE_TA 0U /* Interface byte TA(i) */
|
||||
#define SC_INTERFACEBYTE_TB 1U /* Interface byte TB(i) */
|
||||
#define SC_INTERFACEBYTE_TC 2U /* Interface byte TC(i) */
|
||||
#define SC_INTERFACEBYTE_TD 3U /* Interface byte TD(i) */
|
||||
|
||||
/*-------------------------- Answer to reset Commands ------------------------*/
|
||||
#define SC_GET_A2R 0x00U
|
||||
|
||||
/* SC STATUS: Status Code ----------------------------------------------------*/
|
||||
#define SC_EF_SELECTED 0x9FU
|
||||
#define SC_DF_SELECTED 0x9FU
|
||||
#define SC_OP_TERMINATED 0x9000U
|
||||
|
||||
/* Smartcard Voltage */
|
||||
#define SC_VOLTAGE_5V 0x00U
|
||||
#define SC_VOLTAGE_3V 0x01U
|
||||
#define SC_VOLTAGE_NOINIT 0xFFU
|
||||
/*----------------- ATR Protocole supported ----------------------------------*/
|
||||
#define ATR_T01 0x00U
|
||||
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
SC_POWER_ON = 0x00,
|
||||
SC_RESET_LOW = 0x01,
|
||||
SC_RESET_HIGH = 0x02,
|
||||
SC_ACTIVE = 0x03,
|
||||
SC_ACTIVE_ON_T0 = 0x04,
|
||||
SC_ACTIVE_ON_T1 = 0x05,
|
||||
SC_POWER_OFF = 0x06,
|
||||
SC_NO_INIT = 0x07
|
||||
|
||||
} SC_State;
|
||||
|
||||
/* Interface Byte structure - TA(i), TB(i), TC(i) and TD(i) ------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Status; /* The Presence of the Interface byte */
|
||||
uint8_t Value; /* The Value of the Interface byte */
|
||||
} SC_InterfaceByte;
|
||||
|
||||
/* Protocol Level structure - ------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
SC_InterfaceByte InterfaceByte[MAX_INTERFACEBYTE]; /* The Values of the Interface byte TA(i), TB(i), TC(i)and TD(i) */
|
||||
} SC_ProtocolLevel;
|
||||
|
||||
/* ATR structure - Answer To Reset -------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t TS; /* Bit Convention Direct/Indirect */
|
||||
uint8_t T0; /* Each bit in the high nibble = Presence of the further interface byte;
|
||||
Low nibble = Number of historical byte */
|
||||
|
||||
SC_ProtocolLevel T[MAX_PROTOCOLLEVEL]; /* Setup array */
|
||||
uint8_t H[HIST_LENGTH]; /* Historical array */
|
||||
uint8_t Tlength; /* Setup array dimension */
|
||||
uint8_t Hlength; /* Historical array dimension */
|
||||
uint8_t TCK;
|
||||
} SC_ATR;
|
||||
|
||||
/* ADPU-Header command structure ---------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t CLA; /* Command class */
|
||||
uint8_t INS; /* Operation code */
|
||||
uint8_t P1; /* Selection Mode */
|
||||
uint8_t P2; /* Selection Option */
|
||||
} SC_Header;
|
||||
|
||||
/* ADPU-Body command structure -----------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t LC; /* Data field length */
|
||||
uint8_t Data[LC_MAX]; /* Command parameters */
|
||||
uint8_t LE; /* Expected length of data to be returned */
|
||||
} SC_Body;
|
||||
|
||||
/* ADPU Command structure ----------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
SC_Header Header;
|
||||
SC_Body Body;
|
||||
} SC_ADPU_Commands;
|
||||
|
||||
/* SC response structure -----------------------------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Data[LC_MAX]; /* Data returned from the card */
|
||||
uint8_t SW1; /* Command Processing status */
|
||||
uint8_t SW2; /* Command Processing qualification */
|
||||
} SC_ADPU_Response;
|
||||
|
||||
/* SC Command Status -----------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
SC_CS_FAILED = 0x00,
|
||||
SC_CS_PIN_ENABLED = 0x01,
|
||||
SC_CS_PIN_VERIFIED = 0x02,
|
||||
SC_CS_READ = 0x03,
|
||||
SC_CS_PIN_CHANGED = 0x04
|
||||
|
||||
} SC_Command_State;
|
||||
/* SC Response Status -----------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
REP_OK = 0x00,
|
||||
REP_NOT_OK = 0x01,
|
||||
REP_NOT_SUPP = 0x02,
|
||||
REP_ENABLED = 0x03,
|
||||
REP_CHANGE = 0x04
|
||||
|
||||
} REP_Command_t;
|
||||
/* Conforming of Command with ICC APP -----------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
Command_OK = 0x00,
|
||||
Command_NOT_OK = 0x01,
|
||||
|
||||
} Command_State_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SC_DISABLED = 0U,
|
||||
SC_ENABLED = !SC_DISABLED
|
||||
} SCPowerState;
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/* APPLICATION LAYER ---------------------------------------------------------*/
|
||||
void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Response *SC_Response);
|
||||
void SC_PowerCmd(SCPowerState NewState);
|
||||
void SC_ParityErrorHandler(void);
|
||||
void SC_PTSConfig(void);
|
||||
uint8_t SC_Detect(void);
|
||||
uint32_t SC_GetDTableValue(uint32_t idx);
|
||||
void SC_VoltageConfig(uint32_t SC_Voltage);
|
||||
void SC_SetState(SC_State scState);
|
||||
void SC_IOConfig(void);
|
||||
|
||||
extern uint8_t SC_ATR_Table[40];
|
||||
extern SC_ATR SC_A2R;
|
||||
extern SC_ADPU_Response SC_Response;
|
||||
|
||||
extern uint8_t ProtocolNUM_OUT;
|
||||
extern SC_ADPU_Commands SC_ADPU;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CCID_SMARTCARD_TEMPLATE_H */
|
||||
968
Class/CCID/Src/usbd_ccid.c
Normal file
968
Class/CCID/Src/usbd_ccid.c
Normal file
@@ -0,0 +1,968 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ccid.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the high layer firmware functions to manage
|
||||
* all the functionalities of the USB CCID Class:
|
||||
*
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* CCID Class Driver Description
|
||||
* ===================================================================
|
||||
* This module manages the Specification for Integrated Circuit(s)
|
||||
* Cards Interface Revision 1.1
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Enumeration as CCID device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
|
||||
* and enumeration for each implemented memory interface
|
||||
* - Bulk OUT/IN data Transfers
|
||||
* - Requests management
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ccid.h"
|
||||
#include "usbd_ccid_cmd.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CCID
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CCID_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CCID_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CCID_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CCID_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static uint8_t USBD_CCID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
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_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
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_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pDst, uint16_t u8length);
|
||||
|
||||
static uint8_t *USBD_CCID_GetHSCfgDesc(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_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CCID_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* CCID interface class callbacks structure */
|
||||
USBD_ClassTypeDef USBD_CCID =
|
||||
{
|
||||
USBD_CCID_Init,
|
||||
USBD_CCID_DeInit,
|
||||
USBD_CCID_Setup,
|
||||
NULL, /*EP0_TxSent*/
|
||||
NULL, /*EP0_RxReady*/
|
||||
USBD_CCID_DataIn,
|
||||
USBD_CCID_DataOut,
|
||||
NULL, /*SOF */
|
||||
NULL, /*ISOIn*/
|
||||
NULL, /*ISOOut*/
|
||||
USBD_CCID_GetHSCfgDesc,
|
||||
USBD_CCID_GetFSCfgDesc,
|
||||
USBD_CCID_GetOtherSpeedCfgDesc,
|
||||
USBD_CCID_GetDeviceQualifierDescriptor,
|
||||
};
|
||||
|
||||
/* USB CCID device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CCID_CfgHSDesc[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, /* 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, /* 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_FS_MAX_PACKET_SIZE),
|
||||
HIBYTE(CCID_DATA_FS_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_FS_MAX_PACKET_SIZE),
|
||||
HIBYTE(CCID_DATA_FS_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_FS_BINTERVAL /* Polling interval in milliseconds */
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CCID_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,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CCID_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_Init
|
||||
* Initialize the CCID interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CCID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid;
|
||||
UNUSED(cfgidx);
|
||||
|
||||
/* Allocate CCID structure */
|
||||
hccid = (USBD_CCID_HandleTypeDef *)USBD_malloc(sizeof(USBD_CCID_HandleTypeDef));
|
||||
|
||||
if (hccid == NULL)
|
||||
{
|
||||
pdev->pClassData = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
pdev->pClassData = (void *)hccid;
|
||||
|
||||
/* 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.bSeq = 0U;
|
||||
hccid->USBD_CCID_Param.bSlot = 0U;
|
||||
hccid->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? \
|
||||
CCID_DATA_HS_MAX_PACKET_SIZE : CCID_DATA_FS_MAX_PACKET_SIZE;
|
||||
|
||||
/* Open EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, CCID_IN_EP, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
||||
pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP OUT */
|
||||
(void)USBD_LL_OpenEP(pdev, CCID_OUT_EP, USBD_EP_TYPE_BULK, (uint16_t)hccid->MaxPcktLen);
|
||||
pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open INTR EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, CCID_CMD_EP,
|
||||
USBD_EP_TYPE_INTR, CCID_CMD_PACKET_SIZE);
|
||||
pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Init physical Interface components */
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->Init(pdev);
|
||||
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP,
|
||||
hccid->data, hccid->MaxPcktLen);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_DeInit
|
||||
* DeInitialize the CCID layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CCID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
/* Close EP IN */
|
||||
(void)USBD_LL_CloseEP(pdev, CCID_IN_EP);
|
||||
pdev->ep_in[CCID_IN_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP OUT */
|
||||
(void)USBD_LL_CloseEP(pdev, CCID_OUT_EP);
|
||||
pdev->ep_out[CCID_OUT_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP Command */
|
||||
(void)USBD_LL_CloseEP(pdev, CCID_CMD_EP);
|
||||
pdev->ep_in[CCID_CMD_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->DeInit(pdev);
|
||||
(void)USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_Setup
|
||||
* Handle the CCID specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CCID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
uint8_t ifalt = 0U;
|
||||
uint16_t status_info = 0U;
|
||||
uint16_t len;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
/* Class request */
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
if (req->wLength != 0U)
|
||||
{
|
||||
len = MIN(CCID_EP0_BUFF_SIZ, req->wLength);
|
||||
if ((req->bmRequest & 0x80U) != 0U)
|
||||
{
|
||||
hCCIDitf->Control(req->bRequest, hccid->data, &len);
|
||||
(void)USBD_CtlSendData(pdev, hccid->data, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)USBD_CtlPrepareRx(pdev, hccid->data, len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
len = 0U;
|
||||
hCCIDitf->Control(req->bRequest, (uint8_t *)&req->wValue, &len);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Interface & Endpoint request */
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
(void)USBD_CtlSendData(pdev, &ifalt, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_DataIn
|
||||
* Data sent on non-control IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CCID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (epnum == (CCID_IN_EP & 0x7FU))
|
||||
{
|
||||
/* Filter the epnum by masking with 0x7f (mask of IN Direction) */
|
||||
|
||||
/*************** Handle Bulk Transfer IN data completion *****************/
|
||||
|
||||
switch (hccid->blkt_state)
|
||||
{
|
||||
case CCID_STATE_SEND_RESP:
|
||||
|
||||
/* won't wait ack to avoid missing a command */
|
||||
hccid->blkt_state = CCID_STATE_IDLE;
|
||||
|
||||
/* Prepare EP to Receive Cmd */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP,
|
||||
hccid->data, CCID_DATA_FS_MAX_PACKET_SIZE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (epnum == (CCID_CMD_EP & 0x7FU))
|
||||
{
|
||||
/* Filter the epnum by masking with 0x7f (mask of IN Direction) */
|
||||
|
||||
/*************** Handle Interrupt Transfer IN data completion *****************/
|
||||
|
||||
(void)USBD_CCID_IntMessage(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CCID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
uint16_t CurrPcktLen;
|
||||
|
||||
if (hccid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
if (epnum == CCID_OUT_EP)
|
||||
{
|
||||
CurrPcktLen = (uint16_t)USBD_GetRxCount(pdev, epnum);
|
||||
|
||||
switch (hccid->blkt_state)
|
||||
{
|
||||
case CCID_STATE_IDLE:
|
||||
|
||||
if (CurrPcktLen >= (uint16_t)CCID_CMD_HEADER_SIZE)
|
||||
{
|
||||
hccid->UsbMessageLength = CurrPcktLen; /* Store for future use */
|
||||
|
||||
/* Fill CCID_BulkOut Data Buffer from USB Buffer */
|
||||
(void)USBD_CCID_ReceiveCmdHeader(pdev, (uint8_t *)&hccid->UsbBlkOutData.bMessageType,
|
||||
(uint16_t)CurrPcktLen);
|
||||
|
||||
/*
|
||||
Refer : 6 CCID Messages
|
||||
The response messages always contain the exact same slot number,
|
||||
and sequence number fields from the header that was contained in
|
||||
the Bulk-OUT command message.
|
||||
*/
|
||||
hccid->UsbBlkInData.bSlot = hccid->UsbBlkOutData.bSlot;
|
||||
hccid->UsbBlkInData.bSeq = hccid->UsbBlkOutData.bSeq;
|
||||
|
||||
if (CurrPcktLen < hccid->MaxPcktLen)
|
||||
{
|
||||
/* Short message, less than the EP Out Size, execute the command,
|
||||
if parameter like dwLength is too big, the appropriate command will
|
||||
give an error */
|
||||
(void)USBD_CCID_DispatchCommand(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Check if length of data to be sent by host is > buffer size */
|
||||
if (hccid->UsbBlkOutData.dwLength > (uint32_t)ABDATA_SIZE)
|
||||
{
|
||||
/* Too long data received.... Error ! */
|
||||
hccid->blkt_state = CCID_STATE_UNCORRECT_LENGTH;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Expect more data on OUT EP */
|
||||
hccid->blkt_state = CCID_STATE_RECEIVE_DATA;
|
||||
|
||||
/* Prepare EP to Receive next Cmd */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP,
|
||||
hccid->data, hccid->MaxPcktLen);
|
||||
|
||||
} /* if (CurrPcktLen == CCID_DATA_MAX_PACKET_SIZE) ends */
|
||||
} /* if (CurrPcktLen >= CCID_DATA_MAX_PACKET_SIZE) ends */
|
||||
} /* if (CurrPcktLen >= CCID_CMD_HEADER_SIZE) ends */
|
||||
else
|
||||
{
|
||||
if (CurrPcktLen == 0x00U) /* Zero Length Packet Received */
|
||||
{
|
||||
hccid->blkt_state = CCID_STATE_IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CCID_STATE_RECEIVE_DATA:
|
||||
hccid->UsbMessageLength += CurrPcktLen;
|
||||
|
||||
if (CurrPcktLen < hccid->MaxPcktLen)
|
||||
{
|
||||
/* Short message, less than the EP Out Size, execute the command,
|
||||
if parameter like dwLength is too big, the appropriate command will
|
||||
give an error */
|
||||
|
||||
/* Full command is received, process the Command */
|
||||
(void)USBD_CCID_ReceiveCmdHeader(pdev, (uint8_t *)&hccid->UsbBlkOutData.bMessageType,
|
||||
(uint16_t)CurrPcktLen);
|
||||
|
||||
(void)USBD_CCID_DispatchCommand(pdev);
|
||||
}
|
||||
else if (CurrPcktLen == hccid->MaxPcktLen)
|
||||
{
|
||||
if (hccid->UsbMessageLength < (hccid->UsbBlkOutData.dwLength + (uint32_t)CCID_CMD_HEADER_SIZE))
|
||||
{
|
||||
(void)USBD_CCID_ReceiveCmdHeader(pdev, (uint8_t *)&hccid->UsbBlkOutData.bMessageType,
|
||||
(uint16_t)CurrPcktLen); /* Copy data */
|
||||
|
||||
/* Prepare EP to Receive next Cmd */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CCID_OUT_EP,
|
||||
hccid->data, hccid->MaxPcktLen);
|
||||
}
|
||||
else if (hccid->UsbMessageLength == (hccid->UsbBlkOutData.dwLength + (uint32_t)CCID_CMD_HEADER_SIZE))
|
||||
{
|
||||
/* Full command is received, process the Command */
|
||||
(void)USBD_CCID_ReceiveCmdHeader(pdev, (uint8_t *)&hccid->UsbBlkOutData.bMessageType,
|
||||
(uint16_t)CurrPcktLen);
|
||||
|
||||
(void)USBD_CCID_DispatchCommand(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Too long data received.... Error ! */
|
||||
hccid->blkt_state = CCID_STATE_UNCORRECT_LENGTH;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Too long data received.... Error ! */
|
||||
hccid->blkt_state = CCID_STATE_UNCORRECT_LENGTH;
|
||||
}
|
||||
break;
|
||||
|
||||
case CCID_STATE_UNCORRECT_LENGTH:
|
||||
hccid->blkt_state = CCID_STATE_IDLE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_DispatchCommand
|
||||
* Parse the commands and Process command
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_CCID_DispatchCommand(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
uint8_t errorCode;
|
||||
|
||||
switch (hccid->UsbBlkOutData.bMessageType)
|
||||
{
|
||||
case PC_TO_RDR_ICCPOWERON:
|
||||
errorCode = PC_to_RDR_IccPowerOn(pdev);
|
||||
RDR_to_PC_DataBlock(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_ICCPOWEROFF:
|
||||
errorCode = PC_to_RDR_IccPowerOff(pdev);
|
||||
RDR_to_PC_SlotStatus(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_GETSLOTSTATUS:
|
||||
errorCode = PC_to_RDR_GetSlotStatus(pdev);
|
||||
RDR_to_PC_SlotStatus(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_XFRBLOCK:
|
||||
errorCode = PC_to_RDR_XfrBlock(pdev);
|
||||
RDR_to_PC_DataBlock(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_GETPARAMETERS:
|
||||
errorCode = PC_to_RDR_GetParameters(pdev);
|
||||
RDR_to_PC_Parameters(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_RESETPARAMETERS:
|
||||
errorCode = PC_to_RDR_ResetParameters(pdev);
|
||||
RDR_to_PC_Parameters(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_SETPARAMETERS:
|
||||
errorCode = PC_to_RDR_SetParameters(pdev);
|
||||
RDR_to_PC_Parameters(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_ESCAPE:
|
||||
errorCode = PC_to_RDR_Escape(pdev);
|
||||
RDR_to_PC_Escape(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_ICCCLOCK:
|
||||
errorCode = PC_to_RDR_IccClock(pdev);
|
||||
RDR_to_PC_SlotStatus(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_ABORT:
|
||||
errorCode = PC_to_RDR_Abort(pdev);
|
||||
RDR_to_PC_SlotStatus(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_T0APDU:
|
||||
errorCode = PC_TO_RDR_T0Apdu(pdev);
|
||||
RDR_to_PC_SlotStatus(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_MECHANICAL:
|
||||
errorCode = PC_TO_RDR_Mechanical(pdev);
|
||||
RDR_to_PC_SlotStatus(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_SETDATARATEANDCLOCKFREQUENCY:
|
||||
errorCode = PC_TO_RDR_SetDataRateAndClockFrequency(pdev);
|
||||
RDR_to_PC_DataRateAndClockFrequency(errorCode, pdev);
|
||||
break;
|
||||
|
||||
case PC_TO_RDR_SECURE:
|
||||
errorCode = PC_TO_RDR_Secure(pdev);
|
||||
RDR_to_PC_DataBlock(errorCode, pdev);
|
||||
break;
|
||||
|
||||
default:
|
||||
RDR_to_PC_SlotStatus(SLOTERROR_CMD_NOT_SUPPORTED, pdev);
|
||||
break;
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_Transfer_Data_Request
|
||||
* Prepare the request response to be sent to the host
|
||||
* @param pdev: device instance
|
||||
* @param dataPointer: Pointer to the data buffer to send
|
||||
* @param dataLen : number of bytes to send
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_CCID_Transfer_Data_Request(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *dataPointer, uint16_t dataLen)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CCID_ItfTypeDef *hCCIDitf = (USBD_CCID_ItfTypeDef *)pdev->pUserData;
|
||||
|
||||
UNUSED(dataPointer);
|
||||
|
||||
hccid->blkt_state = CCID_STATE_SEND_RESP;
|
||||
hccid->UsbMessageLength = hccid->UsbBlkInData.dwLength + (uint32_t)dataLen; /* Store for future use */
|
||||
|
||||
/* use the header declared size packet must be well formed */
|
||||
hCCIDitf->Response_SendData(pdev, (uint8_t *)&hccid->UsbBlkInData,
|
||||
(uint16_t)MIN(CCID_DATA_FS_MAX_PACKET_SIZE, hccid->UsbMessageLength));
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_ReceiveCmdHeader
|
||||
* Receive the Data from USB BulkOut Buffer to Pointer
|
||||
* @param pdev: device instance
|
||||
* @param pDst: destination address to copy the buffer
|
||||
* @param u8length: length of data to copy
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CCID_ReceiveCmdHeader(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pDst, uint16_t u8length)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
uint8_t *pdst = pDst;
|
||||
uint32_t Counter;
|
||||
|
||||
for (Counter = 0U; Counter < u8length; Counter++)
|
||||
{
|
||||
*pdst = hccid->data[Counter];
|
||||
pdst++;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_IntMessage
|
||||
* Send the Interrupt-IN data to the host
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
uint8_t USBD_CCID_IntMessage(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* Check if there is change in Smartcard Slot status */
|
||||
if (CCID_IsSlotStatusChange(pdev) != 0U)
|
||||
{
|
||||
/* Check Slot Status is changed. Card is Removed/Fitted */
|
||||
RDR_to_PC_NotifySlotChange(pdev);
|
||||
|
||||
/* Set the Slot status */
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->SetSlotStatus(pdev);
|
||||
|
||||
(void)USBD_LL_Transmit(pdev, CCID_CMD_EP, hccid->UsbIntData, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the Slot status */
|
||||
((USBD_CCID_ItfTypeDef *)pdev->pUserData)->SetSlotStatus(pdev);
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_GetHSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param length pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CCID_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_CCID_CfgHSDesc);
|
||||
return USBD_CCID_CfgHSDesc;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_CCID_GetFSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CCID_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_CCID_CfgFSDesc);
|
||||
return USBD_CCID_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_GetOtherSpeedCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CCID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_CCID_CfgFSDesc);
|
||||
return USBD_CCID_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_GetDeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CCID_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)(sizeof(USBD_CCID_DeviceQualifierDesc));
|
||||
return USBD_CCID_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CCID_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: CD Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CCID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CCID_ItfTypeDef *fops)
|
||||
{
|
||||
if (fops == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
pdev->pUserData = fops;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
1094
Class/CCID/Src/usbd_ccid_cmd.c
Normal file
1094
Class/CCID/Src/usbd_ccid_cmd.c
Normal file
File diff suppressed because it is too large
Load Diff
254
Class/CCID/Src/usbd_ccid_if_template.c
Normal file
254
Class/CCID/Src/usbd_ccid_if_template.c
Normal file
@@ -0,0 +1,254 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ccid_if_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides all the functions for USB Interface for CCID
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ccid.h"
|
||||
#include "usbd_ccid_if_template.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static REP_Command_t REP_command;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static uint8_t CCID_Init(USBD_HandleTypeDef *pdev);
|
||||
static 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_Response_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len);
|
||||
static uint8_t CCID_Send_Process(uint8_t *Command, uint8_t *Data);
|
||||
static uint8_t CCID_Response_Process(void);
|
||||
static uint8_t CCID_SetSlotStatus(USBD_HandleTypeDef *pdev);
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
USBD_CCID_ItfTypeDef USBD_CCID_If_fops =
|
||||
{
|
||||
CCID_Init,
|
||||
CCID_DeInit,
|
||||
CCID_ControlReq,
|
||||
CCID_Response_SendData,
|
||||
CCID_Send_Process,
|
||||
CCID_SetSlotStatus,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief CCID_Init
|
||||
* Initialize the CCID USB Layer
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t CCID_Init(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* CCID Related Initialization */
|
||||
|
||||
hccid->blkt_state = CCID_STATE_IDLE;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CCID_DeInit
|
||||
* Uninitialize the CCID Machine
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t CCID_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hccid->blkt_state = CCID_STATE_IDLE;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CCID_ControlReq
|
||||
* Manage the CCID class requests
|
||||
* @param Cmd: Command code
|
||||
* @param Buf: Buffer containing command data (request parameters)
|
||||
* @param Len: Number of data to be sent (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static uint8_t CCID_ControlReq(uint8_t req, uint8_t *pbuf, uint16_t *length)
|
||||
{
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)(USBD_Device.pClassData);
|
||||
UNUSED(length);
|
||||
|
||||
switch (req)
|
||||
{
|
||||
case REQUEST_ABORT:
|
||||
/* The wValue field contains the slot number (bSlot) in the low byte
|
||||
and the sequence number (bSeq) in the high byte.*/
|
||||
hccid->slot_nb = ((uint16_t) * pbuf & 0x0fU);
|
||||
hccid->seq_nb = (((uint16_t) * pbuf & 0xf0U) >> 8);
|
||||
|
||||
if (CCID_CmdAbort((uint8_t)hccid->slot_nb, (uint8_t)hccid->seq_nb) != 0U)
|
||||
{
|
||||
/* If error is returned by lower layer :
|
||||
Generally Slot# may not have matched */
|
||||
return (int8_t)USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case REQUEST_GET_CLOCK_FREQUENCIES:
|
||||
|
||||
/* User have to fill the pbuf with the GetClockFrequency data buffer */
|
||||
|
||||
break;
|
||||
|
||||
case REQUEST_GET_DATA_RATES:
|
||||
|
||||
/* User have to fill the pbuf with the GetDataRates data buffer */
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
UNUSED(pbuf);
|
||||
|
||||
return ((int8_t)USBD_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CCID_Response_SendData
|
||||
* Send the data on bulk-in EP
|
||||
* @param pdev: device instance
|
||||
* @param buf: pointer to data buffer
|
||||
* @param len: Data Length
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t CCID_Response_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf, uint16_t len)
|
||||
{
|
||||
(void)USBD_LL_Transmit(pdev, CCID_IN_EP, buf, len);
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CCID_SEND_Process
|
||||
* @param Command: pointer to a buffer containing command header
|
||||
* @param Data: pointer to a buffer containing data sent from Host
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static uint8_t CCID_Send_Process(uint8_t *Command, uint8_t *Data)
|
||||
{
|
||||
Command_State_t Command_State = Command_NOT_OK;
|
||||
|
||||
/* Initialize ICC APP header */
|
||||
uint8_t SC_Command[5] = {0};
|
||||
UNUSED(Data);
|
||||
UNUSED(Command_State);
|
||||
UNUSED(SC_Command);
|
||||
|
||||
/* Start SC Demo ---------------------------------------------------------*/
|
||||
switch (Command[1]) /* type of instruction */
|
||||
{
|
||||
case SC_ENABLE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case SC_VERIFY:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case SC_READ_BINARY :
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case SC_CHANGE :
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* check if Command header is OK */
|
||||
(void)CCID_Response_Process(); /* Get ICC response */
|
||||
|
||||
return ((uint8_t)USBD_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CCID_Response_Process
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static uint8_t CCID_Response_Process(void)
|
||||
{
|
||||
switch (REP_command)
|
||||
{
|
||||
case REP_OK:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case REP_NOT_OK :
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case REP_NOT_SUPP :
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case REP_ENABLED :
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case REP_CHANGE :
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ((uint8_t)USBD_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CCID_SetSlotStatus
|
||||
* Set Slot Status of the Interrupt Transfer
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t CCID_SetSlotStatus(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Get the CCID handler pointer */
|
||||
USBD_CCID_HandleTypeDef *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if ((hccid->SlotStatus.SlotStatus) == 1U) /* Transfer Complete Status
|
||||
of previous Interrupt transfer */
|
||||
{
|
||||
/* Add your code here */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add your code here */
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
473
Class/CCID/Src/usbd_ccid_sc_if_template.c
Normal file
473
Class/CCID/Src/usbd_ccid_sc_if_template.c
Normal file
@@ -0,0 +1,473 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ccid_sc_if_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief SmartCard Interface 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ccid_sc_if_template.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* State Machine for the SmartCard Interface */
|
||||
static SC_State SCState = SC_POWER_OFF;
|
||||
|
||||
/* APDU Transport Structures */
|
||||
SC_ADPU_Commands SC_ADPU;
|
||||
SC_ADPU_Response SC_Response;
|
||||
SC_Param_t SC_Param;
|
||||
Protocol_01_DataTypeDef ProtocolData;
|
||||
|
||||
/* Extern variables ----------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void SC_SaveVoltage(uint8_t voltage);
|
||||
static void SC_Itf_UpdateParams(void);
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief SC_Itf_IccPowerOn Manages the Warm and Cold Reset
|
||||
and get the Answer to Reset from ICC
|
||||
* @param voltage: required by host
|
||||
* @retval None
|
||||
*/
|
||||
void SC_Itf_IccPowerOn(uint8_t voltage)
|
||||
{
|
||||
SCState = SC_POWER_ON;
|
||||
SC_ADPU.Header.CLA = 0x00U;
|
||||
SC_ADPU.Header.INS = SC_GET_A2R;
|
||||
SC_ADPU.Header.P1 = 0x00U;
|
||||
SC_ADPU.Header.P2 = 0x00U;
|
||||
SC_ADPU.Body.LC = 0x00U;
|
||||
|
||||
/* Power ON the card */
|
||||
SC_PowerCmd(SC_ENABLED);
|
||||
|
||||
/* Configure the Voltage, Even if IO is still not configured */
|
||||
SC_VoltageConfig(voltage);
|
||||
|
||||
while ((SCState != SC_ACTIVE_ON_T0) && (SCState != SC_ACTIVE_ON_T1)
|
||||
&& (SCState != SC_NO_INIT))
|
||||
{
|
||||
/* If Either The Card has become Active or Become De-Active */
|
||||
SC_Handler(&SCState, &SC_ADPU, &SC_Response);
|
||||
}
|
||||
|
||||
if ((SCState == SC_ACTIVE_ON_T0) || (SCState == SC_ACTIVE_ON_T1))
|
||||
{
|
||||
SC_Itf_UpdateParams();
|
||||
/* Apply the Procedure Type Selection (PTS) */
|
||||
SC_PTSConfig();
|
||||
|
||||
/* Save Voltage for Future use */
|
||||
SC_SaveVoltage(voltage);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_Itf_IccPowerOff Power OFF the card
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SC_Itf_IccPowerOff(void)
|
||||
{
|
||||
SC_PowerCmd(SC_DISABLED);
|
||||
SC_SetState(SC_POWER_OFF);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize the parameters structures to the default value
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SC_Itf_InitParams(void)
|
||||
{
|
||||
/*
|
||||
FI, the reference to a clock rate conversion factor
|
||||
over the bits b8 to b5
|
||||
- DI, the reference to a baud rate adjustment factor
|
||||
over the bits b4 to bl
|
||||
*/
|
||||
SC_Param.SC_A2R_FiDi = DEFAULT_FIDI;
|
||||
SC_Param.SC_hostFiDi = DEFAULT_FIDI;
|
||||
|
||||
ProtocolData.bmFindexDindex = DEFAULT_FIDI;
|
||||
|
||||
/* Placeholder, Ignored */
|
||||
/* 0 = Direct, first byte of the ICC ATR data. */
|
||||
ProtocolData.bmTCCKST0 = DEFAULT_T01CONVCHECKSUM;
|
||||
|
||||
/* Extra GuardTime = 0 etu */
|
||||
ProtocolData.bGuardTimeT0 = DEFAULT_EXTRA_GUARDTIME;
|
||||
ProtocolData.bWaitingIntegerT0 = DEFAULT_WAITINGINTEGER;
|
||||
ProtocolData.bClockStop = 0U; /* Stopping the Clock is not allowed */
|
||||
|
||||
/*T=1 protocol */
|
||||
ProtocolData.bIfsc = DEFAULT_IFSC;
|
||||
ProtocolData.bNad = DEFAULT_NAD;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Save the A2R Parameters for further usage
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SC_Itf_UpdateParams(void)
|
||||
{
|
||||
/*
|
||||
FI, the reference to a clock rate conversion factor
|
||||
over the bits b8 to b5
|
||||
DI, the reference to a baud rate adjustment factor
|
||||
over the bits b4 to bl
|
||||
*/
|
||||
SC_Param.SC_A2R_FiDi = SC_A2R.T[0].InterfaceByte[0].Value;
|
||||
SC_Param.SC_hostFiDi = SC_A2R.T[0].InterfaceByte[0].Value;
|
||||
|
||||
ProtocolData.bmFindexDindex = SC_A2R.T[0].InterfaceByte[0].Value;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_Itf_SetParams
|
||||
* Set the parameters for CCID/USART interface
|
||||
* @param pPtr: pointer to buffer containing the
|
||||
* parameters to be set in USART
|
||||
* @param T_01: type of protocol, T=1 or T=0
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t SC_Itf_SetParams(Protocol_01_DataTypeDef *pPtr, uint8_t T_01)
|
||||
{
|
||||
/* uint16_t guardTime; */ /* Keep it 16b for handling 8b additions */
|
||||
uint32_t fi_new;
|
||||
uint32_t di_new;
|
||||
Protocol_01_DataTypeDef New_DataStructure;
|
||||
fi_new = pPtr->bmFindexDindex;
|
||||
di_new = pPtr->bmFindexDindex;
|
||||
|
||||
New_DataStructure.bmTCCKST0 = pPtr->bmTCCKST0;
|
||||
|
||||
New_DataStructure.bGuardTimeT0 = pPtr->bGuardTimeT0;
|
||||
New_DataStructure.bWaitingIntegerT0 = pPtr->bWaitingIntegerT0;
|
||||
New_DataStructure.bClockStop = pPtr->bClockStop;
|
||||
if (T_01 == 0x01U)
|
||||
{
|
||||
New_DataStructure.bIfsc = pPtr->bIfsc;
|
||||
New_DataStructure.bNad = pPtr->bNad;
|
||||
}
|
||||
else
|
||||
{
|
||||
New_DataStructure.bIfsc = 0x00U;
|
||||
New_DataStructure.bNad = 0x00U;
|
||||
}
|
||||
|
||||
/* Check for the FIDI Value set by Host */
|
||||
di_new &= (uint8_t)0x0F;
|
||||
if (SC_GetDTableValue(di_new) == 0U)
|
||||
{
|
||||
return SLOTERROR_BAD_FIDI;
|
||||
}
|
||||
|
||||
fi_new >>= 4U;
|
||||
fi_new &= 0x0FU;
|
||||
|
||||
if (SC_GetDTableValue(fi_new) == 0U)
|
||||
{
|
||||
return SLOTERROR_BAD_FIDI;
|
||||
}
|
||||
|
||||
if ((T_01 == 0x00U)
|
||||
&& (New_DataStructure.bmTCCKST0 != 0x00U)
|
||||
&& (New_DataStructure.bmTCCKST0 != 0x02U))
|
||||
{
|
||||
return SLOTERROR_BAD_T01CONVCHECKSUM;
|
||||
}
|
||||
|
||||
if ((T_01 == 0x01U)
|
||||
&& (New_DataStructure.bmTCCKST0 != 0x10U)
|
||||
&& (New_DataStructure.bmTCCKST0 != 0x11U)
|
||||
&& (New_DataStructure.bmTCCKST0 != 0x12U)
|
||||
&& (New_DataStructure.bmTCCKST0 != 0x13U))
|
||||
{
|
||||
return SLOTERROR_BAD_T01CONVCHECKSUM;
|
||||
}
|
||||
|
||||
if ((New_DataStructure.bWaitingIntegerT0 >= 0xA0U)
|
||||
&& ((New_DataStructure.bmTCCKST0 & 0x10U) == 0x10U))
|
||||
{
|
||||
return SLOTERROR_BAD_WAITINGINTEGER;
|
||||
}
|
||||
if ((New_DataStructure.bClockStop != 0x00U)
|
||||
&& (New_DataStructure.bClockStop != 0x03U))
|
||||
{
|
||||
return SLOTERROR_BAD_CLOCKSTOP;
|
||||
}
|
||||
if (New_DataStructure.bNad != 0x00U)
|
||||
{
|
||||
return SLOTERROR_BAD_NAD;
|
||||
}
|
||||
/* Put Total GuardTime in USART Settings */
|
||||
/* USART_SetGuardTime(SC_USART, (uint8_t)(guardTime + DEFAULT_EXTRA_GUARDTIME)); */
|
||||
|
||||
/* Save Extra GuardTime Value */
|
||||
ProtocolData.bGuardTimeT0 = New_DataStructure.bGuardTimeT0;
|
||||
ProtocolData.bmTCCKST0 = New_DataStructure.bmTCCKST0;
|
||||
ProtocolData.bWaitingIntegerT0 = New_DataStructure.bWaitingIntegerT0;
|
||||
ProtocolData.bClockStop = New_DataStructure.bClockStop;
|
||||
ProtocolData.bIfsc = New_DataStructure.bIfsc;
|
||||
ProtocolData.bNad = New_DataStructure.bNad;
|
||||
|
||||
/* Save New bmFindexDindex */
|
||||
SC_Param.SC_hostFiDi = pPtr->bmFindexDindex;
|
||||
SC_PTSConfig();
|
||||
|
||||
ProtocolData.bmFindexDindex = pPtr->bmFindexDindex;
|
||||
|
||||
return SLOT_NO_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_Itf_Escape function from the host
|
||||
* This is user implementable
|
||||
* @param ptrEscape: pointer to buffer containing the Escape data
|
||||
* @param escapeLen: length of escaped data
|
||||
* @param responseBuff: pointer containing escape buffer response
|
||||
* @param responseLen: length of escape response buffer
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t SC_Itf_Escape(uint8_t *ptrEscape, uint32_t escapeLen,
|
||||
uint8_t *responseBuff, uint32_t *responseLen)
|
||||
{
|
||||
UNUSED(ptrEscape);
|
||||
UNUSED(escapeLen);
|
||||
UNUSED(responseBuff);
|
||||
UNUSED(responseLen);
|
||||
|
||||
/* Manufacturer specific implementation ... */
|
||||
/*
|
||||
uint32_t idx;
|
||||
uint8_t *pResBuff = responseBuff;
|
||||
uint8_t *pEscape = ptrEscape;
|
||||
|
||||
for(idx = 0; idx < escapeLen; idx++)
|
||||
{
|
||||
*pResBuff = *pEscape;
|
||||
pResBuff++;
|
||||
pEscape++;
|
||||
}
|
||||
|
||||
*responseLen = escapeLen;
|
||||
*/
|
||||
return SLOT_NO_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_Itf_SetClock function to define Clock Status request from the host.
|
||||
* This is user implementable
|
||||
* @param bClockCommand: Clock status from the host
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t SC_Itf_SetClock(uint8_t bClockCommand)
|
||||
{
|
||||
/* bClockCommand
|
||||
00h restarts Clock
|
||||
01h Stops Clock in the state shown in the bClockStop
|
||||
field of the PC_to_RDR_SetParameters command
|
||||
and RDR_to_PC_Parameters message.*/
|
||||
|
||||
if (bClockCommand == 0U)
|
||||
{
|
||||
/* 00h restarts Clock : Since Clock is always running, PASS this command */
|
||||
return SLOT_NO_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bClockCommand == 1U)
|
||||
{
|
||||
return SLOTERROR_BAD_CLOCKCOMMAND;
|
||||
}
|
||||
}
|
||||
|
||||
return SLOTERROR_CMD_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_Itf_XferBlock function from the host.
|
||||
* This is user implementable
|
||||
* @param ptrBlock : Pointer containing the data from host
|
||||
* @param blockLen : length of block data for the data transfer
|
||||
* @param expectedLen: expected length of data transfer
|
||||
* @param CCID_BulkIn_Data: Pointer containing the CCID Bulk In Data Structure
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t SC_Itf_XferBlock(uint8_t *ptrBlock, uint32_t blockLen, uint16_t expectedLen,
|
||||
USBD_CCID_BulkIn_DataTypeDef *CCID_BulkIn_Data)
|
||||
{
|
||||
uint8_t ErrorCode = SLOT_NO_ERROR;
|
||||
UNUSED(CCID_BulkIn_Data);
|
||||
UNUSED(expectedLen);
|
||||
UNUSED(blockLen);
|
||||
UNUSED(ptrBlock);
|
||||
|
||||
if (ProtocolNUM_OUT == 0x00U)
|
||||
{
|
||||
/* Add your code here */
|
||||
}
|
||||
|
||||
if (ProtocolNUM_OUT == 0x01U)
|
||||
{
|
||||
/* Add your code here */
|
||||
}
|
||||
|
||||
if (ErrorCode != SLOT_NO_ERROR)
|
||||
{
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
return ErrorCode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief SC_Itf_T0Apdu
|
||||
Class Specific Request from the host to provide supported data rates
|
||||
* This is Optional function & user implementable
|
||||
* @param bmChanges : value specifying which parameter is valid in
|
||||
* command among next bClassGetResponse, bClassEnvelope
|
||||
* @param bClassGetResponse : Value to force the class byte of the
|
||||
* header in a Get Response command.
|
||||
* @param bClassEnvelope : Value to force the class byte of the header
|
||||
* in a Envelope command.
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t SC_Itf_T0Apdu(uint8_t bmChanges, uint8_t bClassGetResponse,
|
||||
uint8_t bClassEnvelope)
|
||||
{
|
||||
UNUSED(bClassEnvelope);
|
||||
UNUSED(bClassGetResponse);
|
||||
|
||||
/* User have to fill the pbuf with the GetDataRates data buffer */
|
||||
|
||||
if (bmChanges == 0U)
|
||||
{
|
||||
/* Bit cleared indicates that the associated field is not significant and
|
||||
that default behaviour defined in CCID class descriptor is selected */
|
||||
return SLOT_NO_ERROR;
|
||||
}
|
||||
|
||||
return SLOTERROR_CMD_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_Itf_Mechanical
|
||||
Mechanical Function being requested by Host
|
||||
* This is Optional function & user implementable
|
||||
* @param bFunction : value corresponds to the mechanical function
|
||||
* being requested by host
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t SC_Itf_Mechanical(uint8_t bFunction)
|
||||
{
|
||||
UNUSED(bFunction);
|
||||
|
||||
return SLOTERROR_CMD_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_Itf_SetDataRateAndClockFrequency
|
||||
* Set the Clock and data Rate of the Interface
|
||||
* This is Optional function & user implementable
|
||||
* @param dwClockFrequency : value of clock in kHz requested by host
|
||||
* @param dwDataRate : value of data rate requested by host
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t SC_Itf_SetDataRateAndClockFrequency(uint32_t dwClockFrequency,
|
||||
uint32_t dwDataRate)
|
||||
{
|
||||
/* User have to fill the pbuf with the GetDataRates data buffer */
|
||||
|
||||
if ((dwDataRate == USBD_CCID_DEFAULT_DATA_RATE) &&
|
||||
(dwClockFrequency == USBD_CCID_DEFAULT_CLOCK_FREQ))
|
||||
{
|
||||
return SLOT_NO_ERROR;
|
||||
}
|
||||
|
||||
return SLOTERROR_CMD_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_Itf_Secure
|
||||
* Process the Secure command
|
||||
* This is Optional function & user implementable
|
||||
* @param dwLength : length of data from the host
|
||||
* @param bBWI : Block Waiting Timeout sent by host
|
||||
* @param wLevelParameter : Parameters sent by host
|
||||
* @param pbuf : buffer containing the data
|
||||
* @param returnLen : Length of data expected to return
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t SC_Itf_Secure(uint32_t dwLength, uint8_t bBWI, uint16_t wLevelParameter,
|
||||
uint8_t *pbuf, uint32_t *returnLen)
|
||||
{
|
||||
UNUSED(pbuf);
|
||||
UNUSED(wLevelParameter);
|
||||
UNUSED(bBWI);
|
||||
UNUSED(dwLength);
|
||||
*returnLen = 0U;
|
||||
|
||||
return SLOTERROR_CMD_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_SaveVoltage
|
||||
Saves the voltage value to be saved for further usage
|
||||
* @param voltage: voltage value to be saved for further usage
|
||||
* @retval None
|
||||
*/
|
||||
static void SC_SaveVoltage(uint8_t voltage)
|
||||
{
|
||||
SC_Param.voltage = voltage;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Provides the value of SCState variable
|
||||
* @param None
|
||||
* @retval uint8_t SCState
|
||||
*/
|
||||
uint8_t SC_GetState(void)
|
||||
{
|
||||
return (uint8_t)SCState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the value of SCState variable to Off
|
||||
* @param scState: value of SCState to be updated
|
||||
* @retval None
|
||||
*/
|
||||
void SC_SetState(SC_State scState)
|
||||
{
|
||||
SCState = scState;
|
||||
|
||||
return;
|
||||
}
|
||||
482
Class/CCID/Src/usbd_ccid_smartcard_template.c
Normal file
482
Class/CCID/Src/usbd_ccid_smartcard_template.c
Normal file
@@ -0,0 +1,482 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ccid_smartcard_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides all the Smartcard firmware functions.
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup usbd_ccid_Smartcard
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ccid_smartcard_template.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Directories & Files ID */
|
||||
/*The following Directories & Files ID can take any of following Values and can
|
||||
be used in the smartcard application */
|
||||
/*
|
||||
const uint8_t MasterRoot[2] = {0x3F, 0x00};
|
||||
const uint8_t GSMDir[2] = {0x7F, 0x20};
|
||||
const uint8_t ICCID[2] = {0x2F, 0xE2};
|
||||
const uint8_t IMSI[2] = {0x6F, 0x07};
|
||||
|
||||
__IO uint8_t ICCID_Content[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
uint32_t CHV1Status = 0U;
|
||||
|
||||
uint8_t CHV1[8] = {'0', '0', '0', '0', '0', '0', '0', '0'};
|
||||
__IO uint8_t IMSI_Content[9] = {0x01, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
*/
|
||||
|
||||
/* F Table: Clock Rate Conversion Table from ISO/IEC 7816-3 */
|
||||
/* static uint32_t F_Table[16] = {372, 372, 558, 744, 1116, 1488, 1860, 0, 0, 512, 768,
|
||||
1024, 1536, 2048, 0, 0
|
||||
}; */
|
||||
|
||||
|
||||
/* D Table: Baud Rate Adjustment Factor Table from ISO/IEC 7816-3 */
|
||||
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 ----------------------------*/
|
||||
SC_ATR SC_A2R;
|
||||
uint8_t SC_ATR_Table[40];
|
||||
uint8_t ProtocolNUM_OUT;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void SC_Init(void);
|
||||
static void SC_DeInit(void);
|
||||
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 void SC_SendData(SC_ADPU_Commands *SCADPU, SC_ADPU_Response *SC_ResponseStatus);
|
||||
/* static void SC_Reset(GPIO_PinState ResetState); */
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Handles all Smartcard states and serves to send and receive all
|
||||
* communication data between Smartcard and reader.
|
||||
* @param SCState: pointer to an SC_State enumeration that will contain the
|
||||
* Smartcard state.
|
||||
* @param SC_ADPU: pointer to an SC_ADPU_Commands structure that will be initialized.
|
||||
* @param SC_Response: pointer to a SC_ADPU_Response structure which will be initialized.
|
||||
* @retval None
|
||||
*/
|
||||
void SC_Handler(SC_State *SCState, SC_ADPU_Commands *SC_ADPU, SC_ADPU_Response *SC_Response)
|
||||
{
|
||||
uint32_t i, j;
|
||||
|
||||
switch (*SCState)
|
||||
{
|
||||
case SC_POWER_ON:
|
||||
if (SC_ADPU->Header.INS == SC_GET_A2R)
|
||||
{
|
||||
/* Smartcard initialization */
|
||||
SC_Init();
|
||||
|
||||
/* Reset Data from SC buffer */
|
||||
for (i = 0U; i < 40U; i++)
|
||||
{
|
||||
SC_ATR_Table[i] = 0;
|
||||
}
|
||||
|
||||
/* Reset SC_A2R Structure */
|
||||
SC_A2R.TS = 0U;
|
||||
SC_A2R.T0 = 0U;
|
||||
|
||||
for (i = 0U; i < MAX_PROTOCOLLEVEL; i++)
|
||||
{
|
||||
for (j = 0U; j < MAX_INTERFACEBYTE; j++)
|
||||
{
|
||||
SC_A2R.T[i].InterfaceByte[j].Status = 0U;
|
||||
SC_A2R.T[i].InterfaceByte[j].Value = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0U; i < HIST_LENGTH; i++)
|
||||
{
|
||||
SC_A2R.H[i] = 0U;
|
||||
}
|
||||
|
||||
SC_A2R.Tlength = 0U;
|
||||
SC_A2R.Hlength = 0U;
|
||||
|
||||
/* Next State */
|
||||
*SCState = SC_RESET_LOW;
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_RESET_LOW:
|
||||
if (SC_ADPU->Header.INS == SC_GET_A2R)
|
||||
{
|
||||
/* If card is detected then Power ON, Card Reset and wait for an answer) */
|
||||
if (SC_Detect() != 0U)
|
||||
{
|
||||
while (((*SCState) != SC_POWER_OFF) && ((*SCState) != SC_ACTIVE))
|
||||
{
|
||||
SC_AnswerReq(SCState, &SC_ATR_Table[0], 40U); /* Check for answer to reset */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(*SCState) = SC_POWER_OFF;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_ACTIVE:
|
||||
if (SC_ADPU->Header.INS == SC_GET_A2R)
|
||||
{
|
||||
uint8_t protocol = SC_decode_Answer2reset(&SC_ATR_Table[0]);
|
||||
if (protocol == T0_PROTOCOL)
|
||||
{
|
||||
(*SCState) = SC_ACTIVE_ON_T0;
|
||||
ProtocolNUM_OUT = T0_PROTOCOL;
|
||||
}
|
||||
else if (protocol == T1_PROTOCOL)
|
||||
{
|
||||
(*SCState) = SC_ACTIVE_ON_T1;
|
||||
ProtocolNUM_OUT = T1_PROTOCOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*SCState) = SC_POWER_OFF;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_ACTIVE_ON_T0:
|
||||
/* process commands other than ATR */
|
||||
SC_SendData(SC_ADPU, SC_Response);
|
||||
break;
|
||||
|
||||
case SC_ACTIVE_ON_T1:
|
||||
/* process commands other than ATR */
|
||||
SC_SendData(SC_ADPU, SC_Response);
|
||||
break;
|
||||
|
||||
case SC_POWER_OFF:
|
||||
SC_DeInit(); /* Disable Smartcard interface */
|
||||
break;
|
||||
|
||||
default:
|
||||
(*SCState) = SC_POWER_OFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables or disables the power to the Smartcard.
|
||||
* @param NewState: new state of the Smartcard power supply.
|
||||
* This parameter can be: SC_ENABLED or SC_DISABLED.
|
||||
* @retval None
|
||||
*/
|
||||
void SC_PowerCmd(SCPowerState NewState)
|
||||
{
|
||||
UNUSED(NewState);
|
||||
/* enable or disable smartcard pin */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets or clears the Smartcard reset pin.
|
||||
* @param ResetState: this parameter specifies the state of the Smartcard
|
||||
* reset pin. BitVal must be one of the BitAction enum values:
|
||||
* @arg Bit_RESET: to clear the port pin.
|
||||
* @arg Bit_SET: to set the port pin.
|
||||
* @retval None
|
||||
*/
|
||||
/* static void SC_Reset(GPIO_PinState ResetState)
|
||||
{
|
||||
UNUSED(ResetState);
|
||||
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Resends the byte that failed to be received (by the Smartcard) correctly.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void SC_ParityErrorHandler(void)
|
||||
{
|
||||
/* Add your code here */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the IO speed (BaudRate) communication.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void SC_PTSConfig(void)
|
||||
{
|
||||
/* Add your code here */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Manages the Smartcard transport layer: send APDU commands and receives
|
||||
* the APDU response.
|
||||
* @param SC_ADPU: pointer to a SC_ADPU_Commands structure which will be initialized.
|
||||
* @param SC_Response: pointer to a SC_ADPU_Response structure which will be initialized.
|
||||
* @retval None
|
||||
*/
|
||||
static void SC_SendData(SC_ADPU_Commands *SCADPU, SC_ADPU_Response *SC_ResponseStatus)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t SC_Command[5];
|
||||
uint8_t SC_DATA[LC_MAX];
|
||||
|
||||
UNUSED(SCADPU);
|
||||
|
||||
/* Reset response buffer */
|
||||
for (i = 0U; i < LC_MAX; i++)
|
||||
{
|
||||
SC_ResponseStatus->Data[i] = 0U;
|
||||
SC_DATA[i] = 0U;
|
||||
}
|
||||
|
||||
/* User to add code here */
|
||||
|
||||
/* send command to ICC and get response status */
|
||||
USBD_CCID_If_fops.Send_Process((uint8_t *)&SC_Command, (uint8_t *)&SC_DATA);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_AnswerReq
|
||||
Requests the reset answer from card.
|
||||
* @param SC_state: pointer to an SC_State enumeration that will contain the Smartcard state.
|
||||
* @param atr_buffer: pointer to a buffer which will contain the card ATR.
|
||||
* @param length: maximum ATR length
|
||||
* @retval None
|
||||
*/
|
||||
static void SC_AnswerReq(SC_State *SC_state, uint8_t *atr_buffer, uint8_t length)
|
||||
{
|
||||
UNUSED(length);
|
||||
UNUSED(atr_buffer);
|
||||
|
||||
/* to be implemented by USER */
|
||||
switch (*SC_state)
|
||||
{
|
||||
case SC_RESET_LOW:
|
||||
/* Check response with reset low */
|
||||
(*SC_state) = SC_ACTIVE;
|
||||
break;
|
||||
|
||||
case SC_ACTIVE:
|
||||
break;
|
||||
case SC_RESET_HIGH:
|
||||
/* Check response with reset high */
|
||||
|
||||
break;
|
||||
|
||||
case SC_POWER_OFF:
|
||||
/* Close Connection if no answer received */
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
(*SC_state) = SC_RESET_LOW;
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SC_decode_Answer2reset
|
||||
Decodes the Answer to reset received from card.
|
||||
* @param card: pointer to the buffer containing the card ATR.
|
||||
* @retval None
|
||||
*/
|
||||
static uint8_t SC_decode_Answer2reset(uint8_t *card)
|
||||
{
|
||||
uint32_t i, flag = 0U, protocol;
|
||||
uint8_t index = 0U, level = 0U;
|
||||
|
||||
/******************************TS/T0 Decode************************************/
|
||||
index++;
|
||||
SC_A2R.TS = card[index]; /* Initial character */
|
||||
|
||||
index++;
|
||||
SC_A2R.T0 = card[index]; /* Format character */
|
||||
|
||||
/*************************Historical Table Length Decode***********************/
|
||||
SC_A2R.Hlength = SC_A2R.T0 & 0x0FU;
|
||||
|
||||
/******************************Protocol Level(1) Decode************************/
|
||||
/* Check TD(1) if present */
|
||||
if ((SC_A2R.T0 & 0x80U) == 0x80U)
|
||||
{
|
||||
flag = 1U;
|
||||
}
|
||||
|
||||
/* Each bits in the T0 high nibble(b8 to b5) equal to 1 indicates the presence
|
||||
of a further interface byte */
|
||||
for (i = 0U; i < 4U; i++)
|
||||
{
|
||||
if ((((SC_A2R.T0 & 0xF0U) >> (4U + i)) & 0x1U) != 0U)
|
||||
{
|
||||
SC_A2R.T[level].InterfaceByte[i].Status = 1U;
|
||||
index++;
|
||||
SC_A2R.T[level].InterfaceByte[i].Value = card[index];
|
||||
SC_A2R.Tlength++;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************T Decode*****************************************/
|
||||
if (SC_A2R.T[level].InterfaceByte[3].Status == 1U)
|
||||
{
|
||||
/* Only the protocol(parameter T) present in TD(1) is detected
|
||||
if two or more values of parameter T are present in TD(1), TD(2)..., so the
|
||||
firmware should be updated to support them */
|
||||
protocol = (uint8_t)(SC_A2R.T[level].InterfaceByte[SC_INTERFACEBYTE_TD].Value & 0x0FU);
|
||||
}
|
||||
else
|
||||
{
|
||||
protocol = 0U;
|
||||
}
|
||||
|
||||
/* Protocol Level Increment */
|
||||
/******************************Protocol Level(n>1) Decode**********************/
|
||||
while (flag != 0U)
|
||||
{
|
||||
if ((SC_A2R.T[level].InterfaceByte[SC_INTERFACEBYTE_TD].Value & 0x80U) == 0x80U)
|
||||
{
|
||||
flag = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = 0U;
|
||||
}
|
||||
/* Each bits in the high nibble(b8 to b5) for the TD(i) equal to 1 indicates
|
||||
the presence of a further interface byte */
|
||||
for (i = 0U; i < 4U; i++)
|
||||
{
|
||||
if ((((SC_A2R.T[level].InterfaceByte[SC_INTERFACEBYTE_TD].Value & 0xF0U) >> (4U + i)) & 0x1U) != 0U)
|
||||
{
|
||||
SC_A2R.T[level + 1U].InterfaceByte[i].Status = 1U;
|
||||
index++;
|
||||
SC_A2R.T[level + 1U].InterfaceByte[i].Value = card[index];
|
||||
SC_A2R.Tlength++;
|
||||
}
|
||||
}
|
||||
level++;
|
||||
}
|
||||
|
||||
for (i = 0U; i < SC_A2R.Hlength; i++)
|
||||
{
|
||||
SC_A2R.H[i] = card[i + 2U + SC_A2R.Tlength];
|
||||
}
|
||||
/*************************************TCK Decode*******************************/
|
||||
SC_A2R.TCK = card[SC_A2R.Hlength + 2U + SC_A2R.Tlength];
|
||||
|
||||
return (uint8_t)protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes all peripheral used for Smartcard interface.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SC_Init(void)
|
||||
{
|
||||
/*
|
||||
Add your initialization code here
|
||||
*/
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Deinitializes all resources used by the Smartcard interface.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SC_DeInit(void)
|
||||
{
|
||||
/*
|
||||
Add your deinitialization code here
|
||||
*/
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures the card power voltage.
|
||||
* @param SC_Voltage: specifies the card power voltage.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg SC_VOLTAGE_5V: 5V cards.
|
||||
* @arg SC_VOLTAGE_3V: 3V cards.
|
||||
* @retval None
|
||||
*/
|
||||
void SC_VoltageConfig(uint32_t SC_Voltage)
|
||||
{
|
||||
UNUSED(SC_Voltage);
|
||||
/* Add your code here */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures GPIO hardware resources used for Samrtcard.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SC_IOConfig(void)
|
||||
{
|
||||
/* Add your code here */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Detects whether the Smartcard is present or not.
|
||||
* @param None.
|
||||
* @retval 1 - Smartcard inserted
|
||||
* 0 - Smartcard not inserted
|
||||
*/
|
||||
uint8_t SC_Detect(void)
|
||||
{
|
||||
uint8_t PIN_State = 0U;
|
||||
|
||||
/* Add your code here */
|
||||
|
||||
return PIN_State;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the Right Value from the D_Table Index
|
||||
* @param idx : Index to Read from the Table
|
||||
* @retval Value read from the Table
|
||||
*/
|
||||
uint32_t SC_GetDTableValue(uint32_t idx)
|
||||
{
|
||||
return D_Table[idx];
|
||||
}
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -46,11 +45,11 @@ extern "C" {
|
||||
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
||||
|
||||
#ifndef CDC_HS_BINTERVAL
|
||||
#define CDC_HS_BINTERVAL 0x10U
|
||||
#define CDC_HS_BINTERVAL 0x10U
|
||||
#endif /* CDC_HS_BINTERVAL */
|
||||
|
||||
#ifndef CDC_FS_BINTERVAL
|
||||
#define CDC_FS_BINTERVAL 0x10U
|
||||
#define CDC_FS_BINTERVAL 0x10U
|
||||
#endif /* CDC_FS_BINTERVAL */
|
||||
|
||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||
@@ -65,6 +64,7 @@ extern "C" {
|
||||
#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||
#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||
|
||||
#define CDC_REQ_MAX_DATA_SIZE 0x7U
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* CDC definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
@@ -104,13 +104,13 @@ typedef struct _USBD_CDC_Itf
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||
|
||||
int8_t (* TransmitCplt)(uint8_t *Buf, uint32_t *Len, uint8_t epnum);
|
||||
} USBD_CDC_ItfTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */
|
||||
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32-bit alignment */
|
||||
uint8_t CmdOpCode;
|
||||
uint8_t CmdLength;
|
||||
uint8_t *RxBuffer;
|
||||
@@ -120,8 +120,7 @@ typedef struct
|
||||
|
||||
__IO uint32_t TxState;
|
||||
__IO uint32_t RxState;
|
||||
}
|
||||
USBD_CDC_HandleTypeDef;
|
||||
} USBD_CDC_HandleTypeDef;
|
||||
|
||||
|
||||
|
||||
@@ -137,8 +136,8 @@ USBD_CDC_HandleTypeDef;
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_CDC;
|
||||
#define USBD_CDC_CLASS &USBD_CDC
|
||||
extern USBD_ClassTypeDef USBD_CDC;
|
||||
#define USBD_CDC_CLASS &USBD_CDC
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -146,19 +145,15 @@ extern USBD_ClassTypeDef USBD_CDC;
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops);
|
||||
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops);
|
||||
|
||||
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length);
|
||||
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||
uint32_t length);
|
||||
|
||||
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff);
|
||||
|
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -176,4 +171,3 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -42,4 +41,3 @@ extern USBD_CDC_ItfTypeDef USBD_CDC_Template_fops;
|
||||
|
||||
#endif /* __USBD_CDC_IF_TEMPLATE_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -68,13 +67,15 @@ static int8_t TEMPLATE_Init(void);
|
||||
static int8_t TEMPLATE_DeInit(void);
|
||||
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||
static int8_t TEMPLATE_Receive(uint8_t *pbuf, uint32_t *Len);
|
||||
static int8_t TEMPLATE_TransmitCplt(uint8_t *pbuf, uint32_t *Len, uint8_t epnum);
|
||||
|
||||
USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
|
||||
{
|
||||
TEMPLATE_Init,
|
||||
TEMPLATE_DeInit,
|
||||
TEMPLATE_Control,
|
||||
TEMPLATE_Receive
|
||||
TEMPLATE_Receive,
|
||||
TEMPLATE_TransmitCplt
|
||||
};
|
||||
|
||||
USBD_CDC_LineCodingTypeDef linecoding =
|
||||
@@ -192,7 +193,7 @@ static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||
*
|
||||
* @note
|
||||
* This function will issue a NAK packet on any OUT packet received on
|
||||
* USB endpoint untill exiting this function. If you exit this function
|
||||
* USB endpoint until exiting this function. If you exit this function
|
||||
* before transfer is complete on CDC interface (ie. using DMA controller)
|
||||
* it will result in receiving more data while previous ones are still
|
||||
* not sent.
|
||||
@@ -203,6 +204,29 @@ static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||
*/
|
||||
static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len)
|
||||
{
|
||||
UNUSED(Buf);
|
||||
UNUSED(Len);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_TransmitCplt
|
||||
* Data transmitted callback
|
||||
*
|
||||
* @note
|
||||
* This function is IN transfer complete callback used to inform user that
|
||||
* the submitted Data is successfully sent over USB.
|
||||
*
|
||||
* @param Buf: Buffer of data to be received
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_TransmitCplt(uint8_t *Buf, uint32_t *Len, uint8_t epnum)
|
||||
{
|
||||
UNUSED(Buf);
|
||||
UNUSED(Len);
|
||||
UNUSED(epnum);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -219,5 +243,3 @@ static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len)
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
255
Class/CDC_ECM/Inc/usbd_cdc_ecm.h
Normal file
255
Class/CDC_ECM/Inc/usbd_cdc_ecm.h
Normal file
@@ -0,0 +1,255 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc_ecm.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_cdc_ecm.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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 __USB_CDC_ECM_H
|
||||
#define __USB_CDC_ECM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup usbd_cdc_ecm
|
||||
* @brief This file is the Header file for usbd_cdc_ecm.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup usbd_cdc_ecm_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/* Comment this define in order to disable the CDC ECM Notification pipe */
|
||||
|
||||
|
||||
#define CDC_ECM_IN_EP 0x81U /* EP1 for data IN */
|
||||
#define CDC_ECM_OUT_EP 0x01U /* EP1 for data OUT */
|
||||
#define CDC_ECM_CMD_EP 0x82U /* EP2 for CDC ECM commands */
|
||||
|
||||
#ifndef CDC_ECM_CMD_ITF_NBR
|
||||
#define CDC_ECM_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
||||
#endif /* CDC_ECM_CMD_ITF_NBR */
|
||||
|
||||
#ifndef CDC_ECM_COM_ITF_NBR
|
||||
#define CDC_ECM_COM_ITF_NBR 0x01U /* Communication Interface Number 0 */
|
||||
#endif /* CDC_ECM_CMD_ITF_NBR */
|
||||
|
||||
#ifndef CDC_ECM_HS_BINTERVAL
|
||||
#define CDC_ECM_HS_BINTERVAL 0x10U
|
||||
#endif /* CDC_ECM_HS_BINTERVAL */
|
||||
|
||||
#ifndef CDC_ECM_FS_BINTERVAL
|
||||
#define CDC_ECM_FS_BINTERVAL 0x10U
|
||||
#endif /* CDC_ECM_FS_BINTERVAL */
|
||||
|
||||
#ifndef USBD_SUPPORT_USER_STRING_DESC
|
||||
#define USBD_SUPPORT_USER_STRING_DESC 1U
|
||||
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
/* 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_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_DATA_BUFFER_SIZE 2000U
|
||||
|
||||
#define CDC_ECM_DATA_HS_IN_PACKET_SIZE CDC_ECM_DATA_HS_MAX_PACKET_SIZE
|
||||
#define CDC_ECM_DATA_HS_OUT_PACKET_SIZE CDC_ECM_DATA_HS_MAX_PACKET_SIZE
|
||||
|
||||
#define CDC_ECM_DATA_FS_IN_PACKET_SIZE CDC_ECM_DATA_FS_MAX_PACKET_SIZE
|
||||
#define CDC_ECM_DATA_FS_OUT_PACKET_SIZE CDC_ECM_DATA_FS_MAX_PACKET_SIZE
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* CDC_ECM definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
#define CDC_ECM_SEND_ENCAPSULATED_COMMAND 0x00U
|
||||
#define CDC_ECM_GET_ENCAPSULATED_RESPONSE 0x01U
|
||||
#define CDC_ECM_SET_ETH_MULTICAST_FILTERS 0x40U
|
||||
#define CDC_ECM_SET_ETH_PWRM_PATTERN_FILTER 0x41U
|
||||
#define CDC_ECM_GET_ETH_PWRM_PATTERN_FILTER 0x42U
|
||||
#define CDC_ECM_SET_ETH_PACKET_FILTER 0x43U
|
||||
#define CDC_ECM_GET_ETH_STATISTIC 0x44U
|
||||
|
||||
#define CDC_ECM_NET_DISCONNECTED 0x00U
|
||||
#define CDC_ECM_NET_CONNECTED 0x01U
|
||||
|
||||
|
||||
/* Ethernet statistics definitions */
|
||||
#define CDC_ECM_XMIT_OK_VAL CDC_ECM_ETH_STATS_VAL_ENABLED
|
||||
#define CDC_ECM_XMIT_OK 0x01U
|
||||
#define CDC_ECM_RVC_OK 0x02U
|
||||
#define CDC_ECM_XMIT_ERROR 0x04U
|
||||
#define CDC_ECM_RCV_ERROR 0x08U
|
||||
#define CDC_ECM_RCV_NO_BUFFER 0x10U
|
||||
#define CDC_ECM_DIRECTED_BYTES_XMIT 0x20U
|
||||
#define CDC_ECM_DIRECTED_FRAMES_XMIT 0x40U
|
||||
#define CDC_ECM_MULTICAST_BYTES_XMIT 0x80U
|
||||
|
||||
#define CDC_ECM_MULTICAST_FRAMES_XMIT 0x01U
|
||||
#define CDC_ECM_BROADCAST_BYTES_XMIT 0x02U
|
||||
#define CDC_ECM_BROADCAST_FRAMES_XMIT 0x04U
|
||||
#define CDC_ECM_DIRECTED_BYTES_RCV 0x08U
|
||||
#define CDC_ECM_DIRECTED_FRAMES_RCV 0x10U
|
||||
#define CDC_ECM_MULTICAST_BYTES_RCV 0x20U
|
||||
#define CDC_ECM_MULTICAST_FRAMES_RCV 0x40U
|
||||
#define CDC_ECM_BROADCAST_BYTES_RCV 0x80U
|
||||
|
||||
#define CDC_ECM_BROADCAST_FRAMES_RCV 0x01U
|
||||
#define CDC_ECM_RCV_CRC_ERROR 0x02U
|
||||
#define CDC_ECM_TRANSMIT_QUEUE_LENGTH 0x04U
|
||||
#define CDC_ECM_RCV_ERROR_ALIGNMENT 0x08U
|
||||
#define CDC_ECM_XMIT_ONE_COLLISION 0x10U
|
||||
#define CDC_ECM_XMIT_MORE_COLLISIONS 0x20U
|
||||
#define CDC_ECM_XMIT_DEFERRED 0x40U
|
||||
#define CDC_ECM_XMIT_MAX_COLLISIONS 0x80U
|
||||
|
||||
#define CDC_ECM_RCV_OVERRUN 0x40U
|
||||
#define CDC_ECM_XMIT_UNDERRUN 0x40U
|
||||
#define CDC_ECM_XMIT_HEARTBEAT_FAILURE 0x40U
|
||||
#define CDC_ECM_XMIT_TIMES_CRS_LOST 0x40U
|
||||
#define CDC_ECM_XMIT_LATE_COLLISIONS 0x40U
|
||||
|
||||
#define CDC_ECM_ETH_STATS_RESERVED 0xE0U
|
||||
#define CDC_ECM_BMREQUEST_TYPE_ECM 0xA1U
|
||||
|
||||
/* MAC String index */
|
||||
#define CDC_ECM_MAC_STRING_INDEX 6U
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int8_t (* Init)(void);
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||
int8_t (* TransmitCplt)(uint8_t *Buf, uint32_t *Len, uint8_t epnum);
|
||||
int8_t (* Process)(USBD_HandleTypeDef *pdev);
|
||||
const uint8_t *pStrDesc;
|
||||
} USBD_CDC_ECM_ItfTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bmRequest;
|
||||
uint8_t bRequest;
|
||||
uint16_t wValue;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
uint8_t data[8];
|
||||
} USBD_CDC_ECM_NotifTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t data[CDC_ECM_DATA_BUFFER_SIZE / 4U]; /* Force 32-bit alignment */
|
||||
uint8_t CmdOpCode;
|
||||
uint8_t CmdLength;
|
||||
uint8_t Reserved1; /* Reserved Byte to force 4 bytes alignment of following fields */
|
||||
uint8_t Reserved2; /* Reserved Byte to force 4 bytes alignment of following fields */
|
||||
uint8_t *RxBuffer;
|
||||
uint8_t *TxBuffer;
|
||||
uint32_t RxLength;
|
||||
uint32_t TxLength;
|
||||
|
||||
__IO uint32_t TxState;
|
||||
__IO uint32_t RxState;
|
||||
|
||||
__IO uint32_t MaxPcktLen;
|
||||
__IO uint32_t LinkStatus;
|
||||
__IO uint32_t NotificationStatus;
|
||||
USBD_CDC_ECM_NotifTypeDef Req;
|
||||
} 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_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_CDC_ECM;
|
||||
#define USBD_CDC_ECM_CLASS &USBD_CDC_ECM
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_CDC_ECM_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
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_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_CDC_ECM_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_CDC_ECM_SendNotification(USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ECM_NotifCodeTypeDef Notif,
|
||||
uint16_t bVal, uint8_t *pData);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_CDC_ECM_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
80
Class/CDC_ECM/Inc/usbd_cdc_ecm_if_template.h
Normal file
80
Class/CDC_ECM/Inc/usbd_cdc_ecm_if_template.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file Inc/usbd_cdc_ecm_if_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header for usbd_cdc_ecm_if_template.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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_CDC_ECM_IF_H
|
||||
#define __USBD_CDC_ECM_IF_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_cdc_ecm.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Ensure this MAC address value is same as MAC_ADDRx declared in STM32xxx_conf.h */
|
||||
#define CDC_ECM_MAC_STR_DESC (uint8_t *)"000202030000"
|
||||
#define CDC_ECM_MAC_ADDR0 0x00U /* 01 */
|
||||
#define CDC_ECM_MAC_ADDR1 0x02U /* 02 */
|
||||
#define CDC_ECM_MAC_ADDR2 0x02U /* 03 */
|
||||
#define CDC_ECM_MAC_ADDR3 0x03U /* 00 */
|
||||
#define CDC_ECM_MAC_ADDR4 0x00U /* 00 */
|
||||
#define CDC_ECM_MAC_ADDR5 0x00U /* 00 */
|
||||
|
||||
/* Max Number of Trials waiting for Tx ready */
|
||||
#define CDC_ECM_MAX_TX_WAIT_TRIALS 1000000U
|
||||
|
||||
#define CDC_ECM_ETH_STATS_BYTE0 0U
|
||||
/*(uint8_t)(CDC_ECM_XMIT_OK_VAL | CDC_ECM_RVC_OK_VAL | CDC_ECM_XMIT_ERROR_VAL | \
|
||||
CDC_ECM_RCV_ERROR_VAL | CDC_ECM_RCV_NO_BUFFER_VAL | CDC_ECM_DIRECTED_BYTES_XMIT_VAL | \
|
||||
CDC_ECM_DIRECTED_FRAMES_XMIT_VAL | CDC_ECM_MULTICAST_BYTES_XMIT_VAL) */
|
||||
|
||||
#define CDC_ECM_ETH_STATS_BYTE1 0U
|
||||
/*(uint8_t)(CDC_ECM_MULTICAST_FRAMES_XMIT_VAL | CDC_ECM_BROADCAST_BYTES_XMIT_VAL | \
|
||||
CDC_ECM_BROADCAST_FRAMES_XMIT_VAL | CDC_ECM_DIRECTED_BYTES_RCV_VAL | \
|
||||
CDC_ECM_DIRECTED_FRAMES_RCV_VAL | CDC_ECM_MULTICAST_BYTES_RCV_VAL | \
|
||||
CDC_ECM_MULTICAST_FRAMES_RCV_VAL | CDC_ECM_BROADCAST_BYTES_RCV_VAL) */
|
||||
|
||||
#define CDC_ECM_ETH_STATS_BYTE2 0U
|
||||
/*(uint8_t)(CDC_ECM_BROADCAST_FRAMES_RCV_VAL | CDC_ECM_RCV_CRC_ERROR_VAL | \
|
||||
CDC_ECM_TRANSMIT_QUEUE_LENGTH_VAL | CDC_ECM_RCV_ERROR_ALIGNMENT_VAL | \
|
||||
CDC_ECM_XMIT_ONE_COLLISION_VAL | CDC_ECM_XMIT_MORE_COLLISIONS_VAL | \
|
||||
CDC_ECM_XMIT_DEFERRED_VAL | CDC_ECM_XMIT_MAX_COLLISIONS_VAL) */
|
||||
|
||||
#define CDC_ECM_ETH_STATS_BYTE3 0U
|
||||
/*(uint8_t)(CDC_ECM_RCV_OVERRUN_VAL | CDC_ECM_XMIT_UNDERRUN_VAL | CDC_ECM_XMIT_HEARTBEAT_FAILURE_VAL | \
|
||||
CDC_ECM_XMIT_TIMES_CRS_LOST_VAL | CDC_ECM_XMIT_LATE_COLLISIONS_VAL | CDC_ECM_ETH_STATS_RESERVED) */
|
||||
|
||||
/* Ethernet Maximum Segment size, typically 1514 bytes */
|
||||
#define CDC_ECM_ETH_MAX_SEGSZE 1514U
|
||||
|
||||
/* Number of Ethernet multicast filters */
|
||||
#define CDC_ECM_ETH_NBR_MACFILTERS 0U
|
||||
|
||||
/* Number of wakeup power filters */
|
||||
#define CDC_ECM_ETH_NBR_PWRFILTERS 0U
|
||||
|
||||
|
||||
#define CDC_ECM_CONNECT_SPEED_UPSTREAM 0x004C4B40U /* 5Mbps */
|
||||
#define CDC_ECM_CONNECT_SPEED_DOWNSTREAM 0x004C4B40U /* 5Mbps */
|
||||
|
||||
extern USBD_CDC_ECM_ItfTypeDef USBD_CDC_ECM_fops;
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
#endif /* __USBD_CDC_ECM_IF_H */
|
||||
|
||||
1130
Class/CDC_ECM/Src/usbd_cdc_ecm.c
Normal file
1130
Class/CDC_ECM/Src/usbd_cdc_ecm.c
Normal file
File diff suppressed because it is too large
Load Diff
246
Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c
Normal file
246
Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c
Normal file
@@ -0,0 +1,246 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file Src/usbd_cdc_ecm_if_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief Source file for USBD CDC_ECM interface
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "main.h"
|
||||
/*
|
||||
|
||||
Include here LwIP files if used
|
||||
|
||||
*/
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Received Data over USB are stored in this buffer */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__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 */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END;
|
||||
|
||||
static uint8_t CDC_ECMInitialized = 0U;
|
||||
|
||||
/* USB handler declaration */
|
||||
extern USBD_HandleTypeDef USBD_Device;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static int8_t CDC_ECM_Itf_Init(void);
|
||||
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_Receive(uint8_t *pbuf, uint32_t *Len);
|
||||
static int8_t CDC_ECM_Itf_TransmitCplt(uint8_t *pbuf, uint32_t *Len, uint8_t epnum);
|
||||
static int8_t CDC_ECM_Itf_Process(USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_CDC_ECM_ItfTypeDef USBD_CDC_ECM_fops =
|
||||
{
|
||||
CDC_ECM_Itf_Init,
|
||||
CDC_ECM_Itf_DeInit,
|
||||
CDC_ECM_Itf_Control,
|
||||
CDC_ECM_Itf_Receive,
|
||||
CDC_ECM_Itf_TransmitCplt,
|
||||
CDC_ECM_Itf_Process,
|
||||
(uint8_t *)CDC_ECM_MAC_STR_DESC,
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief CDC_ECM_Itf_Init
|
||||
* Initializes the CDC_ECM media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_ECM_Itf_Init(void)
|
||||
{
|
||||
if (CDC_ECMInitialized == 0U)
|
||||
{
|
||||
/*
|
||||
Initialize the TCP/IP stack here
|
||||
*/
|
||||
|
||||
CDC_ECMInitialized = 1U;
|
||||
}
|
||||
|
||||
/* Set Application Buffers */
|
||||
(void)USBD_CDC_ECM_SetTxBuffer(&USBD_Device, UserTxBuffer, 0U);
|
||||
(void)USBD_CDC_ECM_SetRxBuffer(&USBD_Device, UserRxBuffer);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_ECM_Itf_DeInit
|
||||
* DeInitializes the CDC_ECM media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_ECM_Itf_DeInit(void)
|
||||
{
|
||||
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(USBD_Device.pClassData);
|
||||
|
||||
/* Notify application layer that link is down */
|
||||
hcdc_cdc_ecm->LinkStatus = 0U;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_ECM_Itf_Control
|
||||
* Manage the CDC_ECM class requests
|
||||
* @param Cmd: Command code
|
||||
* @param Buf: Buffer containing command data (request parameters)
|
||||
* @param Len: Number of data to be sent (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_ECM_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||
{
|
||||
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(USBD_Device.pClassData);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case CDC_ECM_SEND_ENCAPSULATED_COMMAND:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_ECM_GET_ENCAPSULATED_RESPONSE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_ECM_SET_ETH_MULTICAST_FILTERS:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_ECM_SET_ETH_PWRM_PATTERN_FILTER:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_ECM_GET_ETH_PWRM_PATTERN_FILTER:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_ECM_SET_ETH_PACKET_FILTER:
|
||||
/* Check if this is the first time we enter */
|
||||
if (hcdc_cdc_ecm->LinkStatus == 0U)
|
||||
{
|
||||
/*
|
||||
Setup the Link up at TCP/IP level
|
||||
*/
|
||||
hcdc_cdc_ecm->LinkStatus = 1U;
|
||||
|
||||
/* Modification for MacOS which doesn't send SetInterface before receiving INs */
|
||||
if (hcdc_cdc_ecm->NotificationStatus == 0U)
|
||||
{
|
||||
/* Send notification: NETWORK_CONNECTION Event */
|
||||
(void)USBD_CDC_ECM_SendNotification(&USBD_Device, NETWORK_CONNECTION,
|
||||
CDC_ECM_NET_CONNECTED, NULL);
|
||||
|
||||
/* Prepare for sending Connection Speed Change notification */
|
||||
hcdc_cdc_ecm->NotificationStatus = 1U;
|
||||
}
|
||||
}
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_ECM_GET_ETH_STATISTIC:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
UNUSED(length);
|
||||
UNUSED(pbuf);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_ECM_Itf_Receive
|
||||
* Data received over USB OUT endpoint are sent over CDC_ECM interface
|
||||
* through this function.
|
||||
* @param Buf: Buffer of data to be transmitted
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_ECM_Itf_Receive(uint8_t *Buf, uint32_t *Len)
|
||||
{
|
||||
/* Get the CDC_ECM handler pointer */
|
||||
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(USBD_Device.pClassData);
|
||||
|
||||
/* Call Eth buffer processing */
|
||||
hcdc_cdc_ecm->RxState = 1U;
|
||||
|
||||
UNUSED(Len);
|
||||
UNUSED(Buf);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_ECM_Itf_TransmitCplt
|
||||
* Data transmitted callback
|
||||
*
|
||||
* @note
|
||||
* This function is IN transfer complete callback used to inform user that
|
||||
* the submitted Data is successfully sent over USB.
|
||||
*
|
||||
* @param Buf: Buffer of data to be received
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_ECM_Itf_TransmitCplt(uint8_t *Buf, uint32_t *Len, uint8_t epnum)
|
||||
{
|
||||
UNUSED(Buf);
|
||||
UNUSED(Len);
|
||||
UNUSED(epnum);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_ECM_Itf_Process
|
||||
* Data received over USB OUT endpoint are sent over CDC_ECM interface
|
||||
* through this function.
|
||||
* @param pdef: pointer to the USB Device Handle
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_ECM_Itf_Process(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Get the CDC_ECM handler pointer */
|
||||
USBD_CDC_ECM_HandleTypeDef *hcdc_cdc_ecm = (USBD_CDC_ECM_HandleTypeDef *)(pdev->pClassData);
|
||||
|
||||
if ((hcdc_cdc_ecm != NULL) && (hcdc_cdc_ecm->LinkStatus != 0U))
|
||||
{
|
||||
/*
|
||||
Read a received packet from the Ethernet buffers and send it
|
||||
to the lwIP for handling
|
||||
Call here the TCP/IP background tasks.
|
||||
*/
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
527
Class/CDC_RNDIS/Inc/usbd_cdc_rndis.h
Normal file
527
Class/CDC_RNDIS/Inc/usbd_cdc_rndis.h
Normal file
@@ -0,0 +1,527 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc_rndis.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_cdc_rndis.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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 __USB_CDC_RNDIS_H
|
||||
#define __USB_CDC_RNDIS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup usbd_cdc_rndis
|
||||
* @brief This file is the Header file for usbd_cdc_rndis.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup usbd_cdc_rndis_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define CDC_RNDIS_IN_EP 0x81U /* EP1 for data IN */
|
||||
#define CDC_RNDIS_OUT_EP 0x01U /* EP1 for data OUT */
|
||||
#define CDC_RNDIS_CMD_EP 0x82U /* EP2 for CDC_RNDIS commands */
|
||||
|
||||
#ifndef CDC_RNDIS_CMD_ITF_NBR
|
||||
#define CDC_RNDIS_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
||||
#endif /* CDC_RNDIS_CMD_ITF_NBR */
|
||||
|
||||
#ifndef CDC_RNDIS_COM_ITF_NBR
|
||||
#define CDC_RNDIS_COM_ITF_NBR 0x01U /* Communication Interface Number 0 */
|
||||
#endif /* CDC_RNDIS_CMD_ITF_NBR */
|
||||
|
||||
#ifndef CDC_RNDIS_HS_BINTERVAL
|
||||
#define CDC_RNDIS_HS_BINTERVAL 0x10U
|
||||
#endif /* CDC_RNDIS_HS_BINTERVAL */
|
||||
|
||||
#ifndef CDC_RNDIS_FS_BINTERVAL
|
||||
#define CDC_RNDIS_FS_BINTERVAL 0x10U
|
||||
#endif /* CDC_RNDIS_FS_BINTERVAL */
|
||||
|
||||
|
||||
/* CDC_RNDIS Endpoints parameters: you can fine tune these values
|
||||
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_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_DATA_HS_IN_PACKET_SIZE CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE
|
||||
#define CDC_RNDIS_DATA_HS_OUT_PACKET_SIZE CDC_RNDIS_DATA_HS_MAX_PACKET_SIZE
|
||||
|
||||
#define CDC_RNDIS_DATA_FS_IN_PACKET_SIZE CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE
|
||||
#define CDC_RNDIS_DATA_FS_OUT_PACKET_SIZE CDC_RNDIS_DATA_FS_MAX_PACKET_SIZE
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* CDC_RNDIS definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
/** Implemented CDC_RNDIS Version Major */
|
||||
#define CDC_RNDIS_VERSION_MAJOR 0x01U
|
||||
|
||||
/* Implemented CDC_RNDIS Version Minor */
|
||||
#define CDC_RNDIS_VERSION_MINOR 0x00U
|
||||
|
||||
/* Maximum size in bytes of a CDC_RNDIS control message
|
||||
which can be sent or received */
|
||||
#define CDC_RNDIS_MESSAGE_BUFFER_SIZE 128U
|
||||
|
||||
/* Maximum size in bytes of an Ethernet frame
|
||||
according to the Ethernet standard */
|
||||
#define CDC_RNDIS_ETH_FRAME_SIZE_MAX 1536U
|
||||
|
||||
/* Maximum size allocated for buffer
|
||||
inside Query messages structures */
|
||||
#define CDC_RNDIS_MAX_INFO_BUFF_SZ 200U
|
||||
#define CDC_RNDIS_MAX_DATA_SZE 2000U
|
||||
|
||||
/* Notification request value for a CDC_RNDIS
|
||||
Response Available notification */
|
||||
#define CDC_RNDIS_NOTIFICATION_RESP_AVAILABLE 0x00000001UL
|
||||
|
||||
|
||||
#define CDC_RNDIS_PACKET_MSG_ID 0x00000001UL
|
||||
#define CDC_RNDIS_INITIALIZE_MSG_ID 0x00000002UL
|
||||
#define CDC_RNDIS_HALT_MSG_ID 0x00000003UL
|
||||
#define CDC_RNDIS_QUERY_MSG_ID 0x00000004UL
|
||||
#define CDC_RNDIS_SET_MSG_ID 0x00000005UL
|
||||
#define CDC_RNDIS_RESET_MSG_ID 0x00000006UL
|
||||
#define CDC_RNDIS_INDICATE_STATUS_MSG_ID 0x00000007UL
|
||||
#define CDC_RNDIS_KEEPALIVE_MSG_ID 0x00000008UL
|
||||
|
||||
#define CDC_RNDIS_INITIALIZE_CMPLT_ID 0x80000002UL
|
||||
#define CDC_RNDIS_QUERY_CMPLT_ID 0x80000004UL
|
||||
#define CDC_RNDIS_SET_CMPLT_ID 0x80000005UL
|
||||
#define CDC_RNDIS_RESET_CMPLT_ID 0x80000006UL
|
||||
#define CDC_RNDIS_KEEPALIVE_CMPLT_ID 0x80000008UL
|
||||
|
||||
#define CDC_RNDIS_STATUS_SUCCESS 0x00000000UL
|
||||
#define CDC_RNDIS_STATUS_FAILURE 0xC0000001UL
|
||||
#define CDC_RNDIS_STATUS_INVALID_DATA 0xC0010015UL
|
||||
#define CDC_RNDIS_STATUS_NOT_SUPPORTED 0xC00000BBUL
|
||||
#define CDC_RNDIS_STATUS_MEDIA_CONNECT 0x4001000BUL
|
||||
#define CDC_RNDIS_STATUS_MEDIA_DISCONNECT 0x4001000CUL
|
||||
/** Media state */
|
||||
#define CDC_RNDIS_MEDIA_STATE_CONNECTED 0x00000000UL
|
||||
#define CDC_RNDIS_MEDIA_STATE_DISCONNECTED 0x00000001UL
|
||||
|
||||
/** Media types */
|
||||
#define CDC_RNDIS_MEDIUM_802_3 0x00000000UL
|
||||
|
||||
#define CDC_RNDIS_DF_CONNECTIONLESS 0x00000001UL
|
||||
#define CDC_RNDIS_DF_CONNECTION_ORIENTED 0x00000002UL
|
||||
|
||||
/** Hardware status of the underlying NIC */
|
||||
#define CDC_RNDIS_HW_STS_READY 0x00000000UL
|
||||
#define CDC_RNDIS_HW_STS_INITIALIZING 0x00000001UL
|
||||
#define CDC_RNDIS_HW_STS_RESET 0x00000002UL
|
||||
#define CDC_RNDIS_HW_STS_CLOSING 0x00000003UL
|
||||
#define CDC_RNDIS_HW_STS_NOT_READY 0x00000004UL
|
||||
|
||||
/** Packet filter */
|
||||
#define CDC_RNDIS_PACKET_DIRECTED 0x00000001UL
|
||||
#define CDC_RNDIS_PACKET_MULTICAST 0x00000002UL
|
||||
#define CDC_RNDIS_PACKET_ALL_MULTICAST 0x00000004UL
|
||||
#define CDC_RNDIS_PACKET_BROADCAST 0x00000008UL
|
||||
#define CDC_RNDIS_PACKET_SOURCE_ROUTING 0x00000010UL
|
||||
#define CDC_RNDIS_PACKET_PROMISCUOUS 0x00000020UL
|
||||
#define CDC_RNDIS_PACKET_SMT 0x00000040UL
|
||||
#define CDC_RNDIS_PACKET_ALL_LOCAL 0x00000080UL
|
||||
#define CDC_RNDIS_PACKET_GROUP 0x00001000UL
|
||||
#define CDC_RNDIS_PACKET_ALL_FUNCTIONAL 0x00002000UL
|
||||
#define CDC_RNDIS_PACKET_FUNCTIONAL 0x00004000UL
|
||||
#define CDC_RNDIS_PACKET_MAC_FRAME 0x00008000UL
|
||||
|
||||
#define OID_GEN_SUPPORTED_LIST 0x00010101UL
|
||||
#define OID_GEN_HARDWARE_STATUS 0x00010102UL
|
||||
#define OID_GEN_MEDIA_SUPPORTED 0x00010103UL
|
||||
#define OID_GEN_MEDIA_IN_USE 0x00010104UL
|
||||
#define OID_GEN_MAXIMUM_FRAME_SIZE 0x00010106UL
|
||||
#define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111UL
|
||||
#define OID_GEN_LINK_SPEED 0x00010107UL
|
||||
#define OID_GEN_TRANSMIT_BLOCK_SIZE 0x0001010AUL
|
||||
#define OID_GEN_RECEIVE_BLOCK_SIZE 0x0001010BUL
|
||||
#define OID_GEN_VENDOR_ID 0x0001010CUL
|
||||
#define OID_GEN_VENDOR_DESCRIPTION 0x0001010DUL
|
||||
#define OID_GEN_CURRENT_PACKET_FILTER 0x0001010EUL
|
||||
#define OID_GEN_MEDIA_CONNECT_STATUS 0x00010114UL
|
||||
#define OID_GEN_MAXIMUM_SEND_PACKETS 0x00010115UL
|
||||
#define OID_GEN_PHYSICAL_MEDIUM 0x00010202UL
|
||||
#define OID_GEN_XMIT_OK 0x00020101UL
|
||||
#define OID_GEN_RCV_OK 0x00020102UL
|
||||
#define OID_GEN_XMIT_ERROR 0x00020103UL
|
||||
#define OID_GEN_RCV_ERROR 0x00020104UL
|
||||
#define OID_GEN_RCV_NO_BUFFER 0x00020105UL
|
||||
#define OID_GEN_CDC_RNDIS_CONFIG_PARAMETER 0x0001021BUL
|
||||
#define OID_802_3_PERMANENT_ADDRESS 0x01010101UL
|
||||
#define OID_802_3_CURRENT_ADDRESS 0x01010102UL
|
||||
#define OID_802_3_MULTICAST_LIST 0x01010103UL
|
||||
#define OID_802_3_MAXIMUM_LIST_SIZE 0x01010104UL
|
||||
#define OID_802_3_RCV_ERROR_ALIGNMENT 0x01020101UL
|
||||
#define OID_802_3_XMIT_ONE_COLLISION 0x01020102UL
|
||||
#define OID_802_3_XMIT_MORE_COLLISIONS 0x01020103UL
|
||||
|
||||
|
||||
#define CDC_RNDIS_SEND_ENCAPSULATED_COMMAND 0x00U
|
||||
#define CDC_RNDIS_GET_ENCAPSULATED_RESPONSE 0x01U
|
||||
|
||||
#define CDC_RNDIS_NET_DISCONNECTED 0x00U
|
||||
#define CDC_RNDIS_NET_CONNECTED 0x01U
|
||||
|
||||
#define CDC_RNDIS_BMREQUEST_TYPE_RNDIS 0xA1U
|
||||
#define CDC_RNDIS_PCKTMSG_DATAOFFSET_OFFSET 8U
|
||||
|
||||
/* MAC String index */
|
||||
#define CDC_RNDIS_MAC_STRING_INDEX 6U
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
typedef struct _USBD_CDC_RNDIS_Itf
|
||||
{
|
||||
int8_t (* Init)(void);
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||
int8_t (* TransmitCplt)(uint8_t *Buf, uint32_t *Len, uint8_t epnum);
|
||||
int8_t (* Process)(USBD_HandleTypeDef *pdev);
|
||||
uint8_t *pStrDesc;
|
||||
} USBD_CDC_RNDIS_ItfTypeDef;
|
||||
|
||||
/* CDC_RNDIS State values */
|
||||
typedef enum
|
||||
{
|
||||
CDC_RNDIS_STATE_UNINITIALIZED = 0,
|
||||
CDC_RNDIS_STATE_BUS_INITIALIZED = 1,
|
||||
CDC_RNDIS_STATE_INITIALIZED = 2,
|
||||
CDC_RNDIS_STATE_DATA_INITIALIZED = 3
|
||||
} USBD_CDC_RNDIS_StateTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bmRequest;
|
||||
uint8_t bRequest;
|
||||
uint16_t wValue;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
uint8_t data[8];
|
||||
} USBD_CDC_RNDIS_NotifTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t data[CDC_RNDIS_MAX_DATA_SZE / 4U]; /* Force 32-bit alignment */
|
||||
uint8_t CmdOpCode;
|
||||
uint8_t CmdLength;
|
||||
uint8_t ResponseRdy; /* Indicates if the Device Response to an CDC_RNDIS msg is ready */
|
||||
uint8_t Reserved1; /* Reserved Byte to force 4 bytes alignment of following fields */
|
||||
uint8_t *RxBuffer;
|
||||
uint8_t *TxBuffer;
|
||||
uint32_t RxLength;
|
||||
uint32_t TxLength;
|
||||
|
||||
USBD_CDC_RNDIS_NotifTypeDef Req;
|
||||
USBD_CDC_RNDIS_StateTypeDef State;
|
||||
|
||||
__IO uint32_t TxState;
|
||||
__IO uint32_t RxState;
|
||||
|
||||
__IO uint32_t MaxPcktLen;
|
||||
__IO uint32_t LinkStatus;
|
||||
__IO uint32_t NotificationStatus;
|
||||
__IO uint32_t PacketFilter;
|
||||
} 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 ---------------------*/
|
||||
|
||||
/* Type define for a CDC_RNDIS Initialize command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t ReqId;
|
||||
uint32_t MajorVersion;
|
||||
uint32_t MinorVersion;
|
||||
uint32_t MaxTransferSize;
|
||||
} USBD_CDC_RNDIS_InitMsgTypeDef;
|
||||
|
||||
/* Type define for a CDC_RNDIS Halt Message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t ReqId;
|
||||
} USBD_CDC_RNDIS_HaltMsgTypeDef;
|
||||
|
||||
/* Type define for a CDC_RNDIS Query command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t RequestId;
|
||||
uint32_t Oid;
|
||||
uint32_t InfoBufLength;
|
||||
uint32_t InfoBufOffset;
|
||||
uint32_t DeviceVcHandle;
|
||||
uint32_t InfoBuf[CDC_RNDIS_MAX_INFO_BUFF_SZ];
|
||||
} USBD_CDC_RNDIS_QueryMsgTypeDef;
|
||||
|
||||
/* Type define for a CDC_RNDIS Set command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t ReqId;
|
||||
uint32_t Oid;
|
||||
uint32_t InfoBufLength;
|
||||
uint32_t InfoBufOffset;
|
||||
uint32_t DeviceVcHandle;
|
||||
uint32_t InfoBuf[CDC_RNDIS_MAX_INFO_BUFF_SZ];
|
||||
} USBD_CDC_RNDIS_SetMsgTypeDef;
|
||||
|
||||
/* Type define for a CDC_RNDIS Reset message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t Reserved;
|
||||
} USBD_CDC_RNDIS_ResetMsgTypeDef;
|
||||
|
||||
/* Type define for a CDC_RNDIS Keepalive command message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t ReqId;
|
||||
} USBD_CDC_RNDIS_KpAliveMsgTypeDef;
|
||||
|
||||
|
||||
/* Messages Sent by the Device ---------------------*/
|
||||
|
||||
/* Type define for a CDC_RNDIS Initialize complete response message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t ReqId;
|
||||
uint32_t Status;
|
||||
uint32_t MajorVersion;
|
||||
uint32_t MinorVersion;
|
||||
uint32_t DeviceFlags;
|
||||
uint32_t Medium;
|
||||
uint32_t MaxPacketsPerTransfer;
|
||||
uint32_t MaxTransferSize;
|
||||
uint32_t PacketAlignmentFactor;
|
||||
uint32_t AFListOffset;
|
||||
uint32_t AFListSize;
|
||||
} USBD_CDC_RNDIS_InitCpltMsgTypeDef;
|
||||
|
||||
/* Type define for a CDC_RNDIS Query complete response message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t ReqId;
|
||||
uint32_t Status;
|
||||
uint32_t InfoBufLength;
|
||||
uint32_t InfoBufOffset;
|
||||
uint32_t InfoBuf[CDC_RNDIS_MAX_INFO_BUFF_SZ];
|
||||
} USBD_CDC_RNDIS_QueryCpltMsgTypeDef;
|
||||
|
||||
/* Type define for a CDC_RNDIS Set complete response message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t ReqId;
|
||||
uint32_t Status;
|
||||
} USBD_CDC_RNDIS_SetCpltMsgTypeDef;
|
||||
|
||||
/* Type define for a CDC_RNDIS Reset complete message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t Status;
|
||||
uint32_t AddrReset;
|
||||
} USBD_CDC_RNDIS_ResetCpltMsgTypeDef;
|
||||
|
||||
/* Type define for CDC_RNDIS struct to indicate a change
|
||||
in the status of the device */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t Status;
|
||||
uint32_t StsBufLength;
|
||||
uint32_t StsBufOffset;
|
||||
} USBD_CDC_RNDIS_StsChangeMsgTypeDef;
|
||||
|
||||
/* Type define for a CDC_RNDIS Keepalive complete message */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t ReqId;
|
||||
uint32_t Status;
|
||||
} USBD_CDC_RNDIS_KpAliveCpltMsgTypeDef;
|
||||
|
||||
|
||||
/* Messages Sent by both Host and Device ---------------------*/
|
||||
|
||||
/* Type define for a CDC_RNDIS packet message, used to encapsulate
|
||||
Ethernet packets sent to and from the adapter */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t DataOffset;
|
||||
uint32_t DataLength;
|
||||
uint32_t OOBDataOffset;
|
||||
uint32_t OOBDataLength;
|
||||
uint32_t NumOOBDataElements;
|
||||
uint32_t PerPacketInfoOffset;
|
||||
uint32_t PerPacketInfoLength;
|
||||
uint32_t VcHandle;
|
||||
uint32_t Reserved;
|
||||
} USBD_CDC_RNDIS_PacketMsgTypeDef;
|
||||
|
||||
/* Miscellaneous types used for parsing ---------------------*/
|
||||
|
||||
/* The common part for all CDC_RNDIS messages Complete response */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
uint32_t ReqId;
|
||||
uint32_t Status;
|
||||
} USBD_CDC_RNDIS_CommonCpltMsgTypeDef;
|
||||
|
||||
/* Type define for a single parameter structure */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t ParamNameOffset;
|
||||
uint32_t ParamNameLength;
|
||||
uint32_t ParamType;
|
||||
uint32_t ParamValueOffset;
|
||||
uint32_t ParamValueLength;
|
||||
} USBD_CDC_RNDIS_ParamStructTypeDef;
|
||||
|
||||
|
||||
/* Type define of a single CDC_RNDIS OOB data record */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Size;
|
||||
uint32_t Type;
|
||||
uint32_t ClassInfoType;
|
||||
uint32_t OOBData[sizeof(uint32_t)];
|
||||
} USBD_CDC_RNDIS_OOBPacketTypeDef;
|
||||
|
||||
/* Type define for notification structure */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t notification;
|
||||
uint32_t reserved;
|
||||
} USBD_CDC_RNDIS_NotifStructTypeDef;
|
||||
|
||||
/* This structure will be used to store the type, the size and ID for any
|
||||
received message from the control endpoint */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t MsgType;
|
||||
uint32_t MsgLength;
|
||||
} USBD_CDC_RNDIS_CtrlMsgTypeDef;
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_CDC_RNDIS;
|
||||
#define USBD_CDC_RNDIS_CLASS &USBD_CDC_RNDIS
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
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_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_CDC_RNDIS_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_RNDIS_ItfTypeDef *fops);
|
||||
|
||||
uint8_t USBD_CDC_RNDIS_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff, uint32_t length);
|
||||
|
||||
uint8_t USBD_CDC_RNDIS_SendNotification(USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_RNDIS_NotifCodeTypeDef Notif,
|
||||
uint16_t bVal, uint8_t *pData);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_CDC_RNDIS_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
58
Class/CDC_RNDIS/Inc/usbd_cdc_rndis_if_template.h
Normal file
58
Class/CDC_RNDIS/Inc/usbd_cdc_rndis_if_template.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc_rndis_if_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header for usbd_cdc_rndis_if.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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_CDC_RNDIS_IF_H
|
||||
#define __USBD_CDC_RNDIS_IF_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_cdc_rndis.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* Ensure this MAC address value is same as MAC_ADDRx declared in STM32xxx_conf.h */
|
||||
#define CDC_RNDIS_MAC_STR_DESC (uint8_t *)"000202030000"
|
||||
#define CDC_RNDIS_MAC_ADDR0 0x00U /* 01 */
|
||||
#define CDC_RNDIS_MAC_ADDR1 0x02U /* 02 */
|
||||
#define CDC_RNDIS_MAC_ADDR2 0x02U /* 03 */
|
||||
#define CDC_RNDIS_MAC_ADDR3 0x03U /* 00 */
|
||||
#define CDC_RNDIS_MAC_ADDR4 0x00U /* 00 */
|
||||
#define CDC_RNDIS_MAC_ADDR5 0x00U /* 00 */
|
||||
|
||||
#define USBD_CDC_RNDIS_VENDOR_DESC "STMicroelectronics"
|
||||
#define USBD_CDC_RNDIS_LINK_SPEED 100000U /* 10Mbps */
|
||||
#define USBD_CDC_RNDIS_VID 0x0483U
|
||||
|
||||
/* Max Number of Trials waiting for Tx ready */
|
||||
#define CDC_RNDIS_MAX_TX_WAIT_TRIALS 1000000U
|
||||
|
||||
/* Ethernet Maximum Segment size, typically 1514 bytes */
|
||||
#define CDC_RNDIS_ETH_MAX_SEGSZE 1514U
|
||||
|
||||
#define CDC_RNDIS_CONNECT_SPEED_UPSTREAM 0x1E000000U
|
||||
#define CDC_RNDIS_CONNECT_SPEED_DOWNSTREAM 0x1E000000U
|
||||
|
||||
|
||||
extern USBD_CDC_RNDIS_ItfTypeDef USBD_CDC_RNDIS_fops;
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
#endif /* __USBD_CDC_RNDIS_IF_H */
|
||||
|
||||
1780
Class/CDC_RNDIS/Src/usbd_cdc_rndis.c
Normal file
1780
Class/CDC_RNDIS/Src/usbd_cdc_rndis.c
Normal file
File diff suppressed because it is too large
Load Diff
233
Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c
Normal file
233
Class/CDC_RNDIS/Src/usbd_cdc_rndis_if_template.c
Normal file
@@ -0,0 +1,233 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc_rndis_if_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief Source file for USBD CDC_RNDIS interface template
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2019 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
/* Include TCP/IP stack header files */
|
||||
/*
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/timeouts.h"
|
||||
#include "netif/etharp.h"
|
||||
#include "http_cgi_ssi.h"
|
||||
#include "ethernetif.h"
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Received Data over USB are stored in this buffer */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__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 */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN static uint8_t UserTxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END;
|
||||
|
||||
static uint8_t CDC_RNDISInitialized = 0U;
|
||||
|
||||
/* USB handler declaration */
|
||||
extern USBD_HandleTypeDef USBD_Device;
|
||||
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static int8_t CDC_RNDIS_Itf_Init(void);
|
||||
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_Receive(uint8_t *pbuf, uint32_t *Len);
|
||||
static int8_t CDC_RNDIS_Itf_TransmitCplt(uint8_t *pbuf, uint32_t *Len, uint8_t epnum);
|
||||
static int8_t CDC_RNDIS_Itf_Process(USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_CDC_RNDIS_ItfTypeDef USBD_CDC_RNDIS_fops =
|
||||
{
|
||||
CDC_RNDIS_Itf_Init,
|
||||
CDC_RNDIS_Itf_DeInit,
|
||||
CDC_RNDIS_Itf_Control,
|
||||
CDC_RNDIS_Itf_Receive,
|
||||
CDC_RNDIS_Itf_TransmitCplt,
|
||||
CDC_RNDIS_Itf_Process,
|
||||
(uint8_t *)CDC_RNDIS_MAC_STR_DESC,
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief CDC_RNDIS_Itf_Init
|
||||
* Initializes the CDC_RNDIS media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_RNDIS_Itf_Init(void)
|
||||
{
|
||||
if (CDC_RNDISInitialized == 0U)
|
||||
{
|
||||
/*
|
||||
Initialize the LwIP stack
|
||||
Add your code here
|
||||
|
||||
*/
|
||||
|
||||
CDC_RNDISInitialized = 1U;
|
||||
}
|
||||
|
||||
/* Set Application Buffers */
|
||||
(void)USBD_CDC_RNDIS_SetTxBuffer(&USBD_Device, UserTxBuffer, 0U);
|
||||
(void)USBD_CDC_RNDIS_SetRxBuffer(&USBD_Device, UserRxBuffer);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_RNDIS_Itf_DeInit
|
||||
* DeInitializes the CDC_RNDIS media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_RNDIS_Itf_DeInit(void)
|
||||
{
|
||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(USBD_Device.pClassData);
|
||||
|
||||
/*
|
||||
Add your code here
|
||||
*/
|
||||
|
||||
/* Notify application layer that link is down */
|
||||
hcdc_cdc_rndis->LinkStatus = 0U;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_RNDIS_Itf_Control
|
||||
* Manage the CDC_RNDIS class requests
|
||||
* @param Cmd: Command code
|
||||
* @param Buf: Buffer containing command data (request parameters)
|
||||
* @param Len: Number of data to be sent (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_RNDIS_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||
{
|
||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(USBD_Device.pClassData);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case CDC_RNDIS_SEND_ENCAPSULATED_COMMAND:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_RNDIS_GET_ENCAPSULATED_RESPONSE:
|
||||
/* Check if this is the first time we enter */
|
||||
if (hcdc_cdc_rndis->LinkStatus == 0U)
|
||||
{
|
||||
/* Setup the Link up at TCP/IP stack level */
|
||||
hcdc_cdc_rndis->LinkStatus = 1U;
|
||||
/*
|
||||
Add your code here
|
||||
*/
|
||||
}
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Add your code here */
|
||||
break;
|
||||
}
|
||||
|
||||
UNUSED(length);
|
||||
UNUSED(pbuf);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_RNDIS_Itf_Receive
|
||||
* Data received over USB OUT endpoint are sent over CDC_RNDIS interface
|
||||
* through this function.
|
||||
* @param Buf: Buffer of data to be transmitted
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_RNDIS_Itf_Receive(uint8_t *Buf, uint32_t *Len)
|
||||
{
|
||||
/* Get the CDC_RNDIS handler pointer */
|
||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(USBD_Device.pClassData);
|
||||
|
||||
/* Call Eth buffer processing */
|
||||
hcdc_cdc_rndis->RxState = 1U;
|
||||
|
||||
UNUSED(Buf);
|
||||
UNUSED(Len);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_RNDIS_Itf_TransmitCplt
|
||||
* Data transmitted callback
|
||||
*
|
||||
* @note
|
||||
* This function is IN transfer complete callback used to inform user that
|
||||
* the submitted Data is successfully sent over USB.
|
||||
*
|
||||
* @param Buf: Buffer of data to be received
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @param epnum: EP number
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_RNDIS_Itf_TransmitCplt(uint8_t *Buf, uint32_t *Len, uint8_t epnum)
|
||||
{
|
||||
UNUSED(Buf);
|
||||
UNUSED(Len);
|
||||
UNUSED(epnum);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CDC_RNDIS_Itf_Process
|
||||
* Data received over USB OUT endpoint are sent over CDC_RNDIS interface
|
||||
* through this function.
|
||||
* @param pdef: pointer to the USB Device Handle
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t CDC_RNDIS_Itf_Process(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Get the CDC_RNDIS handler pointer */
|
||||
USBD_CDC_RNDIS_HandleTypeDef *hcdc_cdc_rndis = (USBD_CDC_RNDIS_HandleTypeDef *)(pdev->pClassData);
|
||||
|
||||
if ((hcdc_cdc_rndis != NULL) && (hcdc_cdc_rndis->LinkStatus != 0U))
|
||||
{
|
||||
/*
|
||||
Add your code here
|
||||
Read a received packet from the Ethernet buffers and send it
|
||||
to the lwIP for handling
|
||||
*/
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -41,41 +40,48 @@ extern "C" {
|
||||
/** @defgroup USBD_CUSTOM_HID_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define CUSTOM_HID_EPIN_ADDR 0x81U
|
||||
#define CUSTOM_HID_EPIN_SIZE 0x02U
|
||||
#define CUSTOM_HID_EPIN_ADDR 0x81U
|
||||
|
||||
#define CUSTOM_HID_EPOUT_ADDR 0x01U
|
||||
#define CUSTOM_HID_EPOUT_SIZE 0x02U
|
||||
#ifndef CUSTOM_HID_EPIN_SIZE
|
||||
#define CUSTOM_HID_EPIN_SIZE 0x02U
|
||||
#endif
|
||||
|
||||
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U
|
||||
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
||||
#define CUSTOM_HID_EPOUT_ADDR 0x01U
|
||||
|
||||
#ifndef CUSTOM_HID_EPOUT_SIZE
|
||||
#define CUSTOM_HID_EPOUT_SIZE 0x02U
|
||||
#endif
|
||||
|
||||
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U
|
||||
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
||||
|
||||
#ifndef CUSTOM_HID_HS_BINTERVAL
|
||||
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
||||
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
||||
#endif /* CUSTOM_HID_HS_BINTERVAL */
|
||||
|
||||
#ifndef CUSTOM_HID_FS_BINTERVAL
|
||||
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
||||
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
||||
#endif /* CUSTOM_HID_FS_BINTERVAL */
|
||||
|
||||
#ifndef USBD_CUSTOMHID_OUTREPORT_BUF_SIZE
|
||||
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U
|
||||
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U
|
||||
#endif /* USBD_CUSTOMHID_OUTREPORT_BUF_SIZE */
|
||||
|
||||
#ifndef USBD_CUSTOM_HID_REPORT_DESC_SIZE
|
||||
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U
|
||||
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U
|
||||
#endif /* USBD_CUSTOM_HID_REPORT_DESC_SIZE */
|
||||
|
||||
#define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U
|
||||
#define CUSTOM_HID_REPORT_DESC 0x22U
|
||||
#define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U
|
||||
#define CUSTOM_HID_REPORT_DESC 0x22U
|
||||
|
||||
#define CUSTOM_HID_REQ_SET_PROTOCOL 0x0BU
|
||||
#define CUSTOM_HID_REQ_GET_PROTOCOL 0x03U
|
||||
#define CUSTOM_HID_REQ_SET_PROTOCOL 0x0BU
|
||||
#define CUSTOM_HID_REQ_GET_PROTOCOL 0x03U
|
||||
|
||||
#define CUSTOM_HID_REQ_SET_IDLE 0x0AU
|
||||
#define CUSTOM_HID_REQ_GET_IDLE 0x02U
|
||||
#define CUSTOM_HID_REQ_SET_IDLE 0x0AU
|
||||
#define CUSTOM_HID_REQ_GET_IDLE 0x02U
|
||||
|
||||
#define CUSTOM_HID_REQ_SET_REPORT 0x09U
|
||||
#define CUSTOM_HID_REQ_GET_REPORT 0x01U
|
||||
#define CUSTOM_HID_REQ_SET_REPORT 0x09U
|
||||
#define CUSTOM_HID_REQ_GET_REPORT 0x01U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -88,12 +94,11 @@ typedef enum
|
||||
{
|
||||
CUSTOM_HID_IDLE = 0U,
|
||||
CUSTOM_HID_BUSY,
|
||||
}
|
||||
CUSTOM_HID_StateTypeDef;
|
||||
} CUSTOM_HID_StateTypeDef;
|
||||
|
||||
typedef struct _USBD_CUSTOM_HID_Itf
|
||||
{
|
||||
uint8_t *pReport;
|
||||
uint8_t *pReport;
|
||||
int8_t (* Init)(void);
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* OutEvent)(uint8_t event_idx, uint8_t state);
|
||||
@@ -102,14 +107,13 @@ typedef struct _USBD_CUSTOM_HID_Itf
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Report_buf[USBD_CUSTOMHID_OUTREPORT_BUF_SIZE];
|
||||
uint32_t Protocol;
|
||||
uint32_t IdleState;
|
||||
uint32_t AltSetting;
|
||||
uint32_t IsReportAvailable;
|
||||
CUSTOM_HID_StateTypeDef state;
|
||||
}
|
||||
USBD_CUSTOM_HID_HandleTypeDef;
|
||||
uint8_t Report_buf[USBD_CUSTOMHID_OUTREPORT_BUF_SIZE];
|
||||
uint32_t Protocol;
|
||||
uint32_t IdleState;
|
||||
uint32_t AltSetting;
|
||||
uint32_t IsReportAvailable;
|
||||
CUSTOM_HID_StateTypeDef state;
|
||||
} USBD_CUSTOM_HID_HandleTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -128,8 +132,8 @@ USBD_CUSTOM_HID_HandleTypeDef;
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_CUSTOM_HID;
|
||||
#define USBD_CUSTOM_HID_CLASS &USBD_CUSTOM_HID
|
||||
extern USBD_ClassTypeDef USBD_CUSTOM_HID;
|
||||
#define USBD_CUSTOM_HID_CLASS &USBD_CUSTOM_HID
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -138,13 +142,12 @@ extern USBD_ClassTypeDef USBD_CUSTOM_HID;
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len);
|
||||
uint8_t *report, uint16_t len);
|
||||
|
||||
uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||
|
||||
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops);
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops);
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -163,4 +166,3 @@ uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -40,4 +39,3 @@ extern USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops;
|
||||
|
||||
#endif /* __USBD_CUSTOMHID_IF_TEMPLATE_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -4,6 +4,17 @@
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the CUSTOM_HID core functions.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2015 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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
@@ -24,17 +35,6 @@
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
@@ -84,28 +84,19 @@ EndBSPDependencies */
|
||||
* @{
|
||||
*/
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
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_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
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_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length);
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
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_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length);
|
||||
|
||||
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_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -135,177 +126,183 @@ USBD_ClassTypeDef USBD_CUSTOM_HID =
|
||||
/* USB CUSTOM_HID device FS Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[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 */
|
||||
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*/
|
||||
0xC0, /*bmAttributes: bus powered */
|
||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
||||
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*/
|
||||
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 */
|
||||
0x00, /* 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*/
|
||||
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, /* 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:*/
|
||||
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 Byte max */
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
};
|
||||
|
||||
/* 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 */
|
||||
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*/
|
||||
0xC0, /*bmAttributes: bus powered */
|
||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
||||
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*/
|
||||
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*/
|
||||
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, /* 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:*/
|
||||
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 Byte max */
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
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*/
|
||||
0xC0, /*bmAttributes: bus powered */
|
||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
||||
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*/
|
||||
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*/
|
||||
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, /* 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:*/
|
||||
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 Byte max */
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
};
|
||||
|
||||
@@ -313,14 +310,14 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CO
|
||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/* 18 */
|
||||
0x09, /*bLength: CUSTOM_HID Descriptor size*/
|
||||
CUSTOM_HID_DESCRIPTOR_TYPE, /*bDescriptorType: CUSTOM_HID*/
|
||||
0x11, /*bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number*/
|
||||
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, /* 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,
|
||||
};
|
||||
|
||||
@@ -354,43 +351,53 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUA
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0U;
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||
UNUSED(cfgidx);
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)USBD_malloc(sizeof(USBD_CUSTOM_HID_HandleTypeDef));
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
pdev->pClassData = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
pdev->pClassData = (void *)hhid;
|
||||
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||
}
|
||||
else /* LOW and FULL-speed endpoints */
|
||||
{
|
||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, CUSTOM_HID_EPIN_ADDR, USBD_EP_TYPE_INTR,
|
||||
CUSTOM_HID_EPIN_SIZE);
|
||||
(void)USBD_LL_OpenEP(pdev, CUSTOM_HID_EPIN_ADDR, USBD_EP_TYPE_INTR,
|
||||
CUSTOM_HID_EPIN_SIZE);
|
||||
|
||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, CUSTOM_HID_EPOUT_ADDR, USBD_EP_TYPE_INTR,
|
||||
CUSTOM_HID_EPOUT_SIZE);
|
||||
(void)USBD_LL_OpenEP(pdev, CUSTOM_HID_EPOUT_ADDR, USBD_EP_TYPE_INTR,
|
||||
CUSTOM_HID_EPOUT_SIZE);
|
||||
|
||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_CUSTOM_HID_HandleTypeDef));
|
||||
hhid->state = CUSTOM_HID_IDLE;
|
||||
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
ret = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *) pdev->pClassData;
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
|
||||
hhid->state = CUSTOM_HID_IDLE;
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
/* Prepare Out endpoint to receive 1st packet */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
|
||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||
|
||||
/* Prepare Out endpoint to receive 1st packet */
|
||||
USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
|
||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,25 +407,29 @@ static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev,
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
/* Close CUSTOM_HID EP IN */
|
||||
USBD_LL_CloseEP(pdev, CUSTOM_HID_EPIN_ADDR);
|
||||
(void)USBD_LL_CloseEP(pdev, CUSTOM_HID_EPIN_ADDR);
|
||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].bInterval = 0U;
|
||||
|
||||
/* Close CUSTOM_HID EP OUT */
|
||||
USBD_LL_CloseEP(pdev, CUSTOM_HID_EPOUT_ADDR);
|
||||
(void)USBD_LL_CloseEP(pdev, CUSTOM_HID_EPOUT_ADDR);
|
||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 0U;
|
||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].bInterval = 0U;
|
||||
|
||||
/* FRee allocated memory */
|
||||
/* Free allocated memory */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
return USBD_OK;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,18 +439,23 @@ static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
uint16_t len = 0U;
|
||||
uint8_t *pbuf = NULL;
|
||||
uint16_t status_info = 0U;
|
||||
uint8_t ret = USBD_OK;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case CUSTOM_HID_REQ_SET_PROTOCOL:
|
||||
@@ -447,7 +463,7 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_GET_PROTOCOL:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->Protocol, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_SET_IDLE:
|
||||
@@ -455,12 +471,13 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_GET_IDLE:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->IdleState, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_SET_REPORT:
|
||||
hhid->IsReportAvailable = 1U;
|
||||
USBD_CtlPrepareRx(pdev, hhid->Report_buf, req->wLength);
|
||||
(void)USBD_CtlPrepareRx(pdev, hhid->Report_buf,
|
||||
MIN(req->wLength, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -476,7 +493,7 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -486,27 +503,27 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
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);
|
||||
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (req->wValue >> 8 == CUSTOM_HID_DESCRIPTOR_TYPE)
|
||||
if ((req->wValue >> 8) == CUSTOM_HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_CUSTOM_HID_Desc;
|
||||
len = MIN(USB_CUSTOM_HID_DESC_SIZ, req->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
USBD_CtlSendData(pdev, pbuf, len);
|
||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->AltSetting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -515,7 +532,7 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||
@@ -527,6 +544,9 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
@@ -539,7 +559,7 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -549,25 +569,31 @@ static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
* @param buff: pointer to report
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len)
|
||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report, uint16_t len)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (hhid->state == CUSTOM_HID_IDLE)
|
||||
{
|
||||
hhid->state = CUSTOM_HID_BUSY;
|
||||
USBD_LL_Transmit(pdev, CUSTOM_HID_EPIN_ADDR, report, len);
|
||||
(void)USBD_LL_Transmit(pdev, CUSTOM_HID_EPIN_ADDR, report, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_BUSY;
|
||||
return (uint8_t)USBD_BUSY;
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -577,9 +603,10 @@ uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length)
|
||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_CUSTOM_HID_CfgFSDesc);
|
||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgFSDesc);
|
||||
|
||||
return USBD_CUSTOM_HID_CfgFSDesc;
|
||||
}
|
||||
|
||||
@@ -590,9 +617,10 @@ static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length)
|
||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_CUSTOM_HID_CfgHSDesc);
|
||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgHSDesc);
|
||||
|
||||
return USBD_CUSTOM_HID_CfgHSDesc;
|
||||
}
|
||||
|
||||
@@ -603,9 +631,10 @@ static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_CUSTOM_HID_OtherSpeedCfgDesc);
|
||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_OtherSpeedCfgDesc);
|
||||
|
||||
return USBD_CUSTOM_HID_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
@@ -616,14 +645,15 @@ static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
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)
|
||||
{
|
||||
UNUSED(epnum);
|
||||
|
||||
/* 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 */
|
||||
((USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData)->state = CUSTOM_HID_IDLE;
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -633,21 +663,52 @@ static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev,
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
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)
|
||||
{
|
||||
UNUSED(epnum);
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* USB data will be immediately processed, this allow next USB traffic being
|
||||
NAKed till the end of the application processing */
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0],
|
||||
hhid->Report_buf[1]);
|
||||
|
||||
USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
|
||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_ReceivePacket
|
||||
* prepare OUT Endpoint for reception
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* Resume USB Out process */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
|
||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_EP0_RxReady
|
||||
* Handles control request data.
|
||||
@@ -656,7 +717,12 @@ static uint8_t USBD_CUSTOM_HID_DataOut(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->pClassData;
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
if (hhid->IsReportAvailable == 1U)
|
||||
{
|
||||
@@ -665,39 +731,39 @@ static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
hhid->IsReportAvailable = 0U;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length)
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_CUSTOM_HID_DeviceQualifierDesc);
|
||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_DeviceQualifierDesc);
|
||||
|
||||
return USBD_CUSTOM_HID_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_RegisterInterface
|
||||
* @brief USBD_CUSTOM_HID_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: CUSTOMHID Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops)
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops)
|
||||
{
|
||||
uint8_t ret = USBD_FAIL;
|
||||
|
||||
if (fops != NULL)
|
||||
if (fops == NULL)
|
||||
{
|
||||
pdev->pUserData = fops;
|
||||
ret = USBD_OK;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
pdev->pUserData = fops;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
@@ -713,4 +779,3 @@ uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -8,13 +8,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -53,7 +52,6 @@ USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops =
|
||||
*/
|
||||
static int8_t TEMPLATE_CUSTOM_HID_Init(void)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -81,7 +79,12 @@ static int8_t TEMPLATE_CUSTOM_HID_DeInit(void)
|
||||
*/
|
||||
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state)
|
||||
{
|
||||
UNUSED(event_idx);
|
||||
UNUSED(state);
|
||||
|
||||
/* Start next USB packet transfer once data processing is completed */
|
||||
USBD_CUSTOM_HID_ReceivePacket(&USBD_Device);
|
||||
|
||||
return (0);
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -115,7 +114,7 @@ extern "C" {
|
||||
/* Other defines */
|
||||
/**************************************************/
|
||||
/* Bit Detach capable = bit 3 in bmAttributes field */
|
||||
#define DFU_DETACH_MASK (uint8_t)(1 << 4)
|
||||
#define DFU_DETACH_MASK (1U << 4)
|
||||
#define DFU_STATUS_DEPTH 6U
|
||||
|
||||
typedef enum
|
||||
@@ -133,20 +132,20 @@ typedef void (*pFunction)(void);
|
||||
|
||||
|
||||
/********** Descriptor of DFU interface 0 Alternate setting n ****************/
|
||||
#define USBD_DFU_IF_DESC(n) 0x09, /* bLength: Interface Descriptor size */ \
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
0x00, /* bInterfaceNumber: Number of Interface */ \
|
||||
(n), /* bAlternateSetting: Alternate setting */ \
|
||||
0x00, /* bNumEndpoints*/ \
|
||||
0xFE, /* bInterfaceClass: Application Specific Class Code */ \
|
||||
0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ \
|
||||
0x02, /* nInterfaceProtocol: DFU mode protocol */ \
|
||||
USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */ \
|
||||
#define USBD_DFU_IF_DESC(n) \
|
||||
0x09, /* bLength: Interface Descriptor size */ \
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */ \
|
||||
0x00, /* bInterfaceNumber: Number of Interface */ \
|
||||
(n), /* bAlternateSetting: Alternate setting */ \
|
||||
0x00, /* bNumEndpoints*/ \
|
||||
0xFE, /* bInterfaceClass: Application Specific Class Code */ \
|
||||
0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ \
|
||||
0x02, /* nInterfaceProtocol: DFU mode protocol */ \
|
||||
USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */
|
||||
|
||||
#define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), /* XFERSIZEB0 */\
|
||||
((uint8_t)((size) >> 8)) /* XFERSIZEB1 */
|
||||
#define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), ((uint8_t)((size) >> 8))
|
||||
|
||||
#define IS_PROTECTED_AREA(add) (uint8_t)((((add) >= 0x08000000) && ((add) < (APP_DEFAULT_ADD)))? 1:0)
|
||||
#define IS_PROTECTED_AREA(add) (uint8_t)((((add) >= 0x08000000) && ((add) < (APP_DEFAULT_ADD))) ? 1 : 0)
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -162,20 +161,19 @@ typedef struct
|
||||
union
|
||||
{
|
||||
uint32_t d32[USBD_DFU_XFER_SIZE / 4U];
|
||||
uint8_t d8[USBD_DFU_XFER_SIZE];
|
||||
uint8_t d8[USBD_DFU_XFER_SIZE];
|
||||
} buffer;
|
||||
|
||||
uint32_t wblock_num;
|
||||
uint32_t wlength;
|
||||
uint32_t data_ptr;
|
||||
uint32_t alt_setting;
|
||||
uint32_t wblock_num;
|
||||
uint32_t wlength;
|
||||
uint32_t data_ptr;
|
||||
uint32_t alt_setting;
|
||||
|
||||
uint8_t dev_status[DFU_STATUS_DEPTH];
|
||||
uint8_t ReservedForAlign[2];
|
||||
uint8_t dev_state;
|
||||
uint8_t manif_state;
|
||||
}
|
||||
USBD_DFU_HandleTypeDef;
|
||||
uint8_t dev_status[DFU_STATUS_DEPTH];
|
||||
uint8_t ReservedForAlign[2];
|
||||
uint8_t dev_state;
|
||||
uint8_t manif_state;
|
||||
} USBD_DFU_HandleTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -186,8 +184,7 @@ typedef struct
|
||||
uint16_t (* Write)(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);
|
||||
}
|
||||
USBD_DFU_MediaTypeDef;
|
||||
} USBD_DFU_MediaTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -206,8 +203,8 @@ USBD_DFU_MediaTypeDef;
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_DFU;
|
||||
#define USBD_DFU_CLASS &USBD_DFU
|
||||
extern USBD_ClassTypeDef USBD_DFU;
|
||||
#define USBD_DFU_CLASS &USBD_DFU
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -215,8 +212,8 @@ extern USBD_ClassTypeDef USBD_DFU;
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
||||
USBD_DFU_MediaTypeDef *fops);
|
||||
uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
||||
USBD_DFU_MediaTypeDef *fops);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -233,5 +230,3 @@ uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -92,6 +91,5 @@ extern USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops;
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
* @}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -131,5 +130,4 @@ uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer)
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -41,32 +40,32 @@ extern "C" {
|
||||
/** @defgroup USBD_HID_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define HID_EPIN_ADDR 0x81U
|
||||
#define HID_EPIN_SIZE 0x04U
|
||||
#define HID_EPIN_ADDR 0x81U
|
||||
#define HID_EPIN_SIZE 0x04U
|
||||
|
||||
#define USB_HID_CONFIG_DESC_SIZ 34U
|
||||
#define USB_HID_DESC_SIZ 9U
|
||||
#define HID_MOUSE_REPORT_DESC_SIZE 74U
|
||||
#define USB_HID_CONFIG_DESC_SIZ 34U
|
||||
#define USB_HID_DESC_SIZ 9U
|
||||
#define HID_MOUSE_REPORT_DESC_SIZE 74U
|
||||
|
||||
#define HID_DESCRIPTOR_TYPE 0x21U
|
||||
#define HID_REPORT_DESC 0x22U
|
||||
#define HID_DESCRIPTOR_TYPE 0x21U
|
||||
#define HID_REPORT_DESC 0x22U
|
||||
|
||||
#ifndef HID_HS_BINTERVAL
|
||||
#define HID_HS_BINTERVAL 0x07U
|
||||
#define HID_HS_BINTERVAL 0x07U
|
||||
#endif /* HID_HS_BINTERVAL */
|
||||
|
||||
#ifndef HID_FS_BINTERVAL
|
||||
#define HID_FS_BINTERVAL 0x0AU
|
||||
#define HID_FS_BINTERVAL 0x0AU
|
||||
#endif /* HID_FS_BINTERVAL */
|
||||
|
||||
#define HID_REQ_SET_PROTOCOL 0x0BU
|
||||
#define HID_REQ_GET_PROTOCOL 0x03U
|
||||
#define HID_REQ_SET_PROTOCOL 0x0BU
|
||||
#define HID_REQ_GET_PROTOCOL 0x03U
|
||||
|
||||
#define HID_REQ_SET_IDLE 0x0AU
|
||||
#define HID_REQ_GET_IDLE 0x02U
|
||||
#define HID_REQ_SET_IDLE 0x0AU
|
||||
#define HID_REQ_GET_IDLE 0x02U
|
||||
|
||||
#define HID_REQ_SET_REPORT 0x09U
|
||||
#define HID_REQ_GET_REPORT 0x01U
|
||||
#define HID_REQ_SET_REPORT 0x09U
|
||||
#define HID_REQ_GET_REPORT 0x01U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -79,18 +78,16 @@ typedef enum
|
||||
{
|
||||
HID_IDLE = 0,
|
||||
HID_BUSY,
|
||||
}
|
||||
HID_StateTypeDef;
|
||||
} HID_StateTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Protocol;
|
||||
uint32_t IdleState;
|
||||
uint32_t AltSetting;
|
||||
HID_StateTypeDef state;
|
||||
}
|
||||
USBD_HID_HandleTypeDef;
|
||||
uint32_t Protocol;
|
||||
uint32_t IdleState;
|
||||
uint32_t AltSetting;
|
||||
HID_StateTypeDef state;
|
||||
} USBD_HID_HandleTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -109,8 +106,8 @@ USBD_HID_HandleTypeDef;
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_HID;
|
||||
#define USBD_HID_CLASS &USBD_HID
|
||||
extern USBD_ClassTypeDef USBD_HID;
|
||||
#define USBD_HID_CLASS &USBD_HID
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -118,10 +115,7 @@ extern USBD_ClassTypeDef USBD_HID;
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
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);
|
||||
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev);
|
||||
|
||||
/**
|
||||
@@ -141,4 +135,3 @@ uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev);
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -4,6 +4,17 @@
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the HID core functions.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2015 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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
@@ -25,17 +36,6 @@
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
@@ -83,31 +83,20 @@ EndBSPDependencies */
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_HID_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
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_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
static uint8_t *USBD_HID_GetFSCfgDesc(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_GetDeviceQualifierDesc(uint16_t *length);
|
||||
|
||||
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_GetFSCfgDesc(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_GetDeviceQualifierDesc(uint16_t *length);
|
||||
|
||||
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -116,16 +105,16 @@ static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_ClassTypeDef USBD_HID =
|
||||
USBD_ClassTypeDef USBD_HID =
|
||||
{
|
||||
USBD_HID_Init,
|
||||
USBD_HID_DeInit,
|
||||
USBD_HID_Setup,
|
||||
NULL, /*EP0_TxSent*/
|
||||
NULL, /*EP0_RxReady*/
|
||||
USBD_HID_DataIn, /*DataIn*/
|
||||
NULL, /*DataOut*/
|
||||
NULL, /*SOF */
|
||||
NULL, /* EP0_TxSent */
|
||||
NULL, /* EP0_RxReady */
|
||||
USBD_HID_DataIn, /* DataIn */
|
||||
NULL, /* DataOut */
|
||||
NULL, /* SOF */
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_HID_GetHSCfgDesc,
|
||||
@@ -135,173 +124,179 @@ USBD_ClassTypeDef USBD_HID =
|
||||
};
|
||||
|
||||
/* 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_CfgFSDesc[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 */
|
||||
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*/
|
||||
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
|
||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
||||
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*/
|
||||
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*/
|
||||
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, /* 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:*/
|
||||
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 Byte max */
|
||||
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 */
|
||||
HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
/* 34 */
|
||||
};
|
||||
|
||||
/* USB HID device HS Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_HID_CfgHSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
__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 */
|
||||
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*/
|
||||
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
|
||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
||||
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*/
|
||||
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*/
|
||||
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, /* 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:*/
|
||||
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 Byte max */
|
||||
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 */
|
||||
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 =
|
||||
__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 */
|
||||
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*/
|
||||
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
|
||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
||||
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*/
|
||||
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*/
|
||||
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, /* 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:*/
|
||||
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 Byte max */
|
||||
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 */
|
||||
HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
/* 34 */
|
||||
};
|
||||
|
||||
|
||||
/* 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 =
|
||||
{
|
||||
/* 18 */
|
||||
0x09, /*bLength: HID Descriptor size*/
|
||||
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
|
||||
0x11, /*bcdHID: HID Class Spec release number*/
|
||||
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, /* 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,
|
||||
};
|
||||
|
||||
/* 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 =
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
@@ -315,54 +310,46 @@ __ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_
|
||||
0x00,
|
||||
};
|
||||
|
||||
__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 =
|
||||
{
|
||||
0x05, 0x01,
|
||||
0x09, 0x02,
|
||||
0xA1, 0x01,
|
||||
0x09, 0x01,
|
||||
|
||||
0xA1, 0x00,
|
||||
0x05, 0x09,
|
||||
0x19, 0x01,
|
||||
0x29, 0x03,
|
||||
|
||||
0x15, 0x00,
|
||||
0x25, 0x01,
|
||||
0x95, 0x03,
|
||||
0x75, 0x01,
|
||||
|
||||
0x81, 0x02,
|
||||
0x95, 0x01,
|
||||
0x75, 0x05,
|
||||
0x81, 0x01,
|
||||
|
||||
0x05, 0x01,
|
||||
0x09, 0x30,
|
||||
0x09, 0x31,
|
||||
0x09, 0x38,
|
||||
|
||||
0x15, 0x81,
|
||||
0x25, 0x7F,
|
||||
0x75, 0x08,
|
||||
0x95, 0x03,
|
||||
|
||||
0x81, 0x06,
|
||||
0xC0, 0x09,
|
||||
0x3c, 0x05,
|
||||
0xff, 0x09,
|
||||
|
||||
0x01, 0x15,
|
||||
0x00, 0x25,
|
||||
0x01, 0x75,
|
||||
0x01, 0x95,
|
||||
|
||||
0x02, 0xb1,
|
||||
0x22, 0x75,
|
||||
0x06, 0x95,
|
||||
0x01, 0xb1,
|
||||
|
||||
0x01, 0xc0
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
|
||||
0x09, 0x02, /* Usage (Mouse) */
|
||||
0xA1, 0x01, /* Collection (Application) */
|
||||
0x09, 0x01, /* Usage (Pointer) */
|
||||
0xA1, 0x00, /* Collection (Physical) */
|
||||
0x05, 0x09, /* Usage Page (Button) */
|
||||
0x19, 0x01, /* Usage Minimum (0x01) */
|
||||
0x29, 0x03, /* Usage Maximum (0x03) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x01, /* Logical Maximum (1) */
|
||||
0x95, 0x03, /* Report Count (3) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x81, 0x02, /* Input (Data,Var,Abs) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0x75, 0x05, /* Report Size (5) */
|
||||
0x81, 0x01, /* Input (Const,Array,Abs) */
|
||||
0x05, 0x01, /* Usage Page (Generic Desktop Ctrls) */
|
||||
0x09, 0x30, /* Usage (X) */
|
||||
0x09, 0x31, /* Usage (Y) */
|
||||
0x09, 0x38, /* Usage (Wheel) */
|
||||
0x15, 0x81, /* Logical Minimum (-127) */
|
||||
0x25, 0x7F, /* Logical Maximum (127) */
|
||||
0x75, 0x08, /* Report Size (8) */
|
||||
0x95, 0x03, /* Report Count (3) */
|
||||
0x81, 0x06, /* Input (Data,Var,Rel) */
|
||||
0xC0, /* End Collection */
|
||||
0x09, 0x3C, /* Usage (Motion Wakeup) */
|
||||
0x05, 0xFF, /* Usage Page (Reserved 0xFF) */
|
||||
0x09, 0x01, /* Usage (0x01) */
|
||||
0x15, 0x00, /* Logical Minimum (0) */
|
||||
0x25, 0x01, /* Logical Maximum (1) */
|
||||
0x75, 0x01, /* Report Size (1) */
|
||||
0x95, 0x02, /* Report Count (2) */
|
||||
0xB1, 0x22, /* Feature (Data,Var,Abs,NoWrp) */
|
||||
0x75, 0x06, /* Report Size (6) */
|
||||
0x95, 0x01, /* Report Count (1) */
|
||||
0xB1, 0x01, /* Feature (Const,Array,Abs,NoWrp) */
|
||||
0xC0 /* End Collection */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -380,46 +367,64 @@ __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] _
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, HID_EPIN_ADDR, USBD_EP_TYPE_INTR, HID_EPIN_SIZE);
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
UNUSED(cfgidx);
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_HID_HandleTypeDef));
|
||||
USBD_HID_HandleTypeDef *hhid;
|
||||
|
||||
if (pdev->pClassData == NULL)
|
||||
hhid = (USBD_HID_HandleTypeDef *)USBD_malloc(sizeof(USBD_HID_HandleTypeDef));
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
pdev->pClassData = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE;
|
||||
pdev->pClassData = (void *)hhid;
|
||||
|
||||
return USBD_OK;
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].bInterval = HID_HS_BINTERVAL;
|
||||
}
|
||||
else /* LOW and FULL-speed endpoints */
|
||||
{
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].bInterval = HID_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
/* Open EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, HID_EPIN_ADDR, USBD_EP_TYPE_INTR, HID_EPIN_SIZE);
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
|
||||
hhid->state = HID_IDLE;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_HID_Init
|
||||
* @brief USBD_HID_DeInit
|
||||
* DeInitialize the HID layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
/* Close HID EPs */
|
||||
USBD_LL_CloseEP(pdev, HID_EPIN_ADDR);
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||
UNUSED(cfgidx);
|
||||
|
||||
/* FRee allocated memory */
|
||||
/* Close HID EPs */
|
||||
(void)USBD_LL_CloseEP(pdev, HID_EPIN_ADDR);
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].bInterval = 0U;
|
||||
|
||||
/* Free allocated memory */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
USBD_free(pdev->pClassData);
|
||||
(void)USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -429,14 +434,18 @@ static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
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;
|
||||
uint16_t len = 0U;
|
||||
uint8_t *pbuf = NULL;
|
||||
uint16_t status_info = 0U;
|
||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
uint16_t len;
|
||||
uint8_t *pbuf;
|
||||
uint16_t status_info = 0U;
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
@@ -448,7 +457,7 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_PROTOCOL:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->Protocol, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U);
|
||||
break;
|
||||
|
||||
case HID_REQ_SET_IDLE:
|
||||
@@ -456,7 +465,7 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
|
||||
case HID_REQ_GET_IDLE:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->IdleState, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -471,7 +480,7 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -481,12 +490,12 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if (req->wValue >> 8 == HID_REPORT_DESC)
|
||||
if ((req->wValue >> 8) == HID_REPORT_DESC)
|
||||
{
|
||||
len = MIN(HID_MOUSE_REPORT_DESC_SIZE, req->wLength);
|
||||
pbuf = HID_MOUSE_ReportDesc;
|
||||
}
|
||||
else if (req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
||||
else if ((req->wValue >> 8) == HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_HID_Desc;
|
||||
len = MIN(USB_HID_DESC_SIZ, req->wLength);
|
||||
@@ -497,13 +506,13 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
USBD_CtlSendData(pdev, pbuf, len);
|
||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hhid->AltSetting, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->AltSetting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -512,7 +521,7 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||
@@ -524,6 +533,9 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
@@ -537,7 +549,7 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -547,24 +559,25 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
* @param buff: pointer to report
|
||||
* @retval status
|
||||
*/
|
||||
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->pClassData;
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (hhid->state == HID_IDLE)
|
||||
{
|
||||
hhid->state = HID_BUSY;
|
||||
USBD_LL_Transmit(pdev,
|
||||
HID_EPIN_ADDR,
|
||||
report,
|
||||
len);
|
||||
(void)USBD_LL_Transmit(pdev, HID_EPIN_ADDR, report, len);
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -575,7 +588,7 @@ uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
*/
|
||||
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
uint32_t polling_interval = 0U;
|
||||
uint32_t polling_interval;
|
||||
|
||||
/* HIGH-speed endpoints */
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
@@ -602,9 +615,10 @@ uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length)
|
||||
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_HID_CfgFSDesc);
|
||||
*length = (uint16_t)sizeof(USBD_HID_CfgFSDesc);
|
||||
|
||||
return USBD_HID_CfgFSDesc;
|
||||
}
|
||||
|
||||
@@ -615,9 +629,10 @@ static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length)
|
||||
static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_HID_CfgHSDesc);
|
||||
*length = (uint16_t)sizeof(USBD_HID_CfgHSDesc);
|
||||
|
||||
return USBD_HID_CfgHSDesc;
|
||||
}
|
||||
|
||||
@@ -628,9 +643,10 @@ static uint8_t *USBD_HID_GetHSCfgDesc(uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_HID_OtherSpeedCfgDesc);
|
||||
*length = (uint16_t)sizeof(USBD_HID_OtherSpeedCfgDesc);
|
||||
|
||||
return USBD_HID_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
@@ -641,26 +657,27 @@ static uint8_t *USBD_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
UNUSED(epnum);
|
||||
/* 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 */
|
||||
((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE;
|
||||
return USBD_OK;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length)
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_HID_DeviceQualifierDesc);
|
||||
*length = (uint16_t)sizeof(USBD_HID_DeviceQualifierDesc);
|
||||
|
||||
return USBD_HID_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
@@ -678,4 +695,3 @@ static uint8_t *USBD_HID_GetDeviceQualifierDesc(uint16_t *length)
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -86,7 +85,7 @@ typedef struct
|
||||
uint32_t interface;
|
||||
uint8_t bot_state;
|
||||
uint8_t bot_status;
|
||||
uint16_t bot_data_length;
|
||||
uint32_t bot_data_length;
|
||||
uint8_t bot_data[MSC_MEDIA_PACKET];
|
||||
USBD_MSC_BOT_CBWTypeDef cbw;
|
||||
USBD_MSC_BOT_CSWTypeDef csw;
|
||||
@@ -94,6 +93,7 @@ typedef struct
|
||||
USBD_SCSI_SenseTypeDef scsi_sense [SENSE_LIST_DEEPTH];
|
||||
uint8_t scsi_sense_head;
|
||||
uint8_t scsi_sense_tail;
|
||||
uint8_t scsi_medium_state;
|
||||
|
||||
uint16_t scsi_blk_size;
|
||||
uint32_t scsi_blk_nbr;
|
||||
@@ -125,5 +125,3 @@ uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev,
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -144,7 +143,6 @@ void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev,
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -40,10 +39,11 @@ extern "C" {
|
||||
/** @defgroup USB_INFO_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define MODE_SENSE6_LEN 8U
|
||||
#define MODE_SENSE10_LEN 8U
|
||||
#define LENGTH_INQUIRY_PAGE00 7U
|
||||
#define LENGTH_FORMAT_CAPACITIES 20U
|
||||
#define MODE_SENSE6_LEN 0x17U
|
||||
#define MODE_SENSE10_LEN 0x1BU
|
||||
#define LENGTH_INQUIRY_PAGE00 0x06U
|
||||
#define LENGTH_INQUIRY_PAGE80 0x08U
|
||||
#define LENGTH_FORMAT_CAPACITIES 0x14U
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -70,9 +70,10 @@ extern "C" {
|
||||
/** @defgroup USBD_INFO_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
extern const uint8_t MSC_Page00_Inquiry_Data[];
|
||||
extern const uint8_t MSC_Mode_Sense6_data[];
|
||||
extern const uint8_t MSC_Mode_Sense10_data[] ;
|
||||
extern uint8_t MSC_Page00_Inquiry_Data[LENGTH_INQUIRY_PAGE00];
|
||||
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_Sense10_data[MODE_SENSE10_LEN];
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -97,7 +98,5 @@ extern const uint8_t MSC_Mode_Sense10_data[] ;
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -103,20 +102,13 @@ extern "C" {
|
||||
|
||||
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0CU
|
||||
#define READ_CAPACITY10_DATA_LEN 0x08U
|
||||
#define MODE_SENSE10_DATA_LEN 0x08U
|
||||
#define MODE_SENSE6_DATA_LEN 0x04U
|
||||
#define REQUEST_SENSE_DATA_LEN 0x12U
|
||||
#define STANDARD_INQUIRY_DATA_LEN 0x24U
|
||||
#define BLKVFY 0x04U
|
||||
|
||||
extern uint8_t Page00_Inquiry_Data[];
|
||||
extern uint8_t Standard_Inquiry_Data[];
|
||||
extern uint8_t Standard_Inquiry_Data2[];
|
||||
extern uint8_t Mode_Sense6_data[];
|
||||
extern uint8_t Mode_Sense10_data[];
|
||||
extern uint8_t Scsi_Sense_Data[];
|
||||
extern uint8_t ReadCapacity10_Data[];
|
||||
extern uint8_t ReadFormatCapacity_Data [];
|
||||
#define SCSI_MEDIUM_UNLOCKED 0x00U
|
||||
#define SCSI_MEDIUM_LOCKED 0x01U
|
||||
#define SCSI_MEDIUM_EJECTED 0x02U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -128,16 +120,16 @@ extern uint8_t ReadFormatCapacity_Data [];
|
||||
|
||||
typedef struct _SENSE_ITEM
|
||||
{
|
||||
char Skey;
|
||||
uint8_t Skey;
|
||||
union
|
||||
{
|
||||
struct _ASCs
|
||||
{
|
||||
char ASC;
|
||||
char ASCQ;
|
||||
uint8_t ASC;
|
||||
uint8_t ASCQ;
|
||||
} b;
|
||||
uint8_t ASC;
|
||||
char *pData;
|
||||
uint8_t *pData;
|
||||
} w;
|
||||
} USBD_SCSI_SenseTypeDef;
|
||||
/**
|
||||
@@ -185,8 +177,6 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey,
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -92,6 +91,6 @@ extern USBD_StorageTypeDef USBD_MSC_Template_fops;
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
@@ -4,6 +4,17 @@
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides all the MSC core functions.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2015 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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
@@ -19,17 +30,6 @@
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
@@ -80,16 +80,16 @@ EndBSPDependencies */
|
||||
/** @defgroup MSC_CORE_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
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_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
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_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -121,134 +121,145 @@ USBD_ClassTypeDef USBD_MSC =
|
||||
|
||||
/* USB Mass storage device Configuration Descriptor */
|
||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
||||
__ALIGN_BEGIN uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
__ALIGN_BEGIN static uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
|
||||
0x09, /* bLength: Configuation Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
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: */
|
||||
0xC0, /* bmAttributes: */
|
||||
0x32, /* MaxPower 100 mA */
|
||||
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: */
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
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*/
|
||||
0x00 /* Polling interval in milliseconds */
|
||||
};
|
||||
|
||||
/* USB Mass storage device Configuration Descriptor */
|
||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
||||
__ALIGN_BEGIN uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuation Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
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: */
|
||||
0xC0, /* bmAttributes: */
|
||||
0x32, /* MaxPower 100 mA */
|
||||
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: */
|
||||
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 */
|
||||
0x07, /* Endpoint descriptor length = 7 */
|
||||
0x05, /* Endpoint descriptor type */
|
||||
MSC_EPIN_ADDR, /* Endpoint address (IN, address 1) */
|
||||
0x02, /* Bulk endpoint type */
|
||||
LOBYTE(MSC_MAX_FS_PACKET),
|
||||
HIBYTE(MSC_MAX_FS_PACKET),
|
||||
0x00, /*Polling interval in milliseconds */
|
||||
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 */
|
||||
0x07, /* Endpoint descriptor length = 7 */
|
||||
0x05, /* Endpoint descriptor type */
|
||||
MSC_EPOUT_ADDR, /* Endpoint address (OUT, address 1) */
|
||||
0x02, /* Bulk endpoint type */
|
||||
LOBYTE(MSC_MAX_FS_PACKET),
|
||||
HIBYTE(MSC_MAX_FS_PACKET),
|
||||
0x00 /*Polling interval in milliseconds*/
|
||||
0x00 /* Polling interval in milliseconds */
|
||||
};
|
||||
|
||||
__ALIGN_BEGIN uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
__ALIGN_BEGIN static uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuation Descriptor size */
|
||||
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: */
|
||||
0xC0, /* bmAttributes: */
|
||||
0x32, /* MaxPower 100 mA */
|
||||
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: */
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
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*/
|
||||
0x00 /* Polling interval in milliseconds */
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN 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 =
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
@@ -279,82 +290,95 @@ __ALIGN_BEGIN uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC]
|
||||
*/
|
||||
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc;
|
||||
|
||||
hmsc = (USBD_MSC_BOT_HandleTypeDef *)USBD_malloc(sizeof(USBD_MSC_BOT_HandleTypeDef));
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
pdev->pClassData = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
pdev->pClassData = (void *)hmsc;
|
||||
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
||||
(void)USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
||||
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
||||
(void)USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_HS_PACKET);
|
||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
||||
(void)USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
||||
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
||||
(void)USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK, MSC_MAX_FS_PACKET);
|
||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
}
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_MSC_BOT_HandleTypeDef));
|
||||
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Init the BOT layer */
|
||||
MSC_BOT_Init(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MSC_DeInit
|
||||
* DeInitilaize the mass storage configuration
|
||||
* DeInitialize the mass storage configuration
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
/* Close MSC EPs */
|
||||
USBD_LL_CloseEP(pdev, MSC_EPOUT_ADDR);
|
||||
(void)USBD_LL_CloseEP(pdev, MSC_EPOUT_ADDR);
|
||||
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP IN */
|
||||
USBD_LL_CloseEP(pdev, MSC_EPIN_ADDR);
|
||||
(void)USBD_LL_CloseEP(pdev, MSC_EPIN_ADDR);
|
||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||
|
||||
/* De-Init the BOT layer */
|
||||
MSC_BOT_DeInit(pdev);
|
||||
|
||||
/* Free MSC Class Resources */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
/* De-Init the BOT layer */
|
||||
MSC_BOT_DeInit(pdev);
|
||||
|
||||
(void)USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_MSC_Setup
|
||||
* Handle the MSC specific requests
|
||||
* @param pdev: device instance
|
||||
* @param req: USB request
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_MSC_Setup
|
||||
* Handle the MSC specific requests
|
||||
* @param pdev: device instance
|
||||
* @param req: USB request
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
uint8_t ret = USBD_OK;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
uint16_t status_info = 0U;
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
/* Class request */
|
||||
@@ -366,7 +390,7 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
((req->bmRequest & 0x80U) == 0x80U))
|
||||
{
|
||||
hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun();
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hmsc->max_lun, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->max_lun, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -401,7 +425,7 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -413,7 +437,7 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&hmsc->interface, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmsc->interface, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -435,49 +459,17 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
|
||||
/* Flush the FIFO and Clear the stall status */
|
||||
USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex);
|
||||
|
||||
/* Reactivate the EP */
|
||||
USBD_LL_CloseEP(pdev, (uint8_t)req->wIndex);
|
||||
if ((((uint8_t)req->wIndex) & 0x80U) == 0x80U)
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
pdev->ep_in[(uint8_t)req->wIndex & 0xFU].is_used = 0U;
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
if (req->wValue == USB_FEATURE_EP_HALT)
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_HS_PACKET);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_FS_PACKET);
|
||||
}
|
||||
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
pdev->ep_out[(uint8_t)req->wIndex & 0xFU].is_used = 0U;
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_HS_PACKET);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, MSC_EPOUT_ADDR, USBD_EP_TYPE_BULK,
|
||||
MSC_MAX_FS_PACKET);
|
||||
}
|
||||
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||
}
|
||||
/* Flush the FIFO */
|
||||
(void)USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex);
|
||||
|
||||
/* Handle BOT error */
|
||||
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
|
||||
/* Handle BOT error */
|
||||
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -493,102 +485,103 @@ uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MSC_DataIn
|
||||
* handle data IN Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_MSC_DataIn
|
||||
* handle data IN Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
MSC_BOT_DataIn(pdev, epnum);
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MSC_DataOut
|
||||
* handle data OUT Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_MSC_DataOut
|
||||
* handle data OUT Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
MSC_BOT_DataOut(pdev, epnum);
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MSC_GetHSCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
* @brief USBD_MSC_GetHSCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_MSC_CfgHSDesc);
|
||||
*length = (uint16_t)sizeof(USBD_MSC_CfgHSDesc);
|
||||
|
||||
return USBD_MSC_CfgHSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MSC_GetFSCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
* @brief USBD_MSC_GetFSCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_MSC_CfgFSDesc);
|
||||
*length = (uint16_t)sizeof(USBD_MSC_CfgFSDesc);
|
||||
|
||||
return USBD_MSC_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MSC_GetOtherSpeedCfgDesc
|
||||
* return other speed configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
* @brief USBD_MSC_GetOtherSpeedCfgDesc
|
||||
* return other speed configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_MSC_OtherSpeedCfgDesc);
|
||||
*length = (uint16_t)sizeof(USBD_MSC_OtherSpeedCfgDesc);
|
||||
|
||||
return USBD_MSC_OtherSpeedCfgDesc;
|
||||
}
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_MSC_DeviceQualifierDesc);
|
||||
*length = (uint16_t)sizeof(USBD_MSC_DeviceQualifierDesc);
|
||||
|
||||
return USBD_MSC_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MSC_RegisterStorage
|
||||
* @param fops: storage callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev,
|
||||
USBD_StorageTypeDef *fops)
|
||||
* @brief USBD_MSC_RegisterStorage
|
||||
* @param fops: storage callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, USBD_StorageTypeDef *fops)
|
||||
{
|
||||
if (fops != NULL)
|
||||
if (fops == NULL)
|
||||
{
|
||||
pdev->pUserData = fops;
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
pdev->pUserData = fops;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -605,4 +598,3 @@ uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev,
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -76,11 +75,9 @@ EndBSPDependencies */
|
||||
/** @defgroup MSC_BOT_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev);
|
||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len);
|
||||
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev);
|
||||
static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -91,74 +88,97 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief MSC_BOT_Init
|
||||
* Initialize the BOT Process
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_Init(USBD_HandleTypeDef *pdev)
|
||||
* @brief MSC_BOT_Init
|
||||
* Initialize the BOT Process
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
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->pClassData;
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
||||
|
||||
hmsc->scsi_sense_tail = 0U;
|
||||
hmsc->scsi_sense_head = 0U;
|
||||
hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED;
|
||||
|
||||
((USBD_StorageTypeDef *)pdev->pUserData)->Init(0U);
|
||||
|
||||
USBD_LL_FlushEP(pdev, MSC_EPOUT_ADDR);
|
||||
USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR);
|
||||
(void)USBD_LL_FlushEP(pdev, MSC_EPOUT_ADDR);
|
||||
(void)USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR);
|
||||
|
||||
/* Prapare EP to Receive First BOT Cmd */
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
/* Prepare EP to Receive First BOT Cmd */
|
||||
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MSC_BOT_Reset
|
||||
* Reset the BOT Machine
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev)
|
||||
* @brief MSC_BOT_Reset
|
||||
* Reset the BOT Machine
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
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->pClassData;
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
|
||||
|
||||
/* Prapare EP to Receive First BOT Cmd */
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
(void)USBD_LL_ClearStallEP(pdev, MSC_EPIN_ADDR);
|
||||
(void)USBD_LL_ClearStallEP(pdev, MSC_EPOUT_ADDR);
|
||||
|
||||
/* Prepare EP to Receive First BOT Cmd */
|
||||
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MSC_BOT_DeInit
|
||||
* Deinitialize the BOT Machine
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
* @brief MSC_BOT_DeInit
|
||||
* DeInitialize the BOT Machine
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (hmsc != NULL)
|
||||
{
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MSC_BOT_DataIn
|
||||
* Handle BOT IN data stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
* @brief MSC_BOT_DataIn
|
||||
* Handle BOT IN data stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
UNUSED(epnum);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (hmsc->bot_state)
|
||||
{
|
||||
@@ -179,16 +199,22 @@ void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief MSC_BOT_DataOut
|
||||
* Process MSC OUT data
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
* @brief MSC_BOT_DataOut
|
||||
* Process MSC OUT data
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
UNUSED(epnum);
|
||||
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (hmsc->bot_state)
|
||||
{
|
||||
@@ -197,7 +223,6 @@ void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
|
||||
case USBD_BOT_DATA_OUT:
|
||||
|
||||
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||
{
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||
@@ -210,24 +235,28 @@ void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MSC_BOT_CBW_Decode
|
||||
* Decode the CBW command and set the BOT state machine accordingly
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev)
|
||||
* @brief MSC_BOT_CBW_Decode
|
||||
* Decode the CBW command and set the BOT state machine accordingly
|
||||
* @param pdev: device instance
|
||||
* @retval None
|
||||
*/
|
||||
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->pClassData;
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hmsc->csw.dTag = hmsc->cbw.dTag;
|
||||
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
|
||||
|
||||
if ((USBD_LL_GetRxDataSize(pdev, MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) ||
|
||||
(hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) ||
|
||||
(hmsc->cbw.bLUN > 1U) ||
|
||||
(hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U))
|
||||
(hmsc->cbw.bLUN > 1U) || (hmsc->cbw.bCBLength < 1U) ||
|
||||
(hmsc->cbw.bCBLength > 16U))
|
||||
{
|
||||
|
||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
||||
|
||||
hmsc->bot_status = USBD_BOT_STATUS_ERROR;
|
||||
@@ -246,7 +275,7 @@ static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev)
|
||||
MSC_BOT_Abort(pdev);
|
||||
}
|
||||
}
|
||||
/*Burst xfer handled internally*/
|
||||
/* Burst xfer handled internally */
|
||||
else if ((hmsc->bot_state != USBD_BOT_DATA_IN) &&
|
||||
(hmsc->bot_state != USBD_BOT_DATA_OUT) &&
|
||||
(hmsc->bot_state != USBD_BOT_LAST_DATA_IN))
|
||||
@@ -272,94 +301,112 @@ static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MSC_BOT_SendData
|
||||
* Send the requested data
|
||||
* @param pdev: device instance
|
||||
* @param buf: pointer to data buffer
|
||||
* @param len: Data Length
|
||||
* @retval None
|
||||
*/
|
||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
||||
uint16_t len)
|
||||
* @brief MSC_BOT_SendData
|
||||
* Send the requested data
|
||||
* @param pdev: device instance
|
||||
* @param buf: pointer to data buffer
|
||||
* @param len: Data Length
|
||||
* @retval None
|
||||
*/
|
||||
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->pClassData;
|
||||
|
||||
uint16_t length = (uint16_t)MIN(hmsc->cbw.dDataLength, len);
|
||||
uint32_t length = MIN(hmsc->cbw.dDataLength, len);
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hmsc->csw.dDataResidue -= len;
|
||||
hmsc->csw.bStatus = USBD_CSW_CMD_PASSED;
|
||||
hmsc->bot_state = USBD_BOT_SEND_DATA;
|
||||
|
||||
USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, pbuf, length);
|
||||
(void)USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, pbuf, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MSC_BOT_SendCSW
|
||||
* Send the Command Status Wrapper
|
||||
* @param pdev: device instance
|
||||
* @param status : CSW status
|
||||
* @retval None
|
||||
*/
|
||||
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev,
|
||||
uint8_t CSW_Status)
|
||||
* @brief MSC_BOT_SendCSW
|
||||
* Send the Command Status Wrapper
|
||||
* @param pdev: device instance
|
||||
* @param status : CSW status
|
||||
* @retval None
|
||||
*/
|
||||
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->pClassData;
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE;
|
||||
hmsc->csw.bStatus = CSW_Status;
|
||||
hmsc->bot_state = USBD_BOT_IDLE;
|
||||
|
||||
USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, (uint8_t *)(void *)&hmsc->csw,
|
||||
USBD_BOT_CSW_LENGTH);
|
||||
(void)USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, (uint8_t *)&hmsc->csw,
|
||||
USBD_BOT_CSW_LENGTH);
|
||||
|
||||
/* Prepare EP to Receive next Cmd */
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MSC_BOT_Abort
|
||||
* Abort the current transfer
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief MSC_BOT_Abort
|
||||
* Abort the current transfer
|
||||
* @param pdev: device instance
|
||||
* @retval 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->pClassData;
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((hmsc->cbw.bmFlags == 0U) &&
|
||||
(hmsc->cbw.dDataLength != 0U) &&
|
||||
(hmsc->bot_status == USBD_BOT_STATUS_NORMAL))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR);
|
||||
(void)USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR);
|
||||
}
|
||||
|
||||
USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
||||
(void)USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
||||
|
||||
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR)
|
||||
{
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
||||
USBD_BOT_CBW_LENGTH);
|
||||
(void)USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
||||
(void)USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MSC_BOT_CplClrFeature
|
||||
* Complete the clear feature request
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval None
|
||||
*/
|
||||
* @brief MSC_BOT_CplClrFeature
|
||||
* Complete the clear feature request
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
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->pClassData;
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) /* Bad CBW Signature */
|
||||
{
|
||||
USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
||||
(void)USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
||||
(void)USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR);
|
||||
}
|
||||
else if (((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY))
|
||||
{
|
||||
@@ -384,4 +431,3 @@ void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -65,21 +64,48 @@ EndBSPDependencies */
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* USB Mass storage Page 0 Inquiry Data */
|
||||
const uint8_t MSC_Page00_Inquiry_Data[] =
|
||||
uint8_t MSC_Page00_Inquiry_Data[LENGTH_INQUIRY_PAGE00] =
|
||||
{
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
(LENGTH_INQUIRY_PAGE00 - 4U),
|
||||
0x00,
|
||||
0x80,
|
||||
0x83
|
||||
0x80
|
||||
};
|
||||
/* USB Mass storage sense 6 Data */
|
||||
const uint8_t MSC_Mode_Sense6_data[] =
|
||||
|
||||
/* USB Mass storage VPD Page 0x80 Inquiry Data for Unit Serial Number */
|
||||
uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80] =
|
||||
{
|
||||
0x00,
|
||||
0x80,
|
||||
0x00,
|
||||
LENGTH_INQUIRY_PAGE80,
|
||||
0x20, /* Put Product Serial number */
|
||||
0x20,
|
||||
0x20,
|
||||
0x20
|
||||
};
|
||||
|
||||
/* USB Mass storage sense 6 Data */
|
||||
uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN] =
|
||||
{
|
||||
0x22,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x08,
|
||||
0x12,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
@@ -89,11 +115,32 @@ const uint8_t MSC_Mode_Sense6_data[] =
|
||||
0x00,
|
||||
0x00
|
||||
};
|
||||
|
||||
|
||||
/* USB Mass storage sense 10 Data */
|
||||
const uint8_t MSC_Mode_Sense10_data[] =
|
||||
uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN] =
|
||||
{
|
||||
0x00,
|
||||
0x06,
|
||||
0x26,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x08,
|
||||
0x12,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
@@ -132,4 +179,3 @@ const uint8_t MSC_Mode_Sense10_data[] =
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -88,24 +87,24 @@ USBD_StorageTypeDef USBD_MSC_Template_fops =
|
||||
|
||||
};
|
||||
/*******************************************************************************
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the microSD card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the microSD card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_Init(uint8_t lun)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
||||
{
|
||||
*block_num = STORAGE_BLK_NBR;
|
||||
@@ -114,64 +113,63 @@ int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_siz
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_IsReady(uint8_t lun)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_IsWriteProtected(uint8_t lun)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
* Function Name : Read_Memory
|
||||
* Description : Handle the Read operation from the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf,
|
||||
uint32_t blk_addr, uint16_t blk_len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : Write_Memory
|
||||
* Description : Handle the Write operation to the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
* Function Name : Write_Memory
|
||||
* Description : Handle the Write operation to the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf,
|
||||
uint32_t blk_addr, uint16_t blk_len)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Function Name : Write_Memory
|
||||
* Description : Handle the Write operation to the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
* Function Name : Write_Memory
|
||||
* Description : Handle the Write operation to the STORAGE card.
|
||||
* Input : None.
|
||||
* Output : None.
|
||||
* Return : None.
|
||||
*******************************************************************************/
|
||||
int8_t STORAGE_GetMaxLun(void)
|
||||
{
|
||||
return (STORAGE_LUN_NBR - 1);
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
348
Class/MTP/Inc/usbd_mtp.h
Normal file
348
Class/MTP/Inc/usbd_mtp.h
Normal file
@@ -0,0 +1,348 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_mtp.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 __USB_MTP_H
|
||||
#define __USB_MTP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP
|
||||
* @brief This file is the header file for usbd_mtp.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define MTP_IN_EP 0x81U /* EP1 for data IN */
|
||||
#define MTP_OUT_EP 0x01U /* EP1 for data OUT */
|
||||
#define MTP_CMD_EP 0x82U /* EP2 for MTP commands */
|
||||
|
||||
#ifndef MTP_CMD_ITF_NBR
|
||||
#define MTP_CMD_ITF_NBR 0x00U /* Command Interface Number 0 */
|
||||
#endif /* MTP_CMD_ITF_NBR */
|
||||
|
||||
#ifndef MTP_COM_ITF_NBR
|
||||
#define MTP_COM_ITF_NBR 0x01U /* Communication Interface Number 0 */
|
||||
#endif /* MTP_CMD_ITF_NBR */
|
||||
|
||||
#ifndef MTP_HS_BINTERVAL
|
||||
#define MTP_HS_BINTERVAL 0x10U
|
||||
#endif /* MTP_HS_BINTERVAL */
|
||||
|
||||
#ifndef MTP_FS_BINTERVAL
|
||||
#define MTP_FS_BINTERVAL 0x10U
|
||||
#endif /* MTP_FS_BINTERVAL */
|
||||
|
||||
#define MTP_DATA_MAX_HS_PACKET_SIZE 512U
|
||||
#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_CONT_HEADER_SIZE 12U
|
||||
|
||||
#define MTP_CONFIG_DESC_SIZ 39U
|
||||
#define MTP_INTERFACE_DESC_SIZE 0x09U
|
||||
#define USB_MTP_INTRERFACE_CLASS 0x06U
|
||||
#define USB_MTP_INTRERFACE_SUB_CLASS 0x01U
|
||||
#define USB_MTP_INTRERFACE_PROTOCOL 0x01U
|
||||
#define MTP_ENDPOINT_DESC_SIZE 0x07U
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* MTP definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
/* MTP class requests */
|
||||
#define MTP_REQ_CANCEL 0x64U
|
||||
#define MTP_REQ_GET_EXT_EVENT_DATA 0x65U
|
||||
#define MTP_REQ_RESET 0x66U
|
||||
#define MTP_REQ_GET_DEVICE_STATUS 0x67U
|
||||
|
||||
|
||||
/* Max info items size */
|
||||
#define MTP_SUPPORTED_OPERATIONS_NBR 100U
|
||||
#define MTP_SUPPORTED_EVENTS_NBR 100U
|
||||
#define MTP_SUPPORTED_PROPRIETIES_NBR 100U
|
||||
#define MTP_CAPTURE_FORMATS_NBR 100U
|
||||
#define MTP_IMAGE_FORMATS_NBR 100U
|
||||
#define MTP_MAX_STR_SIZE 255U
|
||||
|
||||
/* MTP response code */
|
||||
#define MTP_RESPONSE_OK 0x2001U
|
||||
#define MTP_RESPONSE_GENERAL_ERROR 0x2002U
|
||||
#define MTP_RESPONSE_PARAMETER_NOT_SUPPORTED 0x2006U
|
||||
#define MTP_RESPONSE_INCOMPLETE_TRANSFER 0x2007U
|
||||
#define MTP_RESPONSE_INVALID_STORAGE_ID 0x2008U
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_HANDLE 0x2009U
|
||||
#define MTP_RESPONSE_DEVICEPROP_NOT_SUPPORTED 0x200AU
|
||||
#define MTP_RESPONSE_STORE_FULL 0x200CU
|
||||
#define MTP_RESPONSE_ACCESS_DENIED 0x200FU
|
||||
#define MTP_RESPONSE_STORE_NOT_AVAILABLE 0x2013U
|
||||
#define MTP_RESPONSE_SPECIFICATION_BY_FORMAT_NOT_SUPPORTED 0x2014U
|
||||
#define MTP_RESPONSE_NO_VALID_OBJECT_INFO 0x2015U
|
||||
#define MTP_RESPONSE_DEVICE_BUSY 0x2019U
|
||||
#define MTP_RESPONSE_INVALID_PARENT_OBJECT 0x201AU
|
||||
#define MTP_RESPONSE_INVALID_PARAMETER 0x201DU
|
||||
#define MTP_RESPONSE_SESSION_ALREADY_OPEN 0x201EU
|
||||
#define MTP_RESPONSE_TRANSACTION_CANCELLED 0x201FU
|
||||
#define MTP_RESPONSE_INVALID_OBJECT_PROP_CODE 0xA801U
|
||||
#define MTP_RESPONSE_SPECIFICATION_BY_GROUP_UNSUPPORTED 0xA807U
|
||||
#define MTP_RESPONSE_OBJECT_PROP_NOT_SUPPORTED 0xA80AU
|
||||
|
||||
/* MTP Object format codes */
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED 0x3000U
|
||||
#define MTP_OBJ_FORMAT_ASSOCIATION 0x3001U
|
||||
#define MTP_OBJ_FORMAT_SCRIPT 0x3002U
|
||||
#define MTP_OBJ_FORMAT_EXECUTABLE 0x3003U
|
||||
#define MTP_OBJ_FORMAT_TEXT 0x3004U
|
||||
#define MTP_OBJ_FORMAT_HTML 0x3005U
|
||||
#define MTP_OBJ_FORMAT_DPOF 0x3006U
|
||||
#define MTP_OBJ_FORMAT_AIFF 0x3007U
|
||||
#define MTP_OBJ_FORMAT_WAV 0x3008U
|
||||
#define MTP_OBJ_FORMAT_MP3 0x3009U
|
||||
#define MTP_OBJ_FORMAT_AVI 0x300AU
|
||||
#define MTP_OBJ_FORMAT_MPEG 0x300BU
|
||||
#define MTP_OBJ_FORMAT_ASF 0x300CU
|
||||
#define MTP_OBJ_FORMAT_DEFINED 0x3800U
|
||||
#define MTP_OBJ_FORMAT_EXIF_JPEG 0x3801U
|
||||
#define MTP_OBJ_FORMAT_TIFF_EP 0x3802U
|
||||
#define MTP_OBJ_FORMAT_FLASHPIX 0x3803U
|
||||
#define MTP_OBJ_FORMAT_BMP 0x3804U
|
||||
#define MTP_OBJ_FORMAT_CIFF 0x3805U
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_RESERVED0 0x3806U
|
||||
#define MTP_OBJ_FORMAT_GIF 0x3807U
|
||||
#define MTP_OBJ_FORMAT_JFIF 0x3808U
|
||||
#define MTP_OBJ_FORMAT_CD 0x3809U
|
||||
#define MTP_OBJ_FORMAT_PICT 0x380AU
|
||||
#define MTP_OBJ_FORMAT_PNG 0x380BU
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_RESERVED1 0x380CU
|
||||
#define MTP_OBJ_FORMAT_TIFF 0x380DU
|
||||
#define MTP_OBJ_FORMAT_TIFF_IT 0x380EU
|
||||
#define MTP_OBJ_FORMAT_JP2 0x380FU
|
||||
#define MTP_OBJ_FORMAT_JPX 0x3810U
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_FIRMWARE 0xB802U
|
||||
#define MTP_OBJ_FORMAT_WINDOWS_IMAGE_FORMAT 0xB881U
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_AUDIO 0xB900U
|
||||
#define MTP_OBJ_FORMAT_WMA 0xB901U
|
||||
#define MTP_OBJ_FORMAT_OGG 0xB902U
|
||||
#define MTP_OBJ_FORMAT_AAC 0xB903U
|
||||
#define MTP_OBJ_FORMAT_AUDIBLE 0xB904U
|
||||
#define MTP_OBJ_FORMAT_FLAC 0xB906U
|
||||
#define MTP_OBJ_FORMAT_UNDEFINED_VIDEO 0xB980U
|
||||
#define MTP_OBJ_FORMAT_WMV 0xB981U
|
||||
#define MTP_OBJ_FORMAT_MP4_CONTAINER 0xB982U
|
||||
#define MTP_OBJ_FORMAT_MP2 0xB983U
|
||||
#define MTP_OBJ_FORMAT_3GP_CONTAINER 0xB984U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/* MTP Session state */
|
||||
typedef enum
|
||||
{
|
||||
MTP_SESSION_NOT_OPENED = 0x00,
|
||||
MTP_SESSION_OPENED = 0x01,
|
||||
} MTP_SessionStateTypeDef;
|
||||
|
||||
/* MTP response phases */
|
||||
typedef enum
|
||||
{
|
||||
MTP_PHASE_IDLE = 0x00,
|
||||
MTP_RESPONSE_PHASE = 0x01,
|
||||
MTP_READ_DATA = 0x02,
|
||||
MTP_RECEIVE_DATA = 0x03,
|
||||
} MTP_ResponsePhaseTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t temp_length;
|
||||
uint32_t prv_len;
|
||||
uint32_t totallen;
|
||||
uint32_t rx_length;
|
||||
uint32_t readbytes; /* File write/read counts */
|
||||
} MTP_DataLengthTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RECEIVE_IDLE_STATE = 0x00U,
|
||||
RECEIVE_COMMAND_DATA = 0x01U,
|
||||
RECEIVE_FIRST_DATA = 0x02U,
|
||||
RECEIVE_REST_OF_DATA = 0x03U,
|
||||
SEND_RESPONSE = 0x04U,
|
||||
} MTP_RECEIVE_DATA_STATUS;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t length;
|
||||
uint16_t type;
|
||||
uint16_t code;
|
||||
uint32_t trans_id;
|
||||
uint32_t Param1;
|
||||
uint32_t Param2;
|
||||
uint32_t Param3;
|
||||
uint32_t Param4;
|
||||
uint32_t Param5;
|
||||
} MTP_OperationsTypedef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t length;
|
||||
uint16_t type;
|
||||
uint16_t code;
|
||||
uint32_t trans_id;
|
||||
uint8_t data[MTP_MEDIA_PACKET];
|
||||
} MTP_GenericContainerTypeDef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t Storage_id;
|
||||
uint16_t ObjectFormat;
|
||||
uint16_t ProtectionStatus;
|
||||
uint32_t ObjectCompressedSize;
|
||||
uint16_t ThumbFormat;
|
||||
uint32_t ThumbCompressedSize;
|
||||
uint32_t ThumbPixWidth;
|
||||
uint32_t ThumbPixHeight;
|
||||
uint32_t ImagePixWidth;
|
||||
uint32_t ImagePixHeight;
|
||||
uint32_t ImageBitDepth;
|
||||
uint32_t ParentObject;
|
||||
uint16_t AssociationType;
|
||||
uint32_t AssociationDesc;
|
||||
uint32_t SequenceNumber;
|
||||
uint8_t Filename_len;
|
||||
uint16_t Filename[255];
|
||||
uint32_t CaptureDate;
|
||||
uint32_t ModificationDate;
|
||||
uint8_t Keywords;
|
||||
} MTP_ObjectInfoTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t alt_setting;
|
||||
uint32_t dev_status;
|
||||
uint32_t ResponseLength;
|
||||
uint32_t ResponseCode;
|
||||
__IO uint16_t MaxPcktLen;
|
||||
uint32_t rx_buff[MTP_MEDIA_PACKET / 4U]; /* Force 32-bit alignment */
|
||||
MTP_ResponsePhaseTypeDef MTP_ResponsePhase;
|
||||
MTP_SessionStateTypeDef MTP_SessionState;
|
||||
MTP_RECEIVE_DATA_STATUS RECEIVE_DATA_STATUS;
|
||||
MTP_OperationsTypedef OperationsContainer;
|
||||
MTP_GenericContainerTypeDef GenericContainer;
|
||||
} USBD_MTP_HandleTypeDef;
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_MTP;
|
||||
#define USBD_MTP_CLASS &USBD_MTP
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct _USBD_MTP_ItfTypeDef
|
||||
{
|
||||
uint8_t (*Init)(void);
|
||||
uint8_t (*DeInit)(void);
|
||||
uint32_t (*ReadData)(uint32_t Param1, uint8_t *buff, MTP_DataLengthTypeDef *data_length);
|
||||
uint16_t (*Create_NewObject)(MTP_ObjectInfoTypeDef ObjectInfo, uint32_t objhandle);
|
||||
|
||||
uint32_t (*GetIdx)(uint32_t Param3, uint32_t *obj_handle);
|
||||
uint32_t (*GetParentObject)(uint32_t Param);
|
||||
uint16_t (*GetObjectFormat)(uint32_t Param);
|
||||
uint8_t (*GetObjectName_len)(uint32_t Param);
|
||||
void (*GetObjectName)(uint32_t Param, uint8_t obj_len, uint16_t *buf);
|
||||
uint32_t (*GetObjectSize)(uint32_t Param);
|
||||
uint64_t (*GetMaxCapability)(void);
|
||||
uint64_t (*GetFreeSpaceInBytes)(void);
|
||||
uint32_t (*GetNewIndex)(uint16_t objformat);
|
||||
void (*WriteData)(uint16_t len, uint8_t buff[]);
|
||||
uint32_t (*GetContainerLength)(uint32_t Param1);
|
||||
uint16_t (*DeleteObject)(uint32_t Param1);
|
||||
void (*Cancel)(uint32_t Phase);
|
||||
uint32_t *ScratchBuff;
|
||||
uint32_t ScratchBuffSze;
|
||||
} USBD_MTP_ItfTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_MTP_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_MTP_ItfTypeDef *fops);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_MTP_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
95
Class/MTP/Inc/usbd_mtp_if_template.h
Normal file
95
Class/MTP/Inc/usbd_mtp_if_template.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_if_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for the usbd_mtp_if_template.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_MTP_IF_TEMPLATE_H
|
||||
#define __USBD_MTP_IF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_mtp.h"
|
||||
|
||||
/* Exported Define -----------------------------------------------------------*/
|
||||
#define USBD_MTP_DEVICE_PROP_SUPPORTED 1U
|
||||
#define USBD_MTP_CAPTURE_FORMAT_SUPPORTED 1U
|
||||
#define USBD_MTP_VEND_EXT_DESC_SUPPORTED 1U
|
||||
#define USBD_MTP_EVENTS_SUPPORTED 1U
|
||||
|
||||
#if USBD_MTP_EVENTS_SUPPORTED == 1
|
||||
#define SUPP_EVENTS_LEN (uint8_t)((uint8_t)sizeof(SuppEvents) / 2U)
|
||||
#else
|
||||
#define SUPP_EVENTS_LEN 0U
|
||||
#endif
|
||||
|
||||
#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1
|
||||
#define VEND_EXT_DESC_LEN (sizeof(VendExtDesc) / 2U)
|
||||
#else
|
||||
#define VEND_EXT_DESC_LEN 0U
|
||||
#endif
|
||||
|
||||
#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1
|
||||
#define SUPP_CAPT_FORMAT_LEN (uint8_t)((uint8_t)sizeof(SuppCaptFormat) / 2U)
|
||||
#else
|
||||
#define SUPP_CAPT_FORMAT_LEN 0U
|
||||
#endif
|
||||
|
||||
#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1
|
||||
#define SUPP_DEVICE_PROP_LEN (uint8_t)((uint8_t)sizeof(DevicePropSupp) / 2U)
|
||||
#else
|
||||
#define SUPP_DEVICE_PROP_LEN 0U
|
||||
#endif
|
||||
|
||||
#define MTP_IF_SCRATCH_BUFF_SZE 1024U
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
extern USBD_MTP_ItfTypeDef USBD_MTP_fops;
|
||||
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
/* Exported variables --------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
static const uint16_t Manuf[] = {'S', 'T', 'M', 0}; /* last 2 bytes must be 0*/
|
||||
static const uint16_t Model[] = {'S', 'T', 'M', '3', '2', 0}; /* last 2 bytes must be 0*/
|
||||
static const uint16_t VendExtDesc[] = {'m', 'i', 'c', 'r', 'o', 's', 'o', 'f', 't', '.',
|
||||
'c', 'o', 'm', ':', ' ', '1', '.', '0', ';', ' ', 0
|
||||
}; /* last 2 bytes must be 0*/
|
||||
/*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',
|
||||
'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*/
|
||||
static const uint16_t DeviceVers[] = {'V', '1', '.', '0', '0', 0}; /* last 2 bytes must be 0*/
|
||||
|
||||
static const uint16_t DefaultFileName[] = {'N', 'e', 'w', ' ', 'F', 'o', 'l', 'd', 'e', 'r', 0};
|
||||
|
||||
static const uint16_t DevicePropDefVal[] = {'S', 'T', 'M', '3', '2', 0}; /* last 2 bytes must be 0*/
|
||||
static const uint16_t DevicePropCurDefVal[] = {'S', 'T', 'M', '3', '2', ' ', 'V', '1', '.', '0', 0};
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_MTP_IF_TEMPLATE_H */
|
||||
|
||||
658
Class/MTP/Inc/usbd_mtp_opt.h
Normal file
658
Class/MTP/Inc/usbd_mtp_opt.h
Normal file
@@ -0,0 +1,658 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_opt.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_mtp_opt.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_MTP_OPT_H__
|
||||
#define __USBD_MTP_OPT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#ifndef __USBD_MTP_IF_H
|
||||
#include "usbd_mtp_if_template.h"
|
||||
#endif
|
||||
#include "usbd_mtp.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_OPT
|
||||
* @brief This file is the header file for usbd_mtp_opt.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/* MTP OBJECT PROPERTIES supported*/
|
||||
#define MTP_OB_PROP_STORAGE_ID 0xDC01U
|
||||
#define MTP_OB_PROP_OBJECT_FORMAT 0xDC02U
|
||||
#define MTP_OB_PROP_PROTECTION_STATUS 0xDC03U
|
||||
#define MTP_OB_PROP_OBJECT_SIZE 0xDC04U
|
||||
#define MTP_OB_PROP_ASSOC_TYPE 0xDC05U
|
||||
#define MTP_OB_PROP_ASSOC_DESC 0xDC06U
|
||||
#define MTP_OB_PROP_OBJ_FILE_NAME 0xDC07U
|
||||
#define MTP_OB_PROP_DATE_CREATED 0xDC08U
|
||||
#define MTP_OB_PROP_DATE_MODIFIED 0xDC09U
|
||||
#define MTP_OB_PROP_KEYWORDS 0xDC0AU
|
||||
#define MTP_OB_PROP_PARENT_OBJECT 0xDC0BU
|
||||
#define MTP_OB_PROP_ALLOWED_FOLD_CONTENTS 0xDC0CU
|
||||
#define MTP_OB_PROP_HIDDEN 0xDC0DU
|
||||
#define MTP_OB_PROP_SYSTEM_OBJECT 0xDC0EU
|
||||
#define MTP_OB_PROP_PERS_UNIQ_OBJ_IDEN 0xDC41U
|
||||
#define MTP_OB_PROP_SYNCID 0xDC42U
|
||||
#define MTP_OB_PROP_PROPERTY_BAG 0xDC43U
|
||||
#define MTP_OB_PROP_NAME 0xDC44U
|
||||
#define MTP_OB_PROP_CREATED_BY 0xDC45U
|
||||
#define MTP_OB_PROP_ARTIST 0xDC46U
|
||||
#define MTP_OB_PROP_DATE_AUTHORED 0xDC47U
|
||||
#define MTP_OB_PROP_DESCRIPTION 0xDC48U
|
||||
#define MTP_OB_PROP_URL_REFERENCE 0xDC49U
|
||||
#define MTP_OB_PROP_LANGUAGELOCALE 0xDC4AU
|
||||
#define MTP_OB_PROP_COPYRIGHT_INFORMATION 0xDC4BU
|
||||
#define MTP_OB_PROP_SOURCE 0xDC4CU
|
||||
#define MTP_OB_PROP_ORIGIN_LOCATION 0xDC4DU
|
||||
#define MTP_OB_PROP_DATE_ADDED 0xDC4EU
|
||||
#define MTP_OB_PROP_NON_CONSUMABLE 0xDC4FU
|
||||
#define MTP_OB_PROP_CORRUPTUNPLAYABLE 0xDC50U
|
||||
#define MTP_OB_PROP_PRODUCERSERIALNUMBER 0xDC51U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_FORMAT 0xDC81U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_SIZE 0xDC82U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_HEIGHT 0xDC83U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_WIDTH 0xDC84U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_DURATION 0xDC85U
|
||||
#define MTP_OB_PROP_REPRESENTATIVE_SAMPLE_DATA 0xDC86U
|
||||
#define MTP_OB_PROP_WIDTH 0xDC87U
|
||||
#define MTP_OB_PROP_HEIGHT 0xDC88U
|
||||
#define MTP_OB_PROP_DURATION 0xDC89U
|
||||
#define MTP_OB_PROP_RATING 0xDC8AU
|
||||
#define MTP_OB_PROP_TRACK 0xDC8BU
|
||||
#define MTP_OB_PROP_GENRE 0xDC8CU
|
||||
#define MTP_OB_PROP_CREDITS 0xDC8DU
|
||||
#define MTP_OB_PROP_LYRICS 0xDC8EU
|
||||
#define MTP_OB_PROP_SUBSCRIPTION_CONTENT_ID 0xDC8FU
|
||||
#define MTP_OB_PROP_PRODUCED_BY 0xDC90U
|
||||
#define MTP_OB_PROP_USE_COUNT 0xDC91U
|
||||
#define MTP_OB_PROP_SKIP_COUNT 0xDC92U
|
||||
#define MTP_OB_PROP_LAST_ACCESSED 0xDC93U
|
||||
#define MTP_OB_PROP_PARENTAL_RATING 0xDC94U
|
||||
#define MTP_OB_PROP_META_GENRE 0xDC95U
|
||||
#define MTP_OB_PROP_COMPOSER 0xDC96U
|
||||
#define MTP_OB_PROP_EFFECTIVE_RATING 0xDC97U
|
||||
#define MTP_OB_PROP_SUBTITLE 0xDC98U
|
||||
#define MTP_OB_PROP_ORIGINAL_RELEASE_DATE 0xDC99U
|
||||
#define MTP_OB_PROP_ALBUM_NAME 0xDC9AU
|
||||
#define MTP_OB_PROP_ALBUM_ARTIST 0xDC9BU
|
||||
#define MTP_OB_PROP_MOOD 0xDC9CU
|
||||
#define MTP_OB_PROP_DRM_STATUS 0xDC9DU
|
||||
#define MTP_OB_PROP_SUB_DESCRIPTION 0xDC9EU
|
||||
#define MTP_OB_PROP_IS_CROPPED 0xDCD1U
|
||||
#define MTP_OB_PROP_IS_COLOUR_CORRECTED 0xDCD2U
|
||||
#define MTP_OB_PROP_IMAGE_BIT_DEPTH 0xDCD3U
|
||||
#define MTP_OB_PROP_FNUMBER 0xDCD4U
|
||||
#define MTP_OB_PROP_EXPOSURE_TIME 0xDCD5U
|
||||
#define MTP_OB_PROP_EXPOSURE_INDEX 0xDCD6U
|
||||
#define MTP_OB_PROP_TOTAL_BITRATE 0xDE91U
|
||||
#define MTP_OB_PROP_BITRATE_TYPE 0xDE92U
|
||||
#define MTP_OB_PROP_SAMPLE_RATE 0xDE93U
|
||||
#define MTP_OB_PROP_NUMBER_OF_CHANNELS 0xDE94U
|
||||
#define MTP_OB_PROP_AUDIO_BITDEPTH 0xDE95U
|
||||
#define MTP_OB_PROP_SCAN_TYPE 0xDE97U
|
||||
#define MTP_OB_PROP_AUDIO_WAVE_CODEC 0xDE99U
|
||||
#define MTP_OB_PROP_AUDIO_BITRATE 0xDE9AU
|
||||
#define MTP_OB_PROP_VIDEO_FOURCC_CODEC 0xDE9BU
|
||||
#define MTP_OB_PROP_VIDEO_BITRATE 0xDE9CU
|
||||
#define MTP_OB_PROP_FRAMES_PER_THOUSAND_SECONDS 0xDE9DU
|
||||
#define MTP_OB_PROP_KEYFRAME_DISTANCE 0xDE9EU
|
||||
#define MTP_OB_PROP_BUFFER_SIZE 0xDE9FU
|
||||
#define MTP_OB_PROP_ENCODING_QUALITY 0xDEA0U
|
||||
#define MTP_OB_PROP_ENCODING_PROFILE 0xDEA1U
|
||||
#define MTP_OB_PROP_DISPLAY_NAME 0xDCE0U
|
||||
#define MTP_OB_PROP_BODY_TEXT 0xDCE1U
|
||||
#define MTP_OB_PROP_SUBJECT 0xDCE2U
|
||||
#define MTP_OB_PROP_PRIORITY 0xDCE3U
|
||||
#define MTP_OB_PROP_GIVEN_NAME 0xDD00U
|
||||
#define MTP_OB_PROP_MIDDLE_NAMES 0xDD01U
|
||||
#define MTP_OB_PROP_FAMILY_NAME 0xDD02U
|
||||
#define MTP_OB_PROP_PREFIX 0xDD03U
|
||||
#define MTP_OB_PROP_SUFFIX 0xDD04U
|
||||
#define MTP_OB_PROP_PHONETIC_GIVEN_NAME 0xDD05U
|
||||
#define MTP_OB_PROP_PHONETIC_FAMILY_NAME 0xDD06U
|
||||
#define MTP_OB_PROP_EMAIL_PRIMARY 0xDD07U
|
||||
#define MTP_OB_PROP_EMAIL_PERSONAL_1 0xDD08U
|
||||
#define MTP_OB_PROP_EMAIL_PERSONAL_2 0xDD09U
|
||||
#define MTP_OB_PROP_EMAIL_BUSINESS_1 0xDD0AU
|
||||
#define MTP_OB_PROP_EMAIL_BUSINESS_2 0xDD0BU
|
||||
#define MTP_OB_PROP_EMAIL_OTHERS 0xDD0CU
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_PRIMARY 0xDD0DU
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_PERSONAL 0xDD0EU
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_PERSONAL_2 0xDD0FU
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_BUSINESS 0xDD10U
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_BUSINESS_2 0xDD11U
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_MOBILE 0xDD12U
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_MOBILE_2 0xDD13U
|
||||
#define MTP_OB_PROP_FAX_NUMBER_PRIMARY 0xDD14U
|
||||
#define MTP_OB_PROP_FAX_NUMBER_PERSONAL 0xDD15U
|
||||
#define MTP_OB_PROP_FAX_NUMBER_BUSINESS 0xDD16U
|
||||
#define MTP_OB_PROP_PAGER_NUMBER 0xDD17U
|
||||
#define MTP_OB_PROP_PHONE_NUMBER_OTHERS 0xDD18U
|
||||
#define MTP_OB_PROP_PRIMARY_WEB_ADDRESS 0xDD19U
|
||||
#define MTP_OB_PROP_PERSONAL_WEB_ADDRESS 0xDD1AU
|
||||
#define MTP_OB_PROP_BUSINESS_WEB_ADDRESS 0xDD1BU
|
||||
#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS 0xDD1CU
|
||||
#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS_2 0xDD1DU
|
||||
#define MTP_OB_PROP_INSTANT_MESSENGER_ADDRESS_3 0xDD1EU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_FULL 0xDD1FU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_LINE_1 0xDD20U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_LINE_2 0xDD21U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_CITY 0xDD22U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_REGION 0xDD23U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_POSTAL_CODE 0xDD24U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_PERSONAL_COUNTRY 0xDD25U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_FULL 0xDD26U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_LINE_1 0xDD27U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_LINE_2 0xDD28U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_CITY 0xDD29U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_REGION 0xDD2AU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_POSTAL_CODE 0xDD2BU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_BUSINESS_COUNTRY 0xDD2CU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_FULL 0xDD2DU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_LINE_1 0xDD2EU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_LINE_2 0xDD2FU
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_CITY 0xDD30U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_REGION 0xDD31U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_POSTAL_CODE 0xDD32U
|
||||
#define MTP_OB_PROP_POSTAL_ADDRESS_OTHER_COUNTRY 0xDD33U
|
||||
#define MTP_OB_PROP_ORGANIZATION_NAME 0xDD34U
|
||||
#define MTP_OB_PROP_PHONETIC_ORGANIZATION_NAME 0xDD35U
|
||||
#define MTP_OB_PROP_ROLE 0xDD36U
|
||||
#define MTP_OB_PROP_BIRTHDATE 0xDD37U
|
||||
#define MTP_OB_PROP_MESSAGE_TO 0xDD40U
|
||||
#define MTP_OB_PROP_MESSAGE_CC 0xDD41U
|
||||
#define MTP_OB_PROP_MESSAGE_BCC 0xDD42U
|
||||
#define MTP_OB_PROP_MESSAGE_READ 0xDD43U
|
||||
#define MTP_OB_PROP_MESSAGE_RECEIVED_TIME 0xDD44U
|
||||
#define MTP_OB_PROP_MESSAGE_SENDER 0xDD45U
|
||||
#define MTP_OB_PROP_ACT_BEGIN_TIME 0xDD50U
|
||||
#define MTP_OB_PROP_ACT_END_TIME 0xDD51U
|
||||
#define MTP_OB_PROP_ACT_LOCATION 0xDD52U
|
||||
#define MTP_OB_PROP_ACT_REQUIRED_ATTENDEES 0xDD54U
|
||||
#define MTP_OB_PROP_ACT_OPTIONAL_ATTENDEES 0xDD55U
|
||||
#define MTP_OB_PROP_ACT_RESOURCES 0xDD56U
|
||||
#define MTP_OB_PROP_ACT_ACCEPTED 0xDD57U
|
||||
#define MTP_OB_PROP_OWNER 0xDD5DU
|
||||
#define MTP_OB_PROP_EDITOR 0xDD5EU
|
||||
#define MTP_OB_PROP_WEBMASTER 0xDD5FU
|
||||
#define MTP_OB_PROP_URL_SOURCE 0xDD60U
|
||||
#define MTP_OB_PROP_URL_DESTINATION 0xDD61U
|
||||
#define MTP_OB_PROP_TIME_BOOKMARK 0xDD62U
|
||||
#define MTP_OB_PROP_OBJECT_BOOKMARK 0xDD63U
|
||||
#define MTP_OB_PROP_BYTE_BOOKMARK 0xDD64U
|
||||
#define MTP_OB_PROP_LAST_BUILD_DATE 0xDD70U
|
||||
#define MTP_OB_PROP_TIME_TO_LIVE 0xDD71U
|
||||
#define MTP_OB_PROP_MEDIA_GUID 0xDD72U
|
||||
|
||||
/* MTP event codes*/
|
||||
#define MTP_EVENT_UNDEFINED 0x4000U
|
||||
#define MTP_EVENT_CANCELTRANSACTION 0x4001U
|
||||
#define MTP_EVENT_OBJECTADDED 0x4002U
|
||||
#define MTP_EVENT_OBJECTREMOVED 0x4003U
|
||||
#define MTP_EVENT_STOREADDED 0x4004U
|
||||
#define MTP_EVENT_STOREREMOVED 0x4005U
|
||||
#define MTP_EVENT_DEVICEPROPCHANGED 0x4006U
|
||||
#define MTP_EVENT_OBJECTINFOCHANGED 0x4007U
|
||||
#define MTP_EVENT_DEVICEINFOCHANGED 0x4008U
|
||||
#define MTP_EVENT_REQUESTOBJECTTRANSFER 0x4009U
|
||||
#define MTP_EVENT_STOREFULL 0x400AU
|
||||
#define MTP_EVENT_DEVICERESET 0x400BU
|
||||
#define MTP_EVENT_STORAGEINFOCHANGED 0x400CU
|
||||
#define MTP_EVENT_CAPTURECOMPLETE 0x400DU
|
||||
#define MTP_EVENT_UNREPORTEDSTATUS 0x400EU
|
||||
#define MTP_EVENT_OBJECTPROPCHANGED 0xC801U
|
||||
#define MTP_EVENT_OBJECTPROPDESCCHANGED 0xC802U
|
||||
#define MTP_EVENT_OBJECTREFERENCESCHANGED 0xC803U
|
||||
|
||||
/* Operations code */
|
||||
#define MTP_OP_GET_DEVICE_INFO 0x1001U
|
||||
#define MTP_OP_OPEN_SESSION 0x1002U
|
||||
#define MTP_OP_CLOSE_SESSION 0x1003U
|
||||
#define MTP_OP_GET_STORAGE_IDS 0x1004U
|
||||
#define MTP_OP_GET_STORAGE_INFO 0x1005U
|
||||
#define MTP_OP_GET_NUM_OBJECTS 0x1006U
|
||||
#define MTP_OP_GET_OBJECT_HANDLES 0x1007U
|
||||
#define MTP_OP_GET_OBJECT_INFO 0x1008U
|
||||
#define MTP_OP_GET_OBJECT 0x1009U
|
||||
#define MTP_OP_GET_THUMB 0x100AU
|
||||
#define MTP_OP_DELETE_OBJECT 0x100BU
|
||||
#define MTP_OP_SEND_OBJECT_INFO 0x100CU
|
||||
#define MTP_OP_SEND_OBJECT 0x100DU
|
||||
#define MTP_OP_FORMAT_STORE 0x100FU
|
||||
#define MTP_OP_RESET_DEVICE 0x1010U
|
||||
#define MTP_OP_GET_DEVICE_PROP_DESC 0x1014U
|
||||
#define MTP_OP_GET_DEVICE_PROP_VALUE 0x1015U
|
||||
#define MTP_OP_SET_DEVICE_PROP_VALUE 0x1016U
|
||||
#define MTP_OP_RESET_DEVICE_PROP_VALUE 0x1017U
|
||||
#define MTP_OP_TERMINATE_OPEN_CAPTURE 0x1018U
|
||||
#define MTP_OP_MOVE_OBJECT 0x1019U
|
||||
#define MTP_OP_COPY_OBJECT 0x101AU
|
||||
#define MTP_OP_GET_PARTIAL_OBJECT 0x101BU
|
||||
#define MTP_OP_INITIATE_OPEN_CAPTURE 0x101CU
|
||||
#define MTP_OP_GET_OBJECT_PROPS_SUPPORTED 0x9801U
|
||||
#define MTP_OP_GET_OBJECT_PROP_DESC 0x9802U
|
||||
#define MTP_OP_GET_OBJECT_PROP_VALUE 0x9803U
|
||||
#define MTP_OP_SET_OBJECT_PROP_VALUE 0x9804U
|
||||
#define MTP_OP_GET_OBJECT_PROPLIST 0x9805U
|
||||
#define MTP_OP_GET_OBJECT_PROP_REFERENCES 0x9810U
|
||||
#define MTP_OP_GETSERVICEIDS 0x9301U
|
||||
#define MTP_OP_GETSERVICEINFO 0x9302U
|
||||
#define MTP_OP_GETSERVICECAPABILITIES 0x9303U
|
||||
#define MTP_OP_GETSERVICEPROPDESC 0x9304U
|
||||
|
||||
/* MTP device properties code*/
|
||||
#define MTP_DEV_PROP_UNDEFINED 0x5000U
|
||||
#define MTP_DEV_PROP_BATTERY_LEVEL 0x5001U
|
||||
#define MTP_DEV_PROP_FUNCTIONAL_MODE 0x5002U
|
||||
#define MTP_DEV_PROP_IMAGE_SIZE 0x5003U
|
||||
#define MTP_DEV_PROP_COMPRESSION_SETTING 0x5004U
|
||||
#define MTP_DEV_PROP_WHITE_BALANCE 0x5005U
|
||||
#define MTP_DEV_PROP_RGB_GAIN 0x5006U
|
||||
#define MTP_DEV_PROP_F_NUMBER 0x5007U
|
||||
#define MTP_DEV_PROP_FOCAL_LENGTH 0x5008U
|
||||
#define MTP_DEV_PROP_FOCUS_DISTANCE 0x5009U
|
||||
#define MTP_DEV_PROP_FOCUS_MODE 0x500AU
|
||||
#define MTP_DEV_PROP_EXPOSURE_METERING_MODE 0x500BU
|
||||
#define MTP_DEV_PROP_FLASH_MODE 0x500CU
|
||||
#define MTP_DEV_PROP_EXPOSURE_TIME 0x500DU
|
||||
#define MTP_DEV_PROP_EXPOSURE_PROGRAM_MODE 0x500EU
|
||||
#define MTP_DEV_PROP_EXPOSURE_INDEX 0x500FU
|
||||
#define MTP_DEV_PROP_EXPOSURE_BIAS_COMPENSATION 0x5010U
|
||||
#define MTP_DEV_PROP_DATETIME 0x5011U
|
||||
#define MTP_DEV_PROP_CAPTURE_DELAY 0x5012U
|
||||
#define MTP_DEV_PROP_STILL_CAPTURE_MODE 0x5013U
|
||||
#define MTP_DEV_PROP_CONTRAST 0x5014U
|
||||
#define MTP_DEV_PROP_SHARPNESS 0x5015U
|
||||
#define MTP_DEV_PROP_DIGITAL_ZOOM 0x5016U
|
||||
#define MTP_DEV_PROP_EFFECT_MODE 0x5017U
|
||||
#define MTP_DEV_PROP_BURST_NUMBER 0x5018U
|
||||
#define MTP_DEV_PROP_BURST_INTERVAL 0x5019U
|
||||
#define MTP_DEV_PROP_TIMELAPSE_NUMBER 0x501AU
|
||||
#define MTP_DEV_PROP_TIMELAPSE_INTERVAL 0x501BU
|
||||
#define MTP_DEV_PROP_FOCUS_METERING_MODE 0x501CU
|
||||
#define MTP_DEV_PROP_UPLOAD_URL 0x501DU
|
||||
#define MTP_DEV_PROP_ARTIST 0x501EU
|
||||
#define MTP_DEV_PROP_COPYRIGHT_INFO 0x501FU
|
||||
#define MTP_DEV_PROP_SYNCHRONIZATION_PARTNER 0xD401U
|
||||
#define MTP_DEV_PROP_DEVICE_FRIENDLY_NAME 0xD402U
|
||||
#define MTP_DEV_PROP_VOLUME 0xD403U
|
||||
#define MTP_DEV_PROP_SUPPORTEDFORMATSORDERED 0xD404U
|
||||
#define MTP_DEV_PROP_DEVICEICON 0xD405U
|
||||
#define MTP_DEV_PROP_PLAYBACK_RATE 0xD410U
|
||||
#define MTP_DEV_PROP_PLAYBACK_OBJECT 0xD411U
|
||||
#define MTP_DEV_PROP_PLAYBACK_CONTAINER 0xD412U
|
||||
#define MTP_DEV_PROP_SESSION_INITIATOR_VERSION_INFO 0xD406U
|
||||
#define MTP_DEV_PROP_PERCEIVED_DEVICE_TYPE 0xD407U
|
||||
|
||||
|
||||
/* Container Types */
|
||||
#define MTP_CONT_TYPE_UNDEFINED 0U
|
||||
#define MTP_CONT_TYPE_COMMAND 1U
|
||||
#define MTP_CONT_TYPE_DATA 2U
|
||||
#define MTP_CONT_TYPE_RESPONSE 3U
|
||||
#define MTP_CONT_TYPE_EVENT 4U
|
||||
|
||||
#ifndef MTP_STORAGE_ID
|
||||
#define MTP_STORAGE_ID 0x00010001U /* SD card is inserted*/
|
||||
#endif /* MTP_STORAGE_ID */
|
||||
|
||||
#define MTP_NBR_STORAGE_ID 1U
|
||||
#define FREE_SPACE_IN_OBJ_NOT_USED 0xFFFFFFFFU
|
||||
|
||||
/* MTP storage type */
|
||||
#define MTP_STORAGE_UNDEFINED 0U
|
||||
#define MTP_STORAGE_FIXED_ROM 0x0001U
|
||||
#define MTP_STORAGE_REMOVABLE_ROM 0x0002U
|
||||
#define MTP_STORAGE_FIXED_RAM 0x0003U
|
||||
#define MTP_STORAGE_REMOVABLE_RAM 0x0004U
|
||||
|
||||
/* MTP file system type */
|
||||
#define MTP_FILESYSTEM_UNDEFINED 0U
|
||||
#define MTP_FILESYSTEM_GENERIC_FLAT 0x0001U
|
||||
#define MTP_FILESYSTEM_GENERIC_HIERARCH 0x0002U
|
||||
#define MTP_FILESYSTEM_DCF 0x0003U
|
||||
|
||||
/* MTP access capability */
|
||||
#define MTP_ACCESS_CAP_RW 0U /* read write */
|
||||
#define MTP_ACCESS_CAP_RO_WITHOUT_DEL 0x0001U
|
||||
#define MTP_ACCESS_CAP_RO_WITH_DEL 0x0002U
|
||||
|
||||
/* MTP standard data types supported */
|
||||
#define MTP_DATATYPE_INT8 0x0001U
|
||||
#define MTP_DATATYPE_UINT8 0x0002U
|
||||
#define MTP_DATATYPE_INT16 0x0003U
|
||||
#define MTP_DATATYPE_UINT16 0x0004U
|
||||
#define MTP_DATATYPE_INT32 0x0005U
|
||||
#define MTP_DATATYPE_UINT32 0x0006U
|
||||
#define MTP_DATATYPE_INT64 0x0007U
|
||||
#define MTP_DATATYPE_UINT64 0x0008U
|
||||
#define MTP_DATATYPE_UINT128 0x000AU
|
||||
#define MTP_DATATYPE_STR 0xFFFFU
|
||||
|
||||
/* MTP reading only or reading/writing */
|
||||
#define MTP_PROP_GET 0x00U
|
||||
#define MTP_PROP_GET_SET 0x01U
|
||||
|
||||
|
||||
/* MTP functional mode */
|
||||
#define STANDARD_MODE 0U
|
||||
#define SLEEP_STATE 1U
|
||||
#define FUNCTIONAL_MODE STANDARD_MODE
|
||||
|
||||
/* MTP device info */
|
||||
#define STANDARD_VERSION 100U
|
||||
#define VEND_EXT_ID 0x06U
|
||||
#define VEND_EXT_VERSION 100U
|
||||
#define MANUF_LEN (sizeof(Manuf) / 2U)
|
||||
#define MODEL_LEN (sizeof(Model) / 2U)
|
||||
#define SUPP_OP_LEN (sizeof(SuppOP) / 2U)
|
||||
#define SERIAL_NBR_LEN (sizeof(SerialNbr) / 2U)
|
||||
#define DEVICE_VERSION_LEN (sizeof(DeviceVers) / 2U)
|
||||
#define SUPP_IMG_FORMAT_LEN (sizeof(SuppImgFormat) / 2U)
|
||||
#define SUPP_OBJ_PROP_LEN (sizeof(ObjectPropSupp) / 2U)
|
||||
|
||||
#ifndef MAX_FILE_NAME
|
||||
#define MAX_FILE_NAME 255U
|
||||
#endif /* MAX_FILE_NAME */
|
||||
|
||||
#ifndef MAX_OBJECT_HANDLE_LEN
|
||||
#define MAX_OBJECT_HANDLE_LEN 100U
|
||||
#endif /* MAX_OBJECT_HANDLE_LEN */
|
||||
|
||||
#ifndef DEVICE_PROP_DESC_DEF_LEN
|
||||
#define DEVICE_PROP_DESC_DEF_LEN (uint8_t)(sizeof(DevicePropDefVal) / 2U)
|
||||
#endif /* DEVICE_PROP_DESC_DEF_LEN */
|
||||
|
||||
#ifndef DEVICE_PROP_DESC_CUR_LEN
|
||||
#define DEVICE_PROP_DESC_CUR_LEN (uint8_t)(sizeof(DevicePropCurDefVal) / 2U)
|
||||
#endif /* DEVICE_PROP_DESC_CUR_LEN */
|
||||
|
||||
#ifndef DEFAULT_FILE_NAME_LEN
|
||||
#define DEFAULT_FILE_NAME_LEN (uint8_t)(sizeof(DefaultFileName) / 2U)
|
||||
#endif /* DEFAULT_FILE_NAME_LEN */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
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,
|
||||
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_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
|
||||
};
|
||||
|
||||
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,
|
||||
MTP_OBJ_FORMAT_MP3, 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};
|
||||
|
||||
/* required for all object format : storageID, objectFormat, ObjectCompressedSize, persistent unique object identifier, name*/
|
||||
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};
|
||||
|
||||
/* for all mtp struct */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t StorageIDS_len;
|
||||
uint32_t StorageIDS[MTP_NBR_STORAGE_ID];
|
||||
} MTP_StorageIDSTypeDef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint8_t FileName_len;
|
||||
uint16_t FileName[MAX_FILE_NAME];
|
||||
} MTP_FileNameTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t ObjectHandle_len;
|
||||
uint32_t ObjectHandle[MAX_OBJECT_HANDLE_LEN];
|
||||
} MTP_ObjectHandleTypeDef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t ObjectPropSupp_len;
|
||||
uint16_t ObjectPropSupp[SUPP_OBJ_PROP_LEN];
|
||||
} MTP_ObjectPropSuppTypeDef;
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint16_t StorageType;
|
||||
uint16_t FilesystemType;
|
||||
uint16_t AccessCapability;
|
||||
uint64_t MaxCapability;
|
||||
uint64_t FreeSpaceInBytes;
|
||||
uint32_t FreeSpaceInObjects;
|
||||
uint8_t StorageDescription;
|
||||
uint8_t VolumeLabel;
|
||||
} MTP_StorageInfoTypedef;
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint16_t str[100];
|
||||
uint8_t u8;
|
||||
int8_t i8;
|
||||
uint16_t u16;
|
||||
int16_t i16;
|
||||
uint32_t u32;
|
||||
int32_t i32;
|
||||
uint64_t u64;
|
||||
int64_t i64;
|
||||
} MTP_PropertyValueTypedef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint16_t ObjectPropertyCode;
|
||||
uint16_t DataType;
|
||||
uint8_t GetSet;
|
||||
uint8_t *DefValue;
|
||||
uint32_t GroupCode;
|
||||
uint8_t FormFlag;
|
||||
} MTP_ObjectPropDescTypeDef;
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t ObjectHandle;
|
||||
uint16_t PropertyCode;
|
||||
uint16_t Datatype;
|
||||
uint8_t *propval;
|
||||
} MTP_PropertiesTypedef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t MTP_Properties_len;
|
||||
MTP_PropertiesTypedef MTP_Properties[SUPP_OBJ_PROP_LEN];
|
||||
} MTP_PropertiesListTypedef;
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint32_t ref_len;
|
||||
uint32_t ref[1];
|
||||
} MTP_RefTypeDef;
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint16_t DevicePropertyCode;
|
||||
uint16_t DataType;
|
||||
uint8_t GetSet;
|
||||
uint8_t DefValue_len;
|
||||
uint16_t DefValue[DEVICE_PROP_DESC_DEF_LEN];
|
||||
uint8_t curDefValue_len;
|
||||
uint16_t curDefValue[DEVICE_PROP_DESC_CUR_LEN];
|
||||
uint8_t FormFlag;
|
||||
} MTP_DevicePropDescTypeDef;
|
||||
|
||||
/* MTP device info structure */
|
||||
#if defined ( __GNUC__ )
|
||||
typedef __PACKED_STRUCT
|
||||
#else
|
||||
__packed typedef struct
|
||||
#endif
|
||||
{
|
||||
uint16_t StandardVersion;
|
||||
uint32_t VendorExtensionID;
|
||||
uint16_t VendorExtensionVersion;
|
||||
uint8_t VendorExtensionDesc_len;
|
||||
#if USBD_MTP_VEND_EXT_DESC_SUPPORTED == 1
|
||||
uint16_t VendorExtensionDesc[VEND_EXT_DESC_LEN];
|
||||
#endif
|
||||
uint16_t FunctionalMode;
|
||||
uint32_t OperationsSupported_len;
|
||||
uint16_t OperationsSupported[SUPP_OP_LEN];
|
||||
uint32_t EventsSupported_len;
|
||||
#if USBD_MTP_EVENTS_SUPPORTED == 1
|
||||
uint16_t EventsSupported[SUPP_EVENTS_LEN];
|
||||
#endif
|
||||
uint32_t DevicePropertiesSupported_len;
|
||||
#if USBD_MTP_DEVICE_PROP_SUPPORTED == 1
|
||||
uint16_t DevicePropertiesSupported[SUPP_DEVICE_PROP_LEN];
|
||||
#endif
|
||||
uint32_t CaptureFormats_len;
|
||||
#if USBD_MTP_CAPTURE_FORMAT_SUPPORTED == 1
|
||||
uint16_t CaptureFormats[SUPP_CAPT_FORMAT_LEN];
|
||||
#endif
|
||||
uint32_t ImageFormats_len;
|
||||
uint16_t ImageFormats[SUPP_IMG_FORMAT_LEN];
|
||||
uint8_t Manufacturer_len;
|
||||
uint16_t Manufacturer[MANUF_LEN];
|
||||
uint8_t Model_len;
|
||||
uint16_t Model[MODEL_LEN];
|
||||
uint8_t DeviceVersion_len;
|
||||
uint16_t DeviceVersion[DEVICE_VERSION_LEN];
|
||||
uint8_t SerialNumber_len;
|
||||
uint16_t SerialNumber[SERIAL_NBR_LEN];
|
||||
} MTP_DeviceInfoTypedef;
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_OPT_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
void USBD_MTP_OPT_CreateObjectHandle(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetDeviceInfo(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetStorageIDS(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetStorageInfo(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectHandle(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectInfo(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectReferences(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectPropSupp(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectPropDesc(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectPropValue(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetObjectPropList(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_GetDevicePropDesc(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_SendObjectInfo(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len);
|
||||
void USBD_MTP_OPT_SendObject(USBD_HandleTypeDef *pdev, uint8_t *buff, uint32_t len);
|
||||
void USBD_MTP_OPT_GetObject(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_OPT_DeleteObject(USBD_HandleTypeDef *pdev);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_MTP_OPT_H__ */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
118
Class/MTP/Inc/usbd_mtp_storage.h
Normal file
118
Class/MTP/Inc/usbd_mtp_storage.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_storage.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_mtp_storage.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_MTP_STORAGE_H__
|
||||
#define __USBD_MTP_STORAGE_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ctlreq.h"
|
||||
#include "usbd_mtp_opt.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE
|
||||
* @brief This file is the header file for usbd_template_core.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DATA_TYPE = 0x00,
|
||||
REP_TYPE = 0x01,
|
||||
} MTP_CONTAINER_TYPE;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
READ_FIRST_DATA = 0x00,
|
||||
READ_REST_OF_DATA = 0x01,
|
||||
} MTP_READ_DATA_STATUS;
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_STORAGE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
uint8_t USBD_MTP_STORAGE_Init(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev);
|
||||
void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev, MTP_ResponsePhaseTypeDef MTP_ResponsePhase);
|
||||
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_ReceiveOpt(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_MTP_STORAGE_ReceiveData(USBD_HandleTypeDef *pdev);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_MTP_STORAGE_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
639
Class/MTP/Src/usbd_mtp.c
Normal file
639
Class/MTP/Src/usbd_mtp.c
Normal file
@@ -0,0 +1,639 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the high layer firmware functions to manage the
|
||||
* following functionalities of the USB MTP Class:
|
||||
* - Initialization and Configuration of high and low layer
|
||||
* - Enumeration as MTP Device (and enumeration for each implemented memory interface)
|
||||
* - OUT/IN data transfer
|
||||
* - Command IN transfer (class requests management)
|
||||
* - Error management
|
||||
*
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* MTP Class Driver Description
|
||||
* ===================================================================
|
||||
* This driver manages the "Universal Serial Bus Class Definitions for Media Transfer Protocol
|
||||
* Revision 1.1 April 6, 2011"
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Enumeration as MTP device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
|
||||
* - Requests management
|
||||
*
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_mtp.h"
|
||||
#include "usbd_mtp_storage.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MTP_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static uint8_t USBD_MTP_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_MTP_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_MTP_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* MTP interface class callbacks structure */
|
||||
USBD_ClassTypeDef USBD_MTP =
|
||||
{
|
||||
USBD_MTP_Init,
|
||||
USBD_MTP_DeInit,
|
||||
USBD_MTP_Setup,
|
||||
NULL, /*EP0_TxSent*/
|
||||
NULL, /*EP0_RxReady*/
|
||||
USBD_MTP_DataIn,
|
||||
USBD_MTP_DataOut,
|
||||
NULL, /*SOF */
|
||||
NULL, /*ISOIn*/
|
||||
NULL, /*ISOOut*/
|
||||
USBD_MTP_GetHSCfgDesc,
|
||||
USBD_MTP_GetFSCfgDesc,
|
||||
USBD_MTP_GetOtherSpeedCfgDesc,
|
||||
USBD_MTP_GetDeviceQualifierDescriptor,
|
||||
};
|
||||
|
||||
/* USB MTP device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_MTP_CfgHSDesc[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)
|
||||
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)
|
||||
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_FS_PACKET_SIZE),
|
||||
HIBYTE(MTP_DATA_MAX_FS_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_FS_PACKET_SIZE),
|
||||
HIBYTE(MTP_DATA_MAX_FS_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_FS_BINTERVAL /* Polling interval in milliseconds */
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_MTP_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,
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MTP_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Init
|
||||
* Initialize the MTP interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
USBD_MTP_HandleTypeDef *hmtp;
|
||||
|
||||
hmtp = (USBD_MTP_HandleTypeDef *)USBD_malloc(sizeof(USBD_MTP_HandleTypeDef));
|
||||
|
||||
if (hmtp == NULL)
|
||||
{
|
||||
pdev->pClassData = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
/* Setup the pClassData pointer */
|
||||
pdev->pClassData = (void *)hmtp;
|
||||
|
||||
/* Initialize all variables */
|
||||
(void)USBD_memset(hmtp, 0, sizeof(USBD_MTP_HandleTypeDef));
|
||||
|
||||
/* Setup the max packet size according to selected speed */
|
||||
hmtp->MaxPcktLen = (pdev->dev_speed == USBD_SPEED_HIGH) ? MTP_DATA_MAX_HS_PACKET_SIZE : MTP_DATA_MAX_FS_PACKET_SIZE;
|
||||
|
||||
/* Open EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, MTP_IN_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||
pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP OUT */
|
||||
(void)USBD_LL_OpenEP(pdev, MTP_OUT_EP, USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||
pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open INTR EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, MTP_CMD_EP, USBD_EP_TYPE_INTR, MTP_CMD_PACKET_SIZE);
|
||||
pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Init the MTP layer */
|
||||
(void)USBD_MTP_STORAGE_Init(pdev);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_DeInit
|
||||
* DeInitialize the MTP layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
/* Close EP IN */
|
||||
(void)USBD_LL_CloseEP(pdev, MTP_IN_EP);
|
||||
pdev->ep_in[MTP_IN_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP OUT */
|
||||
(void)USBD_LL_CloseEP(pdev, MTP_OUT_EP);
|
||||
pdev->ep_out[MTP_OUT_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP Command */
|
||||
(void)USBD_LL_CloseEP(pdev, MTP_CMD_EP);
|
||||
pdev->ep_in[MTP_CMD_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* De-Init the MTP layer */
|
||||
(void)USBD_MTP_STORAGE_DeInit(pdev);
|
||||
|
||||
/* Free MTP Class Resources */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
(void)USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Setup
|
||||
* Handle the MTP specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
uint16_t len = 0U;
|
||||
|
||||
if (hmtp == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
/* Class request */
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case MTP_REQ_CANCEL:
|
||||
len = MIN(hmtp->MaxPcktLen, req->wLength);
|
||||
(void)USBD_CtlPrepareRx(pdev, (uint8_t *)(hmtp->rx_buff), len);
|
||||
break;
|
||||
|
||||
case MTP_REQ_GET_EXT_EVENT_DATA:
|
||||
break;
|
||||
|
||||
case MTP_REQ_RESET:
|
||||
/* Stop low layer file system operations if any */
|
||||
USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, hmtp->MaxPcktLen);
|
||||
break;
|
||||
|
||||
case MTP_REQ_GET_DEVICE_STATUS:
|
||||
switch (hmtp->MTP_ResponsePhase)
|
||||
{
|
||||
case MTP_READ_DATA :
|
||||
len = 4U;
|
||||
hmtp->dev_status = ((uint32_t)MTP_RESPONSE_DEVICE_BUSY << 16) | len;
|
||||
break;
|
||||
|
||||
case MTP_RECEIVE_DATA :
|
||||
len = 4U;
|
||||
hmtp->dev_status = ((uint32_t)MTP_RESPONSE_TRANSACTION_CANCELLED << 16) | len;
|
||||
break;
|
||||
|
||||
case MTP_PHASE_IDLE :
|
||||
len = 4U;
|
||||
hmtp->dev_status = ((uint32_t)MTP_RESPONSE_OK << 16) | len;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmtp->dev_status, len);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Interface & Endpoint request */
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hmtp->alt_setting = 0U;
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hmtp->alt_setting, 1U);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
|
||||
/* Re-activate the EP */
|
||||
(void)USBD_LL_CloseEP(pdev, (uint8_t)req->wIndex);
|
||||
|
||||
if ((((uint8_t)req->wIndex) & 0x80U) == 0x80U)
|
||||
{
|
||||
(void)USBD_LL_OpenEP(pdev, ((uint8_t)req->wIndex), USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)USBD_LL_OpenEP(pdev, ((uint8_t)req->wIndex), USBD_EP_TYPE_BULK, hmtp->MaxPcktLen);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_DataIn
|
||||
* Data sent on non-control IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
UNUSED(epnum);
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint16_t len;
|
||||
|
||||
if (epnum == (MTP_IN_EP & 0x7FU))
|
||||
{
|
||||
switch (hmtp->MTP_ResponsePhase)
|
||||
{
|
||||
case MTP_RESPONSE_PHASE :
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, REP_TYPE);
|
||||
|
||||
/* prepare to receive next operation */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
|
||||
break;
|
||||
case MTP_READ_DATA :
|
||||
(void)USBD_MTP_STORAGE_ReadData(pdev);
|
||||
|
||||
/* prepare to receive next operation */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_IN_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
break;
|
||||
case MTP_PHASE_IDLE :
|
||||
/* prepare to receive next operation */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MTP_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
UNUSED(epnum);
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint16_t len;
|
||||
|
||||
(void)USBD_MTP_STORAGE_ReceiveOpt(pdev);
|
||||
|
||||
switch (hmtp->MTP_ResponsePhase)
|
||||
{
|
||||
case MTP_RESPONSE_PHASE :
|
||||
|
||||
if (hmtp->ResponseLength == MTP_CONT_HEADER_SIZE)
|
||||
{
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, REP_TYPE);
|
||||
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, DATA_TYPE);
|
||||
}
|
||||
break;
|
||||
|
||||
case MTP_READ_DATA :
|
||||
(void)USBD_MTP_STORAGE_ReadData(pdev);
|
||||
break;
|
||||
|
||||
case MTP_RECEIVE_DATA :
|
||||
(void)USBD_MTP_STORAGE_ReceiveData(pdev);
|
||||
|
||||
/* prepare endpoint to receive operations */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
break;
|
||||
|
||||
case MTP_PHASE_IDLE :
|
||||
/* prepare to receive next operation */
|
||||
len = MIN(hmtp->MaxPcktLen, pdev->request.wLength);
|
||||
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff, len);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_GetHSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MTP_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_MTP_CfgHSDesc);
|
||||
return USBD_MTP_CfgHSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_GetFSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MTP_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc);
|
||||
return USBD_MTP_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_GetOtherSpeedCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MTP_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_MTP_CfgFSDesc);
|
||||
return USBD_MTP_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_GetDeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MTP_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)(sizeof(USBD_MTP_DeviceQualifierDesc));
|
||||
return USBD_MTP_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: CD Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MTP_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_MTP_ItfTypeDef *fops)
|
||||
{
|
||||
if (fops == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
pdev->pUserData = fops;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
347
Class/MTP/Src/usbd_mtp_if_template.c
Normal file
347
Class/MTP/Src/usbd_mtp_if_template.c
Normal file
@@ -0,0 +1,347 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_if.c
|
||||
* @author MCD Application Team
|
||||
* @brief Source file for USBD MTP file list_files.
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_mtp_if_template.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/*
|
||||
static FILE MyFile;
|
||||
static FATFS SDFatFs;
|
||||
static char SDPath[4];
|
||||
static FolderLevel Fold_Lvl;
|
||||
static FOLD_INFTypeDef FoldStruct;
|
||||
static FILE_INFTypeDef FileStruct;
|
||||
static SD_Object_TypeDef sd_object;
|
||||
*/
|
||||
extern USBD_HandleTypeDef USBD_Device;
|
||||
|
||||
uint32_t idx[200];
|
||||
uint32_t parent;
|
||||
/* static char path[255]; */
|
||||
uint32_t sc_buff[MTP_IF_SCRATCH_BUFF_SZE / 4U];
|
||||
uint32_t sc_len = 0U;
|
||||
uint32_t pckt_cnt = 1U;
|
||||
uint32_t foldsize;
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static uint8_t USBD_MTP_Itf_Init(void);
|
||||
static uint8_t USBD_MTP_Itf_DeInit(void);
|
||||
static uint32_t USBD_MTP_Itf_ReadData(uint32_t Param1, uint8_t *buff, MTP_DataLengthTypeDef *data_length);
|
||||
static uint16_t USBD_MTP_Itf_Create_NewObject(MTP_ObjectInfoTypeDef ObjectInfo, uint32_t objhandle);
|
||||
|
||||
static uint32_t USBD_MTP_Itf_GetIdx(uint32_t Param3, uint32_t *obj_handle);
|
||||
static uint32_t USBD_MTP_Itf_GetParentObject(uint32_t Param);
|
||||
static uint16_t USBD_MTP_Itf_GetObjectFormat(uint32_t Param);
|
||||
static uint8_t USBD_MTP_Itf_GetObjectName_len(uint32_t Param);
|
||||
static void USBD_MTP_Itf_GetObjectName(uint32_t Param, uint8_t obj_len, uint16_t *buf);
|
||||
static uint32_t USBD_MTP_Itf_GetObjectSize(uint32_t Param);
|
||||
static uint64_t USBD_MTP_Itf_GetMaxCapability(void);
|
||||
static uint64_t USBD_MTP_Itf_GetFreeSpaceInBytes(void);
|
||||
static uint32_t USBD_MTP_Itf_GetNewIndex(uint16_t objformat);
|
||||
static void USBD_MTP_Itf_WriteData(uint16_t len, uint8_t *buff);
|
||||
static uint32_t USBD_MTP_Itf_GetContainerLength(uint32_t Param1);
|
||||
static uint16_t USBD_MTP_Itf_DeleteObject(uint32_t Param1);
|
||||
|
||||
static void USBD_MTP_Itf_Cancel(uint32_t Phase);
|
||||
/* static uint32_t USBD_MTP_Get_idx_to_delete(uint32_t Param, uint8_t *tab); */
|
||||
|
||||
USBD_MTP_ItfTypeDef USBD_MTP_fops =
|
||||
{
|
||||
USBD_MTP_Itf_Init,
|
||||
USBD_MTP_Itf_DeInit,
|
||||
USBD_MTP_Itf_ReadData,
|
||||
USBD_MTP_Itf_Create_NewObject,
|
||||
USBD_MTP_Itf_GetIdx,
|
||||
USBD_MTP_Itf_GetParentObject,
|
||||
USBD_MTP_Itf_GetObjectFormat,
|
||||
USBD_MTP_Itf_GetObjectName_len,
|
||||
USBD_MTP_Itf_GetObjectName,
|
||||
USBD_MTP_Itf_GetObjectSize,
|
||||
USBD_MTP_Itf_GetMaxCapability,
|
||||
USBD_MTP_Itf_GetFreeSpaceInBytes,
|
||||
USBD_MTP_Itf_GetNewIndex,
|
||||
USBD_MTP_Itf_WriteData,
|
||||
USBD_MTP_Itf_GetContainerLength,
|
||||
USBD_MTP_Itf_DeleteObject,
|
||||
USBD_MTP_Itf_Cancel,
|
||||
sc_buff,
|
||||
MTP_IF_SCRATCH_BUFF_SZE,
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_Init
|
||||
* Initialize the file system Layer
|
||||
* @param None
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_Itf_Init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_DeInit
|
||||
* Uninitialize the file system Layer
|
||||
* @param None
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_Itf_DeInit(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetIdx
|
||||
* Get all object handle
|
||||
* @param Param3: current object handle
|
||||
* @param obj_handle: all objects handle (subfolders/files) in current object
|
||||
* @retval number of object handle in current object
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetIdx(uint32_t Param3, uint32_t *obj_handle)
|
||||
{
|
||||
uint32_t count = 0U;
|
||||
UNUSED(Param3);
|
||||
UNUSED(obj_handle);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetParentObject
|
||||
* Get parent object
|
||||
* @param Param: object handle (object index)
|
||||
* @retval parent object
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetParentObject(uint32_t Param)
|
||||
{
|
||||
uint32_t parentobj = 0U;
|
||||
UNUSED(Param);
|
||||
|
||||
return parentobj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetObjectFormat
|
||||
* Get object format
|
||||
* @param Param: object handle (object index)
|
||||
* @retval object format
|
||||
*/
|
||||
static uint16_t USBD_MTP_Itf_GetObjectFormat(uint32_t Param)
|
||||
{
|
||||
uint16_t objformat = 0U;
|
||||
UNUSED(Param);
|
||||
|
||||
return objformat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetObjectName_len
|
||||
* Get object name length
|
||||
* @param Param: object handle (object index)
|
||||
* @retval object name length
|
||||
*/
|
||||
static uint8_t USBD_MTP_Itf_GetObjectName_len(uint32_t Param)
|
||||
{
|
||||
uint8_t obj_len = 0U;
|
||||
UNUSED(Param);
|
||||
|
||||
return obj_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetObjectName
|
||||
* Get object name
|
||||
* @param Param: object handle (object index)
|
||||
* @param obj_len: length of object name
|
||||
* @param buf: pointer to object name
|
||||
* @retval object size in SD card
|
||||
*/
|
||||
static void USBD_MTP_Itf_GetObjectName(uint32_t Param, uint8_t obj_len, uint16_t *buf)
|
||||
{
|
||||
UNUSED(Param);
|
||||
UNUSED(obj_len);
|
||||
UNUSED(buf);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetObjectSize
|
||||
* Get size of current object
|
||||
* @param Param: object handle (object index)
|
||||
* @retval object size in SD card
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetObjectSize(uint32_t Param)
|
||||
{
|
||||
uint32_t ObjCompSize = 0U;
|
||||
UNUSED(Param);
|
||||
|
||||
return ObjCompSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_Create_NewObject
|
||||
* Create new object in SD card and store necessary information for future use
|
||||
* @param ObjectInfo: object information to use
|
||||
* @param objhandle: object handle (object index)
|
||||
* @retval None
|
||||
*/
|
||||
static uint16_t USBD_MTP_Itf_Create_NewObject(MTP_ObjectInfoTypeDef ObjectInfo, uint32_t objhandle)
|
||||
{
|
||||
uint16_t rep_code = 0U;
|
||||
UNUSED(ObjectInfo);
|
||||
UNUSED(objhandle);
|
||||
|
||||
return rep_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetMaxCapability
|
||||
* Get max capability in SD card
|
||||
* @param None
|
||||
* @retval max capability
|
||||
*/
|
||||
static uint64_t USBD_MTP_Itf_GetMaxCapability(void)
|
||||
{
|
||||
uint64_t max_cap = 0U;
|
||||
|
||||
return max_cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetFreeSpaceInBytes
|
||||
* Get free space in bytes in SD card
|
||||
* @param None
|
||||
* @retval free space in bytes
|
||||
*/
|
||||
static uint64_t USBD_MTP_Itf_GetFreeSpaceInBytes(void)
|
||||
{
|
||||
uint64_t f_space_inbytes = 0U;
|
||||
|
||||
return f_space_inbytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetNewIndex
|
||||
* Create new object handle
|
||||
* @param objformat: object format
|
||||
* @retval object handle
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetNewIndex(uint16_t objformat)
|
||||
{
|
||||
uint32_t n_index = 0U;
|
||||
UNUSED(objformat);
|
||||
|
||||
return n_index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_WriteData
|
||||
* Write file data to SD card
|
||||
* @param len: size of data to write
|
||||
* @param buff: data to write in SD card
|
||||
* @retval None
|
||||
*/
|
||||
static void USBD_MTP_Itf_WriteData(uint16_t len, uint8_t *buff)
|
||||
{
|
||||
UNUSED(len);
|
||||
UNUSED(buff);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_GetContainerLength
|
||||
* Get length of generic container
|
||||
* @param Param1: object handle
|
||||
* @retval length of generic container
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_GetContainerLength(uint32_t Param1)
|
||||
{
|
||||
uint32_t length = 0U;
|
||||
UNUSED(Param1);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_DeleteObject
|
||||
* delete object from SD card
|
||||
* @param Param1: object handle (file/folder index)
|
||||
* @retval response code
|
||||
*/
|
||||
static uint16_t USBD_MTP_Itf_DeleteObject(uint32_t Param1)
|
||||
{
|
||||
uint16_t rep_code = 0U;
|
||||
UNUSED(Param1);
|
||||
|
||||
return rep_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Get_idx_to_delete
|
||||
* Get all files/foldres index to delete with descending order ( max depth)
|
||||
* @param Param: object handle (file/folder index)
|
||||
* @param tab: pointer to list of files/folders to delete
|
||||
* @retval Number of files/folders to delete
|
||||
*/
|
||||
/* static uint32_t USBD_MTP_Get_idx_to_delete(uint32_t Param, uint8_t *tab)
|
||||
{
|
||||
uint32_t cnt = 0U;
|
||||
|
||||
return cnt;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_ReadData
|
||||
* Read data from SD card
|
||||
* @param Param1: object handle
|
||||
* @param buff: pointer to data to be read
|
||||
* @param temp_length: current data size read
|
||||
* @retval necessary information for next read/finish reading
|
||||
*/
|
||||
static uint32_t USBD_MTP_Itf_ReadData(uint32_t Param1, uint8_t *buff, MTP_DataLengthTypeDef *data_length)
|
||||
{
|
||||
UNUSED(Param1);
|
||||
UNUSED(buff);
|
||||
UNUSED(data_length);
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_Itf_Cancel
|
||||
* Close opened folder/file while cancelling transaction
|
||||
* @param MTP_ResponsePhase: MTP current state
|
||||
* @retval None
|
||||
*/
|
||||
static void USBD_MTP_Itf_Cancel(uint32_t Phase)
|
||||
{
|
||||
UNUSED(Phase);
|
||||
|
||||
/* Make sure to close open file while canceling transaction */
|
||||
|
||||
return;
|
||||
}
|
||||
1266
Class/MTP/Src/usbd_mtp_opt.c
Normal file
1266
Class/MTP/Src/usbd_mtp_opt.c
Normal file
File diff suppressed because it is too large
Load Diff
456
Class/MTP/Src/usbd_mtp_storage.c
Normal file
456
Class/MTP/Src/usbd_mtp_storage.c
Normal file
@@ -0,0 +1,456 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_mtp_storage.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides all the transfer command functions for MTP
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_mtp_storage.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
static MTP_DataLengthTypeDef MTP_DataLength;
|
||||
static MTP_READ_DATA_STATUS ReadDataStatus;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static uint8_t USBD_MTP_STORAGE_DecodeOperations(USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_MTP_STORAGE_ReceiveContainer(USBD_HandleTypeDef *pdev, uint32_t *pDst, uint32_t len);
|
||||
static uint8_t USBD_MTP_STORAGE_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf, uint32_t len);
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_Init
|
||||
* Initialize the MTP USB Layer
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_Init(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* Initialize the HW layyer of the file system */
|
||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
|
||||
/* Prepare EP to Receive First Operation */
|
||||
(void)USBD_LL_PrepareReceive(pdev, MTP_OUT_EP, (uint8_t *)&hmtp->rx_buff,
|
||||
hmtp->MaxPcktLen);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_DeInit
|
||||
* Uninitialize the MTP Machine
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
hmtp->MTP_SessionState = MTP_SESSION_NOT_OPENED;
|
||||
|
||||
/* Stop low layer file system operations if any */
|
||||
USBD_MTP_STORAGE_Cancel(pdev, MTP_PHASE_IDLE);
|
||||
|
||||
/* Free low layer file system resources */
|
||||
(void)((USBD_MTP_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_ReadData
|
||||
* Read data from device objects and send it to the host
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_ReadData(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t *data_buff;
|
||||
|
||||
/* Get the data buffer pointer from the low layer interface */
|
||||
data_buff = ((USBD_MTP_ItfTypeDef *)pdev->pUserData)->ScratchBuff;
|
||||
|
||||
switch (ReadDataStatus)
|
||||
{
|
||||
case READ_FIRST_DATA:
|
||||
/* Reset the data length */
|
||||
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 */
|
||||
(void)USBD_memcpy((uint8_t *)data_buff, (uint8_t *)&hmtp->GenericContainer, MTP_CONT_HEADER_SIZE);
|
||||
|
||||
/* Start USB data transmission to the host */
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff,
|
||||
MTP_DataLength.readbytes + MTP_CONT_HEADER_SIZE);
|
||||
|
||||
/* Check if this will be the last packet to send ? */
|
||||
if (MTP_DataLength.readbytes < ((uint32_t)hmtp->MaxPcktLen - MTP_CONT_HEADER_SIZE))
|
||||
{
|
||||
/* Move to response phase */
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Continue to the next packets sending */
|
||||
ReadDataStatus = READ_REST_OF_DATA;
|
||||
}
|
||||
break;
|
||||
|
||||
case READ_REST_OF_DATA:
|
||||
/* 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);
|
||||
|
||||
/* Check if more data need to be sent */
|
||||
if (MTP_DataLength.temp_length == MTP_DataLength.totallen)
|
||||
{
|
||||
/* Start USB data transmission to the host */
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MTP_DataLength.readbytes);
|
||||
|
||||
/* Move to response phase */
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
|
||||
/* Reset the stat machine */
|
||||
ReadDataStatus = READ_FIRST_DATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Start USB data transmission to the host */
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)data_buff, MTP_DataLength.readbytes);
|
||||
|
||||
/* Keep the state machine into sending next packet of data */
|
||||
ReadDataStatus = READ_REST_OF_DATA;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_SendContainer
|
||||
* Send generic container to the host
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_SendContainer(USBD_HandleTypeDef *pdev, MTP_CONTAINER_TYPE CONT_TYPE)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
switch (CONT_TYPE)
|
||||
{
|
||||
case DATA_TYPE:
|
||||
/* send header + data : hmtp->ResponseLength = header size + data size */
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, hmtp->ResponseLength);
|
||||
break;
|
||||
case REP_TYPE:
|
||||
/* send header without data */
|
||||
hmtp->GenericContainer.code = (uint16_t)hmtp->ResponseCode;
|
||||
hmtp->ResponseLength = MTP_CONT_HEADER_SIZE;
|
||||
hmtp->GenericContainer.length = hmtp->ResponseLength;
|
||||
hmtp->GenericContainer.type = MTP_CONT_TYPE_RESPONSE;
|
||||
|
||||
(void)USBD_MTP_STORAGE_SendData(pdev, (uint8_t *)&hmtp->GenericContainer, hmtp->ResponseLength);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_ReceiveOpt
|
||||
* Data length Packet Received from host
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_ReceiveOpt(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t *pMsgBuffer;
|
||||
MTP_DataLength.rx_length = USBD_GetRxCount(pdev, MTP_OUT_EP);
|
||||
switch (hmtp->RECEIVE_DATA_STATUS)
|
||||
{
|
||||
case RECEIVE_REST_OF_DATA:
|
||||
/* we don't need to do anything here because we receive only data without operation header*/
|
||||
break;
|
||||
|
||||
case RECEIVE_FIRST_DATA:
|
||||
/* Expected Data Length Packet Received */
|
||||
pMsgBuffer = (uint32_t *) &hmtp->OperationsContainer;
|
||||
|
||||
/* Fill hmtp->OperationsContainer Data Buffer from USB Buffer */
|
||||
(void)USBD_MTP_STORAGE_ReceiveContainer(pdev, pMsgBuffer, MTP_DataLength.rx_length);
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Expected Data Length Packet Received */
|
||||
pMsgBuffer = (uint32_t *) &hmtp->OperationsContainer;
|
||||
|
||||
/* Fill hmtp->OperationsContainer Data Buffer from USB Buffer */
|
||||
(void)USBD_MTP_STORAGE_ReceiveContainer(pdev, pMsgBuffer, MTP_DataLength.rx_length);
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
break;
|
||||
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_ReceiveData
|
||||
* Receive objects or object info from host
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
uint8_t USBD_MTP_STORAGE_ReceiveData(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
switch (hmtp->RECEIVE_DATA_STATUS)
|
||||
{
|
||||
case RECEIVE_COMMAND_DATA :
|
||||
if (hmtp->OperationsContainer.type == MTP_CONT_TYPE_COMMAND)
|
||||
{
|
||||
MTP_DataLength.temp_length = 0;
|
||||
MTP_DataLength.prv_len = 0;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case RECEIVE_FIRST_DATA :
|
||||
if (hmtp->OperationsContainer.type == MTP_CONT_TYPE_DATA)
|
||||
{
|
||||
MTP_DataLength.totallen = hmtp->OperationsContainer.length;
|
||||
MTP_DataLength.temp_length = MTP_DataLength.rx_length;
|
||||
MTP_DataLength.rx_length = MTP_DataLength.temp_length - MTP_CONT_HEADER_SIZE;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
|
||||
if (MTP_DataLength.temp_length < hmtp->MaxPcktLen) /* we received all data, we don't need to go to next state */
|
||||
{
|
||||
hmtp->RECEIVE_DATA_STATUS = SEND_RESPONSE;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
|
||||
/* send response header after receiving all data successfully */
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, DATA_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RECEIVE_REST_OF_DATA :
|
||||
MTP_DataLength.prv_len = MTP_DataLength.temp_length - MTP_CONT_HEADER_SIZE;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
MTP_DataLength.temp_length = MTP_DataLength.temp_length + MTP_DataLength.rx_length;
|
||||
|
||||
if (MTP_DataLength.temp_length == MTP_DataLength.totallen) /* we received all data*/
|
||||
{
|
||||
hmtp->RECEIVE_DATA_STATUS = SEND_RESPONSE;
|
||||
(void)USBD_MTP_STORAGE_DecodeOperations(pdev);
|
||||
|
||||
/* send response header after receiving all data successfully */
|
||||
(void)USBD_MTP_STORAGE_SendContainer(pdev, DATA_TYPE);
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_DecodeOperations
|
||||
* Parse the operations and Process operations
|
||||
* @param pdev: device instance
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_STORAGE_DecodeOperations(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
switch (hmtp->OperationsContainer.code)
|
||||
{
|
||||
case MTP_OP_GET_DEVICE_INFO:
|
||||
USBD_MTP_OPT_GetDeviceInfo(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_OPEN_SESSION:
|
||||
USBD_MTP_OPT_CreateObjectHandle(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_STORAGE_IDS:
|
||||
USBD_MTP_OPT_GetStorageIDS(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_STORAGE_INFO:
|
||||
USBD_MTP_OPT_GetStorageInfo(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_HANDLES:
|
||||
USBD_MTP_OPT_GetObjectHandle(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_INFO:
|
||||
USBD_MTP_OPT_GetObjectInfo(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROP_REFERENCES:
|
||||
USBD_MTP_OPT_GetObjectReferences(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROPS_SUPPORTED:
|
||||
USBD_MTP_OPT_GetObjectPropSupp(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROP_DESC:
|
||||
USBD_MTP_OPT_GetObjectPropDesc(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROPLIST:
|
||||
USBD_MTP_OPT_GetObjectPropList(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT_PROP_VALUE:
|
||||
USBD_MTP_OPT_GetObjectPropValue(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_DEVICE_PROP_DESC:
|
||||
USBD_MTP_OPT_GetDevicePropDesc(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
case MTP_OP_GET_OBJECT:
|
||||
USBD_MTP_OPT_GetObject(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_READ_DATA;
|
||||
break;
|
||||
|
||||
case MTP_OP_SEND_OBJECT_INFO:
|
||||
USBD_MTP_OPT_SendObjectInfo(pdev, (uint8_t *)(hmtp->rx_buff), MTP_DataLength.prv_len);
|
||||
hmtp->MTP_ResponsePhase = MTP_RECEIVE_DATA;
|
||||
break;
|
||||
|
||||
case MTP_OP_SEND_OBJECT:
|
||||
USBD_MTP_OPT_SendObject(pdev, (uint8_t *)(hmtp->rx_buff), MTP_DataLength.rx_length);
|
||||
hmtp->MTP_ResponsePhase = MTP_RECEIVE_DATA;
|
||||
break;
|
||||
|
||||
case MTP_OP_DELETE_OBJECT:
|
||||
USBD_MTP_OPT_DeleteObject(pdev);
|
||||
hmtp->MTP_ResponsePhase = MTP_RESPONSE_PHASE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_ReceiveContainer
|
||||
* Receive the Data from USB BulkOut Buffer to Pointer
|
||||
* @param pdev: device instance
|
||||
* @param pDst: destination address to copy the buffer
|
||||
* @param len: length of data to copy
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_STORAGE_ReceiveContainer(USBD_HandleTypeDef *pdev,
|
||||
uint32_t *pDst, uint32_t len)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t Counter;
|
||||
uint32_t *pdst = pDst;
|
||||
|
||||
for (Counter = 0; Counter < len; Counter++)
|
||||
{
|
||||
*pdst = (hmtp->rx_buff[Counter]);
|
||||
pdst++;
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_Cancel
|
||||
* Reinitialize all states and cancel transfer through Bulk transfer
|
||||
* @param pdev: device instance
|
||||
* @param MTP_ResponsePhase: MTP current state
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_MTP_STORAGE_Cancel(USBD_HandleTypeDef *pdev,
|
||||
MTP_ResponsePhaseTypeDef MTP_ResponsePhase)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmtp->MTP_ResponsePhase = MTP_PHASE_IDLE;
|
||||
ReadDataStatus = READ_FIRST_DATA;
|
||||
hmtp->RECEIVE_DATA_STATUS = RECEIVE_IDLE_STATE;
|
||||
|
||||
if (MTP_ResponsePhase == MTP_RECEIVE_DATA)
|
||||
{
|
||||
((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Cancel(1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
((USBD_MTP_ItfTypeDef *)pdev->pUserData)->Cancel(0U);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MTP_STORAGE_SendData
|
||||
* Send the data on bulk-in EP
|
||||
* @param pdev: device instance
|
||||
* @param buf: pointer to data buffer
|
||||
* @param len: Data Length
|
||||
* @retval status value
|
||||
*/
|
||||
static uint8_t USBD_MTP_STORAGE_SendData(USBD_HandleTypeDef *pdev, uint8_t *buf,
|
||||
uint32_t len)
|
||||
{
|
||||
USBD_MTP_HandleTypeDef *hmtp = (USBD_MTP_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t length = MIN(hmtp->GenericContainer.length, len);
|
||||
|
||||
(void)USBD_LL_Transmit(pdev, MTP_IN_EP, buf, length);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
162
Class/Printer/Inc/usbd_printer.h
Normal file
162
Class/Printer/Inc/usbd_printer.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_printer.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_printer.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 __USB_PRNT_H
|
||||
#define __USB_PRNT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup usbd_PRNT
|
||||
* @brief This file is the Header file for usbd_PRNT.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup usbd_PRNT_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#ifndef PRNT_IN_EP
|
||||
#define PRNT_IN_EP 0x81U /* Default: EP1 for data IN */
|
||||
#endif /* PRNT_IN_EP */
|
||||
|
||||
#ifndef PRNT_OUT_EP
|
||||
#define PRNT_OUT_EP 0x01U /* Default: EP1 for data OUT */
|
||||
#endif /* PRNT_OUT_EP */
|
||||
|
||||
#ifndef PRNT_DATA_HS_MAX_PACKET_SIZE
|
||||
#define PRNT_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
||||
#endif /* PRNT_DATA_HS_MAX_PACKET_SIZE */
|
||||
|
||||
#ifndef PRNT_DATA_FS_MAX_PACKET_SIZE
|
||||
#define PRNT_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||
#endif /* PRNT_DATA_FS_MAX_PACKET_SIZE */
|
||||
|
||||
#define USB_PRNT_CONFIG_DESC_SIZ 32U
|
||||
#define PRNT_DATA_HS_IN_PACKET_SIZE PRNT_DATA_HS_MAX_PACKET_SIZE
|
||||
#define PRNT_DATA_HS_OUT_PACKET_SIZE PRNT_DATA_HS_MAX_PACKET_SIZE
|
||||
|
||||
#define PRNT_DATA_FS_IN_PACKET_SIZE PRNT_DATA_FS_MAX_PACKET_SIZE
|
||||
#define PRNT_DATA_FS_OUT_PACKET_SIZE PRNT_DATA_FS_MAX_PACKET_SIZE
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* PRNT definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
#define PRNT_STATUS_PAPER_EMPTY 0x10U
|
||||
#define PRNT_STATUS_SELECTED 0x08U
|
||||
#define PRNT_STATUS_NO_ERROR 0x00U
|
||||
|
||||
#define USB_PRNT_SUBCLASS 0x01U
|
||||
|
||||
#define USB_PRNT_UNIDIRECTIONAL 0x01U
|
||||
#define USB_PRNT_BIDIRECTIONAL 0x02U
|
||||
|
||||
/* USB PRNT Request types */
|
||||
#define PRNT_GET_DEVICE_ID 0x00U
|
||||
#define PRNT_GET_PORT_STATUS 0x01U
|
||||
#define PRNT_SOFT_RESET 0x02U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
typedef struct _USBD_PRNT_Itf
|
||||
{
|
||||
int8_t (* Init)(void);
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* Control_req)(uint8_t req, uint8_t *pbuf, uint16_t *length);
|
||||
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||
|
||||
} USBD_PRNT_ItfTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t data[PRNT_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32-bit alignment */
|
||||
uint8_t CmdOpCode;
|
||||
uint8_t CmdLength;
|
||||
uint8_t *RxBuffer;
|
||||
uint8_t *TxBuffer;
|
||||
uint32_t RxLength;
|
||||
uint32_t TxLength;
|
||||
|
||||
__IO uint32_t TxState;
|
||||
__IO uint32_t RxState;
|
||||
}
|
||||
USBD_PRNT_HandleTypeDef;
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_PRNT;
|
||||
#define USBD_PRNT_CLASS &USBD_PRNT
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_PRNT_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_PRNT_ItfTypeDef *fops);
|
||||
uint8_t USBD_PRNT_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
||||
uint8_t USBD_PRNT_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_PRNT_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
43
Class/Printer/Inc/usbd_printer_if_template.h
Normal file
43
Class/Printer/Inc/usbd_printer_if_template.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_printer_if_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header for usbd_PRNT_if_template.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_PRNT_IF_TEMPLATE_H
|
||||
#define __USBD_PRNT_IF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_printer.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
extern USBD_PRNT_ItfTypeDef USBD_PRNT_Template_fops;
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_PRNT_IF_TEMPLATE_H */
|
||||
|
||||
671
Class/Printer/Src/usbd_printer.c
Normal file
671
Class/Printer/Src/usbd_printer.c
Normal file
@@ -0,0 +1,671 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_printer.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the high layer firmware functions to manage the
|
||||
* following functionalities of the USB printer Class:
|
||||
* - Initialization and Configuration of high and low layer
|
||||
* - Enumeration as printer Device (and enumeration for each implemented memory interface)
|
||||
* - OUT data transfer
|
||||
* - Command OUT transfer (class requests management)
|
||||
* - Error management
|
||||
*
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* PRINTER Class Driver Description
|
||||
* ===================================================================
|
||||
* This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
|
||||
* Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
|
||||
* printer Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Enumeration as printer device with 2 data endpoints (IN and OUT)
|
||||
* - Control Requests management (PRNT_GET_DEVICE_ID,PRNT_GET_PORT_STATUS,PRNT_SOFT_RESET)
|
||||
* - protocol USB_PRNT_BIDIRECTIONAL
|
||||
*
|
||||
*
|
||||
*
|
||||
* These aspects may be enriched or modified for a specific user application.
|
||||
*
|
||||
* This driver doesn't implement the following aspects of the specification
|
||||
* (but it is possible to manage these features with some modifications on this driver):
|
||||
* - Any class-specific aspect relative to communication classes should be managed by user application.
|
||||
* - All communication classes other than PSTN are not managed
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_printer.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_PRNT
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
static uint32_t usbd_PRNT_altset = 0U;
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static uint8_t USBD_PRNT_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
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_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
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_GetHSCfgDesc(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);
|
||||
|
||||
/* 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,
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* PRNT interface class callbacks structure */
|
||||
USBD_ClassTypeDef USBD_PRNT =
|
||||
{
|
||||
USBD_PRNT_Init,
|
||||
USBD_PRNT_DeInit,
|
||||
USBD_PRNT_Setup,
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_PRNT_DataIn,
|
||||
USBD_PRNT_DataOut,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_PRNT_GetHSCfgDesc,
|
||||
USBD_PRNT_GetFSCfgDesc,
|
||||
USBD_PRNT_GetOtherSpeedCfgDesc,
|
||||
USBD_PRNT_GetDeviceQualifierDescriptor,
|
||||
};
|
||||
|
||||
/* USB PRNT device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_PRNT_CfgHSDesc[] __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 */
|
||||
|
||||
/* 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 */
|
||||
|
||||
/*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 */
|
||||
};
|
||||
|
||||
__ALIGN_BEGIN static uint8_t USBD_PRNT_OtherSpeedCfgDesc[] __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 */
|
||||
|
||||
/*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 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_Init
|
||||
* Initialize the PRNT interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_PRNT_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
USBD_PRNT_HandleTypeDef *hPRNT;
|
||||
uint16_t mps;
|
||||
hPRNT = (USBD_PRNT_HandleTypeDef *)USBD_malloc(sizeof(USBD_PRNT_HandleTypeDef));
|
||||
|
||||
if (hPRNT == NULL)
|
||||
{
|
||||
pdev->pClassData = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
/* Setup the pClassData pointer */
|
||||
pdev->pClassData = (void *)hPRNT;
|
||||
|
||||
/* Setup the max packet size according to selected speed */
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
mps = PRNT_DATA_HS_IN_PACKET_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
mps = PRNT_DATA_FS_IN_PACKET_SIZE;
|
||||
}
|
||||
|
||||
/* Open EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, PRNT_IN_EP, USBD_EP_TYPE_BULK, mps);
|
||||
|
||||
/* Set endpoint as used */
|
||||
pdev->ep_in[PRNT_IN_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP OUT */
|
||||
(void)USBD_LL_OpenEP(pdev, PRNT_OUT_EP, USBD_EP_TYPE_BULK, mps);
|
||||
|
||||
/* Set endpoint as used */
|
||||
pdev->ep_out[PRNT_OUT_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Init physical Interface components */
|
||||
((USBD_PRNT_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
(void)USBD_LL_PrepareReceive(pdev, PRNT_OUT_EP, hPRNT->RxBuffer, mps);
|
||||
|
||||
/* End of initialization phase */
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_DeInit
|
||||
* DeInitialize the PRNT layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_PRNT_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
/* Close EP IN */
|
||||
(void)USBD_LL_CloseEP(pdev, PRNT_IN_EP);
|
||||
pdev->ep_in[PRNT_IN_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP OUT */
|
||||
(void)USBD_LL_CloseEP(pdev, PRNT_OUT_EP);
|
||||
pdev->ep_out[PRNT_OUT_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_PRNT_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
(void)USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_Setup
|
||||
* Handle the PRNT specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_PRNT_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassData;
|
||||
USBD_PRNT_ItfTypeDef *hPRNTitf = (USBD_PRNT_ItfTypeDef *)pdev->pUserData;
|
||||
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
uint16_t status_info = 0U;
|
||||
uint16_t data_length;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
if (req->wLength != 0U)
|
||||
{
|
||||
data_length = MIN(req->wLength, PRNT_DATA_HS_MAX_PACKET_SIZE);
|
||||
|
||||
if ((req->bmRequest & 0x80U) != 0U)
|
||||
{
|
||||
/* Call the User class interface function to process the command */
|
||||
hPRNTitf->Control_req(req->bRequest, (uint8_t *)hPRNT->data, &data_length);
|
||||
|
||||
/* Return the answer to host */
|
||||
(void) USBD_CtlSendData(pdev, (uint8_t *)hPRNT->data, data_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare for control data reception */
|
||||
(void) USBD_CtlPrepareRx(pdev, (uint8_t *)hPRNT->data, data_length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data_length = 0U;
|
||||
hPRNTitf->Control_req(req->bRequest, (uint8_t *)req, &data_length);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&usbd_PRNT_altset, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_DataIn
|
||||
* Data sent on non-control IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_PRNT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassData;
|
||||
PCD_HandleTypeDef *hpcd = pdev->pData;
|
||||
|
||||
if (hPRNT == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
if ((pdev->ep_in[epnum].total_length > 0U) &&
|
||||
((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
|
||||
{
|
||||
/* Update the packet total length */
|
||||
pdev->ep_in[epnum].total_length = 0U;
|
||||
|
||||
/* Send ZLP */
|
||||
(void) USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||
}
|
||||
else
|
||||
{
|
||||
hPRNT->TxState = 0U;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_PRNT_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_PRNT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (hPRNT == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Get the received data length */
|
||||
hPRNT->RxLength = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||
|
||||
/* USB data will be immediately processed, this allow next USB traffic being
|
||||
NAKed till the end of the application Xfer */
|
||||
((USBD_PRNT_ItfTypeDef *)pdev->pUserData)->Receive(hPRNT->RxBuffer, &hPRNT->RxLength);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_GetFSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_PRNT_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t) sizeof(USBD_PRNT_CfgFSDesc);
|
||||
return USBD_PRNT_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_GetHSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_PRNT_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t) sizeof(USBD_PRNT_CfgHSDesc);
|
||||
return USBD_PRNT_CfgHSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_GetOtherSpeedCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_PRNT_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t) sizeof(USBD_PRNT_OtherSpeedCfgDesc);
|
||||
return USBD_PRNT_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_GetDeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_PRNT_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_PRNT_DeviceQualifierDesc);
|
||||
return USBD_PRNT_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: Interface callbacks
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_PRNT_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_PRNT_ItfTypeDef *fops)
|
||||
{
|
||||
/* Check if the fops pointer is valid */
|
||||
if (fops == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Setup the fops pointer */
|
||||
pdev->pUserData = fops;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_SetRxBuffer
|
||||
* @param pdev: device instance
|
||||
* @param pbuff: Rx Buffer
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_PRNT_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
||||
{
|
||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
hPRNT->RxBuffer = pbuff;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_PRNT_ReceivePacket
|
||||
* prepare OUT Endpoint for reception
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_PRNT_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_PRNT_HandleTypeDef *hPRNT = (USBD_PRNT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (hPRNT == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
(void)USBD_LL_PrepareReceive(pdev, PRNT_OUT_EP, hPRNT->RxBuffer,
|
||||
PRNT_DATA_HS_OUT_PACKET_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
(void)USBD_LL_PrepareReceive(pdev, PRNT_OUT_EP, hPRNT->RxBuffer,
|
||||
PRNT_DATA_FS_OUT_PACKET_SIZE);
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
206
Class/Printer/Src/usbd_printer_if_template.c
Normal file
206
Class/Printer/Src/usbd_printer_if_template.c
Normal file
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_printer_if_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief Generic media access Layer.
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_printer_if_template.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_PRNT
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_PRNT_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static int8_t TEMPLATE_Init(void);
|
||||
static int8_t TEMPLATE_DeInit(void);
|
||||
static int8_t TEMPLATE_Control_req(uint8_t req, uint8_t *pbuf, uint16_t *length);
|
||||
static int8_t TEMPLATE_Receive(uint8_t *pbuf, uint32_t *Len);
|
||||
|
||||
/*printer Private function prototypes*/
|
||||
void TEMPLATE_PRNT_PageEndManager(uint8_t *Buf, uint32_t Len);
|
||||
|
||||
USBD_PRNT_ItfTypeDef USBD_PRNT_Template_fops =
|
||||
{
|
||||
TEMPLATE_Init,
|
||||
TEMPLATE_DeInit,
|
||||
TEMPLATE_Control_req,
|
||||
TEMPLATE_Receive
|
||||
};
|
||||
|
||||
static uint8_t PRNT_DEVICE_ID[] =
|
||||
{
|
||||
0x00, 0x6D,
|
||||
'M', 'A', 'N', 'U', 'F', 'A', 'C', 'T', 'U', 'R', 'E', 'R', ':',
|
||||
'S', 'T', 'M', 'i', 'c', 'r', 'o', 'e', 'l', 'e', 'c', 't', 'r', 'o', 'n', 'i', 'c', 's', ';',
|
||||
'C', 'O', 'M', 'M', 'A', 'N', 'D', ' ', 'S', 'E', 'T', ':',
|
||||
'P', 'D', 'L', ',', 'P', 'C', 'P', ';',
|
||||
'M', 'O', 'D', 'E', 'L', ':',
|
||||
'U', 'S', 'B', 'P', 'r', 'i', 'n', 't', 'e', 'r', ';',
|
||||
'C', 'O', 'M', 'M', 'E', 'N', 'T', ':',
|
||||
'G', 'o', 'o', 'd', ' ', '!', ';',
|
||||
'A', 'C', 'T', 'I', 'V', 'E', ' ', 'C', 'O', 'M', 'M', 'A', 'N', 'D', ' ', 'S', 'E', 'T', ':',
|
||||
'P', 'C', 'P', ';'
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_Init
|
||||
* Initializes the PRNT media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_Init(void)
|
||||
{
|
||||
/*
|
||||
Add your initialization code here
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_DeInit
|
||||
* DeInitializes the PRNT media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_DeInit(void)
|
||||
{
|
||||
/*
|
||||
Add your deinitialization code here
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_Receive
|
||||
* Data received over USB OUT endpoint are sent over PRNT interface
|
||||
* through this function.
|
||||
*
|
||||
* @note
|
||||
* This function will issue a NAK packet on any OUT packet received on
|
||||
* USB endpoint until exiting this function. If you exit this function
|
||||
* before transfer is complete on PRNT interface (ie. using DMA controller)
|
||||
* it will result in receiving more data while previous ones are still
|
||||
* not sent.
|
||||
*
|
||||
* @param Buf: Buffer of data to be received
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len)
|
||||
{
|
||||
UNUSED(Buf);
|
||||
UNUSED(Len);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_Control_req
|
||||
* Manage the PRNT class requests
|
||||
* @param req: Command code
|
||||
* @param pbuf: Buffer containing command data (request parameters)
|
||||
* @param length: Number of data to be sent (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_Control_req(uint8_t req, uint8_t *pbuf, uint16_t *length)
|
||||
{
|
||||
uint32_t i = 0U;
|
||||
|
||||
/* Check on the setup request value */
|
||||
switch (req)
|
||||
{
|
||||
/* Get Printer Device ID request */
|
||||
case PRNT_GET_DEVICE_ID:
|
||||
/* Not using for loop here due to MISRA-C2012-Rule-16.1 */
|
||||
while (i < sizeof(PRNT_DEVICE_ID))
|
||||
{
|
||||
pbuf[i] = PRNT_DEVICE_ID[i];
|
||||
i++;
|
||||
}
|
||||
*length = (uint16_t)i;
|
||||
break;
|
||||
|
||||
/* Get Printer current status */
|
||||
case PRNT_GET_PORT_STATUS:
|
||||
pbuf[0] = PRNT_STATUS_PAPER_EMPTY |
|
||||
PRNT_STATUS_SELECTED |
|
||||
PRNT_STATUS_NO_ERROR;
|
||||
|
||||
*length = 1U;
|
||||
break;
|
||||
|
||||
/* Printer SOFT RESET request: cleanup pending tasks */
|
||||
case PRNT_SOFT_RESET:
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Unknown commands are not managed */
|
||||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -41,10 +40,10 @@ extern "C" {
|
||||
/** @defgroup USBD_TEMPLATE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define TEMPLATE_EPIN_ADDR 0x81
|
||||
#define TEMPLATE_EPIN_SIZE 0x10
|
||||
#define TEMPLATE_EPIN_ADDR 0x81U
|
||||
#define TEMPLATE_EPIN_SIZE 0x10U
|
||||
|
||||
#define USB_TEMPLATE_CONFIG_DESC_SIZ 64
|
||||
#define USB_TEMPLATE_CONFIG_DESC_SIZ 64U
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -73,7 +72,7 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver;
|
||||
extern USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -97,5 +96,3 @@ extern USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -4,6 +4,17 @@
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the HID core functions.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2015 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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
@@ -22,17 +33,6 @@
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -83,33 +83,19 @@
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev);
|
||||
static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -118,7 +104,7 @@ static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver =
|
||||
USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver =
|
||||
{
|
||||
USBD_TEMPLATE_Init,
|
||||
USBD_TEMPLATE_DeInit,
|
||||
@@ -140,9 +126,9 @@ USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver =
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
/* USB TEMPLATE device Configuration Descriptor */
|
||||
static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] =
|
||||
__ALIGN_BEGIN static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuation Descriptor size */
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_TEMPLATE_CONFIG_DESC_SIZ,
|
||||
/* wTotalLength: Bytes returned */
|
||||
@@ -162,7 +148,7 @@ static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] =
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
/* USB Standard Device Descriptor */
|
||||
static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] =
|
||||
__ALIGN_BEGIN static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
@@ -191,13 +177,10 @@ static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] =
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
|
||||
|
||||
return ret;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,11 +190,10 @@ static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev,
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,8 +203,8 @@ static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
@@ -254,35 +236,33 @@ static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return (uint8_t)ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_TEMPLATE_GetCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length)
|
||||
static uint8_t *USBD_TEMPLATE_GetCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_TEMPLATE_CfgDesc);
|
||||
*length = (uint16_t)sizeof(USBD_TEMPLATE_CfgDesc);
|
||||
return USBD_TEMPLATE_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor(uint16_t *length)
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
||||
*length = (uint16_t)sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
||||
return USBD_TEMPLATE_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_TEMPLATE_DataIn
|
||||
* handle data IN Stage
|
||||
@@ -290,11 +270,10 @@ uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor(uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,33 +282,36 @@ static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev,
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_TEMPLATE_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_TEMPLATE_EP0_TxReady
|
||||
* handle EP0 TRx Ready event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_TEMPLATE_SOF
|
||||
* handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_TEMPLATE_IsoINIncomplete
|
||||
* handle data ISO IN Incomplete event
|
||||
@@ -337,11 +319,12 @@ static uint8_t USBD_TEMPLATE_SOF(USBD_HandleTypeDef *pdev)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_TEMPLATE_IsoOutIncomplete
|
||||
* handle data ISO OUT Incomplete event
|
||||
@@ -349,10 +332,10 @@ static uint8_t USBD_TEMPLATE_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @brief USBD_TEMPLATE_DataOut
|
||||
@@ -361,22 +344,22 @@ static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return 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)
|
||||
* @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 = sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
||||
*length = (uint16_t)sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
||||
|
||||
return USBD_TEMPLATE_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
@@ -393,5 +376,3 @@ uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
458
Class/VIDEO/Inc/usbd_video.h
Normal file
458
Class/VIDEO/Inc/usbd_video.h
Normal file
@@ -0,0 +1,458 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_video.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_video.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2020 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_VIDEO_H
|
||||
#define __USBD_VIDEO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO
|
||||
* @brief This file is the Header file for usbd_video.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup usbd_VIDEO_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USB Video device class specification version 1.10 */
|
||||
#ifdef UVC_1_0
|
||||
#define UVC_VERSION 0x0100U /* UVC 1.0 */
|
||||
#else
|
||||
#define UVC_VERSION 0x0110U /* UVC 1.1 */
|
||||
#endif
|
||||
|
||||
/* bEndpointAddress in Endpoint Descriptor */
|
||||
#ifndef UVC_IN_EP
|
||||
#define UVC_IN_EP 0x81U
|
||||
#endif /* VIDEO_IN_EP */
|
||||
|
||||
/* These defines shall be updated in the usbd_conf.h file */
|
||||
#ifndef UVC_WIDTH
|
||||
#define UVC_WIDTH 400U
|
||||
#endif /* UVC_WIDTH */
|
||||
|
||||
#ifndef UVC_HEIGHT
|
||||
#define UVC_HEIGHT 240U
|
||||
#endif /* UVC_HEIGHT */
|
||||
|
||||
#ifndef UVC_CAM_FPS_FS
|
||||
#define UVC_CAM_FPS_FS 10U
|
||||
#endif /* UVC_CAM_FPS_FS */
|
||||
|
||||
#ifndef UVC_CAM_FPS_HS
|
||||
#define UVC_CAM_FPS_HS 5U
|
||||
#endif /* UVC_CAM_FPS_HS */
|
||||
|
||||
#ifndef UVC_PACKET_SIZE
|
||||
#define UVC_PACKET_SIZE 512U
|
||||
#endif /* UVC_PACKET_SIZE */
|
||||
|
||||
#ifndef UVC_MAX_FRAME_SIZE
|
||||
#define UVC_MAX_FRAME_SIZE (UVC_WIDTH * UVC_HEIGHT * 16U / 2U)
|
||||
#endif /* UVC_MAX_FRAME_SIZE */
|
||||
|
||||
#ifndef UVC_COLOR_PRIMARIE
|
||||
#define UVC_COLOR_PRIMARIE 0x01U
|
||||
#endif /* UVC_COLOR_PRIMARIE */
|
||||
|
||||
#ifndef UVC_TFR_CHARACTERISTICS
|
||||
#define UVC_TFR_CHARACTERISTICS 0x01U
|
||||
#endif /* UVC_TFR_CHARACTERISTICS */
|
||||
|
||||
#ifndef UVC_MATRIX_COEFFICIENTS
|
||||
#define UVC_MATRIX_COEFFICIENTS 0x04U
|
||||
#endif /* UVC_MATRIX_COEFFICIENTS */
|
||||
|
||||
#ifndef UVC_BITS_PER_PIXEL
|
||||
#define UVC_BITS_PER_PIXEL 12U
|
||||
#endif /* UVC_BITS_PER_PIXEL */
|
||||
|
||||
#define UVC_GUID_YUY2 0x32595559U
|
||||
#define UVC_GUID_NV12 0x3231564EU
|
||||
|
||||
#ifndef UVC_UNCOMPRESSED_GUID
|
||||
#define UVC_UNCOMPRESSED_GUID UVC_GUID_NV12
|
||||
#endif /* UVC_UNCOMPRESSED_GUID */
|
||||
|
||||
#define UVC_INTERVAL(n) (10000000U/(n))
|
||||
|
||||
#define UVC_MIN_BIT_RATE(n) (UVC_WIDTH * UVC_HEIGHT * 16U * (n)) /* 16 bit */
|
||||
#define UVC_MAX_BIT_RATE(n) (UVC_WIDTH * UVC_HEIGHT * 16U * (n)) /* 16 bit */
|
||||
|
||||
#define UVC_PACKETS_IN_FRAME(n) (UVC_MAX_FRAME_SIZE / (n))
|
||||
|
||||
#ifndef UVC_ISO_FS_MPS
|
||||
#define UVC_ISO_FS_MPS 256U
|
||||
#endif
|
||||
|
||||
#ifndef UVC_ISO_HS_MPS
|
||||
#define UVC_ISO_HS_MPS 512U
|
||||
#endif
|
||||
|
||||
#ifndef UVC_HEADER_PACKET_CNT
|
||||
#define UVC_HEADER_PACKET_CNT 0x01U
|
||||
#endif
|
||||
|
||||
|
||||
#define UVC_REQ_READ_MASK 0x80U
|
||||
#define UVC_VC_IF_NUM 0x00U
|
||||
#define UVC_VS_IF_NUM 0x01U
|
||||
#define UVC_TOTAL_IF_NUM 0x02U
|
||||
|
||||
#ifdef USBD_UVC_FORMAT_UNCOMPRESSED
|
||||
#define UVC_CONFIG_DESC_SIZ (0x88U + 0x16U)
|
||||
#else
|
||||
#define UVC_CONFIG_DESC_SIZ 0x88U
|
||||
#endif
|
||||
|
||||
#define UVC_TOTAL_BUF_SIZE 0x04U
|
||||
|
||||
#define UVC_VC_EP_DESC_SIZE 0x05U
|
||||
#define UVC_STREAMING_EP_DESC_SIZE 0x07U
|
||||
#define UVC_EP_DESC_TYPE 0x25U
|
||||
|
||||
/* Video Interface Class Codes*/
|
||||
#define UVC_CC_VIDEO 0x0EU
|
||||
|
||||
#define UVC_PLAY_STATUS_STOP 0x00U
|
||||
#define UVC_PLAY_STATUS_READY 0x01U
|
||||
#define UVC_PLAY_STATUS_STREAMING 0x02U
|
||||
|
||||
#ifndef WBVAL
|
||||
#define WBVAL(x) ((x) & 0xFFU),(((x) >> 8) & 0xFFU)
|
||||
#endif
|
||||
#ifndef DBVAL
|
||||
#define DBVAL(x) ((x)& 0xFFU),(((x) >> 8) & 0xFFU),(((x)>> 16) & 0xFFU),(((x) >> 24) & 0xFFU)
|
||||
#endif
|
||||
|
||||
/* Video Interface Protocol Codes */
|
||||
#define PC_PROTOCOL_UNDEFINED 0x00U
|
||||
|
||||
#define VIDEO_VC_IF_HEADER_DESC_SIZE 0x0DU
|
||||
#define VIDEO_IN_TERMINAL_DESC_SIZE 0x08U
|
||||
#define VIDEO_OUT_TERMINAL_DESC_SIZE 0x09U
|
||||
#define VIDEO_VS_IF_IN_HEADER_DESC_SIZE 0x0EU
|
||||
|
||||
#define VS_FORMAT_UNCOMPRESSED_DESC_SIZE 0x1BU
|
||||
#define VS_FORMAT_MJPEG_DESC_SIZE 0x0BU
|
||||
#define VS_FRAME_DESC_SIZE 0x1EU
|
||||
#define VS_COLOR_MATCHING_DESC_SIZE 0x06U
|
||||
|
||||
#ifdef USBD_UVC_FORMAT_UNCOMPRESSED
|
||||
#define VS_FORMAT_DESC_SIZE VS_FORMAT_UNCOMPRESSED_DESC_SIZE
|
||||
#define VS_FORMAT_SUBTYPE VS_FORMAT_UNCOMPRESSED
|
||||
#define VS_FRAME_SUBTYPE VS_FRAME_UNCOMPRESSED
|
||||
|
||||
#define VC_HEADER_SIZE (VIDEO_VS_IF_IN_HEADER_DESC_SIZE + \
|
||||
VS_FORMAT_UNCOMPRESSED_DESC_SIZE + \
|
||||
VS_FRAME_DESC_SIZE + \
|
||||
VS_COLOR_MATCHING_DESC_SIZE)
|
||||
#else
|
||||
#define VS_FORMAT_DESC_SIZE VS_FORMAT_MJPEG_DESC_SIZE
|
||||
#define VS_FORMAT_SUBTYPE VS_FORMAT_MJPEG
|
||||
#define VS_FRAME_SUBTYPE VS_FRAME_MJPEG
|
||||
|
||||
#define VC_HEADER_SIZE (VIDEO_VS_IF_IN_HEADER_DESC_SIZE + \
|
||||
VS_FORMAT_DESC_SIZE + \
|
||||
VS_FRAME_DESC_SIZE)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Video Class specification release 1.1
|
||||
* Appendix A. Video Device Class Codes defines
|
||||
*/
|
||||
|
||||
/* Video Interface Subclass values */
|
||||
#define SC_UNDEFINED 0x00U
|
||||
#define SC_VIDEOCONTROL 0x01U
|
||||
#define SC_VIDEOSTREAMING 0x02U
|
||||
#define SC_VIDEO_INTERFACE_COLLECTION 0x03U
|
||||
|
||||
/* Video Class-Specific Descriptor Types */
|
||||
#define CS_UNDEFINED 0x20U
|
||||
#define CS_DEVICE 0x21U
|
||||
#define CS_CONFIGURATION 0x22U
|
||||
#define CS_STRING 0x23U
|
||||
#define CS_INTERFACE 0x24U
|
||||
#define CS_ENDPOINT 0x25U
|
||||
|
||||
/* Video Class-Specific VideoControl Interface Descriptor Subtypes */
|
||||
#define VC_DESCRIPTOR_UNDEFINED 0x00U
|
||||
#define VC_HEADER 0x01U
|
||||
#define VC_INPUT_TERMINAL 0x02U
|
||||
#define VC_OUTPUT_TERMINAL 0x03U
|
||||
#define VC_SELECTOR_UNIT 0x04U
|
||||
#define VC_PROCESSING_UNIT 0x05U
|
||||
#define VC_EXTENSION_UNIT 0x06U
|
||||
|
||||
/* Video Class-Specific VideoStreaming Interface Descriptor Subtypes */
|
||||
#define VS_UNDEFINED 0x00U
|
||||
#define VS_INPUT_HEADER 0x01U
|
||||
#define VS_OUTPUT_HEADER 0x02U
|
||||
#define VS_STILL_IMAGE_FRAME 0x03U
|
||||
#define VS_FORMAT_UNCOMPRESSED 0x04U
|
||||
#define VS_FRAME_UNCOMPRESSED 0x05U
|
||||
#define VS_FORMAT_MJPEG 0x06U
|
||||
#define VS_FRAME_MJPEG 0x07U
|
||||
#define VS_FORMAT_MPEG2TS 0x0AU
|
||||
#define VS_FORMAT_DV 0x0CU
|
||||
#define VS_COLORFORMAT 0x0DU
|
||||
#define VS_FORMAT_FRAME_BASED 0x10U
|
||||
#define VS_FRAME_FRAME_BASED 0x11U
|
||||
#define VS_FORMAT_STREAM_BASED 0x12U
|
||||
|
||||
/* Video Class-Specific Request values */
|
||||
#define UVC_RQ_UNDEFINED 0x00U
|
||||
#define UVC_SET_CUR 0x01U
|
||||
#define UVC_GET_CUR 0x81U
|
||||
#define UVC_GET_MIN 0x82U
|
||||
#define UVC_GET_MAX 0x83U
|
||||
#define UVC_GET_RES 0x84U
|
||||
#define UVC_GET_LEN 0x85U
|
||||
#define UVC_GET_INFO 0x86U
|
||||
#define UVC_GET_DEF 0x87U
|
||||
|
||||
/* VideoControl Interface Control Selectors */
|
||||
#define VC_CONTROL_UNDEFINED 0x00U
|
||||
#define VC_VIDEO_POWER_MODE_CONTROL 0x01U
|
||||
#define VC_REQUEST_ERROR_CODE_CONTROL 0x02U
|
||||
|
||||
/* Request Error Code Control */
|
||||
#define UVC_NO_ERROR_ERR 0x00U
|
||||
#define UVC_NOT_READY_ERR 0x01U
|
||||
#define UVC_WRONG_STATE_ERR 0x02U
|
||||
#define UVC_POWER_ERR 0x03U
|
||||
#define UVC_OUT_OF_RANGE_ERR 0x04U
|
||||
#define UVC_INVALID_UNIT_ERR 0x05U
|
||||
#define UVC_INVALID_CONTROL_ERR 0x06U
|
||||
#define UVC_INVALID_REQUEST_ERR 0x07U
|
||||
#define UVC_UNKNOWN_ERR 0xFFU
|
||||
|
||||
/*Terminal Control Selectors*/
|
||||
#define TE_CONTROL_UNDEFINED 0x00U
|
||||
|
||||
/* Selector Unit Control Selectors */
|
||||
#define SU_CONTROL_UNDEFINED 0x00U
|
||||
#define SU_INPUT_SELECT_CONTROL 0x01U
|
||||
|
||||
/* Camera Terminal Control Selectors */
|
||||
#define CT_CONTROL_UNDEFINED 0x00U
|
||||
#define CT_SCANNING_MODE_CONTROL 0x01U
|
||||
#define CT_AE_MODE_CONTROL 0x02U
|
||||
#define CT_AE_PRIORITY_CONTROL 0x03U
|
||||
#define CT_EXPOSURE_TIME_ABSOLUTE_CONTROL 0x04U
|
||||
#define CT_EXPOSURE_TIME_RELATIVE_CONTROL 0x05U
|
||||
#define CT_FOCUS_ABSOLUTE_CONTROL 0x06U
|
||||
#define CT_FOCUS_RELATIVE_CONTROL 0x07U
|
||||
#define CT_FOCUS_AUTO_CONTROL 0x08U
|
||||
#define CT_IRIS_ABSOLUTE_CONTROL 0x09U
|
||||
#define CT_IRIS_RELATIVE_CONTROL 0x0AU
|
||||
#define CT_ZOOM_ABSOLUTE_CONTROL 0x0BU
|
||||
#define CT_ZOOM_RELATIVE_CONTROL 0x0CU
|
||||
#define CT_PANTILT_ABSOLUTE_CONTROL 0x0DU
|
||||
#define CT_PANTILT_RELATIVE_CONTROL 0x0EU
|
||||
#define CT_ROLL_ABSOLUTE_CONTROL 0x0FU
|
||||
#define CT_ROLL_RELATIVE_CONTROL 0x10U
|
||||
#define CT_PRIVACY_CONTROL 0x11U
|
||||
|
||||
/* Processing Unit Control Selectors */
|
||||
#define PU_CONTROL_UNDEFINED 0x00U
|
||||
#define PU_BACKLIGHT_COMPENSATION_CONTROL 0x01U
|
||||
#define PU_BRIGHTNESS_CONTROL 0x02U
|
||||
#define PU_CONTRAST_CONTROL 0x03U
|
||||
#define PU_GAIN_CONTROL 0x04U
|
||||
#define PU_POWER_LINE_FREQUENCY_CONTROL 0x05U
|
||||
#define PU_HUE_CONTROL 0x06U
|
||||
#define PU_SATURATION_CONTROL 0x07U
|
||||
#define PU_SHARPNESS_CONTROL 0x08U
|
||||
#define PU_GAMMA_CONTROL 0x09U
|
||||
#define PU_WHITE_BALANCE_TEMPERATURE_CONTROL 0x0AU
|
||||
#define PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL 0x0BU
|
||||
#define PU_WHITE_BALANCE_COMPONENT_CONTROL 0x0CU
|
||||
#define PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL 0x0DU
|
||||
#define PU_DIGITAL_MULTIPLIER_CONTROL 0x0EU
|
||||
#define PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL 0x0FU
|
||||
#define PU_HUE_AUTO_CONTROL 0x10U
|
||||
#define PU_ANALOG_VIDEO_STANDARD_CONTROL 0x11U
|
||||
#define PU_ANALOG_LOCK_STATUS_CONTROL 0x12U
|
||||
|
||||
/*Extension Unit Control Selectors */
|
||||
#define XU_CONTROL_UNDEFINED 0x00U
|
||||
|
||||
/* VideoStreaming Interface Control Selectors */
|
||||
#define VS_CONTROL_UNDEFINED 0x00U
|
||||
#define VS_PROBE_CONTROL 0x100U
|
||||
#define VS_COMMIT_CONTROL 0x200U
|
||||
#define VS_STILL_PROBE_CONTROL 0x03U
|
||||
#define VS_STILL_COMMIT_CONTROL 0x04U
|
||||
#define VS_STILL_IMAGE_TRIGGER_CONTROL 0x05U
|
||||
#define VS_STREAM_ERROR_CODE_CONTROL 0x06U
|
||||
#define VS_GENERATE_KEY_FRAME_CONTROL 0x07U
|
||||
#define VS_UPDATE_FRAME_SEGMENT_CONTROL 0x08U
|
||||
#define VS_SYNC_DELAY_CONTROL 0x09U
|
||||
|
||||
|
||||
/* Control Capabilities */
|
||||
#define UVC_SUPPORTS_GET 0x01U
|
||||
#define UVC_SUPPORTS_SET 0x02U
|
||||
#define UVC_STATE_DISABLED 0x04U
|
||||
#define UVC_AUTOUPDATE_CONTROL 0x08U
|
||||
#define UVC_ASYNCHRONOUS_CONTROL 0x10U
|
||||
|
||||
/* USB Terminal Types */
|
||||
#define TT_VENDOR_SPECIFIC 0x0100U
|
||||
#define TT_STREAMING 0x0101U
|
||||
|
||||
/* Input Terminal Types */
|
||||
#define ITT_VENDOR_SPECIFIC 0x0200U
|
||||
#define ITT_CAMERA 0x0201U
|
||||
#define ITT_MEDIA_TRANSPORT_INPUT 0x0202U
|
||||
|
||||
/*Output Terminal Types */
|
||||
#define OTT_VENDOR_SPECIFIC 0x0300U
|
||||
#define OTT_DISPLAY 0x0301U
|
||||
#define OTT_MEDIA_TRANSPORT_OUTPUT 0x0302U
|
||||
|
||||
/* External Terminal Types */
|
||||
#define EXTERNAL_VENDOR_SPECIFIC 0x0400U
|
||||
#define COMPOSITE_CONNECTOR 0x0401U
|
||||
#define SVIDEO_CONNECTOR 0x0402U
|
||||
#define COMPONENT_CONNECTOR 0x0403U
|
||||
|
||||
|
||||
/* VIDEO Commands enumeration */
|
||||
typedef enum
|
||||
{
|
||||
VIDEO_CMD_START = 1U,
|
||||
VIDEO_CMD_PLAY,
|
||||
VIDEO_CMD_STOP,
|
||||
} VIDEO_CMD_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
VIDEO_OFFSET_NONE = 0U,
|
||||
VIDEO_OFFSET_HALF,
|
||||
VIDEO_OFFSET_FULL,
|
||||
VIDEO_OFFSET_UNKNOWN,
|
||||
} 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
|
||||
{
|
||||
uint8_t cmd;
|
||||
uint8_t data[USB_MAX_EP0_SIZE];
|
||||
uint8_t len;
|
||||
uint8_t unit;
|
||||
} USBD_VIDEO_ControlTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t interface;
|
||||
uint32_t uvc_state;
|
||||
uint8_t buffer[UVC_TOTAL_BUF_SIZE];
|
||||
VIDEO_OffsetTypeDef offset;
|
||||
USBD_VIDEO_ControlTypeDef control;
|
||||
} USBD_VIDEO_HandleTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int8_t (* Init)(void);
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* Control)(uint8_t, uint8_t *, uint16_t);
|
||||
int8_t (* Data)(uint8_t **, uint16_t *, uint16_t *);
|
||||
} USBD_VIDEO_ItfTypeDef;
|
||||
|
||||
/* UVC uses only 26 first bytes */
|
||||
typedef struct
|
||||
{
|
||||
uint16_t bmHint;
|
||||
uint8_t bFormatIndex;
|
||||
uint8_t bFrameIndex;
|
||||
uint32_t dwFrameInterval;
|
||||
uint16_t wKeyFrameRate;
|
||||
uint16_t wPFrameRate;
|
||||
uint16_t wCompQuality;
|
||||
uint16_t wCompWindowSize;
|
||||
uint16_t wDelay;
|
||||
uint32_t dwMaxVideoFrameSize;
|
||||
uint32_t dwMaxPayloadTransferSize;
|
||||
uint32_t dwClockFrequency;
|
||||
uint8_t bmFramingInfo;
|
||||
uint8_t bPreferedVersion;
|
||||
uint8_t bMinVersion;
|
||||
uint8_t bMaxVersion;
|
||||
} __PACKED USBD_VideoControlTypeDef;
|
||||
|
||||
extern USBD_ClassTypeDef USBD_VIDEO;
|
||||
#define USBD_VIDEO_CLASS &USBD_VIDEO
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
uint8_t USBD_VIDEO_RegisterInterface(USBD_HandleTypeDef *pdev, USBD_VIDEO_ItfTypeDef *fops);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _USBD_VIDEO_H_ */
|
||||
156
Class/VIDEO/Inc/usbd_video_if_template.h
Normal file
156
Class/VIDEO/Inc/usbd_video_if_template.h
Normal file
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_video_if_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief Template Header file for the video Interface application layer functions
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2020 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_VIDEO_IF_H__
|
||||
#define __USBD_VIDEO_IF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_video.h"
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @brief For Usb device.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF
|
||||
* @brief Usb VIDEO interface device module.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Exported_Defines
|
||||
* @brief Defines.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_DEFINES */
|
||||
|
||||
/* USER CODE END EXPORTED_DEFINES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Exported_Types
|
||||
* @brief Types.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_TYPES */
|
||||
|
||||
/* USER CODE END EXPORTED_TYPES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Exported_Macros
|
||||
* @brief Aliases.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_MACRO */
|
||||
|
||||
/* USER CODE END EXPORTED_MACRO */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Exported_Variables
|
||||
* @brief Public variables.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** VIDEO_IF Interface callback. */
|
||||
extern USBD_VIDEO_ItfTypeDef USBD_VIDEO_fops_FS;
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||
|
||||
/* USER CODE END EXPORTED_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Exported_FunctionsPrototype
|
||||
* @brief Public functions declaration.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Manages the DMA full transfer complete event.
|
||||
* @retval None
|
||||
*/
|
||||
void TransferComplete_CallBack_FS(void);
|
||||
|
||||
/**
|
||||
* @brief Manages the DMA half transfer complete event.
|
||||
* @retval None
|
||||
*/
|
||||
void HalfTransfer_CallBack_FS(void);
|
||||
|
||||
|
||||
|
||||
#define IMG_NBR 1U
|
||||
#define IMAGE_SIZE 0x1U
|
||||
|
||||
const uint8_t image[] = {0x00};
|
||||
const uint8_t *tImagesList[] = {image};
|
||||
uint16_t tImagesSizes[] = {IMAGE_SIZE};
|
||||
|
||||
/* Time laps between video frames in ms.
|
||||
Please adjust this value depending on required speed.
|
||||
Please note that this define uses the system HAL_Delay() which uses the systick.
|
||||
In case of changes on HAL_Delay, please ensure the values in ms correspond. */
|
||||
#ifdef USE_USB_HS
|
||||
#define USBD_VIDEO_IMAGE_LAPS 160U
|
||||
#else
|
||||
#define USBD_VIDEO_IMAGE_LAPS 80U
|
||||
#endif /* USE_USB_HS */
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||
|
||||
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* USBD_VIDEO_IF_H_ */
|
||||
|
||||
1047
Class/VIDEO/Src/usbd_video.c
Normal file
1047
Class/VIDEO/Src/usbd_video.c
Normal file
File diff suppressed because it is too large
Load Diff
296
Class/VIDEO/Src/usbd_video_if_template.c
Normal file
296
Class/VIDEO/Src/usbd_video_if_template.c
Normal file
@@ -0,0 +1,296 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_video_if_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief Template file for Video Interface application layer functions
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2020 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_video_if_template.h"
|
||||
|
||||
/* Include you image binary file here
|
||||
Binary image template shall provide:
|
||||
- tImagesList: table containing pointers to all images
|
||||
- tImagesSizes: table containing sizes of each image respectively
|
||||
- img_count: global image counter variable
|
||||
- IMG_NBR: Total image number
|
||||
|
||||
To generate such file, it is possible to use tools converting video to MJPEG then to JPEG images.
|
||||
*/
|
||||
/* #include "img_bin.h" */
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
uint8_t img_count;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @brief Usb device library.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup USBD_VIDEO_IF
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Private_TypesDefinitions
|
||||
* @brief Private types.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_TYPES */
|
||||
|
||||
/* USER CODE END PRIVATE_TYPES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Private_Defines
|
||||
* @brief Private defines.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_DEFINES */
|
||||
|
||||
/* USER CODE END PRIVATE_DEFINES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Private_Macros
|
||||
* @brief Private macros.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_MACRO */
|
||||
|
||||
/* USER CODE END PRIVATE_MACRO */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Private_Variables
|
||||
* @brief Private variables.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_VARIABLES */
|
||||
|
||||
/* USER CODE END PRIVATE_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Exported_Variables
|
||||
* @brief Public variables.
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* USER CODE BEGIN EXPORTED_VARIABLES */
|
||||
|
||||
/* USER CODE END EXPORTED_VARIABLES */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_VIDEO_IF_Private_FunctionPrototypes
|
||||
* @brief Private functions declaration.
|
||||
* @{
|
||||
*/
|
||||
|
||||
static int8_t VIDEO_Itf_Init(void);
|
||||
static int8_t VIDEO_Itf_DeInit(void);
|
||||
static int8_t VIDEO_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||
static int8_t VIDEO_Itf_Data(uint8_t **pbuf, uint16_t *psize, uint16_t *pcktidx);
|
||||
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */
|
||||
|
||||
/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
USBD_VIDEO_ItfTypeDef USBD_VIDEO_fops_FS =
|
||||
{
|
||||
VIDEO_Itf_Init,
|
||||
VIDEO_Itf_DeInit,
|
||||
VIDEO_Itf_Control,
|
||||
VIDEO_Itf_Data,
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Initializes the VIDEO media low layer over USB FS IP
|
||||
* @param VIDEOFreq: VIDEO frequency used to play the VIDEO stream.
|
||||
* @param Volume: Initial volume level (from 0 (Mute) to 100 (Max))
|
||||
* @param options: Reserved for future use
|
||||
* @retval USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t VIDEO_Itf_Init(void)
|
||||
{
|
||||
/*
|
||||
Add your initialization code here
|
||||
*/
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_DeInit
|
||||
* DeInitializes the UVC media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t VIDEO_Itf_DeInit(void)
|
||||
{
|
||||
/*
|
||||
Add your deinitialization code here
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_Control
|
||||
* Manage the UVC class requests
|
||||
* @param Cmd: Command code
|
||||
* @param Buf: Buffer containing command data (request parameters)
|
||||
* @param Len: Number of data to be sent (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t VIDEO_Itf_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||
{
|
||||
UNUSED(cmd);
|
||||
UNUSED(pbuf);
|
||||
UNUSED(length);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_Data
|
||||
* Manage the UVC data packets
|
||||
* @param pbuf: pointer to the buffer data to be filled
|
||||
* @param psize: pointer tot he current packet size to be filled
|
||||
* @param pcktidx: pointer to the current packet index in the current image
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t VIDEO_Itf_Data(uint8_t **pbuf, uint16_t *psize, uint16_t *pcktidx)
|
||||
{
|
||||
/*
|
||||
Implementation of this function is mandatory to provide the video data to the USB video class
|
||||
This function shall parse the MJPEG images and provide each time the buffer packet relative to
|
||||
current packet index and its size.
|
||||
If the packet is the first packet in the current MJPEG image, then packet size shall be zero and
|
||||
the pbuf is ignored and pcktidx shall be zero.
|
||||
Below is typical implementation of this function based on a binary image template.
|
||||
|
||||
Binary image template shall provide:
|
||||
- tImagesList: table containing pointers to all images
|
||||
- tImagesSizes: table containing sizes of each image respectively
|
||||
- img_count: global image counter variable
|
||||
- IMG_NBR: Total image number
|
||||
|
||||
To generate such file, it is possible to use tools converting video to MJPEG then to JPEG images.
|
||||
|
||||
*/
|
||||
const uint8_t *(*ImagePtr) = tImagesList;
|
||||
uint32_t packet_count = (tImagesSizes[img_count]) / ((UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)));
|
||||
uint32_t packet_remainder = (tImagesSizes[img_count]) % ((UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)));
|
||||
static uint8_t packet_index = 0U;
|
||||
|
||||
/* Check if end of current image has been reached */
|
||||
if (packet_index < packet_count)
|
||||
{
|
||||
/* Set the current packet size */
|
||||
*psize = (uint16_t)UVC_PACKET_SIZE;
|
||||
|
||||
/* 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)))));
|
||||
}
|
||||
else if ((packet_index == packet_count))
|
||||
{
|
||||
if (packet_remainder != 0U)
|
||||
{
|
||||
/* 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)))));
|
||||
|
||||
/* Set the current packet size */
|
||||
*psize = (uint16_t)(packet_remainder + (UVC_HEADER_PACKET_CNT * 2U));
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_index++;
|
||||
|
||||
/* New image to be started, send only the packet header */
|
||||
*psize = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* New image to be started, send only the packet header */
|
||||
*psize = 2;
|
||||
}
|
||||
|
||||
/* Update the packet index */
|
||||
*pcktidx = packet_index;
|
||||
|
||||
/* Increment the packet count and check if it reached the end of current image buffer */
|
||||
if (packet_index++ >= (packet_count + 1U))
|
||||
{
|
||||
/* Reset the packet count to zero */
|
||||
packet_index = 0U;
|
||||
|
||||
/* Move to the next image in the images table */
|
||||
|
||||
img_count++;
|
||||
USBD_Delay(USBD_VIDEO_IMAGE_LAPS);
|
||||
/* Check if images count has been reached, then reset to zero (go back to first image in circular loop) */
|
||||
if (img_count == IMG_NBR)
|
||||
{
|
||||
img_count = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||
|
||||
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -44,42 +43,101 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USBD_MAX_NUM_INTERFACES 1U
|
||||
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
||||
#define USBD_SUPPORT_USER_STRING_DESC 0U
|
||||
#define USBD_SELF_POWERED 1U
|
||||
#define USBD_DEBUG_LEVEL 2U
|
||||
#define USBD_MAX_NUM_INTERFACES 1U
|
||||
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
||||
#define USBD_SELF_POWERED 1U
|
||||
#define USBD_DEBUG_LEVEL 2U
|
||||
|
||||
/* ECM, RNDIS, DFU Class Config */
|
||||
#define USBD_SUPPORT_USER_STRING_DESC 1U
|
||||
|
||||
/* BillBoard Class Config */
|
||||
#define USBD_CLASS_USER_STRING_DESC 1U
|
||||
#define USBD_CLASS_BOS_ENABLED 1U
|
||||
#define USB_BB_MAX_NUM_ALT_MODE 0x2U
|
||||
|
||||
/* MSC Class Config */
|
||||
#define MSC_MEDIA_PACKET 8192U
|
||||
#define MSC_MEDIA_PACKET 8192U
|
||||
|
||||
/* CDC Class Config */
|
||||
#define USBD_CDC_INTERVAL 2000U
|
||||
#define USBD_CDC_INTERVAL 2000U
|
||||
|
||||
/* DFU Class Config */
|
||||
#define USBD_DFU_MAX_ITF_NUM 1U
|
||||
#define USBD_DFU_XFERS_IZE 1024U
|
||||
#define USBD_DFU_MAX_ITF_NUM 1U
|
||||
#define USBD_DFU_XFERS_IZE 1024U
|
||||
|
||||
/* AUDIO Class Config */
|
||||
#define USBD_AUDIO_FREQ 22100U
|
||||
#define USBD_AUDIO_FREQ 22100U
|
||||
|
||||
/* CustomHID Class Config */
|
||||
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
||||
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
||||
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U
|
||||
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U
|
||||
|
||||
/* VIDEO Class Config */
|
||||
#define UVC_1_1 /* #define UVC_1_0 */
|
||||
|
||||
/* To be used only with YUY2 and NV12 Video format, shouldn't be defined for MJPEG format */
|
||||
#define USBD_UVC_FORMAT_UNCOMPRESSED
|
||||
|
||||
#ifdef USBD_UVC_FORMAT_UNCOMPRESSED
|
||||
#define UVC_BITS_PER_PIXEL 12U
|
||||
#define UVC_UNCOMPRESSED_GUID UVC_GUID_NV12 /* UVC_GUID_YUY2 */
|
||||
|
||||
/* refer to Table 3-18 Color Matching Descriptor video class v1.1 */
|
||||
#define UVC_COLOR_PRIMARIE 0x01U
|
||||
#define UVC_TFR_CHARACTERISTICS 0x01U
|
||||
#define UVC_MATRIX_COEFFICIENTS 0x04U
|
||||
#endif
|
||||
|
||||
/* Video Stream frame width and height */
|
||||
#define UVC_WIDTH 176U
|
||||
#define UVC_HEIGHT 144U
|
||||
|
||||
/* bEndpointAddress in Endpoint Descriptor */
|
||||
#define UVC_IN_EP 0x81U
|
||||
|
||||
#define UVC_CAM_FPS_FS 10U
|
||||
#define UVC_CAM_FPS_HS 5U
|
||||
|
||||
#define UVC_ISO_FS_MPS 512U
|
||||
#define UVC_ISO_HS_MPS 512U
|
||||
|
||||
#define UVC_PACKET_SIZE UVC_ISO_FS_MPS
|
||||
/* To be used with Device Only IP supporting double buffer mode */
|
||||
/* #define UVC_HEADER_PACKET_CNT 0x02U */
|
||||
/* #define UVC_PACKET_SIZE (UVC_ISO_FS_MPS * UVC_HEADER_PACKET_CNT) */
|
||||
|
||||
#define UVC_MAX_FRAME_SIZE (UVC_WIDTH * UVC_HEIGHT * 16U / 8U)
|
||||
|
||||
/** @defgroup USBD_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Memory management macros */
|
||||
#define USBD_malloc malloc
|
||||
#define USBD_free free
|
||||
#define USBD_memset memset
|
||||
#define USBD_memcpy memcpy
|
||||
/* Memory management macros make sure to use static memory allocation */
|
||||
/** Alias for memory allocation. */
|
||||
#define USBD_malloc (void *)USBD_static_malloc
|
||||
|
||||
/** Alias for memory release. */
|
||||
#define USBD_free USBD_static_free
|
||||
|
||||
/** Alias for memory set. */
|
||||
#define USBD_memset memset
|
||||
|
||||
/** Alias for memory copy. */
|
||||
#define USBD_memcpy memcpy
|
||||
|
||||
/** Alias for delay. */
|
||||
#define USBD_Delay HAL_Delay
|
||||
|
||||
/* DEBUG macros */
|
||||
#if (USBD_DEBUG_LEVEL > 0U)
|
||||
#define USBD_UsrLog(...) do { \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
#else
|
||||
#define USBD_UsrLog(...) do {} while (0)
|
||||
#endif
|
||||
@@ -87,20 +145,20 @@ extern "C" {
|
||||
#if (USBD_DEBUG_LEVEL > 1U)
|
||||
|
||||
#define USBD_ErrLog(...) do { \
|
||||
printf("ERROR: ") ; \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
printf("ERROR: ") ; \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
#else
|
||||
#define USBD_ErrLog(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
#if (USBD_DEBUG_LEVEL > 2U)
|
||||
#define USBD_DbgLog(...) do { \
|
||||
printf("DEBUG : ") ; \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
printf("DEBUG : ") ; \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
#else
|
||||
#define USBD_DbgLog(...) do {} while (0)
|
||||
#endif
|
||||
@@ -141,6 +199,9 @@ extern "C" {
|
||||
/** @defgroup USBD_CONF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
/* Exported functions -------------------------------------------------------*/
|
||||
void *USBD_static_malloc(uint32_t size);
|
||||
void USBD_static_free(void *p);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -159,4 +220,3 @@ extern "C" {
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -88,53 +87,50 @@ USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
||||
|
||||
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup);
|
||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
||||
|
||||
/* USBD Low Level Driver */
|
||||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t ep_type,
|
||||
uint16_t ep_mps);
|
||||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr);
|
||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t *pbuf,
|
||||
uint16_t size);
|
||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||
uint8_t ep_type, uint16_t ep_mps);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t *pbuf,
|
||||
uint16_t size);
|
||||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||
uint8_t *pbuf, uint32_t size);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||
uint8_t *pbuf, uint32_t size);
|
||||
|
||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
|
||||
void USBD_LL_Delay(uint32_t Delay);
|
||||
|
||||
/**
|
||||
@@ -152,10 +148,7 @@ void USBD_LL_Delay(uint32_t Delay);
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -73,16 +72,14 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
|
||||
void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata);
|
||||
|
||||
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -98,8 +95,7 @@ void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -61,10 +60,18 @@ extern "C" {
|
||||
#define USBD_SELF_POWERED 1U
|
||||
#endif /*USBD_SELF_POWERED */
|
||||
|
||||
#ifndef USBD_MAX_POWER
|
||||
#define USBD_MAX_POWER 0x32U /* 100 mA */
|
||||
#endif /* USBD_MAX_POWER */
|
||||
|
||||
#ifndef USBD_SUPPORT_USER_STRING_DESC
|
||||
#define USBD_SUPPORT_USER_STRING_DESC 0U
|
||||
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
#ifndef USBD_CLASS_USER_STRING_DESC
|
||||
#define USBD_CLASS_USER_STRING_DESC 0U
|
||||
#endif /* USBD_CLASS_USER_STRING_DESC */
|
||||
|
||||
#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
|
||||
#define USB_LEN_DEV_DESC 0x12U
|
||||
#define USB_LEN_CFG_DESC 0x09U
|
||||
@@ -110,6 +117,7 @@ extern "C" {
|
||||
#define USB_DESC_TYPE_ENDPOINT 0x05U
|
||||
#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
|
||||
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
|
||||
#define USB_DESC_TYPE_IAD 0x0BU
|
||||
#define USB_DESC_TYPE_BOS 0x0FU
|
||||
|
||||
#define USB_CONFIG_REMOTE_WAKEUP 0x02U
|
||||
@@ -121,6 +129,11 @@ extern "C" {
|
||||
|
||||
#define USB_DEVICE_CAPABITY_TYPE 0x10U
|
||||
|
||||
#define USB_CONF_DESC_SIZE 0x09U
|
||||
#define USB_IF_DESC_SIZE 0x09U
|
||||
#define USB_EP_DESC_SIZE 0x07U
|
||||
#define USB_IAD_DESC_SIZE 0x08U
|
||||
|
||||
#define USB_HS_MAX_PACKET_SIZE 512U
|
||||
#define USB_FS_MAX_PACKET_SIZE 64U
|
||||
#define USB_MAX_EP0_SIZE 64U
|
||||
@@ -146,7 +159,6 @@ extern "C" {
|
||||
#define USBD_EP_TYPE_BULK 0x02U
|
||||
#define USBD_EP_TYPE_INTR 0x03U
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -165,6 +177,36 @@ typedef struct usb_setup_req
|
||||
uint16_t wLength;
|
||||
} USBD_SetupReqTypedef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t wTotalLength;
|
||||
uint8_t bNumInterfaces;
|
||||
uint8_t bConfigurationValue;
|
||||
uint8_t iConfiguration;
|
||||
uint8_t bmAttributes;
|
||||
uint8_t bMaxPower;
|
||||
} USBD_ConfigDescTypedef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t wTotalLength;
|
||||
uint8_t bNumDeviceCaps;
|
||||
} USBD_BosDescTypedef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bEndpointAddress;
|
||||
uint8_t bmAttributes;
|
||||
uint16_t wMaxPacketSize;
|
||||
uint8_t bInterval;
|
||||
} __PACKED USBD_EpDescTypedef;
|
||||
|
||||
struct _USBD_HandleTypeDef;
|
||||
|
||||
typedef struct _Device_cb
|
||||
@@ -203,34 +245,39 @@ typedef enum
|
||||
/* Following USB Device status */
|
||||
typedef enum
|
||||
{
|
||||
USBD_OK = 0U,
|
||||
USBD_OK = 0U,
|
||||
USBD_BUSY,
|
||||
USBD_EMEM,
|
||||
USBD_FAIL,
|
||||
} USBD_StatusTypeDef;
|
||||
|
||||
/* USB Device descriptors structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#if (USBD_LPM_ENABLED == 1U)
|
||||
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||
uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||
#endif
|
||||
#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#endif
|
||||
} USBD_DescriptorsTypeDef;
|
||||
|
||||
/* USB Device handle structure */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t status;
|
||||
uint32_t is_used;
|
||||
uint32_t total_length;
|
||||
uint32_t rem_length;
|
||||
uint32_t maxpacket;
|
||||
uint32_t status;
|
||||
uint32_t total_length;
|
||||
uint32_t rem_length;
|
||||
uint32_t maxpacket;
|
||||
uint16_t is_used;
|
||||
uint16_t bInterval;
|
||||
} USBD_EndpointTypeDef;
|
||||
|
||||
/* USB Device handle structure */
|
||||
@@ -243,14 +290,15 @@ typedef struct _USBD_HandleTypeDef
|
||||
USBD_SpeedTypeDef dev_speed;
|
||||
USBD_EndpointTypeDef ep_in[16];
|
||||
USBD_EndpointTypeDef ep_out[16];
|
||||
uint32_t ep0_state;
|
||||
__IO uint32_t ep0_state;
|
||||
uint32_t ep0_data_len;
|
||||
uint8_t dev_state;
|
||||
uint8_t dev_old_state;
|
||||
__IO uint8_t dev_state;
|
||||
__IO uint8_t dev_old_state;
|
||||
uint8_t dev_address;
|
||||
uint8_t dev_connection_status;
|
||||
uint8_t dev_test_mode;
|
||||
uint32_t dev_remote_wakeup;
|
||||
uint8_t ConfIdx;
|
||||
|
||||
USBD_SetupReqTypedef request;
|
||||
USBD_DescriptorsTypeDef *pDesc;
|
||||
@@ -258,6 +306,8 @@ typedef struct _USBD_HandleTypeDef
|
||||
void *pClassData;
|
||||
void *pUserData;
|
||||
void *pData;
|
||||
void *pBosDesc;
|
||||
void *pConfDesc;
|
||||
} USBD_HandleTypeDef;
|
||||
|
||||
/**
|
||||
@@ -269,14 +319,35 @@ typedef struct _USBD_HandleTypeDef
|
||||
/** @defgroup USBD_DEF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
|
||||
(((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U))
|
||||
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
|
||||
{
|
||||
uint16_t _SwapVal, _Byte1, _Byte2;
|
||||
uint8_t *_pbuff = addr;
|
||||
|
||||
_Byte1 = *(uint8_t *)_pbuff;
|
||||
_pbuff++;
|
||||
_Byte2 = *(uint8_t *)_pbuff;
|
||||
|
||||
_SwapVal = (_Byte2 << 8) | _Byte1;
|
||||
|
||||
return _SwapVal;
|
||||
}
|
||||
|
||||
#ifndef LOBYTE
|
||||
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
|
||||
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef HIBYTE
|
||||
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
#ifndef __weak
|
||||
@@ -343,6 +414,6 @@ typedef struct _USBD_HandleTypeDef
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -26,11 +25,33 @@
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define DEVICE_ID1 (0x1FFF7A10)
|
||||
#define DEVICE_ID2 (0x1FFF7A14)
|
||||
#define DEVICE_ID3 (0x1FFF7A18)
|
||||
#define DEVICE_ID1 (UID_BASE)
|
||||
#define DEVICE_ID2 (UID_BASE + 0x4U)
|
||||
#define DEVICE_ID3 (UID_BASE + 0x8U)
|
||||
|
||||
#define USB_SIZ_STRING_SERIAL 0x1A
|
||||
/*
|
||||
* USB Billboard Class USER string desc Defines Template
|
||||
* index should start form 0x10 to avoid using the reserved device string desc indexes
|
||||
*/
|
||||
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||
#define USBD_BB_IF_STRING_INDEX 0x10U
|
||||
#define USBD_BB_URL_STRING_INDEX 0x11U
|
||||
#define USBD_BB_ALTMODE0_STRING_INDEX 0x12U
|
||||
#define USBD_BB_ALTMODE1_STRING_INDEX 0x13U
|
||||
/* Add Specific USER string Desc */
|
||||
#define USBD_BB_IF_STR_DESC (uint8_t *)"STM32 BillBoard Interface"
|
||||
#define USBD_BB_URL_STR_DESC (uint8_t *)"www.st.com"
|
||||
#define USBD_BB_ALTMODE0_STR_DESC (uint8_t *)"STM32 Alternate0 Mode"
|
||||
#define USBD_BB_ALTMODE1_STR_DESC (uint8_t *)"STM32 Alternate1 Mode"
|
||||
#endif
|
||||
|
||||
#define USB_SIZ_STRING_SERIAL 0x1AU
|
||||
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
#define USB_SIZ_BOS_DESC 0x0CU
|
||||
#elif (USBD_CLASS_BOS_ENABLED == 1)
|
||||
#define USB_SIZ_BOS_DESC 0x5DU
|
||||
#endif
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
@@ -38,4 +59,3 @@ extern USBD_DescriptorsTypeDef XXX_Desc; /* Replace 'XXX_Desc' with your active
|
||||
|
||||
#endif /* __USBD_DESC_TEMPLATE_H*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -77,27 +76,22 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint32_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint32_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint32_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint32_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -114,6 +108,6 @@ uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_hid.h" /* Include class header file */
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@@ -34,6 +34,8 @@
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -44,6 +46,8 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -54,6 +58,8 @@ USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -64,6 +70,8 @@ USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -78,6 +86,11 @@ USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||
uint8_t ep_type, uint16_t ep_mps)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(ep_addr);
|
||||
UNUSED(ep_type);
|
||||
UNUSED(ep_mps);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -89,6 +102,9 @@ USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(ep_addr);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -100,6 +116,9 @@ USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(ep_addr);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -111,6 +130,9 @@ USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(ep_addr);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -123,6 +145,9 @@ USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(ep_addr);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -134,18 +159,24 @@ USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev,
|
||||
*/
|
||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return 0;
|
||||
UNUSED(pdev);
|
||||
UNUSED(ep_addr);
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assigns a USB address to the device.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param dev_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev,
|
||||
uint8_t dev_addr)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(dev_addr);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -158,8 +189,13 @@ USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev,
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||
uint8_t *pbuf, uint16_t size)
|
||||
uint8_t *pbuf, uint32_t size)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(ep_addr);
|
||||
UNUSED(pbuf);
|
||||
UNUSED(size);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -173,8 +209,13 @@ USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr, uint8_t *pbuf,
|
||||
uint16_t size)
|
||||
uint32_t size)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(ep_addr);
|
||||
UNUSED(pbuf);
|
||||
UNUSED(size);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -182,13 +223,37 @@ USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||
* @brief Returns the last transferred packet size.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval Recived Data Size
|
||||
* @retval Received Data Size
|
||||
*/
|
||||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
UNUSED(pdev);
|
||||
UNUSED(ep_addr);
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Static single allocation.
|
||||
* @param size: Size of allocated memory
|
||||
* @retval None
|
||||
*/
|
||||
void *USBD_static_malloc(uint32_t size)
|
||||
{
|
||||
static uint32_t mem[(sizeof(USBD_HID_HandleTypeDef) / 4) + 1]; /* On 32-bit boundary */
|
||||
return mem;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dummy memory free
|
||||
* @param p: Pointer to allocated memory address
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_static_free(void *p)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delays routine for the USB Device Library.
|
||||
* @param Delay: Delay in ms
|
||||
@@ -196,6 +261,6 @@ uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
*/
|
||||
void USBD_LL_Delay(uint32_t Delay)
|
||||
{
|
||||
UNUSED(Delay);
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -21,74 +20,76 @@
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_Init
|
||||
* Initializes the device stack and load the class driver
|
||||
* @param pdev: device instance
|
||||
* @param pdesc: Descriptor structure address
|
||||
* @param id: Low level core index
|
||||
* @retval None
|
||||
*/
|
||||
* @brief USBD_Init
|
||||
* Initializes the device stack and load the class driver
|
||||
* @param pdev: device instance
|
||||
* @param pdesc: Descriptor structure address
|
||||
* @param id: Low level core index
|
||||
* @retval None
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev,
|
||||
USBD_DescriptorsTypeDef *pdesc, uint8_t id)
|
||||
{
|
||||
USBD_StatusTypeDef ret;
|
||||
|
||||
/* Check whether the USB Host handle is valid */
|
||||
if (pdev == NULL)
|
||||
{
|
||||
@@ -98,11 +99,10 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev,
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Unlink previous class*/
|
||||
if (pdev->pClass != NULL)
|
||||
{
|
||||
pdev->pClass = NULL;
|
||||
}
|
||||
/* Unlink previous class resources */
|
||||
pdev->pClass = NULL;
|
||||
pdev->pUserData = NULL;
|
||||
pdev->pConfDesc = NULL;
|
||||
|
||||
/* Assign USBD Descriptors */
|
||||
if (pdesc != NULL)
|
||||
@@ -113,33 +113,45 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev,
|
||||
/* Set Device initial State */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->id = id;
|
||||
/* Initialize low level driver */
|
||||
USBD_LL_Init(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
/* Initialize low level driver */
|
||||
ret = USBD_LL_Init(pdev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DeInit
|
||||
* Re-Initialize th device library
|
||||
* @param pdev: device instance
|
||||
* @retval status: status
|
||||
*/
|
||||
* @brief USBD_DeInit
|
||||
* Re-Initialize the device library
|
||||
* @param pdev: device instance
|
||||
* @retval status: status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_StatusTypeDef ret;
|
||||
|
||||
/* Disconnect the USB Device */
|
||||
(void)USBD_LL_Stop(pdev);
|
||||
|
||||
/* Set Default State */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
|
||||
/* Free Class Resources */
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
if (pdev->pClass != NULL)
|
||||
{
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
pdev->pClass = NULL;
|
||||
pdev->pUserData = NULL;
|
||||
}
|
||||
|
||||
/* Stop the low level driver */
|
||||
USBD_LL_Stop(pdev);
|
||||
/* Free Device descriptors resources */
|
||||
pdev->pDesc = NULL;
|
||||
pdev->pConfDesc = NULL;
|
||||
|
||||
/* Initialize low level driver */
|
||||
USBD_LL_DeInit(pdev);
|
||||
/* DeInitialize low level driver */
|
||||
ret = USBD_LL_DeInit(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,24 +161,35 @@ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
||||
* @param pclass: Class handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass)
|
||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass)
|
||||
{
|
||||
USBD_StatusTypeDef status = USBD_OK;
|
||||
if (pclass != NULL)
|
||||
{
|
||||
/* link the class to the USB Device handle */
|
||||
pdev->pClass = pclass;
|
||||
status = USBD_OK;
|
||||
}
|
||||
else
|
||||
uint16_t len = 0U;
|
||||
|
||||
if (pclass == NULL)
|
||||
{
|
||||
#if (USBD_DEBUG_LEVEL > 1U)
|
||||
USBD_ErrLog("Invalid Class handle");
|
||||
#endif
|
||||
status = USBD_FAIL;
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
return status;
|
||||
/* link the class to the USB Device handle */
|
||||
pdev->pClass = pclass;
|
||||
|
||||
/* Get Device Configuration Descriptor */
|
||||
#ifdef USE_USB_HS
|
||||
if (pdev->pClass->GetHSConfigDescriptor != NULL)
|
||||
{
|
||||
pdev->pConfDesc = (void *)pdev->pClass->GetHSConfigDescriptor(&len);
|
||||
}
|
||||
#else /* Default USE_USB_FS */
|
||||
if (pdev->pClass->GetFSConfigDescriptor != NULL)
|
||||
{
|
||||
pdev->pConfDesc = (void *)pdev->pClass->GetFSConfigDescriptor(&len);
|
||||
}
|
||||
#endif /* USE_USB_FS */
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,12 +198,10 @@ USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeD
|
||||
* @param pdev: Device Handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev)
|
||||
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Start the low level driver */
|
||||
USBD_LL_Start(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
return USBD_LL_Start(pdev);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,24 +210,27 @@ USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: Device Handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev)
|
||||
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Free Class Resources */
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
/* Disconnect USB Device */
|
||||
(void)USBD_LL_Stop(pdev);
|
||||
|
||||
/* Stop the low level driver */
|
||||
USBD_LL_Stop(pdev);
|
||||
/* Free Class Resources */
|
||||
if (pdev->pClass != NULL)
|
||||
{
|
||||
(void)pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_RunTestMode
|
||||
* Launch test mode process
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev)
|
||||
* @brief USBD_RunTestMode
|
||||
* Launch test mode process
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Prevent unused argument compilation warning */
|
||||
UNUSED(pdev);
|
||||
@@ -215,53 +239,55 @@ USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SetClassConfig
|
||||
* Configure device and start the interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_SetClassConfig
|
||||
* Configure device and start the interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_FAIL;
|
||||
|
||||
if (pdev->pClass != NULL)
|
||||
{
|
||||
/* Set configuration and Start the Class*/
|
||||
if (pdev->pClass->Init(pdev, cfgidx) == 0U)
|
||||
{
|
||||
ret = USBD_OK;
|
||||
}
|
||||
/* Set configuration and Start the Class */
|
||||
ret = (USBD_StatusTypeDef)pdev->pClass->Init(pdev, cfgidx);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_ClrClassConfig
|
||||
* Clear current configuration
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status: USBD_StatusTypeDef
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
* @brief USBD_ClrClassConfig
|
||||
* Clear current configuration
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status: USBD_StatusTypeDef
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
/* Clear configuration and De-initialize the Class process*/
|
||||
pdev->pClass->DeInit(pdev, cfgidx);
|
||||
/* Clear configuration and De-initialize the Class process */
|
||||
if (pdev->pClass != NULL)
|
||||
{
|
||||
pdev->pClass->DeInit(pdev, cfgidx);
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetupStage
|
||||
* Handle the setup stage
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_SetupStage
|
||||
* Handle the setup stage
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
||||
{
|
||||
USBD_StatusTypeDef ret;
|
||||
|
||||
USBD_ParseSetupRequest(&pdev->request, psetup);
|
||||
|
||||
pdev->ep0_state = USBD_EP0_SETUP;
|
||||
@@ -271,36 +297,38 @@ USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
||||
switch (pdev->request.bmRequest & 0x1FU)
|
||||
{
|
||||
case USB_REQ_RECIPIENT_DEVICE:
|
||||
USBD_StdDevReq(pdev, &pdev->request);
|
||||
ret = USBD_StdDevReq(pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
case USB_REQ_RECIPIENT_INTERFACE:
|
||||
USBD_StdItfReq(pdev, &pdev->request);
|
||||
ret = USBD_StdItfReq(pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
case USB_REQ_RECIPIENT_ENDPOINT:
|
||||
USBD_StdEPReq(pdev, &pdev->request);
|
||||
ret = USBD_StdEPReq(pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U));
|
||||
ret = USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U));
|
||||
break;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DataOutStage
|
||||
* Handle data OUT stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_DataOutStage
|
||||
* Handle data OUT stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @param pdata: data pointer
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum, uint8_t *pdata)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
USBD_StatusTypeDef ret;
|
||||
|
||||
if (epnum == 0U)
|
||||
{
|
||||
@@ -312,56 +340,66 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
|
||||
{
|
||||
pep->rem_length -= pep->maxpacket;
|
||||
|
||||
USBD_CtlContinueRx(pdev, pdata,
|
||||
(uint16_t)MIN(pep->rem_length, pep->maxpacket));
|
||||
(void)USBD_CtlContinueRx(pdev, pdata, MIN(pep->rem_length, pep->maxpacket));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pdev->pClass->EP0_RxReady != NULL) &&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
pdev->pClass->EP0_RxReady(pdev);
|
||||
if (pdev->pClass->EP0_RxReady != NULL)
|
||||
{
|
||||
pdev->pClass->EP0_RxReady(pdev);
|
||||
}
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
if (pdev->ep0_state == USBD_EP0_STATUS_OUT)
|
||||
{
|
||||
/*
|
||||
* STATUS PHASE completed, update ep0_state to idle
|
||||
*/
|
||||
* STATUS PHASE completed, update ep0_state to idle
|
||||
*/
|
||||
pdev->ep0_state = USBD_EP0_IDLE;
|
||||
USBD_LL_StallEP(pdev, 0U);
|
||||
(void)USBD_LL_StallEP(pdev, 0U);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if ((pdev->pClass->DataOut != NULL) &&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->DataOut(pdev, epnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* should never be in this condition */
|
||||
return USBD_FAIL;
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (pdev->pClass->DataOut != NULL)
|
||||
{
|
||||
ret = (USBD_StatusTypeDef)pdev->pClass->DataOut(pdev, epnum);
|
||||
|
||||
if (ret != USBD_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DataInStage
|
||||
* Handle data in stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_DataInStage
|
||||
* Handle data in stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum, uint8_t *pdata)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
USBD_StatusTypeDef ret;
|
||||
|
||||
if (epnum == 0U)
|
||||
{
|
||||
@@ -373,106 +411,123 @@ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
|
||||
{
|
||||
pep->rem_length -= pep->maxpacket;
|
||||
|
||||
USBD_CtlContinueSendData(pdev, pdata, (uint16_t)pep->rem_length);
|
||||
(void)USBD_CtlContinueSendData(pdev, pdata, pep->rem_length);
|
||||
|
||||
/* Prepare endpoint for premature end of transfer */
|
||||
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||
(void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* last packet is MPS multiple, so send ZLP packet */
|
||||
if ((pep->total_length % pep->maxpacket == 0U) &&
|
||||
if ((pep->maxpacket == pep->rem_length) &&
|
||||
(pep->total_length >= pep->maxpacket) &&
|
||||
(pep->total_length < pdev->ep0_data_len))
|
||||
{
|
||||
USBD_CtlContinueSendData(pdev, NULL, 0U);
|
||||
(void)USBD_CtlContinueSendData(pdev, NULL, 0U);
|
||||
pdev->ep0_data_len = 0U;
|
||||
|
||||
/* Prepare endpoint for premature end of transfer */
|
||||
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||
(void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pdev->pClass->EP0_TxSent != NULL) &&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
pdev->pClass->EP0_TxSent(pdev);
|
||||
if (pdev->pClass->EP0_TxSent != NULL)
|
||||
{
|
||||
pdev->pClass->EP0_TxSent(pdev);
|
||||
}
|
||||
}
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
USBD_CtlReceiveStatus(pdev);
|
||||
(void)USBD_LL_StallEP(pdev, 0x80U);
|
||||
(void)USBD_CtlReceiveStatus(pdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
if ((pdev->ep0_state == USBD_EP0_STATUS_IN) ||
|
||||
(pdev->ep0_state == USBD_EP0_IDLE))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
(void)USBD_LL_StallEP(pdev, 0x80U);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (pdev->dev_test_mode == 1U)
|
||||
{
|
||||
USBD_RunTestMode(pdev);
|
||||
(void)USBD_RunTestMode(pdev);
|
||||
pdev->dev_test_mode = 0U;
|
||||
}
|
||||
}
|
||||
else if ((pdev->pClass->DataIn != NULL) &&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->DataIn(pdev, epnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* should never be in this condition */
|
||||
return USBD_FAIL;
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (pdev->pClass->DataIn != NULL)
|
||||
{
|
||||
ret = (USBD_StatusTypeDef)pdev->pClass->DataIn(pdev, epnum);
|
||||
|
||||
if (ret != USBD_OK)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_LL_Reset
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_Reset
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Open EP0 OUT */
|
||||
USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
||||
pdev->ep_out[0x00U & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
|
||||
/* Open EP0 IN */
|
||||
USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
||||
pdev->ep_in[0x80U & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
|
||||
/* Upon Reset call user call back */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->ep0_state = USBD_EP0_IDLE;
|
||||
pdev->dev_config = 0U;
|
||||
pdev->dev_remote_wakeup = 0U;
|
||||
|
||||
if (pdev->pClassData)
|
||||
if (pdev->pClass == NULL)
|
||||
{
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
if (pdev->pClass->DeInit != NULL)
|
||||
{
|
||||
(void)pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
}
|
||||
}
|
||||
|
||||
/* Open EP0 OUT */
|
||||
(void)USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
||||
pdev->ep_out[0x00U & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
|
||||
/* Open EP0 IN */
|
||||
(void)USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
||||
pdev->ep_in[0x80U & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_LL_Reset
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_SetSpeed
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev,
|
||||
USBD_SpeedTypeDef speed)
|
||||
{
|
||||
@@ -482,26 +537,26 @@ USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Suspend
|
||||
* Handle Suspend event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_Suspend
|
||||
* Handle Suspend event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
pdev->dev_old_state = pdev->dev_state;
|
||||
pdev->dev_state = USBD_STATE_SUSPENDED;
|
||||
pdev->dev_old_state = pdev->dev_state;
|
||||
pdev->dev_state = USBD_STATE_SUSPENDED;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Resume
|
||||
* Handle Resume event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_Resume
|
||||
* Handle Resume event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
@@ -514,19 +569,24 @@ USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SOF
|
||||
* Handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_SOF
|
||||
* Handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
if (pdev->pClass == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (pdev->pClass->SOF != NULL)
|
||||
{
|
||||
pdev->pClass->SOF(pdev);
|
||||
(void)pdev->pClass->SOF(pdev);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,43 +594,61 @@ USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_IsoINIncomplete
|
||||
* Handle iso in incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_IsoINIncomplete
|
||||
* Handle iso in incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
/* Prevent unused arguments compilation warning */
|
||||
UNUSED(pdev);
|
||||
UNUSED(epnum);
|
||||
if (pdev->pClass == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (pdev->pClass->IsoINIncomplete != NULL)
|
||||
{
|
||||
(void)pdev->pClass->IsoINIncomplete(pdev, epnum);
|
||||
}
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_IsoOUTIncomplete
|
||||
* Handle iso out incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_IsoOUTIncomplete
|
||||
* Handle iso out incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
/* Prevent unused arguments compilation warning */
|
||||
UNUSED(pdev);
|
||||
UNUSED(epnum);
|
||||
if (pdev->pClass == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (pdev->pClass->IsoOUTIncomplete != NULL)
|
||||
{
|
||||
(void)pdev->pClass->IsoOUTIncomplete(pdev, epnum);
|
||||
}
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DevConnected
|
||||
* Handle device connection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_DevConnected
|
||||
* Handle device connection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Prevent unused argument compilation warning */
|
||||
@@ -580,32 +658,34 @@ USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DevDisconnected
|
||||
* Handle device disconnection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_LL_DevDisconnected
|
||||
* Handle device disconnection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Free Class Resources */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
|
||||
if (pdev->pClass != NULL)
|
||||
{
|
||||
(void)pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -71,27 +70,13 @@
|
||||
/** @defgroup USBD_REQ_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static uint8_t USBD_GetLen(uint8_t *buf);
|
||||
|
||||
/**
|
||||
@@ -105,14 +90,13 @@ static uint8_t USBD_GetLen(uint8_t *buf);
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_StdDevReq
|
||||
* Handle standard usb device requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
* @brief USBD_StdDevReq
|
||||
* Handle standard usb device requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
@@ -120,7 +104,7 @@ USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev,
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
case USB_REQ_TYPE_VENDOR:
|
||||
pdev->pClass->Setup(pdev, req);
|
||||
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
@@ -135,7 +119,7 @@ USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_CONFIGURATION:
|
||||
USBD_SetConfig(pdev, req);
|
||||
ret = USBD_SetConfig(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_CONFIGURATION:
|
||||
@@ -169,14 +153,13 @@ USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_StdItfReq
|
||||
* Handle standard usb interface requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
* @brief USBD_StdItfReq
|
||||
* Handle standard usb interface requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
@@ -197,7 +180,7 @@ USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev,
|
||||
|
||||
if ((req->wLength == 0U) && (ret == USBD_OK))
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -217,40 +200,31 @@ USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev,
|
||||
break;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_StdEPReq
|
||||
* Handle standard usb endpoint requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
* @brief USBD_StdEPReq
|
||||
* Handle standard usb endpoint requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
uint8_t ep_addr;
|
||||
uint8_t ep_addr;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
ep_addr = LOBYTE(req->wIndex);
|
||||
ep_addr = LOBYTE(req->wIndex);
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
case USB_REQ_TYPE_VENDOR:
|
||||
pdev->pClass->Setup(pdev, req);
|
||||
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
/* Check if it is a class request */
|
||||
if ((req->bmRequest & 0x60U) == 0x20U)
|
||||
{
|
||||
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_SET_FEATURE:
|
||||
@@ -259,8 +233,8 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, ep_addr);
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
(void)USBD_LL_StallEP(pdev, ep_addr);
|
||||
(void)USBD_LL_StallEP(pdev, 0x80U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -271,13 +245,12 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_EP_HALT)
|
||||
{
|
||||
if ((ep_addr != 0x00U) &&
|
||||
(ep_addr != 0x80U) && (req->wLength == 0x00U))
|
||||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U) && (req->wLength == 0x00U))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, ep_addr);
|
||||
(void)USBD_LL_StallEP(pdev, ep_addr);
|
||||
}
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
|
||||
break;
|
||||
|
||||
@@ -294,8 +267,8 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, ep_addr);
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
(void)USBD_LL_StallEP(pdev, ep_addr);
|
||||
(void)USBD_LL_StallEP(pdev, 0x80U);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -308,9 +281,10 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
{
|
||||
if ((ep_addr & 0x7FU) != 0x00U)
|
||||
{
|
||||
USBD_LL_ClearStallEP(pdev, ep_addr);
|
||||
(void)USBD_LL_ClearStallEP(pdev, ep_addr);
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -334,7 +308,7 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
|
||||
pep->status = 0x0000U;
|
||||
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pep->status, 2U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&pep->status, 2U);
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
@@ -362,7 +336,7 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
{
|
||||
pep->status = 0x0000U;
|
||||
}
|
||||
else if (USBD_LL_IsStallEP(pdev, ep_addr))
|
||||
else if (USBD_LL_IsStallEP(pdev, ep_addr) != 0U)
|
||||
{
|
||||
pep->status = 0x0001U;
|
||||
}
|
||||
@@ -371,7 +345,7 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
pep->status = 0x0000U;
|
||||
}
|
||||
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pep->status, 2U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&pep->status, 2U);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -396,14 +370,13 @@ USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_GetDescriptor
|
||||
* Handle Get Descriptor requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
* @brief USBD_GetDescriptor
|
||||
* Handle Get Descriptor requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint16_t len = 0U;
|
||||
uint8_t *pbuf = NULL;
|
||||
@@ -411,7 +384,7 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev,
|
||||
|
||||
switch (req->wValue >> 8)
|
||||
{
|
||||
#if (USBD_LPM_ENABLED == 1U)
|
||||
#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1U))
|
||||
case USB_DESC_TYPE_BOS:
|
||||
if (pdev->pDesc->GetBOSDescriptor != NULL)
|
||||
{
|
||||
@@ -527,11 +500,25 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev,
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
#else
|
||||
#endif
|
||||
|
||||
#if (USBD_CLASS_USER_STRING_DESC == 1U)
|
||||
if (pdev->pDesc->GetUserStrDescriptor != NULL)
|
||||
{
|
||||
pbuf = pdev->pDesc->GetUserStrDescriptor(pdev->dev_speed, (req->wValue), &len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ((USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U))
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -570,30 +557,34 @@ static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev,
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
if (req->wLength != 0U)
|
||||
{
|
||||
if ((len != 0U) && (req->wLength != 0U))
|
||||
if (len != 0U)
|
||||
{
|
||||
len = MIN(len, req->wLength);
|
||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||
}
|
||||
|
||||
if (req->wLength == 0U)
|
||||
else
|
||||
{
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetAddress
|
||||
* Set device address
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
* @brief USBD_SetAddress
|
||||
* Set device address
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint8_t dev_addr;
|
||||
|
||||
@@ -608,8 +599,8 @@ static void USBD_SetAddress(USBD_HandleTypeDef *pdev,
|
||||
else
|
||||
{
|
||||
pdev->dev_address = dev_addr;
|
||||
USBD_LL_SetUSBAddress(pdev, dev_addr);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
(void)USBD_LL_SetUSBAddress(pdev, dev_addr);
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
|
||||
if (dev_addr != 0U)
|
||||
{
|
||||
@@ -628,14 +619,15 @@ static void USBD_SetAddress(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SetConfig
|
||||
* Handle Set device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
* @brief USBD_SetConfig
|
||||
* Handle Set device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
static uint8_t cfgidx;
|
||||
|
||||
cfgidx = (uint8_t)(req->wValue);
|
||||
@@ -643,72 +635,86 @@ static void USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
if (cfgidx > USBD_MAX_NUM_CONFIGURATION)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
return USBD_FAIL;
|
||||
}
|
||||
else
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if (cfgidx)
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if (cfgidx != 0U)
|
||||
{
|
||||
pdev->dev_config = cfgidx;
|
||||
|
||||
ret = USBD_SetClassConfig(pdev, cfgidx);
|
||||
|
||||
if (ret != USBD_OK)
|
||||
{
|
||||
pdev->dev_config = cfgidx;
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
pdev->dev_state = USBD_STATE_CONFIGURED;
|
||||
if (USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
return;
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (cfgidx == 0U)
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (cfgidx == 0U)
|
||||
{
|
||||
pdev->dev_state = USBD_STATE_ADDRESSED;
|
||||
pdev->dev_config = cfgidx;
|
||||
(void)USBD_ClrClassConfig(pdev, cfgidx);
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else if (cfgidx != pdev->dev_config)
|
||||
{
|
||||
/* Clear old configuration */
|
||||
(void)USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config);
|
||||
|
||||
/* set new configuration */
|
||||
pdev->dev_config = cfgidx;
|
||||
|
||||
ret = USBD_SetClassConfig(pdev, cfgidx);
|
||||
|
||||
if (ret != USBD_OK)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
(void)USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config);
|
||||
pdev->dev_state = USBD_STATE_ADDRESSED;
|
||||
pdev->dev_config = cfgidx;
|
||||
USBD_ClrClassConfig(pdev, cfgidx);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else if (cfgidx != pdev->dev_config)
|
||||
{
|
||||
/* Clear old configuration */
|
||||
USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config);
|
||||
|
||||
/* set new configuration */
|
||||
pdev->dev_config = cfgidx;
|
||||
if (USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
return;
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
USBD_ClrClassConfig(pdev, cfgidx);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
(void)USBD_ClrClassConfig(pdev, cfgidx);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetConfig
|
||||
* Handle Get device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_GetConfig
|
||||
* Handle Get device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
if (req->wLength != 1U)
|
||||
@@ -722,11 +728,11 @@ static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
case USBD_STATE_DEFAULT:
|
||||
case USBD_STATE_ADDRESSED:
|
||||
pdev->dev_default_config = 0U;
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_default_config, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&pdev->dev_default_config, 1U);
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_config, 1U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&pdev->dev_config, 1U);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -737,12 +743,12 @@ static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetStatus
|
||||
* Handle Get Status request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_GetStatus
|
||||
* Handle Get Status request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
@@ -762,12 +768,12 @@ static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
pdev->dev_config_status = 0U;
|
||||
#endif
|
||||
|
||||
if (pdev->dev_remote_wakeup)
|
||||
if (pdev->dev_remote_wakeup != 0U)
|
||||
{
|
||||
pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP;
|
||||
}
|
||||
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_config_status, 2U);
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&pdev->dev_config_status, 2U);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -778,32 +784,30 @@ static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetFeature
|
||||
* Handle Set device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
* @brief USBD_SetFeature
|
||||
* Handle Set device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
|
||||
{
|
||||
pdev->dev_remote_wakeup = 1U;
|
||||
USBD_CtlSendStatus(pdev);
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_ClrFeature
|
||||
* Handle clear device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
* @brief USBD_ClrFeature
|
||||
* Handle clear device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
@@ -813,7 +817,7 @@ static void USBD_ClrFeature(USBD_HandleTypeDef *pdev,
|
||||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
|
||||
{
|
||||
pdev->dev_remote_wakeup = 0U;
|
||||
USBD_CtlSendStatus(pdev);
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -823,37 +827,49 @@ static void USBD_ClrFeature(USBD_HandleTypeDef *pdev,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_ParseSetupRequest
|
||||
* Copy buffer into setup structure
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_ParseSetupRequest
|
||||
* Copy buffer into setup structure
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata)
|
||||
{
|
||||
req->bmRequest = *(uint8_t *)(pdata);
|
||||
req->bRequest = *(uint8_t *)(pdata + 1U);
|
||||
req->wValue = SWAPBYTE(pdata + 2U);
|
||||
req->wIndex = SWAPBYTE(pdata + 4U);
|
||||
req->wLength = SWAPBYTE(pdata + 6U);
|
||||
uint8_t *pbuff = pdata;
|
||||
|
||||
req->bmRequest = *(uint8_t *)(pbuff);
|
||||
|
||||
pbuff++;
|
||||
req->bRequest = *(uint8_t *)(pbuff);
|
||||
|
||||
pbuff++;
|
||||
req->wValue = SWAPBYTE(pbuff);
|
||||
|
||||
pbuff++;
|
||||
pbuff++;
|
||||
req->wIndex = SWAPBYTE(pbuff);
|
||||
|
||||
pbuff++;
|
||||
pbuff++;
|
||||
req->wLength = SWAPBYTE(pbuff);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlError
|
||||
* Handle USB low level Error
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void USBD_CtlError(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
/**
|
||||
* @brief USBD_CtlError
|
||||
* Handle USB low level Error
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
USBD_LL_StallEP(pdev, 0U);
|
||||
UNUSED(req);
|
||||
|
||||
(void)USBD_LL_StallEP(pdev, 0x80U);
|
||||
(void)USBD_LL_StallEP(pdev, 0U);
|
||||
}
|
||||
|
||||
|
||||
@@ -868,21 +884,33 @@ void USBD_CtlError(USBD_HandleTypeDef *pdev,
|
||||
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
|
||||
{
|
||||
uint8_t idx = 0U;
|
||||
uint8_t *pdesc;
|
||||
|
||||
if (desc != NULL)
|
||||
if (desc == NULL)
|
||||
{
|
||||
*len = (uint16_t)USBD_GetLen(desc) * 2U + 2U;
|
||||
unicode[idx++] = *(uint8_t *)(void *)len;
|
||||
unicode[idx++] = USB_DESC_TYPE_STRING;
|
||||
return;
|
||||
}
|
||||
|
||||
while (*desc != '\0')
|
||||
{
|
||||
unicode[idx++] = *desc++;
|
||||
unicode[idx++] = 0U;
|
||||
}
|
||||
pdesc = desc;
|
||||
*len = ((uint16_t)USBD_GetLen(pdesc) * 2U) + 2U;
|
||||
|
||||
unicode[idx] = *(uint8_t *)len;
|
||||
idx++;
|
||||
unicode[idx] = USB_DESC_TYPE_STRING;
|
||||
idx++;
|
||||
|
||||
while (*pdesc != (uint8_t)'\0')
|
||||
{
|
||||
unicode[idx] = *pdesc;
|
||||
pdesc++;
|
||||
idx++;
|
||||
|
||||
unicode[idx] = 0U;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_GetLen
|
||||
* return the string length
|
||||
@@ -892,11 +920,12 @@ void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
|
||||
static uint8_t USBD_GetLen(uint8_t *buf)
|
||||
{
|
||||
uint8_t len = 0U;
|
||||
uint8_t *pbuff = buf;
|
||||
|
||||
while (*buf != '\0')
|
||||
while (*pbuff != (uint8_t)'\0')
|
||||
{
|
||||
len++;
|
||||
buf++;
|
||||
pbuff++;
|
||||
}
|
||||
|
||||
return len;
|
||||
@@ -915,4 +944,3 @@ static uint8_t USBD_GetLen(uint8_t *buf)
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -8,13 +8,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -28,7 +27,7 @@
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define USBD_VID 0x0483
|
||||
#define USBD_PID 0xaaaa /* Replace '0xaaaa' with your device product ID */
|
||||
#define USBD_LANGID_STRING 0xbbb /* Replace '0xbbb' with your device language ID */
|
||||
#define USBD_LANGID_STRING 0xbbb /* Replace '0xbbb' with your device language ID */
|
||||
#define USBD_MANUFACTURER_STRING "xxxxx" /* Add your manufacturer string */
|
||||
#define USBD_PRODUCT_HS_STRING "xxxxx" /* Add your product High Speed string */
|
||||
#define USBD_PRODUCT_FS_STRING "xxxxx" /* Add your product Full Speed string */
|
||||
@@ -46,9 +45,14 @@ uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
|
||||
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#ifdef USBD_SUPPORT_USER_STRING_DESC
|
||||
uint8_t *USBD_Class_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||
uint8_t *USBD_Class_UserStrDescriptor(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||
#endif /* USB_CLASS_USER_STRING_DESC */
|
||||
|
||||
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||
uint8_t *USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#endif
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
USBD_DescriptorsTypeDef Class_Desc =
|
||||
@@ -60,17 +64,29 @@ USBD_DescriptorsTypeDef Class_Desc =
|
||||
USBD_Class_SerialStrDescriptor,
|
||||
USBD_Class_ConfigStrDescriptor,
|
||||
USBD_Class_InterfaceStrDescriptor,
|
||||
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||
USBD_CLASS_UserStrDescriptor,
|
||||
#endif
|
||||
|
||||
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||
USBD_USR_BOSDescriptor,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__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 */
|
||||
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
|
||||
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||
0x01, /*bcdUSB */ /* changed to USB version 2.01
|
||||
in order to support BOS Desc */
|
||||
#else
|
||||
0x00, /* bcdUSB */
|
||||
#endif
|
||||
0x02,
|
||||
0x00, /* bDeviceClass */
|
||||
0x00, /* bDeviceSubClass */
|
||||
@@ -88,11 +104,123 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
||||
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
|
||||
}; /* USB_DeviceDescriptor */
|
||||
|
||||
|
||||
/* USB Device LPM BOS descriptor */
|
||||
#if (USBD_LPM_ENABLED == 1)
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
||||
{
|
||||
0x5,
|
||||
USB_DESC_TYPE_BOS,
|
||||
0xC,
|
||||
0x0,
|
||||
0x1, /* 1 device capability */
|
||||
/* device capability */
|
||||
0x7,
|
||||
USB_DEVICE_CAPABITY_TYPE,
|
||||
0x2,
|
||||
0x6, /*LPM capability bit set */
|
||||
0x0,
|
||||
0x0,
|
||||
0x0
|
||||
};
|
||||
#endif
|
||||
|
||||
/* USB Device Billboard BOS descriptor Template */
|
||||
#if (USBD_CLASS_BOS_ENABLED == 1)
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_BOSDesc[USB_SIZ_BOS_DESC] __ALIGN_END =
|
||||
{
|
||||
0x05, /* bLength */
|
||||
USB_DESC_TYPE_BOS, /* Device Descriptor Type */
|
||||
USB_SIZ_BOS_DESC, /* Total length of BOS descriptor and all of its sub descs */
|
||||
0x00,
|
||||
0x04, /* The number of separate device capability descriptors in the BOS */
|
||||
|
||||
/* ----------- Device Capability Descriptor: CONTAINER_ID ---------- */
|
||||
0x14, /* bLength */
|
||||
0x10, /* bDescriptorType: DEVICE CAPABILITY Type */
|
||||
0x04, /* bDevCapabilityType: CONTAINER_ID */
|
||||
0x00, /* bReserved */
|
||||
0xa7, 0xd6, 0x1b, 0xfa, /* ContainerID: This is a Unique 128-bit number GUID */
|
||||
0x91, 0xa6, 0xa8, 0x4e,
|
||||
0xa8, 0x21, 0x9f, 0x2b,
|
||||
0xaf, 0xf7, 0x94, 0xd4,
|
||||
|
||||
/* ----------- Device Capability Descriptor: BillBoard ---------- */
|
||||
0x34, /* bLength */
|
||||
0x10, /* bDescriptorType: DEVICE CAPABILITY Type */
|
||||
0x0D, /* bDevCapabilityType: BILLBOARD_CAPABILITY */
|
||||
USBD_BB_URL_STRING_INDEX, /* iAddtionalInfoURL: Index of string descriptor providing a URL where the user can go to get more
|
||||
detailed information about the product and the various Alternate Modes it supports */
|
||||
|
||||
0x02, /* bNumberOfAlternateModes: Number of Alternate modes supported. The
|
||||
maximum value that this field can be set to is MAX_NUM_ALT_MODE. */
|
||||
|
||||
0x00, /* bPreferredAlternateMode: Index of the preferred Alternate Mode. System
|
||||
software may use this information to provide the user with a better user experience. */
|
||||
|
||||
0x00, 0x00, /* VCONN Power needed by the adapter for full functionality 000b = 1W */
|
||||
|
||||
0x01, 0x00, 0x00, 0x00, /* bmConfigured. 01b: Alternate Mode configuration not attempted or exited */
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x21, 0x01, /* bcdVersion = 0x0121 */
|
||||
0x00, /* bAdditionalFailureInfo */
|
||||
0x00, /* bReserved */
|
||||
LOBYTE(USBD_VID),
|
||||
HIBYTE(USBD_VID), /* wSVID[0]: Standard or Vendor ID. This shall match one of the SVIDs
|
||||
returned in response to a USB PD Discover SVIDs command */
|
||||
|
||||
0x00, /* bAlternateMode[0] Index of the Alternate Mode within the SVID as
|
||||
returned in response to a Discover Modes command. Example:
|
||||
0 first Mode entry
|
||||
1 second mode entry */
|
||||
|
||||
USBD_BB_ALTMODE0_STRING_INDEX, /* iAlternateModeString[0]: Index of string descriptor describing protocol.
|
||||
It is optional to support this string. */
|
||||
LOBYTE(USBD_VID),
|
||||
HIBYTE(USBD_VID), /* wSVID[1]: Standard or Vendor ID. This shall match one of the SVIDs
|
||||
returned in response to a USB PD Discover SVIDs command */
|
||||
|
||||
0x01, /* bAlternateMode[1] Index of the Alternate Mode within the SVID as
|
||||
returned in response to a Discover Modes command. Example:
|
||||
0 first Mode entry
|
||||
1 second Mode entry */
|
||||
|
||||
USBD_BB_ALTMODE1_STRING_INDEX, /* iAlternateModeString[1]: Index of string descriptor describing protocol.
|
||||
It is optional to support this string. */
|
||||
/* Alternate Mode Desc */
|
||||
/* ----------- Device Capability Descriptor: BillBoard Alternate Mode Desc ---------- */
|
||||
0x08, /* bLength */
|
||||
0x10, /* bDescriptorType: Device Descriptor Type */
|
||||
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
|
||||
0x00, /* bIndex: Index of Alternate Mode described in the Billboard Capability Desc */
|
||||
0x10, 0x00, 0x00, 0x00, /* dwAlternateModeVdo: contents of the Mode VDO for the alternate mode identified by bIndex */
|
||||
|
||||
0x08, /* bLength */
|
||||
0x10, /* bDescriptorType: Device Descriptor Type */
|
||||
0x0F, /* bDevCapabilityType: BILLBOARD ALTERNATE MODE CAPABILITY */
|
||||
0x01, /* bIndex: Index of Alternate Mode described in the Billboard Capability Desc */
|
||||
0x20, 0x00, 0x00, 0x00, /* dwAlternateModeVdo: contents of the Mode VDO for the alternate mode identified by bIndex */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__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_DESC_TYPE_STRING,
|
||||
@@ -100,7 +228,10 @@ __ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
||||
HIBYTE(USBD_LANGID_STRING),
|
||||
};
|
||||
|
||||
uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
|
||||
{
|
||||
USB_SIZ_STRING_SERIAL,
|
||||
USB_DESC_TYPE_STRING,
|
||||
@@ -123,6 +254,8 @@ static void Get_SerialNum(void);
|
||||
*/
|
||||
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
UNUSED(speed);
|
||||
|
||||
*length = sizeof(USBD_DeviceDesc);
|
||||
return (uint8_t *)USBD_DeviceDesc;
|
||||
}
|
||||
@@ -135,6 +268,8 @@ uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
*/
|
||||
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
UNUSED(speed);
|
||||
|
||||
*length = sizeof(USBD_LangIDDesc);
|
||||
return (uint8_t *)USBD_LangIDDesc;
|
||||
}
|
||||
@@ -166,6 +301,8 @@ uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
|
||||
*/
|
||||
uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
UNUSED(speed);
|
||||
|
||||
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
@@ -178,6 +315,8 @@ uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t
|
||||
*/
|
||||
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
UNUSED(speed);
|
||||
|
||||
*length = USB_SIZ_STRING_SERIAL;
|
||||
|
||||
/* Update the serial number string descriptor with the data from the unique ID*/
|
||||
@@ -246,6 +385,40 @@ static void Get_SerialNum(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if ((USBD_LPM_ENABLED == 1) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||
/**
|
||||
* @brief USBD_USR_BOSDescriptor
|
||||
* return the BOS descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer to data length variable
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_BOSDesc);
|
||||
return (uint8_t *)USBD_BOSDesc;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||
/**
|
||||
* @brief Returns the Class User string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param idx: index of string descriptor
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_Class_UserStrDescriptor(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length)
|
||||
{
|
||||
static uint8_t USBD_StrDesc[255];
|
||||
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convert Hex 32Bits value into char
|
||||
* @param value: value to convert
|
||||
@@ -273,5 +446,3 @@ static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len)
|
||||
pbuf[2U * idx + 1] = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@@ -77,123 +76,133 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlSendData
|
||||
* send data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_CtlSendData
|
||||
* send data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint16_t len)
|
||||
uint8_t *pbuf, uint32_t len)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_DATA_IN;
|
||||
pdev->ep_in[0].total_length = len;
|
||||
pdev->ep_in[0].rem_length = len;
|
||||
|
||||
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||
pdev->ep_in[0].rem_length = 0U;
|
||||
#else
|
||||
pdev->ep_in[0].rem_length = len;
|
||||
#endif
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlContinueSendData
|
||||
* continue sending data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_CtlContinueSendData
|
||||
* continue sending data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint16_t len)
|
||||
uint8_t *pbuf, uint32_t len)
|
||||
{
|
||||
/* Start the next transfer */
|
||||
USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlPrepareRx
|
||||
* receive data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_CtlPrepareRx
|
||||
* receive data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint16_t len)
|
||||
uint8_t *pbuf, uint32_t len)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
||||
pdev->ep_out[0].total_length = len;
|
||||
pdev->ep_out[0].rem_length = len;
|
||||
|
||||
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||
pdev->ep_out[0].rem_length = 0U;
|
||||
#else
|
||||
pdev->ep_out[0].rem_length = len;
|
||||
#endif
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlContinueRx
|
||||
* continue receive data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_CtlContinueRx
|
||||
* continue receive data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint16_t len)
|
||||
uint8_t *pbuf, uint32_t len)
|
||||
{
|
||||
USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlSendStatus
|
||||
* send zero lzngth packet on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_CtlSendStatus
|
||||
* send zero lzngth packet on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
|
||||
(void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlReceiveStatus
|
||||
* receive zero lzngth packet on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
* @brief USBD_CtlReceiveStatus
|
||||
* receive zero lzngth packet on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||
(void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetRxCount
|
||||
* returns the received data length
|
||||
* @param pdev: device instance
|
||||
* @param ep_addr: endpoint address
|
||||
* @retval Rx Data blength
|
||||
*/
|
||||
* @brief USBD_GetRxCount
|
||||
* returns the received data length
|
||||
* @param pdev: device instance
|
||||
* @param ep_addr: endpoint address
|
||||
* @retval Rx Data blength
|
||||
*/
|
||||
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
||||
@@ -213,4 +222,3 @@ uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
86
LICENSE.txt
Normal file
86
LICENSE.txt
Normal file
@@ -0,0 +1,86 @@
|
||||
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.
|
||||
|
||||
81
License.md
81
License.md
@@ -1,3 +1,80 @@
|
||||
# Copyright (c) 2015 STMicroelectronics.
|
||||
SLA0044 Rev5/February 2018
|
||||
|
||||
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).
|
||||
## 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.
|
||||
|
||||
14
README.md
14
README.md
@@ -29,20 +29,6 @@ This software component is licensed by ST under Ultimate Liberty license SLA004
|
||||
|
||||
Details about the content of this release are available in the release note [here](https://htmlpreview.github.io/?https://github.com/STMicroelectronics/stm32_mw_usb_device/blob/master/Release_Notes.html).
|
||||
|
||||
## Compatibility information
|
||||
|
||||
This table shows the correspondence between the USB Device MW version and the corresponding HAL version of the targeted series. It is **crucial** that you use a consistent set of versions for the MW - HAL, as mentioned in this table.
|
||||
|
||||
Note that:
|
||||
* in case a series does not support a particular tag, it is not mentioned in front of it.
|
||||
* in case a series supports a recent tag, it is not mentioned in front of older ones.
|
||||
|
||||
USB Device | HAL |
|
||||
---------- | ---------- |
|
||||
Tag v2.5.1 | Tag v1.10.2 ([stm32l0xx_hal_driver](https://github.com/STMicroelectronics/stm32l0xx_hal_driver))
|
||||
Tag v2.5.2 | Tag v1.4.0 ([stm32l1xx_hal_driver](https://github.com/STMicroelectronics/stm32l1xx_hal_driver))
|
||||
Tag v2.5.3 | Tag v1.7.3 ([stm32f0xx_hal_driver](https://github.com/STMicroelectronics/stm32f0xx_hal_driver))<br>Tag v1.1.4 ([stm32f1xx_hal_driver](https://github.com/STMicroelectronics/stm32f1xx_hal_driver))<br>Tag v1.2.4 ([stm32f2xx_hal_driver](https://github.com/STMicroelectronics/stm32f2xx_hal_driver))<br>Tag v1.5.3 ([stm32f3xx_hal_driver](https://github.com/STMicroelectronics/stm32f3xx_hal_driver))
|
||||
|
||||
## 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).
|
||||
|
||||
2874
Release_Notes.html
2874
Release_Notes.html
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user