![]() |
CHGame 0.3.0
Libraries for the CHGame handheld
|
Starting the panel and changing its SPI clock, colour mode, orientation and scan rate. More...
Functions | |
| 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, then a default 16-colour palette. | |
| void | gfx_setSpiDiv (uint8_t div) |
| Changes the SPI clock divider, and sets SPI1 up afresh for the panel. | |
| void | gfx_setColorMode (uint8_t mode) |
| Switches the panel's colour output mode. | |
| uint8_t | gfx_colorMode (void) |
| The current colour output mode. | |
| uint8_t | gfx_spiDiv (void) |
| The current SPI clock divider. | |
| uint32_t | gfx_spiHz (void) |
| The current SPI clock. | |
| void | gfx_setPanelOffsets (uint8_t madctl, uint8_t colStart, uint8_t rowStart) |
| Sets the panel's orientation (MADCTL) and the offsets of the visible window in its memory. | |
| void | gfx_setInverted (bool on) |
| Turns the panel's colour inversion (INVON / INVOFF) on or off. | |
| void | gfx_setPanelFrameRate (uint8_t rtna, uint8_t fpa, uint8_t bpa) |
| Sets the panel's own refresh rate (ST7735 FRMCTR1, 0xB1). | |
Starting the panel and changing its SPI clock, colour mode, orientation and scan rate.
Starts the panel: pins, SPI1, DMA, a hardware reset and the ST7735 initialisation, then a default 16-colour palette.
Call it once in setup(). It takes about 0.7 s (the panel's reset and wake-up delays). It parks the SD card's chip select high (unless CHGFX_NO_SD_PARK), selects the colour mode and, in 12 bpp, programs the panel's colour LUT (gfx_writeColorLut()). The framebuffer is not touched and nothing is sent to the glass until the first flush.
gfx_begin() picks one of two starts. A sketch that names GFX_12BPP and never calls gfx_setColorMode() gets the 12 bpp-only start, and the 16 and 18 bpp converters and tables stay out of its image (0.2-0.4 KB of flash, 176 B of it SRAM code). Any other mode, or one only known when it runs, gets the general start, which keeps all three.
| spiDiv | SPI clock divider: GFX_DIV2 (24 MHz, the default), GFX_DIV4, GFX_DIV8 or GFX_DIV16. |
| colorMode | GFX_16BPP (the default), GFX_12BPP or GFX_18BPP. |
| void gfx_setSpiDiv | ( | uint8_t | div | ) |
Changes the SPI clock divider, and sets SPI1 up afresh for the panel.
Waits for any flush in flight first, then programs all of SPI1 as gfx_begin() does (its clock on, master, mode 0, MSB first, this divider). That makes it the way to hand SPI1 back to CHGfx after anything else used it, such as the Arduino SPI class:
| div | GFX_DIV2, GFX_DIV4, GFX_DIV8 or GFX_DIV16 (32 also works); any other value runs at HCLK/2. |
| void gfx_setColorMode | ( | uint8_t | mode | ) |
Switches the panel's colour output mode.
Waits for any flush in flight, sends the panel its new COLMOD (and the colour LUT when entering 12 bpp), and rebuilds the palette table for the next flush. Does nothing if the mode is already set.
| mode | GFX_16BPP, GFX_12BPP or GFX_18BPP. |
| uint8_t gfx_colorMode | ( | void | ) |
The current colour output mode.
| uint8_t gfx_spiDiv | ( | void | ) |
The current SPI clock divider.
| uint32_t gfx_spiHz | ( | void | ) |
The current SPI clock.
| void gfx_setPanelOffsets | ( | uint8_t | madctl, |
| uint8_t | colStart, | ||
| uint8_t | rowStart | ||
| ) |
Sets the panel's orientation (MADCTL) and the offsets of the visible window in its memory.
MADCTL / window offsets differ between 1.44" panel batches. Defaults match Adafruit's INITR_144GREENTAB (madctl 0xC8, colstart 2, rowstart 3), which is what an Adafruit_ST7735 setup is already using. Change them if the image is offset or mirrored. Sends MADCTL at once, so call it after gfx_wait().
| madctl | ST7735 MADCTL (36h) value: rotation, mirroring, RGB/BGR. |
| colStart | First visible column of the panel's memory. |
| rowStart | First visible row of the panel's memory. |
| void gfx_setInverted | ( | bool | on | ) |
Turns the panel's colour inversion (INVON / INVOFF) on or off.
Sends the command at once, so call it after gfx_wait().
| on | true to invert every colour, false for normal. |
| void gfx_setPanelFrameRate | ( | uint8_t | rtna, |
| uint8_t | fpa, | ||
| uint8_t | bpa | ||
| ) |
Sets the panel's own refresh rate (ST7735 FRMCTR1, 0xB1).
Lower values scan the glass faster, which cuts the latency between a GRAM write and the pixel actually changing. The panel's rate is 850 kHz / ((RTNA*2 + 40) * (lines + FPA + BPA)). Defaults to the fast setting 0x05, 0x3A, 0x3A (Adafruit's is a lazy ~60 Hz 0x01, 0x2C, 0x2D). Waits for any flush in flight first.
| rtna | RTNA, the line period. |
| fpa | Front porch, in lines. |
| bpa | Back porch, in lines. |