You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2023/09/22 16:22:22 UTC
[mynewt-core] branch master updated: lvgl/itf: Swap colors in place
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new cba530c70 lvgl/itf: Swap colors in place
cba530c70 is described below
commit cba530c70429a3e861274216d18957a9b1fe7433
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Sep 20 13:07:09 2023 +0200
lvgl/itf: Swap colors in place
Function lcd_itf_write_color_data() had pixel pointer constant
and in case of SPI when LV_COLOR_16_SWAP was set to 0 additional
buffer in RAM was allocated for swapped bytes.
LVGL however does not touch memory after it passes it to interface
so it is safe to swap bytes (if needed) in place.
Setting LV_COLOR_16_SWAP to 1 eliminates need for data swap but
then LVGL internally uses some extra bit manipulation.
Signed-off-by: Jerzy Kasenberg <je...@codecoup.pl>
---
hw/drivers/display/lcd_itf/include/lcd_itf.h | 2 +-
hw/drivers/display/lcd_itf/itf_8080/src/itf_8080.c | 2 +-
.../lcd_itf/itf_lcd_da1469x/src/itf_lcd_da1469x.c | 2 +-
hw/drivers/display/lcd_itf/itf_spi/src/itf_spi.c | 26 ++++++----------------
4 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/hw/drivers/display/lcd_itf/include/lcd_itf.h b/hw/drivers/display/lcd_itf/include/lcd_itf.h
index b720f0055..b18bfd0ce 100644
--- a/hw/drivers/display/lcd_itf/include/lcd_itf.h
+++ b/hw/drivers/display/lcd_itf/include/lcd_itf.h
@@ -96,6 +96,6 @@ void lcd_itf_init(void);
/* Function implemented by LCD interface driver */
void lcd_ift_write_cmd(const uint8_t *cmd, int cmd_length);
-void lcd_itf_write_color_data(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, const void *pixels);
+void lcd_itf_write_color_data(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, void *pixels);
#endif /* LCD_ITF_H */
diff --git a/hw/drivers/display/lcd_itf/itf_8080/src/itf_8080.c b/hw/drivers/display/lcd_itf/itf_8080/src/itf_8080.c
index 6400331c3..6ef364e69 100644
--- a/hw/drivers/display/lcd_itf/itf_8080/src/itf_8080.c
+++ b/hw/drivers/display/lcd_itf/itf_8080/src/itf_8080.c
@@ -91,7 +91,7 @@ lcd_itf_write_bytes(const uint8_t *bytes, size_t size)
}
void
-lcd_itf_write_color_data(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, const void *pixels)
+lcd_itf_write_color_data(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, void *pixels)
{
const uint16_t *data = (const uint16_t *)pixels;
size_t size = (x2 - x1 + 1) * (y2 - y1 + 1) * 2;
diff --git a/hw/drivers/display/lcd_itf/itf_lcd_da1469x/src/itf_lcd_da1469x.c b/hw/drivers/display/lcd_itf/itf_lcd_da1469x/src/itf_lcd_da1469x.c
index 522745d6c..ed375b194 100644
--- a/hw/drivers/display/lcd_itf/itf_lcd_da1469x/src/itf_lcd_da1469x.c
+++ b/hw/drivers/display/lcd_itf/itf_lcd_da1469x/src/itf_lcd_da1469x.c
@@ -29,7 +29,7 @@ static uint16_t display_resx;
static uint16_t display_resy;
void
-lcd_itf_write_color_data(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, const void *pixels)
+lcd_itf_write_color_data(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, void *pixels)
{
uint16_t width = 1 + x2 - x1;
uint16_t height = 1 + y2 - y1;
diff --git a/hw/drivers/display/lcd_itf/itf_spi/src/itf_spi.c b/hw/drivers/display/lcd_itf/itf_spi/src/itf_spi.c
index 294d678d7..a86adb62e 100644
--- a/hw/drivers/display/lcd_itf/itf_spi/src/itf_spi.c
+++ b/hw/drivers/display/lcd_itf/itf_spi/src/itf_spi.c
@@ -34,33 +34,21 @@ static struct bus_spi_node_cfg lcd_spi_cfg = {
};
static struct os_dev *lcd_dev;
-static uint8_t *lv_color_16_swap_buffer;
-static size_t lv_color_16_swap_buffer_size;
-
void
-lcd_itf_write_color_data(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, const void *pixels)
+lcd_itf_write_color_data(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2, void *pixels)
{
- const void *color_data = pixels;
+ uint8_t *color_data = pixels;
+ uint8_t b;
size_t i;
size_t size = (x2 - x1 + 1) * (y2 - y1 + 1) * 2;
LCD_DC_PIN_DATA();
LCD_CS_PIN_ACTIVE();
if (LV_COLOR_16_SWAP == 0) {
- if (size > lv_color_16_swap_buffer_size) {
- lv_color_16_swap_buffer = realloc(lv_color_16_swap_buffer, size);
- if (lv_color_16_swap_buffer) {
- lv_color_16_swap_buffer_size = size;
- } else {
- lv_color_16_swap_buffer_size = 0;
- }
- }
- if (lv_color_16_swap_buffer) {
- color_data = lv_color_16_swap_buffer;
- for (i = 0; i < size; i += 2) {
- lv_color_16_swap_buffer[i] = ((uint8_t *)pixels)[i + 1];
- lv_color_16_swap_buffer[i + 1] = ((uint8_t *)pixels)[i];
- }
+ for (i = 0; i < size; i += 2) {
+ b = color_data[i];
+ color_data[i] = color_data[i + 1];
+ color_data[i + 1] = b;
}
}
bus_node_write(lcd_dev, color_data, size, 1000, BUS_F_NOSTOP);