CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
Direct to the panel

Talking to the ST7735 without the framebuffer: chip select, commands, address windows, DMA fills and raw blits. More...

Functions

void gfx_select (void)
 Asserts the panel's chip select.
 
void gfx_deselect (void)
 Waits for the last byte to leave SPI1, then releases the panel's chip select.
 
void gfx_setWindow (uint8_t x, uint8_t y, uint8_t w, uint8_t h)
 Sets the panel's address window and starts a memory write (CASET, RASET, RAMWR).
 
void gfx_cmd (uint8_t c)
 Sends one command byte (D/C low), then sets D/C back to data.
 
void gfx_data8 (uint8_t d)
 Sends one data byte (D/C high).
 
void gfx_writeColorLut (void)
 Programs the ST7735 RGBSET (2Dh) colour-depth conversion LUT for the current mode.
 
void gfx_setWriteColorLut (bool on)
 Chooses whether entering 12 bpp writes the colour LUT (gfx_writeColorLut()).
 
void gfx_directFillRect (uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t rgb565)
 Fills a rectangle of the panel with one colour by DMA, bypassing the framebuffer.
 
void gfx_directBlit (const void *data, uint32_t bytes, bool halfword)
 Sends a caller-owned buffer, already in panel format, by DMA and waits for it.
 
void gfx_blockingWrite (const uint8_t *data, uint32_t bytes)
 Sends bytes one at a time in a polled loop, for baseline comparisons.
 

Detailed Description

Talking to the ST7735 without the framebuffer: chip select, commands, address windows, DMA fills and raw blits.

These write to the panel at once, so call them only when no flush is in flight (after gfx_wait()); the SD card shares the bus too. Raw pixel data must already be in the panel's current format.

gfx_setWindow(0, 0, 32, 32);
gfx_directBlit(pixels565, 32 * 32 * 2, true);
void gfx_select(void)
Asserts the panel's chip select.
void gfx_deselect(void)
Waits for the last byte to leave SPI1, then releases the panel's chip select.
void gfx_directBlit(const void *data, uint32_t bytes, bool halfword)
Sends a caller-owned buffer, already in panel format, by DMA and waits for it.
void gfx_setWindow(uint8_t x, uint8_t y, uint8_t w, uint8_t h)
Sets the panel's address window and starts a memory write (CASET, RASET, RAMWR).
void gfx_wait(void)
Waits until the flush in flight, if any, has finished.

Function Documentation

◆ gfx_select()

void gfx_select ( void  )

Asserts the panel's chip select.

Assert once, stream a whole frame, deassert - that is the entire performance thesis of this driver in two functions. The panel latches nothing while CS is high.

◆ gfx_deselect()

void gfx_deselect ( void  )

Waits for the last byte to leave SPI1, then releases the panel's chip select.

◆ gfx_setWindow()

void gfx_setWindow ( uint8_t  x,
uint8_t  y,
uint8_t  w,
uint8_t  h 
)

Sets the panel's address window and starts a memory write (CASET, RASET, RAMWR).

Pixel data sent after it fills the window left to right, top to bottom. The panel offsets (gfx_setPanelOffsets()) are added; nothing is clipped. Needs gfx_select() first.

Parameters
xLeft edge, in screen pixels.
yTop edge, in screen pixels.
wWidth in pixels, 1 or more.
hHeight in pixels, 1 or more.

◆ gfx_cmd()

void gfx_cmd ( uint8_t  c)

Sends one command byte (D/C low), then sets D/C back to data.

Parameters
cST7735 command.

◆ gfx_data8()

void gfx_data8 ( uint8_t  d)

Sends one data byte (D/C high).

Parameters
dThe byte.

◆ gfx_writeColorLut()

void gfx_writeColorLut ( void  )

Programs the ST7735 RGBSET (2Dh) colour-depth conversion LUT for the current mode.

Done automatically for 12 bpp because the datasheet says the table powers up "Random"; call gfx_setWriteColorLut(false) before gfx_setColorMode() if you would rather trust the factory contents.

◆ gfx_setWriteColorLut()

void gfx_setWriteColorLut ( bool  on)

Chooses whether entering 12 bpp writes the colour LUT (gfx_writeColorLut()).

Parameters
ontrue (the default) to write it, false to trust the panel's factory contents.

◆ gfx_directFillRect()

void gfx_directFillRect ( uint8_t  x,
uint8_t  y,
uint8_t  w,
uint8_t  h,
uint16_t  rgb565 
)

Fills a rectangle of the panel with one colour by DMA, bypassing the framebuffer.

DMA with memory-increment DISABLED: the DMA engine re-reads one halfword N times. Zero RAM, zero CPU, full wire speed. Waits for any flush in flight; handles chip select itself; not clipped.

Parameters
xLeft edge, in screen pixels.
yTop edge, in screen pixels.
wWidth in pixels.
hHeight in pixels.
rgb565The colour, in RGB565.
Warning
16 bpp only - a 12 bpp solid colour has a 3-byte repeat that does not fit in a single halfword.

◆ gfx_directBlit()

void gfx_directBlit ( const void *  data,
uint32_t  bytes,
bool  halfword 
)

Sends a caller-owned buffer, already in panel format, by DMA and waits for it.

Needs gfx_select() and gfx_setWindow() first.

Parameters
dataThe pixel data.
bytesIts length in bytes (even when halfword).
halfwordtrue to send 16-bit SPI frames (RGB565 as uint16_t, 16 bpp), false for bytes (12 and 18 bpp).

◆ gfx_blockingWrite()

void gfx_blockingWrite ( const uint8_t *  data,
uint32_t  bytes 
)

Sends bytes one at a time in a polled loop, for baseline comparisons.

Parameters
dataThe bytes.
bytesHow many.