- Name: GC9D01N
- Author: Gavin Lyons
- Description:
C++ library for a TFT SPI LCD, GC9D01N Driver.
GC9D01N is a 262,144-color single-chip SOC driver for a-TFT liquid crystal display with resolution of 160RGBx160 dots, comprising a 240-channel source driver, a 32-channel gate driver, 57,600 bytes GRAM for graphic display data of 160RGBx160 dots, and power supply circuit.
- Dynamic install-able Linux C++ library.
- Power modes, Invert, Scroll, Rotate supported.
- Hardware & software SPI
- Tested on 160x160 Round Display also tested by third party on 40x160 bar display by third party.
- Raspberry Pi PICO C++ SDK eco-system library.
- 16 ASCII fonts included, fonts can easily be removed or added.
- 24 bit colour , 16 bit color, bi-color Bitmaps & sprites su
- Dependency: lgpio Library
- NB The Spidev buffer size setting must be larger than biggest buffer the code will attempt to write If not you will get 'Error 99'. See Notes section for more details.
- Make sure SPI is enabled in your computers configuration.
In the example files. There are sections in "Setup()" function where user can make adjustments to select for SPI type used, and screen size.
- USER OPTION 1 GPIO/SPI TYPE
- USER OPTION 2 SCREEN SECTION
- USER OPTION 3 SPI SETTINGS
This library supports both Hardware SPI and software SPI. The SetupGPIO function is overloaded(2 off one for HW SPI the other for SW SPI). The parameters set for SetupGPIO define which is used.
There are options here user can adjust:
- 2A screen pixel height
- 2B screen pixel width
- 2C Resolution and gate type.
- 2D screen pixel X offset
- 2E screen Pixel Y offset
USER OPTION 2C- Resolution & Gate Configuration (Resolution_e)
The GC9D01 controller supports multiple display sizes and gate driving modes. Select the correct enum value for your physical module. In addition to passing the parameter.
| Enum Value | Resolution | Gate Mode | Typical Module Description |
|---|---|---|---|
RGB160x160_DualGate |
160×160 | Dual | Most round GC9D01 displays Default |
RGB120x160_DualGate |
120×160 | Dual | Some rectangular / bar-type modules |
RGB80x160_SingleGate |
80×160 | Single | Smaller rectangular / bar displays |
RGB40x160_SingleGate |
40×160 | Single | Very narrow bar-type or specialty modules |
On some displays an offset is required, I made this a user input rather than hard-coded due to diversity of variant modules available.
| Display type | X offset | Y offset | Notes |
|---|---|---|---|
160x160 Dual Gate |
0 | 0 | No offsets required in any rotation. Default |
120x160 Dual Gate |
TBD | TBD | Expected to require centering offsets (~20 px) depending on rotation. Not hardware tested. |
80x160 Single Gate |
TBD | TBD | Expected to require centering offsets (~40 px) depending on rotation. Not hardware tested. |
40x160 Single Gate |
-60 | 60 | Tested. Offsets required for 90° and 270° rotations due to centered 40-pixel active area. |
InitSPI function is overloaded(2 off, one for HW SPI the other for SW SPI).
| parameter | default value | note | SPi type |
|---|---|---|---|
| HWSPI_DEVICE | 0 | A SPI device, >= 0. which SPI interface to use , ls /dev/spi* | Hardware |
| HWSPI_CHANNEL | 0 | A SPI channel, >= 0. Which Chip enable pin to use usually 0 or 1 | Hardware |
| HWSPI_SPEED | 1000000 | The speed of serial communication in bits per second. | Hardware |
| HWSPI_FLAGS | 0 | mode 0 for this device | Hardware |
| GPIO_CHIP_DEVICE | 0 | gpio chip device >= 0, check ls/dev/gpiochip* | both |
| SWSPI_CommDelay | 0 | uS delay for GPIO | software |
The user can adjust if having reliability issues with SW SPI in some setups. This is a microsecond delay in SW SPI GPIO loop. It is set to 0 by default, Increasing it will slow down SW SPI further.
In example folder: The main.cpp file contains tests showing library functions. A bitmap data file contains data for bi-color bitmaps and icons tests. The color bitmaps used in testing are in bitmap folder.
| # | example file name | Description |
|---|---|---|
| 1 | hello_world | Basic use case |
| 2 | tests | bitmap, text,graphics & function testing |
| 3 | demos | Various demos |
The Hello_world has an option to switch between hardware and software spi. It also has a ''USER SCREEN TYPE SECTION'' where user can switch between
- 160X160 Dual gate display test
- 40X160 single gate display test
Note: All examples for GC9D01 are for Advanced Screen Buffer Mode. Advanced buffer mode must be enabled for these examples to work. This mode is non-default. This is done in examples by: function SetupBufferMode().
Some examples of memory usage for the frame buffer used in advanced buffer mode for selected display sizes.
| Display size | bytes |
|---|---|
| 40x160x2 | 12800 |
| 160x160x2 | 51200 |
These class functions will return an error code in event of error see API for more details.
For functions that accept a 16 bit color value. There is list of pre-defined colors in the 'colors' folder in doc.
Advanced screen buffer mode. There is advanced buffer mode where the code writes to a global screen buffer instead of the VRAM of display. It is off by default more details at readme, which is in the 'doc' folder at link.
Connections as setup in main.cpp test file.
| TFT PinNum | Pindesc | RPI HW SPI | RPI SW SPI |
|---|---|---|---|
| 1 | LED | VCC | VCC |
| 2 | CS | SPI_CE0 | GPI21 |
| 3 | DC | GPIO24 | GPIO24 |
| 4 | RESET | GPI025 | GPIO25 |
| 5 | SDA | SPI_MOSI | GPIO16 |
| 6 | SCLK | SPI_CLK | GPIO20 |
| 7 | VCC | VCC | VCC |
| 8 | GND | GND | GND |
- This is a 3.3V logic device do NOT connect the I/O logic lines to 5V logic device.
- SW SPI pick any GPIO you like , HW SPI CEX, SCLK and SDA will be tied to SPI interface.
- Backlight on/off control is left to user.
160x160 Round Display:
40x160 Bar Display:


