Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
hdw-tft.c File Reference

Macros

#define SWAP(x)   ((x >> 8) | (x << 8))
 Swap the upper and lower bytes in a 16-bit word.
 
#define PARALLEL_LINES   16
 The number of parallel lines used in a SPI transfer.
 
#define LCD_BK_LIGHT_ON_LEVEL   1
 The GPIO level to turn the backlight on.
 
#define LCD_BK_LIGHT_OFF_LEVEL   0
 The GPIO level to turn the backlight off.
 
#define LCD_CMD_BITS   8
 The number of bits in an LCD control command.
 
#define LCD_PARAM_BITS   8
 The number of bits for an LCD control command's parameter.
 
#define NUM_S_LINES   2
 

Functions

esp_err_t setTFTBacklightBrightness (uint8_t intensity)
 Set TFT Backlight brightness. setTftBrightnessSetting() should be called instead if the new volume should be persistent through a reboot.
 
void initTFT (spi_host_device_t spiHost, gpio_num_t sclk, gpio_num_t mosi, gpio_num_t dc, gpio_num_t cs, gpio_num_t rst, gpio_num_t backlight, bool isPwmBacklight, ledc_channel_t ledcChannel, ledc_timer_t ledcTimer, uint8_t brightness)
 Initialize a TFT display and return it through a pointer arg.
 
void deinitTFT (void)
 Deinitialize the TFT display.
 
paletteColor_tgetPxTftFramebuffer (void)
 Return the pixel framebuffer, which is (TFT_WIDTH * TFT_HEIGHT) pixels in row order, starting from the top left. This can be used t directly modify individual pixels without calling setPxTft()
 
void disableTFTBacklight (void)
 Disable the backlight (for power down)
 
void enableTFTBacklight (void)
 Enable the backlight.
 
void setPxTft (int16_t x, int16_t y, paletteColor_t px)
 Set a single pixel in the display, with bounds check.
 
paletteColor_t getPxTft (int16_t x, int16_t y)
 Get a single pixel in the display.
 
void clearPxTft (void)
 Clear all pixels in the display to black.
 
void drawDisplayTft (fnBackgroundDrawCallback_t fnBackgroundDrawCallback)
 Send the current framebuffer to the TFT display over the SPI bus.
 

Variables

paletteColor_tpFrameBuffer = NULL
 

Macro Definition Documentation

◆ SWAP

#define SWAP ( x)    ((x >> 8) | (x << 8))

Swap the upper and lower bytes in a 16-bit word.

◆ PARALLEL_LINES

#define PARALLEL_LINES   16

The number of parallel lines used in a SPI transfer.

To speed up transfers, every SPI transfer sends a bunch of lines. This define specifies how many. More means more memory use, but less overhead for setting up and finishing transfers. Make sure TFT_HEIGHT is dividable by this.

◆ LCD_BK_LIGHT_ON_LEVEL

#define LCD_BK_LIGHT_ON_LEVEL   1

The GPIO level to turn the backlight on.

◆ LCD_BK_LIGHT_OFF_LEVEL

#define LCD_BK_LIGHT_OFF_LEVEL   0

The GPIO level to turn the backlight off.

◆ LCD_CMD_BITS

#define LCD_CMD_BITS   8

The number of bits in an LCD control command.

◆ LCD_PARAM_BITS

#define LCD_PARAM_BITS   8

The number of bits for an LCD control command's parameter.

◆ NUM_S_LINES

#define NUM_S_LINES   2

Function Documentation

◆ setTFTBacklightBrightness()

esp_err_t setTFTBacklightBrightness ( uint8_t intensity)

Set TFT Backlight brightness. setTftBrightnessSetting() should be called instead if the new volume should be persistent through a reboot.

Parameters
intensityThe brightness, 0 to MAX_TFT_BRIGHTNESS
Returns
value is 0 if OK nonzero if error.

◆ initTFT()

void initTFT ( spi_host_device_t spiHost,
gpio_num_t sclk,
gpio_num_t mosi,
gpio_num_t dc,
gpio_num_t cs,
gpio_num_t rst,
gpio_num_t backlight,
bool isPwmBacklight,
ledc_channel_t ledcChannel,
ledc_timer_t ledcTimer,
uint8_t brightness )

Initialize a TFT display and return it through a pointer arg.

Parameters
spiHostThe SPI host to use for this display
sclkThe GPIO for the SCLK pin
mosiThe GPIO for the MOSI pin
dcThe GPIO for the TFT SPI data or command selector pin
csThe GPIO for the chip select pin
rstThe GPIO for the RESET pin
backlightThe GPIO used to PWM control the backlight
isPwmBacklighttrue to set up the backlight as PWM, false to have it be on/off
ledcChannelThe LEDC channel to use for the PWM backlight
ledcTimerThe LEDC timer to use for the PWM backlight
brightnessThe initial backlight brightness

◆ deinitTFT()

void deinitTFT ( void )

Deinitialize the TFT display.

◆ getPxTftFramebuffer()

paletteColor_t * getPxTftFramebuffer ( void )

Return the pixel framebuffer, which is (TFT_WIDTH * TFT_HEIGHT) pixels in row order, starting from the top left. This can be used t directly modify individual pixels without calling setPxTft()

Returns
The pixel framebuffer

◆ disableTFTBacklight()

void disableTFTBacklight ( void )

Disable the backlight (for power down)

◆ enableTFTBacklight()

void enableTFTBacklight ( void )

Enable the backlight.

◆ setPxTft()

void setPxTft ( int16_t x,
int16_t y,
paletteColor_t px )

Set a single pixel in the display, with bounds check.

Parameters
xThe x coordinate of the pixel to set
yThe y coordinate of the pixel to set
pxThe color of the pixel to set

◆ getPxTft()

paletteColor_t getPxTft ( int16_t x,
int16_t y )

Get a single pixel in the display.

Parameters
xThe x coordinate of the pixel to get
yThe y coordinate of the pixel to get
Returns
paletteColor_t The color of the given pixel, or black if out of bounds

◆ clearPxTft()

void clearPxTft ( void )

Clear all pixels in the display to black.

◆ drawDisplayTft()

void drawDisplayTft ( fnBackgroundDrawCallback_t fnBackgroundDrawCallback)

Send the current framebuffer to the TFT display over the SPI bus.

This function can be called as quickly as possible

Because the SPI driver handles transactions in the background, we can calculate the next line while the previous one is being sent.

Parameters
fnBackgroundDrawCallbackA function pointer to draw backgrounds while the transmission is occurring

Variable Documentation

◆ pFrameBuffer

paletteColor_t* pFrameBuffer = NULL