Skip to content
GG
All projects

Oct 2024 – Mar 2025

Low-Level LCD Driver for GC9203

A C++ driver for the GC9203 LCD written from the datasheet, using an 8-bit indexed framebuffer and partial refresh to cut RAM footprint nearly in half on an ESP8266.

ESP8266GC9203 LCDC++SPIAltium Designer
An ESP8266 on a breadboard driving the GC9203 panel, with spare panels beside it

Overview

A C++ driver for the GC9203 LCD controller, written from the datasheet with no graphics library, and tested on an ESP8266. It provides pixel, line, rectangle, and fill primitives on top of a compact framebuffer.

System diagram: ESP8266 driver stack with graphics API, framebuffer, partial refresh, colour LUT, and HSPI, wired by SCK, MOSI, CS, DC, and RST to the GC9203 controller and a 128 by 220 panel

Breakout board

I designed a small ESP8266 breakout board in Altium Designer, had it fabricated by JLCPCB, then assembled the modules and tested them with the driver.

Altium Designer layout of the ESP8266 breakout board: antenna keep-out at the top, module pads, R1 to R4, C1 and C2, and a 4-pin header

The boards back from JLCPCB: four bare boards and two assembled modules

Bring-up

Every SPI word is 16 bits. With DC low, the word selects a register. With DC high, it writes that register’s value or pixel data.

SPI timing: a register write toggles CS for the index and data words, while a pixel burst holds CS low for many RGB565 words

The display stayed blank on the first attempt. A logic analyzer on SCK, MOSI, CS, and DC showed the command timing and framing did not match the datasheet. I fixed the initialization sequence by comparing the captures with the datasheet’s timing diagrams.

Address window

The GC9203 addresses 176 columns, and the 128-pixel panel sits in the middle. Every column written gets a base offset of 24. Rotation changes the entry mode and swaps x and y in the window.

GRAM window: the 128-column panel occupies hardware columns 24 to 151 of a 176-column address space, with the SC, EC, SP, and EP registers

Saving RAM

A full RGB565 framebuffer was too large for the ESP8266. Instead, each pixel is one byte: a 7-bit colour index plus a dirty flag. A 256-entry lookup table expands the colour to RGB565 on the way out. display() skips clean rows using a 28-byte bitmap and sends each dirty run as one window and one burst. This cut RAM from 56.3 KB (128 × 220 × 2 B) to 28.7 KB (28,160 B framebuffer + 512 B LUT + 28 B bitmap), a 49% reduction.

Partial refresh: byte layout with a dirty bit, a row bitmap, and dirty runs merged when gaps are short and split when longer than 12 pixels

Register map

Every register the driver writes, for reference.

RegNameValuePurpose
FEh, FFhVendor unlocknoneSent first, before any other register
01hDriver output control0x001COutput setup, from the datasheet
03hEntry mode0x1000 to 0x1018GRAM write direction, set per rotation
05hSPI 2-data0x0000Single-line SPI
07hDisplay control 10x0013Display on, written last
08hDisplay control 20x0404Front and back porch
0FhOscillator control0x0701Oscillator setup
10hPower control 10x0000Exit standby
11hPower control 20x1000Auto boost, then wait 120 ms
30hGate scan control0x0000Gate scan setup
36h to 39hWindow EC, SC, EP, SPper drawGRAM address window
22hGRAM writenonePixel data follows

Power-up order: reset low 10 ms, high 120 ms, unlock, configure, power on, wait 120 ms, display on.