ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
mipi_rgb.h
Go to the documentation of this file.
1#pragma once
2
3#if defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32P4) || defined(USE_ESP32_VARIANT_ESP32S31)
4#include "esphome/core/gpio.h"
6#include <esp_lcd_panel_rgb.h>
7#ifdef USE_SPI
9#endif
10
11namespace esphome::mipi_rgb {
12
13constexpr static const char *const TAG = "display.mipi_rgb";
14const uint8_t SW_RESET_CMD = 0x01;
15const uint8_t SLEEP_OUT = 0x11;
16const uint8_t SDIR_CMD = 0xC7;
17const uint8_t MADCTL_CMD = 0x36;
18const uint8_t INVERT_OFF = 0x20;
19const uint8_t INVERT_ON = 0x21;
20const uint8_t DISPLAY_ON = 0x29;
21const uint8_t CMD2_BKSEL = 0xFF;
22const uint8_t CMD2_BK0[5] = {0x77, 0x01, 0x00, 0x00, 0x10};
23
24class MipiRgb : public display::Display {
25 public:
26 MipiRgb(int width, int height) : width_(width), height_(height) {}
27 void setup() override;
28#ifdef USE_ESP32_VARIANT_ESP32S3
29 void loop() override {
30 if (this->handle_ != nullptr)
31 esp_lcd_rgb_panel_restart(this->handle_);
32 }
33#endif
34 void update() override;
35 void fill(Color color) override;
36 void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
37 display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
38
40 void set_color_mode(display::ColorOrder color_mode) { this->color_mode_ = color_mode; }
41 void set_invert_colors(bool invert_colors) { this->invert_colors_ = invert_colors; }
42
43 void add_data_pin(InternalGPIOPin *data_pin, size_t index) { this->data_pins_[index] = data_pin; };
44 void set_de_pin(InternalGPIOPin *de_pin) { this->de_pin_ = de_pin; }
45 void set_pclk_pin(InternalGPIOPin *pclk_pin) { this->pclk_pin_ = pclk_pin; }
46 void set_vsync_pin(InternalGPIOPin *vsync_pin) { this->vsync_pin_ = vsync_pin; }
47 void set_hsync_pin(InternalGPIOPin *hsync_pin) { this->hsync_pin_ = hsync_pin; }
48 void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
49 void set_width(uint16_t width) { this->width_ = width; }
50 void set_pclk_frequency(uint32_t pclk_frequency) { this->pclk_frequency_ = pclk_frequency; }
51 void set_pclk_inverted(bool inverted) { this->pclk_inverted_ = inverted; }
52 void set_model(const char *model) { this->model_ = model; }
53 int get_width() override;
54 int get_height() override;
55 void set_hsync_back_porch(uint16_t hsync_back_porch) { this->hsync_back_porch_ = hsync_back_porch; }
56 void set_hsync_front_porch(uint16_t hsync_front_porch) { this->hsync_front_porch_ = hsync_front_porch; }
57 void set_hsync_pulse_width(uint16_t hsync_pulse_width) { this->hsync_pulse_width_ = hsync_pulse_width; }
58 void set_vsync_pulse_width(uint16_t vsync_pulse_width) { this->vsync_pulse_width_ = vsync_pulse_width; }
59 void set_vsync_back_porch(uint16_t vsync_back_porch) { this->vsync_back_porch_ = vsync_back_porch; }
60 void set_vsync_front_porch(uint16_t vsync_front_porch) { this->vsync_front_porch_ = vsync_front_porch; }
61 void set_enable_pins(std::vector<GPIOPin *> enable_pins) { this->enable_pins_ = std::move(enable_pins); }
63 int get_width_internal() override { return this->width_; }
64 int get_height_internal() override { return this->height_; }
65 void dump_config() override;
66 void draw_pixel_at(int x, int y, Color color) override;
67
68 // this will be horribly slow.
69 protected:
70 void write_to_display_(int x_start, int y_start, int w, int h, const uint8_t *ptr, int x_offset, int y_offset,
71 int x_pad);
72 bool check_buffer_();
73 void dump_pins_(uint8_t start, uint8_t end, const char *name, uint8_t offset);
74 void setup_enables_();
75 void common_setup_();
82 uint16_t hsync_pulse_width_ = 10;
83 uint16_t hsync_back_porch_ = 10;
84 uint16_t hsync_front_porch_ = 20;
85 uint16_t vsync_pulse_width_ = 10;
86 uint16_t vsync_back_porch_ = 10;
87 uint16_t vsync_front_porch_ = 10;
88 uint32_t pclk_frequency_ = 16 * 1000 * 1000;
89 bool pclk_inverted_{true};
90 const char *model_{"Unknown"};
93 size_t width_;
94 size_t height_;
95 uint16_t *buffer_{nullptr};
96 std::vector<GPIOPin *> enable_pins_{};
97 uint16_t x_low_{1};
98 uint16_t y_low_{1};
99 uint16_t x_high_{0};
100 uint16_t y_high_{0};
101
102 esp_lcd_panel_handle_t handle_{};
103};
104
105#ifdef USE_SPI
106class MipiRgbSpi final : public MipiRgb,
107 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
108 spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ> {
109 public:
110 MipiRgbSpi(int width, int height) : MipiRgb(width, height) {}
111
112 void set_init_sequence(const std::vector<uint8_t> &init_sequence) { this->init_sequence_ = init_sequence; }
113 void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
114 void setup() override;
115
116 protected:
117 void write_command_(uint8_t value);
118 void write_data_(uint8_t value);
120 void dump_config() override;
121
122 GPIOPin *dc_pin_{nullptr};
123 std::vector<uint8_t> init_sequence_;
124};
125#endif
126
127} // namespace esphome::mipi_rgb
128#endif
uint8_t h
Definition bl0906.h:2
display::ColorOrder get_color_mode()
Definition mipi_rgb.h:39
InternalGPIOPin * de_pin_
Definition mipi_rgb.h:76
std::vector< GPIOPin * > enable_pins_
Definition mipi_rgb.h:96
display::DisplayType get_display_type() override
Definition mipi_rgb.h:62
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 mipi_rgb.cpp:209
void set_de_pin(InternalGPIOPin *de_pin)
Definition mipi_rgb.h:44
esp_lcd_panel_handle_t handle_
Definition mipi_rgb.h:102
void set_enable_pins(std::vector< GPIOPin * > enable_pins)
Definition mipi_rgb.h:61
int get_height() override
Definition mipi_rgb.cpp:332
InternalGPIOPin * hsync_pin_
Definition mipi_rgb.h:78
display::ColorOrder color_mode_
Definition mipi_rgb.h:92
void dump_config() override
Definition mipi_rgb.cpp:359
void set_vsync_pin(InternalGPIOPin *vsync_pin)
Definition mipi_rgb.h:46
void set_hsync_back_porch(uint16_t hsync_back_porch)
Definition mipi_rgb.h:55
void set_hsync_pin(InternalGPIOPin *hsync_pin)
Definition mipi_rgb.h:47
void loop() override
Definition mipi_rgb.h:29
void set_vsync_back_porch(uint16_t vsync_back_porch)
Definition mipi_rgb.h:59
int get_height_internal() override
Definition mipi_rgb.h:64
void add_data_pin(InternalGPIOPin *data_pin, size_t index)
Definition mipi_rgb.h:43
void set_model(const char *model)
Definition mipi_rgb.h:52
void set_pclk_frequency(uint32_t pclk_frequency)
Definition mipi_rgb.h:50
void set_invert_colors(bool invert_colors)
Definition mipi_rgb.h:41
void set_pclk_inverted(bool inverted)
Definition mipi_rgb.h:51
InternalGPIOPin * data_pins_[16]
Definition mipi_rgb.h:81
void draw_pixel_at(int x, int y, Color color) override
Definition mipi_rgb.cpp:261
void set_vsync_front_porch(uint16_t vsync_front_porch)
Definition mipi_rgb.h:60
MipiRgb(int width, int height)
Definition mipi_rgb.h:26
void set_hsync_front_porch(uint16_t hsync_front_porch)
Definition mipi_rgb.h:56
void set_width(uint16_t width)
Definition mipi_rgb.h:49
InternalGPIOPin * vsync_pin_
Definition mipi_rgb.h:79
void dump_pins_(uint8_t start, uint8_t end, const char *name, uint8_t offset)
Definition mipi_rgb.cpp:351
void set_pclk_pin(InternalGPIOPin *pclk_pin)
Definition mipi_rgb.h:45
InternalGPIOPin * pclk_pin_
Definition mipi_rgb.h:77
void fill(Color color) override
Definition mipi_rgb.cpp:301
void set_hsync_pulse_width(uint16_t hsync_pulse_width)
Definition mipi_rgb.h:57
void set_vsync_pulse_width(uint16_t vsync_pulse_width)
Definition mipi_rgb.h:58
int get_width_internal() override
Definition mipi_rgb.h:63
void set_color_mode(display::ColorOrder color_mode)
Definition mipi_rgb.h:40
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 mipi_rgb.cpp:224
void set_reset_pin(GPIOPin *reset_pin)
Definition mipi_rgb.h:48
void write_data_(uint8_t value)
Definition mipi_rgb.cpp:62
void write_init_sequence_()
this relies upon the init sequence being well-formed, which is guaranteed by the Python init code.
Definition mipi_rgb.cpp:77
MipiRgbSpi(int width, int height)
Definition mipi_rgb.h:110
void write_command_(uint8_t value)
Definition mipi_rgb.cpp:50
void set_dc_pin(GPIOPin *dc_pin)
Definition mipi_rgb.h:113
void set_init_sequence(const std::vector< uint8_t > &init_sequence)
Definition mipi_rgb.h:112
std::vector< uint8_t > init_sequence_
Definition mipi_rgb.h:123
The SPIDevice is what components using the SPI will create.
Definition spi.h:450
const uint8_t SLEEP_OUT
Definition mipi_rgb.h:15
const uint8_t MADCTL_CMD
Definition mipi_rgb.h:17
const uint8_t CMD2_BK0[5]
Definition mipi_rgb.h:22
const uint8_t CMD2_BKSEL
Definition mipi_rgb.h:21
const uint8_t SW_RESET_CMD
Definition mipi_rgb.h:14
const uint8_t SDIR_CMD
Definition mipi_rgb.h:16
const uint8_t INVERT_ON
Definition mipi_rgb.h:19
const uint8_t DISPLAY_ON
Definition mipi_rgb.h:20
const uint8_t INVERT_OFF
Definition mipi_rgb.h:18
static void uint32_t
uint8_t end[39]
Definition sun_gtil2.cpp:17
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6