资源简介
基于STM32F4Discovery板子的音频示例代码。
代码片段和文件信息
#include “bsp_audio.h“
#include “stm32f4xx_hal.h“
#include “cs43l22.h“
#define I2C_TIMEOUT 100
#define AUDIO_I2C_ADDRESS 0x94
#define AUDIO_OK 0x00
#define AUDIO_ERROR 0x01
#define AUDIO_TIMEOUT 0x02
#define AUDIODATA_SIZE 2
#define DMA_MAX_SZE 0xFFFF
#define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
AUDIO_DrvTypeDef *audio_drv;
extern I2C_HandleTypeDef hi2c1;
extern I2S_HandleTypeDef hi2s3;
//---------------------for c43l22 port--------------------------//
static void I2Cx_Error(uint8_t Addr)
{
/* De-initialize the IOE comunication BUS */
HAL_I2C_DeInit(&hi2c1);
/* Re-Initiaize the IOE comunication BUS */
//I2Cx_Init();
//MX_I2C1_Init();
}
static void CODEC_Reset(void)
{
#if 1
HAL_GPIO_WritePin(AUDIO_RESET_GPIO_Port AUDIO_RESET_Pin GPIO_PIN_RESET);
HAL_Delay(5);
HAL_GPIO_WritePin(AUDIO_RESET_GPIO_Port AUDIO_RESET_Pin GPIO_PIN_SET);
HAL_Delay(5);
#endif
}
void AUDIO_IO_Init(void)
{
//I2Cx_Init();
}
void AUDIO_IO_DeInit(void)
{
}
/**
* @brief Writes a single data.
* @param Addr: I2C address
* @param Reg: Reg address
* @param Value: Data to be written
*/
static void I2Cx_Write(uint8_t Addr uint8_t Reg uint8_t Value)
{
HAL_StatusTypeDef status = HAL_OK;
status = HAL_I2C_Mem_Write(&hi2c1 Addr (uint16_t)Reg I2C_MEMADD_SIZE_8BIT &Value 1 I2C_TIMEOUT);
/* Check the communication status */
if(status != HAL_OK)
{
/* I2C error occured */
I2Cx_Error(Addr);
}
}
void AUDIO_IO_Write(uint8_t Addr uint8_t Reg uint8_t Value)
{
I2Cx_Write(Addr Reg Value);
}
/**
* @brief Reads a single data.
* @param Addr: I2C address
* @param Reg: Reg address
* @retval Data to be read
*/
static uint8_t I2Cx_Read(uint8_t Addr uint8_t Reg)
{
HAL_StatusTypeDef status = HAL_OK;
uint8_t Value = 0;
status = HAL_I2C_Mem_Read(&hi2c1 Addr Reg I2C_MEMADD_SIZE_8BIT &Value 1 I2C_TIMEOUT);
/* Check the communication status */
if(status != HAL_OK)
{
/* Execute user timeout callback */
I2Cx_Error(Addr);
}
return Value;
}
uint8_t AUDIO_IO_Read(uint8_t Addr uint8_t Reg)
{
return I2Cx_Read(Addr Reg);
}
//----------------for usbd_audio_if port--------------------//
static void I2Sx_Init(uint32_t AudioFreq)
{
/* Initialize the haudio_i2s Instance parameter */
hi2s3.Instance = SPI3;
/* Disable I2S block */
__HAL_I2S_DISABLE(&hi2s3);
hi2s3.Init.Mode = I2S_MODE_MASTER_TX;
hi2s3.Init.Standard = I2S_STANDARD;
hi2s3.Init.DataFormat = I2S_DATAFORMAT_16B;
hi2s3.Init.AudioFreq = AudioFreq;
hi2s3.Init.CPOL = I2S_CPOL_LOW;
hi2s3.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
if(HAL_I2S_GetState(&hi2s3) == HAL_I2S_STATE_RESET)
{
HAL_I2S_MspInit(&hi2s3);
}
/* Init the I2S */
HAL_I2S_Init(&hi2s3);
}
const uint32_t I2SFreq[8] = {8000 11025 16000 2205
- 上一篇:MSComm_VS2010
- 下一篇:添加桌面右键菜单(bat实现)
评论
共有 条评论