Update helpers and drivers to handle LVGLv7 and v8 versions (#161)

* [lvgl_helpers] Cleanup and misc code cleanup

Checks for SPI_HOST_MAX symbol before using it.

Rename lvgl_driver_init to lvgl_interface_init because it now only initialize
the interface bus for display drivers, we still need to remove the indev
drivers from here.

Use types defined in spi_types.h for spi host (spi_host_device_t) and
spi dma channels (spi_dma_chan_t).

Also add a couple of symbols to avoid using magic numbers

* [lvgl_helpers] Reduce usage of if defined in lvgl_interface_init

* [lvgl_helpers] Fix spi dma channel for ESP-IDF versions <= 4.2

* [examples] Update hello_world to call lvgl_interface_init

* Add lvgl_get_display_buffer_size helper

This helper will allow us to get the calculated display buffer size instead of using a global symbol.

* Implement lvgl_get_display_buffer_size

This API will be used to get the calculation of display buffer size.

* Delete DISP_BUF_SIZE symbols

The same functionality is handled by lvgl_get_display_buffer_size

* Move SPI max transfer size calculation to helper

Use calculate_spi_max_transfer_size to calculate the SPI max transfer size for the SPI master configuration

* Remove SPI_BUS_MAX_TRANSFER_SZ definition

Same functionality is now handled in calculate_spi_max_transfer_size

* Update display buffer size calculation

Use lvgl_get_display_buffer_size helper instead of DISP_BUF_SIZE symbol

* Update example to LVGL v8

Add comments about changes from:
- LVGL v7 to LVGL v8
- Configuration helpers and display drivers

* Update lvgl_helpers.c

* Update sh1107 driver

* Update EVE driver

Check for symbols used in previous implementations before trying to use them
and add a fallback temporary implementation when not found.

The falback implementation isn't tested with hardware.

Symbols:
- DISP_BUF_SIZE
- SPI_TRANSFER_SIZE

* Update uc8151d driver

* Update jd79653a driver

* Update ra8875 driver

* Update il3820.h

Check for LV_HOR_RES_MAX and LV_VER_RES_MAX before trying to use them

* Update lvgl_helpers.c

Check for ESP-IDF version before trying to use spi_dma_chan_t type
This commit is contained in:
Carlos Diaz 2022-01-07 17:22:11 -06:00 committed by GitHub
parent bb0e3a1f27
commit 17eb416ef8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 309 additions and 148 deletions

View file

@ -35,6 +35,9 @@ static void sh1107_send_cmd(uint8_t cmd);
static void sh1107_send_data(void * data, uint16_t length);
static void sh1107_send_color(void * data, uint16_t length);
static lv_coord_t get_display_ver_res(lv_disp_drv_t *disp_drv);
static lv_coord_t get_display_hor_res(lv_disp_drv_t *disp_drv);
/**********************
* STATIC VARIABLES
**********************/
@ -117,7 +120,7 @@ void sh1107_init(void)
}
}
void sh1107_set_px_cb(struct _disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
void sh1107_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_color_t color, lv_opa_t opa)
{
/* buf_w will be ignored, the configured CONFIG_LV_DISPLAY_HEIGHT and _WIDTH,
@ -126,10 +129,10 @@ void sh1107_set_px_cb(struct _disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t b
uint8_t bit_index = 0;
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
byte_index = y + (( x>>3 ) * LV_VER_RES_MAX);
byte_index = y + (( x>>3 ) * get_display_ver_res(disp_drv));
bit_index = x & 0x7;
#elif defined CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT
byte_index = x + (( y>>3 ) * LV_HOR_RES_MAX);
byte_index = x + (( y>>3 ) * get_display_hor_res(disp_drv));
bit_index = y & 0x7;
#endif
@ -161,9 +164,9 @@ void sh1107_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
sh1107_send_cmd(0xB0 | i); // Set Page Start Address for Page Addressing Mode
size = area->y2 - area->y1 + 1;
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
ptr = color_map + i * LV_VER_RES_MAX;
ptr = color_map + i * get_display_ver_res(drv);
#else
ptr = color_map + i * LV_HOR_RES_MAX;
ptr = color_map + i * get_display_hor_res(drv);
#endif
if(i != row2){
sh1107_send_data( (void *) ptr, size);
@ -174,21 +177,21 @@ void sh1107_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
}
}
void sh1107_rounder(struct _disp_drv_t * disp_drv, lv_area_t *area)
void sh1107_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area)
{
// workaround: always send complete size display buffer
area->x1 = 0;
area->y1 = 0;
area->x2 = LV_HOR_RES_MAX-1;
area->y2 = LV_VER_RES_MAX-1;
area->x2 = get_display_hor_res(disp_drv) - 1;
area->y2 = get_display_ver_res(disp_drv) - 1;
}
void sh1107_sleep_in()
void sh1107_sleep_in(void)
{
sh1107_send_cmd(0xAE);
}
void sh1107_sleep_out()
void sh1107_sleep_out(void)
{
sh1107_send_cmd(0xAF);
}
@ -218,3 +221,39 @@ static void sh1107_send_color(void * data, uint16_t length)
gpio_set_level(SH1107_DC, 1); /*Data mode*/
disp_spi_send_colors(data, length);
}
static lv_coord_t get_display_ver_res(lv_disp_drv_t *disp_drv)
{
lv_coord_t val = 0;
#if LVGL_VERSION_MAJOR < 8
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
val = LV_VER_RES_MAX;
#endif
#else
/* ToDo Use display rotation API to get vertical size */
#if defined CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE
val = lv_disp_get_ver_res((lv_disp_t *) disp_drv);
#endif
#endif
return val;
}
static lv_coord_t get_display_hor_res(lv_disp_drv_t *disp_drv)
{
lv_coord_t val = 0;
#if LVGL_VERSION_MAJOR < 8
#if defined CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT
val = LV_HOR_RES_MAX;
#endif
#else
/* ToDo Use display rotation API to get horizontal size */
#if defined CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT
val = lv_disp_get_hor_res((lv_disp_t *) disp_drv);
#endif
#endif
return val;
}