forked from xiaozhi/xiaozhi-esp32
board/m5stack-tab5: Add new display st7123 support. (#1409)
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
#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_log.h>
|
||||
#include "esp_check.h"
|
||||
#include "esp_lcd_mipi_dsi.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_ldo_regulator.h"
|
||||
@@ -17,6 +19,7 @@
|
||||
#include <wifi_station.h>
|
||||
#include "i2c_device.h"
|
||||
#include "esp_lcd_touch_gt911.h"
|
||||
#include "esp_lcd_touch_st7123.h"
|
||||
#include <cstring>
|
||||
|
||||
#define TAG "M5StackTab5Board"
|
||||
@@ -24,6 +27,8 @@
|
||||
#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
|
||||
@@ -37,6 +42,10 @@
|
||||
#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) {
|
||||
@@ -50,6 +59,9 @@ public:
|
||||
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 {
|
||||
@@ -65,6 +77,9 @@ public:
|
||||
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 {
|
||||
@@ -77,14 +92,13 @@ private:
|
||||
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,
|
||||
.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,
|
||||
.intr_priority = 0,
|
||||
.trans_queue_depth = 0,
|
||||
.flags = {
|
||||
.enable_internal_pullup = 1,
|
||||
@@ -93,6 +107,15 @@ private:
|
||||
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");
|
||||
@@ -156,37 +179,16 @@ private:
|
||||
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_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_handle_t ldo_mipi_phy = NULL;
|
||||
esp_ldo_channel_config_t ldo_mipi_phy_config = {
|
||||
.chan_id = LCD_MIPI_DSI_PHY_PWR_LDO_CHAN,
|
||||
.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));
|
||||
@@ -194,78 +196,245 @@ private:
|
||||
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
|
||||
.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_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,
|
||||
}};
|
||||
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,
|
||||
},
|
||||
.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;
|
||||
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);
|
||||
}
|
||||
|
||||
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.phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
M5StackTab5Board() : boot_button_(BOOT_BUTTON_GPIO) {
|
||||
InitializeI2c();
|
||||
I2cDetect();
|
||||
InitializePi4ioe();
|
||||
InitializeGt911TouchPad();
|
||||
InitializeIli9881cDisplay();
|
||||
InitializeDisplay(); // Auto-detect and initialize display + touch
|
||||
InitializeButtons();
|
||||
SetChargeQcEn(true);
|
||||
SetChargeEn(true);
|
||||
SetUsb5vEn(true);
|
||||
SetExt5vEn(true);
|
||||
GetBacklight()->RestoreBrightness();
|
||||
}
|
||||
|
||||
@@ -293,6 +462,57 @@ public:
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user