Swadge ESP32-S2/S3
APIs to develop for the Magfest Swadge
Loading...
Searching...
No Matches
hdw-tft.h
Go to the documentation of this file.
1
74
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_ST7789_320x240)
104 #define TFT_WIDTH 320
105 #define TFT_HEIGHT 240
106#elif defined(CONFIG_GC9307_240x280)
107 #define TFT_WIDTH 280
108 #define TFT_HEIGHT 240
109#else
110 #error "Please pick a screen size"
111#endif
112
126typedef void (*fnBackgroundDrawCallback_t)(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum);
127
128void 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,
129 gpio_num_t backlight, bool isPwmBacklight, ledc_channel_t ledcChannel, ledc_timer_t ledcTimer,
130 uint8_t brightness);
131void deinitTFT(void);
132void powerDownTft(void);
133void powerUpTft(void);
134esp_err_t setTFTBacklightBrightness(uint8_t intensity);
135void disableTFTBacklight(void);
136void enableTFTBacklight(void);
137
138void setPxTft(int16_t x, int16_t y, paletteColor_t px);
139paletteColor_t getPxTft(int16_t x, int16_t y);
141void clearPxTft(void);
143
144#if defined(__XTENSA__)
148 #define SETUP_FOR_TURBO() register uint32_t dispPx = (uint32_t)getPxTftFramebuffer();
149
156 #define TURBO_SET_PIXEL(opxc, opy, colorVal) \
157 asm volatile("mul16u a4, %[width], %[y]\nadd a4, a4, %[px]\nadd a4, a4, %[opx]\ns8i %[val],a4, 0" \
158 : \
159 : [opx] "a"(opxc), [y] "a"(opy), [px] "a"(dispPx), [val] "a"(colorVal), [width] "a"(TFT_WIDTH) \
160 : "a4");
161
170 #define TURBO_SET_PIXEL_BOUNDS(opxc, opy, colorVal) \
171 asm volatile( \
172 "bgeu %[opx], %[width], failthrough%=\nbgeu %[y], %[height], failthrough%=\nmul16u a4, %[width], " \
173 "%[y]\nadd a4, a4, %[px]\nadd a4, a4, %[opx]\ns8i %[val],a4, 0\nfailthrough%=:\n" \
174 : \
175 : [opx] "a"(opxc), [y] "a"(opy), [px] "a"(dispPx), [val] "a"(colorVal), [width] "a"(TFT_WIDTH), \
176 [height] "a"(TFT_HEIGHT) \
177 : "a4");
178#else
180 #define SETUP_FOR_TURBO() bool turboSetup = true
182 #define TURBO_SET_PIXEL(opxc, opy, colorVal) \
183 do \
184 { \
185 if (!turboSetup) \
186 { \
187 fprintf(stderr, "SETUP_FOR_TURBO() not called\n"); \
188 exit(1); \
189 } \
190 if (opxc < 0 || opxc >= TFT_WIDTH || opy < 0 || opy >= TFT_HEIGHT) \
191 { \
192 fprintf(stderr, "PXL OOB (%d, %d)\n", opxc, opy); \
193 exit(1); \
194 } \
195 setPxTft(opxc, opy, colorVal); \
196 } while (0)
197
198 #define TURBO_SET_PIXEL_BOUNDS(opxc, opy, colorVal) \
199 do \
200 { \
201 if (!turboSetup) \
202 { \
203 fprintf(stderr, "SETUP_FOR_TURBO() not called\n"); \
204 exit(1); \
205 } \
206 setPxTft(opxc, opy, colorVal); \
207 } while (0)
208#endif
209
210#endif
void disableTFTBacklight(void)
Disable the backlight (for power down).
Definition hdw-tft.c:334
void powerDownTft(void)
Turn off the backlight and put the TFT in sleep mode.
Definition hdw-tft.c:303
paletteColor_t * getPxTftFramebuffer(void)
Return the pixel framebuffer, which is (TFT_WIDTH * TFT_HEIGHT) pixels in row order,...
Definition hdw-tft.c:325
void clearPxTft(void)
Clear all pixels in the display to black.
Definition hdw-tft.c:429
void enableTFTBacklight(void)
Enable the backlight.
Definition hdw-tft.c:352
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:126
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:142
void powerUpTft(void)
Wake the TFT and turn on the backlight.
Definition hdw-tft.c:312
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:178
void deinitTFT(void)
Deinitialize the TFT display.
Definition hdw-tft.c:285
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:402
void drawDisplayTft(fnBackgroundDrawCallback_t cb)
Send the current framebuffer to the TFT display over the SPI bus.
Definition hdw-tft.c:444
paletteColor_t getPxTft(int16_t x, int16_t y)
Get a single pixel in the display.
Definition hdw-tft.c:417
paletteColor_t
All 216 possible colors, named like cRGB.
Definition palette.h:23