From 221b09884638abc053796f7dde2b235b10198c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 21 Nov 2022 15:44:40 +0100 Subject: [PATCH] drivers/lcd/st7789: fix invalid displayed color The write has to be in number of bytes per pixel as single SPI exchange is used to identify single pixel write by the ST7789 driver. By issuing only byte writes the displayed color is corrupted as it is stripped. This fix consist of setting SPI to correct number of exchanged bytes and then passing correctly number of words to the SPI exchange. This also covers usage of st7789_wrram in st7789_putrun as that one was passing just number of pixels as size but the correct is now number of bytes. --- drivers/lcd/st7789.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/lcd/st7789.c b/drivers/lcd/st7789.c index 469ddbce93..e6c366f4cc 100644 --- a/drivers/lcd/st7789.c +++ b/drivers/lcd/st7789.c @@ -455,11 +455,12 @@ static void st7789_wrram(FAR struct st7789_dev_s *dev, st7789_sendcmd(dev, ST7789_RAMWR); - st7789_select(dev->spi, 8); + st7789_select(dev->spi, ST7789_BYTESPP * 8); for (i = 0; i < count; i++) { - SPI_SNDBLOCK(dev->spi, buff + (i * (size + skip)), size); + SPI_SNDBLOCK(dev->spi, buff + (i * (size + skip)), + size / ST7789_BYTESPP); } st7789_deselect(dev->spi); @@ -535,7 +536,7 @@ static int st7789_putrun(FAR struct lcd_dev_s *dev, DEBUGASSERT(buffer && ((uintptr_t)buffer & 1) == 0); st7789_setarea(priv, col, row, col + npixels - 1, row); - st7789_wrram(priv, buffer, npixels, 0, 1); + st7789_wrram(priv, buffer, npixels * ST7789_BYTESPP, 0, 1); return OK; } @@ -568,7 +569,7 @@ static int st7789_putarea(FAR struct lcd_dev_s *dev, FAR struct st7789_dev_s *priv = (FAR struct st7789_dev_s *)dev; size_t cols = col_end - col_start + 1; size_t rows = row_end - row_start + 1; - size_t row_size = cols * (priv->bpp >> 3); + size_t row_size = cols * ST7789_BYTESPP; ginfo("row_start: %d row_end: %d col_start: %d col_end: %d\n", row_start, row_end, col_start, col_end);