1#ifdef USE_ESP32_VARIANT_ESP32P4
8static bool notify_refresh_ready(esp_lcd_panel_handle_t panel, esp_lcd_dpi_panel_event_data_t *edata,
void *user_ctx) {
9 auto *sem =
static_cast<SemaphoreHandle_t *
>(user_ctx);
10 BaseType_t need_yield = pdFALSE;
11 xSemaphoreGiveFromISR(sem, &need_yield);
12 return (need_yield == pdTRUE);
16 ESP_LOGE(TAG,
"%s: %s", LOG_STR_ARG(
message), esp_err_to_name(err));
21 ESP_LOGCONFIG(TAG,
"Running Setup");
26 pin->digital_write(
true);
31 esp_lcd_dsi_bus_config_t bus_config = {
35 .phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT,
38 auto err = esp_lcd_new_dsi_bus(&bus_config, &this->
bus_handle_);
40 this->
smark_failed(LOG_STR(
"lcd_new_dsi_bus failed"), err);
43 esp_lcd_dbi_io_config_t dbi_config = {
50 this->
smark_failed(LOG_STR(
"new_panel_io_dbi failed"), err);
53 auto pixel_format = LCD_COLOR_PIXEL_FORMAT_RGB565;
55 pixel_format = LCD_COLOR_PIXEL_FORMAT_RGB888;
57 esp_lcd_dpi_panel_config_t dpi_config = {.virtual_channel = 0,
58 .dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT,
60 .pixel_format = pixel_format,
78 this->
smark_failed(LOG_STR(
"esp_lcd_new_panel_dpi failed"), err);
92 auto when =
millis() + 120;
93 err = esp_lcd_panel_init(this->
handle_);
100 while (index != vec.size()) {
101 if (vec.size() - index < 2) {
102 this->
mark_failed(LOG_STR(
"Malformed init sequence"));
105 uint8_t cmd = vec[index++];
106 uint8_t
x = vec[index++];
108 ESP_LOGD(TAG,
"Delay %dms", cmd);
111 uint8_t num_args =
x & 0x7F;
112 if (vec.size() - index < num_args) {
113 this->
mark_failed(LOG_STR(
"Malformed init sequence"));
123 const auto *ptr = vec.data() + index;
124 ESP_LOGVV(TAG,
"Command %02X, length %d, byte(s) %s", cmd, num_args,
126 err = esp_lcd_panel_io_tx_param(this->
io_handle_, cmd, ptr, num_args);
128 this->
smark_failed(LOG_STR(
"lcd_panel_io_tx_param failed"), err);
136 this->
io_lock_ = xSemaphoreCreateBinary();
137 esp_lcd_dpi_panel_event_callbacks_t cbs = {
138 .on_color_trans_done = notify_refresh_ready,
141 err = (esp_lcd_dpi_panel_register_event_callbacks(this->
handle_, &cbs, this->
io_lock_));
143 this->
smark_failed(LOG_STR(
"Failed to register callbacks"), err);
147 ESP_LOGCONFIG(TAG,
"MIPI DSI setup complete");
156 }
else if (this->
page_ !=
nullptr) {
169 this->
width_ - w - this->x_low_);
171 this->x_low_ = this->
width_;
179 if (w <= 0 ||
h <= 0)
184 display::Display::draw_pixels_at(x_start, y_start, w,
h, ptr, order, bitness, big_endian, x_offset, y_offset,
192 esp_err_t err = ESP_OK;
194 auto stride = (x_offset + w + x_pad) * bytes_per_pixel;
195 ptr += y_offset * stride + x_offset * bytes_per_pixel;
197 if (x_offset == 0 && x_pad == 0) {
198 err = esp_lcd_panel_draw_bitmap(this->
handle_, x_start, y_start, x_start + w, y_start +
h, ptr);
199 xSemaphoreTake(this->
io_lock_, portMAX_DELAY);
203 for (
int y = 0;
y !=
h;
y++) {
204 err = esp_lcd_panel_draw_bitmap(this->
handle_, x_start,
y + y_start, x_start + w,
y + y_start + 1, ptr);
208 xSemaphoreTake(this->
io_lock_, portMAX_DELAY);
212 ESP_LOGE(TAG,
"lcd_lcd_panel_draw_bitmap failed: %s", esp_err_to_name(err));
224 if (this->
buffer_ ==
nullptr) {
225 this->
mark_failed(LOG_STR(
"Could not allocate buffer for display!"));
257 size_t pos = (
y * this->
width_) + x;
260 auto *ptr_16 =
reinterpret_cast<uint16_t *
>(this->
buffer_);
261 uint8_t hi_byte =
static_cast<uint8_t
>(color.
r & 0xF8) | (color.
g >> 5);
262 uint8_t lo_byte =
static_cast<uint8_t
>((color.
g & 0x1C) << 3) | (color.
b >> 3);
263 uint16_t new_color = lo_byte | (hi_byte << 8);
264 if (ptr_16[pos] == new_color)
266 ptr_16[pos] = new_color;
272 this->
buffer_[pos * 3 + 1] = color.
g;
273 this->
buffer_[pos * 3 + 2] = color.
r;
276 this->
buffer_[pos * 3 + 1] = color.
g;
277 this->
buffer_[pos * 3 + 2] = color.
b;
298 auto *ptr_16 =
reinterpret_cast<uint16_t *
>(this->
buffer_);
299 uint8_t hi_byte =
static_cast<uint8_t
>(color.
r & 0xF8) | (color.
g >> 5);
300 uint8_t lo_byte =
static_cast<uint8_t
>((color.
g & 0x1C) << 3) | (color.
b >> 3);
301 uint16_t new_color = lo_byte | (hi_byte << 8);
302 std::fill_n(ptr_16, this->
width_ * this->
height_, new_color);
350static const uint8_t PIXEL_MODES[] = {0, 16, 18, 24};
361 "\n Rotation: %d degrees"
363 "\n Lane Bit Rate: %uMbps"
364 "\n HSync Pulse Width: %u"
365 "\n HSync Back Porch: %u"
366 "\n HSync Front Porch: %u"
367 "\n VSync Pulse Width: %u"
368 "\n VSync Back Porch: %u"
369 "\n VSync Front Porch: %u"
370 "\n Buffer Color Depth: %d bit"
371 "\n Display Pixel Mode: %d bit"
373 "\n Invert Colors: %s"
374 "\n Pixel Clock: %dMHz",
virtual void mark_failed()
Mark this component as failed.
virtual void digital_write(bool value)=0
An STL allocator that uses SPI or internal RAM.
static uint16_t color_to_565(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
virtual void clear()
Clear the entire screen by filling it with OFF pixels.
Rect get_clipping() const
Get the current the clipping rectangle.
DisplayRotation rotation_
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.
const display_writer_t & get_writer() const
uint16_t vsync_front_porch_
void fill(Color color) override
uint16_t hsync_front_porch_
uint16_t hsync_back_porch_
display::ColorOrder color_mode_
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
void dump_config() override
std::vector< GPIOPin * > enable_pins_
void smark_failed(const LogString *message, esp_err_t err)
uint16_t vsync_pulse_width_
display::ColorBitness color_depth_
uint16_t hsync_pulse_width_
SemaphoreHandle_t io_lock_
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)
esp_lcd_panel_io_handle_t io_handle_
int get_height() override
void draw_pixel_at(int x, int y, Color color) override
uint16_t vsync_back_porch_
int get_width_internal() override
esp_lcd_dsi_bus_handle_t bus_handle_
std::vector< uint8_t > init_sequence_
int get_height_internal() override
esp_lcd_panel_handle_t handle_
@ DISPLAY_ROTATION_0_DEGREES
@ DISPLAY_ROTATION_270_DEGREES
@ DISPLAY_ROTATION_180_DEGREES
@ DISPLAY_ROTATION_90_DEGREES
const uint8_t MADCTL_YFLIP
const uint8_t MADCTL_XFLIP
const uint8_t SW_RESET_CMD
Providing packet encoding functions for exchanging data with a remote host.
constexpr T convert_big_endian(T val)
Convert a value between host byte order and big endian (most significant byte first) order.
std::string format_hex_pretty(const uint8_t *data, size_t length, char separator, bool show_length)
Format a byte array in pretty-printed, human-readable hex format.
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()