Add support for commands with bigger width
This commit is contained in:
parent
db8be8a4da
commit
8a065b32b6
|
@ -66,48 +66,53 @@ bool display_port_gpio_is_busy(lv_disp_drv_t *drv)
|
|||
return device_busy;
|
||||
}
|
||||
|
||||
void display_interface_send_cmd(lv_disp_drv_t *drv, uint8_t cmd, void *args, size_t args_len)
|
||||
void display_interface_send_cmd(lv_disp_drv_t *drv, uint32_t cmd, cmd_width_t cmd_width, 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 (CMD_WIDTH_8BITS == cmd_width) {
|
||||
disp_spi_send_data(&cmd, 1);
|
||||
}
|
||||
else if (CMD_WIDTH_16BITS == cmd_width) {
|
||||
/* Send 16bits cmd */
|
||||
}
|
||||
else {
|
||||
/* Unsupported cmd size */
|
||||
}
|
||||
|
||||
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)
|
||||
(void) drv;
|
||||
uint8_t *data = (uint8_t *) args;
|
||||
|
||||
lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, cmd, data, args_len);
|
||||
#endif
|
||||
}
|
||||
|
||||
void display_interface_send_data_async(lv_disp_drv_t *drv, void *data, size_t len)
|
||||
void display_interface_send_data(lv_disp_drv_t *drv, void *data, size_t len, data_xfer_mode_t mode)
|
||||
{
|
||||
#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)
|
||||
(void) drv;
|
||||
lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, OLED_CONTROL_BYTE_DATA_STREAM, data, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
void display_interface_send_data(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);
|
||||
if (DATA_XFER_MODE_ASYNC == mode) {
|
||||
disp_spi_send_colors(data, len);
|
||||
}
|
||||
else if (DATA_XFER_MODE_SYNC == mode) {
|
||||
/* Send data in polling mode and call lv_disp_flush after that */
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
|
||||
(void) drv;
|
||||
lvgl_i2c_write(OLED_I2C_PORT, OLED_I2C_ADDRESS, OLED_CONTROL_BYTE_DATA_STREAM, data, len);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -15,6 +15,17 @@ extern "C"
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum {
|
||||
CMD_WIDTH_8BITS,
|
||||
CMD_WIDTH_16BITS,
|
||||
CMD_WIDTH_INVALID,
|
||||
} cmd_width_t;
|
||||
|
||||
typedef enum {
|
||||
DATA_XFER_MODE_SYNC,
|
||||
DATA_XFER_MODE_ASYNC,
|
||||
} data_xfer_mode_t;
|
||||
|
||||
/**
|
||||
* Busy wait delay port
|
||||
*
|
||||
|
@ -56,9 +67,27 @@ void display_port_gpio_rst(lv_disp_drv_t *drv, uint8_t state);
|
|||
*/
|
||||
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(lv_disp_drv_t *drv, void *data, size_t len);
|
||||
void display_interface_send_data_async(lv_disp_drv_t *drv, void *data, size_t len);
|
||||
/**
|
||||
* Send cmd to display
|
||||
*
|
||||
* @param drv Pointer to driver
|
||||
* @param cmd Command to send
|
||||
* @param cmd_width Width of the command (in bits) to be sent, see @ref cmd_width_t
|
||||
* @param args Pointer to arguments, use NULL to send command without arguments
|
||||
* @param args_len Arguments length (in bytes) to be sent
|
||||
*/
|
||||
void display_interface_send_cmd(lv_disp_drv_t *drv, uint32_t cmd, cmd_width_t cmd_width, void *args, size_t args_len);
|
||||
|
||||
/**
|
||||
* Send (image) data to display
|
||||
*
|
||||
* @param drv Pointer to driver
|
||||
* @param data Pointer to data to be sent
|
||||
* @param len Data length (in bytes) to be sent
|
||||
* @param mode Data transfer mode, sync (polling) and async, lv_disp_flush must
|
||||
* be called when finishing the data transfer
|
||||
*/
|
||||
void display_interface_send_data(lv_disp_drv_t *drv, void *data, size_t len, data_xfer_mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
@ -92,7 +92,7 @@ void ili9341_init(lv_disp_drv_t * drv)
|
|||
void *args = ili_init_cmds[idx].data;
|
||||
size_t args_len = ili_init_cmds[idx].databytes & 0x1F;
|
||||
|
||||
display_interface_send_cmd(drv, cmd, args, args_len);
|
||||
display_interface_send_cmd(drv, cmd, CMD_WIDTH_8BITS, args, args_len);
|
||||
|
||||
if (ili_init_cmds[idx].databytes & 0x80) {
|
||||
display_port_delay(drv, 100);
|
||||
|
@ -104,9 +104,9 @@ void ili9341_init(lv_disp_drv_t * drv)
|
|||
ili9341_set_orientation(drv, ILI9341_INITIAL_ORIENTATION);
|
||||
|
||||
#if ILI9341_INVERT_COLORS == 1U
|
||||
display_interface_send_cmd(drv, 0x21, NULL, 0);
|
||||
display_interface_send_cmd(drv, 0x21, CMD_WIDTH_8BITS, NULL, 0);
|
||||
#else
|
||||
display_interface_send_cmd(drv, 0x20, NULL, 0);
|
||||
display_interface_send_cmd(drv, 0x20, CMD_WIDTH_8BITS, NULL, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -122,7 +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[3] = area->x2 & 0xFF;
|
||||
|
||||
display_interface_send_cmd(drv, 0x2A, data, sizeof(data));
|
||||
display_interface_send_cmd(drv, 0x2A, CMD_WIDTH_8BITS, data, sizeof(data));
|
||||
|
||||
/* Page addresses */
|
||||
data[0] = (area->y1 >> 8) & 0xFF;
|
||||
|
@ -130,23 +130,23 @@ void ili9341_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
|
|||
data[2] = (area->y2 >> 8) & 0xFF;
|
||||
data[3] = area->y2 & 0xFF;
|
||||
|
||||
display_interface_send_cmd(drv, 0x2B, data, sizeof(data));
|
||||
display_interface_send_cmd(drv, 0x2B, CMD_WIDTH_8BITS, data, sizeof(data));
|
||||
|
||||
/* Memory write */
|
||||
display_interface_send_cmd(drv, 0x2C, NULL, 0);
|
||||
display_interface_send_data_async(drv, color_map, size * 2);
|
||||
display_interface_send_cmd(drv, 0x2C, CMD_WIDTH_8BITS, NULL, 0);
|
||||
display_interface_send_data(drv, color_map, size * 2, DATA_XFER_MODE_ASYNC);
|
||||
}
|
||||
|
||||
void ili9341_sleep_in(lv_disp_drv_t * drv)
|
||||
{
|
||||
uint8_t data[] = {0x08};
|
||||
display_interface_send_cmd(drv, 0x10, data, 1);
|
||||
display_interface_send_cmd(drv, 0x10, CMD_WIDTH_8BITS, data, 1);
|
||||
}
|
||||
|
||||
void ili9341_sleep_out(lv_disp_drv_t * drv)
|
||||
{
|
||||
uint8_t data[] = {0x08};
|
||||
display_interface_send_cmd(drv, 0x11, data, 1);
|
||||
display_interface_send_cmd(drv, 0x11, CMD_WIDTH_8BITS, data, 1);
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
@ -166,7 +166,7 @@ static void ili9341_set_orientation(lv_disp_drv_t *drv, uint8_t orientation)
|
|||
const uint8_t data[] = {0x48, 0x88, 0x28, 0xE8};
|
||||
#endif
|
||||
|
||||
display_interface_send_cmd(drv, MEMORY_ACCESS_CONTROL_REG, &data[orientation], 1);
|
||||
display_interface_send_cmd(drv, MEMORY_ACCESS_CONTROL_REG, CMD_WIDTH_8BITS, &data[orientation], 1);
|
||||
}
|
||||
|
||||
/* Reset the display, if we don't have a reset pin we use software reset */
|
||||
|
@ -178,7 +178,7 @@ static void ili9341_reset(lv_disp_drv_t *drv)
|
|||
display_port_gpio_rst(drv, 1);
|
||||
display_port_delay(drv, 100);
|
||||
#else
|
||||
display_interface_send_cmd(drv, SOFTWARE_RESET_REG, NULL, 0);
|
||||
display_interface_send_cmd(drv, SOFTWARE_RESET_REG, CMD_WIDTH_8BITS, NULL, 0);
|
||||
display_port_delay(drv, 5);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue