This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit aa718dcbac641ced672407535dcf5a56ec6dd939
Author: Yuichi Nakamura <y.512.nakam...@gmail.com>
AuthorDate: Tue Mar 16 00:32:54 2021 +0900

    lcd/st7789: X/Y offset and screen orientation support
---
 drivers/lcd/Kconfig  | 12 ++++++++++++
 drivers/lcd/st7789.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
 drivers/lcd/st7789.h |  1 +
 3 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/drivers/lcd/Kconfig b/drivers/lcd/Kconfig
index deb49e4..1d0dedb 100644
--- a/drivers/lcd/Kconfig
+++ b/drivers/lcd/Kconfig
@@ -607,6 +607,18 @@ if LCD_ST7789
                ---help---
                        Specifies the Y resolution of the LCD.
 
+       config LCD_ST7789_XOFFSET
+               int "ST7789 X Offset"
+               default 0
+               ---help---
+                       Specifies the X offset of the LCD.
+
+       config LCD_ST7789_YOFFSET
+               int "ST7789 Y Offset"
+               default 0
+               ---help---
+                       Specifies the Y offset of the LCD.
+
        config LCD_ST7789_BPP
                int "Bit Per Pixel (12 or 16)"
                default 16
diff --git a/drivers/lcd/st7789.c b/drivers/lcd/st7789.c
index bcce141..d756709 100644
--- a/drivers/lcd/st7789.c
+++ b/drivers/lcd/st7789.c
@@ -106,9 +106,13 @@
 #if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
 #  define ST7789_XRES       CONFIG_LCD_ST7789_YRES
 #  define ST7789_YRES       CONFIG_LCD_ST7789_XRES
+#  define ST7789_XOFFSET    CONFIG_LCD_ST7789_YOFFSET
+#  define ST7789_YOFFSET    CONFIG_LCD_ST7789_XOFFSET
 #else
 #  define ST7789_XRES       CONFIG_LCD_ST7789_XRES
 #  define ST7789_YRES       CONFIG_LCD_ST7789_YRES
+#  define ST7789_XOFFSET    CONFIG_LCD_ST7789_XOFFSET
+#  define ST7789_YOFFSET    CONFIG_LCD_ST7789_YOFFSET
 #endif
 
 /* Color depth and format */
@@ -174,6 +178,7 @@ static void st7789_deselect(FAR struct spi_dev_s *spi);
 
 static inline void st7789_sendcmd(FAR struct st7789_dev_s *dev, uint8_t cmd);
 static void st7789_sleep(FAR struct st7789_dev_s *dev, bool sleep);
+static void st7789_setorientation(FAR struct st7789_dev_s *dev);
 static void st7789_display(FAR struct st7789_dev_s *dev, bool on);
 static void st7789_setarea(FAR struct st7789_dev_s *dev,
                            uint16_t x0, uint16_t y0,
@@ -327,6 +332,42 @@ static void st7789_display(FAR struct st7789_dev_s *dev, 
bool on)
 }
 
 /****************************************************************************
+ * Name: st7789_setorientation
+ *
+ * Description:
+ *   Set screen orientation.
+ *
+ ****************************************************************************/
+
+static void st7789_setorientation(FAR struct st7789_dev_s *dev)
+{
+  /* No need to change the orientation in PORTRAIT mode */
+
+#if !defined(CONFIG_LCD_PORTRAIT)
+  st7789_sendcmd(dev, ST7789_MADCTL);
+  st7789_select(dev->spi, 8);
+
+#  if defined(CONFIG_LCD_RLANDSCAPE)
+  /* RLANDSCAPE : MY=1 MV=1 */
+
+  SPI_SEND(dev->spi, 0xa0);
+
+#  elif defined(CONFIG_LCD_LANDSCAPE)
+  /* LANDSCAPE : MX=1 MV=1 */
+
+  SPI_SEND(dev->spi, 0x70);
+
+#  elif defined(CONFIG_LCD_RPORTRAIT)
+  /* RPORTRAIT : MX=1 MY=1 */
+
+  SPI_SEND(dev->spi, 0xc0);
+#  endif
+
+  st7789_deselect(dev->spi);
+#endif
+}
+
+/****************************************************************************
  * Name: st7789_setarea
  *
  * Description:
@@ -342,16 +383,16 @@ static void st7789_setarea(FAR struct st7789_dev_s *dev,
 
   st7789_sendcmd(dev, ST7789_RASET);
   st7789_select(dev->spi, 16);
-  SPI_SEND(dev->spi, y0);
-  SPI_SEND(dev->spi, y1);
+  SPI_SEND(dev->spi, y0 + ST7789_YOFFSET);
+  SPI_SEND(dev->spi, y1 + ST7789_YOFFSET);
   st7789_deselect(dev->spi);
 
   /* Set column address */
 
   st7789_sendcmd(dev, ST7789_CASET);
   st7789_select(dev->spi, 16);
-  SPI_SEND(dev->spi, x0);
-  SPI_SEND(dev->spi, x1);
+  SPI_SEND(dev->spi, x0 + ST7789_XOFFSET);
+  SPI_SEND(dev->spi, x1 + ST7789_XOFFSET);
   st7789_deselect(dev->spi);
 }
 
@@ -671,6 +712,7 @@ FAR struct lcd_dev_s *st7789_lcdinitialize(FAR struct 
spi_dev_s *spi)
 
   st7789_sleep(priv, false);
   st7789_bpp(priv, ST7789_BPP);
+  st7789_setorientation(priv);
   st7789_display(priv, true);
   st7789_fill(priv, 0xffff);
 
diff --git a/drivers/lcd/st7789.h b/drivers/lcd/st7789.h
index b8bb0a8..3d205d0 100644
--- a/drivers/lcd/st7789.h
+++ b/drivers/lcd/st7789.h
@@ -46,6 +46,7 @@
 #define ST7789_RASET     0x2b   /* Row Address Set */
 #define ST7789_RAMWR     0x2c   /* Memory Write */
 #define ST7789_RAMRD     0x2e   /* Memory Read */
+#define ST7789_MADCTL    0x36   /* Memory Data Access Control */
 #define ST7789_IDMOFF    0x38   /* Idle Mode Off */
 #define ST7789_IDMON     0x39   /* Idle Mode On */
 #define ST7789_COLMOD    0x3a   /* Interface Pixel Format */

Reply via email to