Hi, I add a new models to display Lvgl demo.I use ESP32-WROVER-B module. Epaper display is use Waveshare 5.83 HAT.
Then I follow this project to do it.
lv_port_esp32-epaper
I imitate wave12i48.h wave12i48.cpp then build waveshare583Hat.h waveshare583Hat.cpp file.
The key functions are as follows:
drawPixel function:
void WaveShare0583Hat::drawPixel(int16_t x, int16_t y, uint16_t color) {
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) return;
switch (getRotation())
{
case 1:
swap(x, y);
x = WaveShare0583_WIDTH - x - 1;
break;
case 2:
x = WaveShare0583_WIDTH - x - 1;
y = WaveShare0583_HEIGHT - y - 1;
break;
case 3:
swap(x, y);
y = WaveShare0583_HEIGHT - y - 1;
break;
}
uint32_t i = x / 8 + y * WaveShare0583_WIDTH / 8;
if (!color) {
_buffer[i] = (_buffer[i] | (1 << (7 - x % 8)));
} else {
_buffer[i] = (_buffer[i] & (0xFF ^ (1 << (7 - x % 8))));
}
}
update function is:
void WaveShare0583Hat::update(){
uint64_t startTime = esp_timer_get_time();
uint16_t Width = ( WaveShare0583_WIDTH % 8 == 0 ) ? (WaveShare0583_WIDTH / 8) : (WaveShare0583_WIDTH / 8 + 1);
uint16_t Height = WaveShare0583_HEIGHT;
//_wakeUp();
IO.cmd(0x13);
if (spi_optimized) {
uint32_t i = 0;
uint16_t xLineBytes = ( WaveShare0583_WIDTH % 8 == 0 ) ? (WaveShare0583_WIDTH / 8) : (WaveShare0583_WIDTH / 8 + 1);
// xLineBytes = 81
uint8_t x1buf[xLineBytes];
for (uint16_t y = 1; y <= WaveShare0583_HEIGHT; y++)
{
for (uint16_t x = 1; x <= xLineBytes; x++)
{
uint8_t data = i < sizeof(_buffer) ? _buffer[i] : 0x00;
x1buf[x - 1] = data;
if (x == xLineBytes)
{ // Flush the X line buffer to SPI
IO.data(x1buf, sizeof(x1buf));
}
++i;
}
}
} else {
for (uint32_t i = 0; i < sizeof(_buffer); i++) {
IO.data(_buffer[i]);
}
}
IO.cmd(0x12);
vTaskDelay(100 / portTICK_PERIOD_MS);
_waitBusy("0x12 display refresh");
uint64_t endTime = esp_timer_get_time();
uint64_t powerOnTime = esp_timer_get_time();
printf("\n\nSTATS (ms)\n%llu _wakeUp settings+send Buffer\n%llu _powerOn\n%llu total time in millis\n",
(endTime-startTime)/1000, (powerOnTime-endTime)/1000, (powerOnTime-startTime)/1000);
}
finally, I try flash epaper demo:
static void create_epd_demo_application(void)
{
// Notes: After first refresh the tabview boxes are loosing their top margin
// Also refreshing certain areas is messing the framebuffer (corrupted?)
tv = lv_tabview_create(lv_scr_act(), NULL);
lv_obj_set_height(tv,320);
lv_obj_t *btn = lv_btn_create(tv, NULL);
// Printing this button 10 pixel y down, refreshed it again to 0,0 in the pixel callback. Why?
lv_obj_set_pos(btn, 10, 200);
lv_obj_set_width(btn, lv_obj_get_width_grid(tv, 2, 1));
label = lv_label_create(btn, NULL);
lv_label_set_text(label, "Small");
//lv_obj_set_event_cb(btn, btn_cb);
lv_obj_t *btn2 = lv_btn_create(tv, NULL);
// obj , x , y -> Doing a Y more than 100 it simply get's the down part of the button out
// and prints this button end in the top left (Buf too small?)
lv_obj_set_pos(btn2, 480, 90);
lv_obj_set_width(btn2, lv_obj_get_width_grid(tv, 2, 1));
label2 = lv_label_create(btn2, NULL);
lv_label_set_text(label2, "BUTTON 2");
//lv_obj_set_event_cb(btn2, btn2_cb);
lv_obj_t * cb = lv_checkbox_create(tv, NULL);
lv_checkbox_set_text(cb, "I do not agree.");
lv_obj_align(cb, NULL, LV_ALIGN_IN_TOP_LEFT, 30, 80);
//lv_obj_set_event_cb(cb, checkbox_handler);
/*Create a normal drop down list*/
lv_obj_t * ddlist = lv_dropdown_create(tv, NULL);
lv_dropdown_set_options(ddlist, "Apple\n"
"Banana\n"
"Orange\n"
"Melon\n"
"Grape\n"
"Raspberry");
lv_obj_align(ddlist, NULL, LV_ALIGN_IN_TOP_RIGHT, -20, 20);
/*Create a switch and apply the styles*/
lv_obj_t *sw1 = lv_switch_create(tv, NULL);
lv_obj_set_pos(sw1, 230, 80);
//lv_obj_set_event_cb(sw1, btn_sleep_cb);
lv_obj_t *sw_label = lv_label_create(tv, NULL);
lv_obj_align(sw_label, sw1, LV_LABEL_ALIGN_CENTER, 0, 28);
lv_label_set_text(sw_label, "SLEEP");
}
Then the screen draws only the 680*48 area.
The COM log as follows:
CalEPD component version 1.0.6
WaveShare0583Hat() constructor injects IO and extends Adafruit_GFX(648,480)
e[0;32mI (1325) cpu_start: Starting scheduler on PRO CPU.e[0m
e[0;32mI (0) cpu_start: Starting scheduler on APP CPU.e[0m
app_main started. DISP_BUF_SIZE:58320 LV_HOR_RES_MAX:648 V_RES_MAX:480
guiTask start
e[0;32mI (20) lvgl_helpers: Display hor size: 648, ver size: 480e[0m
e[0;32mI (20) lvgl_helpers: Display buffer size: 58320e[0m
e[0;32mI (30) lvgl_helpers: Initializing Parallel driver for displaye[0m
calepd_init
EpdSPI started at frequency: 4000000
calepd_init
DISP_BUF_SIZE 58320
create_demo_application start
flush 1 x:0 y:0 w:648 h:48
STATS (ms)
2310 _wakeUp settings+send Buffer
0 _powerOn
2310 total time in millis
flush 2 x:0 y:48 w:648 h:48
STATS (ms)
1885 _wakeUp settings+send Buffer
0 _powerOn
1885 total time in millis
flush 3 x:0 y:96 w:648 h:48
STATS (ms)
2303 _wakeUp settings+send Buffer
0 _powerOn
2303 total time in millis
flush 4 x:0 y:144 w:648 h:48
STATS (ms)
1911 _wakeUp settings+send Buffer
0 _powerOn
1911 total time in millis
flush 5 x:0 y:192 w:648 h:48
STATS (ms)
2311 _wakeUp settings+send Buffer
0 _powerOn
2311 total time in millis
flush 6 x:0 y:240 w:648 h:48
STATS (ms)
1879 _wakeUp settings+send Buffer
0 _powerOn
1879 total time in millis
flush 7 x:0 y:288 w:648 h:48
STATS (ms)
2299 _wakeUp settings+send Buffer
0 _powerOn
2299 total time in millis
flush 8 x:0 y:336 w:648 h:48
STATS (ms)
1891 _wakeUp settings+send Buffer
0 _powerOn
1891 total time in millis
flush 9 x:0 y:384 w:648 h:48
STATS (ms)
2311 _wakeUp settings+send Buffer
0 _powerOn
2311 total time in millis
flush 10 x:0 y:432 w:648 h:48
STATS (ms)
1891 _wakeUp settings+send Buffer
0 _powerOn
1891 total time in millis