ili9341: Update driver to use new port interface
This commit is contained in:
parent
f6999a52fe
commit
f7164ff22a
|
@ -18,10 +18,17 @@ extern "C" {
|
||||||
|
|
||||||
#if defined (CONFIG_LV_INVERT_COLORS)
|
#if defined (CONFIG_LV_INVERT_COLORS)
|
||||||
#define ST7789_INVERT_COLORS 1U
|
#define ST7789_INVERT_COLORS 1U
|
||||||
|
#define ILI9341_INVERT_COLORS 1U
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ST7789_INITIAL_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION
|
#define ST7789_INITIAL_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION
|
||||||
|
|
||||||
|
#if CONFIG_LV_DISP_USE_RST
|
||||||
|
#define ILI9341_USE_RST
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ILI9341_INITIAL_ORIENTATION CONFIG_LV_DISPLAY_ORIENTATION
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
void *disp_driver_init(lv_disp_drv_t *drv)
|
void *disp_driver_init(lv_disp_drv_t *drv)
|
||||||
{
|
{
|
||||||
#if defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341
|
#if defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9341
|
||||||
ili9341_init();
|
ili9341_init(drv);
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9481
|
||||||
ili9481_init();
|
ili9481_init();
|
||||||
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488
|
#elif defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_ILI9488
|
||||||
|
|
|
@ -7,22 +7,25 @@
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include "ili9341.h"
|
#include "ili9341.h"
|
||||||
|
|
||||||
#include "disp_spi.h"
|
#include "disp_spi.h"
|
||||||
#include "driver/gpio.h"
|
#include "display_port.h"
|
||||||
#include "esp_log.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
#define TAG "ILI9341"
|
#define TAG "ILI9341"
|
||||||
|
#define END_OF_CMD_MARKER 0xFFU
|
||||||
|
|
||||||
|
#define MEMORY_ACCESS_CONTROL_REG 0x36U
|
||||||
|
#define SOFTWARE_RESET_REG 0x01U
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
/*The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. */
|
/*The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t cmd;
|
uint8_t cmd;
|
||||||
uint8_t data[16];
|
uint8_t data[16];
|
||||||
|
@ -32,12 +35,13 @@ typedef struct {
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
static void ili9341_set_orientation(uint8_t orientation);
|
static void ili9341_set_orientation(lv_disp_drv_t * drv, uint8_t orientation);
|
||||||
|
|
||||||
static void ili9341_send_cmd(uint8_t cmd);
|
static void ili9341_send_cmd(lv_disp_drv_t * drv, uint8_t cmd);
|
||||||
static void ili9341_send_data(void * data, uint16_t length);
|
static void ili9341_send_data(lv_disp_drv_t * drv, void * data, uint16_t length);
|
||||||
static void ili9341_send_color(void * data, uint16_t length);
|
static void ili9341_send_color(lv_disp_drv_t * drv, void * data, uint16_t length);
|
||||||
|
|
||||||
|
static void ili9341_reset(lv_disp_drv_t * drv);
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
|
@ -50,21 +54,27 @@ static void ili9341_send_color(void * data, uint16_t length);
|
||||||
* GLOBAL FUNCTIONS
|
* GLOBAL FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
void ili9341_init(void)
|
void ili9341_init(lv_disp_drv_t * drv)
|
||||||
{
|
{
|
||||||
lcd_init_cmd_t ili_init_cmds[]={
|
lcd_init_cmd_t ili_init_cmds[] = {
|
||||||
{0xCF, {0x00, 0x83, 0X30}, 3},
|
{0xCF, {0x00, 0x83, 0X30}, 3},
|
||||||
{0xED, {0x64, 0x03, 0X12, 0X81}, 4},
|
{0xED, {0x64, 0x03, 0X12, 0X81}, 4},
|
||||||
{0xE8, {0x85, 0x01, 0x79}, 3},
|
{0xE8, {0x85, 0x01, 0x79}, 3},
|
||||||
{0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5},
|
{0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5},
|
||||||
{0xF7, {0x20}, 1},
|
{0xF7, {0x20}, 1},
|
||||||
{0xEA, {0x00, 0x00}, 2},
|
{0xEA, {0x00, 0x00}, 2},
|
||||||
{0xC0, {0x26}, 1}, /*Power control*/
|
/* Power control */
|
||||||
{0xC1, {0x11}, 1}, /*Power control */
|
{0xC0, {0x26}, 1},
|
||||||
{0xC5, {0x35, 0x3E}, 2}, /*VCOM control*/
|
/* Power control */
|
||||||
{0xC7, {0xBE}, 1}, /*VCOM control*/
|
{0xC1, {0x11}, 1},
|
||||||
{0x36, {0x28}, 1}, /*Memory Access Control*/
|
/* VCOM control */
|
||||||
{0x3A, {0x55}, 1}, /*Pixel Format Set*/
|
{0xC5, {0x35, 0x3E}, 2},
|
||||||
|
/* VCOM control */
|
||||||
|
{0xC7, {0xBE}, 1},
|
||||||
|
/* Memory Access Control */
|
||||||
|
{0x36, {0x28}, 1},
|
||||||
|
/* Pixel Format Set */
|
||||||
|
{0x3A, {0x55}, 1},
|
||||||
{0xB1, {0x00, 0x1B}, 2},
|
{0xB1, {0x00, 0x1B}, 2},
|
||||||
{0xF2, {0x08}, 1},
|
{0xF2, {0x08}, 1},
|
||||||
{0x26, {0x01}, 1},
|
{0x26, {0x01}, 1},
|
||||||
|
@ -77,123 +87,115 @@ void ili9341_init(void)
|
||||||
{0xB6, {0x0A, 0x82, 0x27, 0x00}, 4},
|
{0xB6, {0x0A, 0x82, 0x27, 0x00}, 4},
|
||||||
{0x11, {0}, 0x80},
|
{0x11, {0}, 0x80},
|
||||||
{0x29, {0}, 0x80},
|
{0x29, {0}, 0x80},
|
||||||
{0, {0}, 0xff},
|
{0, {0}, END_OF_CMD_MARKER},
|
||||||
};
|
};
|
||||||
|
|
||||||
//Initialize non-SPI GPIOs
|
ili9341_reset(drv);
|
||||||
gpio_pad_select_gpio(ILI9341_DC);
|
|
||||||
gpio_set_direction(ILI9341_DC, GPIO_MODE_OUTPUT);
|
|
||||||
|
|
||||||
#if ILI9341_USE_RST
|
|
||||||
gpio_pad_select_gpio(ILI9341_RST);
|
|
||||||
gpio_set_direction(ILI9341_RST, GPIO_MODE_OUTPUT);
|
|
||||||
|
|
||||||
//Reset the display
|
|
||||||
gpio_set_level(ILI9341_RST, 0);
|
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
|
||||||
gpio_set_level(ILI9341_RST, 1);
|
|
||||||
vTaskDelay(100 / portTICK_RATE_MS);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initialization.");
|
|
||||||
|
|
||||||
//Send all the commands
|
//Send all the commands
|
||||||
uint16_t cmd = 0;
|
uint16_t cmd = 0;
|
||||||
while (ili_init_cmds[cmd].databytes!=0xff) {
|
while (ili_init_cmds[cmd].databytes != END_OF_CMD_MARKER) {
|
||||||
ili9341_send_cmd(ili_init_cmds[cmd].cmd);
|
ili9341_send_cmd(drv, ili_init_cmds[cmd].cmd);
|
||||||
ili9341_send_data(ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes&0x1F);
|
ili9341_send_data(drv, 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);
|
display_port_delay(drv, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd++;
|
cmd++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ili9341_set_orientation(CONFIG_LV_DISPLAY_ORIENTATION);
|
ili9341_set_orientation(drv, ILI9341_INITIAL_ORIENTATION);
|
||||||
|
|
||||||
#if ILI9341_INVERT_COLORS == 1
|
#if ILI9341_INVERT_COLORS == 1U
|
||||||
ili9341_send_cmd(0x21);
|
ili9341_send_cmd(drv, 0x21);
|
||||||
#else
|
#else
|
||||||
ili9341_send_cmd(0x20);
|
ili9341_send_cmd(drv, 0x20);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
|
void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
|
||||||
{
|
{
|
||||||
uint8_t data[4];
|
uint8_t data[4] = {0};
|
||||||
|
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
|
||||||
|
|
||||||
/*Column addresses*/
|
/*Column addresses*/
|
||||||
ili9341_send_cmd(0x2A);
|
|
||||||
data[0] = (area->x1 >> 8) & 0xFF;
|
data[0] = (area->x1 >> 8) & 0xFF;
|
||||||
data[1] = area->x1 & 0xFF;
|
data[1] = area->x1 & 0xFF;
|
||||||
data[2] = (area->x2 >> 8) & 0xFF;
|
data[2] = (area->x2 >> 8) & 0xFF;
|
||||||
data[3] = area->x2 & 0xFF;
|
data[3] = area->x2 & 0xFF;
|
||||||
ili9341_send_data(data, 4);
|
|
||||||
|
|
||||||
/*Page addresses*/
|
ili9341_send_cmd(drv, 0x2A);
|
||||||
ili9341_send_cmd(0x2B);
|
ili9341_send_data(drv, data, 4);
|
||||||
|
|
||||||
|
/* Page addresses */
|
||||||
data[0] = (area->y1 >> 8) & 0xFF;
|
data[0] = (area->y1 >> 8) & 0xFF;
|
||||||
data[1] = area->y1 & 0xFF;
|
data[1] = area->y1 & 0xFF;
|
||||||
data[2] = (area->y2 >> 8) & 0xFF;
|
data[2] = (area->y2 >> 8) & 0xFF;
|
||||||
data[3] = area->y2 & 0xFF;
|
data[3] = area->y2 & 0xFF;
|
||||||
ili9341_send_data(data, 4);
|
|
||||||
|
|
||||||
/*Memory write*/
|
ili9341_send_cmd(drv, 0x2B);
|
||||||
ili9341_send_cmd(0x2C);
|
ili9341_send_data(drv, data, 4);
|
||||||
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
|
|
||||||
ili9341_send_color((void*)color_map, size * 2);
|
/* Memory write */
|
||||||
|
ili9341_send_cmd(drv, 0x2C);
|
||||||
|
ili9341_send_color(drv, (void*)color_map, size * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ili9341_sleep_in()
|
void ili9341_sleep_in(lv_disp_drv_t * drv)
|
||||||
{
|
{
|
||||||
uint8_t data[] = {0x08};
|
uint8_t data[] = {0x08};
|
||||||
ili9341_send_cmd(0x10);
|
ili9341_send_cmd(drv, 0x10);
|
||||||
ili9341_send_data(&data, 1);
|
ili9341_send_data(drv, data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ili9341_sleep_out()
|
void ili9341_sleep_out(lv_disp_drv_t * drv)
|
||||||
{
|
{
|
||||||
uint8_t data[] = {0x08};
|
uint8_t data[] = {0x08};
|
||||||
ili9341_send_cmd(0x11);
|
ili9341_send_cmd(drv, 0x11);
|
||||||
ili9341_send_data(&data, 1);
|
ili9341_send_data(drv, data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
static inline void set_cmd_mode(lv_disp_drv_t * drv)
|
||||||
|
{
|
||||||
|
display_port_gpio_dc(drv, 0);
|
||||||
|
}
|
||||||
|
|
||||||
static void ili9341_send_cmd(uint8_t cmd)
|
static inline void set_data_mode(lv_disp_drv_t * drv)
|
||||||
|
{
|
||||||
|
display_port_gpio_dc(drv, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ili9341_send_cmd(lv_disp_drv_t * drv, uint8_t cmd)
|
||||||
{
|
{
|
||||||
disp_wait_for_pending_transactions();
|
disp_wait_for_pending_transactions();
|
||||||
gpio_set_level(ILI9341_DC, 0); /*Command mode*/
|
set_cmd_mode(drv);
|
||||||
disp_spi_send_data(&cmd, 1);
|
disp_spi_send_data(&cmd, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ili9341_send_data(void * data, uint16_t length)
|
static void ili9341_send_data(lv_disp_drv_t *drv, void * data, uint16_t length)
|
||||||
{
|
{
|
||||||
disp_wait_for_pending_transactions();
|
disp_wait_for_pending_transactions();
|
||||||
gpio_set_level(ILI9341_DC, 1); /*Data mode*/
|
set_data_mode(drv);
|
||||||
disp_spi_send_data(data, length);
|
disp_spi_send_data(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ili9341_send_color(void * data, uint16_t length)
|
static void ili9341_send_color(lv_disp_drv_t *drv, void * data, uint16_t length)
|
||||||
{
|
{
|
||||||
disp_wait_for_pending_transactions();
|
disp_wait_for_pending_transactions();
|
||||||
gpio_set_level(ILI9341_DC, 1); /*Data mode*/
|
set_data_mode(drv);
|
||||||
disp_spi_send_colors(data, length);
|
disp_spi_send_colors(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ili9341_set_orientation(uint8_t orientation)
|
static void ili9341_set_orientation(lv_disp_drv_t *drv, uint8_t orientation)
|
||||||
{
|
{
|
||||||
assert(orientation < 4);
|
assert(orientation < 4);
|
||||||
|
|
||||||
const char *orientation_str[] = {
|
|
||||||
"PORTRAIT", "PORTRAIT_INVERTED", "LANDSCAPE", "LANDSCAPE_INVERTED"
|
|
||||||
};
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Display orientation: %s", orientation_str[orientation]);
|
|
||||||
|
|
||||||
#if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK
|
#if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK
|
||||||
const uint8_t data[] = {0x68, 0x68, 0x08, 0x08};
|
const uint8_t data[] = {0x68, 0x68, 0x08, 0x08};
|
||||||
#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_M5CORE2)
|
#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_M5CORE2)
|
||||||
|
@ -204,8 +206,20 @@ static void ili9341_set_orientation(uint8_t orientation)
|
||||||
const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8};
|
const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ESP_LOGD(TAG, "0x36 command value: 0x%02X", data[orientation]);
|
ili9341_send_cmd(drv, MEMORY_ACCESS_CONTROL_REG);
|
||||||
|
ili9341_send_data(drv, (void *) &data[orientation], 1);
|
||||||
ili9341_send_cmd(0x36);
|
}
|
||||||
ili9341_send_data((void *) &data[orientation], 1);
|
|
||||||
|
/* Reset the display, if we don't have a reset pin we use software reset */
|
||||||
|
static void ili9341_reset(lv_disp_drv_t *drv)
|
||||||
|
{
|
||||||
|
#if defined(ILI9341_USE_RST)
|
||||||
|
display_port_gpio_rst(drv, 0);
|
||||||
|
display_port_delay(drv, 100);
|
||||||
|
display_port_gpio_rst(drv, 1);
|
||||||
|
display_port_delay(drv, 100);
|
||||||
|
#else
|
||||||
|
ili9341_send_cmd(drv, SOFTWARE_RESET_REG);
|
||||||
|
display_port_delay(drv, 5);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,23 +13,17 @@ extern "C" {
|
||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
#else
|
#else
|
||||||
#include "lvgl/lvgl.h"
|
#include "lvgl/lvgl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
#include "display_config.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
#define ILI9341_DC CONFIG_LV_DISP_PIN_DC
|
|
||||||
#define ILI9341_USE_RST CONFIG_LV_DISP_USE_RST
|
|
||||||
#define ILI9341_RST CONFIG_LV_DISP_PIN_RST
|
|
||||||
#define ILI9341_INVERT_COLORS CONFIG_LV_INVERT_COLORS
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
|
@ -39,10 +33,10 @@ extern "C" {
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
void ili9341_init(void);
|
void ili9341_init(lv_disp_drv_t * drv);
|
||||||
void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map);
|
||||||
void ili9341_sleep_in(void);
|
void ili9341_sleep_in(lv_disp_drv_t * drv);
|
||||||
void ili9341_sleep_out(void);
|
void ili9341_sleep_out(lv_disp_drv_t *drv);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
Loading…
Reference in a new issue