增加采样率可变功能
This commit is contained in:
parent
426ff45d48
commit
2bbb094dd7
@ -6,6 +6,9 @@ SourceFiles=Core\Src\main.c;Core\Src\freertos.c;Core\Src\stm32h7xx_it.c;Core\Src
|
||||
HeaderPath=Drivers\STM32H7xx_HAL_Driver\Inc;Drivers\STM32H7xx_HAL_Driver\Inc\Legacy;Middlewares\Third_Party\FreeRTOS\Source\include;Middlewares\Third_Party\FreeRTOS\Source\CMSIS_RTOS;Middlewares\Third_Party\FreeRTOS\Source\portable\GCC\ARM_CM4F;Drivers\CMSIS\Device\ST\STM32H7xx\Include;Drivers\CMSIS\Include;Core\Inc;
|
||||
CDefines=USE_HAL_DRIVER;STM32H743xx;USE_HAL_DRIVER;USE_HAL_DRIVER;
|
||||
|
||||
[]
|
||||
SourceFiles=;;
|
||||
|
||||
[PreviousGenFiles]
|
||||
AdvancedFolderStructure=true
|
||||
HeaderFileListSize=4
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
if(NOT CMAKE_TOOLCHAIN_FILE)
|
||||
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/CMake/gcc-arm-none-eabi.cmake)
|
||||
@ -43,7 +43,7 @@ add_compile_options(
|
||||
|
||||
# 全局连接器选项
|
||||
add_link_options(
|
||||
-Wl,-wrap,_malloc_r -Wl,-wrap,_free_r -Wl,-wrap,_realloc_r # wrap newlib memory allocator functions
|
||||
-Wl,-wrap,_malloc_r -Wl,-wrap,_free_r -Wl,-wrap,_realloc_r #将newlib所提供的内存管理函数替换为用户自定义的
|
||||
-T${CMAKE_CURRENT_LIST_DIR}/STM32H743IITX_FLASH.ld
|
||||
)
|
||||
|
||||
@ -69,9 +69,9 @@ target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
)
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
hal_driver
|
||||
lvgl
|
||||
lvgl_demos
|
||||
drivers
|
||||
# lvgl
|
||||
# lvgl_demos
|
||||
minimp3
|
||||
tlsf
|
||||
freertos
|
||||
|
||||
@ -73,8 +73,10 @@ void Error_Handler(void);
|
||||
#define KEY1_GPIO_Port GPIOF
|
||||
#define KEY2_Pin GPIO_PIN_7
|
||||
#define KEY2_GPIO_Port GPIOF
|
||||
#define HP_DET_Pin GPIO_PIN_3
|
||||
#define HP_DET_GPIO_Port GPIOC
|
||||
#define CODEC_RST_Pin GPIO_PIN_1
|
||||
#define CODEC_RST_GPIO_Port GPIOC
|
||||
#define CODEC_EN_Pin GPIO_PIN_3
|
||||
#define CODEC_EN_GPIO_Port GPIOC
|
||||
#define LED_B_Pin GPIO_PIN_5
|
||||
#define LED_B_GPIO_Port GPIOA
|
||||
#define LED_G_Pin GPIO_PIN_6
|
||||
|
||||
@ -283,7 +283,7 @@ static void MX_I2C1_Init(void)
|
||||
|
||||
/* USER CODE END I2C1_Init 1 */
|
||||
hi2c1.Instance = I2C1;
|
||||
hi2c1.Init.Timing = 0x307077B2;
|
||||
hi2c1.Init.Timing = 0x00B03FDB;
|
||||
hi2c1.Init.OwnAddress1 = 0;
|
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
@ -298,7 +298,7 @@ static void MX_I2C1_Init(void)
|
||||
|
||||
/** Configure Analogue filter
|
||||
*/
|
||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_DISABLE) != HAL_OK)
|
||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
@ -565,6 +565,9 @@ static void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, CODEC_RST_Pin|CODEC_EN_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, LED_B_Pin|LED_G_Pin, GPIO_PIN_SET);
|
||||
|
||||
@ -625,11 +628,19 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Alternate = GPIO_AF14_LTDC;
|
||||
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : HP_DET_Pin */
|
||||
GPIO_InitStruct.Pin = HP_DET_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
/*Configure GPIO pin : CODEC_RST_Pin */
|
||||
GPIO_InitStruct.Pin = CODEC_RST_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(HP_DET_GPIO_Port, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(CODEC_RST_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : CODEC_EN_Pin */
|
||||
GPIO_InitStruct.Pin = CODEC_EN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(CODEC_EN_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PA2 */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
set(SOURCE_DIRS
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(drivers)
|
||||
|
||||
set(DRIVERS_SOURCE_DIRS
|
||||
"${CMAKE_CURRENT_LIST_DIR}/STM32H7xx_HAL_Driver/Src/*.c"
|
||||
)
|
||||
|
||||
file(GLOB SOURCE_FILES ${SOURCE_DIRS})
|
||||
file(GLOB DRIVERS_SOURCE_FILES ${DRIVERS_SOURCE_DIRS})
|
||||
|
||||
add_library(hal_driver ${SOURCE_FILES})
|
||||
add_library(drivers ${DRIVERS_SOURCE_FILES})
|
||||
|
||||
target_include_directories(hal_driver PUBLIC
|
||||
target_include_directories(drivers PUBLIC
|
||||
"${CMAKE_CURRENT_LIST_DIR}/STM32H7xx_HAL_Driver/Inc"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/STM32H7xx_HAL_Driver/Inc/Legacy"
|
||||
)
|
||||
|
||||
@ -15,6 +15,6 @@ target_include_directories(easylogger PUBLIC
|
||||
)
|
||||
|
||||
target_link_libraries(easylogger PRIVATE
|
||||
hal_driver
|
||||
drivers
|
||||
freertos
|
||||
)
|
||||
|
||||
2
Middlewares/Third_Party/FatFs/CMakeLists.txt
vendored
2
Middlewares/Third_Party/FatFs/CMakeLists.txt
vendored
@ -9,6 +9,6 @@ target_include_directories(fatfs PUBLIC
|
||||
)
|
||||
|
||||
target_link_libraries(fatfs PRIVATE
|
||||
hal_driver
|
||||
drivers
|
||||
freertos
|
||||
)
|
||||
|
||||
@ -15,7 +15,7 @@ get_filename_component(LV_CONF_DIR ${LV_CONF_PATH} DIRECTORY)
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
||||
|
||||
file(GLOB_RECURSE SOURCES ${LVGL_ROOT_DIR}/src/*.c)
|
||||
file(GLOB_RECURSE EXAMPLE_SOURCES ${LVGL_ROOT_DIR}/examples/*.c)
|
||||
# file(GLOB_RECURSE EXAMPLE_SOURCES ${LVGL_ROOT_DIR}/examples/*.c)
|
||||
file(GLOB_RECURSE DEMO_SOURCES ${LVGL_ROOT_DIR}/demos/*.c)
|
||||
|
||||
if (BUILD_SHARED_LIBS)
|
||||
@ -25,8 +25,8 @@ else()
|
||||
endif()
|
||||
|
||||
add_library(lvgl::lvgl ALIAS lvgl)
|
||||
add_library(lvgl_examples STATIC ${EXAMPLE_SOURCES})
|
||||
add_library(lvgl::examples ALIAS lvgl_examples)
|
||||
# add_library(lvgl_examples STATIC ${EXAMPLE_SOURCES})
|
||||
# add_library(lvgl::examples ALIAS lvgl_examples)
|
||||
add_library(lvgl_demos STATIC ${DEMO_SOURCES})
|
||||
add_library(lvgl::demos ALIAS lvgl_demos)
|
||||
|
||||
@ -38,12 +38,12 @@ target_compile_definitions(
|
||||
target_include_directories(lvgl SYSTEM PUBLIC ${LVGL_ROOT_DIR} ${LV_CONF_DIR})
|
||||
|
||||
# Include /examples folder
|
||||
target_include_directories(lvgl_examples SYSTEM
|
||||
PUBLIC ${LVGL_ROOT_DIR}/examples)
|
||||
# target_include_directories(lvgl_examples SYSTEM
|
||||
# PUBLIC ${LVGL_ROOT_DIR}/examples)
|
||||
target_include_directories(lvgl_demos SYSTEM
|
||||
PUBLIC ${LVGL_ROOT_DIR}/demos)
|
||||
|
||||
target_link_libraries(lvgl_examples PUBLIC lvgl)
|
||||
# target_link_libraries(lvgl_examples PUBLIC lvgl)
|
||||
target_link_libraries(lvgl_demos PUBLIC lvgl)
|
||||
|
||||
# Lbrary and headers can be installed to system using make install
|
||||
|
||||
@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
add_library(minimp3 INTERFACE)
|
||||
|
||||
enable_language(C)
|
||||
|
||||
target_include_directories(minimp3 INTERFACE
|
||||
"${CMAKE_CURRENT_LIST_DIR}"
|
||||
)
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#define AUDIO_HAL_SAMPLE_QUEUE_SIZE 3
|
||||
#define AUDIO_HAL_SAMPLE_QUEUE_SIZE 5
|
||||
|
||||
void audio_hal_start(uint32_t sample_count, uint8_t sample_size);
|
||||
void audio_hal_stop(void);
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "queue.h"
|
||||
#include "elog.h"
|
||||
#include "heap.h"
|
||||
#include "bsp_aic3204.h"
|
||||
|
||||
#define MINIMP3_IMPLEMENTATION
|
||||
#include "minimp3.h"
|
||||
@ -86,6 +87,62 @@ void music_mp3_play(const char *file_name)
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET) {
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
static uint8_t samplerate = 0;
|
||||
|
||||
switch (samplerate) {
|
||||
case 0:
|
||||
bsp_aic3204_set_fs(&hi2c1, 8000);
|
||||
break;
|
||||
case 1:
|
||||
bsp_aic3204_set_fs(&hi2c1, 11025);
|
||||
break;
|
||||
case 2:
|
||||
bsp_aic3204_set_fs(&hi2c1, 12000);
|
||||
break;
|
||||
case 3:
|
||||
bsp_aic3204_set_fs(&hi2c1, 16000);
|
||||
break;
|
||||
case 4:
|
||||
bsp_aic3204_set_fs(&hi2c1, 22050);
|
||||
break;
|
||||
case 5:
|
||||
bsp_aic3204_set_fs(&hi2c1, 24000);
|
||||
break;
|
||||
case 6:
|
||||
bsp_aic3204_set_fs(&hi2c1, 32000);
|
||||
break;
|
||||
case 7:
|
||||
bsp_aic3204_set_fs(&hi2c1, 44100);
|
||||
break;
|
||||
case 8:
|
||||
bsp_aic3204_set_fs(&hi2c1, 48000);
|
||||
break;
|
||||
case 9:
|
||||
bsp_aic3204_set_fs(&hi2c1, 88200);
|
||||
break;
|
||||
case 10:
|
||||
bsp_aic3204_set_fs(&hi2c1, 96000);
|
||||
break;
|
||||
case 11:
|
||||
bsp_aic3204_set_fs(&hi2c1, 176400);
|
||||
break;
|
||||
case 12:
|
||||
bsp_aic3204_set_fs(&hi2c1, 192000);
|
||||
break;
|
||||
}
|
||||
|
||||
samplerate ++;
|
||||
if (samplerate >= 13) {
|
||||
samplerate = 0;
|
||||
}
|
||||
|
||||
while (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 关闭文件 */
|
||||
|
||||
224
User/bsp/bsp_aic3204.c
Normal file
224
User/bsp/bsp_aic3204.c
Normal file
@ -0,0 +1,224 @@
|
||||
#include "bsp_aic3204.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "elog.h"
|
||||
|
||||
static const char *TAG = "bsp_aic3204";
|
||||
|
||||
#define BSP_AIC3204_I2C_ADDR 0x30
|
||||
|
||||
HAL_StatusTypeDef bsp_aic3204_write_reg(I2C_HandleTypeDef *hi2c, uint8_t reg_addr, uint8_t reg_value)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_I2C_Mem_Write(hi2c, BSP_AIC3204_I2C_ADDR, reg_addr, 1, ®_value, 1, 100);
|
||||
|
||||
if (status == HAL_OK) {
|
||||
elog_debug(TAG, "write register 0x%02X@0x%02X success", reg_value, reg_addr);
|
||||
} else {
|
||||
elog_error(TAG, "write register 0x%02X@0x%02X failed", reg_value, reg_addr);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef bsp_aic3204_read_reg(I2C_HandleTypeDef *hi2c, uint8_t reg_addr, uint8_t *reg_value_out)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_I2C_Mem_Read(hi2c, BSP_AIC3204_I2C_ADDR, reg_addr, 1, reg_value_out, 1, 10);
|
||||
|
||||
if (status == HAL_OK) {
|
||||
elog_debug(TAG, "read register 0x%02X@0x%02X success", *reg_value_out, reg_addr);
|
||||
} else {
|
||||
elog_error(TAG, "read register @0x%02X failed", reg_addr);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef bsp_aic3204_set_fs(I2C_HandleTypeDef *hi2c, uint32_t fs_hz)
|
||||
{
|
||||
uint16_t n_dac;
|
||||
uint16_t pll_j, pll_d;
|
||||
uint16_t prb_no;
|
||||
|
||||
switch (fs_hz) {
|
||||
case 11025:
|
||||
case 22050:
|
||||
case 44100:
|
||||
case 88200:
|
||||
case 176400:
|
||||
pll_j = 7;
|
||||
pll_d = 3500; //PLL输出的时钟频率CODEC_CLKIN=11.2896MHz*8
|
||||
n_dac = (8 * 4) / (fs_hz / 11025);
|
||||
break;
|
||||
case 12000:
|
||||
case 24000:
|
||||
case 48000:
|
||||
case 96000:
|
||||
case 192000:
|
||||
pll_j = 8;
|
||||
pll_d = 0; //PLL输出的时钟频率CODEC_CLKIN=12.288MHz*8
|
||||
n_dac = (8 * 4) / (fs_hz / 12000);
|
||||
break;
|
||||
case 8000:
|
||||
case 16000:
|
||||
case 32000:
|
||||
pll_j = 8;
|
||||
pll_d = 0; //PLL输出的时钟频率CODEC_CLKIN=12.288MHz*8
|
||||
/* PLL输出的时钟频率CODEC_CLKIN=11.2896MHz*8 */
|
||||
n_dac = (8 * 6) / (fs_hz / 8000);
|
||||
break;
|
||||
default:
|
||||
elog_error(TAG, "bsp_aic3204_set_fs: unsupported sample rate: %dHz", fs_hz);
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (fs_hz <= 48000) {
|
||||
prb_no = 1;
|
||||
} else if (fs_hz <= 96000) {
|
||||
prb_no = 9;
|
||||
} else {
|
||||
prb_no = 19;
|
||||
}
|
||||
|
||||
// 设置PLL_J
|
||||
bsp_aic3204_write_reg(hi2c, 0x06, pll_j);
|
||||
// 设置PLL_D
|
||||
bsp_aic3204_write_reg(hi2c, 0x07, pll_d >> 8);
|
||||
bsp_aic3204_write_reg(hi2c, 0x08, pll_d & 0xFF);
|
||||
// 启动NDAC分频器并设置分频值
|
||||
bsp_aic3204_write_reg(hi2c, 0x0b, 0x80 | n_dac);
|
||||
// 设置DAC信号处理块(PRB)
|
||||
bsp_aic3204_write_reg(hi2c, 0x3C, prb_no);
|
||||
|
||||
elog_info(TAG, "bsp_aic3204_set_fs: sample rate: %dHz, NDAC=%d, PLL J.D=%d.%d", fs_hz, n_dac, pll_j, pll_d);
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef bsp_aic3204_init(I2C_HandleTypeDef *hi2c)
|
||||
{
|
||||
// 选择寄存器页0
|
||||
// bsp_aic3204_write_reg(hi2c, 0x00, 0x00);
|
||||
// 软件复位芯片
|
||||
// bsp_aic3204_write_reg(hi2c, 0x01, 0x01);
|
||||
|
||||
// 硬件复位芯片
|
||||
HAL_GPIO_WritePin(CODEC_RST_GPIO_Port, CODEC_RST_Pin, GPIO_PIN_RESET);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
HAL_GPIO_WritePin(CODEC_RST_GPIO_Port, CODEC_RST_Pin, GPIO_PIN_SET);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
/*
|
||||
* 时钟结构
|
||||
* PLL_CLKIN PLL_CLK /NDAC /MDAC /DOSR
|
||||
* MFP5 -----------> PLL ---------> CODEC_CLKIN -------> DAC_CLK -------> DAC_MOD_CLK -------> DAC_FS
|
||||
* |
|
||||
* -------------> BCLK -----------------------> WCLK
|
||||
* /BDIV_CLKIN /SAMPLE_BITS/CHANNELS
|
||||
*
|
||||
* 举例如下
|
||||
* /1 /2 /128
|
||||
* MFP5 ----> CODEC_CLKIN ----> DAC_CLK ----> DAC_MOD_CLK ------> DAC_FS
|
||||
* 12.288MHz 12.288MHz 6.144MHz 48kHz
|
||||
* |
|
||||
* ----> BCLK -------> WCLK
|
||||
* /8 1.536MHz /16/2 48kHz
|
||||
*
|
||||
* BDIV_CLKIN = MDAC * DOSR / SAMPLE_BITS / CHANNELS
|
||||
*/
|
||||
|
||||
/*
|
||||
uint16_t n_dac = 1;
|
||||
uint16_t m_dac = 2;
|
||||
uint16_t dac_osr = 128;
|
||||
uint16_t bdiv_clkin = m_dac * dac_osr / 16 / 2;
|
||||
|
||||
// 选择寄存器页0
|
||||
bsp_aic3204_write_reg(hi2c, 0x00, 0x00);
|
||||
// MFP5用于时钟输入
|
||||
bsp_aic3204_write_reg(hi2c, 0x34, 0x04);
|
||||
// 选择GPIO输入为Codec主时钟源
|
||||
bsp_aic3204_write_reg(hi2c, 0x04, 0x02);
|
||||
// 启动NDAC分频器并设置分频值为1
|
||||
bsp_aic3204_write_reg(hi2c, 0x0b, 0x80 | n_dac);
|
||||
// 启动MDAC分频器并设置分频值为2
|
||||
bsp_aic3204_write_reg(hi2c, 0x0c, 0x80 | m_dac);
|
||||
// 设置DAC的超采样率(OSR)为128
|
||||
bsp_aic3204_write_reg(hi2c, 0x0d, (dac_osr >> 8) & 0x03);
|
||||
bsp_aic3204_write_reg(hi2c, 0x0e, dac_osr & 0xFF);
|
||||
// 总线类型I2S 数据长度16位 BCLK方向为输出 WCLK方向为输出
|
||||
bsp_aic3204_write_reg(hi2c, 0x1b, 0x0D);
|
||||
// 设置DAC信号处理块(PRB)为PRB_1
|
||||
bsp_aic3204_write_reg(hi2c, 0x3c, 0x01);
|
||||
// 选择DAC_CLK做为BDIV_CLKIN
|
||||
bsp_aic3204_write_reg(hi2c, 0x1D, 0x00);
|
||||
// 启用对外WCLK与BCLK时钟输出 CODEC_CLKIN与BCLK的商为每个采样的大小 即声道数与DAC位数的乘积
|
||||
bsp_aic3204_write_reg(hi2c, 0x1E, 0x80 | bdiv_clkin);
|
||||
*/
|
||||
|
||||
// 选择寄存器页0
|
||||
bsp_aic3204_write_reg(hi2c, 0x00, 0x00);
|
||||
// MFP5用于时钟输入
|
||||
bsp_aic3204_write_reg(hi2c, 0x34, 0x04);
|
||||
// 选择GPIO输入为PLL时钟源 选择PLL输出为Codec主时钟源
|
||||
bsp_aic3204_write_reg(hi2c, 0x04, 0x02 << 2 | 0x03 << 0);
|
||||
// 启动PLL并设置PLL_P=1 PLL_R=1
|
||||
bsp_aic3204_write_reg(hi2c, 0x05, 0x80 | 1 << 4 | 1 << 0);
|
||||
// 设置PLL_J=7
|
||||
bsp_aic3204_write_reg(hi2c, 0x06, 0x07);
|
||||
// 设置PLL_D=3500
|
||||
bsp_aic3204_write_reg(hi2c, 0x07, 3500 >> 8);
|
||||
bsp_aic3204_write_reg(hi2c, 0x08, 3500 & 0xFF);
|
||||
// 启动NDAC分频器并设置分频值为8
|
||||
bsp_aic3204_write_reg(hi2c, 0x0B, 0x80 | 8);
|
||||
// 启动MDAC分频器并设置分频值为2
|
||||
bsp_aic3204_write_reg(hi2c, 0x0C, 0x80 | 2);
|
||||
// 设置DAC的超采样率(OSR)为128
|
||||
bsp_aic3204_write_reg(hi2c, 0x0D, 128 >> 8);
|
||||
bsp_aic3204_write_reg(hi2c, 0x0E, 128 & 0xFF);
|
||||
// 总线类型I2S 数据长度16位 BCLK方向为输出 WCLK方向为输出
|
||||
bsp_aic3204_write_reg(hi2c, 0x1B, 0x0D);
|
||||
// 选择DAC_CLK做为BDIV_CLKIN
|
||||
bsp_aic3204_write_reg(hi2c, 0x1D, 0x00);
|
||||
// 启用对外WCLK与BCLK时钟输出 CODEC_CLKIN与BCLK的商为每个采样的大小 即声道数与DAC位数的乘积
|
||||
bsp_aic3204_write_reg(hi2c, 0x1E, 0x80 | 8);
|
||||
// 设置DAC信号处理块(PRB)为PRB_1
|
||||
bsp_aic3204_write_reg(hi2c, 0x3C, 1);
|
||||
|
||||
// 选择寄存器页1
|
||||
bsp_aic3204_write_reg(hi2c, 0x00, 0x01);
|
||||
// 关闭内部AVDD微供电
|
||||
bsp_aic3204_write_reg(hi2c, 0x01, 0x08);
|
||||
// 内部LDO上电 DVDD=1.72V AVDD=1.72V
|
||||
bsp_aic3204_write_reg(hi2c, 0x02, 0x01);
|
||||
// Set the REF charging time to 40ms
|
||||
bsp_aic3204_write_reg(hi2c, 0x7b, 0x01);
|
||||
// HP soft stepping settings for optimal pop performance at power up
|
||||
// Rpop used is 6k with N = 6 and soft step = 20usec. This should work with 47uF coupling capacitor.
|
||||
// Can try N=5,6 or 7 time constants as well. Trade-off delay vs “pop” sound.
|
||||
bsp_aic3204_write_reg(hi2c, 0x14, 0x25);
|
||||
// Set the Input Common Mode to 0.9V and Output Common Mode for Headphone to Input Common Mode
|
||||
bsp_aic3204_write_reg(hi2c, 0x0A, 0x00);
|
||||
// Route Left DAC to HPL
|
||||
bsp_aic3204_write_reg(hi2c, 0x0c, 0x08);
|
||||
// Route Right DAC to HPR
|
||||
bsp_aic3204_write_reg(hi2c, 0x0d, 0x08);
|
||||
// Set the DAC PTM mode to PTM_P3/4
|
||||
bsp_aic3204_write_reg(hi2c, 0x03, 0x00);
|
||||
bsp_aic3204_write_reg(hi2c, 0x04, 0x00);
|
||||
// Set the HPL gain to 0dB
|
||||
bsp_aic3204_write_reg(hi2c, 0x10, 0x00);
|
||||
// Set the HPR gain to 0dB
|
||||
bsp_aic3204_write_reg(hi2c, 0x11, 0x00);
|
||||
// Power up HPL and HPR drivers
|
||||
bsp_aic3204_write_reg(hi2c, 0x09, 0x30);
|
||||
// Wait for 2.5 sec for soft stepping to take effect
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
||||
// 选择寄存器页0
|
||||
bsp_aic3204_write_reg(hi2c, 0x00, 0x00);
|
||||
// Power up the Left and Right DAC Channels with route the Left Audio digital data to Left Channel DAC and Right Audio digital data to Right Channel DAC
|
||||
bsp_aic3204_write_reg(hi2c, 0x3f, 0xd6);
|
||||
// Unmute the DAC digital volume control
|
||||
bsp_aic3204_write_reg(hi2c, 0x40, 0x00);
|
||||
|
||||
return HAL_OK;
|
||||
}
|
||||
10
User/bsp/bsp_aic3204.h
Normal file
10
User/bsp/bsp_aic3204.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef __BSP_AIC3204_H
|
||||
#define __BSP_AIC3204_H
|
||||
|
||||
#include "main.h"
|
||||
|
||||
HAL_StatusTypeDef bsp_aic3204_init(I2C_HandleTypeDef *hi2c);
|
||||
HAL_StatusTypeDef bsp_aic3204_write_reg(I2C_HandleTypeDef *hi2c, uint8_t reg_addr, uint8_t reg_value);
|
||||
HAL_StatusTypeDef bsp_aic3204_set_fs(I2C_HandleTypeDef *hi2c, uint32_t fs_hz);
|
||||
|
||||
#endif
|
||||
@ -8,7 +8,7 @@
|
||||
#include "main.h"
|
||||
#include "ff.h"
|
||||
#include "audio_player_mp3.h"
|
||||
#include "bsp_wm8904.h"
|
||||
#include "bsp_aic3204.h"
|
||||
// #include "lvgl.h"
|
||||
// #include "lv_demos.h"
|
||||
// #include "lv_port_disp.h"
|
||||
@ -91,27 +91,27 @@ void util_i2c_scan(I2C_HandleTypeDef *hi2c)
|
||||
|
||||
// uint8_t *sdram_ptr = (uint8_t *)SDRAM_BANK_ADDR;
|
||||
|
||||
void codec_init(void)
|
||||
{
|
||||
uint8_t retries = 0;
|
||||
while (1) {
|
||||
if (WM8904_Init(&hi2c1) == HAL_OK) {
|
||||
break;
|
||||
}
|
||||
// void codec_init(void)
|
||||
// {
|
||||
// uint8_t retries = 0;
|
||||
// while (1) {
|
||||
// if (WM8904_Init(&hi2c1) == HAL_OK) {
|
||||
// break;
|
||||
// }
|
||||
|
||||
HAL_I2C_DeInit(&hi2c1);
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
HAL_I2C_Init(&hi2c1);
|
||||
// HAL_I2C_DeInit(&hi2c1);
|
||||
// vTaskDelay(pdMS_TO_TICKS(200));
|
||||
// HAL_I2C_Init(&hi2c1);
|
||||
|
||||
retries ++;
|
||||
if (retries > 10) {
|
||||
elog_assert(TAG, "wm8904 configuration failed");
|
||||
while (1) {
|
||||
vTaskDelay(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// retries ++;
|
||||
// if (retries > 10) {
|
||||
// elog_assert(TAG, "wm8904 configuration failed");
|
||||
// while (1) {
|
||||
// vTaskDelay(1);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
void task_main_entry(void *param)
|
||||
{
|
||||
@ -119,7 +119,7 @@ void task_main_entry(void *param)
|
||||
// lv_port_disp_init();
|
||||
// lv_demo_music();
|
||||
|
||||
task_debug_create(NULL);
|
||||
// task_debug_create(NULL);
|
||||
|
||||
// FMC_SDRAM_CommandTypeDef command;
|
||||
// SDRAM_Initialization_Sequence(&hsdram1, &command);
|
||||
@ -144,16 +144,17 @@ void task_main_entry(void *param)
|
||||
}
|
||||
|
||||
// util_i2c_scan(&hi2c1);
|
||||
|
||||
if (HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin) == GPIO_PIN_RESET) {
|
||||
codec_init();
|
||||
}
|
||||
HAL_GPIO_WritePin(CODEC_EN_GPIO_Port, CODEC_EN_Pin, GPIO_PIN_SET);
|
||||
vTaskDelay(20);
|
||||
bsp_aic3204_init(&hi2c1);
|
||||
|
||||
while (1) {
|
||||
music_mp3_play("/V.A. - 花手纸.mp3");
|
||||
music_mp3_play("黒兎ウル - 四季刻歌.mp3");
|
||||
music_mp3_play("/堀江由衣 - silky heart.mp3");
|
||||
music_mp3_play("/MUSIC1.mp3");
|
||||
music_mp3_play("夏川椎菜 - No.1.mp3");
|
||||
music_mp3_play("HoneyWorks,早見沙織 - 可愛くてごめん.mp3");
|
||||
music_mp3_play("堀江由衣 - silky heart.mp3");
|
||||
music_mp3_play("Candy_Wind - Go For The Next !.mp3");
|
||||
music_mp3_play("July - Somewhere.mp3");
|
||||
music_mp3_play("Wiz Khalifa; Charlie Puth - See You Again.mp3");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -107,10 +107,10 @@ FREERTOS.configUSE_TRACE_FACILITY=1
|
||||
FREERTOS.copyHeapFile=0
|
||||
File.Version=6
|
||||
GPIO.groupedBy=Group By Peripherals
|
||||
I2C1.Analog_Filter=I2C_ANALOGFILTER_DISABLE
|
||||
I2C1.I2C_Speed_Mode=I2C_Standard
|
||||
I2C1.Analog_Filter=I2C_ANALOGFILTER_ENABLE
|
||||
I2C1.I2C_Speed_Mode=I2C_Fast
|
||||
I2C1.IPParameters=Timing,I2C_Speed_Mode,Analog_Filter
|
||||
I2C1.Timing=0x307077B2
|
||||
I2C1.Timing=0x00B03FDB
|
||||
KeepUserPlacement=false
|
||||
Mcu.CPN=STM32H743IIT6
|
||||
Mcu.Family=STM32H7
|
||||
@ -133,14 +133,15 @@ Mcu.Package=LQFP176
|
||||
Mcu.Pin0=PE2
|
||||
Mcu.Pin1=PE3
|
||||
Mcu.Pin10=PF1
|
||||
Mcu.Pin100=PI4
|
||||
Mcu.Pin101=PI5
|
||||
Mcu.Pin102=PI6
|
||||
Mcu.Pin103=PI7
|
||||
Mcu.Pin104=VP_FREERTOS_VS_CMSIS_V1
|
||||
Mcu.Pin105=VP_SAI1_VP_$IpInstance_SAIB_SAI_BASIC
|
||||
Mcu.Pin106=VP_SYS_VS_tim6
|
||||
Mcu.Pin107=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin100=PE1
|
||||
Mcu.Pin101=PI4
|
||||
Mcu.Pin102=PI5
|
||||
Mcu.Pin103=PI6
|
||||
Mcu.Pin104=PI7
|
||||
Mcu.Pin105=VP_FREERTOS_VS_CMSIS_V1
|
||||
Mcu.Pin106=VP_SAI1_VP_$IpInstance_SAIB_SAI_BASIC
|
||||
Mcu.Pin107=VP_SYS_VS_tim6
|
||||
Mcu.Pin108=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin11=PF2
|
||||
Mcu.Pin12=PF3
|
||||
Mcu.Pin13=PF4
|
||||
@ -153,92 +154,92 @@ Mcu.Pin19=PF10
|
||||
Mcu.Pin2=PE5
|
||||
Mcu.Pin20=PH0-OSC_IN (PH0)
|
||||
Mcu.Pin21=PH1-OSC_OUT (PH1)
|
||||
Mcu.Pin22=PC3_C
|
||||
Mcu.Pin23=PA2
|
||||
Mcu.Pin24=PH2
|
||||
Mcu.Pin25=PH3
|
||||
Mcu.Pin26=PH5
|
||||
Mcu.Pin27=PA5
|
||||
Mcu.Pin28=PA6
|
||||
Mcu.Pin29=PC4
|
||||
Mcu.Pin22=PC1
|
||||
Mcu.Pin23=PC3_C
|
||||
Mcu.Pin24=PA2
|
||||
Mcu.Pin25=PH2
|
||||
Mcu.Pin26=PH3
|
||||
Mcu.Pin27=PH5
|
||||
Mcu.Pin28=PA5
|
||||
Mcu.Pin29=PA6
|
||||
Mcu.Pin3=PE6
|
||||
Mcu.Pin30=PB2
|
||||
Mcu.Pin31=PF11
|
||||
Mcu.Pin32=PF12
|
||||
Mcu.Pin33=PF13
|
||||
Mcu.Pin34=PF14
|
||||
Mcu.Pin35=PF15
|
||||
Mcu.Pin36=PG0
|
||||
Mcu.Pin37=PG1
|
||||
Mcu.Pin38=PE7
|
||||
Mcu.Pin39=PE8
|
||||
Mcu.Pin30=PC4
|
||||
Mcu.Pin31=PB2
|
||||
Mcu.Pin32=PF11
|
||||
Mcu.Pin33=PF12
|
||||
Mcu.Pin34=PF13
|
||||
Mcu.Pin35=PF14
|
||||
Mcu.Pin36=PF15
|
||||
Mcu.Pin37=PG0
|
||||
Mcu.Pin38=PG1
|
||||
Mcu.Pin39=PE7
|
||||
Mcu.Pin4=PC14-OSC32_IN (OSC32_IN)
|
||||
Mcu.Pin40=PE9
|
||||
Mcu.Pin41=PE10
|
||||
Mcu.Pin42=PE11
|
||||
Mcu.Pin43=PE12
|
||||
Mcu.Pin44=PE13
|
||||
Mcu.Pin45=PE14
|
||||
Mcu.Pin46=PE15
|
||||
Mcu.Pin47=PH6
|
||||
Mcu.Pin48=PH7
|
||||
Mcu.Pin49=PH8
|
||||
Mcu.Pin40=PE8
|
||||
Mcu.Pin41=PE9
|
||||
Mcu.Pin42=PE10
|
||||
Mcu.Pin43=PE11
|
||||
Mcu.Pin44=PE12
|
||||
Mcu.Pin45=PE13
|
||||
Mcu.Pin46=PE14
|
||||
Mcu.Pin47=PE15
|
||||
Mcu.Pin48=PH6
|
||||
Mcu.Pin49=PH7
|
||||
Mcu.Pin5=PC15-OSC32_OUT (OSC32_OUT)
|
||||
Mcu.Pin50=PH9
|
||||
Mcu.Pin51=PH10
|
||||
Mcu.Pin52=PH11
|
||||
Mcu.Pin53=PH12
|
||||
Mcu.Pin54=PD8
|
||||
Mcu.Pin55=PD9
|
||||
Mcu.Pin56=PD10
|
||||
Mcu.Pin57=PD11
|
||||
Mcu.Pin58=PD12
|
||||
Mcu.Pin59=PD13
|
||||
Mcu.Pin50=PH8
|
||||
Mcu.Pin51=PH9
|
||||
Mcu.Pin52=PH10
|
||||
Mcu.Pin53=PH11
|
||||
Mcu.Pin54=PH12
|
||||
Mcu.Pin55=PD8
|
||||
Mcu.Pin56=PD9
|
||||
Mcu.Pin57=PD10
|
||||
Mcu.Pin58=PD11
|
||||
Mcu.Pin59=PD12
|
||||
Mcu.Pin6=PI9
|
||||
Mcu.Pin60=PD14
|
||||
Mcu.Pin61=PD15
|
||||
Mcu.Pin62=PG2
|
||||
Mcu.Pin63=PG3
|
||||
Mcu.Pin64=PG4
|
||||
Mcu.Pin65=PG5
|
||||
Mcu.Pin66=PG6
|
||||
Mcu.Pin67=PG7
|
||||
Mcu.Pin68=PG8
|
||||
Mcu.Pin69=PC8
|
||||
Mcu.Pin60=PD13
|
||||
Mcu.Pin61=PD14
|
||||
Mcu.Pin62=PD15
|
||||
Mcu.Pin63=PG2
|
||||
Mcu.Pin64=PG3
|
||||
Mcu.Pin65=PG4
|
||||
Mcu.Pin66=PG5
|
||||
Mcu.Pin67=PG6
|
||||
Mcu.Pin68=PG7
|
||||
Mcu.Pin69=PG8
|
||||
Mcu.Pin7=PI10
|
||||
Mcu.Pin70=PC9
|
||||
Mcu.Pin71=PA8
|
||||
Mcu.Pin72=PA9
|
||||
Mcu.Pin73=PA10
|
||||
Mcu.Pin74=PA11
|
||||
Mcu.Pin75=PA12
|
||||
Mcu.Pin76=PA13 (JTMS/SWDIO)
|
||||
Mcu.Pin77=PH13
|
||||
Mcu.Pin78=PH14
|
||||
Mcu.Pin79=PH15
|
||||
Mcu.Pin70=PC8
|
||||
Mcu.Pin71=PC9
|
||||
Mcu.Pin72=PA8
|
||||
Mcu.Pin73=PA9
|
||||
Mcu.Pin74=PA10
|
||||
Mcu.Pin75=PA11
|
||||
Mcu.Pin76=PA12
|
||||
Mcu.Pin77=PA13 (JTMS/SWDIO)
|
||||
Mcu.Pin78=PH13
|
||||
Mcu.Pin79=PH14
|
||||
Mcu.Pin8=PI11
|
||||
Mcu.Pin80=PI0
|
||||
Mcu.Pin81=PI2
|
||||
Mcu.Pin82=PA14 (JTCK/SWCLK)
|
||||
Mcu.Pin83=PC10
|
||||
Mcu.Pin84=PC11
|
||||
Mcu.Pin85=PC12
|
||||
Mcu.Pin86=PD0
|
||||
Mcu.Pin87=PD1
|
||||
Mcu.Pin88=PD2
|
||||
Mcu.Pin89=PD6
|
||||
Mcu.Pin80=PH15
|
||||
Mcu.Pin81=PI0
|
||||
Mcu.Pin82=PI2
|
||||
Mcu.Pin83=PA14 (JTCK/SWCLK)
|
||||
Mcu.Pin84=PC10
|
||||
Mcu.Pin85=PC11
|
||||
Mcu.Pin86=PC12
|
||||
Mcu.Pin87=PD0
|
||||
Mcu.Pin88=PD1
|
||||
Mcu.Pin89=PD2
|
||||
Mcu.Pin9=PF0
|
||||
Mcu.Pin90=PG12
|
||||
Mcu.Pin91=PG13
|
||||
Mcu.Pin92=PG14
|
||||
Mcu.Pin93=PG15
|
||||
Mcu.Pin94=PB3 (JTDO/TRACESWO)
|
||||
Mcu.Pin95=PB6
|
||||
Mcu.Pin96=PB8
|
||||
Mcu.Pin97=PB9
|
||||
Mcu.Pin98=PE0
|
||||
Mcu.Pin99=PE1
|
||||
Mcu.PinsNb=108
|
||||
Mcu.Pin90=PD6
|
||||
Mcu.Pin91=PG12
|
||||
Mcu.Pin92=PG13
|
||||
Mcu.Pin93=PG14
|
||||
Mcu.Pin94=PG15
|
||||
Mcu.Pin95=PB3 (JTDO/TRACESWO)
|
||||
Mcu.Pin96=PB6
|
||||
Mcu.Pin97=PB8
|
||||
Mcu.Pin98=PB9
|
||||
Mcu.Pin99=PE0
|
||||
Mcu.PinsNb=109
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32H743IITx
|
||||
@ -339,6 +340,13 @@ PB9.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
||||
PB9.Locked=true
|
||||
PB9.Mode=I2C
|
||||
PB9.Signal=I2C1_SDA
|
||||
PC1.GPIOParameters=PinState,GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultOutputPP
|
||||
PC1.GPIO_Label=CODEC_RST
|
||||
PC1.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_PP
|
||||
PC1.GPIO_PuPd=GPIO_PULLUP
|
||||
PC1.Locked=true
|
||||
PC1.PinState=GPIO_PIN_RESET
|
||||
PC1.Signal=GPIO_Output
|
||||
PC10.Locked=true
|
||||
PC10.Mode=SD_4_bits_Wide_bus
|
||||
PC10.Signal=SDMMC1_D2
|
||||
@ -352,11 +360,11 @@ PC14-OSC32_IN\ (OSC32_IN).Locked=true
|
||||
PC14-OSC32_IN\ (OSC32_IN).Signal=RCC_OSC32_IN
|
||||
PC15-OSC32_OUT\ (OSC32_OUT).Locked=true
|
||||
PC15-OSC32_OUT\ (OSC32_OUT).Signal=RCC_OSC32_OUT
|
||||
PC3_C.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||
PC3_C.GPIO_Label=HP_DET
|
||||
PC3_C.GPIO_PuPd=GPIO_PULLUP
|
||||
PC3_C.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PC3_C.GPIO_Label=CODEC_EN
|
||||
PC3_C.GPIO_Speed=GPIO_SPEED_FREQ_LOW
|
||||
PC3_C.Locked=true
|
||||
PC3_C.Signal=GPIO_Input
|
||||
PC3_C.Signal=GPIO_Output
|
||||
PC4.GPIOParameters=GPIO_Speed,PinState,GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultOutputPP
|
||||
PC4.GPIO_Label=LED_R
|
||||
PC4.GPIO_ModeDefaultOutputPP=GPIO_MODE_OUTPUT_OD
|
||||
|
||||
Loading…
Reference in New Issue
Block a user