feat: 添加MP3驱动模块并集成到系统初始化

新增MP3驱动模块,包含初始化、播放、暂停、停止、音量设置等功能
修改USART3波特率为9600以适配MP3模块
在系统启动时初始化MP3模块并播放启动音效
添加MP3播放索引定义文件
This commit is contained in:
2026-02-23 14:31:55 +08:00
parent 297b0f2384
commit ce8d6fd2eb
8 changed files with 384 additions and 28 deletions

View File

@@ -19,17 +19,21 @@
/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"
#include "main.h"
#include "task.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "device_ctrl.h"
#include "dx_wf_24.h"
#include "elog.h"
#include "mp3_driver.h"
#include "spi_st7735s.h"
#include "stdio.h"
#include "mp3_play_index.h"
/* USER CODE END Includes */
@@ -56,23 +60,23 @@
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.stack_size = 256 * 4,
.priority = (osPriority_t) osPriorityHigh1,
.name = "defaultTask",
.stack_size = 256 * 4,
.priority = (osPriority_t)osPriorityHigh1,
};
/* Definitions for wifi_mqtt */
osThreadId_t wifi_mqttHandle;
const osThreadAttr_t wifi_mqtt_attributes = {
.name = "wifi_mqtt",
.stack_size = 3000 * 4,
.priority = (osPriority_t) osPriorityHigh,
.name = "wifi_mqtt",
.stack_size = 3000 * 4,
.priority = (osPriority_t)osPriorityHigh,
};
/* Definitions for LCD_SHOW_Task */
osThreadId_t LCD_SHOW_TaskHandle;
const osThreadAttr_t LCD_SHOW_Task_attributes = {
.name = "LCD_SHOW_Task",
.stack_size = 1024 * 4,
.priority = (osPriority_t) osPriorityHigh,
.name = "LCD_SHOW_Task",
.stack_size = 1024 * 4,
.priority = (osPriority_t)osPriorityHigh,
};
/* Private function prototypes -----------------------------------------------*/
@@ -87,10 +91,10 @@ void LCD_Task(void *argument);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
/**
* @brief FreeRTOS initialization
* @param None
* @retval None
*/
* @brief FreeRTOS initialization
* @param None
* @retval None
*/
void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */
ST7735_Init(); // 初始化ST7735显示屏
@@ -114,7 +118,8 @@ void MX_FREERTOS_Init(void) {
/* Create the thread(s) */
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
defaultTaskHandle =
osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* creation of wifi_mqtt */
wifi_mqttHandle = osThreadNew(wifi_task_mqtt, NULL, &wifi_mqtt_attributes);
@@ -129,7 +134,6 @@ void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN RTOS_EVENTS */
/* add events, ... */
/* USER CODE END RTOS_EVENTS */
}
/* USER CODE BEGIN Header_StartDefaultTask */
@@ -139,8 +143,7 @@ void MX_FREERTOS_Init(void) {
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
{
void StartDefaultTask(void *argument) {
/* USER CODE BEGIN StartDefaultTask */
// 1. 打开运行灯
Device_Control(DEVICE_LED_RUN, 1);
@@ -148,6 +151,16 @@ void StartDefaultTask(void *argument)
// 2. 初始化日志和屏幕(在 RTOS 任务中)
easylogger_init();
// 初始化MP3模块
HAL_StatusTypeDef ret = MP3_Init();
if (ret != HAL_OK) {
elog_e("MP3", "MP3模块初始化失败");
return;
}
elog_i("MP3", "模块初始化完成");
MP3_Play(SYS_POWER_ON);
/* Infinite loop */
for (;;) {
@@ -166,8 +179,7 @@ void StartDefaultTask(void *argument)
* @retval None
*/
/* USER CODE END Header_LCD_Task */
void LCD_Task(void *argument)
{
void LCD_Task(void *argument) {
/* USER CODE BEGIN LCD_Task */
char time_str[16];
@@ -208,4 +220,3 @@ void LCD_Task(void *argument)
/* USER CODE BEGIN Application */
/* USER CODE END Application */

View File

@@ -100,7 +100,7 @@ void MX_USART3_UART_Init(void)
/* USER CODE END USART3_Init 1 */
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.BaudRate = 9600;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;