ESPHome 2025.5.0
Loading...
Searching...
No Matches
qspi_dbi.h
Go to the documentation of this file.
1//
2// Created by Clyde Stubbs on 29/10/2023.
3//
4#pragma once
5
6#if defined(USE_ESP_IDF) && defined(USE_ESP32_VARIANT_ESP32S3)
11
12#include "esp_lcd_panel_rgb.h"
13
14namespace esphome {
15namespace qspi_dbi {
16
17constexpr static const char *const TAG = "display.qspi_dbi";
18static const uint8_t SW_RESET_CMD = 0x01;
19static const uint8_t SLEEP_OUT = 0x11;
20static const uint8_t NORON = 0x13;
21static const uint8_t INVERT_OFF = 0x20;
22static const uint8_t INVERT_ON = 0x21;
23static const uint8_t ALL_ON = 0x23;
24static const uint8_t WRAM = 0x24;
25static const uint8_t MIPI = 0x26;
26static const uint8_t DISPLAY_ON = 0x29;
27static const uint8_t RASET = 0x2B;
28static const uint8_t CASET = 0x2A;
29static const uint8_t WDATA = 0x2C;
30static const uint8_t TEON = 0x35;
31static const uint8_t MADCTL_CMD = 0x36;
32static const uint8_t PIXFMT = 0x3A;
33static const uint8_t BRIGHTNESS = 0x51;
34static const uint8_t SWIRE1 = 0x5A;
35static const uint8_t SWIRE2 = 0x5B;
36static const uint8_t PAGESEL = 0xFE;
37
38static const uint8_t MADCTL_MY = 0x80;
39static const uint8_t MADCTL_MX = 0x40;
40static const uint8_t MADCTL_MV = 0x20;
41static const uint8_t MADCTL_RGB = 0x00;
42static const uint8_t MADCTL_BGR = 0x08;
43
44static const uint8_t DELAY_FLAG = 0xFF;
45// store a 16 bit value in a buffer, big endian.
46static inline void put16_be(uint8_t *buf, uint16_t value) {
47 buf[0] = value >> 8;
48 buf[1] = value;
49}
50
56
58 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
59 spi::DATA_RATE_1MHZ> {
60 public:
61 void set_model(const char *model) { this->model_ = model; }
62 void update() override;
63 void setup() override;
65 void set_color_mode(display::ColorOrder color_mode) { this->color_mode_ = color_mode; }
66
67 void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
68 void set_enable_pin(GPIOPin *enable_pin) { this->enable_pin_ = enable_pin; }
69 void set_dimensions(uint16_t width, uint16_t height) {
70 this->width_ = width;
71 this->height_ = height;
72 }
73 void set_invert_colors(bool invert_colors) {
74 this->invert_colors_ = invert_colors;
75 this->reset_params_();
76 }
77 void set_mirror_x(bool mirror_x) {
78 this->mirror_x_ = mirror_x;
79 this->reset_params_();
80 }
81 void set_mirror_y(bool mirror_y) {
82 this->mirror_y_ = mirror_y;
83 this->reset_params_();
84 }
85 void set_swap_xy(bool swap_xy) {
86 this->swap_xy_ = swap_xy;
87 this->reset_params_();
88 }
89 void set_brightness(uint8_t brightness) {
90 this->brightness_ = brightness;
91 this->reset_params_();
92 }
93 void set_offsets(int16_t offset_x, int16_t offset_y) {
94 this->offset_x_ = offset_x;
95 this->offset_y_ = offset_y;
96 }
97
98 void set_draw_from_origin(bool draw_from_origin) { this->draw_from_origin_ = draw_from_origin; }
100 void dump_config() override;
101
102 int get_width_internal() override { return this->width_; }
103 int get_height_internal() override { return this->height_; }
104 bool can_proceed() override { return this->setup_complete_; }
105 void add_init_sequence(const std::vector<uint8_t> &sequence) { this->init_sequences_.push_back(sequence); }
106 void set_draw_rounding(unsigned rounding) { this->draw_rounding_ = rounding; }
107
108 protected:
110 if (this->buffer_ == nullptr)
111 this->init_internal_(this->width_ * this->height_ * 2);
112 }
113 void write_sequence_(const std::vector<uint8_t> &vec);
114 void draw_absolute_pixel_internal(int x, int y, Color color) override;
115 void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
116 display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
117 void write_to_display_(int x_start, int y_start, int w, int h, const uint8_t *ptr, int x_offset, int y_offset,
118 int x_pad);
137 void write_command_(uint8_t cmd, const uint8_t *bytes, size_t len);
138
139 void write_command_(uint8_t cmd, uint8_t data) { this->write_command_(cmd, &data, 1); }
140 void write_command_(uint8_t cmd) { this->write_command_(cmd, &cmd, 0); }
141 void reset_params_(bool ready = false);
143 void set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
144
147 uint16_t x_low_{1};
148 uint16_t y_low_{1};
149 uint16_t x_high_{0};
150 uint16_t y_high_{0};
152
155 size_t width_{};
156 size_t height_{};
157 int16_t offset_x_{0};
158 int16_t offset_y_{0};
159 bool swap_xy_{};
160 bool mirror_x_{};
161 bool mirror_y_{};
162 bool draw_from_origin_{false};
163 unsigned draw_rounding_{2};
164 uint8_t brightness_{0xD0};
165 const char *model_{"Unknown"};
166 std::vector<std::vector<uint8_t>> init_sequences_{};
167
168 esp_lcd_panel_handle_t handle_{};
169};
170
171} // namespace qspi_dbi
172} // namespace esphome
173#endif
uint8_t h
Definition bl0906.h:2
void init_internal_(uint32_t buffer_length)
void set_mirror_x(bool mirror_x)
Definition qspi_dbi.h:77
void set_color_mode(display::ColorOrder color_mode)
Definition qspi_dbi.h:65
void set_draw_rounding(unsigned rounding)
Definition qspi_dbi.h:106
void write_sequence_(const std::vector< uint8_t > &vec)
Definition qspi_dbi.cpp:185
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
Definition qspi_dbi.cpp:134
int get_width_internal() override
Definition qspi_dbi.h:102
void set_addr_window_(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
Definition qspi_dbi.cpp:119
void write_to_display_(int x_start, int y_start, int w, int h, const uint8_t *ptr, int x_offset, int y_offset, int x_pad)
Definition qspi_dbi.cpp:161
bool can_proceed() override
Definition qspi_dbi.h:104
void write_command_(uint8_t cmd, uint8_t data)
Definition qspi_dbi.h:139
void write_command_(uint8_t cmd, const uint8_t *bytes, size_t len)
the RM67162 in quad SPI mode seems to work like this (not in the datasheet, this is deduced from the ...
Definition qspi_dbi.cpp:178
void add_init_sequence(const std::vector< uint8_t > &sequence)
Definition qspi_dbi.h:105
void set_model(const char *model)
Definition qspi_dbi.h:61
esp_lcd_panel_handle_t handle_
Definition qspi_dbi.h:168
display::DisplayType get_display_type() override
Definition qspi_dbi.h:99
void set_offsets(int16_t offset_x, int16_t offset_y)
Definition qspi_dbi.h:93
display::ColorOrder color_mode_
Definition qspi_dbi.h:154
void dump_config() override
Definition qspi_dbi.cpp:210
void set_mirror_y(bool mirror_y)
Definition qspi_dbi.h:81
void setup() override
Definition qspi_dbi.cpp:8
void set_dimensions(uint16_t width, uint16_t height)
Definition qspi_dbi.h:69
void set_invert_colors(bool invert_colors)
Definition qspi_dbi.h:73
void set_enable_pin(GPIOPin *enable_pin)
Definition qspi_dbi.h:68
void reset_params_(bool ready=false)
Definition qspi_dbi.cpp:93
std::vector< std::vector< uint8_t > > init_sequences_
Definition qspi_dbi.h:166
void set_swap_xy(bool swap_xy)
Definition qspi_dbi.h:85
int get_height_internal() override
Definition qspi_dbi.h:103
void update() override
Definition qspi_dbi.cpp:29
void set_draw_from_origin(bool draw_from_origin)
Definition qspi_dbi.h:98
void set_reset_pin(GPIOPin *reset_pin)
Definition qspi_dbi.h:67
void draw_absolute_pixel_internal(int x, int y, Color color) override
Definition qspi_dbi.cpp:58
void write_command_(uint8_t cmd)
Definition qspi_dbi.h:140
display::ColorOrder get_color_mode()
Definition qspi_dbi.h:64
void set_brightness(uint8_t brightness)
Definition qspi_dbi.h:89
The SPIDevice is what components using the SPI will create.
Definition spi.h:421
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:301
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6