Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hdw-tft.h
Go to the documentation of this file.
1
75#ifndef _HDW_TFT_H_
76#define _HDW_TFT_H_
77
78#include <stdint.h>
79#include <stdbool.h>
80
81#include <soc/gpio_num.h>
82#include <hal/spi_types.h>
83#include <driver/ledc.h>
84#include <esp_err.h>
85
86#include "palette.h"
87
89#define MAX_TFT_BRIGHTNESS 7
90
91#if defined(CONFIG_ST7735_160x80)
92 #define TFT_WIDTH 160
93 #define TFT_HEIGHT 80
94#elif defined(CONFIG_ST7735_128x160)
95 #define TFT_WIDTH 160
96 #define TFT_HEIGHT 128
97#elif defined(CONFIG_ST7789_240x135)
98 #define TFT_WIDTH 240
99 #define TFT_HEIGHT 135
100#elif defined(CONFIG_ST7789_240x240)
101 #define TFT_WIDTH 240
102 #define TFT_HEIGHT 240
103#elif defined(CONFIG_GC9307_240x280)
104 #define TFT_WIDTH 280
105 #define TFT_HEIGHT 240
106#else
107 #error "Please pick a screen size"
108#endif
109
123typedef void (*fnBackgroundDrawCallback_t)(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum);
124
125void 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,
126 gpio_num_t backlight, bool isPwmBacklight, ledc_channel_t ledcChannel, ledc_timer_t ledcTimer,
127 uint8_t brightness);
128void deinitTFT(void);
129void powerDownTft(void);
130void powerUpTft(void);
131esp_err_t setTFTBacklightBrightness(uint8_t intensity);
132void disableTFTBacklight(void);
133void enableTFTBacklight(void);
134
135void setPxTft(int16_t x, int16_t y, paletteColor_t px);
136paletteColor_t getPxTft(int16_t x, int16_t y);
138void clearPxTft(void);
140
141#if defined(__XTENSA__)
145 #define SETUP_FOR_TURBO() register uint32_t dispPx = (uint32_t)getPxTftFramebuffer();
146
153 #define TURBO_SET_PIXEL(opxc, opy, colorVal) \
154 asm volatile("mul16u a4, %[width], %[y]\nadd a4, a4, %[px]\nadd a4, a4, %[opx]\ns8i %[val],a4, 0" \
155 : \
156 : [opx] "a"(opxc), [y] "a"(opy), [px] "a"(dispPx), [val] "a"(colorVal), [width] "a"(TFT_WIDTH) \
157 : "a4");
158
167 #define TURBO_SET_PIXEL_BOUNDS(opxc, opy, colorVal) \
168 asm volatile( \
169 "bgeu %[opx], %[width], failthrough%=\nbgeu %[y], %[height], failthrough%=\nmul16u a4, %[width], " \
170 "%[y]\nadd a4, a4, %[px]\nadd a4, a4, %[opx]\ns8i %[val],a4, 0\nfailthrough%=:\n" \
171 : \
172 : [opx] "a"(opxc), [y] "a"(opy), [px] "a"(dispPx), [val] "a"(colorVal), [width] "a"(TFT_WIDTH), \
173 [height] "a"(TFT_HEIGHT) \
174 : "a4");
175#else
177 #define SETUP_FOR_TURBO()
179 #define TURBO_SET_PIXEL(opxc, opy, colorVal) setPxTft(opxc, opy, colorVal)
181 #define TURBO_SET_PIXEL_BOUNDS(opxc, opy, colorVal) setPxTft(opxc, opy, colorVal)
182#endif
183
184#endif
void disableTFTBacklight(void)
Disable the backlight (for power down)
Definition hdw-tft.c:327
void powerDownTft(void)
Turn off the backlight and put the TFT in sleep mode.
Definition hdw-tft.c:296
paletteColor_t * getPxTftFramebuffer(void)
Return the pixel framebuffer, which is (TFT_WIDTH * TFT_HEIGHT) pixels in row order,...
Definition hdw-tft.c:318
void clearPxTft(void)
Clear all pixels in the display to black.
Definition hdw-tft.c:422
void enableTFTBacklight(void)
Enable the backlight.
Definition hdw-tft.c:345
void(* fnBackgroundDrawCallback_t)(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum)
This is a typedef for a function pointer passed to drawDisplayTft() which will be called to draw a ba...
Definition hdw-tft.h:123
esp_err_t setTFTBacklightBrightness(uint8_t intensity)
Set TFT Backlight brightness. setTftBrightnessSetting() should be called instead if the new volume sh...
Definition hdw-tft.c:135
void powerUpTft(void)
Wake the TFT and turn on the backlight.
Definition hdw-tft.c:305
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.
Definition hdw-tft.c:171
void deinitTFT(void)
Deinitialize the TFT display.
Definition hdw-tft.c:278
void setPxTft(int16_t x, int16_t y, paletteColor_t px)
Set a single pixel in the display, with bounds check.
Definition hdw-tft.c:395
void drawDisplayTft(fnBackgroundDrawCallback_t cb)
Send the current framebuffer to the TFT display over the SPI bus.
Definition hdw-tft.c:437
paletteColor_t getPxTft(int16_t x, int16_t y)
Get a single pixel in the display.
Definition hdw-tft.c:410
paletteColor_t
All 216 possible colors, named like cRGB.
Definition palette.h:23