这是一次长久的提交:

1. 应用界面增加了返回主页的按钮
2. 修复了gif渲染内存泄漏的严重bug
3. 将PetDao当中的cJSON API替换为cpp_json,完美通过测试
4. 整合已经实现的各种上层建筑,实现了一个宠物对话基本业务应用,用于样品测试展示用
5. 重构了音频播放类,使其更modern,更加便于移植和拓展
This commit is contained in:
Misaki
2025-10-16 11:36:45 +08:00
parent 801138631e
commit ba5e47bc77
38 changed files with 2487 additions and 2008 deletions
+8 -6
View File
@@ -1,8 +1,7 @@
#include "PCM5101.h"
static const char *TAG = "AUDIO PCM5101";
static i2s_chan_handle_t i2s_tx_chan;
i2s_chan_handle_t i2s_tx_chan = NULL;
static i2s_chan_handle_t i2s_rx_chan;
uint8_t Volume = Volume_MAX - 2;
@@ -24,8 +23,8 @@ static esp_err_t bsp_i2s_write(void *audio_buffer, size_t len, size_t *bytes_wri
return i2s_channel_write(i2s_tx_chan, (char *)audio_buffer, len, bytes_written, timeout_ms);
}
static esp_err_t bsp_i2s_reconfig_clk(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch) { // I2S Init
esp_err_t ret = ESP_OK;
esp_err_t bsp_i2s_reconfig_clk(uint32_t rate, uint32_t bits_cfg, i2s_slot_mode_t ch) { // I2S Init
esp_err_t ret = ESP_OK;
i2s_std_config_t std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(rate),
.slot_cfg = I2S_STD_PHILIP_SLOT_DEFAULT_CONFIG((i2s_data_bit_width_t)bits_cfg, ch),
@@ -34,11 +33,11 @@ static esp_err_t bsp_i2s_reconfig_clk(uint32_t rate, uint32_t bits_cfg, i2s_slot
ret |= i2s_channel_disable(i2s_tx_chan);
ret |= i2s_channel_reconfig_std_clock(i2s_tx_chan, &std_cfg.clk_cfg);
ret |= i2s_channel_reconfig_std_slot(i2s_tx_chan, &std_cfg.slot_cfg);
ret |= i2s_channel_enable(i2s_tx_chan);
ret |= i2s_channel_enable(i2s_tx_chan);
return ret;
}
static esp_err_t audio_mute_function(AUDIO_PLAYER_MUTE_SETTING setting) { // audio mute function
static esp_err_t audio_mute_function(AUDIO_PLAYER_MUTE_SETTING setting) { // audio mute function
ESP_LOGI(TAG, "mute setting %d", setting);
return ESP_OK;
}
@@ -214,3 +213,6 @@ void Volume_adjustment(uint8_t Vol) {
Volume = Vol;
ESP_LOGI(TAG, "Volume set to %d", Volume);
}
+9
View File
@@ -57,6 +57,15 @@ uint32_t Music_Elapsed(void);
uint16_t Music_Energy(void);
void Volume_adjustment(uint8_t Volume);
// 供 C++ 层调用的“重新配置时钟”包装
esp_err_t bsp_i2s_reconfig_clk(uint32_t rate,
uint32_t bits_cfg,
i2s_slot_mode_t ch);
// 供 C++ 层直接用的 tx channel 句柄
extern i2s_chan_handle_t i2s_tx_chan;
#ifdef __cplusplus
}
#endif
+5 -5
View File
@@ -239,7 +239,7 @@ int QSPI_Init(void){
.data6_io_num = -1,
.data7_io_num = -1,
.max_transfer_sz = ESP_PANEL_HOST_SPI_MAX_TRANSFER_SIZE,
.flags = SPICOMMON_BUSFLAG_MASTER,
.flags = SPICOMMON_BUSFLAG_MASTER,
.intr_flags = 0,
};
if(spi_bus_initialize(ESP_PANEL_HOST_SPI_ID_DEFAULT, &host_config, SPI_DMA_CH_AUTO) != ESP_OK){
@@ -252,7 +252,7 @@ int QSPI_Init(void){
.cs_gpio_num = ESP_PANEL_LCD_SPI_IO_CS,
.dc_gpio_num = -1,
.spi_mode = ESP_PANEL_LCD_SPI_MODE,
.pclk_hz = 3 * 1000 * 1000,
.pclk_hz = 3 * 1000 * 1000,
.trans_queue_depth = ESP_PANEL_LCD_SPI_TRANS_QUEUE_SZ,
.on_color_trans_done = NULL,
.user_ctx = NULL,
@@ -283,17 +283,17 @@ int QSPI_Init(void){
printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n");
esp_err_t ret;
int lcd_cmd = 0x04;
uint8_t register_data[4];
uint8_t register_data[4];
size_t param_size = sizeof(register_data);
lcd_cmd &= 0xff;
lcd_cmd <<= 8;
lcd_cmd |= LCD_OPCODE_READ_CMD << 24; // Use the read opcode instead of write
ret = esp_lcd_panel_io_rx_param(io_handle, lcd_cmd, register_data, param_size);
ret = esp_lcd_panel_io_rx_param(io_handle, lcd_cmd, register_data, param_size);
if (ret == ESP_OK) {
printf("Register 0x04 data: %02x %02x %02x %02x\n", register_data[0], register_data[1], register_data[2], register_data[3]);
} else {
printf("Failed to read register 0x04, error code: %d\n", ret);
}
}
// panel_io_spi_del(io_handle);
io_config.pclk_hz = ESP_PANEL_LCD_SPI_CLK_HZ;
if(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)ESP_PANEL_HOST_SPI_ID_DEFAULT, &io_config, &io_handle) != ESP_OK){
+3 -3
View File
@@ -33,8 +33,8 @@ extern "C" {
#define ESP_PANEL_HOST_SPI_ID_DEFAULT (SPI2_HOST)
#define ESP_PANEL_LCD_SPI_MODE (0) // 0/1/2/3, typically set to 0
#define ESP_PANEL_LCD_SPI_CLK_HZ (80 * 1000 * 1000) // Should be an integer divisor of 80M, typically set to 40M
#define ESP_PANEL_LCD_SPI_TRANS_QUEUE_SZ (10) // Typically set to 10
#define ESP_PANEL_LCD_SPI_CLK_HZ (40 * 1000 * 1000) // Should be an integer divisor of 80M, typically set to 40M
#define ESP_PANEL_LCD_SPI_TRANS_QUEUE_SZ (40) // Typically set to 10
#define ESP_PANEL_LCD_SPI_CMD_BITS (32) // Typically set to 32
#define ESP_PANEL_LCD_SPI_PARAM_BITS (8) // Typically set to 8
@@ -51,7 +51,7 @@ extern "C" {
#define EXAMPLE_LCD_BK_LIGHT_ON_LEVEL (1)
#define EXAMPLE_LCD_BK_LIGHT_OFF_LEVEL !EXAMPLE_LCD_BK_LIGHT_ON_LEVEL
#define ESP_PANEL_HOST_SPI_MAX_TRANSFER_SIZE (2048)
#define ESP_PANEL_HOST_SPI_MAX_TRANSFER_SIZE (8192)
#define LEDC_HS_TIMER LEDC_TIMER_0
#define LEDC_LS_MODE LEDC_LOW_SPEED_MODE
+7 -8
View File
@@ -18,13 +18,12 @@ void example_increase_lvgl_tick(void *arg)
void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
{
esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t) drv->user_data;
int offsetx1 = area->x1;
int offsetx2 = area->x2;
int offsety1 = area->y1;
int offsety2 = area->y2;
// copy a buffer's content to a specific area of the display
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 +1, offsety2 + 1, color_map);
// 立即通知LVGL传输开始,使用DMA传输
lv_disp_flush_ready(drv);
// copy a buffer's content to a specific area of the display
// 异步传输数据
esp_lcd_panel_draw_bitmap(panel_handle, area->x1, area->y1, area->x2 + 1, area->y2 + 1, color_map);
}
/*Read the touchpad*/
@@ -89,7 +88,7 @@ void LVGL_Init(void)
lv_color_t *buf1 = heap_caps_malloc(LVGL_BUF_LEN * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
assert(buf1);
lv_color_t *buf2 = heap_caps_malloc(LVGL_BUF_LEN * sizeof(lv_color_t) , MALLOC_CAP_SPIRAM);
lv_color_t *buf2 = heap_caps_malloc(LVGL_BUF_LEN * sizeof(lv_color_t) , MALLOC_CAP_SPIRAM);
assert(buf2);
lv_disp_draw_buf_init(&disp_buf, buf1, buf2, LVGL_BUF_LEN); // initialize LVGL draw buffers
@@ -119,7 +118,7 @@ void LVGL_Init(void)
.callback = &example_increase_lvgl_tick,
.name = "lvgl_tick"
};
esp_timer_handle_t lvgl_tick_timer = NULL;
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000));
+1 -1
View File
@@ -15,7 +15,7 @@ extern "C" {
#define LVGL_BUF_LEN (EXAMPLE_LCD_WIDTH * EXAMPLE_LCD_HEIGHT / 20)
#define LVGL_BUF_LEN (EXAMPLE_LCD_WIDTH * EXAMPLE_LCD_HEIGHT / 8) // 1 byte per pixel
#define EXAMPLE_LVGL_TICK_PERIOD_MS 2
extern lv_disp_draw_buf_t disp_buf; // contains internal graphic buffer(s) called draw buffer(s)
+2 -2
View File
@@ -9,10 +9,10 @@ uint32_t Flash_Size = 0;
uint32_t SDCard_Size = 0;
esp_err_t s_example_write_file(const char *path, char *data)
esp_err_t s_example_write_file(const char *path, const char *data, const char *type)
{
ESP_LOGI(SD_TAG, "Opening file %s", path);
FILE *f = fopen(path, "w");
FILE *f = fopen(path, type);
if (f == NULL) {
ESP_LOGE(SD_TAG, "Failed to open file for writing");
return ESP_FAIL;
+1 -1
View File
@@ -30,7 +30,7 @@ extern "C" {
esp_err_t SD_Card_CS_EN(void);
esp_err_t SD_Card_CS_Dis(void);
esp_err_t s_example_write_file(const char *path, char *data);
esp_err_t s_example_write_file(const char *path, const char *data, const char *type);
esp_err_t s_example_read_file(const char *path);
extern uint32_t SDCard_Size;
+2 -2
View File
@@ -102,7 +102,7 @@ uint16_t WIFI_Scan(void)
return ap_count;
}
/*
#define GATTC_TAG "GATTC_TAG"
#define SCAN_DURATION 5
#define MAX_DISCOVERED_DEVICES 100
@@ -266,7 +266,7 @@ uint16_t BLE_Scan(void)
Scan_finish = 1;
return BLE_NUM;
}
*/
// 下面是新增的实现
static EventGroupHandle_t s_wifi_event_group;
+3 -3
View File
@@ -12,9 +12,9 @@ extern "C" {
#include <stdio.h>
#include <string.h> // For memcpy
#include "esp_system.h"
#include "esp_bt.h"
#include "esp_gap_ble_api.h"
#include "esp_bt_main.h"
// #include "esp_bt.h"
// #include "esp_gap_ble_api.h"
// #include "esp_bt_main.h"
// WiFi AP信息结构体
typedef struct {