CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
CHGfx library

Wire-speed ST7735 graphics: a 16-colour framebuffer, DMA flushes, sprites, shapes, text and fonts. More...

Modules

 Configuration
 Screen geometry, the panel's wiring, colour modes and SPI dividers: the build options and the constants they define.
 
 Setup
 Starting the panel and changing its SPI clock, colour mode, orientation and scan rate.
 
 Palette
 The 16 colours the framebuffer's indices stand for, and a fade applied on top of them.
 
 Presenting the framebuffer
 Sending the framebuffer to the panel: whole or a rectangle, blocking or by DMA in the background, and waiting for it.
 
 Direct streaming
 Full-colour procedural frames computed straight into the DMA's buffers, with no framebuffer and no palette.
 
 Drawing
 The clip rectangle, pixels, lines, rectangles, circles and sprite blits, drawn into the 4 bpp framebuffer.
 
 Shapes
 Rounded rectangles, ellipses, dithered fills and in-place recolouring.
 
 Span sprites
 The compact run-length sprite format (sprite4): plain, scaled, recoloured and rotated.
 
 Row operations
 Scrolling and stamping whole framebuffer rows at word speed.
 
 Text
 Text in the built-in 5x7 font or any GFXfont: plain, scaled, measured, and outlined/shadowed banners.
 
 Fonts
 The bundled fonts in src/fonts/, the GFXfont format they use, and the built-in 5x7.
 
 Direct to the panel
 Talking to the ST7735 without the framebuffer: chip select, commands, address windows, DMA fills and raw blits.
 
 Internals and scratch
 The converters the Benchmark example measures, the flush's chunk buffers as scratch memory, and the frame size.
 
 The Gfx object
 The CHGfx class and its one instance, Gfx: the same API with Arduino-style names.
 
 Adafruit_GFX bridge
 CHGfx_GFX: an Adafruit_GFX whose drawing lands in CHGfx's framebuffer, from CHGfx_AdafruitGFX.h (needs the Adafruit GFX Library).
 

Detailed Description

Wire-speed ST7735 graphics: a 16-colour framebuffer, DMA flushes, sprites, shapes, text and fonts.

#include <CHGfx.h>
CHGfx: a maximum-throughput ST7735 driver for the CHGame board (CH32X035G8U6 @ 48 MHz,...

CHGfx drives the 128x128 ST7735S panel on SPI1 with DMA. It keeps a 4 bpp (16-colour) framebuffer of 8 KB in SRAM and expands it through a palette to the panel's 12 or 16 bpp while the DMA is already sending it, so a full frame goes out at 90 fps (16 bpp) or 119 fps (12 bpp). CHGame is built on it, and a sketch that includes CHGame.h has all of CHGfx too.

Everything is a plain C function (gfx_clear(), gfx_flushAsync() ...); the CHGfx class and its one instance Gfx are zero-cost forwarders for those who prefer Gfx.clear(0).

gfx_setPaletteEntry(1, gfx_rgb(255, 255, 255));
gfx_text(4, 4, "Hello", 1);
@ GFX_DIV2
HCLK/2 = 24 MHz: the fastest the chip can clock SPI, and the default.
Definition CHGfx.h:232
@ GFX_12BPP
ST7735 COLMOD 0x03, RGB444, 1.5 bytes/px -> 119 fps.
Definition CHGfx.h:220
void gfx_clear(uint8_t c)
Fills the clip rectangle (normally the whole screen) with one colour.
void gfx_setPaletteEntry(uint8_t index, uint16_t rgb565)
Sets one palette entry.
static uint16_t gfx_rgb(uint8_t r, uint8_t g, uint8_t b)
Packs an 8-bit-per-channel colour into RGB565.
Definition CHGfx.h:456
void gfx_flush(void)
Sends the whole framebuffer to the panel and returns when it has gone out.
static void gfx_begin(uint8_t spiDiv=GFX_DIV2, uint8_t colorMode=GFX_16BPP)
Starts the panel: pins, SPI1, DMA, a hardware reset and the ST7735 initialisation,...
Definition CHGfx.h:308
void gfx_text(int x, int y, const char *s, uint8_t c)
Draws a string in the current font.

The rule that matters: drawing goes into the framebuffer, and the framebuffer is free to draw into only after gfx_wait() (or gfx_waitRow()), once the previous flush has finished reading it.

See also
The library's README (performance, the simulator, configuration and what everything costs), FONTS.md