2020-12-17 06:02:55 +00:00
|
|
|
/**
|
|
|
|
* @file ili9341.c
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
|
|
|
#include "ili9341.h"
|
2021-10-05 05:03:02 +00:00
|
|
|
|
|
|
|
#include "display_port.h"
|
2020-12-17 06:02:55 +00:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2021-10-05 05:03:02 +00:00
|
|
|
#define END_OF_CMD_MARKER 0xFFU
|
|
|
|
|
|
|
|
#define MEMORY_ACCESS_CONTROL_REG 0x36U
|
|
|
|
#define SOFTWARE_RESET_REG 0x01U
|
2020-12-17 06:02:55 +00:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/*The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. */
|
2021-10-05 05:03:02 +00:00
|
|
|
|
2020-12-17 06:02:55 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t cmd;
|
|
|
|
uint8_t data[16];
|
|
|
|
uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
|
|
|
|
} lcd_init_cmd_t;
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2021-10-05 05:03:02 +00:00
|
|
|
static void ili9341_set_orientation(lv_disp_drv_t * drv, uint8_t orientation);
|
|
|
|
static void ili9341_reset(lv_disp_drv_t * drv);
|
2020-12-17 06:02:55 +00:00
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
2021-10-05 05:03:02 +00:00
|
|
|
void ili9341_init(lv_disp_drv_t * drv)
|
2020-12-17 06:02:55 +00:00
|
|
|
{
|
2021-10-05 05:03:02 +00:00
|
|
|
lcd_init_cmd_t ili_init_cmds[] = {
|
|
|
|
{0xCF, {0x00, 0x83, 0X30}, 3},
|
|
|
|
{0xED, {0x64, 0x03, 0X12, 0X81}, 4},
|
|
|
|
{0xE8, {0x85, 0x01, 0x79}, 3},
|
|
|
|
{0xCB, {0x39, 0x2C, 0x00, 0x34, 0x02}, 5},
|
|
|
|
{0xF7, {0x20}, 1},
|
|
|
|
{0xEA, {0x00, 0x00}, 2},
|
|
|
|
/* Power control */
|
|
|
|
{0xC0, {0x26}, 1},
|
|
|
|
/* Power control */
|
|
|
|
{0xC1, {0x11}, 1},
|
|
|
|
/* VCOM control */
|
|
|
|
{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},
|
|
|
|
{0xF2, {0x08}, 1},
|
|
|
|
{0x26, {0x01}, 1},
|
|
|
|
{0xE0, {0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0X87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00}, 15},
|
|
|
|
{0XE1, {0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F}, 15},
|
|
|
|
{0x2A, {0x00, 0x00, 0x00, 0xEF}, 4},
|
|
|
|
{0x2B, {0x00, 0x00, 0x01, 0x3f}, 4},
|
|
|
|
{0x2C, {0}, 0},
|
|
|
|
{0xB7, {0x07}, 1},
|
|
|
|
{0xB6, {0x0A, 0x82, 0x27, 0x00}, 4},
|
|
|
|
{0x11, {0}, 0x80},
|
|
|
|
{0x29, {0}, 0x80},
|
|
|
|
{0, {0}, END_OF_CMD_MARKER},
|
|
|
|
};
|
2020-12-17 06:02:55 +00:00
|
|
|
|
2021-10-05 05:03:02 +00:00
|
|
|
ili9341_reset(drv);
|
2020-12-17 06:02:55 +00:00
|
|
|
|
2021-10-05 05:03:02 +00:00
|
|
|
//Send all the commands
|
2021-11-20 02:06:18 +00:00
|
|
|
uint16_t idx = 0;
|
|
|
|
while (ili_init_cmds[idx].databytes != END_OF_CMD_MARKER) {
|
|
|
|
uint8_t cmd = ili_init_cmds[idx].cmd;
|
|
|
|
void *args = ili_init_cmds[idx].data;
|
|
|
|
size_t args_len = ili_init_cmds[idx].databytes & 0x1F;
|
|
|
|
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, cmd, CMD_WIDTH_8BITS, args, args_len);
|
2021-10-05 05:03:02 +00:00
|
|
|
|
2021-11-20 02:06:18 +00:00
|
|
|
if (ili_init_cmds[idx].databytes & 0x80) {
|
2021-10-05 05:03:02 +00:00
|
|
|
display_port_delay(drv, 100);
|
|
|
|
}
|
2020-12-17 06:02:55 +00:00
|
|
|
|
2021-11-20 02:06:18 +00:00
|
|
|
idx++;
|
2021-10-05 05:03:02 +00:00
|
|
|
}
|
2020-12-17 06:02:55 +00:00
|
|
|
|
2021-10-05 05:03:02 +00:00
|
|
|
ili9341_set_orientation(drv, ILI9341_INITIAL_ORIENTATION);
|
|
|
|
|
|
|
|
#if ILI9341_INVERT_COLORS == 1U
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, 0x21, CMD_WIDTH_8BITS, NULL, 0);
|
2020-12-17 06:02:55 +00:00
|
|
|
#else
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, 0x20, CMD_WIDTH_8BITS, NULL, 0);
|
2020-12-17 06:02:55 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
|
|
|
|
{
|
2021-10-05 05:03:02 +00:00
|
|
|
uint8_t data[4] = {0};
|
|
|
|
uint32_t size = lv_area_get_width(area) * lv_area_get_height(area);
|
|
|
|
|
2021-11-26 17:21:46 +00:00
|
|
|
#if LV_COLOR_DEPTH == 16
|
|
|
|
/* Each pixel is 2bytes */
|
|
|
|
size *= 2;
|
|
|
|
#endif
|
|
|
|
|
2021-10-05 05:03:02 +00:00
|
|
|
/*Column addresses*/
|
|
|
|
data[0] = (area->x1 >> 8) & 0xFF;
|
|
|
|
data[1] = area->x1 & 0xFF;
|
|
|
|
data[2] = (area->x2 >> 8) & 0xFF;
|
|
|
|
data[3] = area->x2 & 0xFF;
|
2021-11-20 02:06:18 +00:00
|
|
|
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, 0x2A, CMD_WIDTH_8BITS, data, sizeof(data));
|
2021-10-05 05:03:02 +00:00
|
|
|
|
|
|
|
/* Page addresses */
|
|
|
|
data[0] = (area->y1 >> 8) & 0xFF;
|
|
|
|
data[1] = area->y1 & 0xFF;
|
|
|
|
data[2] = (area->y2 >> 8) & 0xFF;
|
|
|
|
data[3] = area->y2 & 0xFF;
|
2021-11-20 02:06:18 +00:00
|
|
|
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, 0x2B, CMD_WIDTH_8BITS, data, sizeof(data));
|
2021-10-05 05:03:02 +00:00
|
|
|
|
|
|
|
/* Memory write */
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, 0x2C, CMD_WIDTH_8BITS, NULL, 0);
|
2021-11-26 17:21:46 +00:00
|
|
|
display_interface_send_data(drv, color_map, size);
|
2020-12-17 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 05:03:02 +00:00
|
|
|
void ili9341_sleep_in(lv_disp_drv_t * drv)
|
2020-12-17 06:02:55 +00:00
|
|
|
{
|
2021-10-05 05:03:02 +00:00
|
|
|
uint8_t data[] = {0x08};
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, 0x10, CMD_WIDTH_8BITS, data, 1);
|
2020-12-17 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 05:03:02 +00:00
|
|
|
void ili9341_sleep_out(lv_disp_drv_t * drv)
|
2020-12-17 06:02:55 +00:00
|
|
|
{
|
2021-10-05 05:03:02 +00:00
|
|
|
uint8_t data[] = {0x08};
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, 0x11, CMD_WIDTH_8BITS, data, 1);
|
2020-12-17 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
2021-10-05 05:03:02 +00:00
|
|
|
static void ili9341_set_orientation(lv_disp_drv_t *drv, uint8_t orientation)
|
2020-12-17 06:02:55 +00:00
|
|
|
{
|
2021-08-03 14:35:25 +00:00
|
|
|
assert(orientation < 4);
|
2020-12-17 06:02:55 +00:00
|
|
|
|
|
|
|
#if defined CONFIG_LV_PREDEFINED_DISPLAY_M5STACK
|
2021-08-03 14:35:25 +00:00
|
|
|
const uint8_t data[] = {0x68, 0x68, 0x08, 0x08};
|
2021-04-28 09:43:40 +00:00
|
|
|
#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_M5CORE2)
|
2021-08-03 14:35:25 +00:00
|
|
|
const uint8_t data[] = {0x08, 0x88, 0x28, 0xE8};
|
2020-12-17 06:02:55 +00:00
|
|
|
#elif defined (CONFIG_LV_PREDEFINED_DISPLAY_WROVER4)
|
2021-08-03 14:35:25 +00:00
|
|
|
const uint8_t data[] = {0x6C, 0xEC, 0xCC, 0x4C};
|
|
|
|
#else
|
|
|
|
const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8};
|
2020-12-17 06:02:55 +00:00
|
|
|
#endif
|
|
|
|
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, MEMORY_ACCESS_CONTROL_REG, CMD_WIDTH_8BITS, &data[orientation], 1);
|
2021-10-05 05:03:02 +00:00
|
|
|
}
|
2020-12-17 06:02:55 +00:00
|
|
|
|
2021-10-05 05:03:02 +00:00
|
|
|
/* 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
|
2021-11-26 03:49:44 +00:00
|
|
|
display_interface_send_cmd(drv, SOFTWARE_RESET_REG, CMD_WIDTH_8BITS, NULL, 0);
|
2021-10-05 05:03:02 +00:00
|
|
|
display_port_delay(drv, 5);
|
|
|
|
#endif
|
2020-12-17 06:02:55 +00:00
|
|
|
}
|