This commit is contained in:
Hiruna Wijesinghe 2023-06-03 14:41:05 +00:00 committed by GitHub
commit 98890bf42b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 521 additions and 288 deletions

View file

@ -86,7 +86,7 @@ endif()
idf_component_register(SRCS ${SOURCES} idf_component_register(SRCS ${SOURCES}
INCLUDE_DIRS ${LVGL_INCLUDE_DIRS} INCLUDE_DIRS ${LVGL_INCLUDE_DIRS}
REQUIRES lvgl) REQUIRES lvgl driver)
target_compile_definitions(${COMPONENT_LIB} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE") target_compile_definitions(${COMPONENT_LIB} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE")

View file

@ -16,6 +16,7 @@
#include "lvgl_spi_conf.h" #include "lvgl_spi_conf.h"
#include "lvgl_i2c/i2c_manager.h" #include "lvgl_i2c/i2c_manager.h"
#include "esp_idf_version.h"
#ifdef LV_LVGL_H_INCLUDE_SIMPLE #ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h" #include "lvgl.h"
@ -23,6 +24,9 @@
#include "lvgl/lvgl.h" #include "lvgl/lvgl.h"
#endif #endif
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
#define SPI_HOST_MAX SOC_SPI_PERIPH_NUM
#endif
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
@ -175,10 +179,14 @@ bool lvgl_spi_driver_init(int host,
}; };
ESP_LOGI(TAG, "Initializing SPI bus..."); ESP_LOGI(TAG, "Initializing SPI bus...");
#if defined (CONFIG_IDF_TARGET_ESP32C3) #if defined (CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3)
dma_channel = SPI_DMA_CH_AUTO; dma_channel = SPI_DMA_CH_AUTO;
#endif #endif
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4,3,0)
esp_err_t ret = spi_bus_initialize(host, &buscfg, dma_channel);
#else
esp_err_t ret = spi_bus_initialize(host, &buscfg, (spi_dma_chan_t)dma_channel); esp_err_t ret = spi_bus_initialize(host, &buscfg, (spi_dma_chan_t)dma_channel);
#endif
assert(ret == ESP_OK); assert(ret == ESP_OK);
return ESP_OK != ret; return ESP_OK != ret;

View file

@ -23,6 +23,14 @@ extern "C" {
* DEFINES * DEFINES
*********************/ *********************/
/* Backward compatibility for LV_HOR_RES_MAX & LV_VER_RES_MAX */
#if defined (CONFIG_LV_HOR_RES_MAX)
#define LV_HOR_RES_MAX CONFIG_LV_HOR_RES_MAX
#endif
#if defined (CONFIG_LV_VER_RES_MAX)
#define LV_VER_RES_MAX CONFIG_LV_VER_RES_MAX
#endif
/* DISP_BUF_SIZE value doesn't have an special meaning, but it's the size /* 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 * 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. * were the values working for the contributor of the display controller.
@ -40,7 +48,7 @@ extern "C" {
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789) #if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7789)
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40) #define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7735S
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40) #define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ST7796S
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40) #define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357 #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_HX8357
@ -56,7 +64,7 @@ extern "C" {
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341 #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40) #define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306 #elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306
#if defined (CONFIG_LV_THEME_MONO) #if defined (CONFIG_LV_USE_THEME_MONO)
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * (LV_VER_RES_MAX / 8)) #define DISP_BUF_SIZE (LV_HOR_RES_MAX * (LV_VER_RES_MAX / 8))
#else #else
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX) #define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)

View file

@ -6,10 +6,8 @@ menu "I2C Port 0"
if I2C_MANAGER_0_ENABLED if I2C_MANAGER_0_ENABLED
config I2C_MANAGER_0_SDA config I2C_MANAGER_0_SDA
int "SDA (GPIO pin)" int "SDA (GPIO pin)"
default 0
config I2C_MANAGER_0_SCL config I2C_MANAGER_0_SCL
int "SCL (GPIO pin)" int "SCL (GPIO pin)"
default 0
config I2C_MANAGER_0_FREQ_HZ config I2C_MANAGER_0_FREQ_HZ
int "Frequency (Hz)" int "Frequency (Hz)"
default 400000 default 400000

View file

@ -42,7 +42,7 @@ SOFTWARE.
#if defined __has_include #if defined __has_include
#if __has_include ("esp_idf_version.h") #if __has_include ("esp_idf_version.h")
#include "esp_idf_version.h" #include "esp_idf_version.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0) #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
#define HAS_CLK_FLAGS #define HAS_CLK_FLAGS
@ -58,29 +58,29 @@ static SemaphoreHandle_t* I2C_FN(_mutex) = &I2C_FN(_local_mutex)[0];
static const uint8_t ACK_CHECK_EN = 1; static const uint8_t ACK_CHECK_EN = 1;
#if defined (I2C_NUM_0) && defined (CONFIG_I2C_MANAGER_0_ENABLED) #if defined (CONFIG_I2C_MANAGER_0_ENABLED)
#define I2C_ZERO I2C_NUM_0 #define I2C_ZERO I2C_NUM_0
#if defined (CONFIG_I2C_MANAGER_0_PULLUPS) #if defined (CONFIG_I2C_MANAGER_0_PULLUPS)
#define I2C_MANAGER_0_PULLUPS true #define I2C_MANAGER_0_PULLUPS true
#else #else
#define I2C_MANAGER_0_PULLUPS false #define I2C_MANAGER_0_PULLUPS false
#endif #endif
#define I2C_MANAGER_0_TIMEOUT ( CONFIG_I2C_MANAGER_0_TIMEOUT / portTICK_RATE_MS ) #define I2C_MANAGER_0_TIMEOUT ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_TIMEOUT ) )
#define I2C_MANAGER_0_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT / portTICK_RATE_MS ) #define I2C_MANAGER_0_LOCK_TIMEOUT ( ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT ) )
#endif #endif
#if defined (I2C_NUM_1) && defined (CONFIG_I2C_MANAGER_1_ENABLED) #if defined (CONFIG_I2C_MANAGER_1_ENABLED)
#define I2C_ONE I2C_NUM_1 #define I2C_ONE I2C_NUM_1
#if defined (CONFIG_I2C_MANAGER_1_PULLUPS) #if defined (CONFIG_I2C_MANAGER_1_PULLUPS)
#define I2C_MANAGER_1_PULLUPS true #define I2C_MANAGER_1_PULLUPS true
#else #else
#define I2C_MANAGER_1_PULLUPS false #define I2C_MANAGER_1_PULLUPS false
#endif #endif
#define I2C_MANAGER_1_TIMEOUT ( CONFIG_I2C_MANAGER_1_TIMEOUT / portTICK_RATE_MS ) #define I2C_MANAGER_1_TIMEOUT ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_TIMEOUT ) )
#define I2C_MANAGER_1_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT / portTICK_RATE_MS ) #define I2C_MANAGER_1_LOCK_TIMEOUT ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT ) )
#endif #endif
#define ERROR_PORT(port, fail) { \ #define ERROR_PORT(port, fail) { \
@ -89,198 +89,198 @@ static const uint8_t ACK_CHECK_EN = 1;
} }
#if defined(I2C_ZERO) && defined (I2C_ONE) #if defined(I2C_ZERO) && defined (I2C_ONE)
#define I2C_PORT_CHECK(port, fail) \ #define I2C_PORT_CHECK(port, fail) \
if (port != I2C_NUM_0 && port != I2C_NUM_1) ERROR_PORT(port, fail); if (port != I2C_NUM_0 && port != I2C_NUM_1) ERROR_PORT(port, fail);
#else #else
#if defined(I2C_ZERO) #if defined(I2C_ZERO)
#define I2C_PORT_CHECK(port, fail) \ #define I2C_PORT_CHECK(port, fail) \
if (port != I2C_NUM_0) ERROR_PORT(port, fail); if (port != I2C_NUM_0) ERROR_PORT(port, fail);
#elif defined(I2C_ONE) #elif defined(I2C_ONE)
#define I2C_PORT_CHECK(port, fail) \ #define I2C_PORT_CHECK(port, fail) \
if (port != I2C_NUM_1) ERROR_PORT(port, fail); if (port != I2C_NUM_1) ERROR_PORT(port, fail);
#else #else
#define I2C_PORT_CHECK(port, fail) \ #define I2C_PORT_CHECK(port, fail) \
ERROR_PORT(port, fail); ERROR_PORT(port, fail);
#endif #endif
#endif #endif
static void i2c_send_address(i2c_cmd_handle_t cmd, uint16_t addr, i2c_rw_t rw) { static void i2c_send_address(i2c_cmd_handle_t cmd, uint16_t addr, i2c_rw_t rw) {
if (addr & I2C_ADDR_10) { if (addr & I2C_ADDR_10) {
i2c_master_write_byte(cmd, 0xF0 | ((addr & 0x3FF) >> 7) | rw, ACK_CHECK_EN); i2c_master_write_byte(cmd, 0xF0 | ((addr & 0x3FF) >> 7) | rw, ACK_CHECK_EN);
i2c_master_write_byte(cmd, addr & 0xFF, ACK_CHECK_EN); i2c_master_write_byte(cmd, addr & 0xFF, ACK_CHECK_EN);
} else { } else {
i2c_master_write_byte(cmd, (addr << 1) | rw, ACK_CHECK_EN); i2c_master_write_byte(cmd, (addr << 1) | rw, ACK_CHECK_EN);
} }
} }
static void i2c_send_register(i2c_cmd_handle_t cmd, uint32_t reg) { static void i2c_send_register(i2c_cmd_handle_t cmd, uint32_t reg) {
if (reg & I2C_REG_16) { if (reg & I2C_REG_16) {
i2c_master_write_byte(cmd, (reg & 0xFF00) >> 8, ACK_CHECK_EN); i2c_master_write_byte(cmd, (reg & 0xFF00) >> 8, ACK_CHECK_EN);
} }
i2c_master_write_byte(cmd, reg & 0xFF, ACK_CHECK_EN); i2c_master_write_byte(cmd, reg & 0xFF, ACK_CHECK_EN);
} }
esp_err_t I2C_FN(_init)(i2c_port_t port) { esp_err_t I2C_FN(_init)(i2c_port_t port) {
I2C_PORT_CHECK(port, ESP_FAIL); I2C_PORT_CHECK(port, ESP_FAIL);
esp_err_t ret = ESP_OK; esp_err_t ret = ESP_OK;
if (I2C_FN(_mutex)[port] == 0) { if (I2C_FN(_mutex)[port] == 0) {
ESP_LOGI(TAG, "Starting I2C master at port %d.", (int)port); ESP_LOGI(TAG, "Starting I2C master at port %d.", (int)port);
I2C_FN(_mutex)[port] = xSemaphoreCreateMutex(); I2C_FN(_mutex)[port] = xSemaphoreCreateMutex();
i2c_config_t conf = {0}; i2c_config_t conf = {0};
#ifdef HAS_CLK_FLAGS #ifdef HAS_CLK_FLAGS
conf.clk_flags = 0; conf.clk_flags = 0;
#endif #endif
#if defined (I2C_ZERO) #if defined (I2C_ZERO)
if (port == I2C_NUM_0) { if (port == I2C_NUM_0) {
conf.sda_io_num = CONFIG_I2C_MANAGER_0_SDA; conf.sda_io_num = CONFIG_I2C_MANAGER_0_SDA;
conf.scl_io_num = CONFIG_I2C_MANAGER_0_SCL; conf.scl_io_num = CONFIG_I2C_MANAGER_0_SCL;
conf.sda_pullup_en = I2C_MANAGER_0_PULLUPS ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE; conf.sda_pullup_en = I2C_MANAGER_0_PULLUPS ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
conf.scl_pullup_en = conf.sda_pullup_en; conf.scl_pullup_en = conf.sda_pullup_en;
conf.master.clk_speed = CONFIG_I2C_MANAGER_0_FREQ_HZ; conf.master.clk_speed = CONFIG_I2C_MANAGER_0_FREQ_HZ;
} }
#endif #endif
#if defined (I2C_ONE) #if defined (I2C_ONE)
if (port == I2C_NUM_1) { if (port == I2C_NUM_1) {
conf.sda_io_num = CONFIG_I2C_MANAGER_1_SDA; conf.sda_io_num = CONFIG_I2C_MANAGER_1_SDA;
conf.scl_io_num = CONFIG_I2C_MANAGER_1_SCL; conf.scl_io_num = CONFIG_I2C_MANAGER_1_SCL;
conf.sda_pullup_en = I2C_MANAGER_1_PULLUPS ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE; conf.sda_pullup_en = I2C_MANAGER_1_PULLUPS ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
conf.scl_pullup_en = conf.sda_pullup_en; conf.scl_pullup_en = conf.sda_pullup_en;
conf.master.clk_speed = CONFIG_I2C_MANAGER_1_FREQ_HZ; conf.master.clk_speed = CONFIG_I2C_MANAGER_1_FREQ_HZ;
} }
#endif #endif
conf.mode = I2C_MODE_MASTER; conf.mode = I2C_MODE_MASTER;
ret = i2c_param_config(port, &conf); ret = i2c_param_config(port, &conf);
ret |= i2c_driver_install(port, conf.mode, 0, 0, 0); ret |= i2c_driver_install(port, conf.mode, 0, 0, 0);
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to initialise I2C port %d.", (int)port); ESP_LOGE(TAG, "Failed to initialise I2C port %d.", (int)port);
ESP_LOGW(TAG, "If it was already open, we'll use it with whatever settings were used " ESP_LOGW(TAG, "If it was already open, we'll use it with whatever settings were used "
"to open it. See I2C Manager README for details."); "to open it. See I2C Manager README for details.");
} else { } else {
ESP_LOGI(TAG, "Initialised port %d (SDA: %d, SCL: %d, speed: %d Hz.)", ESP_LOGI(TAG, "Initialised port %d (SDA: %d, SCL: %d, speed: %lu Hz.)",
port, conf.sda_io_num, conf.scl_io_num, conf.master.clk_speed); port, conf.sda_io_num, conf.scl_io_num, conf.master.clk_speed);
} }
} }
return ret; return ret;
} }
esp_err_t I2C_FN(_read)(i2c_port_t port, uint16_t addr, uint32_t reg, uint8_t *buffer, uint16_t size) { esp_err_t I2C_FN(_read)(i2c_port_t port, uint16_t addr, uint32_t reg, uint8_t *buffer, uint16_t size) {
I2C_PORT_CHECK(port, ESP_FAIL); I2C_PORT_CHECK(port, ESP_FAIL);
esp_err_t result; esp_err_t result;
// May seem weird, but init starts with a check if it's needed, no need for that check twice. // May seem weird, but init starts with a check if it's needed, no need for that check twice.
I2C_FN(_init)(port); I2C_FN(_init)(port);
ESP_LOGV(TAG, "Reading port %d, addr 0x%03x, reg 0x%04x", port, addr, reg); ESP_LOGV(TAG, "Reading port %d, addr 0x%03x, reg 0x%04lx", port, addr, reg);
TickType_t timeout = 0; TickType_t timeout = 0;
#if defined (I2C_ZERO) #if defined (I2C_ZERO)
if (port == I2C_NUM_0) { if (port == I2C_NUM_0) {
timeout = I2C_MANAGER_0_TIMEOUT; timeout = I2C_MANAGER_0_TIMEOUT;
} }
#endif #endif
#if defined (I2C_ONE) #if defined (I2C_ONE)
if (port == I2C_NUM_1) { if (port == I2C_NUM_1) {
timeout = I2C_MANAGER_1_TIMEOUT; timeout = I2C_MANAGER_1_TIMEOUT;
} }
#endif #endif
if (I2C_FN(_lock)((int)port) == ESP_OK) { if (I2C_FN(_lock)((int)port) == ESP_OK) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create(); i2c_cmd_handle_t cmd = i2c_cmd_link_create();
if (!(reg & I2C_NO_REG)) { if (!(reg & I2C_NO_REG)) {
/* When reading specific register set the addr pointer first. */ /* When reading specific register set the addr pointer first. */
i2c_master_start(cmd); i2c_master_start(cmd);
i2c_send_address(cmd, addr, I2C_MASTER_WRITE); i2c_send_address(cmd, addr, I2C_MASTER_WRITE);
i2c_send_register(cmd, reg); i2c_send_register(cmd, reg);
} }
/* Read size bytes from the current pointer. */ /* Read size bytes from the current pointer. */
i2c_master_start(cmd); i2c_master_start(cmd);
i2c_send_address(cmd, addr, I2C_MASTER_READ); i2c_send_address(cmd, addr, I2C_MASTER_READ);
i2c_master_read(cmd, buffer, size, I2C_MASTER_LAST_NACK); i2c_master_read(cmd, buffer, size, I2C_MASTER_LAST_NACK);
i2c_master_stop(cmd); i2c_master_stop(cmd);
result = i2c_master_cmd_begin(port, cmd, timeout); result = i2c_master_cmd_begin(port, cmd, timeout);
i2c_cmd_link_delete(cmd); i2c_cmd_link_delete(cmd);
I2C_FN(_unlock)((int)port); I2C_FN(_unlock)((int)port);
} else { } else {
ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port); ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port);
return ESP_ERR_TIMEOUT; return ESP_ERR_TIMEOUT;
}
if (result != ESP_OK) {
ESP_LOGW(TAG, "Error: %d", result);
} }
ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, size, ESP_LOG_VERBOSE); if (result != ESP_OK) {
ESP_LOGD(TAG, "Error: %d", result);
}
ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, size, ESP_LOG_VERBOSE);
return result; return result;
} }
esp_err_t I2C_FN(_write)(i2c_port_t port, uint16_t addr, uint32_t reg, const uint8_t *buffer, uint16_t size) { esp_err_t I2C_FN(_write)(i2c_port_t port, uint16_t addr, uint32_t reg, const uint8_t *buffer, uint16_t size) {
I2C_PORT_CHECK(port, ESP_FAIL); I2C_PORT_CHECK(port, ESP_FAIL);
esp_err_t result; esp_err_t result;
// May seem weird, but init starts with a check if it's needed, no need for that check twice. // May seem weird, but init starts with a check if it's needed, no need for that check twice.
I2C_FN(_init)(port); I2C_FN(_init)(port);
ESP_LOGV(TAG, "Writing port %d, addr 0x%03x, reg 0x%04x", port, addr, reg); ESP_LOGV(TAG, "Writing port %d, addr 0x%03x, reg 0x%04lx", port, addr, reg);
TickType_t timeout = 0; TickType_t timeout = 0;
#if defined (I2C_ZERO) #if defined (I2C_ZERO)
if (port == I2C_NUM_0) { if (port == I2C_NUM_0) {
timeout = (CONFIG_I2C_MANAGER_0_TIMEOUT) / portTICK_RATE_MS; timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_TIMEOUT );
} }
#endif #endif
#if defined (I2C_ONE) #if defined (I2C_ONE)
if (port == I2C_NUM_1) { if (port == I2C_NUM_1) {
timeout = (CONFIG_I2C_MANAGER_1_TIMEOUT) / portTICK_RATE_MS; timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_TIMEOUT );
} }
#endif #endif
if (I2C_FN(_lock)((int)port) == ESP_OK) { if (I2C_FN(_lock)((int)port) == ESP_OK) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create(); i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd); i2c_master_start(cmd);
i2c_send_address(cmd, addr, I2C_MASTER_WRITE); i2c_send_address(cmd, addr, I2C_MASTER_WRITE);
if (!(reg & I2C_NO_REG)) { if (!(reg & I2C_NO_REG)) {
i2c_send_register(cmd, reg); i2c_send_register(cmd, reg);
} }
i2c_master_write(cmd, (uint8_t *)buffer, size, ACK_CHECK_EN); i2c_master_write(cmd, (uint8_t *)buffer, size, ACK_CHECK_EN);
i2c_master_stop(cmd); i2c_master_stop(cmd);
result = i2c_master_cmd_begin( port, cmd, timeout); result = i2c_master_cmd_begin( port, cmd, timeout);
i2c_cmd_link_delete(cmd); i2c_cmd_link_delete(cmd);
I2C_FN(_unlock)((int)port); I2C_FN(_unlock)((int)port);
} else { } else {
ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port); ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port);
return ESP_ERR_TIMEOUT; return ESP_ERR_TIMEOUT;
}
if (result != ESP_OK) {
ESP_LOGW(TAG, "Error: %d", result);
} }
ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, size, ESP_LOG_VERBOSE); if (result != ESP_OK) {
ESP_LOGD(TAG, "Error: %d", result);
}
ESP_LOG_BUFFER_HEX_LEVEL(TAG, buffer, size, ESP_LOG_VERBOSE);
return result; return result;
} }
esp_err_t I2C_FN(_close)(i2c_port_t port) { esp_err_t I2C_FN(_close)(i2c_port_t port) {
I2C_PORT_CHECK(port, ESP_FAIL); I2C_PORT_CHECK(port, ESP_FAIL);
vSemaphoreDelete(I2C_FN(_mutex)[port]); vSemaphoreDelete(I2C_FN(_mutex)[port]);
I2C_FN(_mutex)[port] = NULL; I2C_FN(_mutex)[port] = NULL;
ESP_LOGI(TAG, "Closing I2C master at port %d", port); ESP_LOGI(TAG, "Closing I2C master at port %d", port);
@ -288,59 +288,59 @@ esp_err_t I2C_FN(_close)(i2c_port_t port) {
} }
esp_err_t I2C_FN(_lock)(i2c_port_t port) { esp_err_t I2C_FN(_lock)(i2c_port_t port) {
I2C_PORT_CHECK(port, ESP_FAIL); I2C_PORT_CHECK(port, ESP_FAIL);
ESP_LOGV(TAG, "Mutex lock set for %d.", (int)port); ESP_LOGV(TAG, "Mutex lock set for %d.", (int)port);
TickType_t timeout; TickType_t timeout;
#if defined (I2C_ZERO) #if defined (I2C_ZERO)
if (port == I2C_NUM_0) { if (port == I2C_NUM_0) {
timeout = (CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT) / portTICK_RATE_MS; timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT );
} }
#endif #endif
#if defined (I2C_ONE) #if defined (I2C_ONE)
if (port == I2C_NUM_1) { if (port == I2C_NUM_1) {
timeout = (CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT) / portTICK_RATE_MS; timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT );
} }
#endif #endif
if (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE) { if (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE) {
return ESP_OK; return ESP_OK;
} else { } else {
ESP_LOGE(TAG, "Removing stale mutex lock from port %d.", (int)port); ESP_LOGE(TAG, "Removing stale mutex lock from port %d.", (int)port);
I2C_FN(_force_unlock)(port); I2C_FN(_force_unlock)(port);
return (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE ? ESP_OK : ESP_FAIL); return (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE ? ESP_OK : ESP_FAIL);
} }
} }
esp_err_t I2C_FN(_unlock)(i2c_port_t port) { esp_err_t I2C_FN(_unlock)(i2c_port_t port) {
I2C_PORT_CHECK(port, ESP_FAIL); I2C_PORT_CHECK(port, ESP_FAIL);
ESP_LOGV(TAG, "Mutex lock removed for %d.", (int)port); ESP_LOGV(TAG, "Mutex lock removed for %d.", (int)port);
return (xSemaphoreGive(I2C_FN(_mutex)[port]) == pdTRUE) ? ESP_OK : ESP_FAIL; return (xSemaphoreGive(I2C_FN(_mutex)[port]) == pdTRUE) ? ESP_OK : ESP_FAIL;
} }
esp_err_t I2C_FN(_force_unlock)(i2c_port_t port) { esp_err_t I2C_FN(_force_unlock)(i2c_port_t port) {
I2C_PORT_CHECK(port, ESP_FAIL); I2C_PORT_CHECK(port, ESP_FAIL);
if (I2C_FN(_mutex)[port]) { if (I2C_FN(_mutex)[port]) {
vSemaphoreDelete(I2C_FN(_mutex)[port]); vSemaphoreDelete(I2C_FN(_mutex)[port]);
} }
I2C_FN(_mutex)[port] = xSemaphoreCreateMutex(); I2C_FN(_mutex)[port] = xSemaphoreCreateMutex();
return ESP_OK; return ESP_OK;
} }
#ifdef I2C_OEM #ifdef I2C_OEM
void I2C_FN(_locking)(void* leader) { void I2C_FN(_locking)(void* leader) {
if (leader) { if (leader) {
ESP_LOGI(TAG, "Now following I2C Manager for locking"); ESP_LOGI(TAG, "Now following I2C Manager for locking");
I2C_FN(_mutex) = (SemaphoreHandle_t*)leader; I2C_FN(_mutex) = (SemaphoreHandle_t*)leader;
}
} }
}
#else #else
void* i2c_manager_locking() { void* i2c_manager_locking() {
return (void*)i2c_manager_mutex; return (void*)i2c_manager_mutex;
} }

View file

@ -29,9 +29,9 @@ extern "C" {
#define STR_QUOTE(s) STR_EXPAND(STR_EXPAND(s)) #define STR_QUOTE(s) STR_EXPAND(STR_EXPAND(s))
#ifdef I2C_OEM #ifdef I2C_OEM
#define I2C_NAME_PREFIX CONCAT(I2C_OEM, _i2c) #define I2C_NAME_PREFIX CONCAT(I2C_OEM, _i2c)
#else #else
#define I2C_NAME_PREFIX i2c_manager #define I2C_NAME_PREFIX i2c_manager
#endif #endif
#define I2C_TAG STR_EXPAND(I2C_NAME_PREFIX) #define I2C_TAG STR_EXPAND(I2C_NAME_PREFIX)
@ -53,19 +53,19 @@ esp_err_t I2C_FN(_force_unlock)(i2c_port_t port);
#ifdef I2C_OEM #ifdef I2C_OEM
void I2C_FN(_locking)(void* leader); void I2C_FN(_locking)(void* leader);
#else #else
void* i2c_manager_locking(); void* i2c_manager_locking();
typedef struct { typedef struct {
int32_t (* read)(void *handle, uint8_t address, uint8_t reg, uint8_t *buffer, uint16_t size); int32_t (* read)(void *handle, uint8_t address, uint8_t reg, uint8_t *buffer, uint16_t size);
int32_t (* write)(void *handle, uint8_t address, uint8_t reg, const uint8_t *buffer, uint16_t size); int32_t (* write)(void *handle, uint8_t address, uint8_t reg, const uint8_t *buffer, uint16_t size);
void *handle; void *handle;
} i2c_hal_t; } i2c_hal_t;
void* i2c_hal(i2c_port_t port); void* i2c_hal(i2c_port_t port);
#endif #endif

View file

@ -7,7 +7,10 @@
#include "EVE.h" #include "EVE.h"
#include "EVE_commands.h" #include "EVE_commands.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/* some pre-definded colors */ /* some pre-definded colors */
#define RED 0xff0000UL #define RED 0xff0000UL
#define ORANGE 0xffa500UL #define ORANGE 0xffa500UL
@ -263,7 +266,12 @@ void TFT_bitmap_display(void)
void FT81x_init(void) void FT81x_init(void)
{ {
#if EVE_USE_PDN #if EVE_USE_PDN
gpio_pad_select_gpio(EVE_PDN); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(EVE_PDN);
#else
esp_rom_gpio_pad_select_gpio(EVE_PDN);
#endif
#endif #endif
gpio_set_level(EVE_CS, 1); gpio_set_level(EVE_CS, 1);

View file

@ -12,7 +12,10 @@
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
@ -112,18 +115,26 @@ void GC9A01_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(GC9A01_DC); gpio_pad_select_gpio(GC9A01_DC);
#else
esp_rom_gpio_pad_select_gpio(GC9A01_DC);
#endif
gpio_set_direction(GC9A01_DC, GPIO_MODE_OUTPUT); gpio_set_direction(GC9A01_DC, GPIO_MODE_OUTPUT);
#if GC9A01_USE_RST #if GC9A01_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(GC9A01_RST); gpio_pad_select_gpio(GC9A01_RST);
#else
esp_rom_gpio_pad_select_gpio(GC9A01_RST);
#endif
gpio_set_direction(GC9A01_RST, GPIO_MODE_OUTPUT); gpio_set_direction(GC9A01_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(GC9A01_RST, 0); gpio_set_level(GC9A01_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(GC9A01_RST, 1); gpio_set_level(GC9A01_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
#endif #endif
ESP_LOGI(TAG, "Initialization."); ESP_LOGI(TAG, "Initialization.");
@ -134,7 +145,7 @@ void GC9A01_init(void)
GC9A01_send_cmd(GC_init_cmds[cmd].cmd); GC9A01_send_cmd(GC_init_cmds[cmd].cmd);
GC9A01_send_data(GC_init_cmds[cmd].data, GC_init_cmds[cmd].databytes&0x1F); GC9A01_send_data(GC_init_cmds[cmd].data, GC_init_cmds[cmd].databytes&0x1F);
if (GC_init_cmds[cmd].databytes & 0x80) { if (GC_init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }

View file

@ -196,6 +196,14 @@ menu "LVGL TFT Display controller"
help help
Display controller protocol I2C Display controller protocol I2C
config LV_HOR_RES_MAX
int "Maximal horizontal resolution to support by the library."
default 128
config LV_VER_RES_MAX
int "Maximal vertical resolution to support by the library."
default 64
# Used in display init function to send display orientation commands # Used in display init function to send display orientation commands
choice DISPLAY_ORIENTATION choice DISPLAY_ORIENTATION
prompt "Display orientation" prompt "Display orientation"

View file

@ -6,12 +6,16 @@
/********************* /*********************
* INCLUDES * INCLUDES
*********************/ *********************/
#include <soc/gpio_sig_map.h>
#include "esp_lcd_backlight.h" #include "esp_lcd_backlight.h"
#include "driver/ledc.h" #include "driver/ledc.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "esp_log.h" #include "esp_log.h"
#include "soc/ledc_periph.h" // to invert LEDC output on IDF version < v4.3 #include "soc/ledc_periph.h" // to invert LEDC output on IDF version < v4.3
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
typedef struct { typedef struct {
bool pwm_control; // true: LEDC is used, false: GPIO is used bool pwm_control; // true: LEDC is used, false: GPIO is used
int index; // Either GPIO or LEDC channel int index; // Either GPIO or LEDC channel
@ -49,22 +53,26 @@ disp_backlight_h disp_backlight_new(const disp_backlight_config_t *config)
}; };
const ledc_timer_config_t LCD_backlight_timer = { const ledc_timer_config_t LCD_backlight_timer = {
.speed_mode = LEDC_LOW_SPEED_MODE, .speed_mode = LEDC_LOW_SPEED_MODE,
.bit_num = LEDC_TIMER_10_BIT, .duty_resolution = LEDC_TIMER_10_BIT,
.timer_num = config->timer_idx, .timer_num = config->timer_idx,
.freq_hz = 5000, .freq_hz = 5000,
.clk_cfg = LEDC_AUTO_CLK}; .clk_cfg = LEDC_AUTO_CLK};
ESP_ERROR_CHECK(ledc_timer_config(&LCD_backlight_timer)); ESP_ERROR_CHECK(ledc_timer_config(&LCD_backlight_timer));
ESP_ERROR_CHECK(ledc_channel_config(&LCD_backlight_channel)); ESP_ERROR_CHECK(ledc_channel_config(&LCD_backlight_channel));
gpio_matrix_out(config->gpio_num, ledc_periph_signal[LEDC_LOW_SPEED_MODE].sig_out0_idx + config->channel_idx, config->output_invert, 0); gpio_iomux_out(config->gpio_num, ledc_periph_signal[LEDC_LOW_SPEED_MODE].sig_out0_idx + config->channel_idx, config->output_invert);
} }
else else
{ {
// Configure GPIO for output // Configure GPIO for output
bckl_dev->index = config->gpio_num; bckl_dev->index = config->gpio_num;
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(config->gpio_num); gpio_pad_select_gpio(config->gpio_num);
#else
esp_rom_gpio_pad_select_gpio(config->gpio_num);
#endif
ESP_ERROR_CHECK(gpio_set_direction(config->gpio_num, GPIO_MODE_OUTPUT)); ESP_ERROR_CHECK(gpio_set_direction(config->gpio_num, GPIO_MODE_OUTPUT));
gpio_matrix_out(config->gpio_num, SIG_GPIO_OUT_IDX, config->output_invert, false); gpio_iomux_out(config->gpio_num, SIG_GPIO_OUT_IDX, config->output_invert);
} }
return (disp_backlight_h)bckl_dev; return (disp_backlight_h)bckl_dev;
@ -101,7 +109,11 @@ void disp_backlight_delete(disp_backlight_h bckl)
if (bckl_dev->pwm_control) { if (bckl_dev->pwm_control) {
ledc_stop(LEDC_LOW_SPEED_MODE, bckl_dev->index, 0); ledc_stop(LEDC_LOW_SPEED_MODE, bckl_dev->index, 0);
} else { } else {
gpio_reset_pin(bckl_dev->index); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(bckl_dev->index);
#else
esp_rom_gpio_pad_select_gpio(bckl_dev->index);
#endif
} }
free (bckl); free (bckl);
} }

View file

@ -21,7 +21,10 @@
#include <esp_log.h> #include <esp_log.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
@ -160,18 +163,26 @@ static uint8_t displayType = HX8357D;
void hx8357_init(void) void hx8357_init(void)
{ {
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(HX8357_DC); gpio_pad_select_gpio(HX8357_DC);
#else
esp_rom_gpio_pad_select_gpio(HX8357_DC);
#endif
gpio_set_direction(HX8357_DC, GPIO_MODE_OUTPUT); gpio_set_direction(HX8357_DC, GPIO_MODE_OUTPUT);
#if HX8357_USE_RST #if HX8357_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(HX8357_RST); gpio_pad_select_gpio(HX8357_RST);
#else
esp_rom_gpio_pad_select_gpio(HX8357_RST);
#endif
gpio_set_direction(HX8357_RST, GPIO_MODE_OUTPUT); gpio_set_direction(HX8357_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(HX8357_RST, 0); gpio_set_level(HX8357_RST, 0);
vTaskDelay(10 / portTICK_RATE_MS); vTaskDelay(10 / portTICK_PERIOD_MS);
gpio_set_level(HX8357_RST, 1); gpio_set_level(HX8357_RST, 1);
vTaskDelay(120 / portTICK_RATE_MS); vTaskDelay(120 / portTICK_PERIOD_MS);
#endif #endif
ESP_LOGI(TAG, "Initialization."); ESP_LOGI(TAG, "Initialization.");
@ -192,7 +203,7 @@ void hx8357_init(void)
} }
} }
if (x & 0x80) { // If high bit set... if (x & 0x80) { // If high bit set...
vTaskDelay(numArgs * 5 / portTICK_RATE_MS); // numArgs is actually a delay time (5ms units) vTaskDelay(numArgs * 5 / portTICK_PERIOD_MS); // numArgs is actually a delay time (5ms units)
} }
} }

View file

@ -33,6 +33,10 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
#include "il3820.h" #include "il3820.h"
@ -196,21 +200,33 @@ void il3820_init(void)
uint8_t tmp[3] = {0}; uint8_t tmp[3] = {0};
/* Initialize non-SPI GPIOs */ /* Initialize non-SPI GPIOs */
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(IL3820_DC_PIN); gpio_pad_select_gpio(IL3820_DC_PIN);
#else
esp_rom_gpio_pad_select_gpio(IL3820_DC_PIN);
#endif
gpio_set_direction(IL3820_DC_PIN, GPIO_MODE_OUTPUT); gpio_set_direction(IL3820_DC_PIN, GPIO_MODE_OUTPUT);
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(IL3820_BUSY_PIN); gpio_pad_select_gpio(IL3820_BUSY_PIN);
#else
esp_rom_gpio_pad_select_gpio(IL3820_BUSY_PIN);
#endif
gpio_set_direction(IL3820_BUSY_PIN, GPIO_MODE_INPUT); gpio_set_direction(IL3820_BUSY_PIN, GPIO_MODE_INPUT);
#if IL3820_USE_RST #if IL3820_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(IL3820_RST_PIN); gpio_pad_select_gpio(IL3820_RST_PIN);
#else
esp_rom_gpio_pad_select_gpio(IL3820_RST_PIN);
#endif
gpio_set_direction(IL3820_RST_PIN, GPIO_MODE_OUTPUT); gpio_set_direction(IL3820_RST_PIN, GPIO_MODE_OUTPUT);
/* Harware reset */ /* Harware reset */
gpio_set_level( IL3820_RST_PIN, 0); gpio_set_level( IL3820_RST_PIN, 0);
vTaskDelay(IL3820_RESET_DELAY / portTICK_RATE_MS); vTaskDelay(IL3820_RESET_DELAY / portTICK_PERIOD_MS);
gpio_set_level( IL3820_RST_PIN, 1); gpio_set_level( IL3820_RST_PIN, 1);
vTaskDelay(IL3820_RESET_DELAY / portTICK_RATE_MS); vTaskDelay(IL3820_RESET_DELAY / portTICK_PERIOD_MS);
#endif #endif
/* Software reset */ /* Software reset */
@ -267,14 +283,14 @@ static void il3820_waitbusy(int wait_ms)
{ {
int i = 0; int i = 0;
vTaskDelay(10 / portTICK_RATE_MS); // 10ms delay vTaskDelay(10 / portTICK_PERIOD_MS); // 10ms delay
for(i = 0; i < (wait_ms * 10); i++) { for(i = 0; i < (wait_ms * 10); i++) {
if(gpio_get_level(IL3820_BUSY_PIN) != IL3820_BUSY_LEVEL) { if(gpio_get_level(IL3820_BUSY_PIN) != IL3820_BUSY_LEVEL) {
return; return;
} }
vTaskDelay(10 / portTICK_RATE_MS); vTaskDelay(10 / portTICK_PERIOD_MS);
} }
ESP_LOGE( TAG, "busy exceeded %dms", i*10 ); ESP_LOGE( TAG, "busy exceeded %dms", i*10 );

View file

@ -13,6 +13,10 @@
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "assert.h" #include "assert.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
@ -138,16 +142,24 @@ void ili9163c_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
gpio_pad_select_gpio(ILI9163C_DC); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9163C_DC);
#else
esp_rom_gpio_pad_select_gpio(ILI9163C_DC);
#endif
gpio_set_direction(ILI9163C_DC, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9163C_DC, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(ILI9163C_RST); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9163C_RST);
#else
esp_rom_gpio_pad_select_gpio(ILI9163C_RST);
#endif
gpio_set_direction(ILI9163C_RST, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9163C_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(ILI9163C_RST, 0); gpio_set_level(ILI9163C_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ILI9163C_RST, 1); gpio_set_level(ILI9163C_RST, 1);
vTaskDelay(150 / portTICK_RATE_MS); vTaskDelay(150 / portTICK_PERIOD_MS);
//Send all the commands //Send all the commands
uint16_t cmd = 0; uint16_t cmd = 0;
@ -157,7 +169,7 @@ void ili9163c_init(void)
ili9163c_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes & 0x1F); ili9163c_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes & 0x1F);
if (ili_init_cmds[cmd].databytes & 0x80) if (ili_init_cmds[cmd].databytes & 0x80)
{ {
vTaskDelay(150 / portTICK_RATE_MS); vTaskDelay(150 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }

View file

@ -12,6 +12,10 @@
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
@ -81,18 +85,26 @@ void ili9341_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9341_DC); gpio_pad_select_gpio(ILI9341_DC);
#else
esp_rom_gpio_pad_select_gpio(ILI9341_DC);
#endif
gpio_set_direction(ILI9341_DC, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9341_DC, GPIO_MODE_OUTPUT);
#if ILI9341_USE_RST #if ILI9341_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9341_RST); gpio_pad_select_gpio(ILI9341_RST);
#else
esp_rom_gpio_pad_select_gpio(ILI9341_RST);
#endif
gpio_set_direction(ILI9341_RST, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9341_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(ILI9341_RST, 0); gpio_set_level(ILI9341_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ILI9341_RST, 1); gpio_set_level(ILI9341_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
#endif #endif
ESP_LOGI(TAG, "Initialization."); ESP_LOGI(TAG, "Initialization.");
@ -103,7 +115,7 @@ void ili9341_init(void)
ili9341_send_cmd(ili_init_cmds[cmd].cmd); ili9341_send_cmd(ili_init_cmds[cmd].cmd);
ili9341_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F); ili9341_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F);
if (ili_init_cmds[cmd].databytes & 0x80) { if (ili_init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }

View file

@ -13,7 +13,10 @@
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
*********************/ *********************/
@ -74,25 +77,33 @@ void ili9481_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9481_DC); gpio_pad_select_gpio(ILI9481_DC);
#else
esp_rom_gpio_pad_select_gpio(ILI9481_DC);
#endif
gpio_set_direction(ILI9481_DC, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9481_DC, GPIO_MODE_OUTPUT);
#if ILI9481_USE_RST #if ILI9481_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9481_RST); gpio_pad_select_gpio(ILI9481_RST);
#else
esp_rom_gpio_pad_select_gpio(ILI9481_RST);
#endif
gpio_set_direction(ILI9481_RST, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9481_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(ILI9481_RST, 0); gpio_set_level(ILI9481_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ILI9481_RST, 1); gpio_set_level(ILI9481_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
#endif #endif
ESP_LOGI(TAG, "ILI9481 initialization."); ESP_LOGI(TAG, "ILI9481 initialization.");
// Exit sleep // Exit sleep
ili9481_send_cmd(0x01); /* Software reset */ ili9481_send_cmd(0x01); /* Software reset */
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
//Send all the commands //Send all the commands
uint16_t cmd = 0; uint16_t cmd = 0;
@ -100,7 +111,7 @@ void ili9481_init(void)
ili9481_send_cmd(ili_init_cmds[cmd].cmd); ili9481_send_cmd(ili_init_cmds[cmd].cmd);
ili9481_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F); ili9481_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F);
if (ili_init_cmds[cmd].databytes & 0x80) { if (ili_init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }

View file

@ -12,6 +12,10 @@
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
@ -66,18 +70,26 @@ void ili9486_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9486_DC); gpio_pad_select_gpio(ILI9486_DC);
#else
esp_rom_gpio_pad_select_gpio(ILI9486_DC);
#endif
gpio_set_direction(ILI9486_DC, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9486_DC, GPIO_MODE_OUTPUT);
#if ILI9486_USE_RST #if ILI9486_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9486_RST); gpio_pad_select_gpio(ILI9486_RST);
#else
esp_rom_gpio_pad_select_gpio(ILI9486_RST);
#endif
gpio_set_direction(ILI9486_RST, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9486_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(ILI9486_RST, 0); gpio_set_level(ILI9486_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ILI9486_RST, 1); gpio_set_level(ILI9486_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
#endif #endif
ESP_LOGI(TAG, "ILI9486 Initialization."); ESP_LOGI(TAG, "ILI9486 Initialization.");
@ -88,7 +100,7 @@ void ili9486_init(void)
ili9486_send_cmd(ili_init_cmds[cmd].cmd); ili9486_send_cmd(ili_init_cmds[cmd].cmd);
ili9486_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F); ili9486_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F);
if (ili_init_cmds[cmd].databytes & 0x80) { if (ili_init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }

View file

@ -13,6 +13,10 @@
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
@ -76,25 +80,33 @@ void ili9488_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9488_DC); gpio_pad_select_gpio(ILI9488_DC);
#else
esp_rom_gpio_pad_select_gpio(ILI9488_DC);
#endif
gpio_set_direction(ILI9488_DC, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9488_DC, GPIO_MODE_OUTPUT);
#if ILI9488_USE_RST #if ILI9488_USE_RST
gpio_pad_select_gpio(ILI9488_RST); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ILI9488_RST);
#else
esp_rom_gpio_pad_select_gpio(ILI9488_RST);
#endif
gpio_set_direction(ILI9488_RST, GPIO_MODE_OUTPUT); gpio_set_direction(ILI9488_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(ILI9488_RST, 0); gpio_set_level(ILI9488_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ILI9488_RST, 1); gpio_set_level(ILI9488_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
#endif #endif
ESP_LOGI(TAG, "ILI9488 initialization."); ESP_LOGI(TAG, "ILI9488 initialization.");
// Exit sleep // Exit sleep
ili9488_send_cmd(0x01); /* Software reset */ ili9488_send_cmd(0x01); /* Software reset */
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
//Send all the commands //Send all the commands
uint16_t cmd = 0; uint16_t cmd = 0;
@ -102,7 +114,7 @@ void ili9488_init(void)
ili9488_send_cmd(ili_init_cmds[cmd].cmd); ili9488_send_cmd(ili_init_cmds[cmd].cmd);
ili9488_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F); ili9488_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F);
if (ili_init_cmds[cmd].databytes & 0x80) { if (ili_init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }

View file

@ -14,7 +14,10 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "pcd8544.h" #include "pcd8544.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
#define TAG "lv_pcd8544" #define TAG "lv_pcd8544"
/********************** /**********************
@ -57,16 +60,24 @@ void pcd8544_init(void){
// TODO: orientation // TODO: orientation
// Initialize non-SPI GPIOs // Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(PCD8544_DC); gpio_pad_select_gpio(PCD8544_DC);
#else
esp_rom_gpio_pad_select_gpio(PCD8544_DC);
#endif
gpio_set_direction(PCD8544_DC, GPIO_MODE_OUTPUT); gpio_set_direction(PCD8544_DC, GPIO_MODE_OUTPUT);
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(PCD8544_RST); gpio_pad_select_gpio(PCD8544_RST);
#else
esp_rom_gpio_pad_select_gpio(PCD8544_RST);
#endif
gpio_set_direction(PCD8544_RST, GPIO_MODE_OUTPUT); gpio_set_direction(PCD8544_RST, GPIO_MODE_OUTPUT);
// Reset the display // Reset the display
gpio_set_level(PCD8544_RST, 0); gpio_set_level(PCD8544_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(PCD8544_RST, 1); gpio_set_level(PCD8544_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
pcd8544_send_cmd(0x21); /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */ pcd8544_send_cmd(0x21); /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
pcd8544_send_cmd(0x06); /* temp. control: b10 = 2 */ pcd8544_send_cmd(0x06); /* temp. control: b10 = 2 */

View file

@ -12,6 +12,10 @@
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
@ -151,14 +155,18 @@ void ra8875_init(void)
// Initialize non-SPI GPIOs // Initialize non-SPI GPIOs
#if RA8875_USE_RST #if RA8875_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(RA8875_RST); gpio_pad_select_gpio(RA8875_RST);
#else
esp_rom_gpio_pad_select_gpio(RA8875_RST);
#endif
gpio_set_direction(RA8875_RST, GPIO_MODE_OUTPUT); gpio_set_direction(RA8875_RST, GPIO_MODE_OUTPUT);
// Reset the RA8875 // Reset the RA8875
gpio_set_level(RA8875_RST, 0); gpio_set_level(RA8875_RST, 0);
vTaskDelay(DIV_ROUND_UP(100, portTICK_RATE_MS)); vTaskDelay(DIV_ROUND_UP(100, portTICK_PERIOD_MS));
gpio_set_level(RA8875_RST, 1); gpio_set_level(RA8875_RST, 1);
vTaskDelay(DIV_ROUND_UP(100, portTICK_RATE_MS)); vTaskDelay(DIV_ROUND_UP(100, portTICK_PERIOD_MS));
#endif #endif
// Initalize RA8875 clocks (SPI must be decelerated before initializing clocks) // Initalize RA8875 clocks (SPI must be decelerated before initializing clocks)
@ -251,21 +259,21 @@ void ra8875_sleep_in(void)
ra8875_configure_clocks(false); ra8875_configure_clocks(false);
ra8875_write_cmd(RA8875_REG_PWRR, 0x00); // Power and Display Control Register (PWRR) ra8875_write_cmd(RA8875_REG_PWRR, 0x00); // Power and Display Control Register (PWRR)
vTaskDelay(DIV_ROUND_UP(20, portTICK_RATE_MS)); vTaskDelay(DIV_ROUND_UP(20, portTICK_PERIOD_MS));
ra8875_write_cmd(RA8875_REG_PWRR, 0x02); // Power and Display Control Register (PWRR) ra8875_write_cmd(RA8875_REG_PWRR, 0x02); // Power and Display Control Register (PWRR)
} }
void ra8875_sleep_out(void) void ra8875_sleep_out(void)
{ {
ra8875_write_cmd(RA8875_REG_PWRR, 0x00); // Power and Display Control Register (PWRR) ra8875_write_cmd(RA8875_REG_PWRR, 0x00); // Power and Display Control Register (PWRR)
vTaskDelay(DIV_ROUND_UP(20, portTICK_RATE_MS)); vTaskDelay(DIV_ROUND_UP(20, portTICK_PERIOD_MS));
ra8875_configure_clocks(true); ra8875_configure_clocks(true);
disp_spi_change_device_speed(-1); disp_spi_change_device_speed(-1);
ra8875_write_cmd(RA8875_REG_PWRR, 0x80); // Power and Display Control Register (PWRR) ra8875_write_cmd(RA8875_REG_PWRR, 0x80); // Power and Display Control Register (PWRR)
vTaskDelay(DIV_ROUND_UP(20, portTICK_RATE_MS)); vTaskDelay(DIV_ROUND_UP(20, portTICK_PERIOD_MS));
} }
uint8_t ra8875_read_cmd(uint8_t cmd) uint8_t ra8875_read_cmd(uint8_t cmd)
@ -298,7 +306,7 @@ void ra8875_configure_clocks(bool high_speed)
vTaskDelay(1); vTaskDelay(1);
ra8875_write_cmd(RA8875_REG_PCSR, PCSR_VAL); // Pixel Clock Setting Register (PCSR) ra8875_write_cmd(RA8875_REG_PCSR, PCSR_VAL); // Pixel Clock Setting Register (PCSR)
vTaskDelay(DIV_ROUND_UP(20, portTICK_RATE_MS)); vTaskDelay(DIV_ROUND_UP(20, portTICK_PERIOD_MS));
} }
static void ra8875_set_window(unsigned int xs, unsigned int xe, unsigned int ys, unsigned int ye) static void ra8875_set_window(unsigned int xs, unsigned int xe, unsigned int ys, unsigned int ye)

View file

@ -12,6 +12,10 @@
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
@ -92,18 +96,26 @@ void sh1107_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
gpio_pad_select_gpio(SH1107_DC); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(SH1107_DC);
#else
esp_rom_gpio_pad_select_gpio(SH1107_DC);
#endif
gpio_set_direction(SH1107_DC, GPIO_MODE_OUTPUT); gpio_set_direction(SH1107_DC, GPIO_MODE_OUTPUT);
#if SH1107_USE_RST #if SH1107_USE_RST
gpio_pad_select_gpio(SH1107_RST); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(SH1107_RST);
#else
esp_rom_gpio_pad_select_gpio(SH1107_RST);
#endif
gpio_set_direction(SH1107_RST, GPIO_MODE_OUTPUT); gpio_set_direction(SH1107_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(SH1107_RST, 0); gpio_set_level(SH1107_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(SH1107_RST, 1); gpio_set_level(SH1107_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
#endif #endif
//Send all the commands //Send all the commands
@ -112,7 +124,7 @@ void sh1107_init(void)
sh1107_send_cmd(init_cmds[cmd].cmd); sh1107_send_cmd(init_cmds[cmd].cmd);
sh1107_send_data(init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F); sh1107_send_data(init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
if (init_cmds[cmd].databytes & 0x80) { if (init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }

View file

@ -12,6 +12,10 @@
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
#ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192 #ifdef CONFIG_LV_M5STICKC_HANDLE_AXP192
#include "lvgl_i2c/i2c_manager.h" #include "lvgl_i2c/i2c_manager.h"
@ -98,18 +102,26 @@ void st7735s_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
gpio_pad_select_gpio(ST7735S_DC); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ST7735S_DC);
#else
esp_rom_gpio_pad_select_gpio(ST7735S_DC);
#endif
gpio_set_direction(ST7735S_DC, GPIO_MODE_OUTPUT); gpio_set_direction(ST7735S_DC, GPIO_MODE_OUTPUT);
#if ST7735S_USE_RST #if ST7735S_USE_RST
gpio_pad_select_gpio(ST7735S_RST); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ST7735S_RST);
#else
esp_rom_gpio_pad_select_gpio(ST7735S_RST);
#endif
gpio_set_direction(ST7735S_RST, GPIO_MODE_OUTPUT); gpio_set_direction(ST7735S_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(ST7735S_RST, 0); gpio_set_level(ST7735S_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ST7735S_RST, 1); gpio_set_level(ST7735S_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
#endif #endif
ESP_LOGI(TAG, "ST7735S initialization."); ESP_LOGI(TAG, "ST7735S initialization.");
@ -120,7 +132,7 @@ void st7735s_init(void)
st7735s_send_cmd(init_cmds[cmd].cmd); st7735s_send_cmd(init_cmds[cmd].cmd);
st7735s_send_data(init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F); st7735s_send_data(init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
if (init_cmds[cmd].databytes & 0x80) { if (init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }

View file

@ -37,8 +37,19 @@ extern "C" {
// https://github.com/adafruit/Adafruit-ST7735-Library // https://github.com/adafruit/Adafruit-ST7735-Library
// //
#define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 / 1 offset) #define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 / 1 offset)
// TODO: this should be config option
#if CONFIG_LV_HOR_RES_MAX==128 && CONFIG_LV_VER_RES_MAX==128
#define COLSTART 2
#define ROWSTART 3
#elif CONFIG_LV_HOR_RES_MAX==128 && CONFIG_LV_VER_RES_MAX==80
#define COLSTART 26 #define COLSTART 26
#define ROWSTART 1 #define ROWSTART 1
#else
#define COLSTART 0
#define ROWSTART 0
#endif
// Delay between some initialisation commands // Delay between some initialisation commands
#define TFT_INIT_DELAY 0x80 #define TFT_INIT_DELAY 0x80

View file

@ -14,6 +14,10 @@
#include "disp_spi.h" #include "disp_spi.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
@ -86,20 +90,28 @@ void st7789_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ST7789_DC); gpio_pad_select_gpio(ST7789_DC);
#else
esp_rom_gpio_pad_select_gpio(ST7789_DC);
#endif
gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT); gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT);
#if !defined(ST7789_SOFT_RST) #if !defined(ST7789_SOFT_RST)
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ST7789_RST); gpio_pad_select_gpio(ST7789_RST);
#else
esp_rom_gpio_pad_select_gpio(ST7789_RST);
#endif
gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT); gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT);
#endif #endif
//Reset the display //Reset the display
#if !defined(ST7789_SOFT_RST) #if !defined(ST7789_SOFT_RST)
gpio_set_level(ST7789_RST, 0); gpio_set_level(ST7789_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ST7789_RST, 1); gpio_set_level(ST7789_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
#else #else
st7789_send_cmd(ST7789_SWRESET); st7789_send_cmd(ST7789_SWRESET);
#endif #endif
@ -112,7 +124,7 @@ void st7789_init(void)
st7789_send_cmd(st7789_init_cmds[cmd].cmd); st7789_send_cmd(st7789_init_cmds[cmd].cmd);
st7789_send_data(st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F); st7789_send_data(st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F);
if (st7789_init_cmds[cmd].databytes & 0x80) { if (st7789_init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }
@ -162,8 +174,17 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
offsety1 += 40; offsety1 += 40;
offsety2 += 40; offsety2 += 40;
#endif #endif
#elif (LV_HOR_RES_MAX == 320) && (LV_VER_RES_MAX == 170) // 1.9 inch 170×320 LCD, physically landscape
#if (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT) || (CONFIG_LV_DISPLAY_ORIENTATION_PORTRAIT_INVERTED)
offsety1 += 35;
offsety2 += 35;
#endif
#elif (LV_HOR_RES_MAX == 170) && (LV_VER_RES_MAX == 320) // 1.9 inch 170×320 LCD, physically vertical
#if (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE) || (CONFIG_LV_DISPLAY_ORIENTATION_LANDSCAPE_INVERTED)
offsetx1 += 35;
offsetx2 += 35;
#endif
#endif #endif
/*Column addresses*/ /*Column addresses*/
st7789_send_cmd(ST7789_CASET); st7789_send_cmd(ST7789_CASET);
data[0] = (offsetx1 >> 8) & 0xFF; data[0] = (offsetx1 >> 8) & 0xFF;

View file

@ -12,6 +12,10 @@
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
/********************* /*********************
* DEFINES * DEFINES
@ -82,18 +86,26 @@ void st7796s_init(void)
}; };
//Initialize non-SPI GPIOs //Initialize non-SPI GPIOs
gpio_pad_select_gpio(ST7796S_DC); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ST7796S_DC);
#else
esp_rom_gpio_pad_select_gpio(ST7796S_DC);
#endif
gpio_set_direction(ST7796S_DC, GPIO_MODE_OUTPUT); gpio_set_direction(ST7796S_DC, GPIO_MODE_OUTPUT);
#if ST7796S_USE_RST #if ST7796S_USE_RST
gpio_pad_select_gpio(ST7796S_RST); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ST7796S_RST);
#else
esp_rom_gpio_pad_select_gpio(ST7796S_RST);
#endif
gpio_set_direction(ST7796S_RST, GPIO_MODE_OUTPUT); gpio_set_direction(ST7796S_RST, GPIO_MODE_OUTPUT);
//Reset the display //Reset the display
gpio_set_level(ST7796S_RST, 0); gpio_set_level(ST7796S_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ST7796S_RST, 1); gpio_set_level(ST7796S_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
#endif #endif
ESP_LOGI(TAG, "Initialization."); ESP_LOGI(TAG, "Initialization.");
@ -106,7 +118,7 @@ void st7796s_init(void)
st7796s_send_data(init_cmds[cmd].data, init_cmds[cmd].databytes & 0x1F); st7796s_send_data(init_cmds[cmd].data, init_cmds[cmd].databytes & 0x1F);
if (init_cmds[cmd].databytes & 0x80) if (init_cmds[cmd].databytes & 0x80)
{ {
vTaskDelay(100 / portTICK_RATE_MS); vTaskDelay(100 / portTICK_PERIOD_MS);
} }
cmd++; cmd++;
} }

View file

@ -9,6 +9,10 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include <stddef.h> #include <stddef.h>
#include "esp_idf_version.h"
#if ESP_IDF_VERSION <= ESP_IDF_VERSION_VAL(5,0,0)
#include "rom/gpio.h"
#endif
#if CONFIG_LV_TOUCH_CONTROLLER_ADCRAW #if CONFIG_LV_TOUCH_CONTROLLER_ADCRAW
@ -139,10 +143,18 @@ static void setup_axis(gpio_num_t plus, gpio_num_t minus, gpio_num_t measure, gp
{ {
// Set GPIOs: // Set GPIOs:
// - Float "ignore" and "measure" // - Float "ignore" and "measure"
gpio_pad_select_gpio(ignore); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ignore);
#else
esp_rom_gpio_pad_select_gpio(ignore);
#endif
gpio_set_direction(ignore, GPIO_MODE_DISABLE); gpio_set_direction(ignore, GPIO_MODE_DISABLE);
gpio_set_pull_mode(ignore, GPIO_FLOATING); gpio_set_pull_mode(ignore, GPIO_FLOATING);
gpio_pad_select_gpio(measure); #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(measure);
#else
esp_rom_gpio_pad_select_gpio(measure);
#endif
gpio_set_direction(measure, GPIO_MODE_DISABLE); gpio_set_direction(measure, GPIO_MODE_DISABLE);
gpio_set_pull_mode(measure, GPIO_FLOATING); gpio_set_pull_mode(measure, GPIO_FLOATING);
// - Set "plus" to 1, "minus" to 0 // - Set "plus" to 1, "minus" to 0

View file

@ -150,7 +150,7 @@ bool ft6x36_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
data->point.x = touch_inputs.last_x; data->point.x = touch_inputs.last_x;
data->point.y = touch_inputs.last_y; data->point.y = touch_inputs.last_y;
data->state = touch_inputs.current_state; data->state = touch_inputs.current_state;
ESP_LOGD(TAG, "X=%u Y=%u", data->point.x, data->point.y); ESP_LOGV(TAG, "X=%u Y=%u", data->point.x, data->point.y);
#if CONFIG_LV_FT6X36_COORDINATES_QUEUE #if CONFIG_LV_FT6X36_COORDINATES_QUEUE
xQueueOverwrite( ft6x36_touch_queue_handle, &touch_inputs ); xQueueOverwrite( ft6x36_touch_queue_handle, &touch_inputs );

View file

@ -138,7 +138,7 @@ bool gt911_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
data->point.x = last_x; data->point.x = last_x;
data->point.y = last_y; data->point.y = last_y;
data->state = LV_INDEV_STATE_PR; data->state = LV_INDEV_STATE_PR;
ESP_LOGI(TAG, "X=%u Y=%u", data->point.x, data->point.y); ESP_LOGV(TAG, "X=%u Y=%u", data->point.x, data->point.y);
ESP_LOGV(TAG, "X=%u Y=%u", data->point.x, data->point.y); ESP_LOGV(TAG, "X=%u Y=%u", data->point.x, data->point.y);
return false; return false;
} }

View file

@ -16,7 +16,7 @@
#include "../lvgl_tft/ra8875.h" #include "../lvgl_tft/ra8875.h"
#ifndef CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875 #ifndef CONFIG_LV_TFT_DISPLAY_CONTROLLER_RA8875
#error "Display controller must be RA8875" #error "Display controller must be RA8875"
#endif #endif
/********************* /*********************
@ -31,23 +31,23 @@
#define TPCR0_ADC_TIMING ((CONFIG_LV_TOUCH_RA8875_SAMPLE_TIME << 4) | CONFIG_LV_TOUCH_RA8875_ADC_CLOCK) #define TPCR0_ADC_TIMING ((CONFIG_LV_TOUCH_RA8875_SAMPLE_TIME << 4) | CONFIG_LV_TOUCH_RA8875_ADC_CLOCK)
#if LVGL_TOUCH_RA8875_WAKEUP_ENABLE #if LVGL_TOUCH_RA8875_WAKEUP_ENABLE
#define TPCR0_VAL (0x08 | TPCR0_ADC_TIMING) #define TPCR0_VAL (0x08 | TPCR0_ADC_TIMING)
#else #else
#define TPCR0_VAL (TPCR0_ADC_TIMING) #define TPCR0_VAL (TPCR0_ADC_TIMING)
#endif #endif
#if LVGL_TOUCH_RA8875_EXTERNAL_VREF #if LVGL_TOUCH_RA8875_EXTERNAL_VREF
#if LVGL_TOUCH_RA8875_DEBOUNCE_ENABLE #if LVGL_TOUCH_RA8875_DEBOUNCE_ENABLE
#define TPCR1_VAL (0x24) #define TPCR1_VAL (0x24)
#else
#define TPCR1_VAL (0x20)
#endif
#else #else
#if LVGL_TOUCH_RA8875_DEBOUNCE_ENABLE #define TPCR1_VAL (0x20)
#define TPCR1_VAL (0x04) #endif
#else #else
#define TPCR1_VAL (0x00) #if LVGL_TOUCH_RA8875_DEBOUNCE_ENABLE
#endif #define TPCR1_VAL (0x04)
#else
#define TPCR1_VAL (0x00)
#endif
#endif #endif
/********************** /**********************
@ -58,7 +58,7 @@
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void ra8875_corr(int * x, int * y); static void ra8875_corr(int *x, int *y);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@ -72,16 +72,15 @@ static void ra8875_corr(int * x, int * y);
* GLOBAL FUNCTIONS * GLOBAL FUNCTIONS
**********************/ **********************/
void ra8875_touch_init(void) void ra8875_touch_init(void) {
{
struct { struct {
uint8_t cmd; // Register address of command uint8_t cmd; // Register address of command
uint8_t data; // Value to write to register uint8_t data; // Value to write to register
} init_cmds[] = { } init_cmds[] = {
{RA8875_REG_TPCR0, TPCR0_VAL}, // Touch Panel Control Register 0 (TPCR0) {RA8875_REG_TPCR0, TPCR0_VAL}, // Touch Panel Control Register 0 (TPCR0)
{RA8875_REG_TPCR1, TPCR1_VAL}, // Touch Panel Control Register 1 (TPCR1) {RA8875_REG_TPCR1, TPCR1_VAL}, // Touch Panel Control Register 1 (TPCR1)
}; };
#define INIT_CMDS_SIZE (sizeof(init_cmds)/sizeof(init_cmds[0])) #define INIT_CMDS_SIZE (sizeof(init_cmds)/sizeof(init_cmds[0]))
ESP_LOGI(TAG, "Initializing RA8875 Touch..."); ESP_LOGI(TAG, "Initializing RA8875 Touch...");
@ -92,8 +91,7 @@ void ra8875_touch_init(void)
ra8875_touch_enable(true); ra8875_touch_enable(true);
} }
void ra8875_touch_enable(bool enable) void ra8875_touch_enable(bool enable) {
{
ESP_LOGI(TAG, "%s touch.", enable ? "Enabling" : "Disabling"); ESP_LOGI(TAG, "%s touch.", enable ? "Enabling" : "Disabling");
uint8_t val = enable ? (0x80 | TPCR0_VAL) : (TPCR0_VAL); uint8_t val = enable ? (0x80 | TPCR0_VAL) : (TPCR0_VAL);
ra8875_write_cmd(RA8875_REG_TPCR0, val); ra8875_write_cmd(RA8875_REG_TPCR0, val);
@ -104,8 +102,7 @@ void ra8875_touch_enable(bool enable)
* @param data store the read data here * @param data store the read data here
* @return false: because no more data to be read * @return false: because no more data to be read
*/ */
bool ra8875_touch_read(lv_indev_drv_t * drv, lv_indev_data_t * data) bool ra8875_touch_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
{
static int x = 0; static int x = 0;
static int y = 0; static int y = 0;
@ -121,9 +118,9 @@ bool ra8875_touch_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
x = (x << 2) | (xy & 0x03); x = (x << 2) | (xy & 0x03);
y = (y << 2) | ((xy >> 2) & 0x03); y = (y << 2) | ((xy >> 2) & 0x03);
#if DEBUG
ESP_LOGI(TAG, "Touch Poll Raw: %d,%d", x, y); ESP_LOGV(TAG, "Touch Poll Raw: %d,%d", x, y);
#endif
// Convert to display coordinates // Convert to display coordinates
ra8875_corr(&x, &y); ra8875_corr(&x, &y);
@ -135,9 +132,8 @@ bool ra8875_touch_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
data->point.x = x; data->point.x = x;
data->point.y = y; data->point.y = y;
#if DEBUG ESP_LOGV(TAG, "Touch Poll - Event: %d; %d,%d", data->state, data->point.x, data->point.y);
ESP_LOGI(TAG, "Touch Poll - Event: %d; %d,%d", data->state, data->point.x, data->point.y);
#endif
return false; return false;
} }
@ -147,8 +143,7 @@ bool ra8875_touch_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
static void ra8875_corr(int * x, int * y) static void ra8875_corr(int *x, int *y) {
{
#if RA8875_XY_SWAP != 0 #if RA8875_XY_SWAP != 0
int tmp = *x; int tmp = *x;
*x = *y; *x = *y;
@ -158,17 +153,17 @@ static void ra8875_corr(int * x, int * y)
if ((*x) <= RA8875_X_MIN) { if ((*x) <= RA8875_X_MIN) {
(*x) = 0; (*x) = 0;
} else if ((*x) >= RA8875_X_MAX) { } else if ((*x) >= RA8875_X_MAX) {
(*x) = LV_HOR_RES-1; (*x) = LV_HOR_RES - 1;
} else { } else {
(*x) = (((*x) - RA8875_X_MIN) * (LV_HOR_RES-1)) / (RA8875_X_MAX - RA8875_X_MIN); (*x) = (((*x) - RA8875_X_MIN) * (LV_HOR_RES - 1)) / (RA8875_X_MAX - RA8875_X_MIN);
} }
if ((*y) <= RA8875_Y_MIN) { if ((*y) <= RA8875_Y_MIN) {
(*y) = 0; (*y) = 0;
} else if ((*y) >= RA8875_Y_MAX) { } else if ((*y) >= RA8875_Y_MAX) {
(*y) = LV_VER_RES-1; (*y) = LV_VER_RES - 1;
} else { } else {
(*y) = (((*y) - RA8875_Y_MIN) * (LV_VER_RES-1)) / (RA8875_Y_MAX - RA8875_Y_MIN); (*y) = (((*y) - RA8875_Y_MIN) * (LV_VER_RES - 1)) / (RA8875_Y_MAX - RA8875_Y_MIN);
} }
#if RA8875_X_INV != 0 #if RA8875_X_INV != 0

View file

@ -63,7 +63,7 @@ void stmpe610_init(void)
// Attempt a software reset // Attempt a software reset
write_8bit_reg(STMPE_SYS_CTRL1, STMPE_SYS_CTRL1_RESET); write_8bit_reg(STMPE_SYS_CTRL1, STMPE_SYS_CTRL1_RESET);
vTaskDelay(10 / portTICK_RATE_MS); vTaskDelay(10 / portTICK_PERIOD_MS);
// Reset the SPI configuration, making sure auto-increment is set // Reset the SPI configuration, making sure auto-increment is set
u8 = read_8bit_reg(STMPE_SPI_CFG); u8 = read_8bit_reg(STMPE_SPI_CFG);

View file

@ -94,19 +94,19 @@ bool xpt2046_read(lv_indev_drv_t * drv, lv_indev_data_t * data)
x = xpt2046_cmd(CMD_X_READ); x = xpt2046_cmd(CMD_X_READ);
y = xpt2046_cmd(CMD_Y_READ); y = xpt2046_cmd(CMD_Y_READ);
ESP_LOGI(TAG, "P(%d,%d)", x, y); ESP_LOGV(TAG, "P(%d,%d)", x, y);
/*Normalize Data back to 12-bits*/ /*Normalize Data back to 12-bits*/
x = x >> 4; x = x >> 4;
y = y >> 4; y = y >> 4;
ESP_LOGI(TAG, "P_norm(%d,%d)", x, y); ESP_LOGV(TAG, "P_norm(%d,%d)", x, y);
xpt2046_corr(&x, &y); xpt2046_corr(&x, &y);
xpt2046_avg(&x, &y); xpt2046_avg(&x, &y);
last_x = x; last_x = x;
last_y = y; last_y = y;
ESP_LOGI(TAG, "x = %d, y = %d", x, y); ESP_LOGV(TAG, "x = %d, y = %d", x, y);
} }
else else
{ {