ESPHome 2025.10.0-dev
Loading...
Searching...
No Matches
mipi_rgb.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32_VARIANT_ESP32S3
4#include "esphome/core/gpio.h"
6#include "esp_lcd_panel_ops.h"
7#ifdef USE_SPI
9#endif
10
11namespace esphome {
12namespace mipi_rgb {
13
14constexpr static const char *const TAG = "display.mipi_rgb";
15const uint8_t SW_RESET_CMD = 0x01;
16const uint8_t SLEEP_OUT = 0x11;
17const uint8_t SDIR_CMD = 0xC7;
18const uint8_t MADCTL_CMD = 0x36;
19const uint8_t INVERT_OFF = 0x20;
20const uint8_t INVERT_ON = 0x21;
21const uint8_t DISPLAY_ON = 0x29;
22const uint8_t CMD2_BKSEL = 0xFF;
23const uint8_t CMD2_BK0[5] = {0x77, 0x01, 0x00, 0x00, 0x10};
24
25class MipiRgb : public display::Display {
26 public:
27 MipiRgb(int width, int height) : width_(width), height_(height) {}
28 void setup() override;
29 void loop() override;
30 void update() override;
31 void fill(Color color);
32 void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
33 display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) override;
34 void write_to_display_(int x_start, int y_start, int w, int h, const uint8_t *ptr, int x_offset, int y_offset,
35 int x_pad);
36 bool check_buffer_();
37
39 void set_color_mode(display::ColorOrder color_mode) { this->color_mode_ = color_mode; }
40 void set_invert_colors(bool invert_colors) { this->invert_colors_ = invert_colors; }
41 void set_madctl(uint8_t madctl) { this->madctl_ = madctl; }
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_pins_(uint8_t start, uint8_t end, const char *name, uint8_t offset);
66 void dump_config() override;
67 void draw_pixel_at(int x, int y, Color color) override;
68
69 // this will be horribly slow.
70 protected:
71 void setup_enables_();
72 void common_setup_();
79 uint16_t hsync_pulse_width_ = 10;
80 uint16_t hsync_back_porch_ = 10;
81 uint16_t hsync_front_porch_ = 20;
82 uint16_t vsync_pulse_width_ = 10;
83 uint16_t vsync_back_porch_ = 10;
84 uint16_t vsync_front_porch_ = 10;
85 uint32_t pclk_frequency_ = 16 * 1000 * 1000;
86 bool pclk_inverted_{true};
87 uint8_t madctl_{};
88 const char *model_{"Unknown"};
91 size_t width_;
92 size_t height_;
93 uint16_t *buffer_{nullptr};
94 std::vector<GPIOPin *> enable_pins_{};
95 uint16_t x_low_{1};
96 uint16_t y_low_{1};
97 uint16_t x_high_{0};
98 uint16_t y_high_{0};
99
100 esp_lcd_panel_handle_t handle_{};
101};
102
103#ifdef USE_SPI
104class MipiRgbSpi : public MipiRgb,
105 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
106 spi::DATA_RATE_1MHZ> {
107 public:
108 MipiRgbSpi(int width, int height) : MipiRgb(width, height) {}
109
110 void set_init_sequence(const std::vector<uint8_t> &init_sequence) { this->init_sequence_ = init_sequence; }
111 void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
112 void setup() override;
113
114 protected:
115 void write_command_(uint8_t value);
116 void write_data_(uint8_t value);
118 void dump_config();
119
120 GPIOPin *dc_pin_{nullptr};
121 std::vector<uint8_t> init_sequence_;
122};
123#endif
124
125} // namespace mipi_rgb
126} // namespace esphome
127#endif
uint8_t h
Definition bl0906.h:2
display::ColorOrder get_color_mode()
Definition mipi_rgb.h:38
InternalGPIOPin * de_pin_
Definition mipi_rgb.h:73
std::vector< GPIOPin * > enable_pins_
Definition mipi_rgb.h:94
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:207
void set_de_pin(InternalGPIOPin *de_pin)
Definition mipi_rgb.h:44
esp_lcd_panel_handle_t handle_
Definition mipi_rgb.h:100
void set_enable_pins(std::vector< GPIOPin * > enable_pins)
Definition mipi_rgb.h:61
int get_height() override
Definition mipi_rgb.cpp:322
InternalGPIOPin * hsync_pin_
Definition mipi_rgb.h:75
display::ColorOrder color_mode_
Definition mipi_rgb.h:90
void dump_config() override
Definition mipi_rgb.cpp:346
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 set_vsync_back_porch(uint16_t vsync_back_porch)
Definition mipi_rgb.h:59
void fill(Color color)
Definition mipi_rgb.cpp:300
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:40
void set_pclk_inverted(bool inverted)
Definition mipi_rgb.h:51
InternalGPIOPin * data_pins_[16]
Definition mipi_rgb.h:78
void draw_pixel_at(int x, int y, Color color) override
Definition mipi_rgb.cpp:258
void set_vsync_front_porch(uint16_t vsync_front_porch)
Definition mipi_rgb.h:60
MipiRgb(int width, int height)
Definition mipi_rgb.h:27
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:76
void dump_pins_(uint8_t start, uint8_t end, const char *name, uint8_t offset)
Definition mipi_rgb.cpp:340
void set_pclk_pin(InternalGPIOPin *pclk_pin)
Definition mipi_rgb.h:45
InternalGPIOPin * pclk_pin_
Definition mipi_rgb.h:74
void set_madctl(uint8_t madctl)
Definition mipi_rgb.h:41
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:39
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:222
void set_reset_pin(GPIOPin *reset_pin)
Definition mipi_rgb.h:48
void write_data_(uint8_t value)
Definition mipi_rgb.cpp:56
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:71
MipiRgbSpi(int width, int height)
Definition mipi_rgb.h:108
void write_command_(uint8_t value)
Definition mipi_rgb.cpp:44
void set_dc_pin(GPIOPin *dc_pin)
Definition mipi_rgb.h:111
void set_init_sequence(const std::vector< uint8_t > &init_sequence)
Definition mipi_rgb.h:110
std::vector< uint8_t > init_sequence_
Definition mipi_rgb.h:121
The SPIDevice is what components using the SPI will create.
Definition spi.h:427
const uint8_t SLEEP_OUT
Definition mipi_rgb.h:16
const uint8_t MADCTL_CMD
Definition mipi_rgb.h:18
const uint8_t CMD2_BK0[5]
Definition mipi_rgb.h:23
const uint8_t CMD2_BKSEL
Definition mipi_rgb.h:22
const uint8_t SW_RESET_CMD
Definition mipi_rgb.h:15
const uint8_t SDIR_CMD
Definition mipi_rgb.h:17
const uint8_t INVERT_ON
Definition mipi_rgb.h:20
const uint8_t DISPLAY_ON
Definition mipi_rgb.h:21
const uint8_t INVERT_OFF
Definition mipi_rgb.h:19
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint8_t end[39]
Definition sun_gtil2.cpp:17
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6