drivers/lcd: Add GC9A01 driver and refine ST7735

Added custom resolution, offset and BGR mode for ST7735 driver
Added GC9A01 driver (based on ST7789 driver)

Signed-off-by: Peter Bee <bijunda1@xiaomi.com>
This commit is contained in:
Peter Bee
2021-09-16 11:55:39 +08:00
committed by Alan Carvalho de Assis
parent 2a8b076b38
commit a5406c63cb
7 changed files with 1185 additions and 21 deletions
+92 -5
View File
@@ -569,12 +569,52 @@ config LCD_ST7735
default n
if LCD_ST7735
config LCD_ST7735_GM00
bool "132x162 Display Resolution"
choice
prompt "LCD Preset Resolutions"
optional
config LCD_ST7735_GM11
bool "128x160"
config LCD_ST7735_GM00
bool "132x162"
config LCD_ST7735_GM01
bool "132x132"
endchoice
if !LCD_ST7735_GM00 && !LCD_ST7735_GM01 && !LCD_ST7735_GM11
config LCD_ST7735_XRES
int "ST7735 X Resolution"
default 128
---help---
Specifies the X resolution of the LCD.
config LCD_ST7735_YRES
int "ST7735 Y Resolution"
default 160
---help---
Specifies the Y resolution of the LCD.
config LCD_ST7735_XOFFSET
int "ST7735 X Offset"
default 0
---help---
Specifies the X offset of the LCD.
config LCD_ST7735_YOFFSET
int "ST7735 Y Offset"
default 0
---help---
Specifies the Y offset of the LCD.
endif
config LCD_ST7735_BGR
bool "Swap R & B channel"
default n
---help---
Two resolutions are available, either the 132x162 or
the 128x160
config LCD_ST7735_BPP
int "Bit Per Pixel (12, 16 or 18)"
@@ -633,6 +673,53 @@ if LCD_ST7789
endif # LCD_ST7789
config LCD_GC9A01
bool "Galaxycore GC9A01 TFT Controller"
default n
if LCD_GC9A01
config LCD_GC9A01_XRES
int "GC9A01 X Resolution"
default 240
---help---
Specifies the X resolution of the LCD.
config LCD_GC9A01_YRES
int "GC9A01 Y Resolution"
default 240
---help---
Specifies the Y resolution of the LCD.
config LCD_GC9A01_XOFFSET
int "GC9A01 X Offset"
default 0
---help---
Specifies the X offset of the LCD.
config LCD_GC9A01_YOFFSET
int "GC9A01 Y Offset"
default 0
---help---
Specifies the Y offset of the LCD.
config LCD_GC9A01_BGR
bool "Swap R & B channel"
default n
config LCD_GC9A01_BPP
int "Bit Per Pixel (12 or 16)"
default 16
config LCD_GC9A01_SPIMODE
int "SPI Mode"
default 0
config LCD_GC9A01_FREQUENCY
int "SPI Frequency"
default 1000000
endif # LCD_GC9A01
config LCD_PCD8544
bool "Nokia 5110 LCD Display (Philips PCD8544)"
default n
+4
View File
@@ -133,6 +133,10 @@ ifeq ($(CONFIG_LCD_ST7789),y)
CSRCS += st7789.c
endif
ifeq ($(CONFIG_LCD_GC9A01),y)
CSRCS += gc9a01.c
endif
endif # CONFIG_LCD
ifeq ($(CONFIG_SLCD),y)
File diff suppressed because it is too large Load Diff
+71
View File
@@ -0,0 +1,71 @@
/****************************************************************************
* drivers/lcd/gc9a01.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __DRIVERS_LCD_GC9A01_H
#define __DRIVERS_LCD_GC9A01_H
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define GC9A01_NOP 0x00 /* No Operation */
#define GC9A01_SWRESET 0x01 /* Software Reset */
#define GC9A01_RDDID 0x04 /* Read Display ID */
#define GC9A01_RDDST 0x09 /* Read Display Status */
#define GC9A01_SLPIN 0x10 /* Sleep In & Booster Off */
#define GC9A01_SLPOUT 0x11 /* Sleep Out & Booster On */
#define GC9A01_PTLON 0x12 /* Partial Mode On */
#define GC9A01_NORON 0x13 /* Partial Mode Off */
#define GC9A01_INVOFF 0x20 /* Display Inversion Off */
#define GC9A01_INVON 0x21 /* Display Inversion On */
#define GC9A01_DISPOFF 0x28 /* Display Off */
#define GC9A01_DISPON 0x29 /* Display On */
#define GC9A01_CASET 0x2a /* Column Address Set */
#define GC9A01_RASET 0x2b /* Row Address Set */
#define GC9A01_RAMWR 0x2c /* Memory Write */
#define GC9A01_RAMRD 0x2e /* Memory Read */
#define GC9A01_PTLAR 0x30 /* Partial Area */
#define GC9A01_VSCRDEF 0x33 /* Vertical Scrolling Definition */
#define GC9A01_TEON 0x35 /* Tering Effect Line On */
#define GC9A01_MADCTL 0x36 /* Memory Data Access Control */
#define GC9A01_MADCTL_MY (1<<7) /* Page Address Order */
#define GC9A01_MADCTL_MX (1<<6) /* Column Address Order */
#define GC9A01_MADCTL_MV (1<<5) /* Page/Column Order */
#define GC9A01_MADCTL_ML (1<<4) /* Line Address Order */
#define GC9A01_MADCTL_BGR (1<<3) /* Set Panel Order BGR */
#define GC9A01_MADCTL_MH (1<<2) /* Display Data Latch Order */
#define GC9A01_VSCSAD 0x37 /* Vertical Scrolling Start Address */
#define GC9A01_IDMOFF 0x38 /* Idle Mode Off */
#define GC9A01_IDMON 0x39 /* Idle Mode On */
#define GC9A01_COLMOD 0x3a /* Interface Pixel Format */
#define GC9A01_ENIREG1 0xFE /* Enable internal register 1 */
#define GC9A01_ENIREG2 0xEF /* Enable internal register 2 */
#endif /* __DRIVERS_LCD_GC9A01_H */
+79 -16
View File
@@ -45,6 +45,8 @@
* Pre-processor Definitions
****************************************************************************/
#define MAX(a,b) ((a)>(b)?(a):(b))
/* Verify that all configuration requirements have been met */
#ifndef CONFIG_LCD_ST7735_SPIMODE
@@ -94,24 +96,37 @@
/* Display Resolution */
#ifdef CONFIG_LCD_ST7735_GM00
# define CONFIG_ST7735_XRES 132
# define CONFIG_ST7735_YRES 162
# define ST7735_LUT_SIZE 162
#else
# define CONFIG_ST7735_XRES 128
# define CONFIG_ST7735_YRES 160
# define ST7735_LUT_SIZE 160
#if defined(CONFIG_LCD_ST7735_GM00)
# define CONFIG_LCD_ST7735_XRES 132
# define CONFIG_LCD_ST7735_YRES 162
# define CONFIG_LCD_ST7735_XOFFSET 0
# define CONFIG_LCD_ST7735_YOFFSET 0
#elif defined(CONFIG_LCD_ST7735_GM01)
# define CONFIG_LCD_ST7735_XRES 132
# define CONFIG_LCD_ST7735_YRES 132
# define CONFIG_LCD_ST7735_XOFFSET 0
# define CONFIG_LCD_ST7735_YOFFSET 0
#elif defined(CONFIG_LCD_ST7735_GM11)
# define CONFIG_LCD_ST7735_XRES 128
# define CONFIG_LCD_ST7735_YRES 160
# define CONFIG_LCD_ST7735_XOFFSET 0
# define CONFIG_LCD_ST7735_YOFFSET 0
#endif
#if defined(CONFIG_LCD_LANDSCAPE) || defined(CONFIG_LCD_RLANDSCAPE)
# define ST7735_XRES CONFIG_ST7735_YRES
# define ST7735_YRES CONFIG_ST7735_XRES
# define ST7735_XRES CONFIG_LCD_ST7735_YRES
# define ST7735_YRES CONFIG_LCD_ST7735_XRES
# define ST7735_XOFFSET CONFIG_LCD_ST7735_YOFFSET
# define ST7735_YOFFSET CONFIG_LCD_ST7735_XOFFSET
#else
# define ST7735_XRES CONFIG_ST7735_XRES
# define ST7735_YRES CONFIG_ST7735_YRES
# define ST7735_XRES CONFIG_LCD_ST7735_XRES
# define ST7735_YRES CONFIG_LCD_ST7735_YRES
# define ST7735_XOFFSET CONFIG_LCD_ST7735_XOFFSET
# define ST7735_YOFFSET CONFIG_LCD_ST7735_YOFFSET
#endif
#define ST7735_LUT_SIZE MAX(CONFIG_LCD_ST7735_XRES, CONFIG_LCD_ST7735_YRES)
/* Color depth and format */
#ifdef CONFIG_LCD_ST7735_BPP
@@ -180,6 +195,7 @@ static void st7735_deselect(FAR struct spi_dev_s *spi);
static inline void st7735_sendcmd(FAR struct st7735_dev_s *dev, uint8_t cmd);
static void st7735_sleep(FAR struct st7735_dev_s *dev, bool sleep);
static void st7735_display(FAR struct st7735_dev_s *dev, bool on);
static void st7735_setorientation(FAR struct st7735_dev_s *dev);
static void st7735_setarea(FAR struct st7735_dev_s *dev,
uint16_t x0, uint16_t y0,
uint16_t x1, uint16_t y1);
@@ -328,6 +344,52 @@ static void st7735_display(FAR struct st7735_dev_s *dev, bool on)
st7735_sendcmd(dev, on ? ST7735_DISPON : ST7735_DISPOFF);
}
/****************************************************************************
* Name: st7735_setorientation
*
* Description:
* Set screen orientation.
*
****************************************************************************/
static void st7735_setorientation(FAR struct st7735_dev_s *dev)
{
/* No need to change the orientation in PORTRAIT mode and RGB panel */
#if !defined(CONFIG_LCD_PORTRAIT) || defined(CONFIG_LCD_ST7735_BGR)
uint8_t reg = 0x00;
st7735_sendcmd(dev, ST7735_MADCTL);
st7735_select(dev->spi, 8);
# if defined(CONFIG_LCD_RLANDSCAPE)
/* RLANDSCAPE : MY=1 MV=1 */
reg = ST7735_MADCTL_MY | ST7735_MADCTL_MV;
# elif defined(CONFIG_LCD_LANDSCAPE)
/* LANDSCAPE : MX=1 MV=1 */
reg = ST7735_MADCTL_MX | ST7735_MADCTL_MV;
# elif defined(CONFIG_LCD_RPORTRAIT)
/* RPORTRAIT : MX=1 MY=1 */
reg = ST7735_MADCTL_MX | ST7735_MADCTL_MY;
# endif
# if defined(CONFIG_LCD_ST7735_BGR)
reg |= ST7735_MADCTL_BGR;
# endif
SPI_SEND(dev->spi, reg);
st7735_deselect(dev->spi);
#endif
}
/****************************************************************************
* Name: st7735_setarea
*
@@ -344,16 +406,16 @@ static void st7735_setarea(FAR struct st7735_dev_s *dev,
st7735_sendcmd(dev, ST7735_RASET);
st7735_select(dev->spi, 16);
SPI_SEND(dev->spi, y0);
SPI_SEND(dev->spi, y1);
SPI_SEND(dev->spi, y0 + ST7735_YOFFSET);
SPI_SEND(dev->spi, y1 + ST7735_YOFFSET);
st7735_deselect(dev->spi);
/* Set column address */
st7735_sendcmd(dev, ST7735_CASET);
st7735_select(dev->spi, 16);
SPI_SEND(dev->spi, x0);
SPI_SEND(dev->spi, x1);
SPI_SEND(dev->spi, x0 + ST7735_XOFFSET);
SPI_SEND(dev->spi, x1 + ST7735_XOFFSET);
st7735_deselect(dev->spi);
}
@@ -671,6 +733,7 @@ FAR struct lcd_dev_s *st7735_lcdinitialize(FAR struct spi_dev_s *spi)
st7735_sleep(priv, false);
st7735_bpp(priv, ST7735_BPP);
st7735_setorientation(priv);
st7735_display(priv, true);
st7735_fill(priv, 0xffff);
+11
View File
@@ -46,8 +46,19 @@
#define ST7735_RASET 0x2b /* Row Address Set */
#define ST7735_RAMWR 0x2c /* Memory Write */
#define ST7735_RAMRD 0x2e /* Memory Read */
#define ST7735_MADCTL 0x36 /* Memory Data Access Control */
#define ST7735_MADCTL_MY (1<<7) /* Page Address Order */
#define ST7735_MADCTL_MX (1<<6) /* Column Address Order */
#define ST7735_MADCTL_MV (1<<5) /* Page/Column Order */
#define ST7735_MADCTL_ML (1<<4) /* Line Address Order */
#define ST7735_MADCTL_BGR (1<<3) /* Set Panel Order BGR */
#define ST7735_MADCTL_MH (1<<2) /* Display Data Latch Order */
#define ST7735_IDMOFF 0x38 /* Idle Mode Off */
#define ST7735_IDMON 0x39 /* Idle Mode On */
#define ST7735_COLMOD 0x3a /* Interface Pixel Format */
FAR struct lcd_dev_s *st7735_lcdinitialize(FAR struct spi_dev_s *spi);
#endif /* __DRIVERS_LCD_ST7735_H */
+72
View File
@@ -0,0 +1,72 @@
/****************************************************************************
* include/nuttx/lcd/gc9a01.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_GC9A01_H
#define __INCLUDE_NUTTX_GC9A01_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdbool.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
extern "C"
{
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: gc9a01_initialize
*
* Description:
* Initialize the GC9A01 video hardware. The initial state of the
* LCD is fully initialized, display memory cleared, and the LCD ready
* to use, but with the power setting at 0 (full off == sleep mode).
*
* Returned Value:
*
* On success, this function returns a reference to the LCD object for
* the specified LCD. NULL is returned on any failure.
*
****************************************************************************/
FAR struct lcd_dev_s *gc9a01_lcdinitialize(FAR struct spi_dev_s *spi);
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_NUTTX_GC9A01_H */