20#ifdef TFT_ESPI_VERSION
31class TFT_eSPI_Adapter :
public DisplayDevice {
33 using ColorMode = Rgb565;
35 static constexpr ByteOrder byte_order = roo_io::kBigEndian;
37 TFT_eSPI_Adapter(uint16_t width, uint16_t height)
38 : TFT_eSPI_Adapter(Orientation(), width, height) {}
40 TFT_eSPI_Adapter(Orientation orientation = Orientation())
41 : TFT_eSPI_Adapter(orientation, TFT_WIDTH, TFT_HEIGHT) {}
43 TFT_eSPI_Adapter(Orientation orientation, uint16_t width, uint16_t height)
44 : DisplayDevice(orientation, width, height),
49 ~TFT_eSPI_Adapter()
override {}
51 void init()
override {
55 tft_.setRotation(orientation().getRotationCount());
58 void begin()
override { tft_.startWrite(); }
60 void end()
override { tft_.endWrite(); }
62 void setBgColorHint(Color
bgcolor)
override { bgcolor_ =
bgcolor; }
64 void setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,
66 blending_mode_ = mode;
67 tft_.setWindow(x0, y0, x1, y1);
70 void write(Color* color, uint32_t pixel_count)
override {
72 tft_.setSwapBytes(
true);
73 while (pixel_count > 64) {
74 color = processColorSequence(blending_mode_, color, buffer, 64);
75 tft_.pushPixels(buffer, 64);
78 processColorSequence(blending_mode_, color, buffer, pixel_count);
79 tft_.pushPixels(buffer, pixel_count);
80 tft_.setSwapBytes(
false);
83 void fill(Color color, uint32_t pixel_count)
override {
85 tft_.pushColor(to_raw_color(color), pixel_count);
88 void writeRects(
BlendingMode mode, Color* color, int16_t* x0, int16_t* y0,
89 int16_t* x1, int16_t* y1, uint16_t count)
override {
91 uint32_t pixel_count = (*x1 - *x0 + 1) * (*y1 - *y0 + 1);
92 TFT_eSPI_Adapter::setAddress(*x0++, *y0++, *x1++, *y1++,
94 Color mycolor = *
color++;
96 uint16_t raw_color = to_raw_color(mycolor);
97 tft_.pushBlock(raw_color, pixel_count);
101 void fillRects(
BlendingMode mode, Color color, int16_t* x0, int16_t* y0,
102 int16_t* x1, int16_t* y1, uint16_t count)
override {
104 uint16_t raw_color = to_raw_color(color);
106 while (count-- > 0) {
107 uint32_t pixel_count = (*x1 - *x0 + 1) * (*y1 - *y0 + 1);
108 TFT_eSPI_Adapter::setAddress(*x0++, *y0++, *x1++, *y1++,
110 tft_.pushBlock(raw_color, pixel_count);
114 void writePixels(
BlendingMode mode, Color* colors, int16_t* xs, int16_t* ys,
115 uint16_t pixel_count)
override {
116 compactor_.drawPixels(
118 [
this, mode, colors](int16_t offset, int16_t x, int16_t y,
123 TFT_eSPI_Adapter::setAddress(x, y, x + count - 1, y, mode);
127 TFT_eSPI_Adapter::setAddress(x, y, x, y + count - 1, mode);
131 TFT_eSPI_Adapter::setAddress(x - count + 1, y, x, y, mode);
132 std::reverse(colors + offset, colors + offset + count);
136 TFT_eSPI_Adapter::setAddress(x, y - count + 1, x, y, mode);
137 std::reverse(colors + offset, colors + offset + count);
141 TFT_eSPI_Adapter::write(colors + offset, count);
145 const ColorFormat& getColorFormat()
const override {
146 static const internal::ColorFormatImpl<Rgb565, roo_io::kBigEndian,
148 format(color_mode());
152 const Rgb565& color_mode()
const {
153 static const Rgb565 mode;
157 void fillPixels(
BlendingMode mode, Color color, int16_t* xs, int16_t* ys,
158 uint16_t pixel_count)
override {
160 uint16_t raw_color = to_raw_color(color);
161 compactor_.drawPixels(
163 [
this, raw_color](int16_t offset, int16_t x, int16_t y,
167 TFT_eSPI_Adapter::setAddress(x, y, x + count - 1, y,
172 TFT_eSPI_Adapter::setAddress(x, y, x, y + count - 1,
177 TFT_eSPI_Adapter::setAddress(x - count + 1, y, x, y,
182 TFT_eSPI_Adapter::setAddress(x, y - count + 1, x, y,
187 tft_.pushBlock(raw_color, count);
191 void orientationUpdated()
override {
192 tft_.setRotation(orientation().getRotationCount());
195 static inline uint16_t to_raw_color(Color color)
196 __attribute__((always_inline)) {
197 return Rgb565().fromArgbColor(color);
204 Color* processColorSequence(
BlendingMode mode, Color* src, uint16_t* dest,
205 uint32_t pixel_count) {
207 while (pixel_count-- > 0) {
208 *dest++ = to_raw_color(*src++);
215 Compactor compactor_;
Defines 140 opaque HTML named colors.
void ApplyBlendingOverBackground(BlendingMode mode, Color bg, Color *src, int16_t count)
BlendingMode
Porter-Duff style blending modes.
@ kSource
The new ARGB8888 value completely replaces the old one.
roo_io::ByteOrder ByteOrder