mirror of
https://github.com/esphome/esphome.git
synced 2026-11-01 02:46:39 +00:00
[display] Loop on the reader's step in display drivers and cap mipi_spi args in the reader
This commit is contained in:
5 files changed
+30
-33
No files matched your search
@@ -318,16 +318,18 @@ void EPaperBase::on_safe_shutdown() { this->deep_sleep(); }
|
||||
void EPaperBase::send_init_sequence_(const uint8_t *sequence, size_t length) {
|
||||
display::InitSequenceReader reader(sequence, length);
|
||||
display::InitSequenceEntry entry;
|
||||
while (reader.next(entry)) {
|
||||
if (entry.is_delay()) {
|
||||
while (auto step = reader.next(entry)) {
|
||||
if (step == display::INIT_SEQUENCE_STEP_MALFORMED) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
if (step == display::INIT_SEQUENCE_STEP_DELAY) {
|
||||
ESP_LOGV(TAG, "Delay %dms", entry.value);
|
||||
delay(entry.value);
|
||||
} else {
|
||||
this->cmd_data(entry.value, entry.args, entry.count);
|
||||
}
|
||||
}
|
||||
if (reader.malformed())
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
}
|
||||
|
||||
bool EPaperBase::initialise(bool partial) {
|
||||
|
||||
@@ -126,8 +126,12 @@ void MipiDsi::setup() {
|
||||
}
|
||||
display::InitSequenceReader reader(this->init_sequence_, this->init_sequence_len_);
|
||||
display::InitSequenceEntry entry;
|
||||
while (reader.next(entry)) {
|
||||
if (entry.is_delay()) {
|
||||
while (auto step = reader.next(entry)) {
|
||||
if (step == display::INIT_SEQUENCE_STEP_MALFORMED) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
if (step == display::INIT_SEQUENCE_STEP_DELAY) {
|
||||
ESP_LOGD(TAG, "Delay %dms", entry.value);
|
||||
delay(entry.value);
|
||||
continue;
|
||||
@@ -153,10 +157,6 @@ void MipiDsi::setup() {
|
||||
if (cmd == SLEEP_OUT)
|
||||
delay(10);
|
||||
}
|
||||
if (reader.malformed()) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
this->io_lock_ = xSemaphoreCreateBinary();
|
||||
esp_lcd_dpi_panel_event_callbacks_t cbs = {
|
||||
.on_color_trans_done = notify_refresh_ready,
|
||||
|
||||
@@ -77,8 +77,12 @@ void MipiRgbSpi::write_data_(uint8_t value) {
|
||||
void MipiRgbSpi::write_init_sequence_() {
|
||||
display::InitSequenceReader reader(this->init_sequence_, this->init_sequence_len_);
|
||||
display::InitSequenceEntry entry;
|
||||
while (reader.next(entry)) {
|
||||
if (entry.is_delay()) {
|
||||
while (auto step = reader.next(entry)) {
|
||||
if (step == display::INIT_SEQUENCE_STEP_MALFORMED) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
if (step == display::INIT_SEQUENCE_STEP_DELAY) {
|
||||
ESP_LOGD(TAG, "Delay %dms", entry.value);
|
||||
delay(entry.value);
|
||||
continue;
|
||||
@@ -95,10 +99,6 @@ void MipiRgbSpi::write_init_sequence_() {
|
||||
if (cmd == SLEEP_OUT)
|
||||
delay(10);
|
||||
}
|
||||
if (reader.malformed()) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
// this->spi_teardown(); // SPI not needed after this
|
||||
delay(10);
|
||||
}
|
||||
|
||||
@@ -170,24 +170,20 @@ class MipiSpi : public display::Display,
|
||||
display::InitSequenceEntry entry;
|
||||
// The sequence is in flash, which SPI DMA (and ESP8266 byte loads) cannot read
|
||||
uint8_t args[INIT_SEQUENCE_MAX_ARGS];
|
||||
while (reader.next(entry)) {
|
||||
if (entry.is_delay()) {
|
||||
while (auto step = reader.next(entry, sizeof(args))) {
|
||||
if (step == display::INIT_SEQUENCE_STEP_MALFORMED) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
if (step == display::INIT_SEQUENCE_STEP_DELAY) {
|
||||
const uint8_t ms = entry.value != 0 ? entry.value : clamp_at_least((int) (when - millis()), 0);
|
||||
esph_log_d(TAG, "Delay %dms", ms);
|
||||
delay(ms);
|
||||
continue;
|
||||
}
|
||||
if (entry.count > sizeof(args)) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
progmem_memcpy(args, entry.args, entry.count);
|
||||
this->write_command_(entry.value, args, entry.count);
|
||||
}
|
||||
if (reader.malformed()) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
return;
|
||||
}
|
||||
this->reset_params_();
|
||||
// Marks init as done, so later commands log at verbose level instead of debug
|
||||
this->init_sequence_len_ = 0;
|
||||
|
||||
@@ -57,12 +57,8 @@ void ST7305::reset_() {
|
||||
|
||||
void ST7305::send_init_sequence_() {
|
||||
display::InitSequenceEntry entry;
|
||||
while (this->init_reader_.next(entry)) {
|
||||
if (entry.is_delay()) {
|
||||
// Resume the sequence after the delay instead of blocking the main loop.
|
||||
this->set_timeout(STARTUP_TIMEOUT_ID, entry.value, [this]() { this->send_init_sequence_(); });
|
||||
return;
|
||||
}
|
||||
display::InitSequenceStep step;
|
||||
while ((step = this->init_reader_.next(entry)) == display::INIT_SEQUENCE_STEP_COMMAND) {
|
||||
this->enable();
|
||||
this->send_command_(entry.value);
|
||||
if (entry.count != 0) {
|
||||
@@ -72,7 +68,10 @@ void ST7305::send_init_sequence_() {
|
||||
}
|
||||
this->disable();
|
||||
}
|
||||
if (this->init_reader_.malformed()) {
|
||||
if (step == display::INIT_SEQUENCE_STEP_DELAY) {
|
||||
// Resume the sequence after the delay instead of blocking the main loop.
|
||||
this->set_timeout(STARTUP_TIMEOUT_ID, entry.value, [this]() { this->send_init_sequence_(); });
|
||||
} else if (step == display::INIT_SEQUENCE_STEP_MALFORMED) {
|
||||
this->mark_failed(LOG_STR("Malformed init sequence"));
|
||||
} else {
|
||||
this->finish_init_();
|
||||
|
||||
Reference in new issue
Block a user