Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
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);
129esp_err_t setTFTBacklightBrightness(uint8_t intensity);
130void disableTFTBacklight(void);
131void enableTFTBacklight(void);
132
133void setPxTft(int16_t x, int16_t y, paletteColor_t px);
134paletteColor_t getPxTft(int16_t x, int16_t y);
136void clearPxTft(void);
138
139#if defined(__XTENSA__)
143 #define SETUP_FOR_TURBO() register uint32_t dispPx = (uint32_t)getPxTftFramebuffer();
144
151 #define TURBO_SET_PIXEL(opxc, opy, colorVal) \
152 asm volatile("mul16u a4, %[width], %[y]\nadd a4, a4, %[px]\nadd a4, a4, %[opx]\ns8i %[val],a4, 0" \
153 : \
154 : [opx] "a"(opxc), [y] "a"(opy), [px] "a"(dispPx), [val] "a"(colorVal), [width] "a"(TFT_WIDTH) \
155 : "a4");
156
165 #define TURBO_SET_PIXEL_BOUNDS(opxc, opy, colorVal) \
166 asm volatile( \
167 "bgeu %[opx], %[width], failthrough%=\nbgeu %[y], %[height], failthrough%=\nmul16u a4, %[width], " \
168 "%[y]\nadd a4, a4, %[px]\nadd a4, a4, %[opx]\ns8i %[val],a4, 0\nfailthrough%=:\n" \
169 : \
170 : [opx] "a"(opxc), [y] "a"(opy), [px] "a"(dispPx), [val] "a"(colorVal), [width] "a"(TFT_WIDTH), \
171 [height] "a"(TFT_HEIGHT) \
172 : "a4");
173#else
175 #define SETUP_FOR_TURBO()
177 #define TURBO_SET_PIXEL(opxc, opy, colorVal) setPxTft(opxc, opy, colorVal)
179 #define TURBO_SET_PIXEL_BOUNDS(opxc, opy, colorVal) setPxTft(opxc, opy, colorVal)
180#endif
181
182#endif
void disableTFTBacklight(void)
Disable the backlight (for power down)
Definition hdw-tft.c:309
paletteColor_t * getPxTftFramebuffer(void)
Return the pixel framebuffer, which is (TFT_WIDTH * TFT_HEIGHT) pixels in row order,...
Definition hdw-tft.c:300
void clearPxTft(void)
Clear all pixels in the display to black.
Definition hdw-tft.c:404
void enableTFTBacklight(void)
Enable the backlight.
Definition hdw-tft.c:327
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 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:377
void drawDisplayTft(fnBackgroundDrawCallback_t cb)
Send the current framebuffer to the TFT display over the SPI bus.
Definition hdw-tft.c:419
paletteColor_t getPxTft(int16_t x, int16_t y)
Get a single pixel in the display.
Definition hdw-tft.c:392
paletteColor_t
All 216 possible colors, named like cRGB.
Definition palette.h:23