Initial commit

This commit is contained in:
2026-04-26 21:35:04 +08:00
commit da6ca1b09a
1483 changed files with 115719 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
# 使用说明
* [M5Stack Tab5 docs](https://docs.m5stack.com/zh_CN/core/Tab5)
## 快速体验
到 [M5Burner](https://docs.m5stack.com/zh_CN/uiflow/m5burner/intro) 选择 Tab5 搜索小智下载固件
## 基础使用
* idf version: v6.0-dev
1. 调整 idf_component.yml
```yaml
espressif/esp_video:
version: ==1.3.1 # for compatibility. update version may need to modify this project code.
rules:
- if: target not in [esp32]
```
修改为
```yaml
espressif/esp_video:
version: '==0.7.0'
rules:
- if: target not in [esp32]
espressif/esp_ipa: '==0.1.0'
```
* idf version: v5.5.3
针对 ESP32-P4 Rev <3.0 用户:
确保你的 sdkconfig.defaults 包含:
CONFIG_ESP32P4_SELECTS_REV_LESS_V3=y
否则烧写的时候会出现:'bootloader/bootloader.bin' requires chip revision in range [v3.0 - v3.99] (this chip is revision v1.x)
2. 使用 release.py 编译
```shell
python ./scripts/release.py m5stack-tab5
```
如需手动编译,请参考 `m5stack-tab5/config.json` 修改 menuconfig 对应选项。
3. 编译烧录程序
```shell
idf.py flash monitor
```
> [!NOTE]
> 进入下载模式:长按复位按键(约 2 秒),直至内部绿色 LED 指示灯开始快速闪烁,松开按键。
## log
@2025/05/17 测试问题
1. listening... 需要等几秒才能获取语音输入???
2. 亮度调节不对
3. 音量调节不对
## TODO

View File

@@ -0,0 +1,325 @@
#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 CAMERA_SCL GPIO_NUM_32
#define CAMERA_SDA GPIO_NUM_31
#define CAMERA_MCLK GPIO_NUM_36
/* ---------------------------------------------------------------- */
// 显示屏相关参数配置
#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 false
#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===========
};
// ST7123 vendor specific initialization commands
const st7123_lcd_init_cmd_t st7123_vendor_specific_init_default[] = {
{0x60, (uint8_t[]){0x71, 0x23, 0xa2}, 3, 0},
{0x60, (uint8_t[]){0x71, 0x23, 0xa3}, 3, 0},
{0x60, (uint8_t[]){0x71, 0x23, 0xa4}, 3, 0},
{0xA4, (uint8_t[]){0x31}, 1, 0},
{0xD7, (uint8_t[]){0x10, 0x0A, 0x10, 0x2A, 0x80, 0x80}, 6, 0},
{0x90, (uint8_t[]){0x71, 0x23, 0x5A, 0x20, 0x24, 0x09, 0x09}, 7, 0},
{0xA3, (uint8_t[]){0x80, 0x01, 0x88, 0x30, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00,
0x1E, 0x5C, 0x1E, 0x80, 0x00, 0x4F, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
0x00, 0x00, 0x1E, 0x5C, 0x1E, 0x80, 0x00, 0x6F, 0x58, 0x00, 0x00, 0x00, 0xFF},
40, 0},
{0xA6, (uint8_t[]){0x03, 0x00, 0x24, 0x55, 0x36, 0x00, 0x39, 0x00, 0x6E, 0x6E, 0x91, 0xFF, 0x00, 0x24,
0x55, 0x38, 0x00, 0x37, 0x00, 0x6E, 0x6E, 0x91, 0xFF, 0x00, 0x24, 0x11, 0x00, 0x00,
0x00, 0x00, 0x6E, 0x6E, 0x91, 0xFF, 0x00, 0xEC, 0x11, 0x00, 0x03, 0x00, 0x03, 0x6E,
0x6E, 0xFF, 0xFF, 0x00, 0x08, 0x80, 0x08, 0x80, 0x06, 0x00, 0x00, 0x00, 0x00},
55, 0},
{0xA7, (uint8_t[]){0x19, 0x19, 0x80, 0x64, 0x40, 0x07, 0x16, 0x40, 0x00, 0x44, 0x03, 0x6E, 0x6E, 0x91, 0xFF,
0x08, 0x80, 0x64, 0x40, 0x25, 0x34, 0x40, 0x00, 0x02, 0x01, 0x6E, 0x6E, 0x91, 0xFF, 0x08,
0x80, 0x64, 0x40, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x6E, 0x6E, 0x91, 0xFF, 0x08, 0x80,
0x64, 0x40, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x6E, 0x6E, 0x84, 0xFF, 0x08, 0x80, 0x44},
60, 0},
{0xAC, (uint8_t[]){0x03, 0x19, 0x19, 0x18, 0x18, 0x06, 0x13, 0x13, 0x11, 0x11, 0x08, 0x08, 0x0A, 0x0A, 0x1C,
0x1C, 0x07, 0x07, 0x00, 0x00, 0x02, 0x02, 0x01, 0x19, 0x19, 0x18, 0x18, 0x06, 0x12, 0x12,
0x10, 0x10, 0x09, 0x09, 0x0B, 0x0B, 0x1C, 0x1C, 0x07, 0x07, 0x03, 0x03, 0x01, 0x01},
44, 0},
{0xAD, (uint8_t[]){0xF0, 0x00, 0x46, 0x00, 0x03, 0x50, 0x50, 0xFF, 0xFF, 0xF0, 0x40, 0x06, 0x01,
0x07, 0x42, 0x42, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF},
25, 0},
{0xAE, (uint8_t[]){0xFE, 0x3F, 0x3F, 0xFE, 0x3F, 0x3F, 0x00}, 7, 0},
{0xB2,
(uint8_t[]){0x15, 0x19, 0x05, 0x23, 0x49, 0xAF, 0x03, 0x2E, 0x5C, 0xD2, 0xFF, 0x10, 0x20, 0xFD, 0x20, 0xC0, 0x00},
17, 0},
{0xE8, (uint8_t[]){0x20, 0x6F, 0x04, 0x97, 0x97, 0x3E, 0x04, 0xDC, 0xDC, 0x3E, 0x06, 0xFA, 0x26, 0x3E}, 15, 0},
{0x75, (uint8_t[]){0x03, 0x04}, 2, 0},
{0xE7, (uint8_t[]){0x3B, 0x00, 0x00, 0x7C, 0xA1, 0x8C, 0x20, 0x1A, 0xF0, 0xB1, 0x50, 0x00,
0x50, 0xB1, 0x50, 0xB1, 0x50, 0xD8, 0x00, 0x55, 0x00, 0xB1, 0x00, 0x45,
0xC9, 0x6A, 0xFF, 0x5A, 0xD8, 0x18, 0x88, 0x15, 0xB1, 0x01, 0x01, 0x77},
36, 0},
{0xEA, (uint8_t[]){0x13, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x2C}, 8, 0},
{0xB0, (uint8_t[]){0x22, 0x43, 0x11, 0x61, 0x25, 0x43, 0x43}, 7, 0},
{0xb7, (uint8_t[]){0x00, 0x00, 0x73, 0x73}, 4, 0},
{0xBF, (uint8_t[]){0xA6, 0xAA}, 2, 0},
{0xA9, (uint8_t[]){0x00, 0x00, 0x73, 0xFF, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03}, 10, 0},
{0xC8, (uint8_t[]){0x00, 0x00, 0x10, 0x1F, 0x36, 0x00, 0x5D, 0x04, 0x9D, 0x05, 0x10, 0xF2, 0x06,
0x60, 0x03, 0x11, 0xAD, 0x00, 0xEF, 0x01, 0x22, 0x2E, 0x0E, 0x74, 0x08, 0x32,
0xDC, 0x09, 0x33, 0x0F, 0xF3, 0x77, 0x0D, 0xB0, 0xDC, 0x03, 0xFF},
37, 0},
{0xC9, (uint8_t[]){0x00, 0x00, 0x10, 0x1F, 0x36, 0x00, 0x5D, 0x04, 0x9D, 0x05, 0x10, 0xF2, 0x06,
0x60, 0x03, 0x11, 0xAD, 0x00, 0xEF, 0x01, 0x22, 0x2E, 0x0E, 0x74, 0x08, 0x32,
0xDC, 0x09, 0x33, 0x0F, 0xF3, 0x77, 0x0D, 0xB0, 0xDC, 0x03, 0xFF},
37, 0},
{0x36, (uint8_t[]){0x00}, 1, 0},
{0x11, (uint8_t[]){0x00}, 1, 100},
{0x29, (uint8_t[]){0x00}, 1, 0},
{0x35, (uint8_t[]){0x00}, 1, 100},
};
#endif // _BOARD_CONFIG_H_

View File

@@ -0,0 +1,19 @@
{
"target": "esp32p4",
"builds": [
{
"name": "m5stack-tab5",
"sdkconfig_append": [
"CONFIG_BOARD_TYPE_M5STACK_CORE_TAB5=y",
"CONFIG_CAMERA_SC202CS=y",
"CONFIG_XIAOZHI_ENABLE_ROTATE_CAMERA_IMAGE=y",
"CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_1=13",
"CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_1=12",
"CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_1=11",
"CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D1_4BIT_BUS_SLOT_1=10",
"CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D2_4BIT_BUS_SLOT_1=9",
"CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D3_4BIT_BUS_SLOT_1=8"
]
}
]
}

View File

@@ -0,0 +1,381 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "soc/soc_caps.h"
#if SOC_MIPI_DSI_SUPPORTED
#include "esp_check.h"
#include "esp_log.h"
#include "esp_lcd_panel_commands.h"
#include "esp_lcd_panel_interface.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_mipi_dsi.h"
#include "esp_lcd_panel_vendor.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_lcd_st7123.h"
#define ST7123_PAD_CONTROL (0xB7)
#define ST7123_DSI_2_LANE (0x03)
#define ST7123_DSI_3_4_LANE (0x02)
#define ST7123_CMD_GS_BIT (1 << 0)
#define ST7123_CMD_SS_BIT (1 << 1)
typedef struct {
esp_lcd_panel_io_handle_t io;
int reset_gpio_num;
uint8_t madctl_val; // save current value of LCD_CMD_MADCTL register
uint8_t colmod_val; // save surrent value of LCD_CMD_COLMOD register
const st7123_lcd_init_cmd_t *init_cmds;
uint16_t init_cmds_size;
uint8_t lane_num;
struct {
unsigned int reset_level: 1;
} flags;
// To save the original functions of MIPI DPI panel
esp_err_t (*del)(esp_lcd_panel_t *panel);
esp_err_t (*init)(esp_lcd_panel_t *panel);
} st7123_panel_t;
static const char *TAG = "st7123";
static esp_err_t panel_st7123_del(esp_lcd_panel_t *panel);
static esp_err_t panel_st7123_init(esp_lcd_panel_t *panel);
static esp_err_t panel_st7123_reset(esp_lcd_panel_t *panel);
static esp_err_t panel_st7123_invert_color(esp_lcd_panel_t *panel, bool invert_color_data);
static esp_err_t panel_st7123_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
static esp_err_t panel_st7123_disp_on_off(esp_lcd_panel_t *panel, bool on_off);
static esp_err_t panel_st7123_sleep(esp_lcd_panel_t *panel, bool sleep);
esp_err_t esp_lcd_new_panel_st7123(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config,
esp_lcd_panel_handle_t *ret_panel)
{
ESP_RETURN_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, TAG, "invalid arguments");
st7123_vendor_config_t *vendor_config = (st7123_vendor_config_t *)panel_dev_config->vendor_config;
ESP_RETURN_ON_FALSE(vendor_config && vendor_config->mipi_config.dpi_config && vendor_config->mipi_config.dsi_bus, ESP_ERR_INVALID_ARG, TAG,
"invalid vendor config");
esp_err_t ret = ESP_OK;
st7123_panel_t *st7123 = (st7123_panel_t *)calloc(1, sizeof(st7123_panel_t));
ESP_RETURN_ON_FALSE(st7123, ESP_ERR_NO_MEM, TAG, "no mem for st7123 panel");
if (panel_dev_config->reset_gpio_num >= 0) {
gpio_config_t io_conf = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1ULL << panel_dev_config->reset_gpio_num,
};
ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err, TAG, "configure GPIO for RST line failed");
}
switch (panel_dev_config->rgb_ele_order) {
case LCD_RGB_ELEMENT_ORDER_RGB:
st7123->madctl_val = 0;
break;
case LCD_RGB_ELEMENT_ORDER_BGR:
st7123->madctl_val |= LCD_CMD_BGR_BIT;
break;
default:
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color space");
break;
}
switch (panel_dev_config->bits_per_pixel) {
case 16: // RGB565
st7123->colmod_val = 0x55;
break;
case 18: // RGB666
st7123->colmod_val = 0x66;
break;
case 24: // RGB888
st7123->colmod_val = 0x77;
break;
default:
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
break;
}
st7123->io = io;
st7123->init_cmds = vendor_config->init_cmds;
st7123->init_cmds_size = vendor_config->init_cmds_size;
st7123->lane_num = vendor_config->mipi_config.lane_num;
st7123->reset_gpio_num = panel_dev_config->reset_gpio_num;
st7123->flags.reset_level = panel_dev_config->flags.reset_active_high;
// Create MIPI DPI panel
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_dpi(vendor_config->mipi_config.dsi_bus, vendor_config->mipi_config.dpi_config, ret_panel), err, TAG,
"create MIPI DPI panel failed");
ESP_LOGD(TAG, "new MIPI DPI panel @%p", *ret_panel);
// Save the original functions of MIPI DPI panel
st7123->del = (*ret_panel)->del;
st7123->init = (*ret_panel)->init;
// Overwrite the functions of MIPI DPI panel
(*ret_panel)->del = panel_st7123_del;
(*ret_panel)->init = panel_st7123_init;
(*ret_panel)->reset = panel_st7123_reset;
(*ret_panel)->mirror = panel_st7123_mirror;
(*ret_panel)->invert_color = panel_st7123_invert_color;
(*ret_panel)->disp_on_off = panel_st7123_disp_on_off;
(*ret_panel)->disp_sleep = panel_st7123_sleep;
(*ret_panel)->user_data = st7123;
ESP_LOGD(TAG, "new st7123 panel @%p", st7123);
return ESP_OK;
err:
if (st7123) {
if (panel_dev_config->reset_gpio_num >= 0) {
gpio_reset_pin(panel_dev_config->reset_gpio_num);
}
free(st7123);
}
return ret;
}
static const st7123_lcd_init_cmd_t vendor_specific_init_default[] = {
// {cmd, { data }, data_size, delay_ms}
// TODO:
{0x60, (uint8_t []){0x71,0x23,0xa2}, 3, 0},
{0x60, (uint8_t []){0x71,0x23,0xa3}, 3, 0},
{0x60, (uint8_t []){0x71,0x23,0xa4}, 3, 0},
{0xA4, (uint8_t []){0x31}, 1, 0},
{0xD7, (uint8_t []){0x10,0x0A,0x10,0x2A,0x80,0x80}, 6, 0},
{0x90, (uint8_t []){0x71,0x23,0x5A,0x20,0x24,0x09,0x09}, 7, 0},
{0xA3, (uint8_t []){0x80,0x01,0x88,0x30,0x05,0x00,0x00,0x00,0x00,0x00,0x46,0x00,0x00,0x1E,0x5C,0x1E,0x80,0x00,0x4F,0x05,0x00,0x00,0x00,0x00,0x00,0x46,0x00,0x00,0x1E,0x5C,0x1E,0x80,0x00,0x6F,0x58,0x00,0x00,0x00,0xFF}, 40, 0},
{0xA6, (uint8_t []){0x03,0x00,0x24,0x55,0x36,0x00,0x39,0x00,0x6E,0x6E,0x91,0xFF,0x00,0x24,0x55,0x38,0x00,0x37,0x00,0x6E,0x6E,0x91,0xFF,0x00,0x24,0x11,0x00,0x00,0x00,0x00,0x6E,0x6E,0x91,0xFF,0x00,0xEC,0x11,0x00,0x03,0x00,0x03,0x6E,0x6E,0xFF,0xFF,0x00,0x08,0x80,0x08,0x80,0x06,0x00,0x00,0x00,0x00}, 55, 0},
{0xA7, (uint8_t []){0x19,0x19,0x80,0x64,0x40,0x07,0x16,0x40,0x00,0x44,0x03,0x6E,0x6E,0x91,0xFF,0x08,0x80,0x64,0x40,0x25,0x34,0x40,0x00,0x02,0x01,0x6E,0x6E,0x91,0xFF,0x08,0x80,0x64,0x40,0x00,0x00,0x40,0x00,0x00,0x00,0x6E,0x6E,0x91,0xFF,0x08,0x80,0x64,0x40,0x00,0x00,0x00,0x00,0x20,0x00,0x6E,0x6E,0x84,0xFF,0x08,0x80,0x44}, 60, 0},
{0xAC, (uint8_t []){0x03,0x19,0x19,0x18,0x18,0x06,0x13,0x13,0x11,0x11,0x08,0x08,0x0A,0x0A,0x1C,0x1C,0x07,0x07,0x00,0x00,0x02,0x02,0x01,0x19,0x19,0x18,0x18,0x06,0x12,0x12,0x10,0x10,0x09,0x09,0x0B,0x0B,0x1C,0x1C,0x07,0x07,0x03,0x03,0x01,0x01}, 44, 0},
{0xAD, (uint8_t []){0xF0,0x00,0x46,0x00,0x03,0x50,0x50,0xFF,0xFF,0xF0,0x40,0x06,0x01,0x07,0x42,0x42,0xFF,0xFF,0x01,0x00,0x00,0xFF,0xFF,0xFF,0xFF}, 25, 0},
{0xAE, (uint8_t []){0xFE,0x3F,0x3F,0xFE,0x3F,0x3F,0x00}, 7, 0},
{0xB2, (uint8_t []){0x15,0x19,0x05,0x23,0x49,0xAF,0x03,0x2E,0x5C,0xD2,0xFF,0x10,0x20,0xFD,0x20,0xC0,0x00}, 17, 0},
{0xE8, (uint8_t []){0x20,0x6F,0x04,0x97,0x97,0x3E,0x04,0xDC,0xDC,0x3E,0x06,0xFA,0x26,0x3E}, 15, 0},
{0x75, (uint8_t []){0x03,0x04}, 2, 0},
{0xE7, (uint8_t []){0x3B,0x00,0x00,0x7C,0xA1,0x8C,0x20,0x1A,0xF0,0xB1,0x50,0x00,0x50,0xB1,0x50,0xB1,0x50,0xD8,0x00,0x55,0x00,0xB1,0x00,0x45,0xC9,0x6A,0xFF,0x5A,0xD8,0x18,0x88,0x15,0xB1,0x01,0x01,0x77}, 36, 0},
{0xEA, (uint8_t []){0x13,0x00,0x04,0x00,0x00,0x00,0x00,0x2C}, 8, 0},
{0xB0, (uint8_t []){0x22,0x43,0x11,0x61,0x25,0x43,0x43}, 7, 0},
{0xb7, (uint8_t []){0x00,0x00,0x73,0x73}, 0x04, 0},
{0xBF, (uint8_t []){0xA6,0XAA}, 2, 0},
{0xA9, (uint8_t []){0x00,0x00,0x73,0xFF,0x00,0x00,0x03,0x00,0x00,0x03}, 10, 0},
{0xC8, (uint8_t []){0x00,0x00,0x10,0x1F,0x36,0x00,0x5D,0x04,0x9D,0x05,0x10,0xF2,0x06,0x60,0x03,0x11,0xAD,0x00,0xEF,0x01,0x22,0x2E,0x0E,0x74,0x08,0x32,0xDC,0x09,0x33,0x0F,0xF3,0x77,0x0D,0xB0,0xDC,0x03,0xFF}, 37, 0},
{0xC9, (uint8_t []){0x00,0x00,0x10,0x1F,0x36,0x00,0x5D,0x04,0x9D,0x05,0x10,0xF2,0x06,0x60,0x03,0x11,0xAD,0x00,0xEF,0x01,0x22,0x2E,0x0E,0x74,0x08,0x32,0xDC,0x09,0x33,0x0F,0xF3,0x77,0x0D,0xB0,0xDC,0x03,0xFF}, 37, 0},
{0x36, (uint8_t []){0x03}, 1, 0},
{0x11, (uint8_t []){0x00}, 1, 100},
{0x29, (uint8_t []){0x00}, 1, 0},
{0x35, (uint8_t []){0x00}, 1, 100},
//============ Gamma END===========
};
static esp_err_t panel_st7123_del(esp_lcd_panel_t *panel)
{
st7123_panel_t *st7123 = (st7123_panel_t *)panel->user_data;
if (st7123->reset_gpio_num >= 0) {
gpio_reset_pin(st7123->reset_gpio_num);
}
// Delete MIPI DPI panel
st7123->del(panel);
ESP_LOGD(TAG, "del st7123 panel @%p", st7123);
free(st7123);
return ESP_OK;
}
static esp_err_t panel_st7123_init(esp_lcd_panel_t *panel)
{
st7123_panel_t *st7123 = (st7123_panel_t *)panel->user_data;
esp_lcd_panel_io_handle_t io = st7123->io;
const st7123_lcd_init_cmd_t *init_cmds = NULL;
uint16_t init_cmds_size = 0;
// switch (st7123->lane_num) {
// case 0:
// case 2:
// lane_command = ST7123_DSI_2_LANE;
// break;
// case 3:
// case 4:
// lane_command = ST7123_DSI_3_4_LANE;
// break;
// default:
// ESP_LOGE(TAG, "Invalid lane number %d", st7123->lane_num);
// return ESP_ERR_INVALID_ARG;
// }
uint8_t ID[3];
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_rx_param(io, 0x04, ID, 3), TAG, "read ID failed");
ESP_LOGI(TAG, "LCD ID: %02X %02X %02X", ID[0], ID[1], ID[2]);
// // For modifying MIPI-DSI lane settings
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, ST7123_PAD_CONTROL, (uint8_t[]) {
// lane_command,
// }, 1), TAG, "send command failed");
// // back to CMD_Page 0
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, ST7123_CMD_CNDBKxSEL, (uint8_t[]) {
// ST7123_CMD_BKxSEL_BYTE0, ST7123_CMD_BKxSEL_BYTE1, ST7123_CMD_BKxSEL_BYTE2_PAGE0
// }, 3), TAG, "send command failed");
// // exit sleep mode
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT, NULL, 0), TAG,
// "io tx param failed");
// vTaskDelay(pdMS_TO_TICKS(120));
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t[]) {
// st7123->madctl_val,
// }, 1), TAG, "send command failed");
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]) {
// st7123->colmod_val,
// }, 1), TAG, "send command failed");
// vendor specific initialization, it can be different between manufacturers
// should consult the LCD supplier for initialization sequence code
if (st7123->init_cmds) {
init_cmds = st7123->init_cmds;
init_cmds_size = st7123->init_cmds_size;
} else {
init_cmds = vendor_specific_init_default;
init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(st7123_lcd_init_cmd_t);
}
for (int i = 0; i < init_cmds_size; i++) {
// Check if the command has been used or conflicts with the internal
// if (is_command0_enable && init_cmds[i].data_bytes > 0) {
// switch (init_cmds[i].cmd) {
// case LCD_CMD_MADCTL:
// is_cmd_overwritten = true;
// st7123->madctl_val = ((uint8_t *)init_cmds[i].data)[0];
// break;
// case LCD_CMD_COLMOD:
// is_cmd_overwritten = true;
// st7123->colmod_val = ((uint8_t *)init_cmds[i].data)[0];
// break;
// default:
// is_cmd_overwritten = false;
// break;
// }
// if (is_cmd_overwritten) {
// is_cmd_overwritten = false;
// ESP_LOGW(TAG, "The %02Xh command has been used and will be overwritten by external initialization sequence",
// init_cmds[i].cmd);
// }
// }
// Send command
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, init_cmds[i].cmd, init_cmds[i].data, init_cmds[i].data_bytes), TAG, "send command failed");
vTaskDelay(pdMS_TO_TICKS(init_cmds[i].delay_ms));
// if ((init_cmds[i].cmd == ST7123_CMD_CNDBKxSEL) && (((uint8_t *)init_cmds[i].data)[2] == ST7123_CMD_BKxSEL_BYTE2_PAGE0)) {
// is_command0_enable = true;
// } else if ((init_cmds[i].cmd == ST7123_CMD_CNDBKxSEL) && (((uint8_t *)init_cmds[i].data)[2] != ST7123_CMD_BKxSEL_BYTE2_PAGE0)) {
// is_command0_enable = false;
// }
}
ESP_LOGD(TAG, "send init commands success");
ESP_RETURN_ON_ERROR(st7123->init(panel), TAG, "init MIPI DPI panel failed");
return ESP_OK;
}
static esp_err_t panel_st7123_reset(esp_lcd_panel_t *panel)
{
st7123_panel_t *st7123 = (st7123_panel_t *)panel->user_data;
esp_lcd_panel_io_handle_t io = st7123->io;
// Perform hardware reset
if (st7123->reset_gpio_num >= 0) {
gpio_set_level(st7123->reset_gpio_num, st7123->flags.reset_level);
vTaskDelay(pdMS_TO_TICKS(50));
gpio_set_level(st7123->reset_gpio_num, !st7123->flags.reset_level);
vTaskDelay(pdMS_TO_TICKS(50));
} else if (io) { // Perform software reset
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0), TAG, "send command failed");
vTaskDelay(pdMS_TO_TICKS(20));
}
return ESP_OK;
}
static esp_err_t panel_st7123_invert_color(esp_lcd_panel_t *panel, bool invert_color_data)
{
// st7123_panel_t *st7123 = (st7123_panel_t *)panel->user_data;
// esp_lcd_panel_io_handle_t io = st7123->io;
// uint8_t command = 0;
// ESP_RETURN_ON_FALSE(io, ESP_ERR_INVALID_STATE, TAG, "invalid panel IO");
// if (invert_color_data) {
// command = LCD_CMD_INVON;
// } else {
// command = LCD_CMD_INVOFF;
// }
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
return ESP_OK;
}
static esp_err_t panel_st7123_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
{
// st7123_panel_t *st7123 = (st7123_panel_t *)panel->user_data;
// esp_lcd_panel_io_handle_t io = st7123->io;
// uint8_t madctl_val = st7123->madctl_val;
// ESP_RETURN_ON_FALSE(io, ESP_ERR_INVALID_STATE, TAG, "invalid panel IO");
// // Control mirror through LCD command
// if (mirror_x) {
// madctl_val |= ST7123_CMD_GS_BIT;
// } else {
// madctl_val &= ~ST7123_CMD_GS_BIT;
// }
// if (mirror_y) {
// madctl_val |= ST7123_CMD_SS_BIT;
// } else {
// madctl_val &= ~ST7123_CMD_SS_BIT;
// }
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL, (uint8_t []) {
// madctl_val
// }, 1), TAG, "send command failed");
// st7123->madctl_val = madctl_val;
return ESP_OK;
}
static esp_err_t panel_st7123_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
{
// st7123_panel_t *st7123 = (st7123_panel_t *)panel->user_data;
// esp_lcd_panel_io_handle_t io = st7123->io;
// int command = 0;
// if (on_off) {
// command = LCD_CMD_DISPON;
// } else {
// command = LCD_CMD_DISPOFF;
// }
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
return ESP_OK;
}
static esp_err_t panel_st7123_sleep(esp_lcd_panel_t *panel, bool sleep)
{
// st7123_panel_t *st7123 = (st7123_panel_t *)panel->user_data;
// esp_lcd_panel_io_handle_t io = st7123->io;
// int command = 0;
// if (sleep) {
// command = LCD_CMD_SLPIN;
// } else {
// command = LCD_CMD_SLPOUT;
// }
// ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
// vTaskDelay(pdMS_TO_TICKS(100));
return ESP_OK;
}
#endif // SOC_MIPI_DSI_SUPPORTED

View File

@@ -0,0 +1,125 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LCD: ST7123
*/
#pragma once
#include <stdint.h>
#include "soc/soc_caps.h"
#if SOC_MIPI_DSI_SUPPORTED
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_mipi_dsi.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief LCD panel initialization commands.
*
*/
typedef struct {
int cmd; /*<! The specific LCD command */
const void *data; /*<! Buffer that holds the command specific data */
size_t data_bytes; /*<! Size of `data` in memory, in bytes */
unsigned int delay_ms; /*<! Delay in milliseconds after this command */
} st7123_lcd_init_cmd_t;
/**
* @brief LCD panel vendor configuration.
*
* @note This structure needs to be passed to the `esp_lcd_panel_dev_config_t::vendor_config`.
*
*/
typedef struct {
const st7123_lcd_init_cmd_t *init_cmds; /*!< Pointer to initialization commands array. Set to NULL if using default commands.
* The array should be declared as `static const` and positioned outside the function.
* Please refer to `vendor_specific_init_default` in source file.
*/
uint16_t init_cmds_size; /*<! Number of commands in above array */
struct {
esp_lcd_dsi_bus_handle_t dsi_bus; /*!< MIPI-DSI bus configuration */
const esp_lcd_dpi_panel_config_t *dpi_config; /*!< MIPI-DPI panel configuration */
uint8_t lane_num; /*!< Number of MIPI-DSI lanes */
} mipi_config;
} st7123_vendor_config_t;
/**
* @brief Create LCD panel for model ST7123
*
* @note Vendor specific initialization can be different between manufacturers, should consult the LCD supplier for initialization sequence code.
*
* @param[in] io LCD panel IO handle
* @param[in] panel_dev_config General panel device configuration
* @param[out] ret_panel Returned LCD panel handle
* @return
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_OK on success
* - Otherwise on fail
*/
esp_err_t esp_lcd_new_panel_st7123(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config,
esp_lcd_panel_handle_t *ret_panel);
/**
* @brief MIPI-DSI bus configuration structure
*
*/
#define ST7123_PANEL_BUS_DSI_2CH_CONFIG() \
{ \
.bus_id = 0, \
.num_data_lanes = 2, \
.lane_bit_rate_mbps = 1000, \
}
/**
* @brief MIPI-DBI panel IO configuration structure
*
*/
#define ST7123_PANEL_IO_DBI_CONFIG() \
{ \
.virtual_channel = 0, \
.lcd_cmd_bits = 8, \
.lcd_param_bits = 8, \
}
/**
* @brief MIPI DPI configuration structure
*
* @note refresh_rate = (dpi_clock_freq_mhz * 1000000) / (h_res + hsync_pulse_width + hsync_back_porch + hsync_front_porch)
* / (v_res + vsync_pulse_width + vsync_back_porch + vsync_front_porch)
*
* @param[in] px_format Pixel format of the panel
*
*/
#define ST7123_800_1280_PANEL_60HZ_DPI_CONFIG(px_format) \
{ \
.dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT, \
.dpi_clock_freq_mhz = 80, \
.virtual_channel = 0, \
.pixel_format = px_format, \
.num_fbs = 1, \
.video_timing = { \
.h_size = 800, \
.v_size = 1280, \
.hsync_back_porch = 140, \
.hsync_pulse_width = 40, \
.hsync_front_porch = 40, \
.vsync_back_porch = 16, \
.vsync_pulse_width = 4, \
.vsync_front_porch = 16, \
}, \
.flags.use_dma2d = true, \
}
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,574 @@
#include "wifi_board.h"
#include "tab5_audio_codec.h"
#include "display/lcd_display.h"
#include "esp_lcd_ili9881c.h"
#include "esp_lcd_st7123.h"
#include "font_emoji.h"
#include "application.h"
#include "button.h"
#include "config.h"
#include "esp_video.h"
#include "esp_video_init.h"
#include "esp_cam_sensor_xclk.h"
#include <esp_log.h>
#include "esp_check.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 "i2c_device.h"
#include "esp_lcd_touch_gt911.h"
#include "esp_lcd_touch_st7123.h"
#include <cstring>
#define TAG "M5StackTab5Board"
#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
#define ST7123_TOUCH_I2C_ADDRESS 0x55
// 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
// Bit manipulation macros
#define setbit(x, bit) ((x) |= (1U << (bit)))
#define clrbit(x, bit) ((x) &= ~(1U << (bit)))
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 输出高电平
}
uint8_t ReadOutSet() { return ReadReg(PI4IO_REG_OUT_SET); }
void WriteOutSet(uint8_t value) { WriteReg(PI4IO_REG_OUT_SET, value); }
};
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) 输出高电平
}
uint8_t ReadOutSet() { return ReadReg(PI4IO_REG_OUT_SET); }
void WriteOutSet(uint8_t value) { WriteReg(PI4IO_REG_OUT_SET, value); }
};
class M5StackTab5Board : public WifiBoard {
private:
i2c_master_bus_handle_t i2c_bus_;
Button boot_button_;
LcdDisplay* display_;
EspVideo* camera_ = nullptr;
Pi4ioe1* pi4ioe1_;
Pi4ioe2* pi4ioe2_;
esp_lcd_touch_handle_t touch_ = nullptr;
void InitializeI2c() {
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_));
}
static esp_err_t bsp_enable_dsi_phy_power() {
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,
};
return esp_ldo_acquire_channel(&ldo_mipi_phy_config, &ldo_mipi_phy);
}
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) {
EnterWifiConfigMode();
return;
}
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 = {
.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS,
.control_phase_bytes = 1,
.dc_bit_offset = 0,
.lcd_cmd_bits = 16,
.flags =
{
.disable_control_phase = 1,
}
};
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_);
}
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,
.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_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);
}
void InitializeSt7123Display() {
esp_err_t ret = ESP_OK;
esp_lcd_panel_io_handle_t io = NULL;
esp_lcd_panel_handle_t disp_panel = NULL;
esp_lcd_dsi_bus_handle_t mipi_dsi_bus = NULL;
// Declare all config structures at the top to avoid goto issues
// Initialize with memset to avoid any initialization syntax that might confuse the compiler
esp_lcd_dsi_bus_config_t bus_config;
esp_lcd_dbi_io_config_t dbi_config;
esp_lcd_dpi_panel_config_t dpi_config;
st7123_vendor_config_t vendor_config;
esp_lcd_panel_dev_config_t lcd_dev_config;
memset(&bus_config, 0, sizeof(bus_config));
memset(&dbi_config, 0, sizeof(dbi_config));
memset(&dpi_config, 0, sizeof(dpi_config));
memset(&vendor_config, 0, sizeof(vendor_config));
memset(&lcd_dev_config, 0, sizeof(lcd_dev_config));
ESP_ERROR_CHECK(bsp_enable_dsi_phy_power());
/* create MIPI DSI bus first, it will initialize the DSI PHY as well */
bus_config.bus_id = 0;
bus_config.num_data_lanes = 2; // ST7123 uses 2 data lanes
bus_config.lane_bit_rate_mbps = 965; // ST7123 lane bitrate
ret = esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "New DSI bus init failed");
goto err;
}
ESP_LOGI(TAG, "Install MIPI DSI LCD control panel for ST7123");
// we use DBI interface to send LCD commands and parameters
dbi_config.virtual_channel = 0;
dbi_config.lcd_cmd_bits = 8; // according to the LCD spec
dbi_config.lcd_param_bits = 8; // according to the LCD spec
ret = esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &io);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "New panel IO failed");
goto err;
}
ESP_LOGI(TAG, "Install LCD driver of ST7123");
dpi_config.virtual_channel = 0;
dpi_config.dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT;
dpi_config.dpi_clock_freq_mhz = 70; // ST7123 DPI clock frequency
dpi_config.pixel_format = LCD_COLOR_PIXEL_FORMAT_RGB565;
dpi_config.num_fbs = 1;
dpi_config.video_timing.h_size = 720;
dpi_config.video_timing.v_size = 1280;
dpi_config.video_timing.hsync_pulse_width = 2;
dpi_config.video_timing.hsync_back_porch = 40;
dpi_config.video_timing.hsync_front_porch = 40;
dpi_config.video_timing.vsync_pulse_width = 2;
dpi_config.video_timing.vsync_back_porch = 8;
dpi_config.video_timing.vsync_front_porch = 220;
dpi_config.flags.use_dma2d = true;
vendor_config.init_cmds = st7123_vendor_specific_init_default;
vendor_config.init_cmds_size = sizeof(st7123_vendor_specific_init_default) / sizeof(st7123_vendor_specific_init_default[0]);
vendor_config.mipi_config.dsi_bus = mipi_dsi_bus;
vendor_config.mipi_config.dpi_config = &dpi_config;
vendor_config.mipi_config.lane_num = 2;
lcd_dev_config.reset_gpio_num = -1;
lcd_dev_config.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB;
lcd_dev_config.data_endian = LCD_RGB_DATA_ENDIAN_LITTLE;
lcd_dev_config.bits_per_pixel = 24;
lcd_dev_config.vendor_config = &vendor_config;
// 使用实际的 ST7123 驱动函数
ret = esp_lcd_new_panel_st7123(io, &lcd_dev_config, &disp_panel);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "New LCD panel ST7123 failed");
goto err;
}
ret = esp_lcd_panel_reset(disp_panel);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "LCD panel reset failed");
goto err;
}
ret = esp_lcd_panel_init(disp_panel);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "LCD panel init failed");
goto err;
}
ret = esp_lcd_panel_disp_on_off(disp_panel, true);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "LCD panel display on failed");
goto err;
}
display_ = new MipiLcdDisplay(io, disp_panel, 720, 1280, DISPLAY_OFFSET_X,
DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
ESP_LOGI(TAG, "ST7123 Display initialized with resolution %dx%d", 720, 1280);
return;
err:
if (disp_panel) {
esp_lcd_panel_del(disp_panel);
}
if (io) {
esp_lcd_panel_io_del(io);
}
if (mipi_dsi_bus) {
esp_lcd_del_dsi_bus(mipi_dsi_bus);
}
ESP_ERROR_CHECK(ret);
}
void InitializeSt7123TouchPad() {
ESP_LOGI(TAG, "Init ST7123 Touch");
/* Initialize Touch Panel */
ESP_LOGI(TAG, "Initialize touch IO (I2C)");
const esp_lcd_touch_config_t tp_cfg = {
.x_max = 720,
.y_max = 1280,
.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 = {
.dev_addr = 0x55,
.control_phase_bytes = 1,
.dc_bit_offset = 0,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.scl_speed_hz = 100000,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_bus_, &tp_io_config, &tp_io_handle));
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_st7123(tp_io_handle, &tp_cfg, &touch_));
}
void InitializeDisplay() {
// after tp reset, wait for 100ms to ensure the I2C bus is stable
vTaskDelay(pdMS_TO_TICKS(100));
// 检测 ST7123 触摸屏 (I2C地址 0x55)
esp_err_t ret = i2c_master_probe(i2c_bus_, ST7123_TOUCH_I2C_ADDRESS, 200);
if (ret == ESP_OK) {
ESP_LOGI(TAG, "Detected ST7123 at 0x%02X, initializing ST7123 display", ST7123_TOUCH_I2C_ADDRESS);
InitializeSt7123Display();
InitializeSt7123TouchPad();
} else {
ESP_LOGI(TAG, "ST7123 not found at 0x%02X (ret=0x%x), using default ST7703+GT911", ST7123_TOUCH_I2C_ADDRESS, ret);
InitializeIli9881cDisplay();
InitializeGt911TouchPad();
}
}
void InitializeCamera() {
esp_cam_sensor_xclk_handle_t xclk_handle = NULL;
esp_cam_sensor_xclk_config_t cam_xclk_config = {};
#if CONFIG_CAMERA_XCLK_USE_ESP_CLOCK_ROUTER
if (esp_cam_sensor_xclk_allocate(ESP_CAM_SENSOR_XCLK_ESP_CLOCK_ROUTER, &xclk_handle) == ESP_OK) {
cam_xclk_config.esp_clock_router_cfg.xclk_pin = CAMERA_MCLK;
cam_xclk_config.esp_clock_router_cfg.xclk_freq_hz = 12000000; // 12MHz
(void)esp_cam_sensor_xclk_start(xclk_handle, &cam_xclk_config);
}
#elif CONFIG_CAMERA_XCLK_USE_LEDC
if (esp_cam_sensor_xclk_allocate(ESP_CAM_SENSOR_XCLK_LEDC, &xclk_handle) == ESP_OK) {
cam_xclk_config.ledc_cfg.timer = LEDC_TIMER_0;
cam_xclk_config.ledc_cfg.clk_cfg = LEDC_AUTO_CLK;
cam_xclk_config.ledc_cfg.channel = LEDC_CHANNEL_0;
cam_xclk_config.ledc_cfg.xclk_freq_hz = 12000000; // 12MHz
cam_xclk_config.ledc_cfg.xclk_pin = CAMERA_MCLK;
(void)esp_cam_sensor_xclk_start(xclk_handle, &cam_xclk_config);
}
#endif
esp_video_init_sccb_config_t sccb_config = {
.init_sccb = false,
.i2c_handle = i2c_bus_,
.freq = 400000,
};
esp_video_init_csi_config_t csi_config = {
.sccb_config = sccb_config,
.reset_pin = GPIO_NUM_NC,
.pwdn_pin = GPIO_NUM_NC,
};
esp_video_init_config_t video_config = {
.csi = &csi_config,
};
camera_ = new EspVideo(video_config);
}
public:
M5StackTab5Board() : boot_button_(BOOT_BUTTON_GPIO) {
InitializeI2c();
I2cDetect();
InitializePi4ioe();
InitializeDisplay(); // Auto-detect and initialize display + touch
InitializeCamera();
InitializeButtons();
SetChargeQcEn(true);
SetChargeEn(true);
SetUsb5vEn(true);
SetExt5vEn(true);
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 Camera* GetCamera() override {
return camera_;
}
virtual Backlight* GetBacklight() override {
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
return &backlight;
}
// BSP power control functions
void SetChargeQcEn(bool en) {
if (pi4ioe2_) {
uint8_t value = pi4ioe2_->ReadOutSet();
if (en) {
clrbit(value, 5); // P5 = CHG_QC_EN (低电平使能)
} else {
setbit(value, 5);
}
pi4ioe2_->WriteOutSet(value);
}
}
void SetChargeEn(bool en) {
if (pi4ioe2_) {
uint8_t value = pi4ioe2_->ReadOutSet();
if (en) {
setbit(value, 7); // P7 = CHG_EN
} else {
clrbit(value, 7);
}
pi4ioe2_->WriteOutSet(value);
}
}
void SetUsb5vEn(bool en) {
if (pi4ioe2_) {
uint8_t value = pi4ioe2_->ReadOutSet();
if (en) {
setbit(value, 3); // P3 = USB5V_EN
} else {
clrbit(value, 3);
}
pi4ioe2_->WriteOutSet(value);
}
}
void SetExt5vEn(bool en) {
if (pi4ioe1_) {
uint8_t value = pi4ioe1_->ReadOutSet();
if (en) {
setbit(value, 2); // P2 = EXT5V_EN
} else {
clrbit(value, 2);
}
pi4ioe1_->WriteOutSet(value);
}
}
};
DECLARE_BOARD(M5StackTab5Board);

View File

@@ -0,0 +1,14 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.5.1 Project Minimal Configuration
#
CONFIG_BOARD_TYPE_M5STACK_CORE_TAB5=y
CONFIG_XIAOZHI_ENABLE_ROTATE_CAMERA_IMAGE=y
CONFIG_CAMERA_SC202CS=y
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_1=13
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_1=12
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_1=11
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D1_4BIT_BUS_SLOT_1=10
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D2_4BIT_BUS_SLOT_1=9
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D3_4BIT_BUS_SLOT_1=8

View File

@@ -0,0 +1,245 @@
#include "tab5_audio_codec.h"
#include <esp_log.h>
#include <driver/i2c.h>
#include <driver/i2s_tdm.h>
#define 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;
input_gain_ = 30;
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 = ES7210_SEL_MIC1 | ES7210_SEL_MIC2 | ES7210_SEL_MIC3 | ES7210_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_ERROR_CHECK(i2s_channel_enable(tx_handle_));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle_));
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), input_gain_));
} 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