forked from stm/stm32-mw-usb-device
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60d163f271 | ||
|
|
d1a9b6baea | ||
|
|
edbaa3cd1d | ||
|
|
228c5c57ea | ||
|
|
e5a58ee226 |
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USB_AUDIO_H
|
#define __USB_AUDIO_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -50,6 +50,14 @@
|
|||||||
#define USBD_MAX_NUM_INTERFACES 1U
|
#define USBD_MAX_NUM_INTERFACES 1U
|
||||||
#endif /* USBD_AUDIO_FREQ */
|
#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 AUDIO_OUT_EP 0x01U
|
||||||
#define USB_AUDIO_CONFIG_DESC_SIZ 0x6DU
|
#define USB_AUDIO_CONFIG_DESC_SIZ 0x6DU
|
||||||
#define AUDIO_INTERFACE_DESC_SIZE 0x09U
|
#define AUDIO_INTERFACE_DESC_SIZE 0x09U
|
||||||
@@ -91,6 +99,9 @@
|
|||||||
|
|
||||||
#define AUDIO_OUT_STREAMING_CTRL 0x02U
|
#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_OUT_PACKET (uint16_t)(((USBD_AUDIO_FREQ * 2U * 2U) / 1000U))
|
||||||
#define AUDIO_DEFAULT_VOLUME 70U
|
#define AUDIO_DEFAULT_VOLUME 70U
|
||||||
@@ -101,13 +112,13 @@
|
|||||||
/* Total size of the audio transfer buffer */
|
/* Total size of the audio transfer buffer */
|
||||||
#define AUDIO_TOTAL_BUF_SIZE ((uint16_t)(AUDIO_OUT_PACKET * AUDIO_OUT_PACKET_NUM))
|
#define AUDIO_TOTAL_BUF_SIZE ((uint16_t)(AUDIO_OUT_PACKET * AUDIO_OUT_PACKET_NUM))
|
||||||
|
|
||||||
/* Audio Commands enumeration */
|
/* Audio Commands enumeration */
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
AUDIO_CMD_START = 1,
|
AUDIO_CMD_START = 1,
|
||||||
AUDIO_CMD_PLAY,
|
AUDIO_CMD_PLAY,
|
||||||
AUDIO_CMD_STOP,
|
AUDIO_CMD_STOP,
|
||||||
}AUDIO_CMD_TypeDef;
|
} AUDIO_CMD_TypeDef;
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@@ -116,8 +127,7 @@ typedef enum
|
|||||||
AUDIO_OFFSET_HALF,
|
AUDIO_OFFSET_HALF,
|
||||||
AUDIO_OFFSET_FULL,
|
AUDIO_OFFSET_FULL,
|
||||||
AUDIO_OFFSET_UNKNOWN,
|
AUDIO_OFFSET_UNKNOWN,
|
||||||
}
|
} AUDIO_OffsetTypeDef;
|
||||||
AUDIO_OffsetTypeDef;
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -126,15 +136,13 @@ AUDIO_OffsetTypeDef;
|
|||||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
uint8_t data[USB_MAX_EP0_SIZE];
|
uint8_t data[USB_MAX_EP0_SIZE];
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
uint8_t unit;
|
uint8_t unit;
|
||||||
}
|
} USBD_AUDIO_ControlTypeDef;
|
||||||
USBD_AUDIO_ControlTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -146,20 +154,19 @@ typedef struct
|
|||||||
uint16_t rd_ptr;
|
uint16_t rd_ptr;
|
||||||
uint16_t wr_ptr;
|
uint16_t wr_ptr;
|
||||||
USBD_AUDIO_ControlTypeDef control;
|
USBD_AUDIO_ControlTypeDef control;
|
||||||
}
|
} USBD_AUDIO_HandleTypeDef;
|
||||||
USBD_AUDIO_HandleTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
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 (*DeInit)(uint32_t options);
|
||||||
int8_t (*AudioCmd) (uint8_t* pbuf, uint32_t size, uint8_t cmd);
|
int8_t (*AudioCmd)(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||||
int8_t (*VolumeCtl) (uint8_t vol);
|
int8_t (*VolumeCtl)(uint8_t vol);
|
||||||
int8_t (*MuteCtl) (uint8_t cmd);
|
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);
|
int8_t (*GetState)(void);
|
||||||
}USBD_AUDIO_ItfTypeDef;
|
} USBD_AUDIO_ItfTypeDef;
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -187,10 +194,10 @@ extern USBD_ClassTypeDef USBD_AUDIO;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_AUDIO_ItfTypeDef *fops);
|
USBD_AUDIO_ItfTypeDef *fops);
|
||||||
|
|
||||||
void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_AUDIO_IF_TEMPLATE_H
|
#define __USBD_AUDIO_IF_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -48,16 +48,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}.c"
|
- "stm32xxxxx_{eval}{discovery}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_audio.h"
|
#include "usbd_audio.h"
|
||||||
@@ -103,42 +103,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_AUDIO_Private_FunctionPrototypes
|
/** @defgroup USBD_AUDIO_Private_FunctionPrototypes
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
|
||||||
|
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||||
static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev,
|
|
||||||
uint8_t cfgidx);
|
|
||||||
|
|
||||||
static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
|
||||||
uint8_t cfgidx);
|
|
||||||
|
|
||||||
static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
|
||||||
USBD_SetupReqTypedef *req);
|
USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length);
|
static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length);
|
||||||
|
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc(uint16_t *length);
|
||||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length);
|
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
|
static uint8_t USBD_AUDIO_EP0_TxReady(USBD_HandleTypeDef *pdev);
|
||||||
static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
|
||||||
|
|
||||||
static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev);
|
|
||||||
|
|
||||||
static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev);
|
|
||||||
|
|
||||||
static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
|
||||||
|
|
||||||
static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
|
||||||
|
|
||||||
|
static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,8 +162,12 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
|||||||
0x02, /* bNumInterfaces */
|
0x02, /* bNumInterfaces */
|
||||||
0x01, /* bConfigurationValue */
|
0x01, /* bConfigurationValue */
|
||||||
0x00, /* iConfiguration */
|
0x00, /* iConfiguration */
|
||||||
0xC0, /* bmAttributes BUS Powred*/
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0x32, /* bMaxPower = 100 mA*/
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* bMaxPower = 100 mA */
|
||||||
/* 09 byte*/
|
/* 09 byte*/
|
||||||
|
|
||||||
/* USB Speaker Standard interface descriptor */
|
/* USB Speaker Standard interface descriptor */
|
||||||
@@ -245,7 +233,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
|||||||
0x00, /* iTerminal */
|
0x00, /* iTerminal */
|
||||||
/* 09 byte*/
|
/* 09 byte*/
|
||||||
|
|
||||||
/* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwith */
|
/* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwidth */
|
||||||
/* Interface 1, Alternate Setting 0 */
|
/* Interface 1, Alternate Setting 0 */
|
||||||
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
|
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
|
||||||
@@ -277,7 +265,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
|||||||
AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */
|
AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */
|
||||||
0x01, /* bTerminalLink */
|
0x01, /* bTerminalLink */
|
||||||
0x01, /* bDelay */
|
0x01, /* bDelay */
|
||||||
0x01, /* wFormatTag AUDIO_FORMAT_PCM 0x0001*/
|
0x01, /* wFormatTag AUDIO_FORMAT_PCM 0x0001 */
|
||||||
0x00,
|
0x00,
|
||||||
/* 07 byte*/
|
/* 07 byte*/
|
||||||
|
|
||||||
@@ -296,10 +284,10 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
|||||||
/* Endpoint 1 - Standard Descriptor */
|
/* Endpoint 1 - Standard Descriptor */
|
||||||
AUDIO_STANDARD_ENDPOINT_DESC_SIZE, /* bLength */
|
AUDIO_STANDARD_ENDPOINT_DESC_SIZE, /* bLength */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType */
|
||||||
AUDIO_OUT_EP, /* bEndpointAddress 1 out endpoint*/
|
AUDIO_OUT_EP, /* bEndpointAddress 1 out endpoint */
|
||||||
USBD_EP_TYPE_ISOC, /* bmAttributes */
|
USBD_EP_TYPE_ISOC, /* bmAttributes */
|
||||||
AUDIO_PACKET_SZE(USBD_AUDIO_FREQ), /* wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
|
AUDIO_PACKET_SZE(USBD_AUDIO_FREQ), /* wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
|
||||||
0x01, /* bInterval */
|
AUDIO_FS_BINTERVAL, /* bInterval */
|
||||||
0x00, /* bRefresh */
|
0x00, /* bRefresh */
|
||||||
0x00, /* bSynchAddress */
|
0x00, /* bSynchAddress */
|
||||||
/* 09 byte*/
|
/* 09 byte*/
|
||||||
@@ -316,7 +304,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
|||||||
} ;
|
} ;
|
||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END=
|
__ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
{
|
{
|
||||||
USB_LEN_DEV_QUALIFIER_DESC,
|
USB_LEN_DEV_QUALIFIER_DESC,
|
||||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||||
@@ -345,24 +333,35 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIE
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @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)
|
||||||
{
|
{
|
||||||
|
UNUSED(cfgidx);
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
|
|
||||||
|
/* Allocate Audio structure */
|
||||||
|
haudio = USBD_malloc(sizeof(USBD_AUDIO_HandleTypeDef));
|
||||||
|
|
||||||
|
if (haudio == NULL)
|
||||||
|
{
|
||||||
|
pdev->pClassData = NULL;
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 */
|
/* Open EP OUT */
|
||||||
USBD_LL_OpenEP(pdev, AUDIO_OUT_EP, USBD_EP_TYPE_ISOC, AUDIO_OUT_PACKET);
|
(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;
|
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Allocate Audio structure */
|
|
||||||
pdev->pClassData = USBD_malloc(sizeof (USBD_AUDIO_HandleTypeDef));
|
|
||||||
|
|
||||||
if(pdev->pClassData == NULL)
|
|
||||||
{
|
|
||||||
return USBD_FAIL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
|
||||||
haudio->alt_setting = 0U;
|
haudio->alt_setting = 0U;
|
||||||
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
||||||
haudio->wr_ptr = 0U;
|
haudio->wr_ptr = 0U;
|
||||||
@@ -372,16 +371,16 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
/* Initialize the Audio output Hardware layer */
|
/* Initialize the Audio output Hardware layer */
|
||||||
if (((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->Init(USBD_AUDIO_FREQ,
|
if (((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->Init(USBD_AUDIO_FREQ,
|
||||||
AUDIO_DEFAULT_VOLUME,
|
AUDIO_DEFAULT_VOLUME,
|
||||||
0U) != 0)
|
0U) != 0U)
|
||||||
{
|
{
|
||||||
return USBD_FAIL;
|
return (uint8_t)USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive 1st packet */
|
/* Prepare Out endpoint to receive 1st packet */
|
||||||
USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, haudio->buffer,
|
(void)USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, haudio->buffer,
|
||||||
AUDIO_OUT_PACKET);
|
AUDIO_OUT_PACKET);
|
||||||
}
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -391,23 +390,24 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
uint8_t cfgidx)
|
|
||||||
{
|
{
|
||||||
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* 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].is_used = 0U;
|
||||||
|
pdev->ep_out[AUDIO_OUT_EP & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData != NULL)
|
||||||
{
|
{
|
||||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0U);
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0U);
|
||||||
USBD_free(pdev->pClassData);
|
(void)USBD_free(pdev->pClassData);
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -417,20 +417,25 @@ static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint8_t *pbuf;
|
uint8_t *pbuf;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
uint8_t ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (haudio == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS:
|
||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
case AUDIO_REQ_GET_CUR:
|
case AUDIO_REQ_GET_CUR:
|
||||||
@@ -442,7 +447,7 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -454,38 +459,38 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
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
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_DESCRIPTOR:
|
case USB_REQ_GET_DESCRIPTOR:
|
||||||
if( (req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
if ((req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
||||||
{
|
{
|
||||||
pbuf = USBD_AUDIO_CfgDesc + 18;
|
pbuf = USBD_AUDIO_CfgDesc + 18;
|
||||||
len = MIN(USB_AUDIO_DESC_SIZ , req->wLength);
|
len = MIN(USB_AUDIO_DESC_SIZ, req->wLength);
|
||||||
|
|
||||||
USBD_CtlSendData (pdev, pbuf, len);
|
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE :
|
case USB_REQ_GET_INTERFACE:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
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
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE :
|
case USB_REQ_SET_INTERFACE:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES)
|
if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES)
|
||||||
@@ -494,31 +499,34 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Call the error management function (command will be nacked */
|
/* Call the error management function (command will be NAKed */
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -529,9 +537,10 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_AUDIO_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,12 +551,13 @@ static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(epnum);
|
||||||
|
|
||||||
/* Only OUT data are processed */
|
/* Only OUT data are processed */
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -556,13 +566,19 @@ static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev,
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (haudio == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
if (haudio->control.cmd == AUDIO_REQ_SET_CUR)
|
if (haudio->control.cmd == AUDIO_REQ_SET_CUR)
|
||||||
{/* In this driver, to simplify code, only SET_CUR request is managed */
|
{
|
||||||
|
/* In this driver, to simplify code, only SET_CUR request is managed */
|
||||||
|
|
||||||
if (haudio->control.unit == AUDIO_OUT_STREAMING_CTRL)
|
if (haudio->control.unit == AUDIO_OUT_STREAMING_CTRL)
|
||||||
{
|
{
|
||||||
@@ -572,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
|
* @brief USBD_AUDIO_EP0_TxReady
|
||||||
@@ -580,10 +596,12 @@ static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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 */
|
/* Only OUT control data are processed */
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief USBD_AUDIO_SOF
|
* @brief USBD_AUDIO_SOF
|
||||||
@@ -591,9 +609,11 @@ static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -602,17 +622,23 @@ static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
uint32_t BufferSize = AUDIO_TOTAL_BUF_SIZE / 2U;
|
||||||
|
|
||||||
|
if (pdev->pClassData == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
haudio->offset = offset;
|
haudio->offset = offset;
|
||||||
|
|
||||||
if(haudio->rd_enable == 1U)
|
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)
|
if (haudio->rd_ptr == AUDIO_TOTAL_BUF_SIZE)
|
||||||
{
|
{
|
||||||
@@ -621,40 +647,39 @@ void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(haudio->rd_ptr > haudio->wr_ptr)
|
if (haudio->rd_ptr > haudio->wr_ptr)
|
||||||
{
|
{
|
||||||
if((haudio->rd_ptr - haudio->wr_ptr) < AUDIO_OUT_PACKET)
|
if ((haudio->rd_ptr - haudio->wr_ptr) < AUDIO_OUT_PACKET)
|
||||||
{
|
{
|
||||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U + 4U;
|
BufferSize += 4U;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if((haudio->rd_ptr - haudio->wr_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
if ((haudio->rd_ptr - haudio->wr_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||||
{
|
{
|
||||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U;
|
BufferSize -= 4U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if((haudio->wr_ptr - haudio->rd_ptr) < AUDIO_OUT_PACKET)
|
if ((haudio->wr_ptr - haudio->rd_ptr) < AUDIO_OUT_PACKET)
|
||||||
{
|
{
|
||||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U - 4U;
|
BufferSize -= 4U;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if((haudio->wr_ptr - haudio->rd_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
if ((haudio->wr_ptr - haudio->rd_ptr) > (AUDIO_TOTAL_BUF_SIZE - AUDIO_OUT_PACKET))
|
||||||
{
|
{
|
||||||
cmd = AUDIO_TOTAL_BUF_SIZE / 2U + 4U;
|
BufferSize += 4U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(haudio->offset == AUDIO_OFFSET_FULL)
|
if (haudio->offset == AUDIO_OFFSET_FULL)
|
||||||
{
|
{
|
||||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||||
cmd,
|
BufferSize, AUDIO_CMD_PLAY);
|
||||||
AUDIO_CMD_PLAY);
|
|
||||||
haudio->offset = AUDIO_OFFSET_NONE;
|
haudio->offset = AUDIO_OFFSET_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -666,10 +691,12 @@ void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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)
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(epnum);
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief USBD_AUDIO_IsoOutIncomplete
|
* @brief USBD_AUDIO_IsoOutIncomplete
|
||||||
@@ -678,10 +705,12 @@ static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t ep
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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)
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(epnum);
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief USBD_AUDIO_DataOut
|
* @brief USBD_AUDIO_DataOut
|
||||||
@@ -690,24 +719,36 @@ static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t e
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
|
uint16_t PacketSize;
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
|
||||||
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (haudio == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
if (epnum == AUDIO_OUT_EP)
|
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)
|
if (haudio->wr_ptr == AUDIO_TOTAL_BUF_SIZE)
|
||||||
{
|
{
|
||||||
/* All buffers are full: roll back */
|
/* All buffers are full: roll back */
|
||||||
haudio->wr_ptr = 0U;
|
haudio->wr_ptr = 0U;
|
||||||
|
|
||||||
if(haudio->offset == AUDIO_OFFSET_UNKNOWN)
|
if (haudio->offset == AUDIO_OFFSET_UNKNOWN)
|
||||||
{
|
{
|
||||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||||
AUDIO_TOTAL_BUF_SIZE / 2U,
|
AUDIO_TOTAL_BUF_SIZE / 2U,
|
||||||
@@ -716,7 +757,7 @@ static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(haudio->rd_enable == 0U)
|
if (haudio->rd_enable == 0U)
|
||||||
{
|
{
|
||||||
if (haudio->wr_ptr == (AUDIO_TOTAL_BUF_SIZE / 2U))
|
if (haudio->wr_ptr == (AUDIO_TOTAL_BUF_SIZE / 2U))
|
||||||
{
|
{
|
||||||
@@ -725,11 +766,12 @@ static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive next audio packet */
|
/* Prepare Out endpoint to receive next audio packet */
|
||||||
USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, &haudio->buffer[haudio->wr_ptr],
|
(void)USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP,
|
||||||
|
&haudio->buffer[haudio->wr_ptr],
|
||||||
AUDIO_OUT_PACKET);
|
AUDIO_OUT_PACKET);
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -742,12 +784,17 @@ static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
memset(haudio->control.data, 0, 64U);
|
if (haudio == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)USBD_memset(haudio->control.data, 0, 64U);
|
||||||
|
|
||||||
/* Send the current mute state */
|
/* Send the current mute state */
|
||||||
USBD_CtlSendData (pdev, haudio->control.data, req->wLength);
|
(void)USBD_CtlSendData(pdev, haudio->control.data, req->wLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -760,14 +807,17 @@ static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_AUDIO_HandleTypeDef *haudio;
|
USBD_AUDIO_HandleTypeDef *haudio;
|
||||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
if (req->wLength)
|
if (haudio == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req->wLength != 0U)
|
||||||
{
|
{
|
||||||
/* Prepare the reception of the buffer over EP0 */
|
/* Prepare the reception of the buffer over EP0 */
|
||||||
USBD_CtlPrepareRx (pdev,
|
(void)USBD_CtlPrepareRx(pdev, haudio->control.data, req->wLength);
|
||||||
haudio->control.data,
|
|
||||||
req->wLength);
|
|
||||||
|
|
||||||
haudio->control.cmd = AUDIO_REQ_SET_CUR; /* Set the request value */
|
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)req->wLength; /* Set the request data length */
|
||||||
@@ -777,30 +827,34 @@ static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length)
|
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;
|
return USBD_AUDIO_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_AUDIO_RegisterInterface
|
* @brief USBD_AUDIO_RegisterInterface
|
||||||
* @param fops: Audio interface callback
|
* @param fops: Audio interface callback
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_AUDIO_ItfTypeDef *fops)
|
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;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}.c"
|
- "stm32xxxxx_{eval}{discovery}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_audio_if_template.h"
|
#include "usbd_audio_if_template.h"
|
||||||
@@ -65,13 +65,13 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int8_t TEMPLATE_Init (uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
static int8_t TEMPLATE_Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options);
|
||||||
static int8_t TEMPLATE_DeInit (uint32_t options);
|
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_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||||
static int8_t TEMPLATE_VolumeCtl (uint8_t vol);
|
static int8_t TEMPLATE_VolumeCtl(uint8_t vol);
|
||||||
static int8_t TEMPLATE_MuteCtl (uint8_t cmd);
|
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);
|
static int8_t TEMPLATE_GetState(void);
|
||||||
|
|
||||||
USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops =
|
USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops =
|
||||||
{
|
{
|
||||||
@@ -94,6 +94,10 @@ USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops =
|
|||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options)
|
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
|
Add your initialization code here
|
||||||
*/
|
*/
|
||||||
@@ -108,6 +112,8 @@ static int8_t TEMPLATE_Init(uint32_t AudioFreq, uint32_t Volume, uint32_t optio
|
|||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_DeInit(uint32_t options)
|
static int8_t TEMPLATE_DeInit(uint32_t options)
|
||||||
{
|
{
|
||||||
|
UNUSED(options);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Add your deinitialization code here
|
Add your deinitialization code here
|
||||||
*/
|
*/
|
||||||
@@ -123,8 +129,11 @@ static int8_t TEMPLATE_DeInit(uint32_t options)
|
|||||||
* @param cmd: command opcode
|
* @param cmd: command opcode
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd)
|
static int8_t TEMPLATE_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd)
|
||||||
{
|
{
|
||||||
|
UNUSED(pbuf);
|
||||||
|
UNUSED(size);
|
||||||
|
UNUSED(cmd);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -134,8 +143,9 @@ static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd)
|
|||||||
* @param vol: volume level (0..100)
|
* @param vol: volume level (0..100)
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_VolumeCtl (uint8_t vol)
|
static int8_t TEMPLATE_VolumeCtl(uint8_t vol)
|
||||||
{
|
{
|
||||||
|
UNUSED(vol);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -145,8 +155,9 @@ static int8_t TEMPLATE_VolumeCtl (uint8_t vol)
|
|||||||
* @param cmd: vmute command
|
* @param cmd: vmute command
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_MuteCtl (uint8_t cmd)
|
static int8_t TEMPLATE_MuteCtl(uint8_t cmd)
|
||||||
{
|
{
|
||||||
|
UNUSED(cmd);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -156,8 +167,11 @@ static int8_t TEMPLATE_MuteCtl (uint8_t cmd)
|
|||||||
* @param cmd
|
* @param cmd
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
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);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -167,9 +181,8 @@ static int8_t TEMPLATE_PeriodicTC (uint8_t cmd)
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_GetState (void)
|
static int8_t TEMPLATE_GetState(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
163
Class/BillBoard/Inc/usbd_billboard.h
Normal file
163
Class/BillBoard/Inc/usbd_billboard.h
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_billboard.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header file for the usbd_billboard.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2019 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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
504
Class/BillBoard/Src/usbd_billboard.c
Normal file
504
Class/BillBoard/Src/usbd_billboard.c
Normal file
@@ -0,0 +1,504 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @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
|
||||||
|
* @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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2019 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 ------------------------------------------------------------------*/
|
||||||
|
#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 100 mA: this current is used for detecting Vbus */
|
||||||
|
/* 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 100 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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USB_CDC_H
|
#define __USB_CDC_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -46,11 +46,11 @@
|
|||||||
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
||||||
|
|
||||||
#ifndef CDC_HS_BINTERVAL
|
#ifndef CDC_HS_BINTERVAL
|
||||||
#define CDC_HS_BINTERVAL 0x10U
|
#define CDC_HS_BINTERVAL 0x10U
|
||||||
#endif /* CDC_HS_BINTERVAL */
|
#endif /* CDC_HS_BINTERVAL */
|
||||||
|
|
||||||
#ifndef CDC_FS_BINTERVAL
|
#ifndef CDC_FS_BINTERVAL
|
||||||
#define CDC_FS_BINTERVAL 0x10U
|
#define CDC_FS_BINTERVAL 0x10U
|
||||||
#endif /* CDC_FS_BINTERVAL */
|
#endif /* CDC_FS_BINTERVAL */
|
||||||
|
|
||||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||||
@@ -65,6 +65,7 @@
|
|||||||
#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
#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_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||||
|
|
||||||
|
#define CDC_REQ_MAX_DATA_SIZE 0x7U
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
/* CDC definitions */
|
/* CDC definitions */
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
@@ -96,16 +97,16 @@ typedef struct
|
|||||||
uint8_t format;
|
uint8_t format;
|
||||||
uint8_t paritytype;
|
uint8_t paritytype;
|
||||||
uint8_t datatype;
|
uint8_t datatype;
|
||||||
}USBD_CDC_LineCodingTypeDef;
|
} USBD_CDC_LineCodingTypeDef;
|
||||||
|
|
||||||
typedef struct _USBD_CDC_Itf
|
typedef struct _USBD_CDC_Itf
|
||||||
{
|
{
|
||||||
int8_t (* Init) (void);
|
int8_t (* Init)(void);
|
||||||
int8_t (* DeInit) (void);
|
int8_t (* DeInit)(void);
|
||||||
int8_t (* Control) (uint8_t cmd, uint8_t* pbuf, uint16_t length);
|
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||||
int8_t (* Receive) (uint8_t* Buf, uint32_t *Len);
|
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||||
|
int8_t (* TransmitCplt)(uint8_t *Buf, uint32_t *Len, uint8_t epnum);
|
||||||
}USBD_CDC_ItfTypeDef;
|
} USBD_CDC_ItfTypeDef;
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -120,8 +121,7 @@ typedef struct
|
|||||||
|
|
||||||
__IO uint32_t TxState;
|
__IO uint32_t TxState;
|
||||||
__IO uint32_t RxState;
|
__IO uint32_t RxState;
|
||||||
}
|
} USBD_CDC_HandleTypeDef;
|
||||||
USBD_CDC_HandleTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -146,19 +146,15 @@ extern USBD_ClassTypeDef USBD_CDC;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_ItfTypeDef *fops);
|
USBD_CDC_ItfTypeDef *fops);
|
||||||
|
|
||||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff,
|
||||||
uint8_t *pbuff,
|
uint32_t length);
|
||||||
uint16_t length);
|
|
||||||
|
|
||||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff);
|
||||||
uint8_t *pbuff);
|
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||||
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||||
uint8_t USBD_CDC_ReceivePacket (USBD_HandleTypeDef *pdev);
|
|
||||||
|
|
||||||
uint8_t USBD_CDC_TransmitPacket (USBD_HandleTypeDef *pdev);
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_CDC_IF_TEMPLATE_H
|
#define __USBD_CDC_IF_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -45,15 +45,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_cdc.h"
|
#include "usbd_cdc.h"
|
||||||
@@ -99,33 +99,18 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
|
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
|
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length);
|
||||||
uint8_t cfgidx);
|
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length);
|
||||||
|
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||||
uint8_t cfgidx);
|
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||||
|
|
||||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
|
||||||
USBD_SetupReqTypedef *req);
|
|
||||||
|
|
||||||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev,
|
|
||||||
uint8_t epnum);
|
|
||||||
|
|
||||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev,
|
|
||||||
uint8_t epnum);
|
|
||||||
|
|
||||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
|
||||||
|
|
||||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length);
|
|
||||||
|
|
||||||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length);
|
|
||||||
|
|
||||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
|
||||||
|
|
||||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
|
||||||
|
|
||||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length);
|
|
||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||||
@@ -171,9 +156,9 @@ USBD_ClassTypeDef USBD_CDC =
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* USB CDC device Configuration Descriptor */
|
/* USB CDC device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
/*Configuration Descriptor*/
|
/* Configuration Descriptor */
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
||||||
@@ -181,15 +166,18 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
0x02, /* bNumInterfaces: 2 interface */
|
0x02, /* bNumInterfaces: 2 interface */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
0xC0, /* bmAttributes: self powered */
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0x32, /* MaxPower 0 mA */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/*Interface Descriptor */
|
/* Interface Descriptor */
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||||
/* Interface descriptor type */
|
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x01, /* bNumEndpoints: One endpoints used */
|
0x01, /* bNumEndpoints: One endpoints used */
|
||||||
@@ -198,34 +186,34 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||||
0x00, /* iInterface: */
|
0x00, /* iInterface: */
|
||||||
|
|
||||||
/*Header Functional Descriptor*/
|
/* Header Functional Descriptor */
|
||||||
0x05, /* bLength: Endpoint Descriptor size */
|
0x05, /* bLength: Endpoint Descriptor size */
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||||
0x10, /* bcdCDC: spec release number */
|
0x10, /* bcdCDC: spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
|
|
||||||
/*Call Management Functional Descriptor*/
|
/* Call Management Functional Descriptor */
|
||||||
0x05, /* bFunctionLength */
|
0x05, /* bFunctionLength */
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||||
0x00, /* bmCapabilities: D0+D1 */
|
0x00, /* bmCapabilities: D0+D1 */
|
||||||
0x01, /* bDataInterface: 1 */
|
0x01, /* bDataInterface: 1 */
|
||||||
|
|
||||||
/*ACM Functional Descriptor*/
|
/* ACM Functional Descriptor */
|
||||||
0x04, /* bFunctionLength */
|
0x04, /* bFunctionLength */
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||||
0x02, /* bmCapabilities */
|
0x02, /* bmCapabilities */
|
||||||
|
|
||||||
/*Union Functional Descriptor*/
|
/* Union Functional Descriptor */
|
||||||
0x05, /* bFunctionLength */
|
0x05, /* bFunctionLength */
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
0x06, /* bDescriptorSubtype: Union func desc */
|
0x06, /* bDescriptorSubtype: Union func desc */
|
||||||
0x00, /* bMasterInterface: Communication class interface */
|
0x00, /* bMasterInterface: Communication class interface */
|
||||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||||
|
|
||||||
/*Endpoint 2 Descriptor*/
|
/* Endpoint 2 Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
CDC_CMD_EP, /* bEndpointAddress */
|
CDC_CMD_EP, /* bEndpointAddress */
|
||||||
@@ -235,7 +223,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
CDC_HS_BINTERVAL, /* bInterval: */
|
CDC_HS_BINTERVAL, /* bInterval: */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/*Data class interface descriptor*/
|
/* Data class interface descriptor */
|
||||||
0x09, /* bLength: Endpoint Descriptor size */
|
0x09, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||||
0x01, /* bInterfaceNumber: Number of Interface */
|
0x01, /* bInterfaceNumber: Number of Interface */
|
||||||
@@ -246,7 +234,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
0x00, /* bInterfaceProtocol: */
|
0x00, /* bInterfaceProtocol: */
|
||||||
0x00, /* iInterface: */
|
0x00, /* iInterface: */
|
||||||
|
|
||||||
/*Endpoint OUT Descriptor*/
|
/* Endpoint OUT Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
CDC_OUT_EP, /* bEndpointAddress */
|
CDC_OUT_EP, /* bEndpointAddress */
|
||||||
@@ -255,7 +243,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
|
|
||||||
/*Endpoint IN Descriptor*/
|
/* Endpoint IN Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
CDC_IN_EP, /* bEndpointAddress */
|
CDC_IN_EP, /* bEndpointAddress */
|
||||||
@@ -263,13 +251,13 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
||||||
0x00 /* bInterval: ignore for Bulk transfer */
|
0x00 /* bInterval: ignore for Bulk transfer */
|
||||||
} ;
|
};
|
||||||
|
|
||||||
|
|
||||||
/* USB CDC device Configuration Descriptor */
|
/* USB CDC device Configuration Descriptor */
|
||||||
__ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
/*Configuration Descriptor*/
|
/* Configuration Descriptor */
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
||||||
@@ -277,12 +265,16 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
0x02, /* bNumInterfaces: 2 interface */
|
0x02, /* bNumInterfaces: 2 interface */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
0xC0, /* bmAttributes: self powered */
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0x32, /* MaxPower 0 mA */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA */
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/*Interface Descriptor */
|
/* Interface Descriptor */
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||||
/* Interface descriptor type */
|
/* Interface descriptor type */
|
||||||
@@ -294,34 +286,34 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||||
0x00, /* iInterface: */
|
0x00, /* iInterface: */
|
||||||
|
|
||||||
/*Header Functional Descriptor*/
|
/* Header Functional Descriptor */
|
||||||
0x05, /* bLength: Endpoint Descriptor size */
|
0x05, /* bLength: Endpoint Descriptor size */
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||||
0x10, /* bcdCDC: spec release number */
|
0x10, /* bcdCDC: spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
|
|
||||||
/*Call Management Functional Descriptor*/
|
/* Call Management Functional Descriptor */
|
||||||
0x05, /* bFunctionLength */
|
0x05, /* bFunctionLength */
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||||
0x00, /* bmCapabilities: D0+D1 */
|
0x00, /* bmCapabilities: D0+D1 */
|
||||||
0x01, /* bDataInterface: 1 */
|
0x01, /* bDataInterface: 1 */
|
||||||
|
|
||||||
/*ACM Functional Descriptor*/
|
/* ACM Functional Descriptor */
|
||||||
0x04, /* bFunctionLength */
|
0x04, /* bFunctionLength */
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||||
0x02, /* bmCapabilities */
|
0x02, /* bmCapabilities */
|
||||||
|
|
||||||
/*Union Functional Descriptor*/
|
/* Union Functional Descriptor */
|
||||||
0x05, /* bFunctionLength */
|
0x05, /* bFunctionLength */
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
0x06, /* bDescriptorSubtype: Union func desc */
|
0x06, /* bDescriptorSubtype: Union func desc */
|
||||||
0x00, /* bMasterInterface: Communication class interface */
|
0x00, /* bMasterInterface: Communication class interface */
|
||||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||||
|
|
||||||
/*Endpoint 2 Descriptor*/
|
/* Endpoint 2 Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
CDC_CMD_EP, /* bEndpointAddress */
|
CDC_CMD_EP, /* bEndpointAddress */
|
||||||
@@ -331,7 +323,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
CDC_FS_BINTERVAL, /* bInterval: */
|
CDC_FS_BINTERVAL, /* bInterval: */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/*Data class interface descriptor*/
|
/* Data class interface descriptor */
|
||||||
0x09, /* bLength: Endpoint Descriptor size */
|
0x09, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||||
0x01, /* bInterfaceNumber: Number of Interface */
|
0x01, /* bInterfaceNumber: Number of Interface */
|
||||||
@@ -342,7 +334,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
0x00, /* bInterfaceProtocol: */
|
0x00, /* bInterfaceProtocol: */
|
||||||
0x00, /* iInterface: */
|
0x00, /* iInterface: */
|
||||||
|
|
||||||
/*Endpoint OUT Descriptor*/
|
/* Endpoint OUT Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
CDC_OUT_EP, /* bEndpointAddress */
|
CDC_OUT_EP, /* bEndpointAddress */
|
||||||
@@ -351,7 +343,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
|
|
||||||
/*Endpoint IN Descriptor*/
|
/* Endpoint IN Descriptor */
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
CDC_IN_EP, /* bEndpointAddress */
|
CDC_IN_EP, /* bEndpointAddress */
|
||||||
@@ -359,19 +351,23 @@ __ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||||
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||||
0x00 /* bInterval: ignore for Bulk transfer */
|
0x00 /* bInterval: ignore for Bulk transfer */
|
||||||
} ;
|
};
|
||||||
|
|
||||||
__ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
0x09, /* bLength: Configuation Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
||||||
USB_CDC_CONFIG_DESC_SIZ,
|
USB_CDC_CONFIG_DESC_SIZ,
|
||||||
0x00,
|
0x00,
|
||||||
0x02, /* bNumInterfaces: 2 interfaces */
|
0x02, /* bNumInterfaces: 2 interfaces */
|
||||||
0x01, /* bConfigurationValue: */
|
0x01, /* bConfigurationValue: */
|
||||||
0x04, /* iConfiguration: */
|
0x04, /* iConfiguration: */
|
||||||
0xC0, /* bmAttributes: */
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0x32, /* MaxPower 100 mA */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA */
|
||||||
|
|
||||||
/*Interface Descriptor */
|
/*Interface Descriptor */
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
@@ -385,7 +381,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIG
|
|||||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||||
0x00, /* iInterface: */
|
0x00, /* iInterface: */
|
||||||
|
|
||||||
/*Header Functional Descriptor*/
|
/* Header Functional Descriptor */
|
||||||
0x05, /* bLength: Endpoint Descriptor size */
|
0x05, /* bLength: Endpoint Descriptor size */
|
||||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||||
@@ -414,7 +410,7 @@ __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIG
|
|||||||
|
|
||||||
/*Endpoint 2 Descriptor*/
|
/*Endpoint 2 Descriptor*/
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||||
CDC_CMD_EP, /* bEndpointAddress */
|
CDC_CMD_EP, /* bEndpointAddress */
|
||||||
0x03, /* bmAttributes: Interrupt */
|
0x03, /* bmAttributes: Interrupt */
|
||||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||||
@@ -468,54 +464,60 @@ __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIG
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
uint8_t ret = 0U;
|
UNUSED(cfgidx);
|
||||||
USBD_CDC_HandleTypeDef *hcdc;
|
USBD_CDC_HandleTypeDef *hcdc;
|
||||||
|
|
||||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
hcdc = USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
pdev->pClassData = NULL;
|
||||||
|
return (uint8_t)USBD_EMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdev->pClassData = (void *)hcdc;
|
||||||
|
|
||||||
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
||||||
CDC_DATA_HS_IN_PACKET_SIZE);
|
CDC_DATA_HS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
|
||||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Set bInterval for CDC CMD Endpoint */
|
||||||
|
pdev->ep_in[CDC_CMD_EP & 0xFU].bInterval = CDC_HS_BINTERVAL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Open EP IN */
|
||||||
USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
||||||
CDC_DATA_FS_IN_PACKET_SIZE);
|
CDC_DATA_FS_IN_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
|
||||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;
|
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
|
/* Set bInterval for CMD Endpoint */
|
||||||
|
pdev->ep_in[CDC_CMD_EP & 0xFU].bInterval = CDC_FS_BINTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open Command IN EP */
|
/* Open Command IN EP */
|
||||||
USBD_LL_OpenEP(pdev, CDC_CMD_EP, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
|
(void)USBD_LL_OpenEP(pdev, CDC_CMD_EP, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
|
||||||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 1U;
|
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));
|
|
||||||
|
|
||||||
if(pdev->pClassData == NULL)
|
|
||||||
{
|
|
||||||
ret = 1U;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
|
||||||
|
|
||||||
/* Init physical Interface components */
|
/* Init physical Interface components */
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();
|
||||||
|
|
||||||
@@ -523,20 +525,20 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
hcdc->TxState = 0U;
|
hcdc->TxState = 0U;
|
||||||
hcdc->RxState = 0U;
|
hcdc->RxState = 0U;
|
||||||
|
|
||||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
(void)USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
||||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
(void)USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
||||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ret;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -546,31 +548,32 @@ static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
uint8_t ret = 0U;
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
/* Close EP IN */
|
/* Close EP IN */
|
||||||
USBD_LL_CloseEP(pdev, CDC_IN_EP);
|
(void)USBD_LL_CloseEP(pdev, CDC_IN_EP);
|
||||||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP OUT */
|
/* Close EP OUT */
|
||||||
USBD_LL_CloseEP(pdev, CDC_OUT_EP);
|
(void)USBD_LL_CloseEP(pdev, CDC_OUT_EP);
|
||||||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 0U;
|
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close Command IN EP */
|
/* Close Command IN EP */
|
||||||
USBD_LL_CloseEP(pdev, CDC_CMD_EP);
|
(void)USBD_LL_CloseEP(pdev, CDC_CMD_EP);
|
||||||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U;
|
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U;
|
||||||
|
pdev->ep_in[CDC_CMD_EP & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* DeInit physical Interface components */
|
/* DeInit physical Interface components */
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||||
USBD_free(pdev->pClassData);
|
(void)USBD_free(pdev->pClassData);
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -580,39 +583,46 @@ static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||||
|
uint16_t len;
|
||||||
uint8_t ifalt = 0U;
|
uint8_t ifalt = 0U;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
uint8_t ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS:
|
||||||
if (req->wLength)
|
if (req->wLength != 0U)
|
||||||
{
|
{
|
||||||
if (req->bmRequest & 0x80U)
|
if ((req->bmRequest & 0x80U) != 0U)
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||||
(uint8_t *)(void *)hcdc->data,
|
(uint8_t *)hcdc->data,
|
||||||
req->wLength);
|
req->wLength);
|
||||||
|
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
|
len = MIN(CDC_REQ_MAX_DATA_SIZE, req->wLength);
|
||||||
|
(void)USBD_CtlSendData(pdev, (uint8_t *)hcdc->data, len);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hcdc->CmdOpCode = req->bRequest;
|
hcdc->CmdOpCode = req->bRequest;
|
||||||
hcdc->CmdLength = (uint8_t)req->wLength;
|
hcdc->CmdLength = (uint8_t)req->wLength;
|
||||||
|
|
||||||
USBD_CtlPrepareRx (pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
|
(void)USBD_CtlPrepareRx(pdev, (uint8_t *)hcdc->data, req->wLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||||
(uint8_t *)(void *)req, 0U);
|
(uint8_t *)req, 0U);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -622,11 +632,11 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
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
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -634,11 +644,11 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
case USB_REQ_GET_INTERFACE:
|
case USB_REQ_GET_INTERFACE:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
USBD_CtlSendData (pdev, &ifalt, 1U);
|
(void)USBD_CtlSendData(pdev, &ifalt, 1U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -646,25 +656,28 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
case USB_REQ_SET_INTERFACE:
|
case USB_REQ_SET_INTERFACE:
|
||||||
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -674,31 +687,38 @@ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param epnum: endpoint number
|
* @param epnum: endpoint number
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc;
|
||||||
PCD_HandleTypeDef *hpcd = pdev->pData;
|
PCD_HandleTypeDef *hpcd = pdev->pData;
|
||||||
|
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData == NULL)
|
||||||
{
|
{
|
||||||
if((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
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 */
|
/* Update the packet total length */
|
||||||
pdev->ep_in[epnum].total_length = 0U;
|
pdev->ep_in[epnum].total_length = 0U;
|
||||||
|
|
||||||
/* Send ZLP */
|
/* Send ZLP */
|
||||||
USBD_LL_Transmit (pdev, epnum, NULL, 0U);
|
(void)USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hcdc->TxState = 0U;
|
hcdc->TxState = 0U;
|
||||||
}
|
|
||||||
return USBD_OK;
|
if (((USBD_CDC_ItfTypeDef *)pdev->pUserData)->TransmitCplt != NULL)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return USBD_FAIL;
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->TransmitCplt(hcdc->TxBuffer, &hcdc->TxLength, epnum);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -708,25 +728,24 @@ static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
* @param epnum: endpoint number
|
* @param epnum: endpoint number
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (pdev->pClassData == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the received data length */
|
/* Get the received data length */
|
||||||
hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum);
|
hcdc->RxLength = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||||
|
|
||||||
/* USB data will be immediately processed, this allow next USB traffic being
|
/* USB data will be immediately processed, this allow next USB traffic being
|
||||||
NAKed till the end of the application Xfer */
|
NAKed till the end of the application Xfer */
|
||||||
if(pdev->pClassData != NULL)
|
|
||||||
{
|
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return USBD_FAIL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -735,19 +754,24 @@ static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||||
{
|
{
|
||||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
||||||
(uint8_t *)(void *)hcdc->data,
|
(uint8_t *)hcdc->data,
|
||||||
(uint16_t)hcdc->CmdLength);
|
(uint16_t)hcdc->CmdLength);
|
||||||
hcdc->CmdOpCode = 0xFFU;
|
hcdc->CmdOpCode = 0xFFU;
|
||||||
|
|
||||||
}
|
}
|
||||||
return USBD_OK;
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -757,9 +781,10 @@ static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_CDC_CfgFSDesc);
|
*length = (uint16_t)sizeof(USBD_CDC_CfgFSDesc);
|
||||||
|
|
||||||
return USBD_CDC_CfgFSDesc;
|
return USBD_CDC_CfgFSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,55 +795,57 @@ static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length)
|
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_CDC_CfgHSDesc);
|
*length = (uint16_t)sizeof(USBD_CDC_CfgHSDesc);
|
||||||
|
|
||||||
return USBD_CDC_CfgHSDesc;
|
return USBD_CDC_CfgHSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_GetCfgDesc
|
* @brief USBD_CDC_GetOtherSpeedCfgDesc
|
||||||
* Return configuration descriptor
|
* Return configuration descriptor
|
||||||
* @param speed : current device speed
|
* @param speed : current device speed
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length)
|
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_CDC_OtherSpeedCfgDesc);
|
*length = (uint16_t)sizeof(USBD_CDC_OtherSpeedCfgDesc);
|
||||||
|
|
||||||
return USBD_CDC_OtherSpeedCfgDesc;
|
return USBD_CDC_OtherSpeedCfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief USBD_CDC_GetDeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length)
|
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_CDC_DeviceQualifierDesc);
|
*length = (uint16_t)sizeof(USBD_CDC_DeviceQualifierDesc);
|
||||||
|
|
||||||
return USBD_CDC_DeviceQualifierDesc;
|
return USBD_CDC_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_RegisterInterface
|
* @brief USBD_CDC_RegisterInterface
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param fops: CD Interface callback
|
* @param fops: CD Interface callback
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CDC_ItfTypeDef *fops)
|
USBD_CDC_ItfTypeDef *fops)
|
||||||
{
|
{
|
||||||
uint8_t ret = USBD_FAIL;
|
if (fops == NULL)
|
||||||
|
|
||||||
if(fops != NULL)
|
|
||||||
{
|
{
|
||||||
pdev->pUserData= fops;
|
return (uint8_t)USBD_FAIL;
|
||||||
ret = USBD_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
pdev->pUserData = fops;
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -827,33 +854,40 @@ uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev,
|
|||||||
* @param pbuff: Tx Buffer
|
* @param pbuff: Tx Buffer
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuff,
|
uint8_t *pbuff, uint32_t length)
|
||||||
uint16_t length)
|
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
hcdc->TxBuffer = pbuff;
|
hcdc->TxBuffer = pbuff;
|
||||||
hcdc->TxLength = length;
|
hcdc->TxLength = length;
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_SetRxBuffer
|
* @brief USBD_CDC_SetRxBuffer
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param pbuff: Rx Buffer
|
* @param pbuff: Rx Buffer
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, uint8_t *pbuff)
|
||||||
uint8_t *pbuff)
|
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (hcdc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
hcdc->RxBuffer = pbuff;
|
hcdc->RxBuffer = pbuff;
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -864,11 +898,15 @@ uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||||
|
USBD_StatusTypeDef ret = USBD_BUSY;
|
||||||
|
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData == NULL)
|
||||||
{
|
{
|
||||||
if(hcdc->TxState == 0U)
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hcdc->TxState == 0U)
|
||||||
{
|
{
|
||||||
/* Tx Transfer in progress */
|
/* Tx Transfer in progress */
|
||||||
hcdc->TxState = 1U;
|
hcdc->TxState = 1U;
|
||||||
@@ -877,23 +915,14 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
|||||||
pdev->ep_in[CDC_IN_EP & 0xFU].total_length = hcdc->TxLength;
|
pdev->ep_in[CDC_IN_EP & 0xFU].total_length = hcdc->TxLength;
|
||||||
|
|
||||||
/* Transmit next packet */
|
/* Transmit next packet */
|
||||||
USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer,
|
(void)USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer, hcdc->TxLength);
|
||||||
(uint16_t)hcdc->TxLength);
|
|
||||||
|
|
||||||
return USBD_OK;
|
ret = USBD_OK;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return USBD_BUSY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return USBD_FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CDC_ReceivePacket
|
* @brief USBD_CDC_ReceivePacket
|
||||||
* prepare OUT Endpoint for reception
|
* prepare OUT Endpoint for reception
|
||||||
@@ -902,33 +931,27 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData;
|
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
/* Suspend or Resume USB Out process */
|
if (pdev->pClassData == NULL)
|
||||||
if(pdev->pClassData != NULL)
|
|
||||||
{
|
{
|
||||||
if(pdev->dev_speed == USBD_SPEED_HIGH )
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
USBD_LL_PrepareReceive(pdev,
|
(void)USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
||||||
CDC_OUT_EP,
|
|
||||||
hcdc->RxBuffer,
|
|
||||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Prepare Out endpoint to receive next packet */
|
/* Prepare Out endpoint to receive next packet */
|
||||||
USBD_LL_PrepareReceive(pdev,
|
(void)USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
||||||
CDC_OUT_EP,
|
|
||||||
hcdc->RxBuffer,
|
|
||||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
return USBD_OK;
|
|
||||||
}
|
return (uint8_t)USBD_OK;
|
||||||
else
|
|
||||||
{
|
|
||||||
return USBD_FAIL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -12,15 +12,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_cdc_if_template.h"
|
#include "usbd_cdc_if_template.h"
|
||||||
@@ -64,26 +64,28 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int8_t TEMPLATE_Init (void);
|
static int8_t TEMPLATE_Init(void);
|
||||||
static int8_t TEMPLATE_DeInit (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_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_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 =
|
USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
|
||||||
{
|
{
|
||||||
TEMPLATE_Init,
|
TEMPLATE_Init,
|
||||||
TEMPLATE_DeInit,
|
TEMPLATE_DeInit,
|
||||||
TEMPLATE_Control,
|
TEMPLATE_Control,
|
||||||
TEMPLATE_Receive
|
TEMPLATE_Receive,
|
||||||
|
TEMPLATE_TransmitCplt
|
||||||
};
|
};
|
||||||
|
|
||||||
USBD_CDC_LineCodingTypeDef linecoding =
|
USBD_CDC_LineCodingTypeDef linecoding =
|
||||||
{
|
{
|
||||||
115200, /* baud rate*/
|
115200, /* baud rate*/
|
||||||
0x00, /* stop bits-1*/
|
0x00, /* stop bits-1*/
|
||||||
0x00, /* parity - none*/
|
0x00, /* parity - none*/
|
||||||
0x08 /* nb. of bits 8*/
|
0x08 /* nb. of bits 8*/
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -124,7 +126,7 @@ static int8_t TEMPLATE_DeInit(void)
|
|||||||
* @param Len: Number of data to be sent (in bytes)
|
* @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
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||||
{
|
{
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
@@ -149,7 +151,7 @@ static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CDC_SET_LINE_CODING:
|
case CDC_SET_LINE_CODING:
|
||||||
linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\
|
linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | \
|
||||||
(pbuf[2] << 16) | (pbuf[3] << 24));
|
(pbuf[2] << 16) | (pbuf[3] << 24));
|
||||||
linecoding.format = pbuf[4];
|
linecoding.format = pbuf[4];
|
||||||
linecoding.paritytype = pbuf[5];
|
linecoding.paritytype = pbuf[5];
|
||||||
@@ -192,7 +194,7 @@ static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
|||||||
*
|
*
|
||||||
* @note
|
* @note
|
||||||
* This function will issue a NAK packet on any OUT packet received on
|
* 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)
|
* before transfer is complete on CDC interface (ie. using DMA controller)
|
||||||
* it will result in receiving more data while previous ones are still
|
* it will result in receiving more data while previous ones are still
|
||||||
* not sent.
|
* not sent.
|
||||||
@@ -201,8 +203,31 @@ static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
|||||||
* @param Len: Number of data received (in bytes)
|
* @param Len: Number of data received (in bytes)
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_Receive (uint8_t* Buf, uint32_t *Len)
|
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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
257
Class/CDC_ECM/Inc/usbd_cdc_ecm.h
Normal file
257
Class/CDC_ECM/Inc/usbd_cdc_ecm.h
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_cdc_ecm.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief header file for the usbd_cdc_ecm.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2019 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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 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 / 4]; /* Force 32bits 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 */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
82
Class/CDC_ECM/Inc/usbd_cdc_ecm_if_template.h
Normal file
82
Class/CDC_ECM/Inc/usbd_cdc_ecm_if_template.h
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file Inc/usbd_cdc_ecm_if_template.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header for usbd_cdc_ecm_if_template.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2019 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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
1134
Class/CDC_ECM/Src/usbd_cdc_ecm.c
Normal file
1134
Class/CDC_ECM/Src/usbd_cdc_ecm.c
Normal file
File diff suppressed because it is too large
Load Diff
247
Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c
Normal file
247
Class/CDC_ECM/Src/usbd_cdc_ecm_if_template.c
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file Src/usbd_cdc_ecm_if_template.c
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Source file for USBD CDC_ECM interface
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2019 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 ------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
/*
|
||||||
|
|
||||||
|
Include here LwIP files if used
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
|
/* Private define ------------------------------------------------------------*/
|
||||||
|
/* Private macro -------------------------------------------------------------*/
|
||||||
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif
|
||||||
|
__ALIGN_BEGIN static uint8_t UserRxBuffer[CDC_ECM_ETH_MAX_SEGSZE + 100]__ALIGN_END; /* Received Data over USB 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; /* Received Data over CDC_ECM (CDC_ECM interface) are stored in this buffer */
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
529
Class/CDC_RNDIS/Inc/usbd_cdc_rndis.h
Normal file
529
Class/CDC_RNDIS/Inc/usbd_cdc_rndis.h
Normal file
@@ -0,0 +1,529 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_cdc_rndis.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief header file for the usbd_cdc_rndis.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 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[2000 / 4]; /* Force 32bits 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 */
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
60
Class/CDC_RNDIS/Inc/usbd_cdc_rndis_if_template.h
Normal file
60
Class/CDC_RNDIS/Inc/usbd_cdc_rndis_if_template.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_cdc_rndis_if_template.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Header for usbd_cdc_rndis_if.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2019 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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
1783
Class/CDC_RNDIS/Src/usbd_cdc_rndis.c
Normal file
1783
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
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2019 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 ------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* 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 ---------------------------------------------------------*/
|
||||||
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
|
#pragma data_alignment=4
|
||||||
|
#endif
|
||||||
|
__ALIGN_BEGIN uint8_t UserRxBuffer[CDC_RNDIS_ETH_MAX_SEGSZE + 100] __ALIGN_END; /* Received Data over USB 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; /* Received Data over CDC_RNDIS (CDC_RNDIS interface) are stored in this buffer */
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USB_CUSTOMHID_H
|
#define __USB_CUSTOMHID_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -42,27 +42,34 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define CUSTOM_HID_EPIN_ADDR 0x81U
|
#define CUSTOM_HID_EPIN_ADDR 0x81U
|
||||||
|
|
||||||
|
#ifndef CUSTOM_HID_EPIN_SIZE
|
||||||
#define CUSTOM_HID_EPIN_SIZE 0x02U
|
#define CUSTOM_HID_EPIN_SIZE 0x02U
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CUSTOM_HID_EPOUT_ADDR 0x01U
|
#define CUSTOM_HID_EPOUT_ADDR 0x01U
|
||||||
|
|
||||||
|
#ifndef CUSTOM_HID_EPOUT_SIZE
|
||||||
#define CUSTOM_HID_EPOUT_SIZE 0x02U
|
#define CUSTOM_HID_EPOUT_SIZE 0x02U
|
||||||
|
#endif
|
||||||
|
|
||||||
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U
|
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U
|
||||||
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
||||||
|
|
||||||
#ifndef CUSTOM_HID_HS_BINTERVAL
|
#ifndef CUSTOM_HID_HS_BINTERVAL
|
||||||
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
||||||
#endif /* CUSTOM_HID_HS_BINTERVAL */
|
#endif /* CUSTOM_HID_HS_BINTERVAL */
|
||||||
|
|
||||||
#ifndef CUSTOM_HID_FS_BINTERVAL
|
#ifndef CUSTOM_HID_FS_BINTERVAL
|
||||||
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
||||||
#endif /* CUSTOM_HID_FS_BINTERVAL */
|
#endif /* CUSTOM_HID_FS_BINTERVAL */
|
||||||
|
|
||||||
#ifndef USBD_CUSTOMHID_OUTREPORT_BUF_SIZE
|
#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 */
|
#endif /* USBD_CUSTOMHID_OUTREPORT_BUF_SIZE */
|
||||||
|
|
||||||
#ifndef USBD_CUSTOM_HID_REPORT_DESC_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 */
|
#endif /* USBD_CUSTOM_HID_REPORT_DESC_SIZE */
|
||||||
|
|
||||||
#define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U
|
#define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U
|
||||||
@@ -88,17 +95,16 @@ typedef enum
|
|||||||
{
|
{
|
||||||
CUSTOM_HID_IDLE = 0U,
|
CUSTOM_HID_IDLE = 0U,
|
||||||
CUSTOM_HID_BUSY,
|
CUSTOM_HID_BUSY,
|
||||||
}
|
} CUSTOM_HID_StateTypeDef;
|
||||||
CUSTOM_HID_StateTypeDef;
|
|
||||||
|
|
||||||
typedef struct _USBD_CUSTOM_HID_Itf
|
typedef struct _USBD_CUSTOM_HID_Itf
|
||||||
{
|
{
|
||||||
uint8_t *pReport;
|
uint8_t *pReport;
|
||||||
int8_t (* Init) (void);
|
int8_t (* Init)(void);
|
||||||
int8_t (* DeInit) (void);
|
int8_t (* DeInit)(void);
|
||||||
int8_t (* OutEvent) (uint8_t event_idx, uint8_t state);
|
int8_t (* OutEvent)(uint8_t event_idx, uint8_t state);
|
||||||
|
|
||||||
}USBD_CUSTOM_HID_ItfTypeDef;
|
} USBD_CUSTOM_HID_ItfTypeDef;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -108,8 +114,7 @@ typedef struct
|
|||||||
uint32_t AltSetting;
|
uint32_t AltSetting;
|
||||||
uint32_t IsReportAvailable;
|
uint32_t IsReportAvailable;
|
||||||
CUSTOM_HID_StateTypeDef state;
|
CUSTOM_HID_StateTypeDef state;
|
||||||
}
|
} USBD_CUSTOM_HID_HandleTypeDef;
|
||||||
USBD_CUSTOM_HID_HandleTypeDef;
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -137,13 +142,12 @@ extern USBD_ClassTypeDef USBD_CUSTOM_HID;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *report,
|
uint8_t *report, uint16_t len);
|
||||||
uint16_t len);
|
|
||||||
|
|
||||||
|
uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
|
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t USBD_CUSTOM_HID_RegisterInterface (USBD_HandleTypeDef *pdev,
|
|
||||||
USBD_CUSTOM_HID_ItfTypeDef *fops);
|
USBD_CUSTOM_HID_ItfTypeDef *fops);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_CUSTOMHID_IF_TEMPLATE_H
|
#define __USBD_CUSTOMHID_IF_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -32,15 +32,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_customhid.h"
|
#include "usbd_customhid.h"
|
||||||
@@ -84,28 +84,19 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
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,
|
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t cfgidx);
|
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,
|
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length);
|
||||||
uint8_t cfgidx);
|
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);
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -137,53 +128,55 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgFSDesc[USB_CUSTOM_HID_CONFIG_DES
|
|||||||
{
|
{
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_CUSTOM_HID_CONFIG_DESC_SIZ,
|
USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
||||||
/* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
0x00,
|
||||||
0x01, /*bNumInterfaces: 1 interface*/
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /*bConfigurationValue: Configuration value*/
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x00, /*iConfiguration: Index of string descriptor describing
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
the configuration*/
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /*bmAttributes: bus powered */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */
|
||||||
|
|
||||||
/************** Descriptor of CUSTOM HID interface ****************/
|
/************** Descriptor of CUSTOM HID interface ****************/
|
||||||
/* 09 */
|
/* 09 */
|
||||||
0x09, /*bLength: Interface Descriptor size*/
|
0x09, /* bLength: Interface Descriptor size*/
|
||||||
USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||||
0x00, /*bInterfaceNumber: Number of Interface*/
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /*bAlternateSetting: Alternate setting*/
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x02, /*bNumEndpoints*/
|
0x02, /* bNumEndpoints*/
|
||||||
0x03, /*bInterfaceClass: CUSTOM_HID*/
|
0x03, /* bInterfaceClass: CUSTOM_HID */
|
||||||
0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
|
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||||
0x00, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
|
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||||
0, /*iInterface: Index of string descriptor*/
|
0x00, /* iInterface: Index of string descriptor */
|
||||||
/******************** Descriptor of CUSTOM_HID *************************/
|
/******************** Descriptor of CUSTOM_HID *************************/
|
||||||
/* 18 */
|
/* 18 */
|
||||||
0x09, /*bLength: CUSTOM_HID Descriptor size*/
|
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
||||||
CUSTOM_HID_DESCRIPTOR_TYPE, /*bDescriptorType: CUSTOM_HID*/
|
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
||||||
0x11, /*bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number*/
|
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /*bCountryCode: Hardware target country*/
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /*bNumDescriptors: Number of CUSTOM_HID class descriptors to follow*/
|
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
||||||
0x22, /*bDescriptorType*/
|
0x22, /* bDescriptorType */
|
||||||
USBD_CUSTOM_HID_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
|
USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
0x00,
|
||||||
/******************** Descriptor of Custom HID endpoints ********************/
|
/******************** Descriptor of Custom HID endpoints ********************/
|
||||||
/* 27 */
|
/* 27 */
|
||||||
0x07, /*bLength: Endpoint Descriptor size*/
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
|
|
||||||
CUSTOM_HID_EPIN_ADDR, /*bEndpointAddress: Endpoint Address (IN)*/
|
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||||
0x03, /*bmAttributes: Interrupt endpoint*/
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPIN_SIZE, /*wMaxPacketSize: 2 Byte max */
|
CUSTOM_HID_EPIN_SIZE, /* wMaxPacketSize: 2 Byte max */
|
||||||
0x00,
|
0x00,
|
||||||
CUSTOM_HID_FS_BINTERVAL, /*bInterval: Polling Interval */
|
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||||
0x00,
|
0x00,
|
||||||
@@ -196,53 +189,55 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgHSDesc[USB_CUSTOM_HID_CONFIG_DES
|
|||||||
{
|
{
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_CUSTOM_HID_CONFIG_DESC_SIZ,
|
USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
||||||
/* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
0x00,
|
||||||
0x01, /*bNumInterfaces: 1 interface*/
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /*bConfigurationValue: Configuration value*/
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x00, /*iConfiguration: Index of string descriptor describing
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
the configuration*/
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /*bmAttributes: bus powered */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */
|
||||||
|
|
||||||
/************** Descriptor of CUSTOM HID interface ****************/
|
/************** Descriptor of CUSTOM HID interface ****************/
|
||||||
/* 09 */
|
/* 09 */
|
||||||
0x09, /*bLength: Interface Descriptor size*/
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||||
0x00, /*bInterfaceNumber: Number of Interface*/
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /*bAlternateSetting: Alternate setting*/
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x02, /*bNumEndpoints*/
|
0x02, /* bNumEndpoints */
|
||||||
0x03, /*bInterfaceClass: CUSTOM_HID*/
|
0x03, /* bInterfaceClass: CUSTOM_HID */
|
||||||
0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
|
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||||
0x00, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
|
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||||
0, /*iInterface: Index of string descriptor*/
|
0, /* iInterface: Index of string descriptor */
|
||||||
/******************** Descriptor of CUSTOM_HID *************************/
|
/******************** Descriptor of CUSTOM_HID *************************/
|
||||||
/* 18 */
|
/* 18 */
|
||||||
0x09, /*bLength: CUSTOM_HID Descriptor size*/
|
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
||||||
CUSTOM_HID_DESCRIPTOR_TYPE, /*bDescriptorType: CUSTOM_HID*/
|
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
||||||
0x11, /*bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number*/
|
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /*bCountryCode: Hardware target country*/
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /*bNumDescriptors: Number of CUSTOM_HID class descriptors to follow*/
|
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
||||||
0x22, /*bDescriptorType*/
|
0x22, /* bDescriptorType */
|
||||||
USBD_CUSTOM_HID_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
|
USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
0x00,
|
||||||
/******************** Descriptor of Custom HID endpoints ********************/
|
/******************** Descriptor of Custom HID endpoints ********************/
|
||||||
/* 27 */
|
/* 27 */
|
||||||
0x07, /*bLength: Endpoint Descriptor size*/
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
|
|
||||||
CUSTOM_HID_EPIN_ADDR, /*bEndpointAddress: Endpoint Address (IN)*/
|
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||||
0x03, /*bmAttributes: Interrupt endpoint*/
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPIN_SIZE, /*wMaxPacketSize: 2 Byte max */
|
CUSTOM_HID_EPIN_SIZE, /* wMaxPacketSize: 2 Byte max */
|
||||||
0x00,
|
0x00,
|
||||||
CUSTOM_HID_HS_BINTERVAL, /*bInterval: Polling Interval */
|
CUSTOM_HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||||
0x00,
|
0x00,
|
||||||
@@ -255,53 +250,55 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_OtherSpeedCfgDesc[USB_CUSTOM_HID_CO
|
|||||||
{
|
{
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_CUSTOM_HID_CONFIG_DESC_SIZ,
|
USB_CUSTOM_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
||||||
/* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
0x00,
|
||||||
0x01, /*bNumInterfaces: 1 interface*/
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /*bConfigurationValue: Configuration value*/
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x00, /*iConfiguration: Index of string descriptor describing
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
the configuration*/
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xC0, /*bmAttributes: bus powered */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */
|
||||||
|
|
||||||
/************** Descriptor of CUSTOM HID interface ****************/
|
/************** Descriptor of CUSTOM HID interface ****************/
|
||||||
/* 09 */
|
/* 09 */
|
||||||
0x09, /*bLength: Interface Descriptor size*/
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||||
0x00, /*bInterfaceNumber: Number of Interface*/
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /*bAlternateSetting: Alternate setting*/
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x02, /*bNumEndpoints*/
|
0x02, /* bNumEndpoints */
|
||||||
0x03, /*bInterfaceClass: CUSTOM_HID*/
|
0x03, /* bInterfaceClass: CUSTOM_HID */
|
||||||
0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
|
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||||
0x00, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
|
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||||
0, /*iInterface: Index of string descriptor*/
|
0, /* iInterface: Index of string descriptor */
|
||||||
/******************** Descriptor of CUSTOM_HID *************************/
|
/******************** Descriptor of CUSTOM_HID *************************/
|
||||||
/* 18 */
|
/* 18 */
|
||||||
0x09, /*bLength: CUSTOM_HID Descriptor size*/
|
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
||||||
CUSTOM_HID_DESCRIPTOR_TYPE, /*bDescriptorType: CUSTOM_HID*/
|
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
||||||
0x11, /*bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number*/
|
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /*bCountryCode: Hardware target country*/
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /*bNumDescriptors: Number of CUSTOM_HID class descriptors to follow*/
|
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
||||||
0x22, /*bDescriptorType*/
|
0x22, /* bDescriptorType */
|
||||||
USBD_CUSTOM_HID_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
|
USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
0x00,
|
||||||
/******************** Descriptor of Custom HID endpoints ********************/
|
/******************** Descriptor of Custom HID endpoints ********************/
|
||||||
/* 27 */
|
/* 27 */
|
||||||
0x07, /*bLength: Endpoint Descriptor size*/
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
|
|
||||||
CUSTOM_HID_EPIN_ADDR, /*bEndpointAddress: Endpoint Address (IN)*/
|
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||||
0x03, /*bmAttributes: Interrupt endpoint*/
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPIN_SIZE, /*wMaxPacketSize: 2 Byte max */
|
CUSTOM_HID_EPIN_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||||
0x00,
|
0x00,
|
||||||
CUSTOM_HID_FS_BINTERVAL, /*bInterval: Polling Interval */
|
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
|
|
||||||
0x07, /* bLength: Endpoint Descriptor size */
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
CUSTOM_HID_EPOUT_ADDR, /*bEndpointAddress: Endpoint Address (OUT)*/
|
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
||||||
0x03, /* bmAttributes: Interrupt endpoint */
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
CUSTOM_HID_EPOUT_SIZE, /* wMaxPacketSize: 2 Bytes max */
|
||||||
0x00,
|
0x00,
|
||||||
@@ -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 =
|
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
/* 18 */
|
/* 18 */
|
||||||
0x09, /*bLength: CUSTOM_HID Descriptor size*/
|
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
||||||
CUSTOM_HID_DESCRIPTOR_TYPE, /*bDescriptorType: CUSTOM_HID*/
|
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
||||||
0x11, /*bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number*/
|
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /*bCountryCode: Hardware target country*/
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /*bNumDescriptors: Number of CUSTOM_HID class descriptors to follow*/
|
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors to follow */
|
||||||
0x22, /*bDescriptorType*/
|
0x22, /* bDescriptorType */
|
||||||
USBD_CUSTOM_HID_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
|
USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -354,43 +351,53 @@ __ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_DeviceQualifierDesc[USB_LEN_DEV_QUA
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
uint8_t cfgidx)
|
|
||||||
{
|
{
|
||||||
uint8_t ret = 0U;
|
UNUSED(cfgidx);
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||||
|
|
||||||
|
hhid = 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 */
|
/* Open EP IN */
|
||||||
USBD_LL_OpenEP(pdev, CUSTOM_HID_EPIN_ADDR, USBD_EP_TYPE_INTR,
|
(void)USBD_LL_OpenEP(pdev, CUSTOM_HID_EPIN_ADDR, USBD_EP_TYPE_INTR,
|
||||||
CUSTOM_HID_EPIN_SIZE);
|
CUSTOM_HID_EPIN_SIZE);
|
||||||
|
|
||||||
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP OUT */
|
/* Open EP OUT */
|
||||||
USBD_LL_OpenEP(pdev, CUSTOM_HID_EPOUT_ADDR, USBD_EP_TYPE_INTR,
|
(void)USBD_LL_OpenEP(pdev, CUSTOM_HID_EPOUT_ADDR, USBD_EP_TYPE_INTR,
|
||||||
CUSTOM_HID_EPOUT_SIZE);
|
CUSTOM_HID_EPOUT_SIZE);
|
||||||
|
|
||||||
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 1U;
|
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
pdev->pClassData = USBD_malloc(sizeof (USBD_CUSTOM_HID_HandleTypeDef));
|
|
||||||
|
|
||||||
if(pdev->pClassData == NULL)
|
|
||||||
{
|
|
||||||
ret = 1U;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef*) pdev->pClassData;
|
|
||||||
|
|
||||||
hhid->state = CUSTOM_HID_IDLE;
|
hhid->state = CUSTOM_HID_IDLE;
|
||||||
|
|
||||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->Init();
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->Init();
|
||||||
|
|
||||||
/* Prepare Out endpoint to receive 1st packet */
|
/* Prepare Out endpoint to receive 1st packet */
|
||||||
USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
|
(void)USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf,
|
||||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
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
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
uint8_t cfgidx)
|
|
||||||
{
|
{
|
||||||
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
/* Close CUSTOM_HID EP IN */
|
/* 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].is_used = 0U;
|
||||||
|
pdev->ep_in[CUSTOM_HID_EPIN_ADDR & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* Close CUSTOM_HID EP OUT */
|
/* 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].is_used = 0U;
|
||||||
|
pdev->ep_out[CUSTOM_HID_EPOUT_ADDR & 0xFU].bInterval = 0U;
|
||||||
|
|
||||||
/* FRee allocated memory */
|
/* Free allocated memory */
|
||||||
if(pdev->pClassData != NULL)
|
if (pdev->pClassData != NULL)
|
||||||
{
|
{
|
||||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->DeInit();
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||||
USBD_free(pdev->pClassData);
|
USBD_free(pdev->pClassData);
|
||||||
pdev->pClassData = NULL;
|
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
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData;
|
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||||
uint16_t len = 0U;
|
uint16_t len = 0U;
|
||||||
uint8_t *pbuf = NULL;
|
uint8_t *pbuf = NULL;
|
||||||
uint16_t status_info = 0U;
|
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)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_REQ_TYPE_CLASS :
|
case USB_REQ_TYPE_CLASS:
|
||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
case CUSTOM_HID_REQ_SET_PROTOCOL:
|
case CUSTOM_HID_REQ_SET_PROTOCOL:
|
||||||
@@ -447,7 +463,7 @@ static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CUSTOM_HID_REQ_GET_PROTOCOL:
|
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;
|
break;
|
||||||
|
|
||||||
case CUSTOM_HID_REQ_SET_IDLE:
|
case CUSTOM_HID_REQ_SET_IDLE:
|
||||||
@@ -455,16 +471,16 @@ static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CUSTOM_HID_REQ_GET_IDLE:
|
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;
|
break;
|
||||||
|
|
||||||
case CUSTOM_HID_REQ_SET_REPORT:
|
case CUSTOM_HID_REQ_SET_REPORT:
|
||||||
hhid->IsReportAvailable = 1U;
|
hhid->IsReportAvailable = 1U;
|
||||||
USBD_CtlPrepareRx (pdev, hhid->Report_buf, req->wLength);
|
(void)USBD_CtlPrepareRx(pdev, hhid->Report_buf, req->wLength);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -476,70 +492,73 @@ static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
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
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_DESCRIPTOR:
|
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);
|
len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE, req->wLength);
|
||||||
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport;
|
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->pReport;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( req->wValue >> 8 == CUSTOM_HID_DESCRIPTOR_TYPE)
|
if ((req->wValue >> 8) == CUSTOM_HID_DESCRIPTOR_TYPE)
|
||||||
{
|
{
|
||||||
pbuf = USBD_CUSTOM_HID_Desc;
|
pbuf = USBD_CUSTOM_HID_Desc;
|
||||||
len = MIN(USB_CUSTOM_HID_DESC_SIZ , req->wLength);
|
len = MIN(USB_CUSTOM_HID_DESC_SIZ, req->wLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
USBD_CtlSendData (pdev, pbuf, len);
|
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE :
|
case USB_REQ_GET_INTERFACE:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
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
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE :
|
case USB_REQ_SET_INTERFACE:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -549,25 +568,31 @@ static uint8_t USBD_CUSTOM_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param buff: pointer to report
|
* @param buff: pointer to report
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *report,
|
uint8_t *report, uint16_t len)
|
||||||
uint16_t len)
|
|
||||||
{
|
{
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData;
|
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||||
|
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED )
|
if (pdev->pClassData == NULL)
|
||||||
{
|
{
|
||||||
if(hhid->state == CUSTOM_HID_IDLE)
|
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;
|
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
|
else
|
||||||
{
|
{
|
||||||
return USBD_BUSY;
|
return (uint8_t)USBD_BUSY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -577,9 +602,10 @@ uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev,
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CUSTOM_HID_CfgFSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,9 +616,10 @@ static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CUSTOM_HID_CfgHSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,9 +630,10 @@ static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_CUSTOM_HID_OtherSpeedCfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,14 +644,15 @@ static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc (uint16_t *length)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_DataIn (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
|
UNUSED(epnum);
|
||||||
|
|
||||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||||
be caused by a new transfer before the end of the previous transfer */
|
be caused by a new transfer before the end of the previous transfer */
|
||||||
((USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData)->state = CUSTOM_HID_IDLE;
|
((USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData)->state = CUSTOM_HID_IDLE;
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -633,21 +662,52 @@ static uint8_t USBD_CUSTOM_HID_DataIn (USBD_HandleTypeDef *pdev,
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
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],
|
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0],
|
||||||
hhid->Report_buf[1]);
|
hhid->Report_buf[1]);
|
||||||
|
|
||||||
USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR , hhid->Report_buf,
|
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);
|
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CUSTOM_HID_EP0_RxReady
|
* @brief USBD_CUSTOM_HID_EP0_RxReady
|
||||||
* Handles control request data.
|
* Handles control request data.
|
||||||
@@ -656,7 +716,12 @@ static uint8_t USBD_CUSTOM_HID_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef*)pdev->pClassData;
|
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (hhid == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
if (hhid->IsReportAvailable == 1U)
|
if (hhid->IsReportAvailable == 1U)
|
||||||
{
|
{
|
||||||
@@ -665,39 +730,39 @@ static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
|||||||
hhid->IsReportAvailable = 0U;
|
hhid->IsReportAvailable = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc (uint16_t *length)
|
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;
|
return USBD_CUSTOM_HID_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CUSTOM_HID_RegisterInterface
|
* @brief USBD_CUSTOM_HID_RegisterInterface
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param fops: CUSTOMHID Interface callback
|
* @param fops: CUSTOMHID Interface callback
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_CUSTOM_HID_RegisterInterface (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||||
USBD_CUSTOM_HID_ItfTypeDef *fops)
|
USBD_CUSTOM_HID_ItfTypeDef *fops)
|
||||||
{
|
{
|
||||||
uint8_t ret = USBD_FAIL;
|
if (fops == NULL)
|
||||||
|
|
||||||
if(fops != NULL)
|
|
||||||
{
|
{
|
||||||
pdev->pUserData= fops;
|
return (uint8_t)USBD_FAIL;
|
||||||
ret = USBD_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
pdev->pUserData = fops;
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -14,15 +14,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_customhid_if_template.h"
|
#include "usbd_customhid_if_template.h"
|
||||||
@@ -31,9 +31,9 @@
|
|||||||
/* Private macro -------------------------------------------------------------*/
|
/* Private macro -------------------------------------------------------------*/
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
|
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_Init (void);
|
static int8_t TEMPLATE_CUSTOM_HID_Init(void);
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_DeInit (void);
|
static int8_t TEMPLATE_CUSTOM_HID_DeInit(void);
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_OutEvent (uint8_t event_idx, uint8_t state);
|
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state);
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops =
|
USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops =
|
||||||
{
|
{
|
||||||
@@ -53,7 +53,6 @@ USBD_CUSTOM_HID_ItfTypeDef USBD_CustomHID_template_fops =
|
|||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_Init(void)
|
static int8_t TEMPLATE_CUSTOM_HID_Init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,8 +78,13 @@ static int8_t TEMPLATE_CUSTOM_HID_DeInit(void)
|
|||||||
* @param state: event state
|
* @param state: event state
|
||||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||||
*/
|
*/
|
||||||
static int8_t TEMPLATE_CUSTOM_HID_OutEvent (uint8_t event_idx, uint8_t state)
|
static int8_t TEMPLATE_CUSTOM_HID_OutEvent(uint8_t event_idx, uint8_t state)
|
||||||
{
|
{
|
||||||
|
UNUSED(event_idx);
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
|
/* Start next USB packet transfer once data processing is completed */
|
||||||
|
USBD_CUSTOM_HID_ReceivePacket(&USBD_Device);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USB_DFU_H
|
#define __USB_DFU_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -115,13 +115,13 @@
|
|||||||
/* Other defines */
|
/* Other defines */
|
||||||
/**************************************************/
|
/**************************************************/
|
||||||
/* Bit Detach capable = bit 3 in bmAttributes field */
|
/* 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
|
#define DFU_STATUS_DEPTH 6U
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
DFU_DETACH = 0U,
|
DFU_DETACH = 0U,
|
||||||
DFU_DNLOAD ,
|
DFU_DNLOAD,
|
||||||
DFU_UPLOAD,
|
DFU_UPLOAD,
|
||||||
DFU_GETSTATUS,
|
DFU_GETSTATUS,
|
||||||
DFU_CLRSTATUS,
|
DFU_CLRSTATUS,
|
||||||
@@ -144,9 +144,9 @@ typedef void (*pFunction)(void);
|
|||||||
USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */ \
|
USBD_IDX_INTERFACE_STR + (n) + 1U /* iInterface: Index of string descriptor */ \
|
||||||
|
|
||||||
#define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), /* XFERSIZEB0 */\
|
#define TRANSFER_SIZE_BYTES(size) ((uint8_t)(size)), /* XFERSIZEB0 */\
|
||||||
((uint8_t)(size >> 8)) /* XFERSIZEB1 */
|
((uint8_t)((size) >> 8)) /* XFERSIZEB1 */
|
||||||
|
|
||||||
#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)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -163,7 +163,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
uint32_t d32[USBD_DFU_XFER_SIZE / 4U];
|
uint32_t d32[USBD_DFU_XFER_SIZE / 4U];
|
||||||
uint8_t d8[USBD_DFU_XFER_SIZE];
|
uint8_t d8[USBD_DFU_XFER_SIZE];
|
||||||
}buffer;
|
} buffer;
|
||||||
|
|
||||||
uint32_t wblock_num;
|
uint32_t wblock_num;
|
||||||
uint32_t wlength;
|
uint32_t wlength;
|
||||||
@@ -174,20 +174,18 @@ typedef struct
|
|||||||
uint8_t ReservedForAlign[2];
|
uint8_t ReservedForAlign[2];
|
||||||
uint8_t dev_state;
|
uint8_t dev_state;
|
||||||
uint8_t manif_state;
|
uint8_t manif_state;
|
||||||
}
|
} USBD_DFU_HandleTypeDef;
|
||||||
USBD_DFU_HandleTypeDef;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
const uint8_t* pStrDesc;
|
const uint8_t *pStrDesc;
|
||||||
uint16_t (* Init) (void);
|
uint16_t (* Init)(void);
|
||||||
uint16_t (* DeInit) (void);
|
uint16_t (* DeInit)(void);
|
||||||
uint16_t (* Erase) (uint32_t Add);
|
uint16_t (* Erase)(uint32_t Add);
|
||||||
uint16_t (* Write) (uint8_t *src, uint8_t *dest, uint32_t Len);
|
uint16_t (* Write)(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||||
uint8_t* (* Read) (uint8_t *src, uint8_t *dest, uint32_t Len);
|
uint8_t *(* Read)(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||||
uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
|
uint16_t (* GetStatus)(uint32_t Add, uint8_t cmd, uint8_t *buff);
|
||||||
}
|
} USBD_DFU_MediaTypeDef;
|
||||||
USBD_DFU_MediaTypeDef;
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -215,7 +213,7 @@ extern USBD_ClassTypeDef USBD_DFU;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_DFU_RegisterMedia (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_DFU_RegisterMedia(USBD_HandleTypeDef *pdev,
|
||||||
USBD_DFU_MediaTypeDef *fops);
|
USBD_DFU_MediaTypeDef *fops);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_DFU_MEDIA_TEMPLATE_H
|
#define __USBD_DFU_MEDIA_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -92,6 +92,6 @@ extern USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -12,15 +12,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_dfu_media_template.h"
|
#include "usbd_dfu_media_template.h"
|
||||||
@@ -34,11 +34,11 @@
|
|||||||
/* Extern function prototypes ------------------------------------------------*/
|
/* Extern function prototypes ------------------------------------------------*/
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
uint16_t MEM_If_Init(void);
|
uint16_t MEM_If_Init(void);
|
||||||
uint16_t MEM_If_Erase (uint32_t Add);
|
uint16_t MEM_If_Erase(uint32_t Add);
|
||||||
uint16_t MEM_If_Write (uint8_t *src, uint8_t *dest, uint32_t Len);
|
uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||||
uint8_t *MEM_If_Read (uint8_t *src, uint8_t *dest, uint32_t Len);
|
uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len);
|
||||||
uint16_t MEM_If_DeInit(void);
|
uint16_t MEM_If_DeInit(void);
|
||||||
uint16_t MEM_If_GetStatus (uint32_t Add, uint8_t Cmd, uint8_t *buffer);
|
uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer);
|
||||||
|
|
||||||
USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
|
USBD_DFU_MediaTypeDef USBD_DFU_MEDIA_Template_fops =
|
||||||
{
|
{
|
||||||
@@ -103,10 +103,10 @@ uint16_t MEM_If_Write(uint8_t *src, uint8_t *dest, uint32_t Len)
|
|||||||
* @param Len: Number of data to be read (in bytes).
|
* @param Len: Number of data to be read (in bytes).
|
||||||
* @retval Pointer to the physical address where data should be read.
|
* @retval Pointer to the physical address where data should be read.
|
||||||
*/
|
*/
|
||||||
uint8_t *MEM_If_Read (uint8_t *src, uint8_t *dest, uint32_t Len)
|
uint8_t *MEM_If_Read(uint8_t *src, uint8_t *dest, uint32_t Len)
|
||||||
{
|
{
|
||||||
/* Return a valid address to avoid HardFault */
|
/* Return a valid address to avoid HardFault */
|
||||||
return (uint8_t*)(0);
|
return (uint8_t *)(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,7 +116,7 @@ uint8_t *MEM_If_Read (uint8_t *src, uint8_t *dest, uint32_t Len)
|
|||||||
* @param cmd: Number of data to be read (in bytes).
|
* @param cmd: Number of data to be read (in bytes).
|
||||||
* @retval Pointer to the physical address where data should be read.
|
* @retval Pointer to the physical address where data should be read.
|
||||||
*/
|
*/
|
||||||
uint16_t MEM_If_GetStatus (uint32_t Add, uint8_t Cmd, uint8_t *buffer)
|
uint16_t MEM_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer)
|
||||||
{
|
{
|
||||||
switch (Cmd)
|
switch (Cmd)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USB_HID_H
|
#define __USB_HID_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -52,11 +52,11 @@
|
|||||||
#define HID_REPORT_DESC 0x22U
|
#define HID_REPORT_DESC 0x22U
|
||||||
|
|
||||||
#ifndef HID_HS_BINTERVAL
|
#ifndef HID_HS_BINTERVAL
|
||||||
#define HID_HS_BINTERVAL 0x07U
|
#define HID_HS_BINTERVAL 0x07U
|
||||||
#endif /* HID_HS_BINTERVAL */
|
#endif /* HID_HS_BINTERVAL */
|
||||||
|
|
||||||
#ifndef HID_FS_BINTERVAL
|
#ifndef HID_FS_BINTERVAL
|
||||||
#define HID_FS_BINTERVAL 0x0AU
|
#define HID_FS_BINTERVAL 0x0AU
|
||||||
#endif /* HID_FS_BINTERVAL */
|
#endif /* HID_FS_BINTERVAL */
|
||||||
|
|
||||||
#define HID_REQ_SET_PROTOCOL 0x0BU
|
#define HID_REQ_SET_PROTOCOL 0x0BU
|
||||||
@@ -79,8 +79,7 @@ typedef enum
|
|||||||
{
|
{
|
||||||
HID_IDLE = 0,
|
HID_IDLE = 0,
|
||||||
HID_BUSY,
|
HID_BUSY,
|
||||||
}
|
} HID_StateTypeDef;
|
||||||
HID_StateTypeDef;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -89,8 +88,7 @@ typedef struct
|
|||||||
uint32_t IdleState;
|
uint32_t IdleState;
|
||||||
uint32_t AltSetting;
|
uint32_t AltSetting;
|
||||||
HID_StateTypeDef state;
|
HID_StateTypeDef state;
|
||||||
}
|
} USBD_HID_HandleTypeDef;
|
||||||
USBD_HID_HandleTypeDef;
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -118,11 +116,8 @@ extern USBD_ClassTypeDef USBD_HID;
|
|||||||
/** @defgroup USB_CORE_Exported_Functions
|
/** @defgroup USB_CORE_Exported_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len);
|
||||||
uint8_t *report,
|
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev);
|
||||||
uint16_t len);
|
|
||||||
|
|
||||||
uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -33,15 +33,15 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_hid.h"
|
#include "usbd_hid.h"
|
||||||
@@ -83,31 +83,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_HID_Private_FunctionPrototypes
|
/** @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,
|
static uint8_t *USBD_HID_GetFSCfgDesc(uint16_t *length);
|
||||||
uint8_t cfgidx);
|
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);
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -121,11 +110,11 @@ USBD_ClassTypeDef USBD_HID =
|
|||||||
USBD_HID_Init,
|
USBD_HID_Init,
|
||||||
USBD_HID_DeInit,
|
USBD_HID_DeInit,
|
||||||
USBD_HID_Setup,
|
USBD_HID_Setup,
|
||||||
NULL, /*EP0_TxSent*/
|
NULL, /* EP0_TxSent */
|
||||||
NULL, /*EP0_RxReady*/
|
NULL, /* EP0_RxReady */
|
||||||
USBD_HID_DataIn, /*DataIn*/
|
USBD_HID_DataIn, /* DataIn */
|
||||||
NULL, /*DataOut*/
|
NULL, /* DataOut */
|
||||||
NULL, /*SOF */
|
NULL, /* SOF */
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
USBD_HID_GetHSCfgDesc,
|
USBD_HID_GetHSCfgDesc,
|
||||||
@@ -139,48 +128,50 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIG
|
|||||||
{
|
{
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_HID_CONFIG_DESC_SIZ,
|
USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
||||||
/* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
0x00,
|
||||||
0x01, /*bNumInterfaces: 1 interface*/
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /*bConfigurationValue: Configuration value*/
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x00, /*iConfiguration: Index of string descriptor describing
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
the configuration*/
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
|
0xE0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
#else
|
||||||
|
0xA0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */
|
||||||
|
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
/************** Descriptor of Joystick Mouse interface ****************/
|
||||||
/* 09 */
|
/* 09 */
|
||||||
0x09, /*bLength: Interface Descriptor size*/
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||||
0x00, /*bInterfaceNumber: Number of Interface*/
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /*bAlternateSetting: Alternate setting*/
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x01, /*bNumEndpoints*/
|
0x01, /* bNumEndpoints */
|
||||||
0x03, /*bInterfaceClass: HID*/
|
0x03, /* bInterfaceClass: HID */
|
||||||
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
|
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||||
0x02, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
|
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||||
0, /*iInterface: Index of string descriptor*/
|
0, /* iInterface: Index of string descriptor */
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
/******************** Descriptor of Joystick Mouse HID ********************/
|
||||||
/* 18 */
|
/* 18 */
|
||||||
0x09, /*bLength: HID Descriptor size*/
|
0x09, /* bLength: HID Descriptor size */
|
||||||
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
|
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
|
||||||
0x11, /*bcdHID: HID Class Spec release number*/
|
0x11, /* bcdHID: HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /*bCountryCode: Hardware target country*/
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
|
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||||
0x22, /*bDescriptorType*/
|
0x22, /* bDescriptorType */
|
||||||
HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
|
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
0x00,
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
/******************** Descriptor of Mouse endpoint ********************/
|
||||||
/* 27 */
|
/* 27 */
|
||||||
0x07, /*bLength: Endpoint Descriptor size*/
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType:*/
|
||||||
|
|
||||||
HID_EPIN_ADDR, /*bEndpointAddress: Endpoint Address (IN)*/
|
HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||||
0x03, /*bmAttributes: Interrupt endpoint*/
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
HID_EPIN_SIZE, /*wMaxPacketSize: 4 Byte max */
|
HID_EPIN_SIZE, /* wMaxPacketSize: 4 Byte max */
|
||||||
0x00,
|
0x00,
|
||||||
HID_FS_BINTERVAL, /*bInterval: Polling Interval */
|
HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -189,48 +180,50 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgHSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIG
|
|||||||
{
|
{
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_HID_CONFIG_DESC_SIZ,
|
USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
||||||
/* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
0x00,
|
||||||
0x01, /*bNumInterfaces: 1 interface*/
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /*bConfigurationValue: Configuration value*/
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x00, /*iConfiguration: Index of string descriptor describing
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
the configuration*/
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
|
0xE0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
#else
|
||||||
|
0xA0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */
|
||||||
|
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
/************** Descriptor of Joystick Mouse interface ****************/
|
||||||
/* 09 */
|
/* 09 */
|
||||||
0x09, /*bLength: Interface Descriptor size*/
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||||
0x00, /*bInterfaceNumber: Number of Interface*/
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /*bAlternateSetting: Alternate setting*/
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x01, /*bNumEndpoints*/
|
0x01, /* bNumEndpoints */
|
||||||
0x03, /*bInterfaceClass: HID*/
|
0x03, /* bInterfaceClass: HID */
|
||||||
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
|
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||||
0x02, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
|
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||||
0, /*iInterface: Index of string descriptor*/
|
0, /* iInterface: Index of string descriptor */
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
/******************** Descriptor of Joystick Mouse HID ********************/
|
||||||
/* 18 */
|
/* 18 */
|
||||||
0x09, /*bLength: HID Descriptor size*/
|
0x09, /* bLength: HID Descriptor size */
|
||||||
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
|
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
|
||||||
0x11, /*bcdHID: HID Class Spec release number*/
|
0x11, /* bcdHID: HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /*bCountryCode: Hardware target country*/
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
|
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||||
0x22, /*bDescriptorType*/
|
0x22, /* bDescriptorType */
|
||||||
HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
|
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
0x00,
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
/******************** Descriptor of Mouse endpoint ********************/
|
||||||
/* 27 */
|
/* 27 */
|
||||||
0x07, /*bLength: Endpoint Descriptor size*/
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
|
|
||||||
HID_EPIN_ADDR, /*bEndpointAddress: Endpoint Address (IN)*/
|
HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||||
0x03, /*bmAttributes: Interrupt endpoint*/
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
HID_EPIN_SIZE, /*wMaxPacketSize: 4 Byte max */
|
HID_EPIN_SIZE, /* wMaxPacketSize: 4 Byte max */
|
||||||
0x00,
|
0x00,
|
||||||
HID_HS_BINTERVAL, /*bInterval: Polling Interval */
|
HID_HS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -239,48 +232,50 @@ __ALIGN_BEGIN static uint8_t USBD_HID_OtherSpeedCfgDesc[USB_HID_CONFIG_DESC_SIZ]
|
|||||||
{
|
{
|
||||||
0x09, /* bLength: Configuration Descriptor size */
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_HID_CONFIG_DESC_SIZ,
|
USB_HID_CONFIG_DESC_SIZ, /* wTotalLength: Bytes returned */
|
||||||
/* wTotalLength: Bytes returned */
|
|
||||||
0x00,
|
0x00,
|
||||||
0x01, /*bNumInterfaces: 1 interface*/
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /*bConfigurationValue: Configuration value*/
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
0x00, /*iConfiguration: Index of string descriptor describing
|
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||||
the configuration*/
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
|
0xE0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
|
#else
|
||||||
|
0xA0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA: this current is used for detecting Vbus */
|
||||||
|
|
||||||
/************** Descriptor of Joystick Mouse interface ****************/
|
/************** Descriptor of Joystick Mouse interface ****************/
|
||||||
/* 09 */
|
/* 09 */
|
||||||
0x09, /*bLength: Interface Descriptor size*/
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/
|
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||||
0x00, /*bInterfaceNumber: Number of Interface*/
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /*bAlternateSetting: Alternate setting*/
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x01, /*bNumEndpoints*/
|
0x01, /* bNumEndpoints */
|
||||||
0x03, /*bInterfaceClass: HID*/
|
0x03, /* bInterfaceClass: HID */
|
||||||
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
|
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||||
0x02, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
|
0x02, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||||
0, /*iInterface: Index of string descriptor*/
|
0, /* iInterface: Index of string descriptor */
|
||||||
/******************** Descriptor of Joystick Mouse HID ********************/
|
/******************** Descriptor of Joystick Mouse HID ********************/
|
||||||
/* 18 */
|
/* 18 */
|
||||||
0x09, /*bLength: HID Descriptor size*/
|
0x09, /* bLength: HID Descriptor size */
|
||||||
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
|
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
|
||||||
0x11, /*bcdHID: HID Class Spec release number*/
|
0x11, /* bcdHID: HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /*bCountryCode: Hardware target country*/
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
|
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||||
0x22, /*bDescriptorType*/
|
0x22, /* bDescriptorType */
|
||||||
HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
|
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
0x00,
|
||||||
/******************** Descriptor of Mouse endpoint ********************/
|
/******************** Descriptor of Mouse endpoint ********************/
|
||||||
/* 27 */
|
/* 27 */
|
||||||
0x07, /*bLength: Endpoint Descriptor size*/
|
0x07, /* bLength: Endpoint Descriptor size */
|
||||||
USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/
|
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||||
|
|
||||||
HID_EPIN_ADDR, /*bEndpointAddress: Endpoint Address (IN)*/
|
HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||||
0x03, /*bmAttributes: Interrupt endpoint*/
|
0x03, /* bmAttributes: Interrupt endpoint */
|
||||||
HID_EPIN_SIZE, /*wMaxPacketSize: 4 Byte max */
|
HID_EPIN_SIZE, /* wMaxPacketSize: 4 Byte max */
|
||||||
0x00,
|
0x00,
|
||||||
HID_FS_BINTERVAL, /*bInterval: Polling Interval */
|
HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||||
/* 34 */
|
/* 34 */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -289,14 +284,14 @@ __ALIGN_BEGIN static uint8_t USBD_HID_OtherSpeedCfgDesc[USB_HID_CONFIG_DESC_SIZ]
|
|||||||
__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 */
|
/* 18 */
|
||||||
0x09, /*bLength: HID Descriptor size*/
|
0x09, /* bLength: HID Descriptor size */
|
||||||
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
|
HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
|
||||||
0x11, /*bcdHID: HID Class Spec release number*/
|
0x11, /* bcdHID: HID Class Spec release number */
|
||||||
0x01,
|
0x01,
|
||||||
0x00, /*bCountryCode: Hardware target country*/
|
0x00, /* bCountryCode: Hardware target country */
|
||||||
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
|
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */
|
||||||
0x22, /*bDescriptorType*/
|
0x22, /* bDescriptorType */
|
||||||
HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
|
HID_MOUSE_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -380,46 +375,64 @@ __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] _
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @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 */
|
UNUSED(cfgidx);
|
||||||
USBD_LL_OpenEP(pdev, HID_EPIN_ADDR, USBD_EP_TYPE_INTR, HID_EPIN_SIZE);
|
|
||||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 1U;
|
|
||||||
|
|
||||||
pdev->pClassData = USBD_malloc(sizeof (USBD_HID_HandleTypeDef));
|
USBD_HID_HandleTypeDef *hhid;
|
||||||
|
|
||||||
if (pdev->pClassData == NULL)
|
hhid = 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
|
* DeInitialize the HID layer
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
uint8_t cfgidx)
|
|
||||||
{
|
{
|
||||||
/* Close HID EPs */
|
UNUSED(cfgidx);
|
||||||
USBD_LL_CloseEP(pdev, HID_EPIN_ADDR);
|
|
||||||
pdev->ep_in[HID_EPIN_ADDR & 0xFU].is_used = 0U;
|
|
||||||
|
|
||||||
/* FRee allocated memory */
|
/* Close HID EPs */
|
||||||
if(pdev->pClassData != NULL)
|
(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;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -429,14 +442,18 @@ static uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
USBD_SetupReqTypedef *req)
|
|
||||||
{
|
{
|
||||||
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef*) pdev->pClassData;
|
USBD_HID_HandleTypeDef *hhid = (USBD_HID_HandleTypeDef *)pdev->pClassData;
|
||||||
uint16_t len = 0U;
|
|
||||||
uint8_t *pbuf = NULL;
|
|
||||||
uint16_t status_info = 0U;
|
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
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)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
@@ -448,7 +465,7 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HID_REQ_GET_PROTOCOL:
|
case HID_REQ_GET_PROTOCOL:
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->Protocol, 1U);
|
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HID_REQ_SET_IDLE:
|
case HID_REQ_SET_IDLE:
|
||||||
@@ -456,11 +473,11 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HID_REQ_GET_IDLE:
|
case HID_REQ_GET_IDLE:
|
||||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&hhid->IdleState, 1U);
|
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -471,73 +488,76 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
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
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_DESCRIPTOR:
|
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);
|
len = MIN(HID_MOUSE_REPORT_DESC_SIZE, req->wLength);
|
||||||
pbuf = HID_MOUSE_ReportDesc;
|
pbuf = HID_MOUSE_ReportDesc;
|
||||||
}
|
}
|
||||||
else if(req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
|
else if ((req->wValue >> 8) == HID_DESCRIPTOR_TYPE)
|
||||||
{
|
{
|
||||||
pbuf = USBD_HID_Desc;
|
pbuf = USBD_HID_Desc;
|
||||||
len = MIN(USB_HID_DESC_SIZ, req->wLength);
|
len = MIN(USB_HID_DESC_SIZ, req->wLength);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
USBD_CtlSendData (pdev, pbuf, len);
|
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_GET_INTERFACE :
|
case USB_REQ_GET_INTERFACE :
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
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
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_SET_INTERFACE :
|
case USB_REQ_SET_INTERFACE:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -547,24 +567,25 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
* @param buff: pointer to report
|
* @param buff: pointer to report
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_HID_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len)
|
||||||
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 (pdev->dev_state == USBD_STATE_CONFIGURED )
|
if (hhid == NULL)
|
||||||
{
|
{
|
||||||
if(hhid->state == HID_IDLE)
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
|
{
|
||||||
|
if (hhid->state == HID_IDLE)
|
||||||
{
|
{
|
||||||
hhid->state = HID_BUSY;
|
hhid->state = HID_BUSY;
|
||||||
USBD_LL_Transmit (pdev,
|
(void)USBD_LL_Transmit(pdev, HID_EPIN_ADDR, report, len);
|
||||||
HID_EPIN_ADDR,
|
|
||||||
report,
|
|
||||||
len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return USBD_OK;
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -573,17 +594,17 @@ uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev,
|
|||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval polling interval
|
* @retval polling interval
|
||||||
*/
|
*/
|
||||||
uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev)
|
uint32_t USBD_HID_GetPollingInterval(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
uint32_t polling_interval = 0U;
|
uint32_t polling_interval;
|
||||||
|
|
||||||
/* HIGH-speed endpoints */
|
/* HIGH-speed endpoints */
|
||||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
/* Sets the data transfer polling interval for high speed transfers.
|
/* Sets the data transfer polling interval for high speed transfers.
|
||||||
Values between 1..16 are allowed. Values correspond to interval
|
Values between 1..16 are allowed. Values correspond to interval
|
||||||
of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
|
of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
|
||||||
polling_interval = (((1U <<(HID_HS_BINTERVAL - 1U))) / 8U);
|
polling_interval = (((1U << (HID_HS_BINTERVAL - 1U))) / 8U);
|
||||||
}
|
}
|
||||||
else /* LOW and FULL-speed endpoints */
|
else /* LOW and FULL-speed endpoints */
|
||||||
{
|
{
|
||||||
@@ -602,9 +623,10 @@ uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_HID_CfgFSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,9 +637,10 @@ static uint8_t *USBD_HID_GetFSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_HID_CfgHSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -628,9 +651,10 @@ static uint8_t *USBD_HID_GetHSCfgDesc (uint16_t *length)
|
|||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_HID_OtherSpeedCfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -641,26 +665,27 @@ static uint8_t *USBD_HID_GetOtherSpeedCfgDesc (uint16_t *length)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_HID_DataIn (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
|
UNUSED(epnum);
|
||||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||||
be caused by a new transfer before the end of the previous transfer */
|
be caused by a new transfer before the end of the previous transfer */
|
||||||
((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE;
|
((USBD_HID_HandleTypeDef *)pdev->pClassData)->state = HID_IDLE;
|
||||||
return USBD_OK;
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
static uint8_t *USBD_HID_GetDeviceQualifierDesc (uint16_t *length)
|
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;
|
return USBD_HID_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_MSC_H
|
#define __USBD_MSC_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -68,16 +68,16 @@
|
|||||||
*/
|
*/
|
||||||
typedef struct _USBD_STORAGE
|
typedef struct _USBD_STORAGE
|
||||||
{
|
{
|
||||||
int8_t (* Init) (uint8_t lun);
|
int8_t (* Init)(uint8_t lun);
|
||||||
int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size);
|
int8_t (* GetCapacity)(uint8_t lun, uint32_t *block_num, uint16_t *block_size);
|
||||||
int8_t (* IsReady) (uint8_t lun);
|
int8_t (* IsReady)(uint8_t lun);
|
||||||
int8_t (* IsWriteProtected) (uint8_t lun);
|
int8_t (* IsWriteProtected)(uint8_t lun);
|
||||||
int8_t (* Read) (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
int8_t (* Read)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
||||||
int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
|
||||||
int8_t (* GetMaxLun)(void);
|
int8_t (* GetMaxLun)(void);
|
||||||
int8_t *pInquiry;
|
int8_t *pInquiry;
|
||||||
|
|
||||||
}USBD_StorageTypeDef;
|
} USBD_StorageTypeDef;
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -86,7 +86,7 @@ typedef struct
|
|||||||
uint32_t interface;
|
uint32_t interface;
|
||||||
uint8_t bot_state;
|
uint8_t bot_state;
|
||||||
uint8_t bot_status;
|
uint8_t bot_status;
|
||||||
uint16_t bot_data_length;
|
uint32_t bot_data_length;
|
||||||
uint8_t bot_data[MSC_MEDIA_PACKET];
|
uint8_t bot_data[MSC_MEDIA_PACKET];
|
||||||
USBD_MSC_BOT_CBWTypeDef cbw;
|
USBD_MSC_BOT_CBWTypeDef cbw;
|
||||||
USBD_MSC_BOT_CSWTypeDef csw;
|
USBD_MSC_BOT_CSWTypeDef csw;
|
||||||
@@ -94,6 +94,7 @@ typedef struct
|
|||||||
USBD_SCSI_SenseTypeDef scsi_sense [SENSE_LIST_DEEPTH];
|
USBD_SCSI_SenseTypeDef scsi_sense [SENSE_LIST_DEEPTH];
|
||||||
uint8_t scsi_sense_head;
|
uint8_t scsi_sense_head;
|
||||||
uint8_t scsi_sense_tail;
|
uint8_t scsi_sense_tail;
|
||||||
|
uint8_t scsi_medium_state;
|
||||||
|
|
||||||
uint16_t scsi_blk_size;
|
uint16_t scsi_blk_size;
|
||||||
uint32_t scsi_blk_nbr;
|
uint32_t scsi_blk_nbr;
|
||||||
@@ -107,7 +108,7 @@ USBD_MSC_BOT_HandleTypeDef;
|
|||||||
extern USBD_ClassTypeDef USBD_MSC;
|
extern USBD_ClassTypeDef USBD_MSC;
|
||||||
#define USBD_MSC_CLASS &USBD_MSC
|
#define USBD_MSC_CLASS &USBD_MSC
|
||||||
|
|
||||||
uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev,
|
||||||
USBD_StorageTypeDef *fops);
|
USBD_StorageTypeDef *fops);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_MSC_BOT_H
|
#define __USBD_MSC_BOT_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -116,19 +116,19 @@ USBD_MSC_BOT_CSWTypeDef;
|
|||||||
/** @defgroup USBD_CORE_Exported_FunctionsPrototypes
|
/** @defgroup USBD_CORE_Exported_FunctionsPrototypes
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_Init (USBD_HandleTypeDef *pdev);
|
void MSC_BOT_Init(USBD_HandleTypeDef *pdev);
|
||||||
void MSC_BOT_Reset (USBD_HandleTypeDef *pdev);
|
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev);
|
||||||
void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev);
|
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum);
|
uint8_t epnum);
|
||||||
|
|
||||||
void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum);
|
uint8_t epnum);
|
||||||
|
|
||||||
void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t CSW_Status);
|
uint8_t CSW_Status);
|
||||||
|
|
||||||
void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_CplClrFeature(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum);
|
uint8_t epnum);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -144,7 +144,7 @@ void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_MSC_DATA_H
|
#define __USBD_MSC_DATA_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -40,10 +40,11 @@
|
|||||||
/** @defgroup USB_INFO_Exported_Defines
|
/** @defgroup USB_INFO_Exported_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define MODE_SENSE6_LEN 8U
|
#define MODE_SENSE6_LEN 0x17U
|
||||||
#define MODE_SENSE10_LEN 8U
|
#define MODE_SENSE10_LEN 0x1BU
|
||||||
#define LENGTH_INQUIRY_PAGE00 7U
|
#define LENGTH_INQUIRY_PAGE00 0x06U
|
||||||
#define LENGTH_FORMAT_CAPACITIES 20U
|
#define LENGTH_INQUIRY_PAGE80 0x08U
|
||||||
|
#define LENGTH_FORMAT_CAPACITIES 0x14U
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -70,9 +71,10 @@
|
|||||||
/** @defgroup USBD_INFO_Exported_Variables
|
/** @defgroup USBD_INFO_Exported_Variables
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
extern const uint8_t MSC_Page00_Inquiry_Data[];
|
extern uint8_t MSC_Page00_Inquiry_Data[LENGTH_INQUIRY_PAGE00];
|
||||||
extern const uint8_t MSC_Mode_Sense6_data[];
|
extern uint8_t MSC_Page80_Inquiry_Data[LENGTH_INQUIRY_PAGE80];
|
||||||
extern const uint8_t MSC_Mode_Sense10_data[] ;
|
extern uint8_t MSC_Mode_Sense6_data[MODE_SENSE6_LEN];
|
||||||
|
extern uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -97,7 +99,7 @@ extern const uint8_t MSC_Mode_Sense10_data[] ;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_MSC_SCSI_H
|
#define __USBD_MSC_SCSI_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -103,20 +103,13 @@
|
|||||||
|
|
||||||
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0CU
|
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0CU
|
||||||
#define READ_CAPACITY10_DATA_LEN 0x08U
|
#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 REQUEST_SENSE_DATA_LEN 0x12U
|
||||||
#define STANDARD_INQUIRY_DATA_LEN 0x24U
|
#define STANDARD_INQUIRY_DATA_LEN 0x24U
|
||||||
#define BLKVFY 0x04U
|
#define BLKVFY 0x04U
|
||||||
|
|
||||||
extern uint8_t Page00_Inquiry_Data[];
|
#define SCSI_MEDIUM_UNLOCKED 0x00U
|
||||||
extern uint8_t Standard_Inquiry_Data[];
|
#define SCSI_MEDIUM_LOCKED 0x01U
|
||||||
extern uint8_t Standard_Inquiry_Data2[];
|
#define SCSI_MEDIUM_EJECTED 0x02U
|
||||||
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 [];
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -126,15 +119,18 @@ extern uint8_t ReadFormatCapacity_Data [];
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct _SENSE_ITEM {
|
typedef struct _SENSE_ITEM
|
||||||
char Skey;
|
{
|
||||||
union {
|
uint8_t Skey;
|
||||||
struct _ASCs {
|
union
|
||||||
char ASC;
|
{
|
||||||
char ASCQ;
|
struct _ASCs
|
||||||
}b;
|
{
|
||||||
uint8_t ASC;
|
uint8_t ASC;
|
||||||
char *pData;
|
uint8_t ASCQ;
|
||||||
|
} b;
|
||||||
|
uint8_t ASC;
|
||||||
|
uint8_t *pData;
|
||||||
} w;
|
} w;
|
||||||
} USBD_SCSI_SenseTypeDef;
|
} USBD_SCSI_SenseTypeDef;
|
||||||
/**
|
/**
|
||||||
@@ -182,8 +178,8 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_MSC_STORAGE_H
|
#define __USBD_MSC_STORAGE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -92,6 +92,6 @@ extern USBD_StorageTypeDef USBD_MSC_Template_fops;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|||||||
@@ -27,16 +27,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_msc.h"
|
#include "usbd_msc.h"
|
||||||
@@ -80,30 +80,16 @@
|
|||||||
/** @defgroup MSC_CORE_Private_FunctionPrototypes
|
/** @defgroup MSC_CORE_Private_FunctionPrototypes
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
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_DeInit (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t cfgidx);
|
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -135,10 +121,9 @@ USBD_ClassTypeDef USBD_MSC =
|
|||||||
|
|
||||||
/* USB Mass storage device Configuration Descriptor */
|
/* USB Mass storage device Configuration Descriptor */
|
||||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
||||||
__ALIGN_BEGIN 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: Configuration Descriptor size */
|
||||||
0x09, /* bLength: Configuation Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_MSC_CONFIG_DESC_SIZ,
|
USB_MSC_CONFIG_DESC_SIZ,
|
||||||
|
|
||||||
@@ -146,43 +131,46 @@ __ALIGN_BEGIN uint8_t USBD_MSC_CfgHSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
0x01, /* bNumInterfaces: 1 interface */
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /* bConfigurationValue: */
|
0x01, /* bConfigurationValue: */
|
||||||
0x04, /* iConfiguration: */
|
0x04, /* iConfiguration: */
|
||||||
0xC0, /* bmAttributes: */
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0x32, /* MaxPower 100 mA */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA */
|
||||||
|
|
||||||
/******************** Mass Storage interface ********************/
|
/******************** Mass Storage interface ********************/
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
0x04, /* bDescriptorType: */
|
0x04, /* bDescriptorType: */
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x02, /* bNumEndpoints*/
|
0x02, /* bNumEndpoints */
|
||||||
0x08, /* bInterfaceClass: MSC Class */
|
0x08, /* bInterfaceClass: MSC Class */
|
||||||
0x06, /* bInterfaceSubClass : SCSI transparent*/
|
0x06, /* bInterfaceSubClass : SCSI transparent */
|
||||||
0x50, /* nInterfaceProtocol */
|
0x50, /* nInterfaceProtocol */
|
||||||
0x05, /* iInterface: */
|
0x05, /* iInterface: */
|
||||||
/******************** Mass Storage Endpoints ********************/
|
/******************** Mass Storage Endpoints ********************/
|
||||||
0x07, /*Endpoint descriptor length = 7*/
|
0x07, /* Endpoint descriptor length = 7 */
|
||||||
0x05, /*Endpoint descriptor type */
|
0x05, /* Endpoint descriptor type */
|
||||||
MSC_EPIN_ADDR, /*Endpoint address (IN, address 1) */
|
MSC_EPIN_ADDR, /* Endpoint address (IN, address 1) */
|
||||||
0x02, /*Bulk endpoint type */
|
0x02, /* Bulk endpoint type */
|
||||||
LOBYTE(MSC_MAX_HS_PACKET),
|
LOBYTE(MSC_MAX_HS_PACKET),
|
||||||
HIBYTE(MSC_MAX_HS_PACKET),
|
HIBYTE(MSC_MAX_HS_PACKET),
|
||||||
0x00, /*Polling interval in milliseconds */
|
0x00, /* Polling interval in milliseconds */
|
||||||
|
|
||||||
0x07, /*Endpoint descriptor length = 7 */
|
0x07, /* Endpoint descriptor length = 7 */
|
||||||
0x05, /*Endpoint descriptor type */
|
0x05, /* Endpoint descriptor type */
|
||||||
MSC_EPOUT_ADDR, /*Endpoint address (OUT, address 1) */
|
MSC_EPOUT_ADDR, /* Endpoint address (OUT, address 1) */
|
||||||
0x02, /*Bulk endpoint type */
|
0x02, /* Bulk endpoint type */
|
||||||
LOBYTE(MSC_MAX_HS_PACKET),
|
LOBYTE(MSC_MAX_HS_PACKET),
|
||||||
HIBYTE(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 */
|
/* USB Mass storage device Configuration Descriptor */
|
||||||
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
/* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
|
||||||
uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
__ALIGN_BEGIN static uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||||
{
|
{
|
||||||
|
0x09, /* bLength: Configuration Descriptor size */
|
||||||
0x09, /* bLength: Configuation Descriptor size */
|
|
||||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_MSC_CONFIG_DESC_SIZ,
|
USB_MSC_CONFIG_DESC_SIZ,
|
||||||
|
|
||||||
@@ -190,8 +178,12 @@ uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
0x01, /* bNumInterfaces: 1 interface */
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /* bConfigurationValue: */
|
0x01, /* bConfigurationValue: */
|
||||||
0x04, /* iConfiguration: */
|
0x04, /* iConfiguration: */
|
||||||
0xC0, /* bmAttributes: */
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0x32, /* MaxPower 100 mA */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA */
|
||||||
|
|
||||||
/******************** Mass Storage interface ********************/
|
/******************** Mass Storage interface ********************/
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
@@ -204,27 +196,26 @@ uint8_t USBD_MSC_CfgFSDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
|
|||||||
0x50, /* nInterfaceProtocol */
|
0x50, /* nInterfaceProtocol */
|
||||||
0x05, /* iInterface: */
|
0x05, /* iInterface: */
|
||||||
/******************** Mass Storage Endpoints ********************/
|
/******************** Mass Storage Endpoints ********************/
|
||||||
0x07, /*Endpoint descriptor length = 7*/
|
0x07, /* Endpoint descriptor length = 7 */
|
||||||
0x05, /*Endpoint descriptor type */
|
0x05, /* Endpoint descriptor type */
|
||||||
MSC_EPIN_ADDR, /*Endpoint address (IN, address 1) */
|
MSC_EPIN_ADDR, /* Endpoint address (IN, address 1) */
|
||||||
0x02, /*Bulk endpoint type */
|
0x02, /* Bulk endpoint type */
|
||||||
LOBYTE(MSC_MAX_FS_PACKET),
|
LOBYTE(MSC_MAX_FS_PACKET),
|
||||||
HIBYTE(MSC_MAX_FS_PACKET),
|
HIBYTE(MSC_MAX_FS_PACKET),
|
||||||
0x00, /*Polling interval in milliseconds */
|
0x00, /* Polling interval in milliseconds */
|
||||||
|
|
||||||
0x07, /*Endpoint descriptor length = 7 */
|
0x07, /* Endpoint descriptor length = 7 */
|
||||||
0x05, /*Endpoint descriptor type */
|
0x05, /* Endpoint descriptor type */
|
||||||
MSC_EPOUT_ADDR, /*Endpoint address (OUT, address 1) */
|
MSC_EPOUT_ADDR, /* Endpoint address (OUT, address 1) */
|
||||||
0x02, /*Bulk endpoint type */
|
0x02, /* Bulk endpoint type */
|
||||||
LOBYTE(MSC_MAX_FS_PACKET),
|
LOBYTE(MSC_MAX_FS_PACKET),
|
||||||
HIBYTE(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: Configuration Descriptor size */
|
||||||
0x09, /* bLength: Configuation Descriptor size */
|
|
||||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
||||||
USB_MSC_CONFIG_DESC_SIZ,
|
USB_MSC_CONFIG_DESC_SIZ,
|
||||||
|
|
||||||
@@ -232,39 +223,43 @@ __ALIGN_BEGIN uint8_t USBD_MSC_OtherSpeedCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __AL
|
|||||||
0x01, /* bNumInterfaces: 1 interface */
|
0x01, /* bNumInterfaces: 1 interface */
|
||||||
0x01, /* bConfigurationValue: */
|
0x01, /* bConfigurationValue: */
|
||||||
0x04, /* iConfiguration: */
|
0x04, /* iConfiguration: */
|
||||||
0xC0, /* bmAttributes: */
|
#if (USBD_SELF_POWERED == 1U)
|
||||||
0x32, /* MaxPower 100 mA */
|
0xC0, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#else
|
||||||
|
0x80, /* bmAttributes: Bus Powered according to user configuration */
|
||||||
|
#endif
|
||||||
|
USBD_MAX_POWER, /* MaxPower 100 mA */
|
||||||
|
|
||||||
/******************** Mass Storage interface ********************/
|
/******************** Mass Storage interface ********************/
|
||||||
0x09, /* bLength: Interface Descriptor size */
|
0x09, /* bLength: Interface Descriptor size */
|
||||||
0x04, /* bDescriptorType: */
|
0x04, /* bDescriptorType: */
|
||||||
0x00, /* bInterfaceNumber: Number of Interface */
|
0x00, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x02, /* bNumEndpoints*/
|
0x02, /* bNumEndpoints */
|
||||||
0x08, /* bInterfaceClass: MSC Class */
|
0x08, /* bInterfaceClass: MSC Class */
|
||||||
0x06, /* bInterfaceSubClass : SCSI transparent command set*/
|
0x06, /* bInterfaceSubClass : SCSI transparent command set */
|
||||||
0x50, /* nInterfaceProtocol */
|
0x50, /* nInterfaceProtocol */
|
||||||
0x05, /* iInterface: */
|
0x05, /* iInterface: */
|
||||||
/******************** Mass Storage Endpoints ********************/
|
/******************** Mass Storage Endpoints ********************/
|
||||||
0x07, /*Endpoint descriptor length = 7*/
|
0x07, /* Endpoint descriptor length = 7 */
|
||||||
0x05, /*Endpoint descriptor type */
|
0x05, /* Endpoint descriptor type */
|
||||||
MSC_EPIN_ADDR, /*Endpoint address (IN, address 1) */
|
MSC_EPIN_ADDR, /* Endpoint address (IN, address 1) */
|
||||||
0x02, /*Bulk endpoint type */
|
0x02, /* Bulk endpoint type */
|
||||||
0x40,
|
0x40,
|
||||||
0x00,
|
0x00,
|
||||||
0x00, /*Polling interval in milliseconds */
|
0x00, /* Polling interval in milliseconds */
|
||||||
|
|
||||||
0x07, /*Endpoint descriptor length = 7 */
|
0x07, /* Endpoint descriptor length = 7 */
|
||||||
0x05, /*Endpoint descriptor type */
|
0x05, /* Endpoint descriptor type */
|
||||||
MSC_EPOUT_ADDR, /*Endpoint address (OUT, address 1) */
|
MSC_EPOUT_ADDR, /* Endpoint address (OUT, address 1) */
|
||||||
0x02, /*Bulk endpoint type */
|
0x02, /* Bulk endpoint type */
|
||||||
0x40,
|
0x40,
|
||||||
0x00,
|
0x00,
|
||||||
0x00 /*Polling interval in milliseconds*/
|
0x00 /* Polling interval in milliseconds */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* USB Standard Device Descriptor */
|
/* 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_LEN_DEV_QUALIFIER_DESC,
|
||||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||||
@@ -293,96 +288,109 @@ __ALIGN_BEGIN uint8_t USBD_MSC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC]
|
|||||||
* @param cfgidx: configuration index
|
* @param cfgidx: configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
uint8_t USBD_MSC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
UNUSED(cfgidx);
|
||||||
|
USBD_MSC_BOT_HandleTypeDef *hmsc;
|
||||||
|
|
||||||
|
hmsc = 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 */
|
/* 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;
|
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP IN */
|
/* 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;
|
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 1U;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Open EP OUT */
|
/* 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;
|
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
/* Open EP IN */
|
/* 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->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 */
|
/* Init the BOT layer */
|
||||||
MSC_BOT_Init(pdev);
|
MSC_BOT_Init(pdev);
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_DeInit
|
* @brief USBD_MSC_DeInit
|
||||||
* DeInitilaize the mass storage configuration
|
* DeInitialize the mass storage configuration
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param cfgidx: configuration index
|
* @param cfgidx: configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
uint8_t cfgidx)
|
|
||||||
{
|
{
|
||||||
|
UNUSED(cfgidx);
|
||||||
|
|
||||||
/* Close MSC EPs */
|
/* 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;
|
pdev->ep_out[MSC_EPOUT_ADDR & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
/* Close EP IN */
|
/* 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;
|
pdev->ep_in[MSC_EPIN_ADDR & 0xFU].is_used = 0U;
|
||||||
|
|
||||||
|
/* Free MSC Class Resources */
|
||||||
|
if (pdev->pClassData != NULL)
|
||||||
|
{
|
||||||
/* De-Init the BOT layer */
|
/* De-Init the BOT layer */
|
||||||
MSC_BOT_DeInit(pdev);
|
MSC_BOT_DeInit(pdev);
|
||||||
|
|
||||||
/* Free MSC Class Resources */
|
(void)USBD_free(pdev->pClassData);
|
||||||
if(pdev->pClassData != NULL)
|
|
||||||
{
|
|
||||||
USBD_free(pdev->pClassData);
|
|
||||||
pdev->pClassData = NULL;
|
pdev->pClassData = NULL;
|
||||||
}
|
}
|
||||||
return USBD_OK;
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_Setup
|
* @brief USBD_MSC_Setup
|
||||||
* Handle the MSC specific requests
|
* Handle the MSC specific requests
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param req: USB request
|
* @param req: USB request
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
uint8_t USBD_MSC_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||||
uint8_t ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
uint16_t status_info = 0U;
|
uint16_t status_info = 0U;
|
||||||
|
|
||||||
|
if (hmsc == NULL)
|
||||||
|
{
|
||||||
|
return (uint8_t)USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Class request */
|
/* Class request */
|
||||||
case USB_REQ_TYPE_CLASS:
|
case USB_REQ_TYPE_CLASS:
|
||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
case BOT_GET_MAX_LUN:
|
case BOT_GET_MAX_LUN:
|
||||||
if((req->wValue == 0U) && (req->wLength == 1U) &&
|
if ((req->wValue == 0U) && (req->wLength == 1U) &&
|
||||||
((req->bmRequest & 0x80U) == 0x80U))
|
((req->bmRequest & 0x80U) == 0x80U))
|
||||||
{
|
{
|
||||||
hmsc->max_lun = (uint32_t)((USBD_StorageTypeDef *)pdev->pUserData)->GetMaxLun();
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -392,20 +400,20 @@ uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case BOT_RESET :
|
case BOT_RESET :
|
||||||
if((req->wValue == 0U) && (req->wLength == 0U) &&
|
if ((req->wValue == 0U) && (req->wLength == 0U) &&
|
||||||
((req->bmRequest & 0x80U) != 0x80U))
|
((req->bmRequest & 0x80U) != 0x80U))
|
||||||
{
|
{
|
||||||
MSC_BOT_Reset(pdev);
|
MSC_BOT_Reset(pdev);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError(pdev , req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError(pdev , req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -417,11 +425,11 @@ uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
case USB_REQ_GET_STATUS:
|
case USB_REQ_GET_STATUS:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
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
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -429,11 +437,11 @@ uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
case USB_REQ_GET_INTERFACE:
|
case USB_REQ_GET_INTERFACE:
|
||||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
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
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -445,161 +453,135 @@ uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_CLEAR_FEATURE:
|
case USB_REQ_CLEAR_FEATURE:
|
||||||
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
/* 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)
|
|
||||||
{
|
{
|
||||||
pdev->ep_in[(uint8_t)req->wIndex & 0xFU].is_used = 0U;
|
if (req->wValue == USB_FEATURE_EP_HALT)
|
||||||
if(pdev->dev_speed == USBD_SPEED_HIGH)
|
|
||||||
{
|
{
|
||||||
/* Open EP IN */
|
/* Flush the FIFO */
|
||||||
USBD_LL_OpenEP(pdev, MSC_EPIN_ADDR, USBD_EP_TYPE_BULK,
|
(void)USBD_LL_FlushEP(pdev, (uint8_t)req->wIndex);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Handle BOT error */
|
/* Handle BOT error */
|
||||||
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
|
MSC_BOT_CplClrFeature(pdev, (uint8_t)req->wIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_DataIn
|
* @brief USBD_MSC_DataIn
|
||||||
* handle data IN Stage
|
* handle data IN Stage
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
MSC_BOT_DataIn(pdev , epnum);
|
MSC_BOT_DataIn(pdev, epnum);
|
||||||
return USBD_OK;
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_DataOut
|
* @brief USBD_MSC_DataOut
|
||||||
* handle data OUT Stage
|
* handle data OUT Stage
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
MSC_BOT_DataOut(pdev , epnum);
|
MSC_BOT_DataOut(pdev, epnum);
|
||||||
return USBD_OK;
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_GetHSCfgDesc
|
* @brief USBD_MSC_GetHSCfgDesc
|
||||||
* return configuration descriptor
|
* return configuration descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_MSC_GetHSCfgDesc (uint16_t *length)
|
uint8_t *USBD_MSC_GetHSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_MSC_CfgHSDesc);
|
*length = (uint16_t)sizeof(USBD_MSC_CfgHSDesc);
|
||||||
|
|
||||||
return USBD_MSC_CfgHSDesc;
|
return USBD_MSC_CfgHSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_GetFSCfgDesc
|
* @brief USBD_MSC_GetFSCfgDesc
|
||||||
* return configuration descriptor
|
* return configuration descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_MSC_GetFSCfgDesc (uint16_t *length)
|
uint8_t *USBD_MSC_GetFSCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_MSC_CfgFSDesc);
|
*length = (uint16_t)sizeof(USBD_MSC_CfgFSDesc);
|
||||||
|
|
||||||
return USBD_MSC_CfgFSDesc;
|
return USBD_MSC_CfgFSDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_GetOtherSpeedCfgDesc
|
* @brief USBD_MSC_GetOtherSpeedCfgDesc
|
||||||
* return other speed configuration descriptor
|
* return other speed configuration descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc (uint16_t *length)
|
uint8_t *USBD_MSC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_MSC_OtherSpeedCfgDesc);
|
*length = (uint16_t)sizeof(USBD_MSC_OtherSpeedCfgDesc);
|
||||||
|
|
||||||
return USBD_MSC_OtherSpeedCfgDesc;
|
return USBD_MSC_OtherSpeedCfgDesc;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length)
|
uint8_t *USBD_MSC_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_MSC_DeviceQualifierDesc);
|
*length = (uint16_t)sizeof(USBD_MSC_DeviceQualifierDesc);
|
||||||
|
|
||||||
return USBD_MSC_DeviceQualifierDesc;
|
return USBD_MSC_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_MSC_RegisterStorage
|
* @brief USBD_MSC_RegisterStorage
|
||||||
* @param fops: storage callback
|
* @param fops: storage callback
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev,
|
uint8_t USBD_MSC_RegisterStorage(USBD_HandleTypeDef *pdev, USBD_StorageTypeDef *fops)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_msc_bot.h"
|
#include "usbd_msc_bot.h"
|
||||||
@@ -76,11 +76,8 @@
|
|||||||
/** @defgroup MSC_BOT_Private_FunctionPrototypes
|
/** @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, uint32_t len);
|
||||||
|
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_Abort(USBD_HandleTypeDef *pdev);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -92,90 +89,110 @@ static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_Init
|
* @brief MSC_BOT_Init
|
||||||
* Initialize the BOT Process
|
* Initialize the BOT Process
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_Init (USBD_HandleTypeDef *pdev)
|
void MSC_BOT_Init(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (hmsc == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hmsc->bot_state = USBD_BOT_IDLE;
|
hmsc->bot_state = USBD_BOT_IDLE;
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
||||||
|
|
||||||
hmsc->scsi_sense_tail = 0U;
|
hmsc->scsi_sense_tail = 0U;
|
||||||
hmsc->scsi_sense_head = 0U;
|
hmsc->scsi_sense_head = 0U;
|
||||||
|
hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED;
|
||||||
|
|
||||||
((USBD_StorageTypeDef *)pdev->pUserData)->Init(0U);
|
((USBD_StorageTypeDef *)pdev->pUserData)->Init(0U);
|
||||||
|
|
||||||
USBD_LL_FlushEP(pdev, MSC_EPOUT_ADDR);
|
(void)USBD_LL_FlushEP(pdev, MSC_EPOUT_ADDR);
|
||||||
USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR);
|
(void)USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR);
|
||||||
|
|
||||||
/* Prapare EP to Receive First BOT Cmd */
|
/* Prepare EP to Receive First BOT Cmd */
|
||||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw,
|
||||||
USBD_BOT_CBW_LENGTH);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_Reset
|
* @brief MSC_BOT_Reset
|
||||||
* Reset the BOT Machine
|
* Reset the BOT Machine
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_Reset (USBD_HandleTypeDef *pdev)
|
void MSC_BOT_Reset(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (hmsc == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hmsc->bot_state = USBD_BOT_IDLE;
|
hmsc->bot_state = USBD_BOT_IDLE;
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
|
hmsc->bot_status = USBD_BOT_STATUS_RECOVERY;
|
||||||
|
|
||||||
/* Prapare EP to Receive First BOT Cmd */
|
(void)USBD_LL_ClearStallEP(pdev, MSC_EPIN_ADDR);
|
||||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
(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);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_DeInit
|
* @brief MSC_BOT_DeInit
|
||||||
* Deinitialize the BOT Machine
|
* DeInitialize the BOT Machine
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev)
|
void MSC_BOT_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (hmsc != NULL)
|
||||||
|
{
|
||||||
hmsc->bot_state = USBD_BOT_IDLE;
|
hmsc->bot_state = USBD_BOT_IDLE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_DataIn
|
* @brief MSC_BOT_DataIn
|
||||||
* Handle BOT IN data stage
|
* Handle BOT IN data stage
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
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)
|
switch (hmsc->bot_state)
|
||||||
{
|
{
|
||||||
case USBD_BOT_DATA_IN:
|
case USBD_BOT_DATA_IN:
|
||||||
if(SCSI_ProcessCmd(pdev,
|
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||||
hmsc->cbw.bLUN,
|
|
||||||
&hmsc->cbw.CB[0]) < 0)
|
|
||||||
{
|
{
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED);
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USBD_BOT_SEND_DATA:
|
case USBD_BOT_SEND_DATA:
|
||||||
case USBD_BOT_LAST_DATA_IN:
|
case USBD_BOT_LAST_DATA_IN:
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED);
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -183,16 +200,22 @@ void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_DataOut
|
* @brief MSC_BOT_DataOut
|
||||||
* Process MSC OUT data
|
* Process MSC OUT data
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
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)
|
switch (hmsc->bot_state)
|
||||||
{
|
{
|
||||||
@@ -201,14 +224,10 @@ void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USBD_BOT_DATA_OUT:
|
case USBD_BOT_DATA_OUT:
|
||||||
|
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||||
if(SCSI_ProcessCmd(pdev,
|
|
||||||
hmsc->cbw.bLUN,
|
|
||||||
&hmsc->cbw.CB[0]) < 0)
|
|
||||||
{
|
{
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED);
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -217,24 +236,28 @@ void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_CBW_Decode
|
* @brief MSC_BOT_CBW_Decode
|
||||||
* Decode the CBW command and set the BOT state machine accordingly
|
* Decode the CBW command and set the BOT state machine accordingly
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
static void MSC_BOT_CBW_Decode(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||||
|
|
||||||
|
if (hmsc == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
hmsc->csw.dTag = hmsc->cbw.dTag;
|
hmsc->csw.dTag = hmsc->cbw.dTag;
|
||||||
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
|
hmsc->csw.dDataResidue = hmsc->cbw.dDataLength;
|
||||||
|
|
||||||
if ((USBD_LL_GetRxDataSize (pdev ,MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) ||
|
if ((USBD_LL_GetRxDataSize(pdev, MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) ||
|
||||||
(hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) ||
|
(hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) ||
|
||||||
(hmsc->cbw.bLUN > 1U) ||
|
(hmsc->cbw.bLUN > 1U) || (hmsc->cbw.bCBLength < 1U) ||
|
||||||
(hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U))
|
(hmsc->cbw.bCBLength > 16U))
|
||||||
{
|
{
|
||||||
|
|
||||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
||||||
|
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_ERROR;
|
hmsc->bot_status = USBD_BOT_STATUS_ERROR;
|
||||||
@@ -242,18 +265,18 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
if (SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0)
|
||||||
{
|
{
|
||||||
if(hmsc->bot_state == USBD_BOT_NO_DATA)
|
if (hmsc->bot_state == USBD_BOT_NO_DATA)
|
||||||
{
|
{
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED);
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MSC_BOT_Abort(pdev);
|
MSC_BOT_Abort(pdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*Burst xfer handled internally*/
|
/* Burst xfer handled internally */
|
||||||
else if ((hmsc->bot_state != USBD_BOT_DATA_IN) &&
|
else if ((hmsc->bot_state != USBD_BOT_DATA_IN) &&
|
||||||
(hmsc->bot_state != USBD_BOT_DATA_OUT) &&
|
(hmsc->bot_state != USBD_BOT_DATA_OUT) &&
|
||||||
(hmsc->bot_state != USBD_BOT_LAST_DATA_IN))
|
(hmsc->bot_state != USBD_BOT_LAST_DATA_IN))
|
||||||
@@ -264,7 +287,7 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
else if (hmsc->bot_data_length == 0U)
|
else if (hmsc->bot_data_length == 0U)
|
||||||
{
|
{
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED);
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -279,98 +302,116 @@ static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_SendData
|
* @brief MSC_BOT_SendData
|
||||||
* Send the requested data
|
* Send the requested data
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param buf: pointer to data buffer
|
* @param buf: pointer to data buffer
|
||||||
* @param len: Data Length
|
* @param len: Data Length
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t* pbuf,
|
static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len)
|
||||||
uint16_t len)
|
|
||||||
{
|
{
|
||||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->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.dDataResidue -= len;
|
||||||
hmsc->csw.bStatus = USBD_CSW_CMD_PASSED;
|
hmsc->csw.bStatus = USBD_CSW_CMD_PASSED;
|
||||||
hmsc->bot_state = USBD_BOT_SEND_DATA;
|
hmsc->bot_state = USBD_BOT_SEND_DATA;
|
||||||
|
|
||||||
USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, pbuf, length);
|
(void)USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, pbuf, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_SendCSW
|
* @brief MSC_BOT_SendCSW
|
||||||
* Send the Command Status Wrapper
|
* Send the Command Status Wrapper
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param status : CSW status
|
* @param status : CSW status
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev,
|
void MSC_BOT_SendCSW(USBD_HandleTypeDef *pdev, uint8_t CSW_Status)
|
||||||
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.dSignature = USBD_BOT_CSW_SIGNATURE;
|
||||||
hmsc->csw.bStatus = CSW_Status;
|
hmsc->csw.bStatus = CSW_Status;
|
||||||
hmsc->bot_state = USBD_BOT_IDLE;
|
hmsc->bot_state = USBD_BOT_IDLE;
|
||||||
|
|
||||||
USBD_LL_Transmit (pdev, MSC_EPIN_ADDR, (uint8_t *)(void *)&hmsc->csw,
|
(void)USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, (uint8_t *)&hmsc->csw,
|
||||||
USBD_BOT_CSW_LENGTH);
|
USBD_BOT_CSW_LENGTH);
|
||||||
|
|
||||||
/* Prepare EP to Receive next Cmd */
|
/* Prepare EP to Receive next Cmd */
|
||||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
(void)USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, (uint8_t *)&hmsc->cbw,
|
||||||
USBD_BOT_CBW_LENGTH);
|
USBD_BOT_CBW_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_Abort
|
* @brief MSC_BOT_Abort
|
||||||
* Abort the current transfer
|
* Abort the current transfer
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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) &&
|
if ((hmsc->cbw.bmFlags == 0U) &&
|
||||||
(hmsc->cbw.dDataLength != 0U) &&
|
(hmsc->cbw.dDataLength != 0U) &&
|
||||||
(hmsc->bot_status == USBD_BOT_STATUS_NORMAL))
|
(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)
|
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR)
|
||||||
{
|
{
|
||||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw,
|
(void)USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
||||||
USBD_BOT_CBW_LENGTH);
|
(void)USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MSC_BOT_CplClrFeature
|
* @brief MSC_BOT_CplClrFeature
|
||||||
* Complete the clear feature request
|
* Complete the clear feature request
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval None
|
* @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->bot_status == USBD_BOT_STATUS_ERROR)/* Bad CBW Signature */
|
if (hmsc == NULL)
|
||||||
{
|
{
|
||||||
USBD_LL_StallEP(pdev, MSC_EPIN_ADDR);
|
return;
|
||||||
hmsc->bot_status = USBD_BOT_STATUS_NORMAL;
|
|
||||||
}
|
}
|
||||||
else if(((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY))
|
|
||||||
|
if (hmsc->bot_status == USBD_BOT_STATUS_ERROR) /* Bad CBW Signature */
|
||||||
{
|
{
|
||||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED);
|
(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))
|
||||||
|
{
|
||||||
|
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_FAILED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,16 +12,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_msc_data.h"
|
#include "usbd_msc_data.h"
|
||||||
@@ -65,19 +65,48 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* USB Mass storage Page 0 Inquiry Data */
|
/* 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,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
(LENGTH_INQUIRY_PAGE00 - 4U),
|
(LENGTH_INQUIRY_PAGE00 - 4U),
|
||||||
0x00,
|
0x00,
|
||||||
0x80,
|
0x80
|
||||||
0x83
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* 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 */
|
/* USB Mass storage sense 6 Data */
|
||||||
const uint8_t MSC_Mode_Sense6_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,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
@@ -87,10 +116,32 @@ const uint8_t MSC_Mode_Sense6_data[] = {
|
|||||||
0x00,
|
0x00,
|
||||||
0x00
|
0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* USB Mass storage sense 10 Data */
|
/* USB Mass storage sense 10 Data */
|
||||||
const uint8_t MSC_Mode_Sense10_data[] = {
|
uint8_t MSC_Mode_Sense10_data[MODE_SENSE10_LEN] =
|
||||||
|
{
|
||||||
|
0x00,
|
||||||
|
0x26,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x08,
|
||||||
|
0x12,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x06,
|
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -12,16 +12,16 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* BSPDependencies
|
/* BSPDependencies
|
||||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||||
EndBSPDependencies */
|
EndBSPDependencies */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_msc_storage_template.h"
|
#include "usbd_msc_storage_template.h"
|
||||||
@@ -35,34 +35,30 @@
|
|||||||
/* Extern function prototypes ------------------------------------------------*/
|
/* Extern function prototypes ------------------------------------------------*/
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
#define STORAGE_LUN_NBR 1
|
#define STORAGE_LUN_NBR 1U
|
||||||
#define STORAGE_BLK_NBR 0x10000
|
#define STORAGE_BLK_NBR 0x10000U
|
||||||
#define STORAGE_BLK_SIZ 0x200
|
#define STORAGE_BLK_SIZ 0x200U
|
||||||
|
|
||||||
int8_t STORAGE_Init (uint8_t lun);
|
int8_t STORAGE_Init(uint8_t lun);
|
||||||
|
|
||||||
int8_t STORAGE_GetCapacity (uint8_t lun,
|
int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num,
|
||||||
uint32_t *block_num,
|
|
||||||
uint16_t *block_size);
|
uint16_t *block_size);
|
||||||
|
|
||||||
int8_t STORAGE_IsReady (uint8_t lun);
|
int8_t STORAGE_IsReady(uint8_t lun);
|
||||||
|
|
||||||
int8_t STORAGE_IsWriteProtected (uint8_t lun);
|
int8_t STORAGE_IsWriteProtected(uint8_t lun);
|
||||||
|
|
||||||
int8_t STORAGE_Read (uint8_t lun,
|
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr,
|
||||||
uint8_t *buf,
|
|
||||||
uint32_t blk_addr,
|
|
||||||
uint16_t blk_len);
|
uint16_t blk_len);
|
||||||
|
|
||||||
int8_t STORAGE_Write (uint8_t lun,
|
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr,
|
||||||
uint8_t *buf,
|
|
||||||
uint32_t blk_addr,
|
|
||||||
uint16_t blk_len);
|
uint16_t blk_len);
|
||||||
|
|
||||||
int8_t STORAGE_GetMaxLun (void);
|
int8_t STORAGE_GetMaxLun(void);
|
||||||
|
|
||||||
/* USB Mass storage Standard Inquiry Data */
|
/* USB Mass storage Standard Inquiry Data */
|
||||||
int8_t STORAGE_Inquirydata[] = {//36
|
int8_t STORAGE_Inquirydata[] = /* 36 */
|
||||||
|
{
|
||||||
|
|
||||||
/* LUN 0 */
|
/* LUN 0 */
|
||||||
0x00,
|
0x00,
|
||||||
@@ -76,7 +72,7 @@ int8_t STORAGE_Inquirydata[] = {//36
|
|||||||
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
|
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
|
||||||
'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */
|
'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */
|
||||||
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||||
'0', '.', '0' ,'1', /* Version : 4 Bytes */
|
'0', '.', '0', '1', /* Version : 4 Bytes */
|
||||||
};
|
};
|
||||||
|
|
||||||
USBD_StorageTypeDef USBD_MSC_Template_fops =
|
USBD_StorageTypeDef USBD_MSC_Template_fops =
|
||||||
@@ -92,25 +88,25 @@ USBD_StorageTypeDef USBD_MSC_Template_fops =
|
|||||||
|
|
||||||
};
|
};
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : Read_Memory
|
* Function Name : Read_Memory
|
||||||
* Description : Handle the Read operation from the microSD card.
|
* Description : Handle the Read operation from the microSD card.
|
||||||
* Input : None.
|
* Input : None.
|
||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_Init (uint8_t lun)
|
int8_t STORAGE_Init(uint8_t lun)
|
||||||
{
|
{
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : Read_Memory
|
* Function Name : Read_Memory
|
||||||
* Description : Handle the Read operation from the STORAGE card.
|
* Description : Handle the Read operation from the STORAGE card.
|
||||||
* Input : None.
|
* Input : None.
|
||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
int8_t STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
|
||||||
{
|
{
|
||||||
*block_num = STORAGE_BLK_NBR;
|
*block_num = STORAGE_BLK_NBR;
|
||||||
*block_size = STORAGE_BLK_SIZ;
|
*block_size = STORAGE_BLK_SIZ;
|
||||||
@@ -118,65 +114,61 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint16_t *block_si
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : Read_Memory
|
* Function Name : Read_Memory
|
||||||
* Description : Handle the Read operation from the STORAGE card.
|
* Description : Handle the Read operation from the STORAGE card.
|
||||||
* Input : None.
|
* Input : None.
|
||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_IsReady (uint8_t lun)
|
int8_t STORAGE_IsReady(uint8_t lun)
|
||||||
{
|
{
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : Read_Memory
|
* Function Name : Read_Memory
|
||||||
* Description : Handle the Read operation from the STORAGE card.
|
* Description : Handle the Read operation from the STORAGE card.
|
||||||
* Input : None.
|
* Input : None.
|
||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_IsWriteProtected (uint8_t lun)
|
int8_t STORAGE_IsWriteProtected(uint8_t lun)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : Read_Memory
|
* Function Name : Read_Memory
|
||||||
* Description : Handle the Read operation from the STORAGE card.
|
* Description : Handle the Read operation from the STORAGE card.
|
||||||
* Input : None.
|
* Input : None.
|
||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_Read (uint8_t lun,
|
int8_t STORAGE_Read(uint8_t lun, uint8_t *buf,
|
||||||
uint8_t *buf,
|
uint32_t blk_addr, uint16_t blk_len)
|
||||||
uint32_t blk_addr,
|
|
||||||
uint16_t blk_len)
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : Write_Memory
|
* Function Name : Write_Memory
|
||||||
* Description : Handle the Write operation to the STORAGE card.
|
* Description : Handle the Write operation to the STORAGE card.
|
||||||
* Input : None.
|
* Input : None.
|
||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_Write (uint8_t lun,
|
int8_t STORAGE_Write(uint8_t lun, uint8_t *buf,
|
||||||
uint8_t *buf,
|
uint32_t blk_addr, uint16_t blk_len)
|
||||||
uint32_t blk_addr,
|
|
||||||
uint16_t blk_len)
|
|
||||||
{
|
{
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : Write_Memory
|
* Function Name : Write_Memory
|
||||||
* Description : Handle the Write operation to the STORAGE card.
|
* Description : Handle the Write operation to the STORAGE card.
|
||||||
* Input : None.
|
* Input : None.
|
||||||
* Output : None.
|
* Output : None.
|
||||||
* Return : None.
|
* Return : None.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int8_t STORAGE_GetMaxLun (void)
|
int8_t STORAGE_GetMaxLun(void)
|
||||||
{
|
{
|
||||||
return (STORAGE_LUN_NBR - 1);
|
return (STORAGE_LUN_NBR - 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USB_TEMPLATE_CORE_H
|
#define __USB_TEMPLATE_CORE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -41,10 +41,10 @@
|
|||||||
/** @defgroup USBD_TEMPLATE_Exported_Defines
|
/** @defgroup USBD_TEMPLATE_Exported_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define TEMPLATE_EPIN_ADDR 0x81
|
#define TEMPLATE_EPIN_ADDR 0x81U
|
||||||
#define TEMPLATE_EPIN_SIZE 0x10
|
#define TEMPLATE_EPIN_SIZE 0x10U
|
||||||
|
|
||||||
#define USB_TEMPLATE_CONFIG_DESC_SIZ 64
|
#define USB_TEMPLATE_CONFIG_DESC_SIZ 64U
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -83,33 +83,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
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_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t cfgidx);
|
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_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_EP0_TxReady(USBD_HandleTypeDef *pdev);
|
||||||
USBD_SetupReqTypedef *req);
|
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_GetCfgDesc (uint16_t *length);
|
static uint8_t USBD_TEMPLATE_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
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_GetCfgDesc(uint16_t *length);
|
||||||
|
static uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -137,12 +123,12 @@ USBD_ClassTypeDef USBD_TEMPLATE_ClassDriver =
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif
|
||||||
/* USB TEMPLATE device Configuration Descriptor */
|
/* 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_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||||
USB_TEMPLATE_CONFIG_DESC_SIZ,
|
USB_TEMPLATE_CONFIG_DESC_SIZ,
|
||||||
/* wTotalLength: Bytes returned */
|
/* wTotalLength: Bytes returned */
|
||||||
@@ -159,10 +145,10 @@ static uint8_t USBD_TEMPLATE_CfgDesc[USB_TEMPLATE_CONFIG_DESC_SIZ] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif
|
||||||
/* USB Standard Device Descriptor */
|
/* 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_LEN_DEV_QUALIFIER_DESC,
|
||||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||||
@@ -191,13 +177,10 @@ static uint8_t USBD_TEMPLATE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] =
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
uint8_t cfgidx)
|
|
||||||
{
|
{
|
||||||
uint8_t ret = 0;
|
|
||||||
|
|
||||||
|
return (uint8_t)USBD_OK;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -207,11 +190,10 @@ static uint8_t USBD_TEMPLATE_Init (USBD_HandleTypeDef *pdev,
|
|||||||
* @param cfgidx: Configuration index
|
* @param cfgidx: Configuration index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
uint8_t cfgidx)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -221,7 +203,7 @@ static uint8_t USBD_TEMPLATE_DeInit (USBD_HandleTypeDef *pdev,
|
|||||||
* @param req: usb requests
|
* @param req: usb requests
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_Setup(USBD_HandleTypeDef *pdev,
|
||||||
USBD_SetupReqTypedef *req)
|
USBD_SetupReqTypedef *req)
|
||||||
{
|
{
|
||||||
USBD_StatusTypeDef ret = USBD_OK;
|
USBD_StatusTypeDef ret = USBD_OK;
|
||||||
@@ -232,7 +214,7 @@ static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -242,47 +224,45 @@ static uint8_t USBD_TEMPLATE_Setup (USBD_HandleTypeDef *pdev,
|
|||||||
switch (req->bRequest)
|
switch (req->bRequest)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_CtlError (pdev, req);
|
USBD_CtlError(pdev, req);
|
||||||
ret = USBD_FAIL;
|
ret = USBD_FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return (uint8_t)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_TEMPLATE_GetCfgDesc
|
* @brief USBD_TEMPLATE_GetCfgDesc
|
||||||
* return configuration descriptor
|
* return configuration descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @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;
|
return USBD_TEMPLATE_CfgDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor (uint16_t *length)
|
uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_TEMPLATE_DeviceQualifierDesc);
|
*length = (uint16_t)sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
||||||
return USBD_TEMPLATE_DeviceQualifierDesc;
|
return USBD_TEMPLATE_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_TEMPLATE_DataIn
|
* @brief USBD_TEMPLATE_DataIn
|
||||||
* handle data IN Stage
|
* handle data IN Stage
|
||||||
@@ -290,11 +270,10 @@ uint8_t *USBD_TEMPLATE_DeviceQualifierDescriptor (uint16_t *length)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_DataIn (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
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
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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
|
* @brief USBD_TEMPLATE_EP0_TxReady
|
||||||
* handle EP0 TRx Ready event
|
* handle EP0 TRx Ready event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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
|
* @brief USBD_TEMPLATE_SOF
|
||||||
* handle SOF event
|
* handle SOF event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @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
|
* @brief USBD_TEMPLATE_IsoINIncomplete
|
||||||
* handle data ISO IN Incomplete event
|
* handle data ISO IN Incomplete event
|
||||||
@@ -337,11 +319,12 @@ static uint8_t USBD_TEMPLATE_SOF (USBD_HandleTypeDef *pdev)
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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
|
* @brief USBD_TEMPLATE_IsoOutIncomplete
|
||||||
* handle data ISO OUT Incomplete event
|
* 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
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @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
|
* @brief USBD_TEMPLATE_DataOut
|
||||||
@@ -361,22 +344,22 @@ static uint8_t USBD_TEMPLATE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_
|
|||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
static uint8_t USBD_TEMPLATE_DataOut (USBD_HandleTypeDef *pdev,
|
static uint8_t USBD_TEMPLATE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||||
uint8_t epnum)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
return USBD_OK;
|
return (uint8_t)USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DeviceQualifierDescriptor
|
* @brief DeviceQualifierDescriptor
|
||||||
* return Device Qualifier descriptor
|
* return Device Qualifier descriptor
|
||||||
* @param length : pointer data length
|
* @param length : pointer data length
|
||||||
* @retval pointer to descriptor buffer
|
* @retval pointer to descriptor buffer
|
||||||
*/
|
*/
|
||||||
uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc (uint16_t *length)
|
uint8_t *USBD_TEMPLATE_GetDeviceQualifierDesc(uint16_t *length)
|
||||||
{
|
{
|
||||||
*length = sizeof (USBD_TEMPLATE_DeviceQualifierDesc);
|
*length = (uint16_t)sizeof(USBD_TEMPLATE_DeviceQualifierDesc);
|
||||||
|
|
||||||
return USBD_TEMPLATE_DeviceQualifierDesc;
|
return USBD_TEMPLATE_DeviceQualifierDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
457
Class/VIDEO/Inc/usbd_video.h
Normal file
457
Class/VIDEO/Inc/usbd_video.h
Normal file
@@ -0,0 +1,457 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_video.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief header file for the usbd_video.c file.
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2020 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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 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 *);
|
||||||
|
uint8_t *pStrDesc;
|
||||||
|
} 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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _USBD_VIDEO_H_ */
|
||||||
142
Class/VIDEO/Inc/usbd_video_if_template.h
Normal file
142
Class/VIDEO/Inc/usbd_video_if_template.h
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file usbd_video_if_template.h
|
||||||
|
* @author MCD Application Team
|
||||||
|
* @brief Template Header file for the video Interface application layer functions
|
||||||
|
******************************************************************************
|
||||||
|
* @attention
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2020 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
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/* USER CODE END EXPORTED_FUNCTIONS */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USBD_VIDEO_IF_H_ */
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1040
Class/VIDEO/Src/usbd_video.c
Normal file
1040
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
|
||||||
|
*
|
||||||
|
* <h2><center>© Copyright (c) 2020 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 ------------------------------------------------------------------*/
|
||||||
|
#include "usbd_video_if.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 ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
|
||||||
|
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]) / ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)));
|
||||||
|
uint32_t packet_remainder = (tImagesSizes[img_count]) % ((uint16_t)(UVC_PACKET_SIZE - (UVC_HEADER_PACKET_CNT * 2U)));
|
||||||
|
static uint8_t packet_index = 0;
|
||||||
|
|
||||||
|
/* 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 = 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 + 1))
|
||||||
|
{
|
||||||
|
/* Reset the packet count to zero */
|
||||||
|
packet_index = 0U;
|
||||||
|
|
||||||
|
/* Move to the next image in the images table */
|
||||||
|
|
||||||
|
img_count++;
|
||||||
|
HAL_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 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_CONF_TEMPLATE_H
|
#define __USBD_CONF_TEMPLATE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -47,39 +47,98 @@
|
|||||||
#define USBD_MAX_NUM_INTERFACES 1U
|
#define USBD_MAX_NUM_INTERFACES 1U
|
||||||
#define USBD_MAX_NUM_CONFIGURATION 1U
|
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||||
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
||||||
#define USBD_SUPPORT_USER_STRING 0U
|
|
||||||
#define USBD_SELF_POWERED 1U
|
#define USBD_SELF_POWERED 1U
|
||||||
#define USBD_DEBUG_LEVEL 2U
|
#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 */
|
/* MSC Class Config */
|
||||||
#define MSC_MEDIA_PACKET 8192U
|
#define MSC_MEDIA_PACKET 8192U
|
||||||
|
|
||||||
/* CDC Class Config */
|
/* CDC Class Config */
|
||||||
#define USBD_CDC_INTERVAL 2000U
|
#define USBD_CDC_INTERVAL 2000U
|
||||||
|
|
||||||
/* DFU Class Config */
|
/* DFU Class Config */
|
||||||
#define USBD_DFU_MAX_ITF_NUM 1U
|
#define USBD_DFU_MAX_ITF_NUM 1U
|
||||||
#define USBD_DFU_XFERS_IZE 1024U
|
#define USBD_DFU_XFERS_IZE 1024U
|
||||||
|
|
||||||
/* AUDIO Class Config */
|
/* 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
|
/** @defgroup USBD_Exported_Macros
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Memory management macros */
|
/* Memory management macros make sure to use static memory allocation */
|
||||||
#define USBD_malloc malloc
|
/** Alias for memory allocation. */
|
||||||
#define USBD_free free
|
#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
|
#define USBD_memset memset
|
||||||
|
|
||||||
|
/** Alias for memory copy. */
|
||||||
#define USBD_memcpy memcpy
|
#define USBD_memcpy memcpy
|
||||||
|
|
||||||
|
/** Alias for delay. */
|
||||||
|
#define USBD_Delay HAL_Delay
|
||||||
|
|
||||||
/* DEBUG macros */
|
/* DEBUG macros */
|
||||||
#if (USBD_DEBUG_LEVEL > 0U)
|
#if (USBD_DEBUG_LEVEL > 0U)
|
||||||
#define USBD_UsrLog(...) do { \
|
#define USBD_UsrLog(...) do { \
|
||||||
printf(__VA_ARGS__); \
|
printf(__VA_ARGS__); \
|
||||||
printf("\n"); \
|
printf("\n"); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define USBD_UsrLog(...) do {} while (0)
|
#define USBD_UsrLog(...) do {} while (0)
|
||||||
#endif
|
#endif
|
||||||
@@ -90,7 +149,7 @@
|
|||||||
printf("ERROR: ") ; \
|
printf("ERROR: ") ; \
|
||||||
printf(__VA_ARGS__); \
|
printf(__VA_ARGS__); \
|
||||||
printf("\n"); \
|
printf("\n"); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define USBD_ErrLog(...) do {} while (0)
|
#define USBD_ErrLog(...) do {} while (0)
|
||||||
#endif
|
#endif
|
||||||
@@ -100,7 +159,7 @@
|
|||||||
printf("DEBUG : ") ; \
|
printf("DEBUG : ") ; \
|
||||||
printf(__VA_ARGS__); \
|
printf(__VA_ARGS__); \
|
||||||
printf("\n"); \
|
printf("\n"); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define USBD_DbgLog(...) do {} while (0)
|
#define USBD_DbgLog(...) do {} while (0)
|
||||||
#endif
|
#endif
|
||||||
@@ -141,6 +200,9 @@
|
|||||||
/** @defgroup USBD_CONF_Exported_FunctionsPrototype
|
/** @defgroup USBD_CONF_Exported_FunctionsPrototype
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
/* Exported functions -------------------------------------------------------*/
|
||||||
|
void *USBD_static_malloc(uint32_t size);
|
||||||
|
void USBD_static_free(void *p);
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_CORE_H
|
#define __USBD_CORE_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -84,17 +84,17 @@
|
|||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
|
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
|
||||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
USBD_StatusTypeDef USBD_ClrClassConfig(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_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_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_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Reset(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_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
||||||
@@ -109,33 +109,30 @@ USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
|
|||||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
||||||
|
|
||||||
/* USBD Low Level Driver */
|
/* USBD Low Level Driver */
|
||||||
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
||||||
USBD_StatusTypeDef USBD_LL_Stop (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_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
uint8_t ep_type, uint16_t ep_mps);
|
||||||
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_PrepareReceive(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
uint8_t ep_addr,
|
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
uint8_t *pbuf,
|
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
uint16_t size);
|
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||||
|
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr);
|
||||||
|
|
||||||
uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
void USBD_LL_Delay (uint32_t Delay);
|
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,8 +149,8 @@ void USBD_LL_Delay (uint32_t Delay);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USB_REQUEST_H
|
#define __USB_REQUEST_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -73,16 +73,14 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_StdDevReq (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_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
USBD_StatusTypeDef USBD_StdEPReq (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);
|
||||||
|
|
||||||
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 +96,8 @@ void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_DEF_H
|
#define __USBD_DEF_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -61,9 +61,17 @@
|
|||||||
#define USBD_SELF_POWERED 1U
|
#define USBD_SELF_POWERED 1U
|
||||||
#endif /*USBD_SELF_POWERED */
|
#endif /*USBD_SELF_POWERED */
|
||||||
|
|
||||||
#ifndef USBD_SUPPORT_USER_STRING
|
#ifndef USBD_MAX_POWER
|
||||||
#define USBD_SUPPORT_USER_STRING 0U
|
#define USBD_MAX_POWER 0x32U /* 100 mA */
|
||||||
#endif /* USBD_SUPPORT_USER_STRING */
|
#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_QUALIFIER_DESC 0x0AU
|
||||||
#define USB_LEN_DEV_DESC 0x12U
|
#define USB_LEN_DEV_DESC 0x12U
|
||||||
@@ -110,6 +118,7 @@
|
|||||||
#define USB_DESC_TYPE_ENDPOINT 0x05U
|
#define USB_DESC_TYPE_ENDPOINT 0x05U
|
||||||
#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
|
#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
|
||||||
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
|
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
|
||||||
|
#define USB_DESC_TYPE_IAD 0x0BU
|
||||||
#define USB_DESC_TYPE_BOS 0x0FU
|
#define USB_DESC_TYPE_BOS 0x0FU
|
||||||
|
|
||||||
#define USB_CONFIG_REMOTE_WAKEUP 0x02U
|
#define USB_CONFIG_REMOTE_WAKEUP 0x02U
|
||||||
@@ -121,6 +130,11 @@
|
|||||||
|
|
||||||
#define USB_DEVICE_CAPABITY_TYPE 0x10U
|
#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_HS_MAX_PACKET_SIZE 512U
|
||||||
#define USB_FS_MAX_PACKET_SIZE 64U
|
#define USB_FS_MAX_PACKET_SIZE 64U
|
||||||
#define USB_MAX_EP0_SIZE 64U
|
#define USB_MAX_EP0_SIZE 64U
|
||||||
@@ -146,7 +160,6 @@
|
|||||||
#define USBD_EP_TYPE_BULK 0x02U
|
#define USBD_EP_TYPE_BULK 0x02U
|
||||||
#define USBD_EP_TYPE_INTR 0x03U
|
#define USBD_EP_TYPE_INTR 0x03U
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
@@ -158,37 +171,66 @@
|
|||||||
|
|
||||||
typedef struct usb_setup_req
|
typedef struct usb_setup_req
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t bmRequest;
|
uint8_t bmRequest;
|
||||||
uint8_t bRequest;
|
uint8_t bRequest;
|
||||||
uint16_t wValue;
|
uint16_t wValue;
|
||||||
uint16_t wIndex;
|
uint16_t wIndex;
|
||||||
uint16_t wLength;
|
uint16_t wLength;
|
||||||
}USBD_SetupReqTypedef;
|
} 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;
|
||||||
|
} USBD_EpDescTypedef;
|
||||||
|
|
||||||
struct _USBD_HandleTypeDef;
|
struct _USBD_HandleTypeDef;
|
||||||
|
|
||||||
typedef struct _Device_cb
|
typedef struct _Device_cb
|
||||||
{
|
{
|
||||||
uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
|
uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev , uint8_t cfgidx);
|
uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||||
/* Control Endpoints*/
|
/* Control Endpoints*/
|
||||||
uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req);
|
uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||||
uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev );
|
uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev);
|
||||||
uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev );
|
uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev);
|
||||||
/* Class Specific Endpoints*/
|
/* Class Specific Endpoints*/
|
||||||
uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev);
|
uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev);
|
||||||
uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev , uint8_t epnum);
|
uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||||
|
|
||||||
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
|
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
|
||||||
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
|
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
|
||||||
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
|
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
|
||||||
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
||||||
#if (USBD_SUPPORT_USER_STRING == 1U)
|
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||||
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev ,uint8_t index, uint16_t *length);
|
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} USBD_ClassTypeDef;
|
} USBD_ClassTypeDef;
|
||||||
@@ -199,27 +241,32 @@ typedef enum
|
|||||||
USBD_SPEED_HIGH = 0U,
|
USBD_SPEED_HIGH = 0U,
|
||||||
USBD_SPEED_FULL = 1U,
|
USBD_SPEED_FULL = 1U,
|
||||||
USBD_SPEED_LOW = 2U,
|
USBD_SPEED_LOW = 2U,
|
||||||
}USBD_SpeedTypeDef;
|
} USBD_SpeedTypeDef;
|
||||||
|
|
||||||
/* Following USB Device status */
|
/* Following USB Device status */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
USBD_OK = 0U,
|
USBD_OK = 0U,
|
||||||
USBD_BUSY,
|
USBD_BUSY,
|
||||||
|
USBD_EMEM,
|
||||||
USBD_FAIL,
|
USBD_FAIL,
|
||||||
}USBD_StatusTypeDef;
|
} USBD_StatusTypeDef;
|
||||||
|
|
||||||
/* USB Device descriptors structure */
|
/* USB Device descriptors structure */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t *(*GetDeviceDescriptor)( 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 *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *(*GetManufacturerStrDescriptor)( 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 *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *(*GetSerialStrDescriptor)( 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 *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *(*GetInterfaceStrDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
#if (USBD_LPM_ENABLED == 1U)
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
uint8_t *(*GetBOSDescriptor)( USBD_SpeedTypeDef speed , uint16_t *length);
|
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
|
#endif
|
||||||
} USBD_DescriptorsTypeDef;
|
} USBD_DescriptorsTypeDef;
|
||||||
|
|
||||||
@@ -227,10 +274,11 @@ typedef struct
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
uint32_t is_used;
|
|
||||||
uint32_t total_length;
|
uint32_t total_length;
|
||||||
uint32_t rem_length;
|
uint32_t rem_length;
|
||||||
uint32_t maxpacket;
|
uint32_t maxpacket;
|
||||||
|
uint16_t is_used;
|
||||||
|
uint16_t bInterval;
|
||||||
} USBD_EndpointTypeDef;
|
} USBD_EndpointTypeDef;
|
||||||
|
|
||||||
/* USB Device handle structure */
|
/* USB Device handle structure */
|
||||||
@@ -241,16 +289,17 @@ typedef struct _USBD_HandleTypeDef
|
|||||||
uint32_t dev_default_config;
|
uint32_t dev_default_config;
|
||||||
uint32_t dev_config_status;
|
uint32_t dev_config_status;
|
||||||
USBD_SpeedTypeDef dev_speed;
|
USBD_SpeedTypeDef dev_speed;
|
||||||
USBD_EndpointTypeDef ep_in[15];
|
USBD_EndpointTypeDef ep_in[16];
|
||||||
USBD_EndpointTypeDef ep_out[15];
|
USBD_EndpointTypeDef ep_out[16];
|
||||||
uint32_t ep0_state;
|
__IO uint32_t ep0_state;
|
||||||
uint32_t ep0_data_len;
|
uint32_t ep0_data_len;
|
||||||
uint8_t dev_state;
|
__IO uint8_t dev_state;
|
||||||
uint8_t dev_old_state;
|
__IO uint8_t dev_old_state;
|
||||||
uint8_t dev_address;
|
uint8_t dev_address;
|
||||||
uint8_t dev_connection_status;
|
uint8_t dev_connection_status;
|
||||||
uint8_t dev_test_mode;
|
uint8_t dev_test_mode;
|
||||||
uint32_t dev_remote_wakeup;
|
uint32_t dev_remote_wakeup;
|
||||||
|
uint8_t ConfIdx;
|
||||||
|
|
||||||
USBD_SetupReqTypedef request;
|
USBD_SetupReqTypedef request;
|
||||||
USBD_DescriptorsTypeDef *pDesc;
|
USBD_DescriptorsTypeDef *pDesc;
|
||||||
@@ -258,6 +307,8 @@ typedef struct _USBD_HandleTypeDef
|
|||||||
void *pClassData;
|
void *pClassData;
|
||||||
void *pUserData;
|
void *pUserData;
|
||||||
void *pData;
|
void *pData;
|
||||||
|
void *pBosDesc;
|
||||||
|
void *pConfDesc;
|
||||||
} USBD_HandleTypeDef;
|
} USBD_HandleTypeDef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,40 +320,67 @@ typedef struct _USBD_HandleTypeDef
|
|||||||
/** @defgroup USBD_DEF_Exported_Macros
|
/** @defgroup USBD_DEF_Exported_Macros
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
|
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
|
||||||
(((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U))
|
{
|
||||||
|
uint16_t _SwapVal, _Byte1, _Byte2;
|
||||||
|
uint8_t *_pbuff = addr;
|
||||||
|
|
||||||
#define LOBYTE(x) ((uint8_t)(x & 0x00FFU))
|
_Byte1 = *(uint8_t *)_pbuff;
|
||||||
#define HIBYTE(x) ((uint8_t)((x & 0xFF00U) >> 8U))
|
_pbuff++;
|
||||||
|
_Byte2 = *(uint8_t *)_pbuff;
|
||||||
|
|
||||||
|
_SwapVal = (_Byte2 << 8) | _Byte1;
|
||||||
|
|
||||||
|
return _SwapVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef LOBYTE
|
||||||
|
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HIBYTE
|
||||||
|
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined ( __GNUC__ )
|
#if defined ( __GNUC__ )
|
||||||
#ifndef __weak
|
#ifndef __weak
|
||||||
#define __weak __attribute__((weak))
|
#define __weak __attribute__((weak))
|
||||||
#endif /* __weak */
|
#endif /* __weak */
|
||||||
#ifndef __packed
|
#ifndef __packed
|
||||||
#define __packed __attribute__((__packed__))
|
#define __packed __attribute__((__packed__))
|
||||||
#endif /* __packed */
|
#endif /* __packed */
|
||||||
#endif /* __GNUC__ */
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
|
|
||||||
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
||||||
with the DMA during the transaction process should be 4-bytes aligned */
|
with the DMA during the transaction process should be 4-bytes aligned */
|
||||||
|
|
||||||
#if defined (__GNUC__) /* GNU Compiler */
|
#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
|
||||||
#define __ALIGN_END __attribute__ ((aligned (4)))
|
#ifndef __ALIGN_END
|
||||||
#define __ALIGN_BEGIN
|
#define __ALIGN_END __attribute__ ((aligned (4U)))
|
||||||
|
#endif /* __ALIGN_END */
|
||||||
|
#ifndef __ALIGN_BEGIN
|
||||||
|
#define __ALIGN_BEGIN
|
||||||
|
#endif /* __ALIGN_BEGIN */
|
||||||
#else
|
#else
|
||||||
#define __ALIGN_END
|
#ifndef __ALIGN_END
|
||||||
#if defined (__CC_ARM) /* ARM Compiler */
|
#define __ALIGN_END
|
||||||
#define __ALIGN_BEGIN __align(4)
|
#endif /* __ALIGN_END */
|
||||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
#ifndef __ALIGN_BEGIN
|
||||||
#define __ALIGN_BEGIN
|
#if defined (__CC_ARM) /* ARM Compiler */
|
||||||
#elif defined (__TASKING__) /* TASKING Compiler */
|
#define __ALIGN_BEGIN __align(4U)
|
||||||
#define __ALIGN_BEGIN __align(4)
|
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||||
#endif /* __CC_ARM */
|
#define __ALIGN_BEGIN
|
||||||
|
#endif /* __CC_ARM */
|
||||||
|
#endif /* __ALIGN_BEGIN */
|
||||||
#endif /* __GNUC__ */
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
|
|
||||||
@@ -337,6 +415,6 @@ typedef struct _USBD_HandleTypeDef
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -26,11 +26,33 @@
|
|||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
#define DEVICE_ID1 (0x1FFF7A10)
|
#define DEVICE_ID1 (UID_BASE)
|
||||||
#define DEVICE_ID2 (0x1FFF7A14)
|
#define DEVICE_ID2 (UID_BASE + 0x4U)
|
||||||
#define DEVICE_ID3 (0x1FFF7A18)
|
#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 macro ------------------------------------------------------------*/
|
||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#define __USBD_IOREQ_H
|
#define __USBD_IOREQ_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -77,27 +77,22 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf, uint32_t len);
|
||||||
uint16_t len);
|
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf, uint32_t len);
|
||||||
uint16_t len);
|
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf, uint32_t len);
|
||||||
uint16_t len);
|
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf,
|
uint8_t *pbuf, uint32_t len);
|
||||||
uint16_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 +109,6 @@ uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
* @file usbd_conf_template.c
|
* @file usbd_conf_template.c
|
||||||
* @author MCD Application Team
|
* @author MCD Application Team
|
||||||
* @brief USB Device configuration and interface file
|
* @brief USB Device configuration and interface file
|
||||||
* This template should be copied to the user folder, renamed and customized
|
* This template should be copied to the user folder,
|
||||||
* following user needs.
|
* renamed and customized following user needs.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
@@ -14,13 +14,14 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
|
#include "usbd_hid.h" /* Include class header file */
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
/* Private macro -------------------------------------------------------------*/
|
/* Private macro -------------------------------------------------------------*/
|
||||||
@@ -34,6 +35,8 @@
|
|||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +47,8 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +59,8 @@ USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +71,8 @@ USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,11 +84,14 @@ USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
|||||||
* @param ep_mps: Endpoint Max Packet Size
|
* @param ep_mps: Endpoint Max Packet Size
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
uint8_t ep_addr,
|
uint8_t ep_type, uint16_t ep_mps)
|
||||||
uint8_t ep_type,
|
|
||||||
uint16_t ep_mps)
|
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
UNUSED(ep_type);
|
||||||
|
UNUSED(ep_mps);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +103,9 @@ USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
|
|||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_CloseEP(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;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +117,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)
|
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +131,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)
|
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,8 +143,12 @@ USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
|||||||
* @param ep_addr: Endpoint Number
|
* @param ep_addr: Endpoint Number
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(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;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +160,10 @@ USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_add
|
|||||||
*/
|
*/
|
||||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
return 0;
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,8 +172,12 @@ uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
|||||||
* @param ep_addr: Endpoint Number
|
* @param ep_addr: Endpoint Number
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
|
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t dev_addr)
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,11 +189,14 @@ USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_a
|
|||||||
* @param size: Data size
|
* @param size: Data size
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||||
uint8_t ep_addr,
|
uint8_t *pbuf, uint32_t size)
|
||||||
uint8_t *pbuf,
|
|
||||||
uint16_t size)
|
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
UNUSED(pbuf);
|
||||||
|
UNUSED(size);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,10 +209,14 @@ USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
|
|||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t ep_addr,
|
uint8_t ep_addr, uint8_t *pbuf,
|
||||||
uint8_t *pbuf,
|
uint32_t size)
|
||||||
uint16_t size)
|
|
||||||
{
|
{
|
||||||
|
UNUSED(pdev);
|
||||||
|
UNUSED(ep_addr);
|
||||||
|
UNUSED(pbuf);
|
||||||
|
UNUSED(size);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,11 +224,35 @@ USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
|||||||
* @brief Returns the last transferred packet size.
|
* @brief Returns the last transferred packet size.
|
||||||
* @param pdev: Device handle
|
* @param pdev: Device handle
|
||||||
* @param ep_addr: Endpoint Number
|
* @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)
|
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
return 0;
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -199,6 +262,7 @@ uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
|||||||
*/
|
*/
|
||||||
void USBD_LL_Delay(uint32_t Delay)
|
void USBD_LL_Delay(uint32_t Delay)
|
||||||
{
|
{
|
||||||
|
UNUSED(Delay);
|
||||||
}
|
}
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -21,74 +21,78 @@
|
|||||||
#include "usbd_core.h"
|
#include "usbd_core.h"
|
||||||
|
|
||||||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE
|
/** @defgroup USBD_CORE
|
||||||
* @brief usbd core module
|
* @brief usbd core module
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Private_TypesDefinitions
|
/** @defgroup USBD_CORE_Private_TypesDefinitions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Private_Defines
|
/** @defgroup USBD_CORE_Private_Defines
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Private_Macros
|
/** @defgroup USBD_CORE_Private_Macros
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Private_FunctionPrototypes
|
/** @defgroup USBD_CORE_Private_FunctionPrototypes
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Private_Variables
|
/** @defgroup USBD_CORE_Private_Variables
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/** @defgroup USBD_CORE_Private_Functions
|
/** @defgroup USBD_CORE_Private_Functions
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_Init
|
* @brief USBD_Init
|
||||||
* Initializes the device stack and load the class driver
|
* Initializes the device stack and load the class driver
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param pdesc: Descriptor structure address
|
* @param pdesc: Descriptor structure address
|
||||||
* @param id: Low level core index
|
* @param id: Low level core index
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id)
|
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_DescriptorsTypeDef *pdesc, uint8_t id)
|
||||||
{
|
{
|
||||||
|
USBD_StatusTypeDef ret;
|
||||||
|
|
||||||
/* Check whether the USB Host handle is valid */
|
/* Check whether the USB Host handle is valid */
|
||||||
if(pdev == NULL)
|
if (pdev == NULL)
|
||||||
{
|
{
|
||||||
#if (USBD_DEBUG_LEVEL > 1U)
|
#if (USBD_DEBUG_LEVEL > 1U)
|
||||||
USBD_ErrLog("Invalid Device handle");
|
USBD_ErrLog("Invalid Device handle");
|
||||||
@@ -96,14 +100,13 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *
|
|||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unlink previous class*/
|
/* Unlink previous class resources */
|
||||||
if(pdev->pClass != NULL)
|
|
||||||
{
|
|
||||||
pdev->pClass = NULL;
|
pdev->pClass = NULL;
|
||||||
}
|
pdev->pUserData = NULL;
|
||||||
|
pdev->pConfDesc = NULL;
|
||||||
|
|
||||||
/* Assign USBD Descriptors */
|
/* Assign USBD Descriptors */
|
||||||
if(pdesc != NULL)
|
if (pdesc != NULL)
|
||||||
{
|
{
|
||||||
pdev->pDesc = pdesc;
|
pdev->pDesc = pdesc;
|
||||||
}
|
}
|
||||||
@@ -111,33 +114,45 @@ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *
|
|||||||
/* Set Device initial State */
|
/* Set Device initial State */
|
||||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||||
pdev->id = id;
|
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
|
* @brief USBD_DeInit
|
||||||
* Re-Initialize th device library
|
* Re-Initialize the device library
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status: status
|
* @retval status: status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
USBD_StatusTypeDef ret;
|
||||||
|
|
||||||
|
/* Disconnect the USB Device */
|
||||||
|
(void)USBD_LL_Stop(pdev);
|
||||||
|
|
||||||
/* Set Default State */
|
/* Set Default State */
|
||||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||||
|
|
||||||
/* Free Class Resources */
|
/* Free Class Resources */
|
||||||
|
if (pdev->pClass != NULL)
|
||||||
|
{
|
||||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||||
|
pdev->pClass = NULL;
|
||||||
|
pdev->pUserData = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Stop the low level driver */
|
/* Free Device descriptors resources */
|
||||||
USBD_LL_Stop(pdev);
|
pdev->pDesc = NULL;
|
||||||
|
pdev->pConfDesc = NULL;
|
||||||
|
|
||||||
/* Initialize low level driver */
|
/* DeInitialize low level driver */
|
||||||
USBD_LL_DeInit(pdev);
|
ret = USBD_LL_DeInit(pdev);
|
||||||
|
|
||||||
return USBD_OK;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,22 +164,33 @@ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
|||||||
*/
|
*/
|
||||||
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;
|
uint16_t len = 0U;
|
||||||
if(pclass != 0)
|
|
||||||
{
|
if (pclass == NULL)
|
||||||
/* link the class to the USB Device handle */
|
|
||||||
pdev->pClass = pclass;
|
|
||||||
status = USBD_OK;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
#if (USBD_DEBUG_LEVEL > 1U)
|
#if (USBD_DEBUG_LEVEL > 1U)
|
||||||
USBD_ErrLog("Invalid Class handle");
|
USBD_ErrLog("Invalid Class handle");
|
||||||
#endif
|
#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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -173,13 +199,10 @@ USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeD
|
|||||||
* @param pdev: Device Handle
|
* @param pdev: Device Handle
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Start the low level driver */
|
/* Start the low level driver */
|
||||||
USBD_LL_Start(pdev);
|
return USBD_LL_Start(pdev);
|
||||||
|
|
||||||
return USBD_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,24 +211,27 @@ USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev)
|
|||||||
* @param pdev: Device Handle
|
* @param pdev: Device Handle
|
||||||
* @retval USBD Status
|
* @retval USBD Status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Free Class Resources */
|
/* Disconnect USB Device */
|
||||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
(void)USBD_LL_Stop(pdev);
|
||||||
|
|
||||||
/* Stop the low level driver */
|
/* Free Class Resources */
|
||||||
USBD_LL_Stop(pdev);
|
if (pdev->pClass != NULL)
|
||||||
|
{
|
||||||
|
(void)pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||||
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_RunTestMode
|
* @brief USBD_RunTestMode
|
||||||
* Launch test mode process
|
* Launch test mode process
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Prevent unused argument compilation warning */
|
/* Prevent unused argument compilation warning */
|
||||||
UNUSED(pdev);
|
UNUSED(pdev);
|
||||||
@@ -214,52 +240,55 @@ USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_SetClassConfig
|
* @brief USBD_SetClassConfig
|
||||||
* Configure device and start the interface
|
* Configure device and start the interface
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param cfgidx: configuration index
|
* @param cfgidx: configuration index
|
||||||
* @retval status
|
* @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;
|
USBD_StatusTypeDef ret = USBD_FAIL;
|
||||||
|
|
||||||
if(pdev->pClass != NULL)
|
if (pdev->pClass != NULL)
|
||||||
{
|
{
|
||||||
/* Set configuration and Start the Class*/
|
/* Set configuration and Start the Class */
|
||||||
if(pdev->pClass->Init(pdev, cfgidx) == 0U)
|
ret = (USBD_StatusTypeDef)pdev->pClass->Init(pdev, cfgidx);
|
||||||
{
|
|
||||||
ret = USBD_OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_ClrClassConfig
|
* @brief USBD_ClrClassConfig
|
||||||
* Clear current configuration
|
* Clear current configuration
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param cfgidx: configuration index
|
* @param cfgidx: configuration index
|
||||||
* @retval status: USBD_StatusTypeDef
|
* @retval status: USBD_StatusTypeDef
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||||
{
|
{
|
||||||
/* Clear configuration and De-initialize the Class process*/
|
/* Clear configuration and De-initialize the Class process */
|
||||||
|
if (pdev->pClass != NULL)
|
||||||
|
{
|
||||||
pdev->pClass->DeInit(pdev, cfgidx);
|
pdev->pClass->DeInit(pdev, cfgidx);
|
||||||
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_SetupStage
|
* @brief USBD_LL_SetupStage
|
||||||
* Handle the setup stage
|
* Handle the setup stage
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
||||||
{
|
{
|
||||||
|
USBD_StatusTypeDef ret;
|
||||||
|
|
||||||
USBD_ParseSetupRequest(&pdev->request, psetup);
|
USBD_ParseSetupRequest(&pdev->request, psetup);
|
||||||
|
|
||||||
pdev->ep0_state = USBD_EP0_SETUP;
|
pdev->ep0_state = USBD_EP0_SETUP;
|
||||||
@@ -269,295 +298,358 @@ USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
|||||||
switch (pdev->request.bmRequest & 0x1FU)
|
switch (pdev->request.bmRequest & 0x1FU)
|
||||||
{
|
{
|
||||||
case USB_REQ_RECIPIENT_DEVICE:
|
case USB_REQ_RECIPIENT_DEVICE:
|
||||||
USBD_StdDevReq (pdev, &pdev->request);
|
ret = USBD_StdDevReq(pdev, &pdev->request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_RECIPIENT_INTERFACE:
|
case USB_REQ_RECIPIENT_INTERFACE:
|
||||||
USBD_StdItfReq(pdev, &pdev->request);
|
ret = USBD_StdItfReq(pdev, &pdev->request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_REQ_RECIPIENT_ENDPOINT:
|
case USB_REQ_RECIPIENT_ENDPOINT:
|
||||||
USBD_StdEPReq(pdev, &pdev->request);
|
ret = USBD_StdEPReq(pdev, &pdev->request);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U));
|
ret = USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_DataOutStage
|
* @brief USBD_LL_DataOutStage
|
||||||
* Handle data OUT stage
|
* Handle data OUT stage
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @param pdata: data pointer
|
||||||
*/
|
* @retval status
|
||||||
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t epnum, uint8_t *pdata)
|
uint8_t epnum, uint8_t *pdata)
|
||||||
{
|
{
|
||||||
USBD_EndpointTypeDef *pep;
|
USBD_EndpointTypeDef *pep;
|
||||||
|
USBD_StatusTypeDef ret;
|
||||||
|
|
||||||
if(epnum == 0U)
|
if (epnum == 0U)
|
||||||
{
|
{
|
||||||
pep = &pdev->ep_out[0];
|
pep = &pdev->ep_out[0];
|
||||||
|
|
||||||
if ( pdev->ep0_state == USBD_EP0_DATA_OUT)
|
if (pdev->ep0_state == USBD_EP0_DATA_OUT)
|
||||||
{
|
{
|
||||||
if(pep->rem_length > pep->maxpacket)
|
if (pep->rem_length > pep->maxpacket)
|
||||||
{
|
{
|
||||||
pep->rem_length -= pep->maxpacket;
|
pep->rem_length -= pep->maxpacket;
|
||||||
|
|
||||||
USBD_CtlContinueRx (pdev,
|
(void)USBD_CtlContinueRx(pdev, pdata, MIN(pep->rem_length, pep->maxpacket));
|
||||||
pdata,
|
|
||||||
(uint16_t)MIN(pep->rem_length, pep->maxpacket));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if((pdev->pClass->EP0_RxReady != NULL)&&
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
{
|
||||||
|
if (pdev->pClass->EP0_RxReady != NULL)
|
||||||
{
|
{
|
||||||
pdev->pClass->EP0_RxReady(pdev);
|
pdev->pClass->EP0_RxReady(pdev);
|
||||||
}
|
}
|
||||||
USBD_CtlSendStatus(pdev);
|
}
|
||||||
|
|
||||||
|
(void)USBD_CtlSendStatus(pdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
if (pdev->ep0_state == USBD_EP0_STATUS_OUT)
|
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;
|
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
|
else
|
||||||
{
|
{
|
||||||
/* should never be in this condition */
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
return USBD_FAIL;
|
{
|
||||||
|
if (pdev->pClass->DataOut != NULL)
|
||||||
|
{
|
||||||
|
ret = (USBD_StatusTypeDef)pdev->pClass->DataOut(pdev, epnum);
|
||||||
|
|
||||||
|
if (ret != USBD_OK)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_DataInStage
|
* @brief USBD_LL_DataInStage
|
||||||
* Handle data in stage
|
* Handle data in stage
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param epnum: endpoint index
|
* @param epnum: endpoint index
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum,
|
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pdata)
|
uint8_t epnum, uint8_t *pdata)
|
||||||
{
|
{
|
||||||
USBD_EndpointTypeDef *pep;
|
USBD_EndpointTypeDef *pep;
|
||||||
|
USBD_StatusTypeDef ret;
|
||||||
|
|
||||||
if(epnum == 0U)
|
if (epnum == 0U)
|
||||||
{
|
{
|
||||||
pep = &pdev->ep_in[0];
|
pep = &pdev->ep_in[0];
|
||||||
|
|
||||||
if ( pdev->ep0_state == USBD_EP0_DATA_IN)
|
if (pdev->ep0_state == USBD_EP0_DATA_IN)
|
||||||
{
|
{
|
||||||
if(pep->rem_length > pep->maxpacket)
|
if (pep->rem_length > pep->maxpacket)
|
||||||
{
|
{
|
||||||
pep->rem_length -= pep->maxpacket;
|
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 */
|
/* Prepare endpoint for premature end of transfer */
|
||||||
USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U);
|
(void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /* last packet is MPS multiple, so send ZLP packet */
|
{
|
||||||
if((pep->total_length % pep->maxpacket == 0U) &&
|
/* last packet is MPS multiple, so send ZLP packet */
|
||||||
|
if ((pep->maxpacket == pep->rem_length) &&
|
||||||
(pep->total_length >= pep->maxpacket) &&
|
(pep->total_length >= pep->maxpacket) &&
|
||||||
(pep->total_length < pdev->ep0_data_len))
|
(pep->total_length < pdev->ep0_data_len))
|
||||||
{
|
{
|
||||||
USBD_CtlContinueSendData(pdev, NULL, 0U);
|
(void)USBD_CtlContinueSendData(pdev, NULL, 0U);
|
||||||
pdev->ep0_data_len = 0U;
|
pdev->ep0_data_len = 0U;
|
||||||
|
|
||||||
/* Prepare endpoint for premature end of transfer */
|
/* Prepare endpoint for premature end of transfer */
|
||||||
USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U);
|
(void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if((pdev->pClass->EP0_TxSent != NULL)&&
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
{
|
||||||
|
if (pdev->pClass->EP0_TxSent != NULL)
|
||||||
{
|
{
|
||||||
pdev->pClass->EP0_TxSent(pdev);
|
pdev->pClass->EP0_TxSent(pdev);
|
||||||
}
|
}
|
||||||
USBD_LL_StallEP(pdev, 0x80U);
|
}
|
||||||
USBD_CtlReceiveStatus(pdev);
|
(void)USBD_LL_StallEP(pdev, 0x80U);
|
||||||
|
(void)USBD_CtlReceiveStatus(pdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
if ((pdev->ep0_state == USBD_EP0_STATUS_IN) ||
|
if ((pdev->ep0_state == USBD_EP0_STATUS_IN) ||
|
||||||
(pdev->ep0_state == USBD_EP0_IDLE))
|
(pdev->ep0_state == USBD_EP0_IDLE))
|
||||||
{
|
{
|
||||||
USBD_LL_StallEP(pdev, 0x80U);
|
(void)USBD_LL_StallEP(pdev, 0x80U);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdev->dev_test_mode == 1U)
|
if (pdev->dev_test_mode == 1U)
|
||||||
{
|
{
|
||||||
USBD_RunTestMode(pdev);
|
(void)USBD_RunTestMode(pdev);
|
||||||
pdev->dev_test_mode = 0U;
|
pdev->dev_test_mode = 0U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if((pdev->pClass->DataIn != NULL) &&
|
|
||||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
|
||||||
{
|
|
||||||
pdev->pClass->DataIn(pdev, epnum);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* should never be in this condition */
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
return USBD_FAIL;
|
{
|
||||||
|
if (pdev->pClass->DataIn != NULL)
|
||||||
|
{
|
||||||
|
ret = (USBD_StatusTypeDef)pdev->pClass->DataIn(pdev, epnum);
|
||||||
|
|
||||||
|
if (ret != USBD_OK)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_LL_Reset
|
* @brief USBD_LL_Reset
|
||||||
* Handle Reset event
|
* Handle Reset event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
/* 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->pClass == NULL)
|
||||||
|
{
|
||||||
|
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 */
|
/* Open EP0 OUT */
|
||||||
USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
(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[0x00U & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE;
|
pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||||
|
|
||||||
/* Open EP0 IN */
|
/* Open EP0 IN */
|
||||||
USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
(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[0x80U & 0xFU].is_used = 1U;
|
||||||
|
|
||||||
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
|
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)
|
|
||||||
{
|
|
||||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_LL_Reset
|
* @brief USBD_LL_SetSpeed
|
||||||
* Handle Reset event
|
* Handle Reset event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed)
|
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev,
|
||||||
|
USBD_SpeedTypeDef speed)
|
||||||
{
|
{
|
||||||
pdev->dev_speed = speed;
|
pdev->dev_speed = speed;
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_Suspend
|
* @brief USBD_LL_Suspend
|
||||||
* Handle Suspend event
|
* Handle Suspend event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
pdev->dev_old_state = pdev->dev_state;
|
pdev->dev_old_state = pdev->dev_state;
|
||||||
pdev->dev_state = USBD_STATE_SUSPENDED;
|
pdev->dev_state = USBD_STATE_SUSPENDED;
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_Resume
|
* @brief USBD_LL_Resume
|
||||||
* Handle Resume event
|
* Handle Resume event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
|
if (pdev->dev_state == USBD_STATE_SUSPENDED)
|
||||||
|
{
|
||||||
pdev->dev_state = pdev->dev_old_state;
|
pdev->dev_state = pdev->dev_old_state;
|
||||||
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_SOF
|
* @brief USBD_LL_SOF
|
||||||
* Handle SOF event
|
* Handle SOF event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
if(pdev->dev_state == USBD_STATE_CONFIGURED)
|
if (pdev->pClass == NULL)
|
||||||
{
|
{
|
||||||
if(pdev->pClass->SOF != NULL)
|
return USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
{
|
{
|
||||||
pdev->pClass->SOF(pdev);
|
if (pdev->pClass->SOF != NULL)
|
||||||
|
{
|
||||||
|
(void)pdev->pClass->SOF(pdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_IsoINIncomplete
|
* @brief USBD_LL_IsoINIncomplete
|
||||||
* Handle iso in incomplete event
|
* Handle iso in incomplete event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
/* Prevent unused arguments compilation warning */
|
if (pdev->pClass == NULL)
|
||||||
UNUSED(pdev);
|
{
|
||||||
UNUSED(epnum);
|
return USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
|
{
|
||||||
|
if (pdev->pClass->IsoINIncomplete != NULL)
|
||||||
|
{
|
||||||
|
(void)pdev->pClass->IsoINIncomplete(pdev, epnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_IsoOUTIncomplete
|
* @brief USBD_LL_IsoOUTIncomplete
|
||||||
* Handle iso out incomplete event
|
* Handle iso out incomplete event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev,
|
||||||
|
uint8_t epnum)
|
||||||
{
|
{
|
||||||
/* Prevent unused arguments compilation warning */
|
if (pdev->pClass == NULL)
|
||||||
UNUSED(pdev);
|
{
|
||||||
UNUSED(epnum);
|
return USBD_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||||
|
{
|
||||||
|
if (pdev->pClass->IsoOUTIncomplete != NULL)
|
||||||
|
{
|
||||||
|
(void)pdev->pClass->IsoOUTIncomplete(pdev, epnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_DevConnected
|
* @brief USBD_LL_DevConnected
|
||||||
* Handle device connection event
|
* Handle device connection event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Prevent unused argument compilation warning */
|
/* Prevent unused argument compilation warning */
|
||||||
@@ -567,32 +659,36 @@ USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_DevDisconnected
|
* @brief USBD_LL_DevDisconnected
|
||||||
* Handle device disconnection event
|
* Handle device disconnection event
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Free Class Resources */
|
/* Free Class Resources */
|
||||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
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;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,8 +3,8 @@
|
|||||||
* @file usbd_desc_template.c
|
* @file usbd_desc_template.c
|
||||||
* @author MCD Application Team
|
* @author MCD Application Team
|
||||||
* @brief This file provides the USBD descriptors and string formatting method.
|
* @brief This file provides the USBD descriptors and string formatting method.
|
||||||
* This template should be copied to the user folder, renamed and customized
|
* This template should be copied to the user folder,
|
||||||
* following user needs.
|
* renamed and customized following user needs.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -41,17 +41,23 @@
|
|||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
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_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||||
#ifdef USB_SUPPORT_USER_STRING_DESC
|
|
||||||
uint8_t *USBD_Class_USRStringDesc (USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
#if (USBD_CLASS_USER_STRING_DESC == 1)
|
||||||
#endif /* USB_SUPPORT_USER_STRING_DESC */
|
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 ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
USBD_DescriptorsTypeDef Class_Desc = {
|
USBD_DescriptorsTypeDef Class_Desc =
|
||||||
|
{
|
||||||
USBD_Class_DeviceDescriptor,
|
USBD_Class_DeviceDescriptor,
|
||||||
USBD_Class_LangIDStrDescriptor,
|
USBD_Class_LangIDStrDescriptor,
|
||||||
USBD_Class_ManufacturerStrDescriptor,
|
USBD_Class_ManufacturerStrDescriptor,
|
||||||
@@ -59,16 +65,29 @@ USBD_DescriptorsTypeDef Class_Desc = {
|
|||||||
USBD_Class_SerialStrDescriptor,
|
USBD_Class_SerialStrDescriptor,
|
||||||
USBD_Class_ConfigStrDescriptor,
|
USBD_Class_ConfigStrDescriptor,
|
||||||
USBD_Class_InterfaceStrDescriptor,
|
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 */
|
/* USB Standard Device Descriptor */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#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 */
|
0x12, /* bLength */
|
||||||
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
|
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 */
|
0x00, /* bcdUSB */
|
||||||
|
#endif
|
||||||
0x02,
|
0x02,
|
||||||
0x00, /* bDeviceClass */
|
0x00, /* bDeviceClass */
|
||||||
0x00, /* bDeviceSubClass */
|
0x00, /* bDeviceSubClass */
|
||||||
@@ -86,30 +105,146 @@ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {
|
|||||||
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
|
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
|
||||||
}; /* USB_DeviceDescriptor */
|
}; /* 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 <20> first Mode entry
|
||||||
|
1 <20> 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 <20> first Mode entry
|
||||||
|
1 <20> 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 */
|
/* USB Standard Device Descriptor */
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#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_LEN_LANGID_STR_DESC,
|
||||||
USB_DESC_TYPE_STRING,
|
USB_DESC_TYPE_STRING,
|
||||||
LOBYTE(USBD_LANGID_STRING),
|
LOBYTE(USBD_LANGID_STRING),
|
||||||
HIBYTE(USBD_LANGID_STRING),
|
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_SIZ_STRING_SERIAL,
|
||||||
USB_DESC_TYPE_STRING,
|
USB_DESC_TYPE_STRING,
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||||
#pragma data_alignment=4
|
#pragma data_alignment=4
|
||||||
#endif
|
#endif
|
||||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||||
|
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len);
|
static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len);
|
||||||
static void Get_SerialNum(void);
|
static void Get_SerialNum(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,8 +255,10 @@ static void Get_SerialNum(void);
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
|
||||||
*length = sizeof(USBD_DeviceDesc);
|
*length = sizeof(USBD_DeviceDesc);
|
||||||
return (uint8_t*)USBD_DeviceDesc;
|
return (uint8_t *)USBD_DeviceDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,8 +269,10 @@ uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
|
||||||
*length = sizeof(USBD_LangIDDesc);
|
*length = sizeof(USBD_LangIDDesc);
|
||||||
return (uint8_t*)USBD_LangIDDesc;
|
return (uint8_t *)USBD_LangIDDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,7 +283,7 @@ uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
if(speed == USBD_SPEED_HIGH)
|
if (speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
@@ -163,6 +302,8 @@ uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *leng
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
|
||||||
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||||
return USBD_StrDesc;
|
return USBD_StrDesc;
|
||||||
}
|
}
|
||||||
@@ -175,12 +316,14 @@ uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
|
||||||
*length = USB_SIZ_STRING_SERIAL;
|
*length = USB_SIZ_STRING_SERIAL;
|
||||||
|
|
||||||
/* Update the serial number string descriptor with the data from the unique ID*/
|
/* Update the serial number string descriptor with the data from the unique ID*/
|
||||||
Get_SerialNum();
|
Get_SerialNum();
|
||||||
|
|
||||||
return (uint8_t*)USBD_StringSerial;
|
return (uint8_t *)USBD_StringSerial;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -191,7 +334,7 @@ uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
if(speed == USBD_SPEED_HIGH)
|
if (speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
@@ -210,7 +353,7 @@ uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
if(speed == USBD_SPEED_HIGH)
|
if (speed == USBD_SPEED_HIGH)
|
||||||
{
|
{
|
||||||
USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
|
USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
|
||||||
}
|
}
|
||||||
@@ -230,19 +373,53 @@ static void Get_SerialNum(void)
|
|||||||
{
|
{
|
||||||
uint32_t deviceserial0, deviceserial1, deviceserial2;
|
uint32_t deviceserial0, deviceserial1, deviceserial2;
|
||||||
|
|
||||||
deviceserial0 = *(uint32_t*)DEVICE_ID1;
|
deviceserial0 = *(uint32_t *)DEVICE_ID1;
|
||||||
deviceserial1 = *(uint32_t*)DEVICE_ID2;
|
deviceserial1 = *(uint32_t *)DEVICE_ID2;
|
||||||
deviceserial2 = *(uint32_t*)DEVICE_ID3;
|
deviceserial2 = *(uint32_t *)DEVICE_ID3;
|
||||||
|
|
||||||
deviceserial0 += deviceserial2;
|
deviceserial0 += deviceserial2;
|
||||||
|
|
||||||
if (deviceserial0 != 0)
|
if (deviceserial0 != 0U)
|
||||||
{
|
{
|
||||||
IntToUnicode (deviceserial0, &USBD_StringSerial[2] ,8);
|
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8U);
|
||||||
IntToUnicode (deviceserial1, &USBD_StringSerial[18] ,4);
|
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4U);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
* @brief Convert Hex 32Bits value into char
|
||||||
* @param value: value to convert
|
* @param value: value to convert
|
||||||
@@ -250,24 +427,24 @@ static void Get_SerialNum(void)
|
|||||||
* @param len: buffer length
|
* @param len: buffer length
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len)
|
static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len)
|
||||||
{
|
{
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0U;
|
||||||
|
|
||||||
for( idx = 0 ; idx < len ; idx ++)
|
for (idx = 0U ; idx < len ; idx ++)
|
||||||
{
|
{
|
||||||
if( ((value >> 28)) < 0xA )
|
if (((value >> 28)) < 0xAU)
|
||||||
{
|
{
|
||||||
pbuf[ 2* idx] = (value >> 28) + '0';
|
pbuf[ 2U * idx] = (value >> 28) + '0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pbuf[2* idx] = (value >> 28) + 'A' - 10;
|
pbuf[2U * idx] = (value >> 28) + 'A' - 10U;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = value << 4;
|
value = value << 4;
|
||||||
|
|
||||||
pbuf[ 2* idx + 1] = 0;
|
pbuf[2U * idx + 1] = 0U;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* This software component is licensed by ST under Ultimate Liberty license
|
* This software component is licensed by ST under Ultimate Liberty license
|
||||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at:
|
* the License. You may obtain a copy of the License at:
|
||||||
* http://www.st.com/SLA0044
|
* www.st.com/SLA0044
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
@@ -77,124 +77,134 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CtlSendData
|
* @brief USBD_CtlSendData
|
||||||
* send data on the ctl pipe
|
* send data on the ctl pipe
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param buff: pointer to data buffer
|
* @param buff: pointer to data buffer
|
||||||
* @param len: length of data to be sent
|
* @param len: length of data to be sent
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||||
uint16_t len)
|
uint8_t *pbuf, uint32_t len)
|
||||||
{
|
{
|
||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_DATA_IN;
|
pdev->ep0_state = USBD_EP0_DATA_IN;
|
||||||
pdev->ep_in[0].total_length = len;
|
pdev->ep_in[0].total_length = len;
|
||||||
|
|
||||||
|
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||||
|
pdev->ep_in[0].rem_length = 0U;
|
||||||
|
#else
|
||||||
pdev->ep_in[0].rem_length = len;
|
pdev->ep_in[0].rem_length = len;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Start the transfer */
|
/* Start the transfer */
|
||||||
USBD_LL_Transmit (pdev, 0x00U, pbuf, len);
|
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CtlContinueSendData
|
* @brief USBD_CtlContinueSendData
|
||||||
* continue sending data on the ctl pipe
|
* continue sending data on the ctl pipe
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param buff: pointer to data buffer
|
* @param buff: pointer to data buffer
|
||||||
* @param len: length of data to be sent
|
* @param len: length of data to be sent
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev,
|
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||||
uint8_t *pbuf, uint16_t len)
|
uint8_t *pbuf, uint32_t len)
|
||||||
{
|
{
|
||||||
/* Start the next transfer */
|
/* Start the next transfer */
|
||||||
USBD_LL_Transmit (pdev, 0x00U, pbuf, len);
|
(void)USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CtlPrepareRx
|
* @brief USBD_CtlPrepareRx
|
||||||
* receive data on the ctl pipe
|
* receive data on the ctl pipe
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param buff: pointer to data buffer
|
* @param buff: pointer to data buffer
|
||||||
* @param len: length of data to be received
|
* @param len: length of data to be received
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||||
uint16_t len)
|
uint8_t *pbuf, uint32_t len)
|
||||||
{
|
{
|
||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
||||||
pdev->ep_out[0].total_length = len;
|
pdev->ep_out[0].total_length = len;
|
||||||
|
|
||||||
|
#ifdef USBD_AVOID_PACKET_SPLIT_MPS
|
||||||
|
pdev->ep_out[0].rem_length = 0U;
|
||||||
|
#else
|
||||||
pdev->ep_out[0].rem_length = len;
|
pdev->ep_out[0].rem_length = len;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Start the transfer */
|
/* Start the transfer */
|
||||||
USBD_LL_PrepareReceive (pdev, 0U, pbuf, len);
|
(void)USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CtlContinueRx
|
* @brief USBD_CtlContinueRx
|
||||||
* continue receive data on the ctl pipe
|
* continue receive data on the ctl pipe
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param buff: pointer to data buffer
|
* @param buff: pointer to data buffer
|
||||||
* @param len: length of data to be received
|
* @param len: length of data to be received
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf,
|
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||||
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;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CtlSendStatus
|
* @brief USBD_CtlSendStatus
|
||||||
* send zero lzngth packet on the ctl pipe
|
* send zero lzngth packet on the ctl pipe
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
||||||
|
|
||||||
/* Start the transfer */
|
/* Start the transfer */
|
||||||
USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
|
(void)USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_CtlReceiveStatus
|
* @brief USBD_CtlReceiveStatus
|
||||||
* receive zero lzngth packet on the ctl pipe
|
* receive zero lzngth packet on the ctl pipe
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @retval status
|
* @retval status
|
||||||
*/
|
*/
|
||||||
USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev)
|
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev)
|
||||||
{
|
{
|
||||||
/* Set EP0 State */
|
/* Set EP0 State */
|
||||||
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
||||||
|
|
||||||
/* Start the transfer */
|
/* Start the transfer */
|
||||||
USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U);
|
(void)USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief USBD_GetRxCount
|
* @brief USBD_GetRxCount
|
||||||
* returns the received data length
|
* returns the received data length
|
||||||
* @param pdev: device instance
|
* @param pdev: device instance
|
||||||
* @param ep_addr: endpoint address
|
* @param ep_addr: endpoint address
|
||||||
* @retval Rx Data blength
|
* @retval Rx Data blength
|
||||||
*/
|
*/
|
||||||
uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
||||||
}
|
}
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -29,19 +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).
|
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))
|
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
If you have any issue with the **software content** of this repository, you can file an issue [here](https://github.com/STMicroelectronics/stm32_mw_usb_device/issues/new/choose).
|
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).
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||||
<link rel="File-List" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/filelist.xml">
|
<link rel="File-List" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/filelist.xml">
|
||||||
<link rel="Edit-Time-Data" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/editdata.mso"><!--[if !mso]>
|
<link rel="Edit-Time-Data" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/editdata.mso"><!--[if !mso]>
|
||||||
@@ -891,8 +893,7 @@ ul
|
|||||||
</xml><![endif]--><!--[if gte mso 9]><xml>
|
</xml><![endif]--><!--[if gte mso 9]><xml>
|
||||||
<o:shapelayout v:ext="edit">
|
<o:shapelayout v:ext="edit">
|
||||||
<o:idmap v:ext="edit" data="1"/>
|
<o:idmap v:ext="edit" data="1"/>
|
||||||
</o:shapelayout></xml><![endif]--><meta content="MCD Application Team" name="author"></head>
|
</o:shapelayout></xml><![endif]--><meta content="MCD Application Team" name="author"></head><body style="" link="blue" vlink="blue">
|
||||||
<body style="" link="blue" vlink="blue">
|
|
||||||
|
|
||||||
<div class="WordSection1">
|
<div class="WordSection1">
|
||||||
|
|
||||||
@@ -920,10 +921,148 @@ ul
|
|||||||
</tbody></table>
|
</tbody></table>
|
||||||
<p class="MsoNormal"><span style="font-family: "Arial","sans-serif"; display: none;"><o:p> </o:p></span></p>
|
<p class="MsoNormal"><span style="font-family: "Arial","sans-serif"; display: none;"><o:p> </o:p></span></p>
|
||||||
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900">
|
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900">
|
||||||
<tbody><tr style="">
|
<tbody><tr>
|
||||||
<td style="padding: 0in;" valign="top">
|
<td style="padding: 0in;" valign="top">
|
||||||
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">Update History</span></h2>
|
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">Update History</span></h2>
|
||||||
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.2 / 27-Mars-2019</span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
|
||||||
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.7.1 / 18-August-2020</span></h3>
|
||||||
|
<b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
|
Changes<br>
|
||||||
|
</span></u></b>
|
||||||
|
<ul style="margin-top: 0cm;" type="square">
|
||||||
|
<li>USB All Class:</li>
|
||||||
|
<ul>
|
||||||
|
<li>Add NULL pointer access check to Class handler<br>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.7.0 / 12-August-2020</span></h3>
|
||||||
|
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
|
Changes</span></u></b></p><ul style="margin-top: 0cm;" type="square"><li>Integration of new USB device Class driver:</li><ul><li>USB video Class driver based on USB-IF video class definition version 1.1</li></ul></ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<ul style="margin-top: 0cm;" type="square"><li>USB Core:</li><ul><li>Enhance NULL pointer check in Core APIs</li><li>Allow supporting both USER and USER Class string desc</li><li>Add support of USB controller which handles packet-size splitting by hardware</li><li>Avoid compilation warning due macro redefinition</li><li>change
|
||||||
|
added to USBD_HandleTypeDef structure: dev_state, old_dev_state and
|
||||||
|
ep0_state declaration become volatile to disable compiler optimization</li><li>Word spelling correction and file indentation improved</li><li>usbd_conf.h/c Template file updated to suggest using by default a static memory allocation for Class handler</li></ul></ul><ul style="margin-top: 0cm;" type="square"><li>USB All Classes</li><ul><li>Word spelling correction and file indentation improved</li><li>Allow updating device config descriptor Max power from user code usbd_conf.h using USBD_MAX_POWER define</li><li>Fix device config descriptor bmAttributes value which depends on user code define USBD_SELF_POWERED</li></ul></ul><ul style="margin-top: 0cm;" type="square"><li>USB CDC Class:</li><ul><li>Class specific request, add protection to limit the maximum data length to be sent by the CDC device</li></ul></ul><ul style="margin-top: 0cm;" type="square"><li>USB CustomHID Class:</li><ul><li>Allow changing CustomHID data EP size from user code </li></ul></ul>
|
||||||
|
<br><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.6.1 / 05-June-2020</span></h3>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
|
Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; color: black;"><o:p></o:p></span></u></p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<ul style="margin-top: 0cm;" type="square">
|
||||||
|
<li>USB Core:</li>
|
||||||
|
<ul>
|
||||||
|
<li>minor rework on USBD_Init() USBD_DeInit()</li>
|
||||||
|
<li>Fix warning issue with Keil due to missing return value of setup API<br>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<li>USB CDC Class:</li>
|
||||||
|
<ul>
|
||||||
|
<li>Fix file indentation</li>
|
||||||
|
<li>Avoid accessing to NULL pointer in case
|
||||||
|
TransmitCplt() user fops is not defined to allow application
|
||||||
|
compatibility with device library version below v2.6.0<br>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
|
<ul style="margin-top: 0cm;" type="square">
|
||||||
|
<li>Fix minor misra-c 2012 violations</li>
|
||||||
|
</ul>
|
||||||
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.6.0 / 27-December-2019</span></h3>
|
||||||
|
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
|
Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; color: black;"><o:p></o:p></span></u></p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<ul style="margin-top: 0cm;" type="square"><li>Integration of three new USB device Class drivers:</li><ul><li>USB CDC ECM Class driver</li><li>USB CDC RNDIS Microsoft Class driver</li><li>USB Billboard Class driver</li></ul><li>Fix mandatory misra-c 2012 violations</li><li>update user core and class template files</li><li>USB Core:</li><ul><li>Fix unexpected EP0 stall during enumeration phase </li><li>Improve APIs error management and prevent accessing NULL pointers</li></ul><li>USB MSC Class:</li><ul><li>Fix USBCV specific class tests</li><li>Fix multiple error with SCSI commands handling</li><li>Protect medium access when host ask for medium ejection</li></ul><li>USB CDC Class:</li><ul><li>Add new function to inform user that current IN transfer is completed</li><li>update transmit and receive APIs to transfer up to 64KB</li></ul></ul><ul style="margin-top: 0cm;" type="square"><li>USB AUDIO Class:</li><ul><li>Fix audio sync start buffer size</li><li>update user callback periodicTC args by adding pointer to user buffer and size</li></ul><li>USB CustomHID Class:</li><ul><li>Rework the OUT transfer complete and prevent automatically re-enabling the OUT EP </li><li>Add new user API to restart the OUT transfer: USBD_CUSTOM_HID_ReceivePacket()</li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.3 / 30-April-2019</span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
|
Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; color: black;"><o:p></o:p></span></u></p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<ul style="margin-top: 0cm;" type="square"><li>Fix misra-c 2012 high severity violations</li><li>Core driver:</li><ul><li>protect shared macros __ALIGN_BEGIN, __ALIGN_END with C directive #ifndef</li><li>update Core driver and DFU Class driver to use USBD_SUPPORT_USER_STRING_DESC instead of USBD_SUPPORT_USER_STRING</li><li> prevent accessing to NULL pointer if the get descriptor functions are not defined</li><li>Update on USBD_LL_Resume(), restore the device state only if the current state is USBD_STATE_SUSPENDED </li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.2 / 27-Mars-2019</span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; color: black;"><o:p></o:p></span></u></p>
|
Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; color: black;"><o:p></o:p></span></u></p>
|
||||||
|
|
||||||
|
|
||||||
@@ -947,7 +1086,7 @@ Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; col
|
|||||||
|
|
||||||
|
|
||||||
<ul style="margin-top: 0cm;" type="square"><li><span style="font-family: Verdana; font-size: 10pt;">DFU Class:</span></li><ul><li><span style="font-family: Verdana; font-size: 10pt;"></span><span style="font-size: 10pt; font-family: "Verdana",sans-serif;" lang="EN-US"></span><span style="font-family: Verdana; font-size: 10pt;"></span>fix compilation warning due to <span style="font-size: 11pt; font-family: "Calibri",sans-serif;" lang="EN-US">unreachable
|
<ul style="margin-top: 0cm;" type="square"><li><span style="font-family: Verdana; font-size: 10pt;">DFU Class:</span></li><ul><li><span style="font-family: Verdana; font-size: 10pt;"></span><span style="font-size: 10pt; font-family: "Verdana",sans-serif;" lang="EN-US"></span><span style="font-family: Verdana; font-size: 10pt;"></span>fix compilation warning due to <span style="font-size: 11pt; font-family: "Calibri",sans-serif;" lang="EN-US">unreachable
|
||||||
</span> instruction code introduced with CMSIS V5.4.0 NVIC_SystemReset() prototype change</li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.1 / 03-August-2018<br>
|
</span> instruction code introduced with CMSIS V5.4.0 NVIC_SystemReset() prototype change</li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.1 / 03-August-2018<br>
|
||||||
</span></h3>
|
</span></h3>
|
||||||
|
|
||||||
|
|
||||||
@@ -989,7 +1128,7 @@ Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; col
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ul style="margin-top: 0cm;" type="square"><li><span style="font-size: 10pt; font-family: Verdana;">Update license section by adding path to get copy of ST Ultimate Liberty license</span></li><li><span style="font-family: Verdana; font-size: 10pt;">Core: Fix unexpected stall during status OUT phase</span></li><li><span style="font-family: Verdana; font-size: 10pt;">DFU Class:</span></li><ul><li><span style="font-family: Verdana; font-size: 10pt;">rework hdfu struct to prevent </span><span style="font-size: 10pt; font-family: "Verdana",sans-serif;" lang="EN-US">unaligned </span><span style="font-family: Verdana; font-size: 10pt;"> addresses</span></li></ul><li>MSC Class:</li><ul><li>fix lba address overflow during large file transfers > 4Go</li></ul><li>Template Class:</li><ul><li>add missing Switch case Break on USBD_Template_Setup API</li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.0 / 15-December-2017<br>
|
<ul style="margin-top: 0cm;" type="square"><li><span style="font-size: 10pt; font-family: Verdana;">Update license section by adding path to get copy of ST Ultimate Liberty license</span></li><li><span style="font-family: Verdana; font-size: 10pt;">Core: Fix unexpected stall during status OUT phase</span></li><li><span style="font-family: Verdana; font-size: 10pt;">DFU Class:</span></li><ul><li><span style="font-family: Verdana; font-size: 10pt;">rework hdfu struct to prevent </span><span style="font-size: 10pt; font-family: "Verdana",sans-serif;" lang="EN-US">unaligned </span><span style="font-family: Verdana; font-size: 10pt;"> addresses</span></li></ul><li>MSC Class:</li><ul><li>fix lba address overflow during large file transfers > 4Go</li></ul><li>Template Class:</li><ul><li>add missing Switch case Break on USBD_Template_Setup API</li></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.5.0 / 15-December-2017<br>
|
||||||
</span></h3>
|
</span></h3>
|
||||||
|
|
||||||
|
|
||||||
@@ -1031,7 +1170,7 @@ Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; col
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ul style="margin-top: 0cm;" type="square"><li><span style="font-size: 10pt; font-family: Verdana;">Update license section</span></li><li><span style="font-family: Verdana; font-size: 10pt;">Update</span><span style="font-size: 10pt; font-family: Verdana;"> some functions to be </span><span style="font-size: 10pt; font-family: Verdana;">MISRAC 2004</span><span style="font-size: 10pt; font-family: Verdana;"> compliant</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Add HS and OtherSpeed configuration descriptor for HID and CustomHID classes</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Correct error handling in all class setup function</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Add usbd_desc_template.c/ usbd_desc_template.h templates files</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Add support of class and vendor request<br></span></li><li><span style="font-family: Verdana; font-size: 10pt;">CDC Class: </span><span style="font-family: Verdana; font-size: 10pt;">fix zero-length packet issue in bulk IN transfer</span></li><li><span style="font-family: Verdana; font-size: 10pt;">Fix compilation warning with unused arguments for some functions</span></li><li><span style="font-family: Verdana; font-size: 10pt;">Improve USB Core enumeration state machine<br></span></li></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.4.2 / 11-December-2015<br>
|
<ul style="margin-top: 0cm;" type="square"><li><span style="font-size: 10pt; font-family: Verdana;">Update license section</span></li><li><span style="font-family: Verdana; font-size: 10pt;">Update</span><span style="font-size: 10pt; font-family: Verdana;"> some functions to be </span><span style="font-size: 10pt; font-family: Verdana;">MISRAC 2004</span><span style="font-size: 10pt; font-family: Verdana;"> compliant</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Add HS and OtherSpeed configuration descriptor for HID and CustomHID classes</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Correct error handling in all class setup function</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Add usbd_desc_template.c/ usbd_desc_template.h templates files</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Add support of class and vendor request<br></span></li><li><span style="font-family: Verdana; font-size: 10pt;">CDC Class: </span><span style="font-family: Verdana; font-size: 10pt;">fix zero-length packet issue in bulk IN transfer</span></li><li><span style="font-family: Verdana; font-size: 10pt;">Fix compilation warning with unused arguments for some functions</span></li><li><span style="font-family: Verdana; font-size: 10pt;">Improve USB Core enumeration state machine<br></span></li></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.4.2 / 11-December-2015<br>
|
||||||
</span></h3>
|
</span></h3>
|
||||||
|
|
||||||
|
|
||||||
@@ -1078,7 +1217,7 @@ Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; col
|
|||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.4.1 / 19-June-2015<br>
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.4.1 / 19-June-2015<br>
|
||||||
</span></h3>
|
</span></h3>
|
||||||
|
|
||||||
|
|
||||||
@@ -1137,7 +1276,7 @@ Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; col
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.4.0 / 28-February-2015<br>
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.4.0 / 28-February-2015<br>
|
||||||
</span></h3>
|
</span></h3>
|
||||||
|
|
||||||
|
|
||||||
@@ -1187,7 +1326,7 @@ USBD_CDC_Setup() function to allow correct user implementation of
|
|||||||
CDC_SET_CONTROL_LINE_STATE and similar no-data setup requests.<br></span></li></ul></ul>
|
CDC_SET_CONTROL_LINE_STATE and similar no-data setup requests.<br></span></li></ul></ul>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.3.0 / 04-November-2014<br>
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.3.0 / 04-November-2014<br>
|
||||||
</span></h3>
|
</span></h3>
|
||||||
|
|
||||||
|
|
||||||
@@ -1230,7 +1369,7 @@ Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; col
|
|||||||
</ul>
|
</ul>
|
||||||
<li><span style="font-size: 10pt; font-family: Verdana;">Miscellaneous source code comments update</span></li>
|
<li><span style="font-size: 10pt; font-family: Verdana;">Miscellaneous source code comments update</span></li>
|
||||||
</ul>
|
</ul>
|
||||||
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.2.0 / 13-June-2014</span></h3>
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.2.0 / 13-June-2014</span></h3>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1276,7 +1415,7 @@ Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; col
|
|||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
<div style="margin-left: 80px;"><span style="font-size: 10pt; font-family: Verdana;">ex. for the HID, the <span style="font-style: italic;">USBD_HID_CLASS</span> macro is defined this way </span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">#define USBD_HID_CLASS &USBD_HID</span></span><br> <span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;">and the application code can use the previous definition: <span style="font-style: italic;">&USBD_HID</span> ex. <span style="font-style: italic;">USBD_RegisterClass(&USBD_Device, &USBD_HID)</span> or the new <span style="font-style: italic;">USBD_HID_CLASS</span> ex. <span style="font-style: italic;">USBD_RegisterClass(&USBD_Device, USBD_HID_CLASS)</span></span></div>
|
<div style="margin-left: 80px;"><span style="font-size: 10pt; font-family: Verdana;">ex. for the HID, the <span style="font-style: italic;">USBD_HID_CLASS</span> macro is defined this way </span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">#define USBD_HID_CLASS &USBD_HID</span></span><br> <span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;">and the application code can use the previous definition: <span style="font-style: italic;">&USBD_HID</span> ex. <span style="font-style: italic;">USBD_RegisterClass(&USBD_Device, &USBD_HID)</span> or the new <span style="font-style: italic;">USBD_HID_CLASS</span> ex. <span style="font-style: italic;">USBD_RegisterClass(&USBD_Device, USBD_HID_CLASS)</span></span></div>
|
||||||
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.1.0 / 22-April-2014</span></h3>
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.1.0 / 22-April-2014</span></h3>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1314,7 +1453,7 @@ Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; col
|
|||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.0.0 / 18-February-2014</span></h3>
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 180px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V2.0.0 / 18-February-2014</span></h3>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1339,14 +1478,14 @@ modified vs. V1.1.0, and thus the 2 versions are not compatible.<br>
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 200px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.1.0 / 19-March-2012<o:p></o:p></span></h3>
|
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 200px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.1.0 / 19-March-2012<o:p></o:p></span></h3>
|
||||||
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
Changes<o:p></o:p></span></u></b></p>
|
Changes<o:p></o:p></span></u></b></p>
|
||||||
|
|
||||||
<ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Official support of </span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-weight: bold; font-style: italic;">STM32F4xx</span> devices</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">All source files: license disclaimer text update and add link to the License file on ST Internet.<br></span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle test mode in the set feature request</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle dynamically the USB SELF POWERED feature</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle correctly the USBD_CtlError process to take into account error during Control OUT stage</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Miscellaneous bug fix</span></li></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 171px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0 / 22-July-2011<o:p></o:p></span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
<ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Official support of </span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-weight: bold; font-style: italic;">STM32F4xx</span> devices</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">All source files: license disclaimer text update and add link to the License file on ST Internet.<br></span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle test mode in the set feature request</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle dynamically the USB SELF POWERED feature</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle correctly the USBD_CtlError process to take into account error during Control OUT stage</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Miscellaneous bug fix</span></li></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 171px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0 / 22-July-2011<o:p></o:p></span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
|
||||||
Changes<o:p></o:p></span></u></b></p>
|
Changes<o:p></o:p></span></u></b></p>
|
||||||
<ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">First official version for <span style="font-weight: bold; font-style: italic;">STM32F105/7xx</span> and <span style="font-weight: bold; font-style: italic;">STM32F2xx</span> devices</span></li></ul><span style="font-size: 10pt; font-family: Verdana;"></span><br><span style="font-size: 10pt; font-family: "Verdana","sans-serif";"></span>
|
<ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">First official version for <span style="font-weight: bold; font-style: italic;">STM32F105/7xx</span> and <span style="font-weight: bold; font-style: italic;">STM32F2xx</span> devices</span></li></ul><span style="font-size: 10pt; font-family: Verdana;"></span><br><span style="font-size: 10pt; font-family: "Verdana","sans-serif";"></span>
|
||||||
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span></h2><p>This
|
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span></h2><p>This
|
||||||
software component is licensed by ST under Ultimate Liberty license
|
software component is licensed by ST under Ultimate Liberty license
|
||||||
SLA0044, the "License"; You may not use this component except in
|
SLA0044, the "License"; You may not use this component except in
|
||||||
compliance with the License. You may obtain a copy of the License at:</p><p style="text-align: center;"><a href="http://www.st.com/SLA0044" target="_blank">http://www.st.com/SLA0044</a></p><p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: "Verdana",sans-serif; color: black;"></span><span style="font-size: 12pt; font-family: "Times New Roman",serif;"><o:p></o:p></span></p>
|
compliance with the License. You may obtain a copy of the License at:</p><p style="text-align: center;"><a href="http://www.st.com/SLA0044" target="_blank">http://www.st.com/SLA0044</a></p><p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: "Verdana",sans-serif; color: black;"></span><span style="font-size: 12pt; font-family: "Times New Roman",serif;"><o:p></o:p></span></p>
|
||||||
|
|||||||
Reference in New Issue
Block a user