mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 19:44:08 +00:00
[mipi_dsi] Keep the init sequence in flash (#20091)
This commit is contained in:
@@ -201,7 +201,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
|
||||
sequence = model.get_sequence(config)
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
cg.add(var.set_init_sequence(sequence))
|
||||
table = cg.shared_progmem_array("mipi_dsi_init_sequence", cg.uint8, sequence)
|
||||
cg.add(var.set_init_sequence(table, len(sequence)))
|
||||
cg.add(var.set_invert_colors(config[CONF_INVERT_COLORS]))
|
||||
cg.add(var.set_hsync_pulse_width(config[CONF_HSYNC_PULSE_WIDTH]))
|
||||
cg.add(var.set_hsync_back_porch(config[CONF_HSYNC_BACK_PORCH]))
|
||||
|
||||
@@ -121,20 +121,21 @@ void MipiDsi::setup() {
|
||||
return;
|
||||
}
|
||||
size_t index = 0;
|
||||
auto &vec = this->init_sequence_;
|
||||
while (index != vec.size()) {
|
||||
if (vec.size() - index < 2) {
|
||||
const uint8_t *seq = this->init_sequence_;
|
||||
const size_t len = this->init_sequence_len_;
|
||||
while (index != len) {
|
||||
if (len - index < 2) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
uint8_t cmd = vec[index++];
|
||||
uint8_t x = vec[index++];
|
||||
uint8_t cmd = seq[index++];
|
||||
uint8_t x = seq[index++];
|
||||
if (x == DELAY_FLAG) {
|
||||
ESP_LOGD(TAG, "Delay %dms", cmd);
|
||||
delay(cmd);
|
||||
} else {
|
||||
uint8_t num_args = x & 0x7F;
|
||||
if (vec.size() - index < num_args) {
|
||||
if (len - index < num_args) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
@@ -145,7 +146,7 @@ void MipiDsi::setup() {
|
||||
delay(duration);
|
||||
}
|
||||
}
|
||||
const auto *ptr = vec.data() + index;
|
||||
const auto *ptr = seq + index;
|
||||
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE
|
||||
char hex_buf[format_hex_pretty_size(MIPI_DSI_MAX_CMD_LOG_BYTES)];
|
||||
#endif
|
||||
|
||||
@@ -55,7 +55,10 @@ class MipiDsi final : public display::Display {
|
||||
void set_vsync_pulse_width(uint16_t vsync_pulse_width) { this->vsync_pulse_width_ = vsync_pulse_width; }
|
||||
void set_vsync_back_porch(uint16_t vsync_back_porch) { this->vsync_back_porch_ = vsync_back_porch; }
|
||||
void set_vsync_front_porch(uint16_t vsync_front_porch) { this->vsync_front_porch_ = vsync_front_porch; }
|
||||
void set_init_sequence(const std::vector<uint8_t> &init_sequence) { this->init_sequence_ = init_sequence; }
|
||||
void set_init_sequence(const uint8_t *init_sequence, size_t len) {
|
||||
this->init_sequence_ = init_sequence;
|
||||
this->init_sequence_len_ = len;
|
||||
}
|
||||
void set_model(const char *model) { this->model_ = model; }
|
||||
void set_lane_bit_rate(float lane_bit_rate) { this->lane_bit_rate_ = lane_bit_rate; }
|
||||
void set_lanes(uint8_t lanes) { this->lanes_ = lanes; }
|
||||
@@ -91,7 +94,9 @@ class MipiDsi final : public display::Display {
|
||||
uint16_t vsync_back_porch_ = 10;
|
||||
uint16_t vsync_front_porch_ = 10;
|
||||
const char *model_{"Unknown"};
|
||||
std::vector<uint8_t> init_sequence_{};
|
||||
// Shared PROGMEM table
|
||||
const uint8_t *init_sequence_{nullptr};
|
||||
size_t init_sequence_len_{0};
|
||||
float pclk_frequency_ = 16; // in MHz
|
||||
float lane_bit_rate_{1500}; // in Mbps
|
||||
uint8_t lanes_{2}; // 1, 2, 3 or 4 lanes
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from collections.abc import Callable
|
||||
import logging
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -201,7 +202,12 @@ def test_code_generation(
|
||||
"new(p4_nano) mipi_dsi::MipiDsi(800, 1280, display::COLOR_BITNESS_565, 16);"
|
||||
in main_cpp
|
||||
)
|
||||
assert "set_init_sequence({224, 1, 0, 225, 1, 147, 226, 1," in main_cpp
|
||||
seq = re.search(r"p4_nano->set_init_sequence\((\w+), \d+\);", main_cpp)
|
||||
assert seq is not None
|
||||
assert (
|
||||
f"static constexpr uint8_t {seq.group(1)}[] PROGMEM = "
|
||||
"{224, 1, 0, 225, 1, 147, 226, 1," in main_cpp
|
||||
)
|
||||
assert "p4_nano->set_lane_bit_rate(1500.0f);" in main_cpp
|
||||
assert "p4_nano->set_rotation(display::DISPLAY_ROTATION_90_DEGREES);" in main_cpp
|
||||
assert "p4_86->set_rotation(display::DISPLAY_ROTATION_0_DEGREES);" not in main_cpp
|
||||
|
||||
Reference in New Issue
Block a user