TinyGPU
Loading...
Searching...
No Matches
LCDBoardsCommon.h
Go to the documentation of this file.
1#pragma once
2/**
3 * @file LCDBoards.h
4 * @brief Platform-independent interface for a board that bundles a
5 * display, an optional touch controller, an I2S pin assignment, and an
6 * LED pin assignment behind one begin() call.
7 *
8 * This file only defines the shared interface (I2SPins, LEDPins,
9 * LCDBoard). Concrete board classes with actual pin numbers live in
10 * platform-specific files, e.g. LCDBoardsESP32.h for ESP32(-S3) boards
11 * from the arduino-audio-tools "Audio Boards" wiki:
12 * https://github.com/pschatzmann/arduino-audio-tools/wiki/Audio-Boards
13 */
14#include "../../TinyGPU.h"
15#include "TinyGPU/Drivers/DisplayDriver.h"
16#include "TinyGPU/Input/TouchDriver.h"
17
18namespace tinygpu {
19
20/// I2S pin assignment for a board's audio codec/amplifier. Not used by
21/// TinyGPU itself - hand these to the audio library of choice (e.g.
22/// audio_tools::I2SConfig's pin_mck/pin_bck/pin_ws/pin_data/pin_data_rx).
23/// -1 means "not present on this board".
24///
25/// paEnable/paEnableActiveLow describe a separate GPIO some boards use to
26/// gate the speaker amplifier (not part of the I2S bus itself, but bundled
27/// here since it's only ever needed alongside these pins).
28struct I2SPins {
29 int8_t mclk = -1;
30 int8_t bck = -1;
31 int8_t ws = -1;
32 int8_t dataOut = -1;
33 int8_t dataIn = -1;
34 int8_t paEnable = -1;
35 bool paEnableActiveLow = false;
36
37 /// True if this board has a usable I2S bus (bck/ws plus at least one of
38 /// dataOut/dataIn) wired up.
39 bool isValid() const {
40 return bck != -1 && ws != -1 && (dataOut != -1 || dataIn != -1);
41 }
42};
43
44/// LED pin assignment for a board's status LED, if any. Boards in this
45/// file use one of two shapes: a single-wire addressable LED (WS2812 and
46/// similar - set `single`) or a discrete 3-pin RGB LED (set `r`/`g`/`b`
47/// and `activeLow`). -1 means "no pin of that kind on this board" - a
48/// board with neither leaves every field at -1.
49struct LEDPins {
50 int8_t single = -1;
51 int8_t r = -1;
52 int8_t g = -1;
53 int8_t b = -1;
54 bool activeLow = false;
55};
56
57/// Common interface for a board that bundles a display, an optional touch
58/// controller, an I2S pin assignment, and an LED pin assignment behind one
59/// begin() call. All boards implementing this use RGB565 panels, so
60/// display() is pinned to that color type here (each concrete board still
61/// returns its own driver subclass via a covariant return type).
62class LCDBoard {
63 public:
64 virtual ~LCDBoard() = default;
65
66 /// Brings up the board's backlight/bus/display/touch. Returns false if
67 /// the display or touch begin() fails.
68 virtual bool begin() = 0;
69
70 /// Panel width in pixels.
71 virtual size_t width() const = 0;
72 /// Panel height in pixels.
73 virtual size_t height() const = 0;
74
75 /// The board's display driver.
76 virtual DisplayDriver<RGB565>& display() = 0;
77 /// The board's touch controller, or nullptr if none is wired up.
78 virtual TouchDriver* touch() = 0;
79 /// The board's I2S/PA pin assignment.
80 virtual const I2SPins& i2s() const = 0;
81 /// The board's LED pin assignment.
82 virtual const LEDPins& led() const = 0;
83 /// The board's backlight GPIO pin, or -1 if unknown/not applicable.
84 /// begin() already drives it digitally HIGH; this accessor exists so
85 /// callers can reconfigure the same pin for PWM brightness control
86 /// (e.g. via ledcAttach/ledcWrite) after begin().
87 virtual int8_t backlightPin() const { return -1; }
88
89 /// Copies this board's I2S pins into an audio_tools-style I2SConfig
90 /// (any type exposing pin_bck/pin_ws/pin_data/pin_data_rx).
91 template <typename I2SConfig>
92 void setI2SPins(I2SConfig& cfg) {
93 const I2SPins& pins = i2s();
94 cfg.pin_mck = pins.mclk;
95 cfg.pin_bck = pins.bck;
96 cfg.pin_ws = pins.ws;
97 cfg.pin_data = pins.dataOut;
98 cfg.pin_data_rx = pins.dataIn;
99 }
100};
101
102} // namespace tinygpu
Definition: DisplayDriver.h:49
Definition: LCDBoardsCommon.h:62
void setI2SPins(I2SConfig &cfg)
Definition: LCDBoardsCommon.h:92
virtual size_t height() const =0
Panel height in pixels.
virtual TouchDriver * touch()=0
The board's touch controller, or nullptr if none is wired up.
virtual DisplayDriver< RGB565 > & display()=0
The board's display driver.
virtual ~LCDBoard()=default
virtual int8_t backlightPin() const
Definition: LCDBoardsCommon.h:87
virtual size_t width() const =0
Panel width in pixels.
virtual const I2SPins & i2s() const =0
The board's I2S/PA pin assignment.
virtual const LEDPins & led() const =0
The board's LED pin assignment.
virtual bool begin()=0
RGB color stored in 16-bit RGB565 format, byte-swapped from the conventional bit layout.
Definition: RGB565.h:24
Base class for touch controllers.
Definition: TouchDriverCommon.h:72
Definition: DSIBusESP32.h:19
Definition: LCDBoardsCommon.h:28
int8_t ws
Definition: LCDBoardsCommon.h:31
int8_t paEnable
Definition: LCDBoardsCommon.h:34
int8_t mclk
Definition: LCDBoardsCommon.h:29
bool isValid() const
Definition: LCDBoardsCommon.h:39
bool paEnableActiveLow
Definition: LCDBoardsCommon.h:35
int8_t dataIn
Definition: LCDBoardsCommon.h:33
int8_t bck
Definition: LCDBoardsCommon.h:30
int8_t dataOut
Definition: LCDBoardsCommon.h:32
Definition: LCDBoardsCommon.h:49
int8_t b
Definition: LCDBoardsCommon.h:53
int8_t r
Definition: LCDBoardsCommon.h:51
int8_t single
Definition: LCDBoardsCommon.h:50
int8_t g
Definition: LCDBoardsCommon.h:52
bool activeLow
Definition: LCDBoardsCommon.h:54