Files

77 lines
2.4 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
****************************************************************************************************
* @file main.c
* @author HiFi Player Project
* @version V1.0
* @date 2026-01-01
* @brief HiFi 播放器(ESP32-S3 + SPI LCD + ES8388 + SD 卡 + LVGL)
*
* 硬件资源(正点原子 DNESP32S3 开发板):
* - SPI LCD : ST7789 320x240,SPI2(SCLK=12, MOSI=11, CS=21, DC=40)
* - SD 卡 : SPI 模式,SPI2(CS=2),FATFS 挂载点 "/0:"
* - 音频 : ES8388 + I2S0(MCLK=3, BCLK=46, WS=9, DOUT=10, DIN=14)
* - 按键 : XL9555 的 KEY0~KEY3(I2C0:SDA=41, SCL=42)
*
* 目录约定:把 .wav 文件放到 SD 卡的 /MUSIC 目录(16bit 或 24bit PCM)
****************************************************************************************************
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_err.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "my_spi.h"
#include "myiic.h"
#include "xl9555.h"
#include "spilcd.h"
#include "led.h"
#include "lvgl_port.h"
#include "ui.h"
#include "app.h"
#include "player.h"
static const char *TAG = "app";
void app_main(void)
{
/* ---------------- 1. NVS ---------------- */
esp_err_t ret = nvs_flash_init();
if ((ret == ESP_ERR_NVS_NO_FREE_PAGES) || (ret == ESP_ERR_NVS_NEW_VERSION_FOUND))
{
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
/* ---------------- 2. 基础外设 ---------------- */
led_init();
LED0(0);
/* SPI2 由 LCD 和 SD 卡共用,必须先初始化总线,再初始化 LCD */
ESP_ERROR_CHECK(my_spi_init());
ESP_ERROR_CHECK(myiic_init());
ESP_ERROR_CHECK(xl9555_init());
/* ---------------- 3. 显示 ---------------- */
ESP_ERROR_CHECK(spilcd_init());
LCD_BL(1); /* 打开背光 */
/* ---------------- 4. 应用管理与界面 ---------------- */
app_start(); /* 按键服务 + 应用模式管理 */
ESP_ERROR_CHECK(lvgl_port_init());
ui_create(); /* 主界面 + 播放器界面 */
lvgl_port_start();
/* ---------------- 5. 播放器任务(进入播放器界面后才出声) ---------------- */
player_start();
ESP_LOGI(TAG, "HiFi player started, press K2 on HOME to open MUSIC PLAYER");
}