Repository navigation
uCompute — ST7789 IPS Pitfall
The uCompute hardware ecosystem features an upgraded 240x240 pixels IPS display driven by the popular ST7789 controller. While this screen offers crisp rendering, wide viewing angles, and rich colors, generic 7-pin breakout modules introduce major architectural traps for embedded software developers.
This page explores how the uCompute custom ecosystem elegantly bypasses these hardware omissions via pure software adjustments.
The official uCompute display driver is built directly upon the excellent work of Russ Hughes and his st7789py_mpy MicroPython implementation.
While the original library features extensive support for rotation and hardware scrolling, it expects standard panels with direct software-configured color spaces. To streamline performance for the uCompute community and eliminate repetitive software-side color mapping overhead, a custom low-level hard patch was integrated into the rotation registers.
Standard, low-cost ST7789 modules designed for makers usually expose only 7 pins instead of the standard 8-pin SPI interface layout. They introduce two distinct challenges:
Most modules omit the physical CS pin to reduce size and cost, permanently tying the controller's internal CS gate to GND (logic LOW).
- The Pitfall: In normal SPI communications (SPI Mode 0), data lines are sampled on the rising edge of the clock signal, and the CS line is cycled to synchronize the frame start. Without an actively toggling CS pin, the SPI controller can easily drop bits or lose frame synchronization permanently during fast, sequential operations.
Depending on the manufacturer's liquid crystal layer routing, the physical order of the sub-pixels can vary between Red-Green-Blue and Blue-Green-Red.
-
The Pitfall: When using standard MicroPython libraries, drawing a native
st7789.GREENcolor can accidentally output red or blue pixels. Handling this via a software conversion function adds massive CPU overhead, causing animations and framerates to lag heavily.
To guarantee fluid rendering and accurate colors without hardware modifications, uCompute implements two elegant software patches.
Since we cannot toggle a physical CS line to reset the internal state machine of the display, uCompute forces SPI Mode 3.
# Forcing SPI Mode 3 inside uCompute initialization
spi = SPI(0, baudrate=20000000, polarity=1, phase=1, bits=8, firstbit=SPI.MSB, ... )-
Why it works: In SPI Mode 3, the clock line (
SCK) remains at a logic HIGH level when idle, and data bits are captured on the falling edge. This shift in clock timing allows the internal ST7789 state machine to maintain perfect synchronization on continuous streaming data, completely compensating for the missing CS pin.
To resolve the inverted colors without slowing down the MicroPython framebuf runtime environment, the uCompute custom st7789.py driver patches the configuration at the hardware register level.
By modifying the D3 bit of the MADCTL (36h) register (Memory Data Access Control), we switch the screen's internal color map decoding from RGB to BGR dynamically during the display orientation setup:
# Hardware patched rotation matrix inside uCompute's st7789.py
# Forces D3='1' (0x08 bitwise flag) to fix inverted IPS panels out of the box
ROTATIONS = [0x08, 0x68, 0xc8, 0xa8]This structural tweak ensures that calling standard constants like st7789.GREEN maps immediately and perfectly to the panel's physical sub-pixels with zero CPU overhead, maximizing double-buffering performance with framebuf2.
Please note a minor routing difference regarding the uCompute Junior variant:
- On the standard uCompute and uCompute2, the BL (Backlight) pin of the ST7789 module is connected to GP6, allowing software-defined brightness dimming via PWM.
- On the uCompute Junior, the physical GP6 pin has been reassigned to drive the dedicated NeoPixel addressable LED connector. Consequently, the display's BL pin is hardwired directly to the 3.3V rail. The backlight will remain at full brightness whenever the board is powered on, and any software calls trying to manipulate
_ST7789_BLor control it via PWM will have no effect on this specific model.
When writing custom drivers or modifying existing code, always reference the official uCompute SPI0 mapping:
| Pin Name | RP2040 GPIO | Function | Note for Junior |
|---|---|---|---|
_ST7789_SCK |
GP2 | SPI0 Clock | Identical |
_ST7789_MOSI |
GP3 | SPI0 Master Out Slave In | Identical |
_ST7789_RESET |
GP4 | Hardware Reset (Active Low) | Identical |
_ST7789_DC |
GP5 | Data / Command Selection | Identical |
_ST7789_BL |
GP6 | Backlight Control / PWM Dimming | N/A (Hardwired to 3.3V) |