ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
rpi_dpi_rgb.cpp
Go to the documentation of this file.
1#ifdef USE_ESP32_VARIANT_ESP32S3
2#include "rpi_dpi_rgb.h"
3#include "esphome/core/gpio.h"
4#include "esphome/core/log.h"
5#include <driver/gpio.h>
6
7namespace esphome {
8namespace rpi_dpi_rgb {
9
11 this->reset_display_();
12 esp_lcd_rgb_panel_config_t config{};
13 config.flags.fb_in_psram = 1;
14 config.bounce_buffer_size_px = this->width_ * 10;
15 config.num_fbs = 1;
16 config.timings.h_res = this->width_;
17 config.timings.v_res = this->height_;
18 config.timings.hsync_pulse_width = this->hsync_pulse_width_;
19 config.timings.hsync_back_porch = this->hsync_back_porch_;
20 config.timings.hsync_front_porch = this->hsync_front_porch_;
21 config.timings.vsync_pulse_width = this->vsync_pulse_width_;
22 config.timings.vsync_back_porch = this->vsync_back_porch_;
23 config.timings.vsync_front_porch = this->vsync_front_porch_;
24 config.timings.flags.pclk_active_neg = this->pclk_inverted_;
25 config.timings.pclk_hz = this->pclk_frequency_;
26 config.clk_src = LCD_CLK_SRC_PLL160M;
27 size_t data_pin_count = sizeof(this->data_pins_) / sizeof(this->data_pins_[0]);
28 for (size_t i = 0; i != data_pin_count; i++) {
29 config.data_gpio_nums[i] = static_cast<gpio_num_t>(this->data_pins_[i]->get_pin());
30 }
31 config.data_width = data_pin_count;
32 config.disp_gpio_num = GPIO_NUM_NC;
33 config.hsync_gpio_num = static_cast<gpio_num_t>(this->hsync_pin_->get_pin());
34 config.vsync_gpio_num = static_cast<gpio_num_t>(this->vsync_pin_->get_pin());
35 config.de_gpio_num = static_cast<gpio_num_t>(this->de_pin_->get_pin());
36 config.pclk_gpio_num = static_cast<gpio_num_t>(this->pclk_pin_->get_pin());
37 esp_err_t err = esp_lcd_new_rgb_panel(&config, &this->handle_);
38 if (err != ESP_OK) {
39 ESP_LOGE(TAG, "lcd_new_rgb_panel failed: %s", esp_err_to_name(err));
40 this->mark_failed();
41 return;
42 }
43 ESP_ERROR_CHECK(esp_lcd_panel_reset(this->handle_));
44 ESP_ERROR_CHECK(esp_lcd_panel_init(this->handle_));
45}
47 if (this->handle_ != nullptr)
48 esp_lcd_rgb_panel_restart(this->handle_);
49}
50
51void RpiDpiRgb::draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, display::ColorOrder order,
52 display::ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) {
53 if (w <= 0 || h <= 0)
54 return;
55 // if color mapping is required, pass the buck.
56 // note that endianness is not considered here - it is assumed to match!
57 if (bitness != display::COLOR_BITNESS_565) {
58 return display::Display::draw_pixels_at(x_start, y_start, w, h, ptr, order, bitness, big_endian, x_offset, y_offset,
59 x_pad);
60 }
61 x_start += this->offset_x_;
62 y_start += this->offset_y_;
63 esp_err_t err = ESP_OK;
64 // x_ and y_offset are offsets into the source buffer, unrelated to our own offsets into the display.
65 if (x_offset == 0 && x_pad == 0 && y_offset == 0) {
66 // we could deal here with a non-zero y_offset, but if x_offset is zero, y_offset probably will be so don't bother
67 err = esp_lcd_panel_draw_bitmap(this->handle_, x_start, y_start, x_start + w, y_start + h, ptr);
68 } else {
69 // draw line by line
70 auto stride = x_offset + w + x_pad;
71 for (int y = 0; y != h; y++) {
72 err = esp_lcd_panel_draw_bitmap(this->handle_, x_start, y + y_start, x_start + w, y + y_start + 1,
73 ptr + ((y + y_offset) * stride + x_offset) * 2);
74 if (err != ESP_OK)
75 break;
76 }
77 }
78 if (err != ESP_OK)
79 ESP_LOGE(TAG, "lcd_lcd_panel_draw_bitmap failed: %s", esp_err_to_name(err));
80}
81
83 switch (this->rotation_) {
86 return this->get_height_internal();
87 default:
88 return this->get_width_internal();
89 }
90}
91
93 switch (this->rotation_) {
96 return this->get_width_internal();
97 default:
98 return this->get_height_internal();
99 }
100}
101
102void RpiDpiRgb::draw_pixel_at(int x, int y, Color color) {
103 if (!this->get_clipping().inside(x, y))
104 return; // NOLINT
105
106 switch (this->rotation_) {
108 break;
110 std::swap(x, y);
111 x = this->width_ - x - 1;
112 break;
114 x = this->width_ - x - 1;
115 y = this->height_ - y - 1;
116 break;
118 std::swap(x, y);
119 y = this->height_ - y - 1;
120 break;
121 }
123
124 this->draw_pixels_at(x, y, 1, 1, (const uint8_t *) &pixel, display::COLOR_ORDER_RGB, display::COLOR_BITNESS_565, true,
125 0, 0, 0);
126 App.feed_wdt();
127}
128
130 ESP_LOGCONFIG("", "RPI_DPI_RGB LCD");
131 ESP_LOGCONFIG(TAG,
132 " Height: %u\n"
133 " Width: %u",
134 this->height_, this->width_);
135 LOG_PIN(" DE Pin: ", this->de_pin_);
136 LOG_PIN(" Enable Pin: ", this->enable_pin_);
137 LOG_PIN(" Reset Pin: ", this->reset_pin_);
138 size_t data_pin_count = sizeof(this->data_pins_) / sizeof(this->data_pins_[0]);
139 char pin_summary[GPIO_SUMMARY_MAX_LEN];
140 for (size_t i = 0; i != data_pin_count; i++) {
141 this->data_pins_[i]->dump_summary(pin_summary, sizeof(pin_summary));
142 ESP_LOGCONFIG(TAG, " Data pin %d: %s", i, pin_summary);
143 }
144}
145
147 if (this->reset_pin_ != nullptr) {
148 this->reset_pin_->setup();
149 this->reset_pin_->digital_write(false);
150 if (this->enable_pin_ != nullptr) {
151 this->enable_pin_->setup();
152 this->enable_pin_->digital_write(false);
153 }
154 delay(1);
155 this->reset_pin_->digital_write(true);
156 if (this->enable_pin_ != nullptr) {
157 delay(11);
158 this->enable_pin_->digital_write(true);
159 }
160 }
161}
162
163} // namespace rpi_dpi_rgb
164} // namespace esphome
165
166#endif // USE_ESP32_VARIANT_ESP32S3
uint8_t h
Definition bl0906.h:2
void feed_wdt()
Feed the task watchdog.
void mark_failed()
Mark this component as failed.
virtual void setup()=0
virtual void digital_write(bool value)=0
virtual size_t dump_summary(char *buffer, size_t len) const
Write a summary of this pin to the provided buffer.
Definition gpio.h:129
virtual uint8_t get_pin() const =0
static uint16_t color_to_565(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
Rect get_clipping() const
Get the current the clipping rectangle.
Definition display.cpp:766
DisplayRotation rotation_
Definition display.h:790
virtual void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorOrder order, ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad)
Given an array of pixels encoded in the nominated format, draw these into the display's buffer.
Definition display.cpp:54
InternalGPIOPin * data_pins_[16]
Definition rpi_dpi_rgb.h:75
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
esp_lcd_panel_handle_t handle_
Definition rpi_dpi_rgb.h:92
void draw_pixel_at(int x, int y, Color color) override
@ DISPLAY_ROTATION_0_DEGREES
Definition display.h:135
@ DISPLAY_ROTATION_270_DEGREES
Definition display.h:138
@ DISPLAY_ROTATION_180_DEGREES
Definition display.h:137
@ DISPLAY_ROTATION_90_DEGREES
Definition display.h:136
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
constexpr T convert_big_endian(T val)
Convert a value between host byte order and big endian (most significant byte first) order.
Definition helpers.h:937
constexpr size_t GPIO_SUMMARY_MAX_LEN
Maximum buffer size for dump_summary output.
Definition gpio.h:13
void HOT delay(uint32_t ms)
Definition core.cpp:28
Application App
Global storage of Application pointer - only one Application can exist.
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6