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}
INCLUDE_DIRS ${LVGL_INCLUDE_DIRS}
REQUIRES lvgl)
REQUIRES lvgl driver)
target_compile_definitions(${COMPONENT_LIB} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE")

View file

@ -16,6 +16,7 @@
#include "lvgl_spi_conf.h"
#include "lvgl_i2c/i2c_manager.h"
#include "esp_idf_version.h"
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
@ -23,6 +24,9 @@
#include "lvgl/lvgl.h"
#endif
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
#define SPI_HOST_MAX SOC_SPI_PERIPH_NUM
#endif
/*********************
* DEFINES
*********************/
@ -175,10 +179,14 @@ bool lvgl_spi_driver_init(int host,
};
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;
#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);
#endif
assert(ret == ESP_OK);
return ESP_OK != ret;

View file

@ -22,6 +22,14 @@ extern "C" {
/*********************
* 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
* of the buffer(s) passed to LVGL as display buffers. The default values used
@ -40,7 +48,7 @@ extern "C" {
#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)
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
#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
@ -56,7 +64,7 @@ extern "C" {
#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)
#if defined (CONFIG_LV_USE_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)

View file

@ -6,10 +6,8 @@ menu "I2C Port 0"
if I2C_MANAGER_0_ENABLED
config I2C_MANAGER_0_SDA
int "SDA (GPIO pin)"
default 0
config I2C_MANAGER_0_SCL
int "SCL (GPIO pin)"
default 0
config I2C_MANAGER_0_FREQ_HZ
int "Frequency (Hz)"
default 400000
@ -19,7 +17,7 @@ menu "I2C Port 0"
5000000 (5 Mhz). I2C busses that involve external wires may
have to be slower, and the real maximum speed the bus will
support depends on the value of the pullup resistors and the
design of the overall circuit.
design of the overall circuit.
config I2C_MANAGER_0_TIMEOUT
int "R/W timeout (ms)"
default 20
@ -50,10 +48,10 @@ endmenu
menu "I2C Port 1"
config I2C_MANAGER_1_ENABLED
bool "Enable I2C port 1"
if I2C_MANAGER_1_ENABLED
config I2C_MANAGER_1_SDA
int "SDA (GPIO pin)"
@ -68,7 +66,7 @@ menu "I2C Port 1"
5000000 (5 Mhz). I2C busses that involve external wires may
have to be slower, and the real maximum speed the bus will
support depends on the value of the pullup resistors and the
design of the overall circuit.
design of the overall circuit.
config I2C_MANAGER_1_TIMEOUT
int "R/W timeout (ms)"
default 20
@ -95,4 +93,4 @@ menu "I2C Port 1"
can attain. Try with these off first if you don't know.
endif
endmenu
endmenu

View file

@ -42,7 +42,7 @@ SOFTWARE.
#if defined __has_include
#if __has_include ("esp_idf_version.h")
#if __has_include ("esp_idf_version.h")
#include "esp_idf_version.h"
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
#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;
#if defined (I2C_NUM_0) && defined (CONFIG_I2C_MANAGER_0_ENABLED)
#define I2C_ZERO I2C_NUM_0
#if defined (CONFIG_I2C_MANAGER_0_ENABLED)
#define I2C_ZERO I2C_NUM_0
#if defined (CONFIG_I2C_MANAGER_0_PULLUPS)
#define I2C_MANAGER_0_PULLUPS true
#else
#define I2C_MANAGER_0_PULLUPS false
#endif
#define I2C_MANAGER_0_TIMEOUT ( CONFIG_I2C_MANAGER_0_TIMEOUT / portTICK_RATE_MS )
#define I2C_MANAGER_0_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT / portTICK_RATE_MS )
#define I2C_MANAGER_0_TIMEOUT ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_TIMEOUT ) )
#define I2C_MANAGER_0_LOCK_TIMEOUT ( ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT ) )
#endif
#if defined (I2C_NUM_1) && defined (CONFIG_I2C_MANAGER_1_ENABLED)
#define I2C_ONE I2C_NUM_1
#if defined (CONFIG_I2C_MANAGER_1_ENABLED)
#define I2C_ONE I2C_NUM_1
#if defined (CONFIG_I2C_MANAGER_1_PULLUPS)
#define I2C_MANAGER_1_PULLUPS true
#else
#define I2C_MANAGER_1_PULLUPS false
#endif
#define I2C_MANAGER_1_TIMEOUT ( CONFIG_I2C_MANAGER_1_TIMEOUT / portTICK_RATE_MS )
#define I2C_MANAGER_1_LOCK_TIMEOUT ( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT / portTICK_RATE_MS )
#define I2C_MANAGER_1_TIMEOUT ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_TIMEOUT ) )
#define I2C_MANAGER_1_LOCK_TIMEOUT ( pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT ) )
#endif
#define ERROR_PORT(port, fail) { \
@ -89,198 +89,198 @@ static const uint8_t ACK_CHECK_EN = 1;
}
#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);
#else
#if defined(I2C_ZERO)
#define I2C_PORT_CHECK(port, fail) \
#if defined(I2C_ZERO)
#define I2C_PORT_CHECK(port, fail) \
if (port != I2C_NUM_0) ERROR_PORT(port, fail);
#elif defined(I2C_ONE)
#define I2C_PORT_CHECK(port, fail) \
#elif defined(I2C_ONE)
#define I2C_PORT_CHECK(port, fail) \
if (port != I2C_NUM_1) ERROR_PORT(port, fail);
#else
#define I2C_PORT_CHECK(port, fail) \
#else
#define I2C_PORT_CHECK(port, fail) \
ERROR_PORT(port, fail);
#endif
#endif
#endif
static void i2c_send_address(i2c_cmd_handle_t cmd, uint16_t addr, i2c_rw_t rw) {
if (addr & I2C_ADDR_10) {
i2c_master_write_byte(cmd, 0xF0 | ((addr & 0x3FF) >> 7) | rw, ACK_CHECK_EN);
i2c_master_write_byte(cmd, addr & 0xFF, ACK_CHECK_EN);
} else {
i2c_master_write_byte(cmd, (addr << 1) | rw, ACK_CHECK_EN);
}
if (addr & I2C_ADDR_10) {
i2c_master_write_byte(cmd, 0xF0 | ((addr & 0x3FF) >> 7) | rw, ACK_CHECK_EN);
i2c_master_write_byte(cmd, addr & 0xFF, ACK_CHECK_EN);
} else {
i2c_master_write_byte(cmd, (addr << 1) | rw, ACK_CHECK_EN);
}
}
static void i2c_send_register(i2c_cmd_handle_t cmd, uint32_t reg) {
if (reg & I2C_REG_16) {
i2c_master_write_byte(cmd, (reg & 0xFF00) >> 8, ACK_CHECK_EN);
}
if (reg & I2C_REG_16) {
i2c_master_write_byte(cmd, (reg & 0xFF00) >> 8, ACK_CHECK_EN);
}
i2c_master_write_byte(cmd, reg & 0xFF, ACK_CHECK_EN);
}
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};
#ifdef HAS_CLK_FLAGS
conf.clk_flags = 0;
#endif
i2c_config_t conf = {0};
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
#ifdef HAS_CLK_FLAGS
conf.clk_flags = 0;
#endif
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
conf.sda_io_num = CONFIG_I2C_MANAGER_0_SDA;
conf.scl_io_num = CONFIG_I2C_MANAGER_0_SCL;
conf.sda_pullup_en = I2C_MANAGER_0_PULLUPS ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
conf.scl_pullup_en = conf.sda_pullup_en;
conf.master.clk_speed = CONFIG_I2C_MANAGER_0_FREQ_HZ;
}
#endif
#endif
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
conf.sda_io_num = CONFIG_I2C_MANAGER_1_SDA;
conf.scl_io_num = CONFIG_I2C_MANAGER_1_SCL;
conf.sda_pullup_en = I2C_MANAGER_1_PULLUPS ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
conf.scl_pullup_en = conf.sda_pullup_en;
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_driver_install(port, conf.mode, 0, 0, 0);
ret = i2c_param_config(port, &conf);
ret |= i2c_driver_install(port, conf.mode, 0, 0, 0);
if (ret != ESP_OK) {
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 "
"to open it. See I2C Manager README for details.");
} else {
ESP_LOGI(TAG, "Initialised port %d (SDA: %d, SCL: %d, speed: %d Hz.)",
port, conf.sda_io_num, conf.scl_io_num, conf.master.clk_speed);
}
if (ret != ESP_OK) {
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 "
"to open it. See I2C Manager README for details.");
} else {
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);
}
}
}
return ret;
}
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;
// 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;
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
TickType_t timeout = 0;
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
timeout = I2C_MANAGER_0_TIMEOUT;
}
#endif
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
#endif
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
timeout = I2C_MANAGER_1_TIMEOUT;
}
#endif
#endif
if (I2C_FN(_lock)((int)port) == ESP_OK) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
if (!(reg & I2C_NO_REG)) {
/* When reading specific register set the addr pointer first. */
i2c_master_start(cmd);
i2c_send_address(cmd, addr, I2C_MASTER_WRITE);
i2c_send_register(cmd, reg);
}
/* Read size bytes from the current pointer. */
i2c_master_start(cmd);
i2c_send_address(cmd, addr, I2C_MASTER_READ);
i2c_master_read(cmd, buffer, size, I2C_MASTER_LAST_NACK);
i2c_master_stop(cmd);
result = i2c_master_cmd_begin(port, cmd, timeout);
i2c_cmd_link_delete(cmd);
I2C_FN(_unlock)((int)port);
} else {
ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port);
return ESP_ERR_TIMEOUT;
}
if (result != ESP_OK) {
ESP_LOGW(TAG, "Error: %d", result);
if (I2C_FN(_lock)((int)port) == ESP_OK) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
if (!(reg & I2C_NO_REG)) {
/* When reading specific register set the addr pointer first. */
i2c_master_start(cmd);
i2c_send_address(cmd, addr, I2C_MASTER_WRITE);
i2c_send_register(cmd, reg);
}
/* Read size bytes from the current pointer. */
i2c_master_start(cmd);
i2c_send_address(cmd, addr, I2C_MASTER_READ);
i2c_master_read(cmd, buffer, size, I2C_MASTER_LAST_NACK);
i2c_master_stop(cmd);
result = i2c_master_cmd_begin(port, cmd, timeout);
i2c_cmd_link_delete(cmd);
I2C_FN(_unlock)((int)port);
} else {
ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port);
return ESP_ERR_TIMEOUT;
}
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;
}
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;
// 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;
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
timeout = (CONFIG_I2C_MANAGER_0_TIMEOUT) / portTICK_RATE_MS;
TickType_t timeout = 0;
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_TIMEOUT );
}
#endif
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
timeout = (CONFIG_I2C_MANAGER_1_TIMEOUT) / portTICK_RATE_MS;
#endif
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_TIMEOUT );
}
#endif
#endif
if (I2C_FN(_lock)((int)port) == ESP_OK) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_send_address(cmd, addr, I2C_MASTER_WRITE);
if (!(reg & I2C_NO_REG)) {
i2c_send_register(cmd, reg);
}
i2c_master_write(cmd, (uint8_t *)buffer, size, ACK_CHECK_EN);
i2c_master_stop(cmd);
result = i2c_master_cmd_begin( port, cmd, timeout);
i2c_cmd_link_delete(cmd);
I2C_FN(_unlock)((int)port);
} else {
ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port);
return ESP_ERR_TIMEOUT;
}
if (result != ESP_OK) {
ESP_LOGW(TAG, "Error: %d", result);
if (I2C_FN(_lock)((int)port) == ESP_OK) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_send_address(cmd, addr, I2C_MASTER_WRITE);
if (!(reg & I2C_NO_REG)) {
i2c_send_register(cmd, reg);
}
i2c_master_write(cmd, (uint8_t *)buffer, size, ACK_CHECK_EN);
i2c_master_stop(cmd);
result = i2c_master_cmd_begin( port, cmd, timeout);
i2c_cmd_link_delete(cmd);
I2C_FN(_unlock)((int)port);
} else {
ESP_LOGE(TAG, "Lock could not be obtained for port %d.", (int)port);
return ESP_ERR_TIMEOUT;
}
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;
}
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]);
I2C_FN(_mutex)[port] = NULL;
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) {
I2C_PORT_CHECK(port, ESP_FAIL);
ESP_LOGV(TAG, "Mutex lock set for %d.", (int)port);
I2C_PORT_CHECK(port, ESP_FAIL);
ESP_LOGV(TAG, "Mutex lock set for %d.", (int)port);
TickType_t timeout;
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
timeout = (CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT) / portTICK_RATE_MS;
TickType_t timeout;
#if defined (I2C_ZERO)
if (port == I2C_NUM_0) {
timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_0_LOCK_TIMEOUT );
}
#endif
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
timeout = (CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT) / portTICK_RATE_MS;
#endif
#if defined (I2C_ONE)
if (port == I2C_NUM_1) {
timeout = pdMS_TO_TICKS( CONFIG_I2C_MANAGER_1_LOCK_TIMEOUT );
}
#endif
#endif
if (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE) {
return ESP_OK;
} else {
ESP_LOGE(TAG, "Removing stale mutex lock from port %d.", (int)port);
I2C_FN(_force_unlock)(port);
return (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE ? ESP_OK : ESP_FAIL);
}
if (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE) {
return ESP_OK;
} else {
ESP_LOGE(TAG, "Removing stale mutex lock from port %d.", (int)port);
I2C_FN(_force_unlock)(port);
return (xSemaphoreTake(I2C_FN(_mutex)[port], timeout) == pdTRUE ? ESP_OK : ESP_FAIL);
}
}
esp_err_t I2C_FN(_unlock)(i2c_port_t port) {
I2C_PORT_CHECK(port, ESP_FAIL);
ESP_LOGV(TAG, "Mutex lock removed for %d.", (int)port);
return (xSemaphoreGive(I2C_FN(_mutex)[port]) == pdTRUE) ? ESP_OK : ESP_FAIL;
I2C_PORT_CHECK(port, ESP_FAIL);
ESP_LOGV(TAG, "Mutex lock removed for %d.", (int)port);
return (xSemaphoreGive(I2C_FN(_mutex)[port]) == pdTRUE) ? ESP_OK : ESP_FAIL;
}
esp_err_t I2C_FN(_force_unlock)(i2c_port_t port) {
I2C_PORT_CHECK(port, ESP_FAIL);
if (I2C_FN(_mutex)[port]) {
vSemaphoreDelete(I2C_FN(_mutex)[port]);
}
I2C_FN(_mutex)[port] = xSemaphoreCreateMutex();
return ESP_OK;
I2C_PORT_CHECK(port, ESP_FAIL);
if (I2C_FN(_mutex)[port]) {
vSemaphoreDelete(I2C_FN(_mutex)[port]);
}
I2C_FN(_mutex)[port] = xSemaphoreCreateMutex();
return ESP_OK;
}
#ifdef I2C_OEM
void I2C_FN(_locking)(void* leader) {
if (leader) {
ESP_LOGI(TAG, "Now following I2C Manager for locking");
I2C_FN(_mutex) = (SemaphoreHandle_t*)leader;
}
void I2C_FN(_locking)(void* leader) {
if (leader) {
ESP_LOGI(TAG, "Now following I2C Manager for locking");
I2C_FN(_mutex) = (SemaphoreHandle_t*)leader;
}
}
#else
void* i2c_manager_locking() {
void* i2c_manager_locking() {
return (void*)i2c_manager_mutex;
}
@ -365,4 +365,4 @@ esp_err_t I2C_FN(_force_unlock)(i2c_port_t port) {
return (void*)&_i2c_hal[port];
}
#endif
#endif

View file

@ -29,9 +29,9 @@ extern "C" {
#define STR_QUOTE(s) STR_EXPAND(STR_EXPAND(s))
#ifdef I2C_OEM
#define I2C_NAME_PREFIX CONCAT(I2C_OEM, _i2c)
#define I2C_NAME_PREFIX CONCAT(I2C_OEM, _i2c)
#else
#define I2C_NAME_PREFIX i2c_manager
#define I2C_NAME_PREFIX i2c_manager
#endif
#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
void I2C_FN(_locking)(void* leader);
void I2C_FN(_locking)(void* leader);
#else
void* i2c_manager_locking();
void* i2c_manager_locking();
typedef struct {
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);
void *handle;
} i2c_hal_t;
typedef struct {
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);
void *handle;
} i2c_hal_t;
void* i2c_hal(i2c_port_t port);
void* i2c_hal(i2c_port_t port);
#endif
@ -73,4 +73,4 @@ esp_err_t I2C_FN(_force_unlock)(i2c_port_t port);
#ifdef __cplusplus
}
#endif
#endif
#endif

View file

@ -7,7 +7,10 @@
#include "EVE.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 */
#define RED 0xff0000UL
#define ORANGE 0xffa500UL
@ -263,7 +266,12 @@ void TFT_bitmap_display(void)
void FT81x_init(void)
{
#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
gpio_set_level(EVE_CS, 1);

View file

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

View file

@ -196,6 +196,14 @@ menu "LVGL TFT Display controller"
help
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
choice DISPLAY_ORIENTATION
prompt "Display orientation"

View file

@ -6,12 +6,16 @@
/*********************
* INCLUDES
*********************/
#include <soc/gpio_sig_map.h>
#include "esp_lcd_backlight.h"
#include "driver/ledc.h"
#include "driver/gpio.h"
#include "esp_log.h"
#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 {
bool pwm_control; // true: LEDC is used, false: GPIO is used
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 = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.bit_num = LEDC_TIMER_10_BIT,
.duty_resolution = LEDC_TIMER_10_BIT,
.timer_num = config->timer_idx,
.freq_hz = 5000,
.clk_cfg = LEDC_AUTO_CLK};
ESP_ERROR_CHECK(ledc_timer_config(&LCD_backlight_timer));
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
{
// Configure GPIO for output
bckl_dev->index = config->gpio_num;
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
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));
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;
@ -101,7 +109,11 @@ void disp_backlight_delete(disp_backlight_h bckl)
if (bckl_dev->pwm_control) {
ledc_stop(LEDC_LOW_SPEED_MODE, bckl_dev->index, 0);
} 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);
}

View file

@ -21,7 +21,10 @@
#include <esp_log.h>
#include "freertos/FreeRTOS.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
*********************/
@ -160,18 +163,26 @@ static uint8_t displayType = HX8357D;
void hx8357_init(void)
{
//Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(HX8357_DC);
#else
esp_rom_gpio_pad_select_gpio(HX8357_DC);
#endif
gpio_set_direction(HX8357_DC, GPIO_MODE_OUTPUT);
#if HX8357_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(HX8357_RST);
#else
esp_rom_gpio_pad_select_gpio(HX8357_RST);
#endif
gpio_set_direction(HX8357_RST, GPIO_MODE_OUTPUT);
//Reset the display
gpio_set_level(HX8357_RST, 0);
vTaskDelay(10 / portTICK_RATE_MS);
vTaskDelay(10 / portTICK_PERIOD_MS);
gpio_set_level(HX8357_RST, 1);
vTaskDelay(120 / portTICK_RATE_MS);
vTaskDelay(120 / portTICK_PERIOD_MS);
#endif
ESP_LOGI(TAG, "Initialization.");
@ -192,7 +203,7 @@ void hx8357_init(void)
}
}
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 "freertos/FreeRTOS.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"
@ -196,21 +200,33 @@ void il3820_init(void)
uint8_t tmp[3] = {0};
/* Initialize non-SPI GPIOs */
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
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);
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
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);
#if IL3820_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
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);
/* Harware reset */
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);
vTaskDelay(IL3820_RESET_DELAY / portTICK_RATE_MS);
vTaskDelay(IL3820_RESET_DELAY / portTICK_PERIOD_MS);
#endif
/* Software reset */
@ -267,14 +283,14 @@ static void il3820_waitbusy(int wait_ms)
{
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++) {
if(gpio_get_level(IL3820_BUSY_PIN) != IL3820_BUSY_LEVEL) {
return;
}
vTaskDelay(10 / portTICK_RATE_MS);
vTaskDelay(10 / portTICK_PERIOD_MS);
}
ESP_LOGE( TAG, "busy exceeded %dms", i*10 );

View file

@ -13,6 +13,10 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.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
@ -138,16 +142,24 @@ void ili9163c_init(void)
};
//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_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);
//Reset the display
gpio_set_level(ILI9163C_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ILI9163C_RST, 1);
vTaskDelay(150 / portTICK_RATE_MS);
vTaskDelay(150 / portTICK_PERIOD_MS);
//Send all the commands
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);
if (ili_init_cmds[cmd].databytes & 0x80)
{
vTaskDelay(150 / portTICK_RATE_MS);
vTaskDelay(150 / portTICK_PERIOD_MS);
}
cmd++;
}

View file

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

View file

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

View file

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

View file

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

View file

@ -14,7 +14,10 @@
#include "freertos/task.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"
/**********************
@ -57,16 +60,24 @@ void pcd8544_init(void){
// TODO: orientation
// Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(PCD8544_DC);
#else
esp_rom_gpio_pad_select_gpio(PCD8544_DC);
#endif
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);
#else
esp_rom_gpio_pad_select_gpio(PCD8544_RST);
#endif
gpio_set_direction(PCD8544_RST, GPIO_MODE_OUTPUT);
// Reset the display
gpio_set_level(PCD8544_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
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(0x06); /* temp. control: b10 = 2 */

View file

@ -12,6 +12,10 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.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
@ -151,14 +155,18 @@ void ra8875_init(void)
// Initialize non-SPI GPIOs
#if RA8875_USE_RST
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(RA8875_RST);
#else
esp_rom_gpio_pad_select_gpio(RA8875_RST);
#endif
gpio_set_direction(RA8875_RST, GPIO_MODE_OUTPUT);
// Reset the RA8875
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);
vTaskDelay(DIV_ROUND_UP(100, portTICK_RATE_MS));
vTaskDelay(DIV_ROUND_UP(100, portTICK_PERIOD_MS));
#endif
// Initalize RA8875 clocks (SPI must be decelerated before initializing clocks)
@ -251,21 +259,21 @@ void ra8875_sleep_in(void)
ra8875_configure_clocks(false);
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)
}
void ra8875_sleep_out(void)
{
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);
disp_spi_change_device_speed(-1);
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)
@ -298,7 +306,7 @@ void ra8875_configure_clocks(bool high_speed)
vTaskDelay(1);
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)

View file

@ -12,6 +12,10 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.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
@ -92,18 +96,26 @@ void sh1107_init(void)
};
//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);
#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);
//Reset the display
gpio_set_level(SH1107_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(SH1107_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
#endif
//Send all the commands
@ -112,7 +124,7 @@ void sh1107_init(void)
sh1107_send_cmd(init_cmds[cmd].cmd);
sh1107_send_data(init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
if (init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
cmd++;
}

View file

@ -12,6 +12,10 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.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
#include "lvgl_i2c/i2c_manager.h"
@ -98,18 +102,26 @@ void st7735s_init(void)
};
//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);
#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);
//Reset the display
gpio_set_level(ST7735S_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ST7735S_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
#endif
ESP_LOGI(TAG, "ST7735S initialization.");
@ -120,7 +132,7 @@ void st7735s_init(void)
st7735s_send_cmd(init_cmds[cmd].cmd);
st7735s_send_data(init_cmds[cmd].data, init_cmds[cmd].databytes&0x1F);
if (init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
cmd++;
}

View file

@ -37,8 +37,19 @@ extern "C" {
// https://github.com/adafruit/Adafruit-ST7735-Library
//
#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 ROWSTART 1
#else
#define COLSTART 0
#define ROWSTART 0
#endif
// Delay between some initialisation commands
#define TFT_INIT_DELAY 0x80

View file

@ -14,6 +14,10 @@
#include "disp_spi.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
@ -86,20 +90,28 @@ void st7789_init(void)
};
//Initialize non-SPI GPIOs
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ST7789_DC);
#else
esp_rom_gpio_pad_select_gpio(ST7789_DC);
#endif
gpio_set_direction(ST7789_DC, GPIO_MODE_OUTPUT);
#if !defined(ST7789_SOFT_RST)
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0)
gpio_pad_select_gpio(ST7789_RST);
#else
esp_rom_gpio_pad_select_gpio(ST7789_RST);
#endif
gpio_set_direction(ST7789_RST, GPIO_MODE_OUTPUT);
#endif
//Reset the display
#if !defined(ST7789_SOFT_RST)
gpio_set_level(ST7789_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ST7789_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
#else
st7789_send_cmd(ST7789_SWRESET);
#endif
@ -112,7 +124,7 @@ void st7789_init(void)
st7789_send_cmd(st7789_init_cmds[cmd].cmd);
st7789_send_data(st7789_init_cmds[cmd].data, st7789_init_cmds[cmd].databytes&0x1F);
if (st7789_init_cmds[cmd].databytes & 0x80) {
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
cmd++;
}
@ -162,8 +174,17 @@ void st7789_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * colo
offsety1 += 40;
offsety2 += 40;
#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
/*Column addresses*/
st7789_send_cmd(ST7789_CASET);
data[0] = (offsetx1 >> 8) & 0xFF;

View file

@ -12,6 +12,10 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.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
@ -82,18 +86,26 @@ void st7796s_init(void)
};
//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);
#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);
//Reset the display
gpio_set_level(ST7796S_RST, 0);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(ST7796S_RST, 1);
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
#endif
ESP_LOGI(TAG, "Initialization.");
@ -106,7 +118,7 @@ void st7796s_init(void)
st7796s_send_data(init_cmds[cmd].data, init_cmds[cmd].databytes & 0x1F);
if (init_cmds[cmd].databytes & 0x80)
{
vTaskDelay(100 / portTICK_RATE_MS);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
cmd++;
}

View file

@ -9,6 +9,10 @@
#include "freertos/task.h"
#include "driver/gpio.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
@ -139,10 +143,18 @@ static void setup_axis(gpio_num_t plus, gpio_num_t minus, gpio_num_t measure, gp
{
// Set GPIOs:
// - 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_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_pull_mode(measure, GPIO_FLOATING);
// - 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.y = touch_inputs.last_y;
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
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.y = last_y;
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);
return false;
}

View file

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

View file

@ -63,7 +63,7 @@ void stmpe610_init(void)
// Attempt a software 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
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);
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*/
x = x >> 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_avg(&x, &y);
last_x = x;
last_y = y;
ESP_LOGI(TAG, "x = %d, y = %d", x, y);
ESP_LOGV(TAG, "x = %d, y = %d", x, y);
}
else
{