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