Update epdiy driver using it standalone, without CalEPD. Previous is not epdiy_cale.cpp

This commit is contained in:
Martin Fasani 2021-06-01 16:10:59 +02:00
parent debae0b814
commit 19b1ecde22

View file

@ -4,63 +4,93 @@
#include "epdiy_epaper.h" #include "epdiy_epaper.h"
// NOTE: This needs Epdiy component https://github.com/vroland/epdiy #include "epd_driver.h"
// Run idf.py menuconfig-> Component Config -> E-Paper driver and select: #include "epd_highlevel.h"
// Display type: LILIGO 4.7 ED047TC1
// Board: LILIGO T5-4.7 Epaper
// In the same section Component Config -> ESP32 Specifics -> Enable PSRAM
#include "parallel/ED047TC1.h"
Ed047TC1 display;
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
#define TAG "EPDIY" #define TAG "EPDIY"
EpdiyHighlevelState hl;
uint16_t flushcalls = 0; uint16_t flushcalls = 0;
uint8_t * framebuffer;
uint8_t temperature = 25;
/* Display initialization routine */ /* Display initialization routine */
void epdiy_init(void) void epdiy_init(void)
{ {
printf("epdiy_init\n"); epd_init(EPD_OPTIONS_DEFAULT);
display.init(); hl = epd_hl_init(EPD_BUILTIN_WAVEFORM);
display.setRotation(0); framebuffer = epd_hl_get_framebuffer(&hl);
display.clearScreen(); epd_fullclear(&hl, temperature);
epd_poweron();
} }
uint16_t xo = 0;
uint16_t yo = 0;
/* Required by LVGL */ /* Required by LVGL */
void epdiy_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) void epdiy_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
{ {
++flushcalls; ++flushcalls;
printf("epdiy_flush %d x:%d y:%d w:%d h:%d\n", flushcalls,area->x1,area->y1,lv_area_get_width(area),lv_area_get_height(area)); xo = area->x1;
yo = area->y1;
uint16_t w = lv_area_get_width(area);
uint16_t h = lv_area_get_height(area);
// Full update EpdRect update_area = {
if (lv_area_get_width(area)==display.width() && lv_area_get_height(area)==display.height()) { .x = xo,
display.update(); .y = yo,
} else { .width = w,
// Partial update: Looks nice but should find a way to clear that area first. Mode: MODE_EPDIY_WHITE_TO_GL16 .height = h,
display.updateWindow(area->x1,area->y1,lv_area_get_width(area),lv_area_get_height(area),MODE_GC16); };
}
/* IMPORTANT!!! // Debug test: Draw box x:232 y:78 w:496 h:198. Flush coords are correct:
* Inform the graphics library that you are ready with the flushing */ /* EpdRect rect_area = {
.x = 232,
.y = 78,
.width = 496,
.height = 198,
};
epd_draw_rect(rect_area, 0, framebuffer); */
epd_hl_update_area(&hl, MODE_GC16, temperature, update_area); //update_area
printf("epdiy_flush %d x:%d y:%d w:%d h:%d\n", flushcalls,xo,yo,w,h);
/* Inform the graphics library that you are ready with the flushing */
lv_disp_flush_ready(drv); lv_disp_flush_ready(drv);
} }
/* Called for each pixel */ /*
* Called for each pixel. Designed with the idea to fill the buffer directly, not to set each pixel, see:
* https://forum.lvgl.io/t/lvgl-port-to-be-used-with-epaper-displays/5630/3
*/
void epdiy_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t* buf, void epdiy_set_px_cb(lv_disp_drv_t * disp_drv, uint8_t* buf,
lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
lv_color_t color, lv_opa_t opa) lv_color_t color, lv_opa_t opa)
{ {
// Is printing Y axis only till 40 px: And flushing too many times // Debug where x y is printed, not all otherwise is too much Serial
//printf("%d ", (int16_t)y); // Works and prints "Hello world" /* if ((int16_t)y%10==0 && flushcalls>0){
//printf("%d ",(int16_t)color.full); // Debug colors if ((int16_t)x%2==0){
printf("x%d y%d\n", (int16_t)x, (int16_t)y);
}
}
*/
// Test using RGB232 // Test using RGB232
int16_t epd_color = EPD_WHITE; int16_t epd_color = 255;
// Color setting use: RGB232 // Color setting use: RGB232
if ((int16_t)color.full<250) { if ((int16_t)color.full<250) {
epd_color = (int16_t)color.full/3; epd_color = (int16_t)color.full/3;
} }
display.drawPixel((int16_t)x, (int16_t)y, epd_color);
int16_t x1 = (int16_t)x;
int16_t y1 = (int16_t)y;
// Add offsets from last flush test. Why is drawing in wrong place?
// Bad idea: But is just writing in different area. And I don't understand why:
/* if (flushcalls>0) {
x1 = x1 + xo;
y1 = y1 + yo;
} */
epd_draw_pixel(x1, y1, epd_color, framebuffer);
} }