feat:MagiClick-2p5增加硬件版本识别,增加对新屏幕的支持 (#1797)
* 增加硬件版本识别,开机自动切换不同的显示驱动 1、增加PCB版本识别 2、增加对ST7735屏幕的支持 3、删除sdk多余配置 4、增加电池均值次数 * fix lcd info
This commit is contained in:
@ -37,9 +37,10 @@
|
|||||||
|
|
||||||
#define DISPLAY_WIDTH 128
|
#define DISPLAY_WIDTH 128
|
||||||
#define DISPLAY_HEIGHT 128
|
#define DISPLAY_HEIGHT 128
|
||||||
#define DISPLAY_MIRROR_X false
|
|
||||||
#define DISPLAY_MIRROR_Y false
|
// 根据PCB版本动态选择屏幕类型和配置
|
||||||
#define DISPLAY_SWAP_XY false
|
#define PCB_VERSION_2_5A 1 // 使用GC9107
|
||||||
|
#define PCB_VERSION_2_5A1 2 // 使用ST7735
|
||||||
|
|
||||||
#define DISPLAY_OFFSET_X 0
|
#define DISPLAY_OFFSET_X 0
|
||||||
#define DISPLAY_OFFSET_Y 0
|
#define DISPLAY_OFFSET_Y 0
|
||||||
|
|||||||
@ -4,8 +4,6 @@
|
|||||||
{
|
{
|
||||||
"name": "magiclick-2p5",
|
"name": "magiclick-2p5",
|
||||||
"sdkconfig_append": [
|
"sdkconfig_append": [
|
||||||
"CONFIG_PM_ENABLE=y",
|
|
||||||
"CONFIG_FREERTOS_USE_TICKLESS_IDLE=y"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -19,15 +19,11 @@
|
|||||||
#include "power_save_timer.h"
|
#include "power_save_timer.h"
|
||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
|
|
||||||
#define TAG "magiclick_2p5"
|
#include <esp_adc/adc_oneshot.h>
|
||||||
|
#include <esp_adc/adc_cali.h>
|
||||||
|
#include <esp_adc/adc_cali_scheme.h>
|
||||||
|
|
||||||
class GC9107Display : public SpiLcdDisplay {
|
#define TAG "magiclick_2p5"
|
||||||
public:
|
|
||||||
GC9107Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
|
||||||
int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy)
|
|
||||||
: SpiLcdDisplay(panel_io, panel, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static const gc9a01_lcd_init_cmd_t gc9107_lcd_init_cmds[] = {
|
static const gc9a01_lcd_init_cmd_t gc9107_lcd_init_cmds[] = {
|
||||||
// {cmd, { data }, data_size, delay_ms}
|
// {cmd, { data }, data_size, delay_ms}
|
||||||
@ -69,13 +65,71 @@ private:
|
|||||||
Button main_button_;
|
Button main_button_;
|
||||||
Button left_button_;
|
Button left_button_;
|
||||||
Button right_button_;
|
Button right_button_;
|
||||||
GC9107Display* display_;
|
LcdDisplay* display_;
|
||||||
|
|
||||||
PowerSaveTimer* power_save_timer_;
|
PowerSaveTimer* power_save_timer_;
|
||||||
PowerManager* power_manager_;
|
PowerManager* power_manager_;
|
||||||
|
|
||||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
uint8_t pcb_version_ = 0;
|
||||||
esp_lcd_panel_handle_t panel = nullptr;
|
|
||||||
|
// 屏幕配置结构体
|
||||||
|
struct DisplayConfig {
|
||||||
|
bool use_gc9107;
|
||||||
|
bool mirror_x;
|
||||||
|
bool mirror_y;
|
||||||
|
bool swap_xy;
|
||||||
|
bool invert_color;
|
||||||
|
lcd_rgb_element_order_t rgb_order;
|
||||||
|
int offset_x;
|
||||||
|
int offset_y;
|
||||||
|
int spi_mode;
|
||||||
|
const char* screen_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
DisplayConfig GetDisplayConfig() {
|
||||||
|
if (pcb_version_ == PCB_VERSION_2_5A) {
|
||||||
|
return DisplayConfig{
|
||||||
|
.use_gc9107 = true,
|
||||||
|
.mirror_x = false,
|
||||||
|
.mirror_y = false,
|
||||||
|
.swap_xy = false,
|
||||||
|
.invert_color = false,
|
||||||
|
.rgb_order = LCD_RGB_ELEMENT_ORDER_RGB,
|
||||||
|
.offset_x = 0,
|
||||||
|
.offset_y = 0,
|
||||||
|
.spi_mode = 0,
|
||||||
|
.screen_name = "GC9107"
|
||||||
|
};
|
||||||
|
} else if (pcb_version_ == PCB_VERSION_2_5A1) {
|
||||||
|
return DisplayConfig{
|
||||||
|
.use_gc9107 = false,
|
||||||
|
.mirror_x = true,
|
||||||
|
.mirror_y = true,
|
||||||
|
.swap_xy = false,
|
||||||
|
.invert_color = true,
|
||||||
|
.rgb_order = LCD_RGB_ELEMENT_ORDER_BGR,
|
||||||
|
.offset_x = 2,
|
||||||
|
.offset_y = 3,
|
||||||
|
.spi_mode = 0,
|
||||||
|
.screen_name = "ST7735"
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
ESP_LOGW(TAG, "Unknown PCB version: %d, using default ST7735 configuration", pcb_version_);
|
||||||
|
return DisplayConfig{
|
||||||
|
.use_gc9107 = false,
|
||||||
|
.mirror_x = true,
|
||||||
|
.mirror_y = true,
|
||||||
|
.swap_xy = false,
|
||||||
|
.invert_color = true,
|
||||||
|
.rgb_order = LCD_RGB_ELEMENT_ORDER_BGR,
|
||||||
|
.offset_x = 2,
|
||||||
|
.offset_y = 3,
|
||||||
|
.spi_mode = 0,
|
||||||
|
.screen_name = "ST7735 (default)"
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void InitializePowerManager() {
|
void InitializePowerManager() {
|
||||||
power_manager_ = new PowerManager(GPIO_NUM_48);
|
power_manager_ = new PowerManager(GPIO_NUM_48);
|
||||||
@ -141,6 +195,44 @@ private:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//通过adc读取IO3引脚的电压来获取PCB版本
|
||||||
|
void CheckPCBVersion() {
|
||||||
|
adc_oneshot_unit_handle_t adc1_handle;
|
||||||
|
adc_oneshot_unit_init_cfg_t init_config1 = {
|
||||||
|
.unit_id = ADC_UNIT_1,
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle));
|
||||||
|
|
||||||
|
adc_oneshot_chan_cfg_t config = {
|
||||||
|
.atten = ADC_ATTEN_DB_12,
|
||||||
|
.bitwidth = ADC_BITWIDTH_12,
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, ADC_CHANNEL_2, &config));
|
||||||
|
|
||||||
|
//获取10次, 然后求平均
|
||||||
|
int adc_value = 0;
|
||||||
|
int raw_value;
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, ADC_CHANNEL_2, &raw_value));
|
||||||
|
adc_value += raw_value;
|
||||||
|
}
|
||||||
|
adc_value /= 10;
|
||||||
|
|
||||||
|
int voltage = adc_value * (3300 / 4095.0);
|
||||||
|
if (voltage < 100) {
|
||||||
|
// 版本1
|
||||||
|
pcb_version_ = PCB_VERSION_2_5A;
|
||||||
|
} else if (voltage > 3200 ) {
|
||||||
|
// 版本2
|
||||||
|
pcb_version_ = PCB_VERSION_2_5A1;
|
||||||
|
}
|
||||||
|
// test
|
||||||
|
// pcb_version_ = PCB_VERSION_2_5A1;
|
||||||
|
|
||||||
|
adc_oneshot_del_unit(adc1_handle);
|
||||||
|
ESP_LOGI(TAG, "io voltage: %d, pcb_version: %d\n", voltage, pcb_version_);
|
||||||
|
}
|
||||||
|
|
||||||
void InitializeButtons() {
|
void InitializeButtons() {
|
||||||
main_button_.OnClick([this]() {
|
main_button_.OnClick([this]() {
|
||||||
auto& app = Application::GetInstance();
|
auto& app = Application::GetInstance();
|
||||||
@ -219,44 +311,56 @@ private:
|
|||||||
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeGc9107Display(){
|
void InitializeLcdDisplay(){
|
||||||
// esp_lcd_panel_io_handle_t panel_io = nullptr;
|
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||||
// esp_lcd_panel_handle_t panel = nullptr;
|
esp_lcd_panel_handle_t panel = nullptr;
|
||||||
|
|
||||||
|
// 获取屏幕配置
|
||||||
|
DisplayConfig config = GetDisplayConfig();
|
||||||
|
ESP_LOGW(TAG, "PCB Version: %d, Using %s screen", pcb_version_, config.screen_name);
|
||||||
|
|
||||||
// 液晶屏控制IO初始化
|
// 液晶屏控制IO初始化
|
||||||
ESP_LOGD(TAG, "Install panel IO");
|
ESP_LOGD(TAG, "Install panel IO");
|
||||||
esp_lcd_panel_io_spi_config_t io_config = {};
|
esp_lcd_panel_io_spi_config_t io_config = {};
|
||||||
io_config.cs_gpio_num = DISPLAY_CS_PIN;
|
io_config.cs_gpio_num = DISPLAY_CS_PIN;
|
||||||
io_config.dc_gpio_num = DISPLAY_DC_PIN;
|
io_config.dc_gpio_num = DISPLAY_DC_PIN;
|
||||||
io_config.spi_mode = 0;
|
io_config.spi_mode = config.spi_mode;
|
||||||
io_config.pclk_hz = 40 * 1000 * 1000;
|
io_config.pclk_hz = 20 * 1000 * 1000;
|
||||||
io_config.trans_queue_depth = 10;
|
io_config.trans_queue_depth = 10;
|
||||||
io_config.lcd_cmd_bits = 8;
|
io_config.lcd_cmd_bits = 8;
|
||||||
io_config.lcd_param_bits = 8;
|
io_config.lcd_param_bits = 8;
|
||||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io));
|
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io));
|
||||||
|
|
||||||
// 初始化液晶屏驱动芯片GC9107
|
// 初始化液晶屏驱动芯片
|
||||||
ESP_LOGD(TAG, "Install LCD driver");
|
ESP_LOGD(TAG, "Install LCD driver");
|
||||||
gc9a01_vendor_config_t gc9107_vendor_config = {
|
|
||||||
.init_cmds = gc9107_lcd_init_cmds,
|
|
||||||
.init_cmds_size = sizeof(gc9107_lcd_init_cmds) / sizeof(gc9a01_lcd_init_cmd_t),
|
|
||||||
};
|
|
||||||
esp_lcd_panel_dev_config_t panel_config = {};
|
esp_lcd_panel_dev_config_t panel_config = {};
|
||||||
panel_config.reset_gpio_num = DISPLAY_RST_PIN;
|
panel_config.reset_gpio_num = DISPLAY_RST_PIN;
|
||||||
panel_config.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB;
|
panel_config.rgb_ele_order = config.rgb_order;
|
||||||
panel_config.bits_per_pixel = 16;
|
panel_config.bits_per_pixel = 16;
|
||||||
panel_config.vendor_config = &gc9107_vendor_config;
|
panel_config.flags.reset_active_high = 0;
|
||||||
|
|
||||||
esp_lcd_new_panel_gc9a01(panel_io, &panel_config, &panel);
|
if (config.use_gc9107) {
|
||||||
|
gc9a01_vendor_config_t gc9107_vendor_config = {
|
||||||
|
.init_cmds = gc9107_lcd_init_cmds,
|
||||||
|
.init_cmds_size = sizeof(gc9107_lcd_init_cmds) / sizeof(gc9a01_lcd_init_cmd_t),
|
||||||
|
};
|
||||||
|
panel_config.vendor_config = &gc9107_vendor_config;
|
||||||
|
ESP_ERROR_CHECK(esp_lcd_new_panel_gc9a01(panel_io, &panel_config, &panel));
|
||||||
|
} else {
|
||||||
|
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel));
|
||||||
|
}
|
||||||
|
|
||||||
esp_lcd_panel_reset(panel);
|
esp_lcd_panel_reset(panel);
|
||||||
|
|
||||||
esp_lcd_panel_init(panel);
|
esp_lcd_panel_init(panel);
|
||||||
esp_lcd_panel_invert_color(panel, false);
|
esp_lcd_panel_invert_color(panel, config.invert_color);
|
||||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
esp_lcd_panel_swap_xy(panel, config.swap_xy);
|
||||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
esp_lcd_panel_mirror(panel, config.mirror_x, config.mirror_y);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel, true));
|
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel, true));
|
||||||
display_ = new GC9107Display(panel_io, panel,
|
|
||||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
|
display_ = new SpiLcdDisplay(panel_io, panel,
|
||||||
|
DISPLAY_WIDTH, DISPLAY_HEIGHT, config.offset_x, config.offset_y, config.mirror_x, config.mirror_y, config.swap_xy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -264,14 +368,15 @@ public:
|
|||||||
main_button_(MAIN_BUTTON_GPIO),
|
main_button_(MAIN_BUTTON_GPIO),
|
||||||
left_button_(LEFT_BUTTON_GPIO),
|
left_button_(LEFT_BUTTON_GPIO),
|
||||||
right_button_(RIGHT_BUTTON_GPIO) {
|
right_button_(RIGHT_BUTTON_GPIO) {
|
||||||
|
CheckPCBVersion();
|
||||||
InitializeLedPower();
|
InitializeLedPower();
|
||||||
CheckNetType();
|
CheckNetType();
|
||||||
InitializePowerManager();
|
InitializePowerManager();
|
||||||
InitializePowerSaveTimer();
|
InitializePowerSaveTimer();
|
||||||
InitializeCodecI2c();
|
InitializeCodecI2c();
|
||||||
InitializeButtons();
|
InitializeButtons();
|
||||||
InitializeSpi();
|
InitializeSpi();
|
||||||
InitializeGc9107Display();
|
InitializeLcdDisplay();
|
||||||
GetBacklight()->RestoreBrightness();
|
GetBacklight()->RestoreBrightness();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ private:
|
|||||||
bool is_low_battery_ = false;
|
bool is_low_battery_ = false;
|
||||||
int ticks_ = 0;
|
int ticks_ = 0;
|
||||||
const int kBatteryAdcInterval = 60;
|
const int kBatteryAdcInterval = 60;
|
||||||
const int kBatteryAdcDataCount = 3;
|
const int kBatteryAdcDataCount = 5;
|
||||||
const int kLowBatteryLevel = 20;
|
const int kLowBatteryLevel = 20;
|
||||||
|
|
||||||
adc_oneshot_unit_handle_t adc_handle_;
|
adc_oneshot_unit_handle_t adc_handle_;
|
||||||
|
|||||||
Reference in New Issue
Block a user