Help with migration to ESP32_Display_Panel Release v1.0.3 or 1.0.4 #231
-
|
I use a display with a Previously I used the following software versions:
The file for working with the display, written for lvgl 8, is as follows: The file includes pins and necessary libraries:
In the specified configuration, everything worked fine for me, the image was drawn and there were no problems. Until I started using rtos with And the microcontroller writes this error:
After that it was decided to update First, I downloaded the latest
Then I looked at the examples inside the repository and realized that the examples were very confusing, since the example for
The display config file in the
The contents of the file are as follows: #ifndef _SCR_ST77916_H_
#define _SCR_ST77916_H_
#include "pincfg.h"
#include <lvgl.h>
// enables ESP32_IO_Expander at once
#include <esp_display_panel.hpp>
using namespace esp_panel::drivers;
/*Change to your screen resolution*/
// static const uint16_t screenWidth = 320;
// static const uint16_t screenHeight = 170;
#define SCREEN_RES_HOR 280
#define SCREEN_RES_VER 280
// #define SCREEN_RES_HOR 359
// #define SCREEN_RES_VER 359
/* When using settings, you need to reduce the screen buffer */
// #define SCREEN_RES_HOR 300
// #define SCREEN_RES_VER 300
// to offset the reduced screen from the origin
#define RATIO (360 - SCREEN_RES_HOR) / 2
extern int brightness;
// static lv_color_t *disp_draw_buf;
static lv_color_t *disp_draw_buf = NULL;
static lv_color_t *buf1 = NULL;
static lv_color_t *buf2 = NULL;
static lv_disp_draw_buf_t draw_buf;
static lv_disp_drv_t disp_drv;
// static lv_indev_t *indev_touchpad;
// static ESP_PanelBacklight *backlight = NULL;
BacklightPWM_LEDC *backlight;
static ESP_PanelLcd *lcd = NULL;
// static ESP_PanelTouch *touch = NULL;
Touch *touch = nullptr;
#define _EXAMPLE_TOUCH_CLASS(name, ...) Touch##name(__VA_ARGS__)
#define EXAMPLE_TOUCH_CLASS(name, ...) _EXAMPLE_TOUCH_CLASS(name, ##__VA_ARGS__)
// new setup
uint32_t screenWidth;
uint32_t screenHeight;
uint32_t drawBufSize;
#define USE_CUSTOM_INIT_CMD 0 // 是否用自定义的初始化代码
#if TOUCH_PIN_NUM_INT >= 0
IRAM_ATTR bool onTouchInterruptCallback(void *user_data)
{
return false;
}
#endif
const esp_lcd_panel_vendor_init_cmd_t lcd_init_cmd[] = {
{0xF0, (uint8_t[]){0x08}, 1, 0},
{0xF2, (uint8_t[]){0x08}, 1, 0},
{0x9B, (uint8_t[]){0x51}, 1, 0},
{0x86, (uint8_t[]){0x53}, 1, 0},
{0xF2, (uint8_t[]){0x80}, 1, 0},
{0xF0, (uint8_t[]){0x00}, 1, 0},
{0xF0, (uint8_t[]){0x01}, 1, 0},
{0xF1, (uint8_t[]){0x01}, 1, 0},
{0xB0, (uint8_t[]){0x54}, 1, 0},
{0xB1, (uint8_t[]){0x3F}, 1, 0},
{0xB2, (uint8_t[]){0x2A}, 1, 0},
{0xB4, (uint8_t[]){0x46}, 1, 0},
{0xB5, (uint8_t[]){0x34}, 1, 0},
{0xB6, (uint8_t[]){0xD5}, 1, 0},
{0xB7, (uint8_t[]){0x30}, 1, 0},
{0xBA, (uint8_t[]){0x00}, 1, 0},
{0xBB, (uint8_t[]){0x08}, 1, 0},
{0xBC, (uint8_t[]){0x08}, 1, 0},
{0xBD, (uint8_t[]){0x00}, 1, 0},
{0xC0, (uint8_t[]){0x80}, 1, 0},
{0xC1, (uint8_t[]){0x10}, 1, 0},
{0xC2, (uint8_t[]){0x37}, 1, 0},
{0xC3, (uint8_t[]){0x80}, 1, 0},
{0xC4, (uint8_t[]){0x10}, 1, 0},
{0xC5, (uint8_t[]){0x37}, 1, 0},
{0xC6, (uint8_t[]){0xA9}, 1, 0},
{0xC7, (uint8_t[]){0x41}, 1, 0},
{0xC8, (uint8_t[]){0x51}, 1, 0},
{0xC9, (uint8_t[]){0xA9}, 1, 0},
{0xCA, (uint8_t[]){0x41}, 1, 0},
{0xCB, (uint8_t[]){0x51}, 1, 0},
{0xD0, (uint8_t[]){0x91}, 1, 0},
{0xD1, (uint8_t[]){0x68}, 1, 0},
{0xD2, (uint8_t[]){0x69}, 1, 0},
{0xF5, (uint8_t[]){0x00, 0xA5}, 2, 0},
{0xDD, (uint8_t[]){0x3F}, 1, 0},
{0xDE, (uint8_t[]){0x3F}, 1, 0},
{0xF1, (uint8_t[]){0x10}, 1, 0},
{0xF0, (uint8_t[]){0x00}, 1, 0},
{0xF0, (uint8_t[]){0x02}, 1, 0},
{0xE0, (uint8_t[]){0x70, 0x09, 0x12, 0x0C, 0x0B, 0x27, 0x38, 0x54, 0x4E, 0x19, 0x15, 0x15, 0x2C, 0x2F}, 14, 0},
{0xE1, (uint8_t[]){0x70, 0x08, 0x11, 0x0C, 0x0B, 0x27, 0x38, 0x43, 0x4C, 0x18, 0x14, 0x14, 0x2B, 0x2D}, 14, 0},
{0xF0, (uint8_t[]){0x10}, 1, 0},
{0xF3, (uint8_t[]){0x10}, 1, 0},
{0xE0, (uint8_t[]){0x08}, 1, 0},
{0xE1, (uint8_t[]){0x00}, 1, 0},
{0xE2, (uint8_t[]){0x00}, 1, 0},
{0xE3, (uint8_t[]){0x00}, 1, 0},
{0xE4, (uint8_t[]){0xE0}, 1, 0},
{0xE5, (uint8_t[]){0x06}, 1, 0},
{0xE6, (uint8_t[]){0x21}, 1, 0},
{0xE7, (uint8_t[]){0x00}, 1, 0},
{0xE8, (uint8_t[]){0x05}, 1, 0},
{0xE9, (uint8_t[]){0x82}, 1, 0},
{0xEA, (uint8_t[]){0xDF}, 1, 0},
{0xEB, (uint8_t[]){0x89}, 1, 0},
{0xEC, (uint8_t[]){0x20}, 1, 0},
{0xED, (uint8_t[]){0x14}, 1, 0},
{0xEE, (uint8_t[]){0xFF}, 1, 0},
{0xEF, (uint8_t[]){0x00}, 1, 0},
{0xF8, (uint8_t[]){0xFF}, 1, 0},
{0xF9, (uint8_t[]){0x00}, 1, 0},
{0xFA, (uint8_t[]){0x00}, 1, 0},
{0xFB, (uint8_t[]){0x30}, 1, 0},
{0xFC, (uint8_t[]){0x00}, 1, 0},
{0xFD, (uint8_t[]){0x00}, 1, 0},
{0xFE, (uint8_t[]){0x00}, 1, 0},
{0xFF, (uint8_t[]){0x00}, 1, 0},
{0x60, (uint8_t[]){0x42}, 1, 0},
{0x61, (uint8_t[]){0xE0}, 1, 0},
{0x62, (uint8_t[]){0x40}, 1, 0},
{0x63, (uint8_t[]){0x40}, 1, 0},
{0x64, (uint8_t[]){0x02}, 1, 0},
{0x65, (uint8_t[]){0x00}, 1, 0},
{0x66, (uint8_t[]){0x40}, 1, 0},
{0x67, (uint8_t[]){0x03}, 1, 0},
{0x68, (uint8_t[]){0x00}, 1, 0},
{0x69, (uint8_t[]){0x00}, 1, 0},
{0x6A, (uint8_t[]){0x00}, 1, 0},
{0x6B, (uint8_t[]){0x00}, 1, 0},
{0x70, (uint8_t[]){0x42}, 1, 0},
{0x71, (uint8_t[]){0xE0}, 1, 0},
{0x72, (uint8_t[]){0x40}, 1, 0},
{0x73, (uint8_t[]){0x40}, 1, 0},
{0x74, (uint8_t[]){0x02}, 1, 0},
{0x75, (uint8_t[]){0x00}, 1, 0},
{0x76, (uint8_t[]){0x40}, 1, 0},
{0x77, (uint8_t[]){0x03}, 1, 0},
{0x78, (uint8_t[]){0x00}, 1, 0},
{0x79, (uint8_t[]){0x00}, 1, 0},
{0x7A, (uint8_t[]){0x00}, 1, 0},
{0x7B, (uint8_t[]){0x00}, 1, 0},
{0x80, (uint8_t[]){0x48}, 1, 0},
{0x81, (uint8_t[]){0x00}, 1, 0},
{0x82, (uint8_t[]){0x05}, 1, 0},
{0x83, (uint8_t[]){0x02}, 1, 0},
{0x84, (uint8_t[]){0xDD}, 1, 0},
{0x85, (uint8_t[]){0x00}, 1, 0},
{0x86, (uint8_t[]){0x00}, 1, 0},
{0x87, (uint8_t[]){0x00}, 1, 0},
{0x88, (uint8_t[]){0x48}, 1, 0},
{0x89, (uint8_t[]){0x00}, 1, 0},
{0x8A, (uint8_t[]){0x07}, 1, 0},
{0x8B, (uint8_t[]){0x02}, 1, 0},
{0x8C, (uint8_t[]){0xDF}, 1, 0},
{0x8D, (uint8_t[]){0x00}, 1, 0},
{0x8E, (uint8_t[]){0x00}, 1, 0},
{0x8F, (uint8_t[]){0x00}, 1, 0},
{0x90, (uint8_t[]){0x48}, 1, 0},
{0x91, (uint8_t[]){0x00}, 1, 0},
{0x92, (uint8_t[]){0x09}, 1, 0},
{0x93, (uint8_t[]){0x02}, 1, 0},
{0x94, (uint8_t[]){0xE1}, 1, 0},
{0x95, (uint8_t[]){0x00}, 1, 0},
{0x96, (uint8_t[]){0x00}, 1, 0},
{0x97, (uint8_t[]){0x00}, 1, 0},
{0x98, (uint8_t[]){0x48}, 1, 0},
{0x99, (uint8_t[]){0x00}, 1, 0},
{0x9A, (uint8_t[]){0x0B}, 1, 0},
{0x9B, (uint8_t[]){0x02}, 1, 0},
{0x9C, (uint8_t[]){0xE3}, 1, 0},
{0x9D, (uint8_t[]){0x00}, 1, 0},
{0x9E, (uint8_t[]){0x00}, 1, 0},
{0x9F, (uint8_t[]){0x00}, 1, 0},
{0xA0, (uint8_t[]){0x48}, 1, 0},
{0xA1, (uint8_t[]){0x00}, 1, 0},
{0xA2, (uint8_t[]){0x04}, 1, 0},
{0xA3, (uint8_t[]){0x02}, 1, 0},
{0xA4, (uint8_t[]){0xDC}, 1, 0},
{0xA5, (uint8_t[]){0x00}, 1, 0},
{0xA6, (uint8_t[]){0x00}, 1, 0},
{0xA7, (uint8_t[]){0x00}, 1, 0},
{0xA8, (uint8_t[]){0x48}, 1, 0},
{0xA9, (uint8_t[]){0x00}, 1, 0},
{0xAA, (uint8_t[]){0x06}, 1, 0},
{0xAB, (uint8_t[]){0x02}, 1, 0},
{0xAC, (uint8_t[]){0xDE}, 1, 0},
{0xAD, (uint8_t[]){0x00}, 1, 0},
{0xAE, (uint8_t[]){0x00}, 1, 0},
{0xAF, (uint8_t[]){0x00}, 1, 0},
{0xB0, (uint8_t[]){0x48}, 1, 0},
{0xB1, (uint8_t[]){0x00}, 1, 0},
{0xB2, (uint8_t[]){0x08}, 1, 0},
{0xB3, (uint8_t[]){0x02}, 1, 0},
{0xB4, (uint8_t[]){0xE0}, 1, 0},
{0xB5, (uint8_t[]){0x00}, 1, 0},
{0xB6, (uint8_t[]){0x00}, 1, 0},
{0xB7, (uint8_t[]){0x00}, 1, 0},
{0xB8, (uint8_t[]){0x48}, 1, 0},
{0xB9, (uint8_t[]){0x00}, 1, 0},
{0xBA, (uint8_t[]){0x0A}, 1, 0},
{0xBB, (uint8_t[]){0x02}, 1, 0},
{0xBC, (uint8_t[]){0xE2}, 1, 0},
{0xBD, (uint8_t[]){0x00}, 1, 0},
{0xBE, (uint8_t[]){0x00}, 1, 0},
{0xBF, (uint8_t[]){0x00}, 1, 0},
{0xC0, (uint8_t[]){0x12}, 1, 0},
{0xC1, (uint8_t[]){0xAA}, 1, 0},
{0xC2, (uint8_t[]){0x65}, 1, 0},
{0xC3, (uint8_t[]){0x74}, 1, 0},
{0xC4, (uint8_t[]){0x47}, 1, 0},
{0xC5, (uint8_t[]){0x56}, 1, 0},
{0xC6, (uint8_t[]){0x00}, 1, 0},
{0xC7, (uint8_t[]){0x88}, 1, 0},
{0xC8, (uint8_t[]){0x99}, 1, 0},
{0xC9, (uint8_t[]){0x33}, 1, 0},
{0xD0, (uint8_t[]){0x21}, 1, 0},
{0xD1, (uint8_t[]){0xAA}, 1, 0},
{0xD2, (uint8_t[]){0x65}, 1, 0},
{0xD3, (uint8_t[]){0x74}, 1, 0},
{0xD4, (uint8_t[]){0x47}, 1, 0},
{0xD5, (uint8_t[]){0x56}, 1, 0},
{0xD6, (uint8_t[]){0x00}, 1, 0},
{0xD7, (uint8_t[]){0x88}, 1, 0},
{0xD8, (uint8_t[]){0x99}, 1, 0},
{0xD9, (uint8_t[]){0x33}, 1, 0},
{0xF3, (uint8_t[]){0x01}, 1, 0},
{0xF0, (uint8_t[]){0x00}, 1, 0},
{0xF0, (uint8_t[]){0x01}, 1, 0},
{0xF1, (uint8_t[]){0x01}, 1, 0},
{0xA0, (uint8_t[]){0x0B}, 1, 0},
{0xA3, (uint8_t[]){0x2A}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2B}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2C}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2D}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2E}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x2F}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x30}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x31}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x32}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA3, (uint8_t[]){0x33}, 1, 0},
{0xA5, (uint8_t[]){0xC3}, 1, 1},
{0xA0, (uint8_t[]){0x09}, 1, 0},
{0xF1, (uint8_t[]){0x10}, 1, 0},
{0xF0, (uint8_t[]){0x00}, 1, 0},
{0x2A, (uint8_t[]){0x00, 0x00, 0x01, 0x67}, 4, 0},
{0x2B, (uint8_t[]){0x01, 0x68, 0x01, 0x68}, 4, 0},
{0x4D, (uint8_t[]){0x00}, 1, 0},
{0x4E, (uint8_t[]){0x00}, 1, 0},
{0x4F, (uint8_t[]){0x00}, 1, 0},
{0x4C, (uint8_t[]){0x01}, 1, 10},
{0x4C, (uint8_t[]){0x00}, 1, 0},
{0x2A, (uint8_t[]){0x00, 0x00, 0x01, 0x67}, 4, 0},
{0x2B, (uint8_t[]){0x00, 0x00, 0x01, 0x67}, 4, 0},
{0x21, (uint8_t[]){0x00}, 1, 0},
//{0x3A, (uint8_t[]){0x55}, 1, 0}, // color=16
{0x11, (uint8_t[]){0x00}, 1, 120},
{0x29, (uint8_t[]){0x00}, 1, 0},
};
#define TFT_SPI_FREQ_HZ (30 * 1000 * 1000)
static void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
ESP_PanelLcd *lcd = (ESP_PanelLcd *)disp->user_data;
const int offsetx1 = area->x1;
const int offsetx2 = area->x2;
const int offsety1 = area->y1;
const int offsety2 = area->y2;
// lcd->drawBitmap(offsetx1, offsety1, offsetx2 - offsetx1 + 1, offsety2 - offsety1 + 1, (const uint8_t *)color_p);
lcd->drawBitmap(offsetx1 + RATIO, offsety1 + RATIO, offsetx2 - offsetx1 + 1, offsety2 - offsety1 + 1, (const uint8_t *)color_p);
}
IRAM_ATTR bool onRefreshFinishCallback(void *user_data)
{
lv_disp_drv_t *drv = (lv_disp_drv_t *)user_data;
lv_disp_flush_ready(drv);
return false;
}
void setRotation(uint8_t rot)
{
if (rot > 3)
return;
if (lcd == NULL || touch == NULL)
return;
switch (rot)
{
case 1: // 顺时针90度
lcd->swapXY(true);
lcd->mirrorX(true);
lcd->mirrorY(false);
touch->swapXY(true);
touch->mirrorX(true);
touch->mirrorY(false);
break;
case 2:
lcd->swapXY(false);
lcd->mirrorX(true);
lcd->mirrorY(true);
touch->swapXY(false);
touch->mirrorX(true);
touch->mirrorY(true);
break;
case 3:
lcd->swapXY(true);
lcd->mirrorX(false);
lcd->mirrorY(true);
touch->swapXY(true);
touch->mirrorX(false);
touch->mirrorY(true);
break;
default:
lcd->swapXY(false);
lcd->mirrorX(false);
lcd->mirrorY(false);
touch->swapXY(false);
touch->mirrorX(false);
touch->mirrorY(false);
break;
}
}
void screen_switch(bool on)
{
if (NULL == backlight)
return;
if (on)
backlight->on();
else
backlight->off();
}
// 输入值为0-100
void set_brightness(uint8_t bri)
{
if (NULL == backlight)
return;
backlight->setBrightness(bri);
}
/* static void touchpad_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{
ESP_PanelTouch *tp = (ESP_PanelTouch *)indev_drv->user_data;
ESP_PanelTouchPoint point;
int read_touch_result = tp->readPoints(&point, 1);
if (read_touch_result > 0)
{
data->point.x = point.x;
data->point.y = point.y;
data->state = LV_INDEV_STATE_PRESSED;
}
else
{
data->state = LV_INDEV_STATE_RELEASED;
}
} */
/* static lv_indev_t *indev_init(ESP_PanelTouch *tp)
{
ESP_UTILS_CHECK_FALSE_RETURN(tp != nullptr, nullptr, "Invalid touch device");
ESP_UTILS_CHECK_FALSE_RETURN(tp->getHandle() != nullptr, nullptr, "Touch device is not initialized");
static lv_indev_drv_t indev_drv_tp;
lv_indev_drv_init(&indev_drv_tp);
indev_drv_tp.type = LV_INDEV_TYPE_POINTER;
indev_drv_tp.read_cb = touchpad_read;
indev_drv_tp.user_data = (void *)tp;
return lv_indev_drv_register(&indev_drv_tp);
} */
static Touch *create_touch_without_config(void)
{
BusI2C *bus = new BusI2C(
TOUCH_PIN_NUM_I2C_SCL, TOUCH_PIN_NUM_I2C_SDA,
(BusI2C::ControlPanelFullConfig)ESP_PANEL_TOUCH_I2C_CONTROL_PANEL_CONFIG(TOUCH_NAME)
// mystical error with incomprehensible define
// lib/ESP32_Display_Panel/src/drivers/touch/esp_panel_touch.hpp:761:5: error: 'ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG_WITH_ADDR' was not declared in this scope;
// (BusI2C::ControlPanelFullConfig)ESP_PANEL_TOUCH_I2C_CONTROL_PANEL_CONFIG_WITH_ADDR(TOUCH_NAME, TOUCH_IO_I2C_CST816S_ADDRESS)
// (BusI2C::ControlPanelFullConfig)ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG()
);
/**
* Take GT911 as an example, the following is the actual code after macro expansion:
* TouchGT911(bus, 320, 240, 13, 14);
*/
return new EXAMPLE_TOUCH_CLASS(
TOUCH_NAME, bus, SCREEN_RES_HOR, SCREEN_RES_VER,
TOUCH_PIN_NUM_RST, TOUCH_PIN_NUM_INT
);
}
void scr_lvgl_init()
{
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = LEDC_TIMER_13_BIT,
.timer_num = LEDC_TIMER_0,
.freq_hz = 1000,
// .freq_hz = 5000,
.clk_cfg = LEDC_AUTO_CLK};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
ledc_channel_config_t ledc_channel = {
.gpio_num = (TFT_BLK),
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER_0,
.duty = 0,
.hpoint = 0};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
// backlight = new ESP_PanelBacklight(ledc_timer, ledc_channel);
// BacklightPWM_LEDC *backlight = new BacklightPWM_LEDC(TFT_BLK, 50);
backlight = new BacklightPWM_LEDC(TFT_BLK, 50);
backlight->begin();
backlight->off();
// touch_bus->configI2cFreqHz(400000);
// touch_bus->begin();
// touch = new ESP_PanelTouch_CST816S(touch_bus, SCREEN_RES_HOR, SCREEN_RES_VER, TOUCH_PIN_NUM_RST, TOUCH_PIN_NUM_INT);
touch = create_touch_without_config();
/* Configure bus and touch before startup */
auto bus = static_cast<BusI2C *>(touch->getBus());
bus->configI2C_FreqHz(TOUCH_I2C_FREQ_HZ);
bus->configI2C_PullupEnable(TOUCH_I2C_SDA_PULLUP, TOUCH_I2C_SCL_PULLUP);
touch->configResetActiveLevel(TOUCH_RST_ACTIVE_LEVEL);
/* Startup the LCD and operate it */
assert(touch->begin());
// touch->init();
// touch->begin();
/* #if TOUCH_PIN_NUM_INT >= 0
touch->attachInterruptCallback(onTouchInterruptCallback, NULL);
#endif */
ESP_PanelBus_QSPI *panel_bus = new ESP_PanelBus_QSPI(TFT_CS, TFT_SCK, TFT_SDA0, TFT_SDA1, TFT_SDA2, TFT_SDA3);
panel_bus->configQspiFreqHz(TFT_SPI_FREQ_HZ);
panel_bus->begin();
lcd = new ESP_PanelLcd_ST77916(panel_bus, 16, TFT_RST);
// lcd = new ESP_PanelLcd_ST77916(panel_bus, 8, TFT_RST);
// 注意,初始化代码的设置必须在INIT之前
// lcd->configVendorCommands(lcd_init_cmd, sizeof(lcd_init_cmd) / sizeof(lcd_init_cmd[0]));
lcd->init();
lcd->reset();
lcd->begin();
lcd->invertColor(true);
// lcd->invertColor(false);
// setRotation(0); //设置屏幕方向
lcd->displayOn();
screen_switch(true);
// backlight->setBrightness(100); // 设置亮度
// backlight->setBrightness(brightness); // 设置亮度
size_t lv_cache_rows = 72;
// size_t lv_buffer_size = SCREEN_RES_HOR * SCREEN_RES_VER * sizeof(lv_color_t);
size_t lv_buffer_size = SCREEN_RES_HOR * SCREEN_RES_VER;
disp_draw_buf = (lv_color_t *)heap_caps_malloc(lv_cache_rows * SCREEN_RES_HOR * 2, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
// disp_draw_buf = (lv_color_t *)ps_malloc(lv_buffer_size);
assert(disp_draw_buf);
// buf1 = (lv_color_t *)ps_malloc(lv_buffer_size);
buf1 = (lv_color_t *)heap_caps_malloc(lv_buffer_size, MALLOC_CAP_SPIRAM);
assert(buf1);
lv_init();
lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, buf1, SCREEN_RES_HOR * lv_cache_rows);
// lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, buf1, SCREEN_RES_HOR * SCREEN_RES_VER);
/* // new setup
drawBufSize = screenWidth * screenHeight;
buf1= (lv_color_t*)heap_caps_malloc(drawBufSize, MALLOC_CAP_SPIRAM);
assert(buf1);
buf2 = (lv_color_t*)heap_caps_malloc(drawBufSize, MALLOC_CAP_SPIRAM);
assert(buf2);
lv_init();
lv_disp_draw_buf_init(&draw_buf, buf1, buf2, SCREEN_RES_HOR * SCREEN_RES_VER); */
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = SCREEN_RES_HOR;
disp_drv.ver_res = SCREEN_RES_VER;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
disp_drv.user_data = (void *)lcd;
lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
if (lcd->getBus()->getType() != ESP_PANEL_BUS_TYPE_SPI)
// if (lcd->getBus()->getType() != ESP_PANEL_BUS_TYPE_RGB)
{
lcd->attachRefreshFinishCallback(onRefreshFinishCallback, (void *)disp->driver);
}
// indev_touchpad = indev_init(touch);
}
#endif // _SCR_ST77916_H_At the moment I have stopped migrating to the
then when compiling you get a
When you specify a line like this:
Then the compilation moves on, and as I already said, it still gets stuck on
And all this was used in this form:
Why is this left in the new version of the library, if we configure the display via the
Now they only get this: Maybe I didn't include the |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
Hello @Lzw655😀 I cleaned up the #ifndef _SCR_ST77916_H_
#define _SCR_ST77916_H_
#include "pincfg.h"
#include <lvgl.h>
// includes ESP32_IO_Expander at once
#include <esp_display_panel.hpp>
using namespace esp_panel::drivers;
#define SCREEN_RES_HOR 280
#define SCREEN_RES_VER 280
// to shift the reduced screen away from the origin
#define RATIO (360 - SCREEN_RES_HOR) / 2
extern int brightness;
static lv_color_t *disp_draw_buf = NULL;
static lv_color_t *buf1 = NULL;
static lv_color_t *buf2 = NULL;
static lv_disp_draw_buf_t draw_buf;
static lv_disp_drv_t disp_drv;
BacklightPWM_LEDC *backlight;
static ESP_PanelLcd *lcd = NULL;
Touch *touch = nullptr;
#define _EXAMPLE_TOUCH_CLASS(name, ...) Touch##name(__VA_ARGS__)
#define EXAMPLE_TOUCH_CLASS(name, ...) _EXAMPLE_TOUCH_CLASS(name, ##__VA_ARGS__)
#define _EXAMPLE_LCD_CLASS(name, ...) LCD_##name(__VA_ARGS__)
#define EXAMPLE_LCD_CLASS(name, ...) _EXAMPLE_LCD_CLASS(name, ##__VA_ARGS__)
// new setup
uint32_t screenWidth;
uint32_t screenHeight;
uint32_t drawBufSize;
IRAM_ATTR bool onTouchInterruptCallback(void *user_data)
{
return false;
}
IRAM_ATTR bool onLCD_DrawFinishCallback(void *user_data)
{
esp_rom_printf("LCD draw finish callback\n");
return false;
}
const esp_lcd_panel_vendor_init_cmd_t lcd_init_cmd[] = {
{0xF0, (uint8_t[]){0x08}, 1, 0},
{0xF2, (uint8_t[]){0x08}, 1, 0},
...
{0x11, (uint8_t[]){0x00}, 1, 120},
{0x29, (uint8_t[]){0x00}, 1, 0},
};
static void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
ESP_PanelLcd *lcd = (ESP_PanelLcd *)disp->user_data;
const int offsetx1 = area->x1;
const int offsetx2 = area->x2;
const int offsety1 = area->y1;
const int offsety2 = area->y2;
// lcd->drawBitmap(offsetx1, offsety1, offsetx2 - offsetx1 + 1, offsety2 - offsety1 + 1, (const uint8_t *)color_p);
lcd->drawBitmap(offsetx1 + RATIO, offsety1 + RATIO, offsetx2 - offsetx1 + 1, offsety2 - offsety1 + 1, (const uint8_t *)color_p);
}
IRAM_ATTR bool onRefreshFinishCallback(void *user_data)
{
lv_disp_drv_t *drv = (lv_disp_drv_t *)user_data;
lv_disp_flush_ready(drv);
return false;
}
void setRotation(uint8_t rot)
{
if (rot > 3)
return;
if (lcd == NULL || touch == NULL)
return;
switch (rot)
{
case 1: // 顺时针90度
lcd->swapXY(true);
lcd->mirrorX(true);
lcd->mirrorY(false);
touch->swapXY(true);
touch->mirrorX(true);
touch->mirrorY(false);
break;
case 2:
lcd->swapXY(false);
lcd->mirrorX(true);
lcd->mirrorY(true);
touch->swapXY(false);
touch->mirrorX(true);
touch->mirrorY(true);
break;
case 3:
lcd->swapXY(true);
lcd->mirrorX(false);
lcd->mirrorY(true);
touch->swapXY(true);
touch->mirrorX(false);
touch->mirrorY(true);
break;
default:
lcd->swapXY(false);
lcd->mirrorX(false);
lcd->mirrorY(false);
touch->swapXY(false);
touch->mirrorX(false);
touch->mirrorY(false);
break;
}
}
void screen_switch(bool on)
{
if (NULL == backlight)
return;
if (on)
backlight->on();
else
backlight->off();
}
void set_brightness(uint8_t bri)
{
if (NULL == backlight)
return;
backlight->setBrightness(bri);
}
static Touch *create_touch_without_config(void)
{
BusI2C *bus = new BusI2C(
TOUCH_PIN_NUM_I2C_SCL, TOUCH_PIN_NUM_I2C_SDA,
(BusI2C::ControlPanelFullConfig)ESP_PANEL_TOUCH_I2C_CONTROL_PANEL_CONFIG(TOUCH_NAME)
// mystical error with incomprehensible define
// lib/ESP32_Display_Panel/src/drivers/touch/esp_panel_touch.hpp:761:5: error: 'ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG_WITH_ADDR' was not declared in this scope;
// (BusI2C::ControlPanelFullConfig)ESP_PANEL_TOUCH_I2C_CONTROL_PANEL_CONFIG_WITH_ADDR(TOUCH_NAME, TOUCH_IO_I2C_CST816S_ADDRESS)
// (BusI2C::ControlPanelFullConfig)ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG()
);
/**
* Take GT911 as an example, the following is the actual code after macro expansion:
* TouchGT911(bus, 320, 240, 13, 14);
*/
return new EXAMPLE_TOUCH_CLASS(
TOUCH_NAME, bus, SCREEN_RES_HOR, SCREEN_RES_VER,
TOUCH_PIN_NUM_RST, TOUCH_PIN_NUM_INT
);
}
static LCD *create_lcd_without_config(void)
{
BusQSPI *bus = new BusQSPI(
TFT_CS, TFT_SCK,
TFT_SDA0, TFT_SDA1, TFT_SDA2, TFT_SDA3
);
/**
* Take `ST77922` as an example, the following is the actual code after macro expansion:
* LCD_ST77922(bus, 532, 300, 16, 3);
*/
return new EXAMPLE_LCD_CLASS(
LCD_NAME, bus, SCREEN_RES_HOR, SCREEN_RES_VER, LCD_COLOR_BITS, TFT_RST
);
}
void scr_lvgl_init()
{
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = LEDC_TIMER_13_BIT,
.timer_num = LEDC_TIMER_0,
.freq_hz = 1000,
// .freq_hz = 5000,
.clk_cfg = LEDC_AUTO_CLK};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
ledc_channel_config_t ledc_channel = {
.gpio_num = (TFT_BLK),
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER_0,
.duty = 0,
.hpoint = 0};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
backlight = new BacklightPWM_LEDC(TFT_BLK, 50);
backlight->begin();
backlight->off();
touch = create_touch_without_config();
auto lcd = create_lcd_without_config();
/* Configure bus, lcd and touch before startup */
auto bus1 = static_cast<BusI2C *>(touch->getBus());
auto bus2 = static_cast<BusQSPI *>(lcd->getBus());
bus1->configI2C_FreqHz(TOUCH_I2C_FREQ_HZ);
bus1->configI2C_PullupEnable(TOUCH_I2C_SDA_PULLUP, TOUCH_I2C_SCL_PULLUP);
touch->configResetActiveLevel(TOUCH_RST_ACTIVE_LEVEL);
bus2->configQSPI_FreqHz(LCD_QSPI_FREQ_HZ);
/* Startup the LCD and operate it */
assert(touch->begin());
// Attach a callback function which will be called when every bitmap drawing is completed
lcd->attachDrawBitmapFinishCallback(onLCD_DrawFinishCallback);
/* Startup the LCD and operate it */
assert(lcd->begin());
lcd->displayOn();
screen_switch(true);
size_t lv_cache_rows = 72;
// size_t lv_buffer_size = SCREEN_RES_HOR * SCREEN_RES_VER * sizeof(lv_color_t);
size_t lv_buffer_size = SCREEN_RES_HOR * SCREEN_RES_VER;
disp_draw_buf = (lv_color_t *)heap_caps_malloc(lv_cache_rows * SCREEN_RES_HOR * 2, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
// disp_draw_buf = (lv_color_t *)ps_malloc(lv_buffer_size);
assert(disp_draw_buf);
// buf1 = (lv_color_t *)ps_malloc(lv_buffer_size);
buf1 = (lv_color_t *)heap_caps_malloc(lv_buffer_size, MALLOC_CAP_SPIRAM);
assert(buf1);
lv_init();
lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, buf1, SCREEN_RES_HOR * lv_cache_rows);
// lv_disp_draw_buf_init(&draw_buf, disp_draw_buf, buf1, SCREEN_RES_HOR * SCREEN_RES_VER);
/* // new setup
drawBufSize = screenWidth * screenHeight;
buf1= (lv_color_t*)heap_caps_malloc(drawBufSize, MALLOC_CAP_SPIRAM);
assert(buf1);
buf2 = (lv_color_t*)heap_caps_malloc(drawBufSize, MALLOC_CAP_SPIRAM);
assert(buf2);
lv_init();
lv_disp_draw_buf_init(&draw_buf, buf1, buf2, SCREEN_RES_HOR * SCREEN_RES_VER); */
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = SCREEN_RES_HOR;
disp_drv.ver_res = SCREEN_RES_VER;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
disp_drv.user_data = (void *)lcd;
lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
/* if (lcd->getBus()->getType() != ESP_PANEL_BUS_TYPE_SPI)
// if (lcd->getBus()->getType() != ESP_PANEL_BUS_TYPE_RGB)
{
lcd->attachRefreshFinishCallback(onRefreshFinishCallback, (void *)disp->driver);
} */
// indev_touchpad = indev_init(touch);
}
#endif // _SCR_ST77916_H_I managed to assemble this Could you help please with the code, I can't understand the repository examples with a lot of files here: and
I collected the file |
Beta Was this translation helpful? Give feedback.
-
|
Hi @brightproject,
This is caused by insufficient SRAM. Since the current SPI driver cannot directly transfer data on PSRAM through DMA, the SPI driver will default to applying for an SRAM of the same size and copying the data from PSRAM for transmission. Your lvgl buffer is allocated on PSRAM and is quite large, with a size of Solution: Based on using the ESP32_Display_Panel v1 version, use
This is because the current CST816 driver initialization will default to reading the ID, and some CST816 chips will fail to perform this operation. Solution: Comment out |
Beta Was this translation helpful? Give feedback.
-
|
Ok, I saw that there is also the ESP_PanelBus_QSPI *panel_bus = new ESP_PanelBus_QSPI(TFT_CS, TFT_SCK, TFT_SDA0, TFT_SDA1, TFT_SDA2, TFT_SDA3);
panel_bus->configQspiFreqHz(TFT_SPI_FREQ_HZ);
// Modification
panel_bus->configQspiTransQueueDepth(1);
panel_bus->begin(); |
Beta Was this translation helpful? Give feedback.
-
I tried this feature for version Thank you for your participation😀 Unfortunately, at the moment I couldn't migrate to the latest version of
For example, this code
is replaced by And so on with the touch panel and backlight.
I was able to run my widget without problems, and what's good is that it runs on version IMG_4553.MOV |
Beta Was this translation helpful? Give feedback.



Ok, I saw that there is also the
configQspiTransQueueDepth()API inv0.1.4. You can refer to the following modifications: