ESPHome 2026.5.1
Loading...
Searching...
No Matches
ili9xxx_display.h
Go to the documentation of this file.
1#pragma once
5#include "ili9xxx_defines.h"
6#include "ili9xxx_init.h"
7
8namespace esphome::ili9xxx {
9
10static const char *const TAG = "ili9xxx";
11const size_t ILI9XXX_TRANSFER_BUFFER_SIZE = 126; // ensure this is divisible by 6
12
14 BITS_8 = 0x08,
16 BITS_16 = 0x10,
17};
18
24
26 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
27 spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_40MHZ> {
28 public:
29 ILI9XXXDisplay() = default;
30 ILI9XXXDisplay(uint8_t const *init_sequence, int16_t width, int16_t height)
31 : init_sequence_{init_sequence}, width_{width}, height_{height} {
32 uint8_t cmd, num_args, bits;
33 const uint8_t *addr = init_sequence;
34 while ((cmd = *addr++) != 0) {
35 num_args = *addr++;
36 if (num_args == ILI9XXX_DELAY_FLAG)
37 continue;
38 bits = *addr;
39 switch (cmd) {
40 case ILI9XXX_MADCTL: {
41 this->swap_xy_ = (bits & MADCTL_MV) != 0;
42 this->mirror_x_ = (bits & MADCTL_MX) != 0;
43 this->mirror_y_ = (bits & MADCTL_MY) != 0;
45 break;
46 }
47
48 case ILI9XXX_PIXFMT: {
49 if ((bits & 0xF) == 6)
50 this->is_18bitdisplay_ = true;
51 break;
52 }
53
54 default:
55 break;
56 }
57 addr += (num_args & 0x7F);
58 }
59 }
60
61 void add_init_sequence(const std::vector<uint8_t> &sequence) { this->extra_init_sequence_ = sequence; }
62 void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
63 float get_setup_priority() const override;
65 void set_palette(const uint8_t *palette) { this->palette_ = palette; }
66 void set_buffer_color_mode(ILI9XXXColorMode color_mode) { this->buffer_color_mode_ = color_mode; }
67 void set_dimensions(int16_t width, int16_t height) {
68 this->height_ = height;
69 this->width_ = width;
70 }
71 void set_offsets(int16_t offset_x, int16_t offset_y) {
72 this->offset_x_ = offset_x;
73 this->offset_y_ = offset_y;
74 }
75 void invert_colors(bool invert);
76 virtual void command(uint8_t value);
77 virtual void data(uint8_t value);
78 void send_command(uint8_t command_byte, const uint8_t *data_bytes, uint8_t num_data_bytes);
79 void set_color_order(display::ColorOrder color_order) { this->color_order_ = color_order; }
80 void set_swap_xy(bool swap_xy) { this->swap_xy_ = swap_xy; }
81 void set_mirror_x(bool mirror_x) { this->mirror_x_ = mirror_x; }
82 void set_mirror_y(bool mirror_y) { this->mirror_y_ = mirror_y; }
84
85 void update() override;
86
87 void fill(Color color) override;
88
89 void dump_config() override;
90 void setup() override;
91 void on_powerdown() override { this->command(ILI9XXX_SLPIN); }
92
94 void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
95 display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
96
97 protected:
98 inline bool check_buffer_() {
99 if (this->buffer_ == nullptr) {
100 if (!this->is_failed())
101 this->alloc_buffer_();
102 return !this->is_failed();
103 }
104 return true;
105 }
106
107 void draw_absolute_pixel_internal(int x, int y, Color color) override;
108 void setup_pins_();
109
110 virtual void set_madctl();
111 void display_();
112 void init_lcd_(const uint8_t *addr);
113 void set_addr_window_(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2);
114 void reset_();
115
116 uint8_t const *init_sequence_{};
117 std::vector<uint8_t> extra_init_sequence_;
118 int16_t width_{0};
119 int16_t height_{0};
120 int16_t offset_x_{0};
121 int16_t offset_y_{0};
122 uint16_t x_low_{0};
123 uint16_t y_low_{0};
124 uint16_t x_high_{0};
125 uint16_t y_high_{0};
126 const uint8_t *palette_{};
127
129
131 int get_width_internal() override;
132 int get_height_internal() override;
133
134 void start_command_();
135 void end_command_();
136 void start_data_();
137 void end_data_();
138 void alloc_buffer_();
139
141 GPIOPin *dc_pin_{nullptr};
143
144 bool prossing_update_ = false;
145 bool need_update_ = false;
146 bool is_18bitdisplay_ = false;
150 bool swap_xy_{};
151 bool mirror_x_{};
152 bool mirror_y_{};
153};
154
155//----------- M5Stack display --------------
157 public:
158 ILI9XXXM5Stack() : ILI9XXXDisplay(INITCMD_M5STACK, 320, 240) {}
159};
160
161//----------- M5Stack display --------------
163 public:
164 ILI9XXXM5CORE() : ILI9XXXDisplay(INITCMD_M5CORE, 320, 240) {}
165};
166
167//----------- ST7789V display --------------
169 public:
170 ILI9XXXST7789V() : ILI9XXXDisplay(INITCMD_ST7789V, 240, 320) {}
171};
172
173//----------- ILI9XXX_24_TFT display --------------
175 public:
176 ILI9XXXILI9341() : ILI9XXXDisplay(INITCMD_ILI9341, 240, 320) {}
177};
178
179//----------- ILI9XXX_24_TFT rotated display --------------
181 public:
182 ILI9XXXILI9342() : ILI9XXXDisplay(INITCMD_ILI9341, 320, 240) {}
183};
184
185//----------- ILI9XXX_??_TFT rotated display --------------
187 public:
188 ILI9XXXILI9481() : ILI9XXXDisplay(INITCMD_ILI9481, 480, 320) {}
189};
190
191//----------- ILI9481 in 18 bit mode --------------
193 public:
194 ILI9XXXILI948118() : ILI9XXXDisplay(INITCMD_ILI9481_18, 320, 480) {}
195};
196
197//----------- ILI9XXX_35_TFT rotated display --------------
199 public:
200 ILI9XXXILI9486() : ILI9XXXDisplay(INITCMD_ILI9486, 480, 320) {}
201};
202
204 public:
205 ILI9XXXILI9488(const uint8_t *seq = INITCMD_ILI9488) : ILI9XXXDisplay(seq, 480, 320) {}
206
207 protected:
208 void set_madctl() override {
209 uint8_t mad = this->color_order_ == display::COLOR_ORDER_BGR ? MADCTL_BGR : MADCTL_RGB;
210 uint8_t dfun = 0x22;
211 this->width_ = 320;
212 this->height_ = 480;
213 if (!(this->swap_xy_ || this->mirror_x_ || this->mirror_y_)) {
214 // no transforms
215 } else if (this->mirror_y_ && this->mirror_x_) {
216 // rotate 180
217 dfun = 0x42;
218 } else if (this->swap_xy_) {
219 this->width_ = 480;
220 this->height_ = 320;
221 mad |= 0x20;
222 if (this->mirror_x_) {
223 dfun = 0x02;
224 } else {
225 dfun = 0x62;
226 }
227 }
228 this->command(ILI9XXX_DFUNCTR);
229 this->data(0);
230 this->data(dfun);
231 this->command(ILI9XXX_MADCTL);
232 this->data(mad);
233 }
234};
235//----------- Waveshare 3.5 Res Touch - ILI9488 interfaced via 16 bit shift register to parallel */
237 public:
238 WAVESHARERES35() : ILI9XXXILI9488(INITCMD_WAVESHARE_RES_3_5) {}
239 void data(uint8_t value) override {
240 this->start_data_();
241 this->write_byte(0);
242 this->write_byte(value);
243 this->end_data_();
244 }
245};
246
247//----------- ILI9XXX_35_TFT origin colors rotated display --------------
249 public:
250 ILI9XXXILI9488A() : ILI9XXXDisplay(INITCMD_ILI9488_A, 480, 320) {}
251};
252
253//----------- ILI9XXX_35_TFT rotated display --------------
255 public:
256 ILI9XXXST7796() : ILI9XXXDisplay(INITCMD_ST7796, 320, 480) {}
257};
258
260 public:
261 ILI9XXXS3Box() : ILI9XXXDisplay(INITCMD_S3BOX, 320, 240) {}
262};
263
265 public:
266 ILI9XXXS3BoxLite() : ILI9XXXDisplay(INITCMD_S3BOXLITE, 320, 240) {}
267};
268
270 public:
271 ILI9XXXGC9A01A() : ILI9XXXDisplay(INITCMD_GC9A01A, 240, 240) {}
272};
273
275 public:
276 ILI9XXXGC9D01N() : ILI9XXXDisplay(INITCMD_GC9D01N, 160, 160) {}
277};
278
279//----------- ILI9XXX_24_TFT display --------------
281 public:
282 ILI9XXXST7735() : ILI9XXXDisplay(INITCMD_ST7735, 128, 160) {}
283};
284
285} // namespace esphome::ili9xxx
BedjetMode mode
BedJet operating mode.
uint8_t h
Definition bl0906.h:2
bool is_failed() const
Definition component.h:284
void set_pixel_mode(PixelMode mode)
virtual void data(uint8_t value)
void set_dc_pin(GPIOPin *dc_pin)
int16_t width_
Display width as modified by current rotation.
std::vector< uint8_t > extra_init_sequence_
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order, display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override
float get_setup_priority() const override
void set_addr_window_(uint16_t x, uint16_t y, uint16_t x2, uint16_t y2)
void set_color_order(display::ColorOrder color_order)
void add_init_sequence(const std::vector< uint8_t > &sequence)
display::DisplayType get_display_type() override
void init_lcd_(const uint8_t *addr)
void set_offsets(int16_t offset_x, int16_t offset_y)
void set_palette(const uint8_t *palette)
virtual void command(uint8_t value)
void draw_absolute_pixel_internal(int x, int y, Color color) override
void fill(Color color) override
void set_reset_pin(GPIOPin *reset)
void set_dimensions(int16_t width, int16_t height)
void set_buffer_color_mode(ILI9XXXColorMode color_mode)
ILI9XXXDisplay(uint8_t const *init_sequence, int16_t width, int16_t height)
void send_command(uint8_t command_byte, const uint8_t *data_bytes, uint8_t num_data_bytes)
int16_t height_
Display height as modified by current rotation.
ILI9XXXILI9488(const uint8_t *seq=INITCMD_ILI9488)
void data(uint8_t value) override
The SPIDevice is what components using the SPI will create.
Definition spi.h:429
uint16_t reset
Definition ina226.h:5
const size_t ILI9XXX_TRANSFER_BUFFER_SIZE
static void uint32_t
uint16_t seq
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6