TinyGPU
Loading...
Searching...
No Matches
LCDBoardsSTM32F723Discovery.h
Go to the documentation of this file.
1#pragma once
2/**
3 * @file LCDBoardsSTM32F723Discovery.h
4 * @brief LCDBoard backed by the stm32f723-disco Arduino library
5 * (https://github.com/pschatzmann/stm32f723-disco) for the STM32F723E-
6 * Discovery board's on-board 240x240 ST7789H2 LCD (wired to the STM32F723
7 * via its FMC peripheral in 8080-parallel mode - not SPI/QSPI/DSI) and
8 * FT6x06/FT3x67 capacitive touch controller.
9 *
10 * stm32f723-disco is a separate, optional Arduino library - install it
11 * alongside TinyGPU (requires the STM32duino "STMicroelectronics:stm32"
12 * core, board "Discovery" / STM32F723E-DISCOVERY, pnum=DISCO_F723IE) and
13 * `#include <TinyGPU/Boards/LCDBoardsSTM32F723Discovery.h>` explicitly
14 * (this header is not pulled in by LCDBoards.h's platform dispatcher,
15 * since it targets one specific STM32 board rather than being a platform
16 * default - the same reason LCDBoardsTFTeSPI.h is opt-in) to use it.
17 *
18 * Deliberately built on the library's own `LCD`/`TouchScreen` wrappers
19 * (themselves thin wrappers around ST's STM32Cube BSP `BSP_LCD_*`/
20 * `BSP_TS_*` calls) rather than a from-scratch native TinyGPU FMC bus
21 * driver: getting the FMC bank/pin/timing mapping and the ST7789H2 init
22 * sequence right for this exact board is exactly what that BSP already
23 * does, verified by ST for this kit - re-deriving it here without real
24 * hardware to test against would risk a driver that's subtly wrong in a
25 * way nothing would catch. Same tradeoff LCDBoardsTFTeSPI.h makes by
26 * wrapping TFT_eSPI's own `User_Setup.h` instead of re-deriving pin/init
27 * tables, and DSIBusSTM32.h makes by taking the DSI PHY PLL config as a
28 * pre-computed constructor input instead of guessing board-specific
29 * divisors.
30 *
31 * See LCDBoardsCommon.h for the platform-independent LCDBoard interface
32 * this implements.
33 */
34#include "TinyGPU/Boards/LCDBoardsCommon.h"
35#include "TinyGPU/Color/RGB565.h"
36#include "TinyGPU/Drivers/DisplayDriver.h"
37#include "TinyGPU/Input/TouchDriver.h"
38
39#include <STM32F723Discovery.h>
40
41#include <vector>
42
43namespace tinygpu {
44
45/**
46 * @brief DisplayDriver<RGB565> wrapping the stm32f723-disco library's
47 * `LCD` class - the library owns the panel's init sequence and pixel
48 * output entirely (STM32Cube BSP driving the STM32F723's FMC peripheral),
49 * so this class is a thin adapter rather than a bus-level driver like
50 * DisplayDriverSPI/QSPI/DSI. Fixed 240x240 resolution - the panel is
51 * square, so width()/height() don't change with orientation.
52 *
53 * Byte order: `LCD::drawRGBImage()` expects the conventional (native)
54 * RGB565 bit layout - like DisplayDriverSDL's SDL texture upload, this is
55 * the opposite of TinyGPU's own stored (SPI-wire-swapped) byte order (see
56 * RGB565.h), so writeData() swaps into a scratch buffer before calling
57 * drawRGBImage() rather than mutating the surface.
58 */
60 public:
62 stm32f723::LcdOrientation orientation =
65
66 /// Resets and initializes the panel via the stm32f723-disco BSP wrapper.
67 bool begin() override { return lcd_.begin(orientation_); }
68
69 size_t width() const override { return kSize; }
70 size_t height() const override { return kSize; }
71
72 bool writeData(ISurface<RGB565>& surface) override {
73 return writeData(surface, 0, 0);
74 }
75
76 bool writeData(ISurface<RGB565>& surface, size_t x, size_t y) override {
77 const size_t n = surface.size();
78 if (scratch_.size() < n) scratch_.resize(n);
79 const uint16_t* src = reinterpret_cast<const uint16_t*>(surface.data());
80 uint16_t* dst = reinterpret_cast<uint16_t*>(scratch_.data());
81 const size_t pixelCount = n / sizeof(RGB565);
82 for (size_t i = 0; i < pixelCount; ++i) {
83 dst[i] = RGB565::swapBytes(src[i]);
84 }
85 lcd_.drawRGBImage(static_cast<uint16_t>(x), static_cast<uint16_t>(y),
86 static_cast<uint16_t>(surface.width()),
87 static_cast<uint16_t>(surface.height()),
88 scratch_.data());
89 return true;
90 }
91
92 /// Direct access to the underlying stm32f723::LCD instance - e.g. for
93 /// displayOn()/displayOff() or the library's own text/shape drawing,
94 /// which this driver doesn't wrap.
95 stm32f723::LCD& lcd() { return lcd_; }
96
97 protected:
98 bool setAddressWindow(size_t x, size_t y, size_t w, size_t h) override {
99 return true;
100 }
101
102 private:
103 static constexpr size_t kSize = 240;
104
105 stm32f723::LcdOrientation orientation_;
106 stm32f723::LCD lcd_;
107 std::vector<uint8_t> scratch_;
108};
109
110/**
111 * @brief TouchDriver wrapping the stm32f723-disco library's `TouchScreen`
112 * class (on-board FT6x06/FT3x67 capacitive touch controller - bus/pin
113 * setup is entirely owned by the library, same as the LCD side).
114 */
116 public:
117 /// Initializes the touch controller, scaled to the panel's 240x240
118 /// resolution (see DisplayDriverSTM32F723Discovery).
119 bool begin() override { return touch_.begin(kSize, kSize); }
120
121 bool isTouched() override { return touch_.read().touched(); }
122
123 bool getPoint(Point& outPoint) override {
124 const stm32f723::TouchState state = touch_.read();
125 if (!state.touched()) return false;
126 outPoint.x = state.primary().x;
127 outPoint.y = state.primary().y;
128 outPoint.pressure = 255;
129 return true;
130 }
131
132 /// The FT6x06/FT3x67 supports up to two simultaneous touches.
133 bool getSecondPoint(Point& outPoint) override {
134 const stm32f723::TouchState state = touch_.read();
135 if (state.touchCount < 2) return false;
136 outPoint.x = state.points[1].x;
137 outPoint.y = state.points[1].y;
138 outPoint.pressure = 255;
139 return true;
140 }
141
142 private:
143 static constexpr uint16_t kSize = 240;
144
145 stm32f723::TouchScreen touch_;
146};
147
148/**
149 * @brief "STM32F723E-Discovery" - on-board 240x240 ST7789H2 LCD (FMC) +
150 * FT6x06/FT3x67 capacitive touch, via the stm32f723-disco library.
151 *
152 * No I2S/LED pin assignment here: the board's audio codec is driven over
153 * SAI (see the library's own Audio.h), not I2S, so i2s() reports "not
154 * present" (every field -1); LED_RED/LED_GREEN/USER_BTN are ordinary
155 * Arduino digital pins defined by the STM32duino board variant itself
156 * (see the stm32f723-disco umbrella header's doc comment) rather than
157 * pins this class would need to track, so led() likewise reports "not
158 * present".
159 */
161 public:
162 /// Initializes the display, then the touch controller.
163 bool begin() override {
164 if (!display_.begin()) return false;
165 return touch_.begin();
166 }
167
168 size_t width() const override { return display_.width(); }
169 size_t height() const override { return display_.height(); }
170
171 DisplayDriverSTM32F723Discovery& display() override { return display_; }
172 TouchDriver* touch() override { return &touch_; }
173 const I2SPins& i2s() const override { return i2s_; }
174 const LEDPins& led() const override { return led_; }
175
176 private:
179 I2SPins i2s_{};
180 LEDPins led_{};
181};
182
183using STM32F723Discovery = LCDBoardSTM32F723Discovery;
184
185} // namespace tinygpu
DisplayDriver<RGB565> wrapping the stm32f723-disco library's LCD class - the library owns the panel's...
Definition: LCDBoardsSTM32F723Discovery.h:59
bool writeData(ISurface< RGB565 > &surface) override
Definition: LCDBoardsSTM32F723Discovery.h:72
size_t height() const override
Definition: LCDBoardsSTM32F723Discovery.h:70
bool writeData(ISurface< RGB565 > &surface, size_t x, size_t y) override
Definition: LCDBoardsSTM32F723Discovery.h:76
size_t width() const override
Definition: LCDBoardsSTM32F723Discovery.h:69
bool begin() override
Resets and initializes the panel via the stm32f723-disco BSP wrapper.
Definition: LCDBoardsSTM32F723Discovery.h:67
bool setAddressWindow(size_t x, size_t y, size_t w, size_t h) override
Definition: LCDBoardsSTM32F723Discovery.h:98
DisplayDriverSTM32F723Discovery(stm32f723::LcdOrientation orientation=stm32f723::LcdOrientation::Landscape)
Definition: LCDBoardsSTM32F723Discovery.h:61
stm32f723::LCD & lcd()
Definition: LCDBoardsSTM32F723Discovery.h:95
"STM32F723E-Discovery" - on-board 240x240 ST7789H2 LCD (FMC) + FT6x06/FT3x67 capacitive touch,...
Definition: LCDBoardsSTM32F723Discovery.h:160
size_t height() const override
Panel height in pixels.
Definition: LCDBoardsSTM32F723Discovery.h:169
const I2SPins & i2s() const override
The board's I2S/PA pin assignment.
Definition: LCDBoardsSTM32F723Discovery.h:173
TouchDriver * touch() override
The board's touch controller, or nullptr if none is wired up.
Definition: LCDBoardsSTM32F723Discovery.h:172
size_t width() const override
Panel width in pixels.
Definition: LCDBoardsSTM32F723Discovery.h:168
bool begin() override
Initializes the display, then the touch controller.
Definition: LCDBoardsSTM32F723Discovery.h:163
const LEDPins & led() const override
The board's LED pin assignment.
Definition: LCDBoardsSTM32F723Discovery.h:174
DisplayDriverSTM32F723Discovery & display() override
The board's display driver.
Definition: LCDBoardsSTM32F723Discovery.h:171
Definition: LCDBoardsCommon.h:62
RGB color stored in 16-bit RGB565 format, byte-swapped from the conventional bit layout.
Definition: RGB565.h:24
TouchDriver wrapping the stm32f723-disco library's TouchScreen class (on-board FT6x06/FT3x67 capaciti...
Definition: LCDBoardsSTM32F723Discovery.h:115
bool isTouched() override
Return whether the panel currently appears touched.
Definition: LCDBoardsSTM32F723Discovery.h:121
bool getPoint(Point &outPoint) override
Read the current touch point.
Definition: LCDBoardsSTM32F723Discovery.h:123
bool begin() override
Definition: LCDBoardsSTM32F723Discovery.h:119
bool getSecondPoint(Point &outPoint) override
The FT6x06/FT3x67 supports up to two simultaneous touches.
Definition: LCDBoardsSTM32F723Discovery.h:133
Base class for touch controllers.
Definition: TouchDriverCommon.h:72
Definition: DSIBusESP32.h:19
Definition: LCDBoardsCommon.h:28
Definition: LCDBoardsCommon.h:49
Touch point.
Definition: TouchDriverCommon.h:32
uint16_t pressure
Definition: TouchDriverCommon.h:35