2020-12-17 06:02:55 +00:00
|
|
|
/**
|
|
|
|
* @file lvgl_helpers.c
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "lvgl_helpers.h"
|
|
|
|
#include "esp_log.h"
|
|
|
|
|
|
|
|
#include "lvgl_tft/disp_spi.h"
|
|
|
|
#include "lvgl_touch/tp_spi.h"
|
|
|
|
|
|
|
|
#include "lvgl_spi_conf.h"
|
|
|
|
|
2021-07-08 09:04:07 +00:00
|
|
|
#include "i2c_manager/i2c_manager.h"
|
2020-12-17 06:02:55 +00:00
|
|
|
|
2020-12-23 22:06:47 +00:00
|
|
|
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
2021-06-16 02:01:36 +00:00
|
|
|
#include "lvgl.h"
|
2021-06-08 03:00:17 +00:00
|
|
|
#else
|
2021-06-16 02:01:36 +00:00
|
|
|
#include "lvgl/lvgl.h"
|
2020-12-23 22:06:47 +00:00
|
|
|
#endif
|
2020-12-17 06:02:55 +00:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
#define TAG "lvgl_helpers"
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/* Interface and driver initialization */
|
|
|
|
void lvgl_driver_init(void)
|
|
|
|
{
|
2021-06-08 02:57:00 +00:00
|
|
|
/* Since LVGL v8 LV_HOR_RES_MAX and LV_VER_RES_MAX are not defined, so
|
|
|
|
* print it only if they are defined. */
|
|
|
|
#if (LVGL_VERSION_MAJOR < 8)
|
2020-12-17 06:02:55 +00:00
|
|
|
ESP_LOGI(TAG, "Display hor size: %d, ver size: %d", LV_HOR_RES_MAX, LV_VER_RES_MAX);
|
2021-06-08 02:57:00 +00:00
|
|
|
#endif
|
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
ESP_LOGI(TAG, "Display buffer size: %d", DISP_BUF_SIZE);
|
|
|
|
|
|
|
|
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
|
|
|
|
ESP_LOGI(TAG, "Initializing SPI master for FT81X");
|
|
|
|
|
|
|
|
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);
|
2021-07-08 09:04:07 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
disp_spi_add_device(TFT_SPI_HOST);
|
|
|
|
disp_driver_init();
|
|
|
|
|
|
|
|
#if defined (CONFIG_LV_TOUCH_CONTROLLER_FT81X)
|
|
|
|
touch_driver_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined (SHARED_SPI_BUS)
|
|
|
|
ESP_LOGI(TAG, "Initializing shared SPI master");
|
|
|
|
|
|
|
|
lvgl_spi_driver_init(TFT_SPI_HOST,
|
|
|
|
TP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
|
|
|
|
SPI_BUS_MAX_TRANSFER_SZ, 1,
|
|
|
|
-1, -1);
|
2021-07-08 09:04:07 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
disp_spi_add_device(TFT_SPI_HOST);
|
|
|
|
tp_spi_add_device(TOUCH_SPI_HOST);
|
|
|
|
|
|
|
|
disp_driver_init();
|
|
|
|
touch_driver_init();
|
2021-07-08 09:04:07 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Display controller initialization */
|
|
|
|
#if defined CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI
|
|
|
|
ESP_LOGI(TAG, "Initializing SPI master for display");
|
2021-07-08 09:04:07 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
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);
|
2021-07-08 09:04:07 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
disp_spi_add_device(TFT_SPI_HOST);
|
2021-07-08 09:04:07 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
disp_driver_init();
|
2021-07-08 09:04:07 +00:00
|
|
|
#elif defined (CONFIG_LV_I2C_DISPLAY)
|
2020-12-17 06:02:55 +00:00
|
|
|
disp_driver_init();
|
|
|
|
#else
|
|
|
|
#error "No protocol defined for display controller"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Touch controller initialization */
|
|
|
|
#if CONFIG_LV_TOUCH_CONTROLLER != TOUCH_CONTROLLER_NONE
|
|
|
|
#if defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI)
|
|
|
|
ESP_LOGI(TAG, "Initializing SPI master for touch");
|
2021-07-08 09:04:07 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
lvgl_spi_driver_init(TOUCH_SPI_HOST,
|
|
|
|
TP_SPI_MISO, TP_SPI_MOSI, TP_SPI_CLK,
|
|
|
|
0 /* Defaults to 4094 */, 2,
|
|
|
|
-1, -1);
|
2021-07-08 09:04:07 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
tp_spi_add_device(TOUCH_SPI_HOST);
|
2021-07-08 09:04:07 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
touch_driver_init();
|
2021-07-08 09:04:07 +00:00
|
|
|
#elif defined (CONFIG_LV_I2C_TOUCH)
|
2020-12-17 06:02:55 +00:00
|
|
|
touch_driver_init();
|
|
|
|
#elif defined (CONFIG_LV_TOUCH_DRIVER_ADC)
|
|
|
|
touch_driver_init();
|
|
|
|
#elif defined (CONFIG_LV_TOUCH_DRIVER_DISPLAY)
|
|
|
|
touch_driver_init();
|
|
|
|
#else
|
|
|
|
#error "No protocol defined for touch controller"
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-22 18:05:58 +00:00
|
|
|
/* Initialize spi bus master
|
|
|
|
*
|
|
|
|
* NOTE: dma_chan type and value changed to int instead of spi_dma_chan_t
|
|
|
|
* for backwards compatibility with ESP-IDF versions prior v4.3.
|
|
|
|
*
|
|
|
|
* We could use the ESP_IDF_VERSION_VAL macro available in the "esp_idf_version.h"
|
|
|
|
* header available since ESP-IDF v4.
|
|
|
|
*/
|
2020-12-17 06:02:55 +00:00
|
|
|
bool lvgl_spi_driver_init(int host,
|
|
|
|
int miso_pin, int mosi_pin, int sclk_pin,
|
|
|
|
int max_transfer_sz,
|
|
|
|
int dma_channel,
|
|
|
|
int quadwp_pin, int quadhd_pin)
|
|
|
|
{
|
2021-06-22 18:05:58 +00:00
|
|
|
int dma_chan = 0 /* SPI_DMA_DISABLED */;
|
2021-06-11 03:22:44 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
#if defined (CONFIG_IDF_TARGET_ESP32)
|
|
|
|
assert((SPI_HOST <= host) && (VSPI_HOST >= host));
|
|
|
|
const char *spi_names[] = {
|
|
|
|
"SPI_HOST", "HSPI_HOST", "VSPI_HOST"
|
|
|
|
};
|
2021-06-11 03:22:44 +00:00
|
|
|
|
|
|
|
dma_chan = dma_channel;
|
2020-12-17 06:02:55 +00:00
|
|
|
#elif defined (CONFIG_IDF_TARGET_ESP32S2)
|
|
|
|
assert((SPI_HOST <= host) && (HSPI_HOST >= host));
|
|
|
|
const char *spi_names[] = {
|
|
|
|
"SPI_HOST", "", ""
|
|
|
|
};
|
2021-06-11 03:22:44 +00:00
|
|
|
|
|
|
|
dma_chan = dma_channel;
|
2021-06-08 15:26:03 +00:00
|
|
|
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
|
|
|
|
assert((SPI1_HOST <= host) && (SPI3_HOST >= host));
|
|
|
|
const char *spi_names[] = {
|
|
|
|
"SPI1_HOST", "SPI2_HOST", "SPI3_HOST"
|
|
|
|
};
|
2021-06-11 03:22:44 +00:00
|
|
|
|
2021-06-22 18:05:58 +00:00
|
|
|
dma_chan = 3 /* SPI_DMA_CH_AUTO */;
|
2021-06-08 15:26:03 +00:00
|
|
|
#else
|
|
|
|
#error "Target chip not selected"
|
2020-12-17 06:02:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ESP_LOGI(TAG, "Configuring SPI host %s (%d)", spi_names[host], host);
|
|
|
|
ESP_LOGI(TAG, "MISO pin: %d, MOSI pin: %d, SCLK pin: %d, IO2/WP pin: %d, IO3/HD pin: %d",
|
|
|
|
miso_pin, mosi_pin, sclk_pin, quadwp_pin, quadhd_pin);
|
|
|
|
|
|
|
|
ESP_LOGI(TAG, "Max transfer size: %d (bytes)", max_transfer_sz);
|
|
|
|
|
|
|
|
spi_bus_config_t buscfg = {
|
|
|
|
.miso_io_num = miso_pin,
|
|
|
|
.mosi_io_num = mosi_pin,
|
|
|
|
.sclk_io_num = sclk_pin,
|
|
|
|
.quadwp_io_num = quadwp_pin,
|
|
|
|
.quadhd_io_num = quadhd_pin,
|
|
|
|
.max_transfer_sz = max_transfer_sz
|
|
|
|
};
|
|
|
|
|
|
|
|
ESP_LOGI(TAG, "Initializing SPI bus...");
|
2021-06-11 03:22:44 +00:00
|
|
|
esp_err_t ret = spi_bus_initialize(host, &buscfg, dma_chan);
|
2020-12-17 06:02:55 +00:00
|
|
|
assert(ret == ESP_OK);
|
|
|
|
|
|
|
|
return ESP_OK != ret;
|
|
|
|
}
|
|
|
|
|