TinyGPU
Loading...
Searching...
No Matches
LCDBoardsTFTeSPI.h
Go to the documentation of this file.
1#pragma once
2/**
3 * @file LCDBoardsTFTeSPI.h
4 * @brief LCDBoard backed by Bodmer's TFT_eSPI
5 * (https://github.com/Bodmer/TFT_eSPI) instead of one of this library's
6 * own SPI panel/touch drivers - useful if you already have a working
7 * TFT_eSPI `User_Setup.h` for your panel (and optionally its touch
8 * calibration) and would rather reuse it than re-wire the same panel
9 * through LCDBoardsESP32.h's board-specific pin tables.
10 *
11 * TFT_eSPI is a separate, optional Arduino library - install it alongside
12 * TinyGPU and `#include <TinyGPU/Boards/LCDBoardsTFTeSPI.h>` explicitly
13 * (this header is not pulled in by LCDBoards.h's platform dispatcher,
14 * since TFT_eSPI is a deliberate choice rather than a platform default -
15 * it can just as well be used on an ESP32 board that would otherwise get
16 * LCDBoardsESP32.h) to opt in.
17 *
18 * See LCDBoardsCommon.h for the platform-independent LCDBoard interface
19 * this implements, and DisplayDriverTFTeSPI.h/TouchDriverTFTeSPI.h for the
20 * two drivers it bundles.
21 */
22#include "TinyGPU/Boards/LCDBoardsCommon.h"
23#include "TinyGPU/Drivers/DisplayDriverTFTeSPI.h"
24#include "TinyGPU/Input/TouchDriverTFTeSPI.h"
25
26namespace tinygpu {
27
28/**
29 * @brief LCDBoard wrapping a single TFT_eSPI instance, shared between its
30 * DisplayDriverTFTeSPI and (optional) TouchDriverTFTeSPI.
31 *
32 * All panel-specific configuration (controller, pins, SPI frequency, ...)
33 * is TFT_eSPI's own `User_Setup.h`/`User_Setup_Select.h` job, same as any
34 * other TFT_eSPI sketch - width/height are still passed to the
35 * constructor (rather than read from TFT_eSPI) because, like every other
36 * LCDBoard here, callers may need them before begin() runs.
37 *
38 * Touch is opt-in via the constructor's `hasTouch` flag (many TFT_eSPI
39 * panels have no touch hardware at all) - touch() returns nullptr when
40 * disabled. When enabled, use tft() to reach TFT_eSPI's own touch
41 * calibration (tft().setTouch(calData), from tft().calibrateTouch(...)
42 * or a hardcoded panel-specific array) before calling begin() - TFT_eSPI
43 * owns touch calibration entirely, the same "driver does not own
44 * bus/calibration setup, the application does" split
45 * TouchDriverArduino.h's drivers use for their own SPI/I2C buses.
46 *
47 * No backlight/I2S/LED pin handling here - TFT_eSPI's own `User_Setup.h`
48 * covers the backlight pin (`TFT_BL`) if your panel needs one driven
49 * manually; i2s()/led() report "not present" (every field -1) and
50 * backlightPin() is -1, the same as LCDBoardDesktopSDL.
51 */
52class LCDBoardTFTeSPI : public LCDBoard {
53 public:
54 explicit LCDBoardTFTeSPI(size_t width, size_t height, bool hasTouch = false,
55 uint16_t touchThreshold = 600)
56 : width_(width),
60 hasTouch_(hasTouch) {}
61
62 /// Initializes TFT_eSPI (via DisplayDriverTFTeSPI::begin()) and, if
63 /// `hasTouch` was set, the touch driver.
64 bool begin() override {
65 if (!display_.begin()) return false;
66 if (hasTouch_) return touch_.begin();
67 return true;
68 }
69
70 /// Panel width in pixels, as passed to the constructor.
71 size_t width() const override { return width_; }
72 /// Panel height in pixels, as passed to the constructor.
73 size_t height() const override { return height_; }
74
75 /// The board's display driver.
76 DisplayDriverTFTeSPI<RGB565>& display() override { return display_; }
77 /// The board's touch controller, or nullptr if `hasTouch` was false.
78 TouchDriver* touch() override { return hasTouch_ ? &touch_ : nullptr; }
79 /// No I2S bus tracked here - every field is -1.
80 const I2SPins& i2s() const override { return i2s_; }
81 /// No LED tracked here - every field is -1.
82 const LEDPins& led() const override { return led_; }
83
84 /// Direct access to the underlying TFT_eSPI instance - e.g. for touch
85 /// calibration (see class comment) or any TFT_eSPI feature this driver
86 /// doesn't wrap.
87 TFT_eSPI& tft() { return tft_; }
88
89 private:
90 TFT_eSPI tft_; // must be declared (and so constructed) before display_/
91 // touch_ below, which bind references to it.
92 size_t width_;
93 size_t height_;
95 TouchDriverTFTeSPI touch_;
96 bool hasTouch_;
97 I2SPins i2s_{};
98 LEDPins led_{};
99};
100
101} // namespace tinygpu
Display driver that renders a TinyGPU surface through Bodmer's TFT_eSPI (https://github....
Definition: DisplayDriverTFTeSPI.h:36
LCDBoard wrapping a single TFT_eSPI instance, shared between its DisplayDriverTFTeSPI and (optional) ...
Definition: LCDBoardsTFTeSPI.h:52
TFT_eSPI & tft()
Definition: LCDBoardsTFTeSPI.h:87
size_t height() const override
Panel height in pixels, as passed to the constructor.
Definition: LCDBoardsTFTeSPI.h:73
const I2SPins & i2s() const override
No I2S bus tracked here - every field is -1.
Definition: LCDBoardsTFTeSPI.h:80
DisplayDriverTFTeSPI< RGB565 > & display() override
The board's display driver.
Definition: LCDBoardsTFTeSPI.h:76
TouchDriver * touch() override
The board's touch controller, or nullptr if hasTouch was false.
Definition: LCDBoardsTFTeSPI.h:78
size_t width() const override
Panel width in pixels, as passed to the constructor.
Definition: LCDBoardsTFTeSPI.h:71
bool begin() override
Definition: LCDBoardsTFTeSPI.h:64
LCDBoardTFTeSPI(size_t width, size_t height, bool hasTouch=false, uint16_t touchThreshold=600)
Definition: LCDBoardsTFTeSPI.h:54
const LEDPins & led() const override
No LED tracked here - every field is -1.
Definition: LCDBoardsTFTeSPI.h:82
Definition: LCDBoardsCommon.h:62
RGB color stored in 16-bit RGB565 format, byte-swapped from the conventional bit layout.
Definition: RGB565.h:24
Touch driver that reads through Bodmer's TFT_eSPI (https://github.com/Bodmer/TFT_eSPI) resistive touc...
Definition: TouchDriverTFTeSPI.h:37
Base class for touch controllers.
Definition: TouchDriverCommon.h:72
Definition: DSIBusESP32.h:19
Definition: LCDBoardsCommon.h:28
Definition: LCDBoardsCommon.h:49