display: ili9340: Add RGB565 pixel format support.
Add support of RGB565 pixel format to ILI9340 driver. Signed-off-by: Bernard Lee <bernard.lee@nordicsemi.no>
This commit is contained in:
parent
7ab3bc57b5
commit
1541d5f8c1
2 changed files with 35 additions and 5 deletions
|
@ -25,4 +25,17 @@ config ILI9340_LCD_ADAFRUIT_1480
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "Color pixel format"
|
||||||
|
help
|
||||||
|
Specify the color pixel format of the ILI9340 display controller.
|
||||||
|
|
||||||
|
config ILI9340_RGB888
|
||||||
|
bool "RGB888"
|
||||||
|
|
||||||
|
config ILI9340_RGB565
|
||||||
|
bool "RGB565"
|
||||||
|
|
||||||
|
endchoice
|
||||||
|
|
||||||
endif #ILI9340
|
endif #ILI9340
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
* Copyright (c) 2017 Jan Van Winkel <jan.van_winkel@dxplore.eu>
|
||||||
|
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
@ -31,6 +32,13 @@ struct ili9340_data {
|
||||||
#define ILI9340_CMD_DATA_PIN_COMMAND 0
|
#define ILI9340_CMD_DATA_PIN_COMMAND 0
|
||||||
#define ILI9340_CMD_DATA_PIN_DATA 1
|
#define ILI9340_CMD_DATA_PIN_DATA 1
|
||||||
|
|
||||||
|
/* The number of bytes taken by a RGB pixel */
|
||||||
|
#ifdef CONFIG_ILI9340_RGB565
|
||||||
|
#define ILI9340_RGB_SIZE 2U
|
||||||
|
#else
|
||||||
|
#define ILI9340_RGB_SIZE 3U
|
||||||
|
#endif
|
||||||
|
|
||||||
static void ili9340_exit_sleep(struct ili9340_data *data)
|
static void ili9340_exit_sleep(struct ili9340_data *data)
|
||||||
{
|
{
|
||||||
ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0);
|
ili9340_transmit(data, ILI9340_CMD_EXIT_SLEEP, NULL, 0);
|
||||||
|
@ -132,7 +140,7 @@ static int ili9340_write(const struct device *dev, const u16_t x,
|
||||||
u16_t write_h;
|
u16_t write_h;
|
||||||
|
|
||||||
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width");
|
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width");
|
||||||
__ASSERT((desc->pitch * 3U * desc->height) <= desc->bu_size,
|
__ASSERT((desc->pitch * ILI9340_RGB_SIZE * desc->height) <= desc->bu_size,
|
||||||
"Input buffer to small");
|
"Input buffer to small");
|
||||||
|
|
||||||
LOG_DBG("Writing %dx%d (w,h) @ %dx%d (x,y)", desc->width, desc->height,
|
LOG_DBG("Writing %dx%d (w,h) @ %dx%d (x,y)", desc->width, desc->height,
|
||||||
|
@ -149,17 +157,17 @@ static int ili9340_write(const struct device *dev, const u16_t x,
|
||||||
|
|
||||||
ili9340_transmit(data, ILI9340_CMD_MEM_WRITE,
|
ili9340_transmit(data, ILI9340_CMD_MEM_WRITE,
|
||||||
(void *) write_data_start,
|
(void *) write_data_start,
|
||||||
desc->width * 3U * write_h);
|
desc->width * ILI9340_RGB_SIZE * write_h);
|
||||||
|
|
||||||
tx_bufs.buffers = &tx_buf;
|
tx_bufs.buffers = &tx_buf;
|
||||||
tx_bufs.count = 1;
|
tx_bufs.count = 1;
|
||||||
|
|
||||||
write_data_start += (desc->pitch * 3U);
|
write_data_start += (desc->pitch * ILI9340_RGB_SIZE);
|
||||||
for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) {
|
for (write_cnt = 1U; write_cnt < nbr_of_writes; ++write_cnt) {
|
||||||
tx_buf.buf = (void *)write_data_start;
|
tx_buf.buf = (void *)write_data_start;
|
||||||
tx_buf.len = desc->width * 3U * write_h;
|
tx_buf.len = desc->width * ILI9340_RGB_SIZE * write_h;
|
||||||
spi_write(data->spi_dev, &data->spi_config, &tx_bufs);
|
spi_write(data->spi_dev, &data->spi_config, &tx_bufs);
|
||||||
write_data_start += (desc->pitch * 3U);
|
write_data_start += (desc->pitch * ILI9340_RGB_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -215,7 +223,11 @@ static int ili9340_set_pixel_format(const struct device *dev,
|
||||||
const enum display_pixel_format
|
const enum display_pixel_format
|
||||||
pixel_format)
|
pixel_format)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_ILI9340_RGB565
|
||||||
|
if (pixel_format == PIXEL_FORMAT_RGB_565) {
|
||||||
|
#else
|
||||||
if (pixel_format == PIXEL_FORMAT_RGB_888) {
|
if (pixel_format == PIXEL_FORMAT_RGB_888) {
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
LOG_ERR("Pixel format change not implemented");
|
LOG_ERR("Pixel format change not implemented");
|
||||||
|
@ -238,8 +250,13 @@ static void ili9340_get_capabilities(const struct device *dev,
|
||||||
memset(capabilities, 0, sizeof(struct display_capabilities));
|
memset(capabilities, 0, sizeof(struct display_capabilities));
|
||||||
capabilities->x_resolution = 320U;
|
capabilities->x_resolution = 320U;
|
||||||
capabilities->y_resolution = 240U;
|
capabilities->y_resolution = 240U;
|
||||||
|
#ifdef CONFIG_ILI9340_RGB565
|
||||||
|
capabilities->supported_pixel_formats = PIXEL_FORMAT_RGB_565;
|
||||||
|
capabilities->current_pixel_format = PIXEL_FORMAT_RGB_565;
|
||||||
|
#else
|
||||||
capabilities->supported_pixel_formats = PIXEL_FORMAT_RGB_888;
|
capabilities->supported_pixel_formats = PIXEL_FORMAT_RGB_888;
|
||||||
capabilities->current_pixel_format = PIXEL_FORMAT_RGB_888;
|
capabilities->current_pixel_format = PIXEL_FORMAT_RGB_888;
|
||||||
|
#endif
|
||||||
capabilities->current_orientation = DISPLAY_ORIENTATION_NORMAL;
|
capabilities->current_orientation = DISPLAY_ORIENTATION_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue