main/boards: Add support for M5Stack Tab5. (#632)

This commit is contained in:
Create123
2025-05-19 01:43:49 +08:00
committed by GitHub
parent 7925f77739
commit f7ea248845
9 changed files with 4231 additions and 30 deletions

View File

@@ -77,6 +77,8 @@ elseif(CONFIG_BOARD_TYPE_MAGICLICK_C3_V2)
set(BOARD_TYPE "magiclick-c3-v2")
elseif(CONFIG_BOARD_TYPE_M5STACK_CORE_S3)
set(BOARD_TYPE "m5stack-core-s3")
elseif(CONFIG_BOARD_TYPE_M5STACK_CORE_TAB5)
set(BOARD_TYPE "m5stack-tab5")
elseif(CONFIG_BOARD_TYPE_ATOMS3_ECHO_BASE)
set(BOARD_TYPE "atoms3-echo-base")
elseif(CONFIG_BOARD_TYPE_ATOMS3R_ECHO_BASE)

View File

@@ -74,6 +74,8 @@ choice BOARD_TYPE
bool "神奇按钮 Magiclick_C3_v2"
config BOARD_TYPE_M5STACK_CORE_S3
bool "M5Stack CoreS3"
config BOARD_TYPE_M5STACK_CORE_TAB5
bool "M5Stack Tab5"
config BOARD_TYPE_ATOMS3_ECHO_BASE
bool "AtomS3 + Echo Base"
config BOARD_TYPE_ATOMS3R_ECHO_BASE

View File

@@ -0,0 +1,47 @@
# 使用说明
* [M5Stack Tab5 docs](https://docs.m5stack.com/zh_CN/core/Tab5)
## 快速体验
下载编译好的 [固件](https://pan.baidu.com/s/1dgbUQtMyVLSCSBJLHARpwQ?pwd=1234) 提取码: 1234
```shell
esptool.py --chip esp32p4 -p /dev/ttyACM0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 16MB 0x00 tab5_xiaozhi_v1_addr0.bin
```
## 基础使用
* idf version: v5.5-dev
1. 设置编译目标为 esp32p4
```shell
idf.py set-target esp32p4
```
2. 修改配置
```shell
cp main/boards/m5stack-tab5/sdkconfig.tab5 sdkconfig
```
3. 编译烧录程序
```shell
idf.py build flash monitor
```
> [!NOTE]
> 进入下载模式:长按复位按键(约 2 秒),直至内部绿色 LED 指示灯开始快速闪烁,松开按键。
## log
@2025/05/17 测试问题
1. listening... 需要等几秒才能获取语音输入???
2. 亮度调节不对
3. 音量调节不对
## TODO

View File

@@ -0,0 +1,261 @@
#ifndef _BOARD_CONFIG_H_
#define _BOARD_CONFIG_H_
#include <driver/gpio.h>
/* ---------------------------------------------------------------- */
// Audio CODEC ES7210 + ES8311
#define AUDIO_INPUT_SAMPLE_RATE 24000
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
#define AUDIO_INPUT_REFERENCE true
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_30
#define AUDIO_I2S_GPIO_WS GPIO_NUM_29
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_27
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_28
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_26
#define AUDIO_CODEC_PA_PIN GPIO_NUM_NC // PI4IOE 控制
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_31
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_32
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
#define AUDIO_CODEC_ES7210_ADDR ES7210_CODEC_DEFAULT_ADDR
#define BUILTIN_LED_GPIO GPIO_NUM_NC
#define BOOT_BUTTON_GPIO GPIO_NUM_0
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_NC
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_NC
/* ---------------------------------------------------------------- */
// 显示屏相关参数配置
#define DISPLAY_WIDTH 720
#define DISPLAY_HEIGHT 1280
#define DISPLAY_MIRROR_X false
#define DISPLAY_MIRROR_Y false
#define DISPLAY_SWAP_XY false
#define DISPLAY_OFFSET_X 0
#define DISPLAY_OFFSET_Y 0
#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_22
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT true
#define TOUCH_INT_GPIO GPIO_NUM_23 // 触摸中断
const ili9881c_lcd_init_cmd_t tab5_lcd_ili9881c_specific_init_code_default[] = {
// {cmd, { data }, data_size, delay}
/**** CMD_Page 1 ****/
{0xFF, (uint8_t[]){0x98, 0x81, 0x01}, 3, 0},
{0xB7, (uint8_t[]){0x03}, 1, 0}, // set 2 lane
/**** CMD_Page 3 ****/
{0xFF, (uint8_t[]){0x98, 0x81, 0x03}, 3, 0},
{0x01, (uint8_t[]){0x00}, 1, 0},
{0x02, (uint8_t[]){0x00}, 1, 0},
{0x03, (uint8_t[]){0x73}, 1, 0},
{0x04, (uint8_t[]){0x00}, 1, 0},
{0x05, (uint8_t[]){0x00}, 1, 0},
{0x06, (uint8_t[]){0x08}, 1, 0},
{0x07, (uint8_t[]){0x00}, 1, 0},
{0x08, (uint8_t[]){0x00}, 1, 0},
{0x09, (uint8_t[]){0x1B}, 1, 0},
{0x0a, (uint8_t[]){0x01}, 1, 0},
{0x0b, (uint8_t[]){0x01}, 1, 0},
{0x0c, (uint8_t[]){0x0D}, 1, 0},
{0x0d, (uint8_t[]){0x01}, 1, 0},
{0x0e, (uint8_t[]){0x01}, 1, 0},
{0x0f, (uint8_t[]){0x26}, 1, 0},
{0x10, (uint8_t[]){0x26}, 1, 0},
{0x11, (uint8_t[]){0x00}, 1, 0},
{0x12, (uint8_t[]){0x00}, 1, 0},
{0x13, (uint8_t[]){0x02}, 1, 0},
{0x14, (uint8_t[]){0x00}, 1, 0},
{0x15, (uint8_t[]){0x00}, 1, 0},
{0x16, (uint8_t[]){0x00}, 1, 0},
{0x17, (uint8_t[]){0x00}, 1, 0},
{0x18, (uint8_t[]){0x00}, 1, 0},
{0x19, (uint8_t[]){0x00}, 1, 0},
{0x1a, (uint8_t[]){0x00}, 1, 0},
{0x1b, (uint8_t[]){0x00}, 1, 0},
{0x1c, (uint8_t[]){0x00}, 1, 0},
{0x1d, (uint8_t[]){0x00}, 1, 0},
{0x1e, (uint8_t[]){0x40}, 1, 0},
{0x1f, (uint8_t[]){0x00}, 1, 0},
{0x20, (uint8_t[]){0x06}, 1, 0},
{0x21, (uint8_t[]){0x01}, 1, 0},
{0x22, (uint8_t[]){0x00}, 1, 0},
{0x23, (uint8_t[]){0x00}, 1, 0},
{0x24, (uint8_t[]){0x00}, 1, 0},
{0x25, (uint8_t[]){0x00}, 1, 0},
{0x26, (uint8_t[]){0x00}, 1, 0},
{0x27, (uint8_t[]){0x00}, 1, 0},
{0x28, (uint8_t[]){0x33}, 1, 0},
{0x29, (uint8_t[]){0x03}, 1, 0},
{0x2a, (uint8_t[]){0x00}, 1, 0},
{0x2b, (uint8_t[]){0x00}, 1, 0},
{0x2c, (uint8_t[]){0x00}, 1, 0},
{0x2d, (uint8_t[]){0x00}, 1, 0},
{0x2e, (uint8_t[]){0x00}, 1, 0},
{0x2f, (uint8_t[]){0x00}, 1, 0},
{0x30, (uint8_t[]){0x00}, 1, 0},
{0x31, (uint8_t[]){0x00}, 1, 0},
{0x32, (uint8_t[]){0x00}, 1, 0},
{0x33, (uint8_t[]){0x00}, 1, 0},
{0x34, (uint8_t[]){0x00}, 1, 0},
{0x35, (uint8_t[]){0x00}, 1, 0},
{0x36, (uint8_t[]){0x00}, 1, 0},
{0x37, (uint8_t[]){0x00}, 1, 0},
{0x38, (uint8_t[]){0x00}, 1, 0},
{0x39, (uint8_t[]){0x00}, 1, 0},
{0x3a, (uint8_t[]){0x00}, 1, 0},
{0x3b, (uint8_t[]){0x00}, 1, 0},
{0x3c, (uint8_t[]){0x00}, 1, 0},
{0x3d, (uint8_t[]){0x00}, 1, 0},
{0x3e, (uint8_t[]){0x00}, 1, 0},
{0x3f, (uint8_t[]){0x00}, 1, 0},
{0x40, (uint8_t[]){0x00}, 1, 0},
{0x41, (uint8_t[]){0x00}, 1, 0},
{0x42, (uint8_t[]){0x00}, 1, 0},
{0x43, (uint8_t[]){0x00}, 1, 0},
{0x44, (uint8_t[]){0x00}, 1, 0},
{0x50, (uint8_t[]){0x01}, 1, 0},
{0x51, (uint8_t[]){0x23}, 1, 0},
{0x52, (uint8_t[]){0x45}, 1, 0},
{0x53, (uint8_t[]){0x67}, 1, 0},
{0x54, (uint8_t[]){0x89}, 1, 0},
{0x55, (uint8_t[]){0xab}, 1, 0},
{0x56, (uint8_t[]){0x01}, 1, 0},
{0x57, (uint8_t[]){0x23}, 1, 0},
{0x58, (uint8_t[]){0x45}, 1, 0},
{0x59, (uint8_t[]){0x67}, 1, 0},
{0x5a, (uint8_t[]){0x89}, 1, 0},
{0x5b, (uint8_t[]){0xab}, 1, 0},
{0x5c, (uint8_t[]){0xcd}, 1, 0},
{0x5d, (uint8_t[]){0xef}, 1, 0},
{0x5e, (uint8_t[]){0x11}, 1, 0},
{0x5f, (uint8_t[]){0x02}, 1, 0},
{0x60, (uint8_t[]){0x00}, 1, 0},
{0x61, (uint8_t[]){0x07}, 1, 0},
{0x62, (uint8_t[]){0x06}, 1, 0},
{0x63, (uint8_t[]){0x0E}, 1, 0},
{0x64, (uint8_t[]){0x0F}, 1, 0},
{0x65, (uint8_t[]){0x0C}, 1, 0},
{0x66, (uint8_t[]){0x0D}, 1, 0},
{0x67, (uint8_t[]){0x02}, 1, 0},
{0x68, (uint8_t[]){0x02}, 1, 0},
{0x69, (uint8_t[]){0x02}, 1, 0},
{0x6a, (uint8_t[]){0x02}, 1, 0},
{0x6b, (uint8_t[]){0x02}, 1, 0},
{0x6c, (uint8_t[]){0x02}, 1, 0},
{0x6d, (uint8_t[]){0x02}, 1, 0},
{0x6e, (uint8_t[]){0x02}, 1, 0},
{0x6f, (uint8_t[]){0x02}, 1, 0},
{0x70, (uint8_t[]){0x02}, 1, 0},
{0x71, (uint8_t[]){0x02}, 1, 0},
{0x72, (uint8_t[]){0x02}, 1, 0},
{0x73, (uint8_t[]){0x05}, 1, 0},
{0x74, (uint8_t[]){0x01}, 1, 0},
{0x75, (uint8_t[]){0x02}, 1, 0},
{0x76, (uint8_t[]){0x00}, 1, 0},
{0x77, (uint8_t[]){0x07}, 1, 0},
{0x78, (uint8_t[]){0x06}, 1, 0},
{0x79, (uint8_t[]){0x0E}, 1, 0},
{0x7a, (uint8_t[]){0x0F}, 1, 0},
{0x7b, (uint8_t[]){0x0C}, 1, 0},
{0x7c, (uint8_t[]){0x0D}, 1, 0},
{0x7d, (uint8_t[]){0x02}, 1, 0},
{0x7e, (uint8_t[]){0x02}, 1, 0},
{0x7f, (uint8_t[]){0x02}, 1, 0},
{0x80, (uint8_t[]){0x02}, 1, 0},
{0x81, (uint8_t[]){0x02}, 1, 0},
{0x82, (uint8_t[]){0x02}, 1, 0},
{0x83, (uint8_t[]){0x02}, 1, 0},
{0x84, (uint8_t[]){0x02}, 1, 0},
{0x85, (uint8_t[]){0x02}, 1, 0},
{0x86, (uint8_t[]){0x02}, 1, 0},
{0x87, (uint8_t[]){0x02}, 1, 0},
{0x88, (uint8_t[]){0x02}, 1, 0},
{0x89, (uint8_t[]){0x05}, 1, 0},
{0x8A, (uint8_t[]){0x01}, 1, 0},
/**** CMD_Page 4 ****/
{0xFF, (uint8_t[]){0x98, 0x81, 0x04}, 3, 0},
{0x38, (uint8_t[]){0x01}, 1, 0},
{0x39, (uint8_t[]){0x00}, 1, 0},
{0x6C, (uint8_t[]){0x15}, 1, 0},
{0x6E, (uint8_t[]){0x1A}, 1, 0},
{0x6F, (uint8_t[]){0x25}, 1, 0},
{0x3A, (uint8_t[]){0xA4}, 1, 0},
{0x8D, (uint8_t[]){0x20}, 1, 0},
{0x87, (uint8_t[]){0xBA}, 1, 0},
{0x3B, (uint8_t[]){0x98}, 1, 0},
/**** CMD_Page 1 ****/
{0xFF, (uint8_t[]){0x98, 0x81, 0x01}, 3, 0},
{0x22, (uint8_t[]){0x0A}, 1, 0},
{0x31, (uint8_t[]){0x00}, 1, 0},
{0x50, (uint8_t[]){0x6B}, 1, 0},
{0x51, (uint8_t[]){0x66}, 1, 0},
{0x53, (uint8_t[]){0x73}, 1, 0},
{0x55, (uint8_t[]){0x8B}, 1, 0},
{0x60, (uint8_t[]){0x1B}, 1, 0},
{0x61, (uint8_t[]){0x01}, 1, 0},
{0x62, (uint8_t[]){0x0C}, 1, 0},
{0x63, (uint8_t[]){0x00}, 1, 0},
// Gamma P
{0xA0, (uint8_t[]){0x00}, 1, 0},
{0xA1, (uint8_t[]){0x15}, 1, 0},
{0xA2, (uint8_t[]){0x1F}, 1, 0},
{0xA3, (uint8_t[]){0x13}, 1, 0},
{0xA4, (uint8_t[]){0x11}, 1, 0},
{0xA5, (uint8_t[]){0x21}, 1, 0},
{0xA6, (uint8_t[]){0x17}, 1, 0},
{0xA7, (uint8_t[]){0x1B}, 1, 0},
{0xA8, (uint8_t[]){0x6B}, 1, 0},
{0xA9, (uint8_t[]){0x1E}, 1, 0},
{0xAA, (uint8_t[]){0x2B}, 1, 0},
{0xAB, (uint8_t[]){0x5D}, 1, 0},
{0xAC, (uint8_t[]){0x19}, 1, 0},
{0xAD, (uint8_t[]){0x14}, 1, 0},
{0xAE, (uint8_t[]){0x4B}, 1, 0},
{0xAF, (uint8_t[]){0x1D}, 1, 0},
{0xB0, (uint8_t[]){0x27}, 1, 0},
{0xB1, (uint8_t[]){0x49}, 1, 0},
{0xB2, (uint8_t[]){0x5D}, 1, 0},
{0xB3, (uint8_t[]){0x39}, 1, 0},
// Gamma N
{0xC0, (uint8_t[]){0x00}, 1, 0},
{0xC1, (uint8_t[]){0x01}, 1, 0},
{0xC2, (uint8_t[]){0x0C}, 1, 0},
{0xC3, (uint8_t[]){0x11}, 1, 0},
{0xC4, (uint8_t[]){0x15}, 1, 0},
{0xC5, (uint8_t[]){0x28}, 1, 0},
{0xC6, (uint8_t[]){0x1B}, 1, 0},
{0xC7, (uint8_t[]){0x1C}, 1, 0},
{0xC8, (uint8_t[]){0x62}, 1, 0},
{0xC9, (uint8_t[]){0x1C}, 1, 0},
{0xCA, (uint8_t[]){0x29}, 1, 0},
{0xCB, (uint8_t[]){0x60}, 1, 0},
{0xCC, (uint8_t[]){0x16}, 1, 0},
{0xCD, (uint8_t[]){0x17}, 1, 0},
{0xCE, (uint8_t[]){0x4A}, 1, 0},
{0xCF, (uint8_t[]){0x23}, 1, 0},
{0xD0, (uint8_t[]){0x24}, 1, 0},
{0xD1, (uint8_t[]){0x4F}, 1, 0},
{0xD2, (uint8_t[]){0x5F}, 1, 0},
{0xD3, (uint8_t[]){0x39}, 1, 0},
/**** CMD_Page 0 ****/
{0xFF, (uint8_t[]){0x98, 0x81, 0x00}, 3, 0},
{0x35, (uint8_t[]){0x00}, 0, 0},
// {0x11, (uint8_t []){0x00}, 0},
{0xFE, (uint8_t[]){0x00}, 0, 0},
{0x29, (uint8_t[]){0x00}, 0, 0},
//============ Gamma END===========
};
#endif // _BOARD_CONFIG_H_

View File

@@ -0,0 +1,330 @@
#include "wifi_board.h"
#include "tab5_audio_codec.h"
#include "display/lcd_display.h"
#include "esp_lcd_ili9881c.h"
#include "font_awesome_symbols.h"
#include "font_emoji.h"
#include "application.h"
#include "button.h"
#include "config.h"
#include "iot/thing_manager.h"
#include <esp_log.h>
#include "esp_lcd_mipi_dsi.h"
#include "esp_lcd_panel_ops.h"
#include "esp_ldo_regulator.h"
#include <esp_lcd_panel_vendor.h>
#include <driver/i2c_master.h>
#include <driver/spi_common.h>
#include <wifi_station.h>
#include "i2c_device.h"
#include "esp_lcd_touch_gt911.h"
#include <cstring>
#define TAG "M5StackTab5Board"
LV_FONT_DECLARE(font_puhui_30_4);
LV_FONT_DECLARE(font_awesome_30_4);
#define AUDIO_CODEC_ES8388_ADDR ES8388_CODEC_DEFAULT_ADDR
#define LCD_MIPI_DSI_PHY_PWR_LDO_CHAN 3 // LDO_VO3 is connected to VDD_MIPI_DPHY
#define LCD_MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV 2500
// PI4IO registers
#define PI4IO_REG_CHIP_RESET 0x01
#define PI4IO_REG_IO_DIR 0x03
#define PI4IO_REG_OUT_SET 0x05
#define PI4IO_REG_OUT_H_IM 0x07
#define PI4IO_REG_IN_DEF_STA 0x09
#define PI4IO_REG_PULL_EN 0x0B
#define PI4IO_REG_PULL_SEL 0x0D
#define PI4IO_REG_IN_STA 0x0F
#define PI4IO_REG_INT_MASK 0x11
#define PI4IO_REG_IRQ_STA 0x13
class Pi4ioe1 : public I2cDevice {
public:
Pi4ioe1(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr)
{
WriteReg(PI4IO_REG_CHIP_RESET, 0xFF);
uint8_t data = ReadReg(PI4IO_REG_CHIP_RESET);
WriteReg(PI4IO_REG_IO_DIR, 0b01111111); // 0: input 1: output
WriteReg(PI4IO_REG_OUT_H_IM, 0b00000000); // 使用到的引脚关闭 High-Impedance
WriteReg(PI4IO_REG_PULL_SEL, 0b01111111); // pull up/down select, 0 down, 1 up
WriteReg(PI4IO_REG_PULL_EN, 0b01111111); // pull up/down enable, 0 disable, 1 enable
WriteReg(PI4IO_REG_IN_DEF_STA, 0b10000000); // P1, P7 默认高电平
WriteReg(PI4IO_REG_INT_MASK, 0b01111111); // P7 中断使能 0 enable, 1 disable
WriteReg(PI4IO_REG_OUT_SET, 0b01110110); // Output Port Register P1(SPK_EN), P2(EXT5V_EN), P4(LCD_RST), P5(TP_RST), P6(CAM)RST 输出高电平
}
};
class Pi4ioe2 : public I2cDevice {
public:
Pi4ioe2(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr)
{
WriteReg(PI4IO_REG_CHIP_RESET, 0xFF);
uint8_t data = ReadReg(PI4IO_REG_CHIP_RESET);
WriteReg(PI4IO_REG_IO_DIR, 0b10111001); // 0: input 1: output
WriteReg(PI4IO_REG_OUT_H_IM, 0b00000110); // 使用到的引脚关闭 High-Impedance
WriteReg(PI4IO_REG_PULL_SEL, 0b10111001); // pull up/down select, 0 down, 1 up
WriteReg(PI4IO_REG_PULL_EN, 0b11111001); // pull up/down enable, 0 disable, 1 enable
WriteReg(PI4IO_REG_IN_DEF_STA, 0b01000000); // P6 默认高电平
WriteReg(PI4IO_REG_INT_MASK, 0b10111111); // P6 中断使能 0 enable, 1 disable
WriteReg(PI4IO_REG_OUT_SET, 0b10001001); // Output Port Register P0(WLAN_PWR_EN), P3(USB5V_EN), P7(CHG_EN) 输出高电平
}
};
class M5StackTab5Board : public WifiBoard {
private:
i2c_master_bus_handle_t i2c_bus_;
Button boot_button_;
LcdDisplay* display_;
Pi4ioe1* pi4ioe1_;
Pi4ioe2* pi4ioe2_;
esp_lcd_touch_handle_t touch_ = nullptr;
void InitializeI2c()
{
// Initialize I2C peripheral
i2c_master_bus_config_t i2c_bus_cfg = {
.i2c_port = (i2c_port_t)1,
.sda_io_num = AUDIO_CODEC_I2C_SDA_PIN,
.scl_io_num = AUDIO_CODEC_I2C_SCL_PIN,
.clk_source = I2C_CLK_SRC_DEFAULT,
.glitch_ignore_cnt = 7,
.intr_priority = 0,
.trans_queue_depth = 0,
.flags = {
.enable_internal_pullup = 1,
},
};
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
}
void I2cDetect()
{
uint8_t address;
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n");
for (int i = 0; i < 128; i += 16) {
printf("%02x: ", i);
for (int j = 0; j < 16; j++) {
fflush(stdout);
address = i + j;
esp_err_t ret = i2c_master_probe(i2c_bus_, address, pdMS_TO_TICKS(200));
if (ret == ESP_OK) {
printf("%02x ", address);
} else if (ret == ESP_ERR_TIMEOUT) {
printf("UU ");
} else {
printf("-- ");
}
}
printf("\r\n");
}
}
void InitializePi4ioe()
{
ESP_LOGI(TAG, "Init I/O Exapander PI4IOE");
pi4ioe1_ = new Pi4ioe1(i2c_bus_, 0x43);
pi4ioe2_ = new Pi4ioe2(i2c_bus_, 0x44);
}
void InitializeButtons()
{
boot_button_.OnClick([this]() {
auto& app = Application::GetInstance();
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
// ResetWifiConfiguration();
}
app.ToggleChatState();
});
}
void InitializeGt911TouchPad() {
ESP_LOGI(TAG, "Init GT911");
/* Initialize Touch Panel */
ESP_LOGI(TAG, "Initialize touch IO (I2C)");
const esp_lcd_touch_config_t tp_cfg = {
.x_max = DISPLAY_WIDTH,
.y_max = DISPLAY_HEIGHT,
.rst_gpio_num = GPIO_NUM_NC,
.int_gpio_num = TOUCH_INT_GPIO,
.levels = {
.reset = 0,
.interrupt = 0,
},
.flags = {
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
},
};
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG();
tp_io_config.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP; // 更改 GT911 地址
tp_io_config.scl_speed_hz = 100000;
esp_lcd_new_panel_io_i2c(i2c_bus_, &tp_io_config, &tp_io_handle);
esp_lcd_touch_new_i2c_gt911(tp_io_handle, &tp_cfg, &touch_);
// 检测不到触摸?待更换设备测试
// /* read data test */
// for (uint8_t i = 0; i < 50; i++) {
// esp_lcd_touch_read_data(touch_);
// if (touch_->data.points > 0) {
// printf("\ntouch: %d, %d\n", touch_->data.coords[0].x, touch_->data.coords[0].y);
// }
// vTaskDelay(pdMS_TO_TICKS(100));
// }
}
void InitializeSpi() {
spi_bus_config_t buscfg = {};
buscfg.mosi_io_num = GPIO_NUM_37;
buscfg.miso_io_num = GPIO_NUM_NC;
buscfg.sclk_io_num = GPIO_NUM_36;
buscfg.quadwp_io_num = GPIO_NUM_NC;
buscfg.quadhd_io_num = GPIO_NUM_NC;
buscfg.max_transfer_sz = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint16_t);
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
}
void InitializeIli9881cDisplay()
{
esp_lcd_panel_io_handle_t panel_io = nullptr;
esp_lcd_panel_handle_t panel = nullptr;
ESP_LOGI(TAG, "Turn on the power for MIPI DSI PHY");
esp_ldo_channel_handle_t ldo_mipi_phy = NULL;
esp_ldo_channel_config_t ldo_mipi_phy_config = {
.chan_id = LCD_MIPI_DSI_PHY_PWR_LDO_CHAN,
.voltage_mv = LCD_MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV,
};
ESP_ERROR_CHECK(esp_ldo_acquire_channel(&ldo_mipi_phy_config, &ldo_mipi_phy));
ESP_LOGI(TAG, "Install MIPI DSI LCD control panel");
esp_lcd_dsi_bus_handle_t mipi_dsi_bus;
esp_lcd_dsi_bus_config_t bus_config = {
.bus_id = 0,
.num_data_lanes = 2,
.phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT,
.lane_bit_rate_mbps = 900, // 900MHz
};
ESP_ERROR_CHECK(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus));
ESP_LOGI(TAG, "Install panel IO");
esp_lcd_dbi_io_config_t dbi_config = {
.virtual_channel = 0,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &panel_io));
ESP_LOGI(TAG, "Install LCD driver of ili9881c");
esp_lcd_dpi_panel_config_t dpi_config = {.virtual_channel = 0,
.dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT,
.dpi_clock_freq_mhz = 60,
.pixel_format = LCD_COLOR_PIXEL_FORMAT_RGB565,
.num_fbs = 2,
.video_timing =
{
.h_size = DISPLAY_WIDTH,
.v_size = DISPLAY_HEIGHT,
.hsync_pulse_width = 40,
.hsync_back_porch = 140,
.hsync_front_porch = 40,
.vsync_pulse_width = 4,
.vsync_back_porch = 20,
.vsync_front_porch = 20,
},
.flags = {
.use_dma2d = false,
}};
ili9881c_vendor_config_t vendor_config = {
.init_cmds = tab5_lcd_ili9881c_specific_init_code_default,
.init_cmds_size = sizeof(tab5_lcd_ili9881c_specific_init_code_default) /
sizeof(tab5_lcd_ili9881c_specific_init_code_default[0]),
.mipi_config =
{
.dsi_bus = mipi_dsi_bus,
.dpi_config = &dpi_config,
.lane_num = 2,
},
};
esp_lcd_panel_dev_config_t lcd_dev_config = {};
lcd_dev_config.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB;
lcd_dev_config.reset_gpio_num = -1;
lcd_dev_config.bits_per_pixel = 16;
lcd_dev_config.vendor_config = &vendor_config;
ESP_ERROR_CHECK(esp_lcd_new_panel_ili9881c(panel_io, &lcd_dev_config, &panel));
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel));
ESP_ERROR_CHECK(esp_lcd_panel_init(panel));
// ESP_ERROR_CHECK(esp_lcd_panel_mirror(disp_panel, false, true));
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel, true));
display_ = new MipiLcdDisplay(panel_io, panel, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X,
DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
{
.text_font = &font_puhui_30_4,
.icon_font = &font_awesome_30_4,
.emoji_font = font_emoji_64_init(),
});
}
// 物联网初始化,添加对 AI 可见设备
void InitializeIot() {
auto& thing_manager = iot::ThingManager::GetInstance();
thing_manager.AddThing(iot::CreateThing("Speaker"));
thing_manager.AddThing(iot::CreateThing("Screen"));
}
public:
M5StackTab5Board() : boot_button_(BOOT_BUTTON_GPIO)
{
InitializeI2c();
I2cDetect();
InitializePi4ioe();
InitializeGt911TouchPad();
InitializeIli9881cDisplay();
InitializeButtons();
InitializeIot();
GetBacklight()->RestoreBrightness();
}
virtual AudioCodec* GetAudioCodec() override
{
static Tab5AudioCodec audio_codec(i2c_bus_,
AUDIO_INPUT_SAMPLE_RATE,
AUDIO_OUTPUT_SAMPLE_RATE,
AUDIO_I2S_GPIO_MCLK,
AUDIO_I2S_GPIO_BCLK,
AUDIO_I2S_GPIO_WS,
AUDIO_I2S_GPIO_DOUT,
AUDIO_I2S_GPIO_DIN,
AUDIO_CODEC_PA_PIN,
AUDIO_CODEC_ES8388_ADDR,
AUDIO_CODEC_ES7210_ADDR,
AUDIO_INPUT_REFERENCE);
return &audio_codec;
}
virtual Display* GetDisplay() override
{
return display_;
}
virtual Backlight* GetBacklight() override
{
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
return &backlight;
}
};
DECLARE_BOARD(M5StackTab5Board);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,244 @@
#include "tab5_audio_codec.h"
#include <esp_log.h>
#include <driver/i2c.h>
#include <driver/i2s_tdm.h>
static const char TAG[] = "Tab5AudioCodec";
Tab5AudioCodec::Tab5AudioCodec(void* i2c_master_handle, int input_sample_rate, int output_sample_rate,
gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din,
gpio_num_t pa_pin, uint8_t es8388_addr, uint8_t es7210_addr, bool input_reference) {
duplex_ = true; // 是否双工
input_reference_ = input_reference; // 是否使用参考输入,实现回声消除
input_channels_ = input_reference_ ? 2 : 1; // 输入通道数
input_sample_rate_ = input_sample_rate;
output_sample_rate_ = output_sample_rate;
CreateDuplexChannels(mclk, bclk, ws, dout, din);
// Do initialize of related interface: data_if, ctrl_if and gpio_if
audio_codec_i2s_cfg_t i2s_cfg = {
.port = I2S_NUM_0,
.rx_handle = rx_handle_,
.tx_handle = tx_handle_,
};
data_if_ = audio_codec_new_i2s_data(&i2s_cfg);
assert(data_if_ != NULL);
// Output
audio_codec_i2c_cfg_t i2c_cfg = {
.port = (i2c_port_t)1,
.addr = es8388_addr,
.bus_handle = i2c_master_handle,
};
out_ctrl_if_ = audio_codec_new_i2c_ctrl(&i2c_cfg);
assert(out_ctrl_if_ != NULL);
gpio_if_ = audio_codec_new_gpio();
assert(gpio_if_ != NULL);
es8388_codec_cfg_t es8388_cfg = {};
es8388_cfg.ctrl_if = out_ctrl_if_;
es8388_cfg.gpio_if = gpio_if_;
es8388_cfg.codec_mode = ESP_CODEC_DEV_WORK_MODE_DAC;
es8388_cfg.master_mode = true;
es8388_cfg.pa_pin = -1; // PI4IOE1 P1 控制
es8388_cfg.pa_reverted = false;
es8388_cfg.hw_gain.pa_voltage = 5.0;
es8388_cfg.hw_gain.codec_dac_voltage = 3.3;
out_codec_if_ = es8388_codec_new(&es8388_cfg);
assert(out_codec_if_ != NULL);
esp_codec_dev_cfg_t dev_cfg = {
.dev_type = ESP_CODEC_DEV_TYPE_OUT,
.codec_if = out_codec_if_,
.data_if = data_if_,
};
output_dev_ = esp_codec_dev_new(&dev_cfg);
assert(output_dev_ != NULL);
// Input
i2c_cfg.addr = es7210_addr;
in_ctrl_if_ = audio_codec_new_i2c_ctrl(&i2c_cfg);
assert(in_ctrl_if_ != NULL);
es7210_codec_cfg_t es7210_cfg = {};
es7210_cfg.ctrl_if = in_ctrl_if_;
es7210_cfg.mic_selected = ES7120_SEL_MIC1 | ES7120_SEL_MIC2 | ES7120_SEL_MIC3 | ES7120_SEL_MIC4;
in_codec_if_ = es7210_codec_new(&es7210_cfg);
assert(in_codec_if_ != NULL);
dev_cfg.dev_type = ESP_CODEC_DEV_TYPE_IN;
dev_cfg.codec_if = in_codec_if_;
input_dev_ = esp_codec_dev_new(&dev_cfg);
assert(input_dev_ != NULL);
ESP_LOGI(TAG, "Tab5 AudioDevice initialized");
}
Tab5AudioCodec::~Tab5AudioCodec() {
ESP_ERROR_CHECK(esp_codec_dev_close(output_dev_));
esp_codec_dev_delete(output_dev_);
ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_));
esp_codec_dev_delete(input_dev_);
audio_codec_delete_codec_if(in_codec_if_);
audio_codec_delete_ctrl_if(in_ctrl_if_);
audio_codec_delete_codec_if(out_codec_if_);
audio_codec_delete_ctrl_if(out_ctrl_if_);
audio_codec_delete_gpio_if(gpio_if_);
audio_codec_delete_data_if(data_if_);
}
void Tab5AudioCodec::CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din) {
assert(input_sample_rate_ == output_sample_rate_);
i2s_chan_config_t chan_cfg = {
.id = I2S_NUM_0,
.role = I2S_ROLE_MASTER,
.dma_desc_num = 6,
.dma_frame_num = 240,
.auto_clear_after_cb = true,
.auto_clear_before_cb = false,
.intr_priority = 0,
};
ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, &tx_handle_, &rx_handle_));
i2s_std_config_t std_cfg = {
.clk_cfg = {
.sample_rate_hz = (uint32_t)output_sample_rate_,
.clk_src = I2S_CLK_SRC_DEFAULT,
.ext_clk_freq_hz = 0,
.mclk_multiple = I2S_MCLK_MULTIPLE_256
},
.slot_cfg = {
.data_bit_width = I2S_DATA_BIT_WIDTH_16BIT,
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO,
.slot_mode = I2S_SLOT_MODE_STEREO,
.slot_mask = I2S_STD_SLOT_BOTH,
.ws_width = I2S_DATA_BIT_WIDTH_16BIT,
.ws_pol = false,
.bit_shift = true,
.left_align = true,
.big_endian = false,
.bit_order_lsb = false
},
.gpio_cfg = {
.mclk = mclk,
.bclk = bclk,
.ws = ws,
.dout = dout,
.din = I2S_GPIO_UNUSED,
.invert_flags = {
.mclk_inv = false,
.bclk_inv = false,
.ws_inv = false
}
}
};
i2s_tdm_config_t tdm_cfg = {
.clk_cfg = {
.sample_rate_hz = (uint32_t)input_sample_rate_,
.clk_src = I2S_CLK_SRC_DEFAULT,
.ext_clk_freq_hz = 0,
.mclk_multiple = I2S_MCLK_MULTIPLE_256,
.bclk_div = 8,
},
.slot_cfg = {
.data_bit_width = I2S_DATA_BIT_WIDTH_16BIT,
.slot_bit_width = I2S_SLOT_BIT_WIDTH_AUTO,
.slot_mode = I2S_SLOT_MODE_STEREO,
.slot_mask = i2s_tdm_slot_mask_t(I2S_TDM_SLOT0 | I2S_TDM_SLOT1 | I2S_TDM_SLOT2 | I2S_TDM_SLOT3),
.ws_width = I2S_TDM_AUTO_WS_WIDTH,
.ws_pol = false,
.bit_shift = true,
.left_align = false,
.big_endian = false,
.bit_order_lsb = false,
.skip_mask = false,
.total_slot = I2S_TDM_AUTO_SLOT_NUM
},
.gpio_cfg = {
.mclk = mclk,
.bclk = bclk,
.ws = ws,
.dout = I2S_GPIO_UNUSED,
.din = din,
.invert_flags = {
.mclk_inv = false,
.bclk_inv = false,
.ws_inv = false
}
}
};
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_tdm_mode(rx_handle_, &tdm_cfg));
ESP_LOGI(TAG, "Duplex channels created");
}
void Tab5AudioCodec::SetOutputVolume(int volume) {
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(output_dev_, volume));
AudioCodec::SetOutputVolume(volume);
}
void Tab5AudioCodec::EnableInput(bool enable) {
if (enable == input_enabled_) {
return;
}
if (enable) {
esp_codec_dev_sample_info_t fs = {
.bits_per_sample = 16,
.channel = 4,
.channel_mask = ESP_CODEC_DEV_MAKE_CHANNEL_MASK(0),
.sample_rate = (uint32_t)output_sample_rate_,
.mclk_multiple = 0,
};
if (input_reference_) {
fs.channel_mask |= ESP_CODEC_DEV_MAKE_CHANNEL_MASK(1);
}
ESP_ERROR_CHECK(esp_codec_dev_open(input_dev_, &fs));
ESP_ERROR_CHECK(esp_codec_dev_set_in_channel_gain(input_dev_, ESP_CODEC_DEV_MAKE_CHANNEL_MASK(0), 40.0));
} else {
ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_));
}
AudioCodec::EnableInput(enable);
}
void Tab5AudioCodec::EnableOutput(bool enable) {
if (enable == output_enabled_) {
return;
}
if (enable) {
// Play 16bit 1 channel
esp_codec_dev_sample_info_t fs = {
.bits_per_sample = 16,
.channel = 1,
.channel_mask = 0,
.sample_rate = (uint32_t)output_sample_rate_,
.mclk_multiple = 0,
};
ESP_ERROR_CHECK(esp_codec_dev_open(output_dev_, &fs));
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(output_dev_, output_volume_));
} else {
ESP_ERROR_CHECK(esp_codec_dev_close(output_dev_));
}
AudioCodec::EnableOutput(enable);
}
int Tab5AudioCodec::Read(int16_t* dest, int samples) {
if (input_enabled_) {
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_codec_dev_read(input_dev_, (void*)dest, samples * sizeof(int16_t)));
}
return samples;
}
int Tab5AudioCodec::Write(const int16_t* data, int samples) {
if (output_enabled_) {
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_codec_dev_write(output_dev_, (void*)data, samples * sizeof(int16_t)));
}
return samples;
}

View File

@@ -0,0 +1,37 @@
#ifndef _TAB5_AUDIO_CODEC_H
#define _TAB5_AUDIO_CODEC_H
#include "audio_codec.h"
#include <esp_codec_dev.h>
#include <esp_codec_dev_defaults.h>
class Tab5AudioCodec : public AudioCodec {
private:
const audio_codec_data_if_t* data_if_ = nullptr;
const audio_codec_ctrl_if_t* out_ctrl_if_ = nullptr;
const audio_codec_if_t* out_codec_if_ = nullptr;
const audio_codec_ctrl_if_t* in_ctrl_if_ = nullptr;
const audio_codec_if_t* in_codec_if_ = nullptr;
const audio_codec_gpio_if_t* gpio_if_ = nullptr;
esp_codec_dev_handle_t output_dev_ = nullptr;
esp_codec_dev_handle_t input_dev_ = nullptr;
void CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din);
virtual int Read(int16_t* dest, int samples) override;
virtual int Write(const int16_t* data, int samples) override;
public:
Tab5AudioCodec(void* i2c_master_handle, int input_sample_rate, int output_sample_rate,
gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din,
gpio_num_t pa_pin, uint8_t es8388_addr, uint8_t es7210_addr, bool input_reference);
virtual ~Tab5AudioCodec();
virtual void SetOutputVolume(int volume) override;
virtual void EnableInput(bool enable) override;
virtual void EnableOutput(bool enable) override;
};
#endif // _TAB5_AUDIO_CODEC_H

View File

@@ -1,42 +1,43 @@
## IDF Component Manager Manifest File
dependencies:
waveshare/esp_lcd_sh8601: "1.0.2"
espressif/esp_lcd_ili9341: "==1.2.0"
espressif/esp_lcd_gc9a01: "==2.0.1"
espressif/esp_lcd_st77916: "^1.0.1"
espressif/esp_lcd_st7796: "==1.3.2"
espressif/esp_lcd_spd2010: "==1.0.2"
espressif/esp_io_expander_tca9554: "==2.0.0"
espressif/esp_lcd_panel_io_additions: "^1.0.1"
78/esp_lcd_nv3023: "~1.0.0"
78/esp-wifi-connect: "~2.4.2"
78/esp-opus-encoder: "~2.3.2"
78/esp-ml307: "~2.0.0"
78/xiaozhi-fonts: "~1.3.2"
espressif/led_strip: "^2.5.5"
espressif/esp_codec_dev: "~1.3.2"
espressif/esp-sr: "~2.1.1"
espressif/button: "~4.1.3"
espressif/knob: "^1.0.0"
espressif/esp_lcd_touch_ft5x06: "~1.0.7"
espressif/esp_lcd_touch_gt911: "^1"
lvgl/lvgl: "~9.2.2"
esp_lvgl_port: "~2.6.0"
espressif/esp_io_expander_tca95xx_16bit: "^2.0.0"
waveshare/esp_lcd_sh8601: 1.0.2
espressif/esp_lcd_ili9341: ==1.2.0
espressif/esp_lcd_gc9a01: ==2.0.1
espressif/esp_lcd_st77916: ^1.0.1
espressif/esp_lcd_st7796: ==1.3.2
espressif/esp_lcd_spd2010: ==1.0.2
espressif/esp_io_expander_tca9554: ==2.0.0
espressif/esp_lcd_panel_io_additions: ^1.0.1
78/esp_lcd_nv3023: ~1.0.0
78/esp-wifi-connect: ~2.4.2
78/esp-opus-encoder: ~2.3.2
78/esp-ml307: ~2.0.0
78/xiaozhi-fonts: ~1.3.2
espressif/led_strip: ^2.5.5
espressif/esp_codec_dev: ~1.3.2
espressif/esp-sr: ~2.1.1
espressif/button: ~4.1.3
espressif/knob: ^1.0.0
espressif/esp_lcd_touch_ft5x06: ~1.0.7
espressif/esp_lcd_touch_gt911: ^1
lvgl/lvgl: ~9.2.2
esp_lvgl_port: ~2.6.0
espressif/esp_io_expander_tca95xx_16bit: ^2.0.0
tny-robotics/sh1106-esp-idf:
version: "^1.0.0"
version: ^1.0.0
rules:
- if: 'idf_version >= "5.4.0"'
- if: idf_version >= "5.4.0"
waveshare/esp_lcd_jd9365_10_1:
version: "*"
version: '*'
rules:
- if: "target in [esp32p4]"
- if: target in [esp32p4]
espressif/esp_wifi_remote:
version: "*"
version: '*'
rules:
- if: "target in [esp32p4]"
- if: target in [esp32p4]
## Required IDF version
idf:
version: ">=5.3"
version: '>=5.3'
espressif/esp_lcd_ili9881c: ^1.0.1