Description
Running a self designed display of 5 units or more with information display I AM USING ARDUINO IDE TO COMPILE
What MCU/Processor/Board and compiler are you using?
ESP32-S3 4.3inch Capacitive Touch Display Development Board, 800×480, 5-point Touch, 32-bit
LX7 Dual-core Processor.
What LVGL version are you using?
Version 8.3.6 if I update the version using this board Compilation Errors occur.
What do you want to achieve?
Square line GUI development accept for this specific board I really want to use Square line as its
easy to understand for me. I am not on a level yet where I can write the whole code including
functions events etc. I just want some advice and a point into the rite direction on how to export
the files from Square line as this board uses the ST 7262 Driver and Square line exports in (TFT
eSPI) and integrates LVGL and since its a integrated display you cannot define the pins in config
files. Any point in the rite direction would be greatly appreciated. The Code I provide is a working
example code if Square line exports the files is obviously different
What have you tried so far?
I have tried using Square line Studio to export the GUI project as it adds LVGL libraries and
designing options are relatively easy to use and understand. And to write and add through the
sample code provided which works to a certain point.
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
The code block(s) should be formatted like:
/**
* The example demonstrates how to port LVGL.
*
* ## How to Use
*
* To use this example, please firstly install `ESP32_Display_Panel` (including its dependent libraries) and
* `lvgl` (v8.3.x) libraries, then follow the steps to configure them:
*
* 1. [Configure ESP32_Display_Panel](https://github.com/esp-arduino-libs/ESP32_Display_Panel#configure-esp32_display_panel)
* 2. [Configure LVGL](https://github.com/esp-arduino-libs/ESP32_Display_Panel#configure-lvgl)
* 3. [Configure Board](https://github.com/esp-arduino-libs/ESP32_Display_Panel#configure-board)
*
* ## Example Output
*
* ```bash
* ...
* Hello LVGL! V8.3.8
* I am ESP32_Display_Panel
* Starting LVGL task
* Setup done
* Loop
* Loop
* Loop
* Loop
* ...
* ```
*/
#include <Arduino.h>
#include <lvgl.h>
#include <ESP_Panel_Library.h>
#include <ESP_IOExpander_Library.h>
#include "lv_conf.h"
#include <demos/lv_demos.h>
// Extend IO Pin define
#define TP_RST 1
#define LCD_BL 2
#define LCD_RST 3
#define SD_CS 4
#define USB_SEL 5
// I2C Pin define
#define I2C_MASTER_NUM 0
#define I2C_MASTER_SDA_IO 8
#define I2C_MASTER_SCL_IO 9
/**
/* To use the built-in examples and demos of LVGL uncomment the includes below respectively.
* You also need to copy `lvgl/examples` to `lvgl/src/examples`. Similarly for the demos `lvgl/demos` to `lvgl/src/demos`.
*/
#include <demos/lv_demos.h>
#include <examples/lv_examples.h>
/* LVGL porting configurations */
#define LVGL_TICK_PERIOD_MS (2)
#define LVGL_TASK_MAX_DELAY_MS (500)
#define LVGL_TASK_MIN_DELAY_MS (1)
#define LVGL_TASK_STACK_SIZE (4 * 1024)
#define LVGL_TASK_PRIORITY (2)
#define LVGL_BUF_SIZE (ESP_PANEL_LCD_H_RES * 20)
ESP_Panel *panel = NULL;
SemaphoreHandle_t lvgl_mux = NULL; // LVGL mutex
#if ESP_PANEL_LCD_BUS_TYPE == ESP_PANEL_BUS_TYPE_RGB
/* Display flushing */
void lvgl_port_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
panel->getLcd()->drawBitmap(area->x1, area->y1, area->x2 + 1, area->y2 + 1, color_p);
lv_disp_flush_ready(disp);
}
#else
/* Display flushing */
void lvgl_port_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
panel->getLcd()->drawBitmap(area->x1, area->y1, area->x2 + 1, area->y2 + 1, color_p);
}
bool notify_lvgl_flush_ready(void *user_ctx)
{
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
lv_disp_flush_ready(disp_driver);
return false;
}
#endif /* ESP_PANEL_LCD_BUS_TYPE */
#if ESP_PANEL_USE_LCD_TOUCH
/* Read the touchpad */
void lvgl_port_tp_read(lv_indev_drv_t * indev, lv_indev_data_t * data)
{
panel->getLcdTouch()->readData();
bool touched = panel->getLcdTouch()->getTouchState();
if(!touched) {
data->state = LV_INDEV_STATE_REL;
} else {
TouchPoint point = panel->getLcdTouch()->getPoint();
data->state = LV_INDEV_STATE_PR;
/*Set the coordinates*/
data->point.x = point.x;
data->point.y = point.y;
Serial.printf("Touch point: x %d, y %d\n", point.x, point.y);
}
}
#endif
void lvgl_port_lock(int timeout_ms)
{
const TickType_t timeout_ticks = (timeout_ms < 0) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
xSemaphoreTakeRecursive(lvgl_mux, timeout_ticks);
}
void lvgl_port_unlock(void)
{
xSemaphoreGiveRecursive(lvgl_mux);
}
void lvgl_port_task(void *arg)
{
Serial.println("Starting LVGL task");
uint32_t task_delay_ms = LVGL_TASK_MAX_DELAY_MS;
while (1) {
// Lock the mutex due to the LVGL APIs are not thread-safe
lvgl_port_lock(-1);
task_delay_ms = lv_timer_handler();
// Release the mutex
lvgl_port_unlock();
if (task_delay_ms > LVGL_TASK_MAX_DELAY_MS) {
task_delay_ms = LVGL_TASK_MAX_DELAY_MS;
} else if (task_delay_ms < LVGL_TASK_MIN_DELAY_MS) {
task_delay_ms = LVGL_TASK_MIN_DELAY_MS;
}
vTaskDelay(pdMS_TO_TICKS(task_delay_ms));
}
}
void setup()
{
Serial.begin(115200); /* prepare for possible serial debug */
String LVGL_Arduino = "";
Serial.println(LVGL_Arduino);
Serial.println("I am ESP32_Display_Panel");
panel = new ESP_Panel();
/* Initialize LVGL core */
lv_init();
/* Initialize LVGL buffers */
static lv_disp_draw_buf_t draw_buf;
/* Using double buffers is more faster than single buffer */
/* Using internal SRAM is more fast than PSRAM (Note: Memory allocated using `malloc` may be located in PSRAM.) */
uint8_t *buf = (uint8_t *)heap_caps_calloc(1, LVGL_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_INTERNAL);
assert(buf);
lv_disp_draw_buf_init(&draw_buf, buf, NULL, LVGL_BUF_SIZE);
/* Initialize the display device */
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
/* Change the following line to your display resolution */
disp_drv.hor_res = ESP_PANEL_LCD_H_RES;
disp_drv.ver_res = ESP_PANEL_LCD_V_RES;
disp_drv.flush_cb = lvgl_port_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
#if ESP_PANEL_USE_LCD_TOUCH
/* Initialize the input device */
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = lvgl_port_tp_read;
lv_indev_drv_register(&indev_drv);
#endif
/* Initialize bus and device of panel */
panel->init();
#if ESP_PANEL_LCD_BUS_TYPE != ESP_PANEL_BUS_TYPE_RGB
/* Register a function to notify LVGL when the panel is ready to flush */
/* This is useful for refreshing the screen using DMA transfers */
panel->getLcd()->setCallback(notify_lvgl_flush_ready, &disp_drv);
#endif
/**
* These development boards require the use of an IO expander to configure the screen,
* so it needs to be initialized in advance and registered with the panel for use.
*
*/
Serial.println("Initialize IO expander");
/* Initialize IO expander */
// ESP_IOExpander *expander = new ESP_IOExpander_CH422G(I2C_MASTER_NUM, ESP_IO_EXPANDER_I2C_CH422G_ADDRESS_000, I2C_MASTER_SCL_IO, I2C_MASTER_SDA_IO);
ESP_IOExpander *expander = new ESP_IOExpander_CH422G(I2C_MASTER_NUM, ESP_IO_EXPANDER_I2C_CH422G_ADDRESS_000);
expander->init();
expander->begin();
expander->multiPinMode(TP_RST | LCD_BL | LCD_RST | SD_CS | USB_SEL, OUTPUT);
expander->multiDigitalWrite(TP_RST | LCD_BL | LCD_RST | SD_CS, HIGH);
// Turn off backlight
// expander->digitalWrite(USB_SEL, LOW);
expander->digitalWrite(USB_SEL, LOW);
/* Add into panel */
panel->addIOExpander(expander);
/* Start panel */
panel->begin();
/* Create a task to run the LVGL task periodically */
lvgl_mux = xSemaphoreCreateRecursiveMutex();
xTaskCreate(lvgl_port_task, "lvgl", LVGL_TASK_STACK_SIZE, NULL, LVGL_TASK_PRIORITY, NULL);
/* Lock the mutex due to the LVGL APIs are not thread-safe */
lvgl_port_lock(-1);
/* Create simple label */
lv_obj_t *label = lv_label_create(lv_scr_act());
lv_label_set_text(label, LVGL_Arduino.c_str());
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
/**
* Try an example. Don't forget to uncomment header.
* See all the examples online: https://docs.lvgl.io/master/examples.html
* source codes: https://github.com/lvgl/lvgl/tree/e7f88efa5853128bf871dde335c0ca8da9eb7731/examples
*/
// lv_example_btn_1();
/**
* Or try out a demo.
* Don't forget to uncomment header and enable the demos in `lv_conf.h`. E.g. `LV_USE_DEMOS_WIDGETS`
*/
//lv_demo_widgets();
// lv_demo_benchmark();
// lv_demo_music();
// lv_demo_stress();
/* Release the mutex */
lvgl_port_unlock();
Serial.println("Setup done");
}
void loop()
{
// Serial.println("Loop");
sleep(1);
}
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.