mirror of
https://github.com/STMicroelectronics/stm32-mw-usb-device.git
synced 2026-02-08 20:18:07 -05:00
Release v2.5.3
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
* ===================================================================
|
||||
* AUDIO Class Description
|
||||
* ===================================================================
|
||||
* This driver manages the Audio Class 1.0 following the "USB Device Class Definition for
|
||||
* This driver manages the Audio Class 1.0 following the "USB Device Class Definition for
|
||||
* Audio Devices V1.0 Mar 18, 98".
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
@@ -48,16 +48,16 @@
|
||||
* 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:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_audio.h"
|
||||
@@ -93,7 +93,7 @@
|
||||
/** @defgroup USBD_AUDIO_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
#define AUDIO_SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
#define AUDIO_SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
|
||||
|
||||
#define AUDIO_PACKET_SZE(frq) (uint8_t)(((frq * 2U * 2U)/1000U) & 0xFFU), \
|
||||
(uint8_t)((((frq * 2U * 2U)/1000U) >> 8) & 0xFFU)
|
||||
@@ -103,42 +103,26 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @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_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_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc (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_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_GetCfgDesc(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_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 void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
/**
|
||||
@@ -316,7 +300,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALI
|
||||
} ;
|
||||
|
||||
/* 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_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
@@ -345,7 +329,7 @@ __ALIGN_BEGIN static uint8_t USBD_AUDIO_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIE
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
static uint8_t USBD_AUDIO_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
|
||||
@@ -354,15 +338,15 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Allocate Audio structure */
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_AUDIO_HandleTypeDef));
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_AUDIO_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
haudio->alt_setting = 0U;
|
||||
haudio->offset = AUDIO_OFFSET_UNKNOWN;
|
||||
haudio->wr_ptr = 0U;
|
||||
@@ -381,6 +365,7 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
USBD_LL_PrepareReceive(pdev, AUDIO_OUT_EP, haudio->buffer,
|
||||
AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
@@ -391,18 +376,17 @@ static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
static uint8_t USBD_AUDIO_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_CloseEP(pdev, AUDIO_OUT_EP);
|
||||
pdev->ep_out[AUDIO_OUT_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* 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);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
@@ -417,8 +401,8 @@ static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev,
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
static uint8_t USBD_AUDIO_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
uint16_t len;
|
||||
@@ -426,96 +410,96 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
||||
uint16_t status_info = 0U;
|
||||
uint8_t ret = USBD_OK;
|
||||
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
AUDIO_REQ_GetCurrent(pdev, req);
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case AUDIO_REQ_GET_CUR:
|
||||
AUDIO_REQ_GetCurrent(pdev, req);
|
||||
break;
|
||||
|
||||
case AUDIO_REQ_SET_CUR:
|
||||
AUDIO_REQ_SetCurrent(pdev, req);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case AUDIO_REQ_SET_CUR:
|
||||
AUDIO_REQ_SetCurrent(pdev, req);
|
||||
break;
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if ((req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_AUDIO_CfgDesc + 18;
|
||||
len = MIN(USB_AUDIO_DESC_SIZ, req->wLength);
|
||||
|
||||
USBD_CtlSendData(pdev, pbuf, len);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&haudio->alt_setting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES)
|
||||
{
|
||||
haudio->alt_setting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if( (req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_AUDIO_CfgDesc + 18;
|
||||
len = MIN(USB_AUDIO_DESC_SIZ , req->wLength);
|
||||
|
||||
USBD_CtlSendData (pdev, pbuf, len);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData (pdev, (uint8_t *)(void *)&haudio->alt_setting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES)
|
||||
{
|
||||
haudio->alt_setting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Call the error management function (command will be nacked */
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -529,9 +513,10 @@ static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev,
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length)
|
||||
static uint8_t *USBD_AUDIO_GetCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_AUDIO_CfgDesc);
|
||||
*length = sizeof(USBD_AUDIO_CfgDesc);
|
||||
|
||||
return USBD_AUDIO_CfgDesc;
|
||||
}
|
||||
|
||||
@@ -542,10 +527,8 @@ static uint8_t *USBD_AUDIO_GetCfgDesc (uint16_t *length)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
/* Only OUT data are processed */
|
||||
return USBD_OK;
|
||||
}
|
||||
@@ -556,17 +539,18 @@ static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev,
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_AUDIO_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
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)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->MuteCtl(haudio->control.data[0]);
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->MuteCtl(haudio->control.data[0]);
|
||||
haudio->control.cmd = 0U;
|
||||
haudio->control.len = 0U;
|
||||
}
|
||||
@@ -580,7 +564,7 @@ static uint8_t USBD_AUDIO_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_AUDIO_EP0_TxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Only OUT control data are processed */
|
||||
return USBD_OK;
|
||||
@@ -591,7 +575,7 @@ static uint8_t USBD_AUDIO_EP0_TxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev)
|
||||
static uint8_t USBD_AUDIO_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
@@ -602,15 +586,15 @@ static uint8_t USBD_AUDIO_SOF (USBD_HandleTypeDef *pdev)
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
void USBD_AUDIO_Sync(USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
{
|
||||
uint32_t cmd = 0U;
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
haudio->offset = offset;
|
||||
|
||||
if(haudio->rd_enable == 1U)
|
||||
if (haudio->rd_enable == 1U)
|
||||
{
|
||||
haudio->rd_ptr += (uint16_t)(AUDIO_TOTAL_BUF_SIZE / 2U);
|
||||
|
||||
@@ -621,15 +605,15 @@ 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -637,25 +621,25 @@ void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(haudio->offset == AUDIO_OFFSET_FULL)
|
||||
if (haudio->offset == AUDIO_OFFSET_FULL)
|
||||
{
|
||||
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->AudioCmd(&haudio->buffer[0],
|
||||
cmd,
|
||||
AUDIO_CMD_PLAY);
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -666,9 +650,8 @@ void USBD_AUDIO_Sync (USBD_HandleTypeDef *pdev, AUDIO_OffsetTypeDef offset)
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
@@ -678,9 +661,8 @@ static uint8_t USBD_AUDIO_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t ep
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
@@ -690,11 +672,10 @@ static uint8_t USBD_AUDIO_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t e
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
static uint8_t USBD_AUDIO_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (epnum == AUDIO_OUT_EP)
|
||||
{
|
||||
@@ -707,16 +688,16 @@ static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
||||
/* All buffers are full: roll back */
|
||||
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],
|
||||
AUDIO_TOTAL_BUF_SIZE / 2U,
|
||||
AUDIO_CMD_START);
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
haudio->offset = AUDIO_OFFSET_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
if(haudio->rd_enable == 0U)
|
||||
if (haudio->rd_enable == 0U)
|
||||
{
|
||||
if (haudio->wr_ptr == (AUDIO_TOTAL_BUF_SIZE / 2U))
|
||||
{
|
||||
@@ -742,12 +723,12 @@ static uint8_t USBD_AUDIO_DataOut (USBD_HandleTypeDef *pdev,
|
||||
static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
memset(haudio->control.data, 0, 64U);
|
||||
|
||||
/* Send the current mute state */
|
||||
USBD_CtlSendData (pdev, haudio->control.data, req->wLength);
|
||||
USBD_CtlSendData(pdev, haudio->control.data, req->wLength);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -760,14 +741,12 @@ static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
||||
static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_AUDIO_HandleTypeDef *haudio;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
|
||||
haudio = (USBD_AUDIO_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (req->wLength)
|
||||
{
|
||||
/* Prepare the reception of the buffer over EP0 */
|
||||
USBD_CtlPrepareRx (pdev,
|
||||
haudio->control.data,
|
||||
req->wLength);
|
||||
USBD_CtlPrepareRx(pdev, haudio->control.data, req->wLength);
|
||||
|
||||
haudio->control.cmd = AUDIO_REQ_SET_CUR; /* Set the request value */
|
||||
haudio->control.len = (uint8_t)req->wLength; /* Set the request data length */
|
||||
@@ -782,9 +761,10 @@ static void AUDIO_REQ_SetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef
|
||||
* @param length : pointer data length
|
||||
* @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 = sizeof(USBD_AUDIO_DeviceQualifierDesc);
|
||||
|
||||
return USBD_AUDIO_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
@@ -793,13 +773,14 @@ static uint8_t *USBD_AUDIO_GetDeviceQualifierDesc (uint16_t *length)
|
||||
* @param fops: Audio interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_AUDIO_RegisterInterface (USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops)
|
||||
uint8_t USBD_AUDIO_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_AUDIO_ItfTypeDef *fops)
|
||||
{
|
||||
if(fops != NULL)
|
||||
if (fops != NULL)
|
||||
{
|
||||
pdev->pUserData= fops;
|
||||
pdev->pUserData = fops;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
* 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:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_audio.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#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_DeInit (uint32_t options);
|
||||
static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd);
|
||||
static int8_t TEMPLATE_VolumeCtl (uint8_t vol);
|
||||
static int8_t TEMPLATE_MuteCtl (uint8_t cmd);
|
||||
static int8_t TEMPLATE_PeriodicTC (uint8_t cmd);
|
||||
static int8_t TEMPLATE_GetState (void);
|
||||
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_AudioCmd(uint8_t *pbuf, uint32_t size, uint8_t cmd);
|
||||
static int8_t TEMPLATE_VolumeCtl(uint8_t vol);
|
||||
static int8_t TEMPLATE_MuteCtl(uint8_t cmd);
|
||||
static int8_t TEMPLATE_PeriodicTC(uint8_t cmd);
|
||||
static int8_t TEMPLATE_GetState(void);
|
||||
|
||||
USBD_AUDIO_ItfTypeDef USBD_AUDIO_Template_fops =
|
||||
{
|
||||
@@ -123,9 +123,8 @@ static int8_t TEMPLATE_DeInit(uint32_t options)
|
||||
* @param cmd: command opcode
|
||||
* @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)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -134,9 +133,8 @@ static int8_t TEMPLATE_AudioCmd (uint8_t* pbuf, uint32_t size, uint8_t cmd)
|
||||
* @param vol: volume level (0..100)
|
||||
* @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)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -145,9 +143,8 @@ static int8_t TEMPLATE_VolumeCtl (uint8_t vol)
|
||||
* @param cmd: vmute command
|
||||
* @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)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -156,9 +153,8 @@ static int8_t TEMPLATE_MuteCtl (uint8_t cmd)
|
||||
* @param cmd
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_PeriodicTC (uint8_t cmd)
|
||||
static int8_t TEMPLATE_PeriodicTC(uint8_t cmd)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -167,9 +163,8 @@ static int8_t TEMPLATE_PeriodicTC (uint8_t cmd)
|
||||
* @param None
|
||||
* @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);
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user