ESPHome 2026.5.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)
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) override;
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
42 void add_data_pin(InternalGPIOPin *data_pin, size_t index) { this->data_pins_[index] = data_pin; };
43 void set_de_pin(InternalGPIOPin *de_pin) { this->de_pin_ = de_pin; }
44 void set_pclk_pin(InternalGPIOPin *pclk_pin) { this->pclk_pin_ = pclk_pin; }
45 void set_vsync_pin(InternalGPIOPin *vsync_pin) { this->vsync_pin_ = vsync_pin; }
46 void set_hsync_pin(InternalGPIOPin *hsync_pin) { this->hsync_pin_ = hsync_pin; }
47 void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
48 void set_width(uint16_t width) { this->width_ = width; }
49 void set_pclk_frequency(uint32_t pclk_frequency) { this->pclk_frequency_ = pclk_frequency; }
50 void set_pclk_inverted(bool inverted) { this->pclk_inverted_ = inverted; }
51 void set_model(const char *model) { this->model_ = model; }
52 int get_width() override;
53 int get_height() override;
54 void set_hsync_back_porch(uint16_t hsync_back_porch) { this->hsync_back_porch_ = hsync_back_porch; }
55 void set_hsync_front_porch(uint16_t hsync_front_porch) { this->hsync_front_porch_ = hsync_front_porch; }
56 void set_hsync_pulse_width(uint16_t hsync_pulse_width) { this->hsync_pulse_width_ = hsync_pulse_width; }
57 void set_vsync_pulse_width(uint16_t vsync_pulse_width) { this->vsync_pulse_width_ = vsync_pulse_width; }
58 void set_vsync_back_porch(uint16_t vsync_back_porch) { this->vsync_back_porch_ = vsync_back_porch; }
59 void set_vsync_front_porch(uint16_t vsync_front_porch) { this->vsync_front_porch_ = vsync_front_porch; }
60 void set_enable_pins(std::vector<GPIOPin *> enable_pins) { this->enable_pins_ = std::move(enable_pins); }
62 int get_width_internal() override { return this->width_; }
63 int get_height_internal() override { return this->height_; }
64 void dump_pins_(uint8_t start, uint8_t end, const char *name, uint8_t offset);
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 setup_enables_();
71 void common_setup_();
78 uint16_t hsync_pulse_width_ = 10;
79 uint16_t hsync_back_porch_ = 10;
80 uint16_t hsync_front_porch_ = 20;
81 uint16_t vsync_pulse_width_ = 10;
82 uint16_t vsync_back_porch_ = 10;
83 uint16_t vsync_front_porch_ = 10;
84 uint32_t pclk_frequency_ = 16 * 1000 * 1000;
85 bool pclk_inverted_{true};
86 const char *model_{"Unknown"};
89 size_t width_;
90 size_t height_;
91 uint16_t *buffer_{nullptr};
92 std::vector<GPIOPin *> enable_pins_{};
93 uint16_t x_low_{1};
94 uint16_t y_low_{1};
95 uint16_t x_high_{0};
96 uint16_t y_high_{0};
97
98 esp_lcd_panel_handle_t handle_{};
99};
100
101#ifdef USE_SPI
102class MipiRgbSpi : public MipiRgb,
103 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
104 spi::DATA_RATE_1MHZ> {
105 public:
106 MipiRgbSpi(int width, int height) : MipiRgb(width, height) {}
107
108 void set_init_sequence(const std::vector<uint8_t> &init_sequence) { this->init_sequence_ = init_sequence; }
109 void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
110 void setup() override;
111
112 protected:
113 void write_command_(uint8_t value);
114 void write_data_(uint8_t value);
116 void dump_config() override;
117
118 GPIOPin *dc_pin_{nullptr};
119 std::vector<uint8_t> init_sequence_;
120};
121#endif
122
123} // namespace mipi_rgb
124} // namespace esphome
125#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:72
std::vector< GPIOPin * > enable_pins_
Definition mipi_rgb.h:92
display::DisplayType get_display_type() override
Definition mipi_rgb.h:61
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:215
void set_de_pin(InternalGPIOPin *de_pin)
Definition mipi_rgb.h:43
esp_lcd_panel_handle_t handle_
Definition mipi_rgb.h:98
void set_enable_pins(std::vector< GPIOPin * > enable_pins)
Definition mipi_rgb.h:60
int get_height() override
Definition mipi_rgb.cpp:337
InternalGPIOPin * hsync_pin_
Definition mipi_rgb.h:74
display::ColorOrder color_mode_
Definition mipi_rgb.h:88
void dump_config() override
Definition mipi_rgb.cpp:364
void set_vsync_pin(InternalGPIOPin *vsync_pin)
Definition mipi_rgb.h:45
void set_hsync_back_porch(uint16_t hsync_back_porch)
Definition mipi_rgb.h:54
void set_hsync_pin(InternalGPIOPin *hsync_pin)
Definition mipi_rgb.h:46
void set_vsync_back_porch(uint16_t vsync_back_porch)
Definition mipi_rgb.h:58
int get_height_internal() override
Definition mipi_rgb.h:63
void add_data_pin(InternalGPIOPin *data_pin, size_t index)
Definition mipi_rgb.h:42
void set_model(const char *model)
Definition mipi_rgb.h:51
void set_pclk_frequency(uint32_t pclk_frequency)
Definition mipi_rgb.h:49
void set_invert_colors(bool invert_colors)
Definition mipi_rgb.h:40
void set_pclk_inverted(bool inverted)
Definition mipi_rgb.h:50
InternalGPIOPin * data_pins_[16]
Definition mipi_rgb.h:77
void draw_pixel_at(int x, int y, Color color) override
Definition mipi_rgb.cpp:266
void set_vsync_front_porch(uint16_t vsync_front_porch)
Definition mipi_rgb.h:59
MipiRgb(int width, int height)
Definition mipi_rgb.h:27
void set_hsync_front_porch(uint16_t hsync_front_porch)
Definition mipi_rgb.h:55
void set_width(uint16_t width)
Definition mipi_rgb.h:48
InternalGPIOPin * vsync_pin_
Definition mipi_rgb.h:75
void dump_pins_(uint8_t start, uint8_t end, const char *name, uint8_t offset)
Definition mipi_rgb.cpp:356
void set_pclk_pin(InternalGPIOPin *pclk_pin)
Definition mipi_rgb.h:44
InternalGPIOPin * pclk_pin_
Definition mipi_rgb.h:73
void fill(Color color) override
Definition mipi_rgb.cpp:306
void set_hsync_pulse_width(uint16_t hsync_pulse_width)
Definition mipi_rgb.h:56
void set_vsync_pulse_width(uint16_t vsync_pulse_width)
Definition mipi_rgb.h:57
int get_width_internal() override
Definition mipi_rgb.h:62
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:230
void set_reset_pin(GPIOPin *reset_pin)
Definition mipi_rgb.h:47
void write_data_(uint8_t value)
Definition mipi_rgb.cpp:63
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:78
MipiRgbSpi(int width, int height)
Definition mipi_rgb.h:106
void write_command_(uint8_t value)
Definition mipi_rgb.cpp:51
void set_dc_pin(GPIOPin *dc_pin)
Definition mipi_rgb.h:109
void set_init_sequence(const std::vector< uint8_t > &init_sequence)
Definition mipi_rgb.h:108
std::vector< uint8_t > init_sequence_
Definition mipi_rgb.h:119
The SPIDevice is what components using the SPI will create.
Definition spi.h:429
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
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