Communication interface proposal

This commit is contained in:
C47D 2021-11-19 20:06:18 -06:00
parent c7607e93d8
commit 8bdc2aed38
3 changed files with 57 additions and 61 deletions

View file

@ -6,6 +6,11 @@
#include "sdkconfig.h" #include "sdkconfig.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "disp_spi.h"
#define LV_DISPLAY_DC_CMD_MODE 0
#define LV_DISPLAY_DC_DATA_MODE 1
void display_port_delay(lv_disp_drv_t *drv, uint32_t delay_ms) void display_port_delay(lv_disp_drv_t *drv, uint32_t delay_ms)
{ {
(void) drv; (void) drv;
@ -55,3 +60,31 @@ bool display_port_gpio_is_busy(lv_disp_drv_t *drv)
return device_busy; return device_busy;
} }
void display_interface_send_cmd(lv_disp_drv_t *drv, uint8_t cmd, void *args, size_t args_len)
{
(void) drv;
#if defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI)
disp_wait_for_pending_transactions();
display_port_gpio_dc(drv, LV_DISPLAY_DC_CMD_MODE);
disp_spi_send_data(&cmd, 1);
if (args != NULL) {
display_port_gpio_dc(drv, LV_DISPLAY_DC_DATA_MODE);
disp_spi_send_data(args, args_len);
}
#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
#endif
}
void display_interface_send_data_async(lv_disp_drv_t *drv, void *data, size_t len)
{
#if defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI)
disp_wait_for_pending_transactions();
display_port_gpio_dc(drv, LV_DISPLAY_DC_DATA_MODE);
disp_spi_send_colors(data, len);
#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
#endif
}

View file

@ -56,6 +56,9 @@ void display_port_gpio_rst(lv_disp_drv_t *drv, uint8_t state);
*/ */
bool display_port_gpio_is_busy(lv_disp_drv_t *drv); bool display_port_gpio_is_busy(lv_disp_drv_t *drv);
void display_interface_send_cmd(lv_disp_drv_t *drv, uint8_t cmd, void *args, size_t args_len);
void display_interface_send_data_async(lv_disp_drv_t *drv, void *data, size_t len);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

View file

@ -8,7 +8,6 @@
*********************/ *********************/
#include "ili9341.h" #include "ili9341.h"
#include "disp_spi.h"
#include "display_port.h" #include "display_port.h"
/********************* /*********************
@ -35,11 +34,6 @@ typedef struct {
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void ili9341_set_orientation(lv_disp_drv_t * drv, uint8_t orientation); static void ili9341_set_orientation(lv_disp_drv_t * drv, uint8_t orientation);
static void ili9341_send_cmd(lv_disp_drv_t * drv, uint8_t cmd);
static void ili9341_send_data(lv_disp_drv_t * drv, 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 void ili9341_reset(lv_disp_drv_t * drv);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@ -92,24 +86,27 @@ void ili9341_init(lv_disp_drv_t * drv)
ili9341_reset(drv); ili9341_reset(drv);
//Send all the commands //Send all the commands
uint16_t cmd = 0; uint16_t idx = 0;
while (ili_init_cmds[cmd].databytes != END_OF_CMD_MARKER) { while (ili_init_cmds[idx].databytes != END_OF_CMD_MARKER) {
ili9341_send_cmd(drv, ili_init_cmds[cmd].cmd); uint8_t cmd = ili_init_cmds[idx].cmd;
ili9341_send_data(drv, ili_init_cmds[cmd].data, ili_init_cmds[cmd].databytes & 0x1F); void *args = ili_init_cmds[idx].data;
size_t args_len = ili_init_cmds[idx].databytes & 0x1F;
if (ili_init_cmds[cmd].databytes & 0x80) { display_interface_send_cmd(drv, cmd, args, args_len);
if (ili_init_cmds[idx].databytes & 0x80) {
display_port_delay(drv, 100); display_port_delay(drv, 100);
} }
cmd++; idx++;
} }
ili9341_set_orientation(drv, ILI9341_INITIAL_ORIENTATION); ili9341_set_orientation(drv, ILI9341_INITIAL_ORIENTATION);
#if ILI9341_INVERT_COLORS == 1U #if ILI9341_INVERT_COLORS == 1U
ili9341_send_cmd(drv, 0x21); display_interface_send_cmd(drv, 0x21, NULL, 0);
#else #else
ili9341_send_cmd(drv, 0x20); display_interface_send_cmd(drv, 0x20, NULL, 0);
#endif #endif
} }
@ -125,8 +122,7 @@ void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
data[2] = (area->x2 >> 8) & 0xFF; data[2] = (area->x2 >> 8) & 0xFF;
data[3] = area->x2 & 0xFF; data[3] = area->x2 & 0xFF;
ili9341_send_cmd(drv, 0x2A); display_interface_send_cmd(drv, 0x2A, data, sizeof(data));
ili9341_send_data(drv, data, 4);
/* Page addresses */ /* Page addresses */
data[0] = (area->y1 >> 8) & 0xFF; data[0] = (area->y1 >> 8) & 0xFF;
@ -134,63 +130,28 @@ void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
data[2] = (area->y2 >> 8) & 0xFF; data[2] = (area->y2 >> 8) & 0xFF;
data[3] = area->y2 & 0xFF; data[3] = area->y2 & 0xFF;
ili9341_send_cmd(drv, 0x2B); display_interface_send_cmd(drv, 0x2B, data, sizeof(data));
ili9341_send_data(drv, data, 4);
/* Memory write */ /* Memory write */
ili9341_send_cmd(drv, 0x2C); display_interface_send_cmd(drv, 0x2C, NULL, 0);
ili9341_send_color(drv, (void*)color_map, size * 2); display_interface_send_data_async(drv, color_map, size * 2);
} }
void ili9341_sleep_in(lv_disp_drv_t * drv) void ili9341_sleep_in(lv_disp_drv_t * drv)
{ {
uint8_t data[] = {0x08}; uint8_t data[] = {0x08};
ili9341_send_cmd(drv, 0x10); display_interface_send_cmd(drv, 0x10, data, 1);
ili9341_send_data(drv, data, 1);
} }
void ili9341_sleep_out(lv_disp_drv_t * drv) void ili9341_sleep_out(lv_disp_drv_t * drv)
{ {
uint8_t data[] = {0x08}; uint8_t data[] = {0x08};
ili9341_send_cmd(drv, 0x11); display_interface_send_cmd(drv, 0x11, 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 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();
set_cmd_mode(drv);
disp_spi_send_data(&cmd, 1);
}
static void ili9341_send_data(lv_disp_drv_t *drv, void * data, uint16_t length)
{
disp_wait_for_pending_transactions();
set_data_mode(drv);
disp_spi_send_data(data, length);
}
static void ili9341_send_color(lv_disp_drv_t *drv, void * data, uint16_t length)
{
disp_wait_for_pending_transactions();
set_data_mode(drv);
disp_spi_send_colors(data, length);
}
static void ili9341_set_orientation(lv_disp_drv_t *drv, uint8_t orientation) static void ili9341_set_orientation(lv_disp_drv_t *drv, uint8_t orientation)
{ {
assert(orientation < 4); assert(orientation < 4);
@ -205,8 +166,7 @@ static void ili9341_set_orientation(lv_disp_drv_t *drv, uint8_t orientation)
const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8}; const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8};
#endif #endif
ili9341_send_cmd(drv, MEMORY_ACCESS_CONTROL_REG); display_interface_send_cmd(drv, MEMORY_ACCESS_CONTROL_REG, &data[orientation], 1);
ili9341_send_data(drv, (void *) &data[orientation], 1);
} }
/* Reset the display, if we don't have a reset pin we use software reset */ /* Reset the display, if we don't have a reset pin we use software reset */
@ -218,7 +178,7 @@ static void ili9341_reset(lv_disp_drv_t *drv)
display_port_gpio_rst(drv, 1); display_port_gpio_rst(drv, 1);
display_port_delay(drv, 100); display_port_delay(drv, 100);
#else #else
ili9341_send_cmd(drv, SOFTWARE_RESET_REG); display_interface_send_cmd(drv, SOFTWARE_RESET_REG, NULL, 0);
display_port_delay(drv, 5); display_port_delay(drv, 5);
#endif #endif
} }