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);
15 ESP_LOGCONFIG(TAG,
"Running Setup");
20 pin->digital_write(
true);
25 esp_lcd_dsi_bus_config_t bus_config = {
29 .phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT,
32 auto err = esp_lcd_new_dsi_bus(&bus_config, &this->
bus_handle_);
37 esp_lcd_dbi_io_config_t dbi_config = {
47 auto pixel_format = LCD_COLOR_PIXEL_FORMAT_RGB565;
49 pixel_format = LCD_COLOR_PIXEL_FORMAT_RGB888;
51 esp_lcd_dpi_panel_config_t dpi_config = {.virtual_channel = 0,
52 .dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT,
54 .pixel_format = pixel_format,
86 auto when =
millis() + 120;
87 err = esp_lcd_panel_init(this->
handle_);
94 while (index != vec.size()) {
95 if (vec.size() - index < 2) {
99 uint8_t cmd = vec[index++];
100 uint8_t
x = vec[index++];
102 ESP_LOGD(TAG,
"Delay %dms", cmd);
105 uint8_t num_args =
x & 0x7F;
106 if (vec.size() - index < num_args) {
117 const auto *ptr = vec.data() + index;
118 ESP_LOGVV(TAG,
"Command %02X, length %d, byte(s) %s", cmd, num_args,
120 err = esp_lcd_panel_io_tx_param(this->
io_handle_, cmd, ptr, num_args);
122 this->
smark_failed(
"lcd_panel_io_tx_param failed", err);
130 this->
io_lock_ = xSemaphoreCreateBinary();
131 esp_lcd_dpi_panel_event_callbacks_t cbs = {
132 .on_color_trans_done = notify_refresh_ready,
135 err = (esp_lcd_dpi_panel_register_event_callbacks(this->
handle_, &cbs, this->
io_lock_));
137 this->
smark_failed(
"Failed to register callbacks", err);
141 ESP_LOGCONFIG(TAG,
"MIPI DSI setup complete");
150 }
else if (this->
page_ !=
nullptr) {
163 this->
width_ - w - this->x_low_);
165 this->x_low_ = this->
width_;
173 if (w <= 0 ||
h <= 0)
178 display::Display::draw_pixels_at(x_start, y_start, w,
h, ptr, order, bitness, big_endian, x_offset, y_offset,
186 esp_err_t err = ESP_OK;
188 auto stride = (x_offset + w + x_pad) * bytes_per_pixel;
189 ptr += y_offset * stride + x_offset * bytes_per_pixel;
191 if (x_offset == 0 && x_pad == 0) {
192 err = esp_lcd_panel_draw_bitmap(this->
handle_, x_start, y_start, x_start + w, y_start +
h, ptr);
193 xSemaphoreTake(this->
io_lock_, portMAX_DELAY);
197 for (
int y = 0;
y !=
h;
y++) {
198 err = esp_lcd_panel_draw_bitmap(this->
handle_, x_start,
y + y_start, x_start + w,
y + y_start + 1, ptr);
202 xSemaphoreTake(this->
io_lock_, portMAX_DELAY);
206 ESP_LOGE(TAG,
"lcd_lcd_panel_draw_bitmap failed: %s", esp_err_to_name(err));
218 if (this->
buffer_ ==
nullptr) {
219 this->
mark_failed(
"Could not allocate buffer for display!");
251 size_t pos = (
y * this->
width_) + x;
254 auto *ptr_16 =
reinterpret_cast<uint16_t *
>(this->
buffer_);
255 uint8_t hi_byte =
static_cast<uint8_t
>(color.
r & 0xF8) | (color.
g >> 5);
256 uint8_t lo_byte =
static_cast<uint8_t
>((color.
g & 0x1C) << 3) | (color.
b >> 3);
257 uint16_t new_color = lo_byte | (hi_byte << 8);
258 if (ptr_16[pos] == new_color)
260 ptr_16[pos] = new_color;
266 this->
buffer_[pos * 3 + 1] = color.
g;
267 this->
buffer_[pos * 3 + 2] = color.
r;
270 this->
buffer_[pos * 3 + 1] = color.
g;
271 this->
buffer_[pos * 3 + 2] = color.
b;
292 auto *ptr_16 =
reinterpret_cast<uint16_t *
>(this->
buffer_);
293 uint8_t hi_byte =
static_cast<uint8_t
>(color.
r & 0xF8) | (color.
g >> 5);
294 uint8_t lo_byte =
static_cast<uint8_t
>((color.
g & 0x1C) << 3) | (color.
b >> 3);
295 uint16_t new_color = lo_byte | (hi_byte << 8);
296 std::fill_n(ptr_16, this->
width_ * this->
height_, new_color);
344static const uint8_t PIXEL_MODES[] = {0, 16, 18, 24};
355 "\n Rotation: %d degrees"
357 "\n Lane Bit Rate: %uMbps"
358 "\n HSync Pulse Width: %u"
359 "\n HSync Back Porch: %u"
360 "\n HSync Front Porch: %u"
361 "\n VSync Pulse Width: %u"
362 "\n VSync Back Porch: %u"
363 "\n VSync Front Porch: %u"
364 "\n Buffer Color Depth: %d bit"
365 "\n Display Pixel Mode: %d bit"
367 "\n Invert Colors: %s"
368 "\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)
void clear()
Clear the entire screen by filling it with OFF pixels.
optional< display_writer_t > writer_
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_
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)
void smark_failed(const char *message, esp_err_t err)
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()