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

@ -50,20 +50,29 @@ static void guiTask(void *pvParameter)
{
(void) pvParameter;
lv_init();
lvgl_driver_init();
lv_color_t* buf1 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
/* Initialize the needed peripherals */
lvgl_interface_init();
/* Initialize needed GPIOs, e.g. backlight, reset GPIOs */
display_bsp_init_io();
/* ToDo Initialize used display driver passing registered lv_disp_drv_t as parameter */
size_t display_buffer_size = lvgl_get_display_buffer_size();
lv_color_t* buf1 = heap_caps_malloc(display_buffer_size * sizeof(lv_color_t), MALLOC_CAP_DMA);
assert(buf1 != NULL);
static lv_disp_draw_buf_t disp_buf;
lv_disp_draw_buf_init(&disp_buf, buf1, NULL, DISP_BUF_SIZE * 8);
lv_disp_draw_buf_init(&disp_buf, buf1, NULL, display_buffer_size * 8);
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.flush_cb = disp_driver_flush;
disp_drv.rounder_cb = disp_driver_rounder;
disp_drv.set_px_cb = disp_driver_set_px;
disp_drv.draw_buffer = &disp_buf;
disp_drv.draw_buf = &disp_buf;
/* LVGL v8: Set display horizontal and vertical resolution (in pixels), it's no longer done with lv_conf.h */
disp_drv.hor_res = 128u;
disp_drv.ver_res = 64u;
lv_disp_drv_register(&disp_drv);
/* Create and start a periodic timer interrupt to call lv_tick_inc */
@ -77,6 +86,8 @@ static void guiTask(void *pvParameter)
/* Create a Hellow World label on the currently active screen */
lv_obj_t *scr = lv_disp_get_scr_act(NULL);
/* LVGL v8 lv_label_create no longer takes 2 parameters */
lv_obj_t *label1 = lv_label_create(scr);
lv_label_set_text(label1, "Hello\nworld");

View file

@ -9,6 +9,7 @@
#include "sdkconfig.h"
#include "lvgl_helpers.h"
#include "esp_log.h"
#include "esp_idf_version.h"
#include "lvgl_tft/disp_spi.h"
#include "lvgl_touch/tp_spi.h"
@ -29,6 +30,8 @@
#define TAG "lvgl_helpers"
#define GPIO_NOT_USED (-1)
#define DMA_DEFAULT_TRANSFER_SIZE (0u)
/**********************
* TYPEDEFS
**********************/
@ -37,6 +40,13 @@
* STATIC PROTOTYPES
**********************/
/**
* Calculates the SPI max transfer size based on the display buffer size
*
* @return SPI max transfer size in bytes
*/
static int calculate_spi_max_transfer_size(const int display_buffer_size);
/**********************
* STATIC VARIABLES
**********************/
@ -49,8 +59,8 @@
* GLOBAL FUNCTIONS
**********************/
/* Interface and driver initialization */
void lvgl_driver_init(void)
/* Interface (SPI, I2C) initialization */
void lvgl_interface_init(void)
{
/* Since LVGL v8 LV_HOR_RES_MAX and LV_VER_RES_MAX are not defined, so
* print it only if they are defined. */
@ -58,14 +68,17 @@ void lvgl_driver_init(void)
ESP_LOGI(TAG, "Display hor size: %d, ver size: %d", LV_HOR_RES_MAX, LV_VER_RES_MAX);
#endif
ESP_LOGI(TAG, "Display buffer size: %d", DISP_BUF_SIZE);
ESP_LOGI(TAG, "Display buffer size: %d", lvgl_get_display_buffer_size());
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
ESP_LOGI(TAG, "Initializing SPI master for FT81X");
size_t display_buffer_size = lvgl_get_display_buffer_size();
int spi_max_transfer_size = calculate_spi_max_transfer_size(display_buffer_size);
lvgl_spi_driver_init(TFT_SPI_HOST,
DISP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
SPI_BUS_MAX_TRANSFER_SZ, 1,
spi_max_transfer_size, SPI_DMA_CH1,
DISP_SPI_IO2, DISP_SPI_IO3);
disp_spi_add_device(TFT_SPI_HOST);
@ -77,32 +90,31 @@ void lvgl_driver_init(void)
return;
#endif
/* Display controller initialization */
#if defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI) || defined (SHARED_SPI_BUS)
ESP_LOGI(TAG, "Initializing SPI master");
int miso = DISP_SPI_MISO;
size_t display_buffer_size = lvgl_get_display_buffer_size();
int spi_max_transfer_size = calculate_spi_max_transfer_size(display_buffer_size);
#if defined (SHARED_SPI_BUS)
ESP_LOGI(TAG, "Initializing shared SPI master");
miso = TP_SPI_MISO;
#endif
lvgl_spi_driver_init(TFT_SPI_HOST,
TP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
SPI_BUS_MAX_TRANSFER_SZ, 1,
-1, -1);
miso, DISP_SPI_MOSI, DISP_SPI_CLK,
spi_max_transfer_size, SPI_DMA_CH1,
DISP_SPI_IO2, DISP_SPI_IO3);
disp_spi_add_device(TFT_SPI_HOST);
#if defined (SHARED_SPI_BUS)
tp_spi_add_device(TOUCH_SPI_HOST);
touch_driver_init();
return;
#endif
/* Display controller initialization */
#if defined CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI
ESP_LOGI(TAG, "Initializing SPI master for display");
lvgl_spi_driver_init(TFT_SPI_HOST,
DISP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
SPI_BUS_MAX_TRANSFER_SZ, 1,
DISP_SPI_IO2, DISP_SPI_IO3);
disp_spi_add_device(TFT_SPI_HOST);
#elif defined (CONFIG_LV_I2C_DISPLAY)
#else
#error "No protocol defined for display controller"
@ -115,8 +127,8 @@ void lvgl_driver_init(void)
lvgl_spi_driver_init(TOUCH_SPI_HOST,
TP_SPI_MISO, TP_SPI_MOSI, TP_SPI_CLK,
0 /* Defaults to 4094 */, 2,
-1, -1);
DMA_DEFAULT_TRANSFER_SIZE, SPI_DMA_CH2,
GPIO_NOT_USED, GPIO_NOT_USED);
tp_spi_add_device(TOUCH_SPI_HOST);
@ -157,7 +169,8 @@ void display_bsp_init_io(void)
ESP_ERROR_CHECK(err);
#endif
#if !defined(CONFIG_LV_DISP_BACKLIGHT_OFF) && defined(CONFIG_LV_DISP_PIN_BCKL)
#if !defined(CONFIG_LV_DISP_BACKLIGHT_OFF) && defined(CONFIG_LV_DISP_PIN_BCKL) && \
(CONFIG_LV_DISP_PIN_BCKL > 0)
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL << CONFIG_LV_DISP_PIN_BCKL);
err = gpio_config(&io_conf);
@ -172,6 +185,67 @@ void display_bsp_init_io(void)
#endif
}
/* DISP_BUF_SIZE value doesn't have an special meaning, but it's the size
* of the buffer(s) passed to LVGL as display buffers. The default values used
* were the values working for the contributor of the display controller.
*
* As LVGL supports partial display updates the DISP_BUF_SIZE doesn't
* necessarily need to be equal to the display size.
*
* When using RGB displays the display buffer size will also depends on the
* color format being used, for RGB565 each pixel needs 2 bytes.
* When using the mono theme, the display pixels can be represented in one bit,
* so the buffer size can be divided by 8, e.g. see SSD1306 display size. */
size_t lvgl_get_display_buffer_size(void)
{
size_t disp_buffer_size = 0;
#if LVGL_VERSION_MAJOR < 8
#if defined (CONFIG_CUSTOM_DISPLAY_BUFFER_SIZE)
disp_buffer_size = CONFIG_CUSTOM_DISPLAY_BUFFER_BYTES;
#else
/* Calculate total of 40 lines of display horizontal size */
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9486) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_GC9A01) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C)
disp_buffer_size = LV_HOR_RES_MAX * 40;
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107
disp_buffer_size = LV_HOR_RES_MAX * LV_VER_RES_MAX;
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306
#if defined (CONFIG_LV_THEME_MONO)
disp_buffer_size = LV_HOR_RES_MAX * (LV_VER_RES_MAX / 8);
#else
disp_buffer_size = LV_HOR_RES_MAX * LV_VER_RES_MAX);
#endif
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820)
disp_buffer_size = LV_VER_RES_MAX * IL3820_COLUMNS;
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A)
disp_buffer_size = ((LV_VER_RES_MAX * LV_VER_RES_MAX) / 8); // 5KB
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D)
disp_buffer_size = ((LV_VER_RES_MAX * LV_VER_RES_MAX) / 8); // 2888 bytes
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544)
disp_buffer_size = (LV_HOR_RES_MAX * (LV_VER_RES_MAX / 8));
#else
#error "No display controller selected"
#endif
#endif
#else /* LVGL v8 */
/* ToDo: Implement display buffer size calculation with configuration values from the display driver */
#endif
return disp_buffer_size;
}
/* Initialize spi bus master
*
* NOTE: dma_chan type and value changed to int instead of spi_dma_chan_t
@ -180,13 +254,18 @@ void display_bsp_init_io(void)
* We could use the ESP_IDF_VERSION_VAL macro available in the "esp_idf_version.h"
* header available since ESP-IDF v4.
*/
bool lvgl_spi_driver_init(int host,
bool lvgl_spi_driver_init(spi_host_device_t host,
int miso_pin, int mosi_pin, int sclk_pin,
int max_transfer_sz,
int dma_channel,
int quadwp_pin, int quadhd_pin)
{
assert((0 <= host) && (SPI_HOST_MAX > host));
#if defined (SPI_HOST_MAX)
assert((SPI1_HOST <= host) && (SPI_HOST_MAX > host));
#else
assert((SPI1_HOST <= host) && ((SPI3_HOST + 1) > host));
#endif
const char *spi_names[] = {
"SPI1_HOST", "SPI2_HOST", "SPI3_HOST"
};
@ -211,8 +290,37 @@ bool lvgl_spi_driver_init(int host,
dma_channel = SPI_DMA_CH_AUTO;
#endif
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
esp_err_t ret = spi_bus_initialize(host, &buscfg, (spi_dma_chan_t)dma_channel);
#else
esp_err_t ret = spi_bus_initialize(host, &buscfg, dma_channel);
#endif
assert(ret == ESP_OK);
return ESP_OK != ret;
}
static int calculate_spi_max_transfer_size(const int display_buffer_size)
{
int retval = 0;
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488)
retval = display_buffer_size * 3;
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C)
retval = display_buffer_size * 2;
#else
retval = display_buffer_size * 2;
#endif
return retval;
}

View file

@ -14,6 +14,8 @@ extern "C" {
*********************/
#include <stdbool.h>
#include "driver/spi_common.h"
#include "lvgl_spi_conf.h"
#include "lvgl_tft/disp_driver.h"
#include "lvgl_tft/esp_lcd_backlight.h"
@ -23,66 +25,6 @@ extern "C" {
* DEFINES
*********************/
/* DISP_BUF_SIZE value doesn't have an special meaning, but it's the size
* of the buffer(s) passed to LVGL as display buffers. The default values used
* were the values working for the contributor of the display controller.
*
* As LVGL supports partial display updates the DISP_BUF_SIZE doesn't
* necessarily need to be equal to the display size.
*
* When using RGB displays the display buffer size will also depends on the
* color format being used, for RGB565 each pixel needs 2 bytes.
* When using the mono theme, the display pixels can be represented in one bit,
* so the buffer size can be divided by 8, e.g. see SSD1306 display size. */
#if defined (CONFIG_CUSTOM_DISPLAY_BUFFER_SIZE)
#define DISP_BUF_SIZE CONFIG_CUSTOM_DISPLAY_BUFFER_BYTES
#else
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789)
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9486
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306
#if defined (CONFIG_LV_THEME_MONO)
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * (LV_VER_RES_MAX / 8))
#else
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
#endif
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
#define DISP_BUF_LINES 40
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * DISP_BUF_LINES)
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820)
#define DISP_BUF_SIZE (LV_VER_RES_MAX * IL3820_COLUMNS)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_GC9A01)
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A)
#define DISP_BUF_SIZE ((LV_VER_RES_MAX * LV_VER_RES_MAX) / 8) // 5KB
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D)
#define DISP_BUF_SIZE ((LV_VER_RES_MAX * LV_VER_RES_MAX) / 8) // 2888 bytes
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_PCD8544)
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * (LV_VER_RES_MAX / 8))
#else
#error "No display controller selected"
#endif
#endif
/**********************
* TYPEDEFS
**********************/
@ -94,14 +36,18 @@ extern "C" {
void lvgl_i2c_locking(void* leader);
/* Initialize detected SPI and I2C bus and devices */
void lvgl_driver_init(void);
void lvgl_interface_init(void);
/* Initialize SPI master */
bool lvgl_spi_driver_init(int host, int miso_pin, int mosi_pin, int sclk_pin,
bool lvgl_spi_driver_init(spi_host_device_t host, int miso_pin, int mosi_pin, int sclk_pin,
int max_transfer_sz, int dma_channel, int quadwp_pin, int quadhd_pin);
/* Initialize display GPIOs, e.g. DC and RST pins */
void display_bsp_init_io(void);
/* Get display buffer size */
size_t lvgl_get_display_buffer_size(void);
/**********************
* MACROS
**********************/

View file

@ -114,27 +114,6 @@ extern "C" {
/**********************
* TYPEDEFS
**********************/
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488)
#define SPI_BUS_MAX_TRANSFER_SZ (DISP_BUF_SIZE * 3)
#elif defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_SH1107) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A) || \
defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9163C)
#define SPI_BUS_MAX_TRANSFER_SZ (DISP_BUF_SIZE * 2)
#else
#define SPI_BUS_MAX_TRANSFER_SZ (DISP_BUF_SIZE * 2)
#endif
#if defined (CONFIG_LV_TFT_USE_CUSTOM_SPI_CLK_DIVIDER)
#define SPI_TFT_CLOCK_SPEED_HZ ((80 * 1000 * 1000) / CONFIG_LV_TFT_CUSTOM_SPI_CLK_DIVIDER)
#else

View file

@ -267,7 +267,13 @@ void EVE_memWrite_buffer(uint32_t ftAddress, const uint8_t *data, uint32_t len,
uint32_t bytes_left = len;
while(bytes_left > 0)
{
uint32_t block_len = (bytes_left > SPI_TRANSER_SIZE ? SPI_TRANSER_SIZE : bytes_left);
uint32_t block_len = 0;
#if defined (SPI_TRANSFER_SIZE)
block_len = (bytes_left > SPI_TRANSER_SIZE ? SPI_TRANSER_SIZE : bytes_left);
#else
/* ToDo Update SPI_TRANSFER_SIZE calculation, it's based on the DISP_BUF_SIZE */
#endif
// only send flush on last chunk
disp_spi_send_flag_t flush_flag = 0;

View file

@ -51,7 +51,11 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
#define EVE_PDN CONFIG_LV_DISP_PIN_RST // grey
#define EVE_USE_PDN CONFIG_LV_DISP_USE_RST
#if defined (DISP_BUF_SIZE)
#define SPI_TRANSER_SIZE (DISP_BUF_SIZE * (LV_COLOR_DEPTH / 8))
#else
/* ToDo Update using new API */
#endif
#define BYTES_PER_PIXEL (LV_COLOR_DEPTH / 8) // bytes per pixel for (16 for RGB565)
#define BYTES_PER_LINE (EVE_HSIZE * BYTES_PER_PIXEL)

View file

@ -20,8 +20,19 @@ extern "C"
/* Values for Waveshare 2.9inch e-Paper Module, this values shouldn't be
* swapped to change display orientation */
#if defined (LV_HOR_RES_MAX)
#define EPD_PANEL_WIDTH LV_HOR_RES_MAX /* 128 */
#else
/* Fallback to default value */
#define EPD_PANEL_WIDTH 128u
#endif
#if defined (LV_VER_RES_MAX)
#define EPD_PANEL_HEIGHT LV_VER_RES_MAX /* 296 */
#else
/* Fallback to default value */
#define EPD_PANEL_HEIGHT 296u
#endif
/* 128 = panel width */
#define IL3820_COLUMNS (EPD_PANEL_WIDTH / 8)

View file

@ -44,9 +44,24 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
#define PIN_BUSY CONFIG_LV_DISP_PIN_BUSY
#define PIN_BUSY_BIT ((1ULL << (uint8_t)(CONFIG_LV_DISP_PIN_BUSY)))
#define EVT_BUSY (1UL << 0UL)
#if defined (LV_HOR_RES_MAX)
#define EPD_WIDTH LV_HOR_RES_MAX
#else
/* ToDo Remove magic number */
#define EPD_WIDTH 256u
#endif
#if defined (LV_VER_RES_MAX)
#define EPD_HEIGHT LV_VER_RES_MAX
#else
/* ToDo Remove magic number */
#define EPD_HEIGHT 128u
#endif
#define EPD_ROW_LEN (EPD_HEIGHT / 8u)
/* ToDo Remove semicolon */
#define EPD_PARTIAL_CNT 5;
#define BIT_SET(a, b) ((a) |= (1U << (b)))
@ -200,21 +215,21 @@ static esp_err_t jd79653a_wait_busy(uint32_t timeout_ms)
return ((bits & EVT_BUSY) != 0) ? ESP_OK : ESP_ERR_TIMEOUT;
}
static void jd79653a_power_on()
static void jd79653a_power_on(void)
{
jd79653a_spi_send_seq(power_on_seq, EPD_SEQ_LEN(power_on_seq));
vTaskDelay(pdMS_TO_TICKS(10));
jd79653a_wait_busy(0);
}
static void jd79653a_power_off()
static void jd79653a_power_off(void)
{
jd79653a_spi_send_seq(power_off_seq, EPD_SEQ_LEN(power_off_seq));
vTaskDelay(pdMS_TO_TICKS(10));
jd79653a_wait_busy(0);
}
static void jd79653a_load_partial_lut()
static void jd79653a_load_partial_lut(void)
{
jd79653a_spi_send_cmd(0x20); // LUT VCOM register
jd79653a_spi_send_data((uint8_t *)lut_vcom_dc1, sizeof(lut_vcom_dc1));
@ -232,7 +247,7 @@ static void jd79653a_load_partial_lut()
jd79653a_spi_send_data((uint8_t *)lut_bb1, sizeof(lut_bb1));
}
static void jd79653a_partial_in()
static void jd79653a_partial_in(void)
{
LV_LOG_INFO("Partial in!");
@ -260,7 +275,7 @@ static void jd79653a_partial_in()
jd79653a_spi_send_cmd(0x91);
}
static void jd79653a_partial_out()
static void jd79653a_partial_out(void)
{
LV_LOG_INFO("Partial out!");
@ -378,7 +393,7 @@ void jd79653a_fb_full_update(uint8_t *data, size_t len)
jd79653a_power_off();
}
void jd79653a_lv_set_fb_cb(struct _disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
void jd79653a_lv_set_fb_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)
{
uint16_t byte_index = (x >> 3u) + (y * EPD_ROW_LEN);
@ -391,7 +406,7 @@ void jd79653a_lv_set_fb_cb(struct _disp_drv_t *disp_drv, uint8_t *buf, lv_coord_
}
}
void jd79653a_lv_rounder_cb(struct _disp_drv_t *disp_drv, lv_area_t *area)
void jd79653a_lv_rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area)
{
// Always send full framebuffer if it's not in partial mode
area->x1 = 0;
@ -419,7 +434,7 @@ void jd79653a_lv_fb_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t
lv_disp_flush_ready(drv);
}
void jd79653a_deep_sleep()
void jd79653a_deep_sleep(void)
{
jd79653a_spi_send_seq(power_off_seq, EPD_SEQ_LEN(power_off_seq));
jd79653a_wait_busy(1000);
@ -429,7 +444,7 @@ void jd79653a_deep_sleep()
jd79653a_spi_send_data(&check_code, sizeof(check_code));
}
void jd79653a_init()
void jd79653a_init(void)
{
// Initialise event group
jd79653a_evts = xEventGroupCreate();

View file

@ -17,12 +17,12 @@ extern "C"
#include "lvgl/lvgl.h"
#endif
void jd79653a_init();
void jd79653a_deep_sleep();
void jd79653a_init(void);
void jd79653a_deep_sleep(void);
void jd79653a_lv_set_fb_cb(struct _disp_drv_t * disp_drv, uint8_t* buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
void jd79653a_lv_set_fb_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);
void jd79653a_lv_rounder_cb(struct _disp_drv_t * disp_drv, lv_area_t *area);
void jd79653a_lv_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t *area);
void jd79653a_lv_fb_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
void jd79653a_fb_set_full_color(uint8_t color);

View file

@ -26,8 +26,19 @@
#define BYTES_PER_PIXEL (LV_COLOR_DEPTH / 8)
#if defined (LV_HOR_RES_MAX)
#define HDWR_VAL (LV_HOR_RES_MAX/8 - 1)
#else
/* ToDo Remove magic number 256u */
#define HDWR_VAL (256u/8u - 1u)
#endif
#if defined (LV_VER_RES_MAX)
#define VDHR_VAL (LV_VER_RES_MAX - 1)
#else
/* ToDo Remove magic number 128u */
#define VDHR_VAL (128u - 1u)
#endif
#define VDIR_MASK (1 << 2)
#define HDIR_MASK (1 << 3)
@ -234,7 +245,16 @@ void ra8875_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
// Set window if needed
if ((x1 != area->x1) || (x2 != area->x2)) {
LV_LOG_INFO("flush: set window (x1,x2): %d,%d -> %d,%d", x1, x2, area->x1, area->x2);
ra8875_set_window(area->x1, area->x2, 0, LV_VER_RES_MAX-1);
unsigned int ye = 0;
#if LVGL_VERSION_MAJOR < 8
ye = LV_VER_RES_MAX - 1;
#else
/* ToDo Get y end from driver information */
#endif
ra8875_set_window(area->x1, area->x2, 0, ye);
x1 = area->x1;
x2 = area->x2;
}
@ -248,7 +268,16 @@ void ra8875_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
// Update to future cursor location
y = area->y2 + 1;
if (y >= LV_VER_RES_MAX) {
lv_coord_t ver_max = 0;
#if LVGL_VERSION_MAJOR < 8
ver_max = LV_VER_RES_MAX;
#else
/* ToDo Get vertical max from driver information */
ver_max = lv_disp_get_ver_res((lv_disp_t *) drv);
#endif
if (y >= ver_max) {
y = 0;
}

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;
}

View file

@ -39,8 +39,8 @@ extern "C" {
void sh1107_init(void);
void sh1107_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
void sh1107_rounder(struct _disp_drv_t * disp_drv, lv_area_t *area);
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_rounder(lv_disp_drv_t * disp_drv, lv_area_t *area);
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);
void sh1107_sleep_in(void);
void sh1107_sleep_out(void);

View file

@ -45,8 +45,21 @@
#define PIN_BUSY CONFIG_LV_DISP_PIN_BUSY
#define PIN_BUSY_BIT ((1ULL << (uint8_t)(CONFIG_LV_DISP_PIN_BUSY)))
#define EVT_BUSY (1UL << 0UL)
#if defined (LV_HOR_RES_MAX)
#define EPD_WIDTH LV_HOR_RES_MAX
#else
/* ToDo Fix, 256 is just a magic number */
#define EPD_WIDTH 256u
#endif
#if defined (LV_VER_RES_MAX)
#define EPD_HEIGHT LV_VER_RES_MAX
#else
/* ToDo Fix, 128 is just a magic number */
#define EPD_HEIGHT 128u
#endif
#define EPD_ROW_LEN (EPD_HEIGHT / 8u)
#define BIT_SET(a, b) ((a) |= (1U << (b)))
@ -105,7 +118,7 @@ static esp_err_t uc8151d_wait_busy(uint32_t timeout_ms)
return ((bits & EVT_BUSY) != 0) ? ESP_OK : ESP_ERR_TIMEOUT;
}
static void uc8151d_sleep()
static void uc8151d_sleep(void)
{
// Set VCOM to 0xf7
uc8151d_spi_send_cmd(0x50);
@ -122,7 +135,7 @@ static void uc8151d_sleep()
static void uc8151d_reset(void);
static void uc8151d_panel_init()
static void uc8151d_panel_init(void)
{
// Hardware reset for 3 times - not sure why but it's from official demo code
for (uint8_t cnt = 0; cnt < 3; cnt++) {
@ -186,7 +199,7 @@ void uc8151d_lv_fb_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *
LV_LOG_INFO("Ready");
}
void uc8151d_lv_set_fb_cb(struct _disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
void uc8151d_lv_set_fb_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)
{
uint16_t byte_index = (x >> 3u) + (y * EPD_ROW_LEN);
@ -200,7 +213,7 @@ void uc8151d_lv_set_fb_cb(struct _disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t
}
}
void uc8151d_lv_rounder_cb(struct _disp_drv_t *disp_drv, lv_area_t *area)
void uc8151d_lv_rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area)
{
// Always send full framebuffer if it's not in partial mode
area->x1 = 0;
@ -209,7 +222,7 @@ void uc8151d_lv_rounder_cb(struct _disp_drv_t *disp_drv, lv_area_t *area)
area->y2 = EPD_HEIGHT - 1;
}
void uc8151d_init()
void uc8151d_init(void)
{
// Initialise event group
uc8151d_evts = xEventGroupCreate();

View file

@ -29,11 +29,11 @@
#include <lvgl.h>
void uc8151d_init();
void uc8151d_lv_set_fb_cb(struct _disp_drv_t *disp_drv, uint8_t *buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
void uc8151d_init(void);
void uc8151d_lv_set_fb_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);
void uc8151d_lv_rounder_cb(struct _disp_drv_t *disp_drv, lv_area_t *area);
void uc8151d_lv_rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area);
void uc8151d_lv_fb_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map);
#endif //LVGL_DEMO_UC8151D_H