mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +01:00
[st7701s] Add delay feature in init sequences (#7343)
Some checks failed
CI / list-components (push) Blocked by required conditions
CI / Run script/ci-custom (push) Blocked by required conditions
CI / Create common environment (push) Waiting to run
CI / Check black (push) Blocked by required conditions
CI / Check flake8 (push) Blocked by required conditions
CI / Check pylint (push) Blocked by required conditions
CI / Check pyupgrade (push) Blocked by required conditions
CI / Run pytest (macOS-latest, 3.11) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.11) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.12) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.9) (push) Blocked by required conditions
CI / Run pytest (windows-latest, 3.11) (push) Blocked by required conditions
CI / Check clang-format (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 IDF (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP8266 (push) Blocked by required conditions
CI / Component test ${{ matrix.file }} (push) Blocked by required conditions
CI / Split components for testing into 20 groups maximum (push) Blocked by required conditions
CI / Test split components (push) Blocked by required conditions
CI / CI Status (push) Blocked by required conditions
YAML lint / yamllint (push) Waiting to run
CI / Run pytest (ubuntu-latest, 3.10) (push) Blocked by required conditions
CI for docker images / Build docker containers (aarch64, docker) (push) Has been cancelled
CI for docker images / Build docker containers (aarch64, ha-addon) (push) Has been cancelled
CI for docker images / Build docker containers (aarch64, lint) (push) Has been cancelled
CI for docker images / Build docker containers (amd64, docker) (push) Has been cancelled
CI for docker images / Build docker containers (amd64, ha-addon) (push) Has been cancelled
CI for docker images / Build docker containers (amd64, lint) (push) Has been cancelled
CI for docker images / Build docker containers (armv7, docker) (push) Has been cancelled
CI for docker images / Build docker containers (armv7, ha-addon) (push) Has been cancelled
CI for docker images / Build docker containers (armv7, lint) (push) Has been cancelled
Some checks failed
CI / list-components (push) Blocked by required conditions
CI / Run script/ci-custom (push) Blocked by required conditions
CI / Create common environment (push) Waiting to run
CI / Check black (push) Blocked by required conditions
CI / Check flake8 (push) Blocked by required conditions
CI / Check pylint (push) Blocked by required conditions
CI / Check pyupgrade (push) Blocked by required conditions
CI / Run pytest (macOS-latest, 3.11) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.11) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.12) (push) Blocked by required conditions
CI / Run pytest (ubuntu-latest, 3.9) (push) Blocked by required conditions
CI / Run pytest (windows-latest, 3.11) (push) Blocked by required conditions
CI / Check clang-format (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 IDF (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP8266 (push) Blocked by required conditions
CI / Component test ${{ matrix.file }} (push) Blocked by required conditions
CI / Split components for testing into 20 groups maximum (push) Blocked by required conditions
CI / Test split components (push) Blocked by required conditions
CI / CI Status (push) Blocked by required conditions
YAML lint / yamllint (push) Waiting to run
CI / Run pytest (ubuntu-latest, 3.10) (push) Blocked by required conditions
CI for docker images / Build docker containers (aarch64, docker) (push) Has been cancelled
CI for docker images / Build docker containers (aarch64, ha-addon) (push) Has been cancelled
CI for docker images / Build docker containers (aarch64, lint) (push) Has been cancelled
CI for docker images / Build docker containers (amd64, docker) (push) Has been cancelled
CI for docker images / Build docker containers (amd64, ha-addon) (push) Has been cancelled
CI for docker images / Build docker containers (amd64, lint) (push) Has been cancelled
CI for docker images / Build docker containers (armv7, docker) (push) Has been cancelled
CI for docker images / Build docker containers (armv7, ha-addon) (push) Has been cancelled
CI for docker images / Build docker containers (armv7, lint) (push) Has been cancelled
This commit is contained in:
parent
725e50348b
commit
d754bdde1b
4 changed files with 61 additions and 52 deletions
|
@ -1,47 +1,39 @@
|
||||||
import esphome.codegen as cg
|
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome import pins
|
from esphome import pins
|
||||||
from esphome.components import (
|
import esphome.codegen as cg
|
||||||
spi,
|
from esphome.components import display, spi
|
||||||
display,
|
from esphome.components.esp32 import const, only_on_variant
|
||||||
)
|
|
||||||
from esphome.const import (
|
|
||||||
CONF_DC_PIN,
|
|
||||||
CONF_HSYNC_PIN,
|
|
||||||
CONF_RESET_PIN,
|
|
||||||
CONF_DATA_PINS,
|
|
||||||
CONF_ID,
|
|
||||||
CONF_DIMENSIONS,
|
|
||||||
CONF_VSYNC_PIN,
|
|
||||||
CONF_WIDTH,
|
|
||||||
CONF_HEIGHT,
|
|
||||||
CONF_LAMBDA,
|
|
||||||
CONF_MIRROR_X,
|
|
||||||
CONF_MIRROR_Y,
|
|
||||||
CONF_COLOR_ORDER,
|
|
||||||
CONF_TRANSFORM,
|
|
||||||
CONF_OFFSET_HEIGHT,
|
|
||||||
CONF_OFFSET_WIDTH,
|
|
||||||
CONF_INVERT_COLORS,
|
|
||||||
CONF_RED,
|
|
||||||
CONF_GREEN,
|
|
||||||
CONF_BLUE,
|
|
||||||
CONF_NUMBER,
|
|
||||||
CONF_IGNORE_STRAPPING_WARNING,
|
|
||||||
)
|
|
||||||
|
|
||||||
from esphome.components.esp32 import (
|
|
||||||
only_on_variant,
|
|
||||||
const,
|
|
||||||
)
|
|
||||||
from esphome.components.rpi_dpi_rgb.display import (
|
from esphome.components.rpi_dpi_rgb.display import (
|
||||||
CONF_PCLK_FREQUENCY,
|
CONF_PCLK_FREQUENCY,
|
||||||
CONF_PCLK_INVERTED,
|
CONF_PCLK_INVERTED,
|
||||||
)
|
)
|
||||||
from .init_sequences import (
|
import esphome.config_validation as cv
|
||||||
ST7701S_INITS,
|
from esphome.const import (
|
||||||
cmd,
|
CONF_BLUE,
|
||||||
|
CONF_COLOR_ORDER,
|
||||||
|
CONF_DATA_PINS,
|
||||||
|
CONF_DC_PIN,
|
||||||
|
CONF_DIMENSIONS,
|
||||||
|
CONF_GREEN,
|
||||||
|
CONF_HEIGHT,
|
||||||
|
CONF_HSYNC_PIN,
|
||||||
|
CONF_ID,
|
||||||
|
CONF_IGNORE_STRAPPING_WARNING,
|
||||||
|
CONF_INVERT_COLORS,
|
||||||
|
CONF_LAMBDA,
|
||||||
|
CONF_MIRROR_X,
|
||||||
|
CONF_MIRROR_Y,
|
||||||
|
CONF_NUMBER,
|
||||||
|
CONF_OFFSET_HEIGHT,
|
||||||
|
CONF_OFFSET_WIDTH,
|
||||||
|
CONF_RED,
|
||||||
|
CONF_RESET_PIN,
|
||||||
|
CONF_TRANSFORM,
|
||||||
|
CONF_VSYNC_PIN,
|
||||||
|
CONF_WIDTH,
|
||||||
)
|
)
|
||||||
|
from esphome.core import TimePeriod
|
||||||
|
|
||||||
|
from .init_sequences import ST7701S_INITS, cmd
|
||||||
|
|
||||||
CONF_INIT_SEQUENCE = "init_sequence"
|
CONF_INIT_SEQUENCE = "init_sequence"
|
||||||
CONF_DE_PIN = "de_pin"
|
CONF_DE_PIN = "de_pin"
|
||||||
|
@ -59,6 +51,7 @@ DEPENDENCIES = ["spi", "esp32"]
|
||||||
st7701s_ns = cg.esphome_ns.namespace("st7701s")
|
st7701s_ns = cg.esphome_ns.namespace("st7701s")
|
||||||
ST7701S = st7701s_ns.class_("ST7701S", display.Display, cg.Component, spi.SPIDevice)
|
ST7701S = st7701s_ns.class_("ST7701S", display.Display, cg.Component, spi.SPIDevice)
|
||||||
ColorOrder = display.display_ns.enum("ColorMode")
|
ColorOrder = display.display_ns.enum("ColorMode")
|
||||||
|
ST7701S_DELAY_FLAG = 0xFF
|
||||||
|
|
||||||
COLOR_ORDERS = {
|
COLOR_ORDERS = {
|
||||||
"RGB": ColorOrder.COLOR_ORDER_RGB,
|
"RGB": ColorOrder.COLOR_ORDER_RGB,
|
||||||
|
@ -93,18 +86,23 @@ def map_sequence(value):
|
||||||
"""
|
"""
|
||||||
An initialisation sequence can be selected from one of the pre-defined sequences in init_sequences.py,
|
An initialisation sequence can be selected from one of the pre-defined sequences in init_sequences.py,
|
||||||
or can be a literal array of data bytes.
|
or can be a literal array of data bytes.
|
||||||
The format is a repeated sequence of [CMD, LEN, <data>] where <data> is LEN bytes.
|
The format is a repeated sequence of [CMD, <data>] where <data> is s a sequence of bytes. The length is inferred
|
||||||
|
from the length of the sequence and should not be explicit.
|
||||||
|
A delay can be inserted by specifying "- delay N" where N is in ms
|
||||||
"""
|
"""
|
||||||
|
if isinstance(value, str) and value.lower().startswith("delay "):
|
||||||
|
value = value.lower()[6:]
|
||||||
|
delay = cv.All(
|
||||||
|
cv.positive_time_period_milliseconds,
|
||||||
|
cv.Range(TimePeriod(milliseconds=1), TimePeriod(milliseconds=255)),
|
||||||
|
)(value)
|
||||||
|
return [delay, ST7701S_DELAY_FLAG]
|
||||||
if not isinstance(value, list):
|
if not isinstance(value, list):
|
||||||
value = cv.int_(value)
|
value = cv.int_(value)
|
||||||
value = cv.one_of(*ST7701S_INITS)(value)
|
value = cv.one_of(*ST7701S_INITS)(value)
|
||||||
return ST7701S_INITS[value]
|
return ST7701S_INITS[value]
|
||||||
# value = cv.ensure_list(cv.uint8_t)(value)
|
value = cv.Length(min=1, max=254)(value)
|
||||||
data_length = len(value)
|
return cmd(*value)
|
||||||
if data_length == 0:
|
|
||||||
raise cv.Invalid("Empty sequence")
|
|
||||||
value = cmd(*value)
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.All(
|
CONFIG_SCHEMA = cv.All(
|
||||||
|
|
|
@ -138,12 +138,17 @@ void ST7701S::write_init_sequence_() {
|
||||||
for (size_t i = 0; i != this->init_sequence_.size();) {
|
for (size_t i = 0; i != this->init_sequence_.size();) {
|
||||||
uint8_t cmd = this->init_sequence_[i++];
|
uint8_t cmd = this->init_sequence_[i++];
|
||||||
size_t len = this->init_sequence_[i++];
|
size_t len = this->init_sequence_[i++];
|
||||||
|
if (len == ST7701S_DELAY_FLAG) {
|
||||||
|
ESP_LOGV(TAG, "Delay %dms", cmd);
|
||||||
|
delay(cmd);
|
||||||
|
} else {
|
||||||
this->write_sequence_(cmd, len, &this->init_sequence_[i]);
|
this->write_sequence_(cmd, len, &this->init_sequence_[i]);
|
||||||
i += len;
|
i += len;
|
||||||
esph_log_v(TAG, "Command %X, %d bytes", cmd, len);
|
ESP_LOGV(TAG, "Command %X, %d bytes", cmd, len);
|
||||||
if (cmd == SW_RESET_CMD)
|
if (cmd == SW_RESET_CMD)
|
||||||
delay(6);
|
delay(6);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// st7701 does not appear to support axis swapping
|
// st7701 does not appear to support axis swapping
|
||||||
this->write_sequence_(CMD2_BKSEL, sizeof(CMD2_BK0), CMD2_BK0);
|
this->write_sequence_(CMD2_BKSEL, sizeof(CMD2_BK0), CMD2_BK0);
|
||||||
this->write_command_(SDIR_CMD); // this is in the BK0 command set
|
this->write_command_(SDIR_CMD); // this is in the BK0 command set
|
||||||
|
@ -153,7 +158,7 @@ void ST7701S::write_init_sequence_() {
|
||||||
val |= 0x10;
|
val |= 0x10;
|
||||||
this->write_command_(MADCTL_CMD);
|
this->write_command_(MADCTL_CMD);
|
||||||
this->write_data_(val);
|
this->write_data_(val);
|
||||||
esph_log_d(TAG, "write MADCTL %X", val);
|
ESP_LOGD(TAG, "write MADCTL %X", val);
|
||||||
this->write_command_(this->invert_colors_ ? INVERT_ON : INVERT_OFF);
|
this->write_command_(this->invert_colors_ ? INVERT_ON : INVERT_OFF);
|
||||||
this->set_timeout(120, [this] {
|
this->set_timeout(120, [this] {
|
||||||
this->write_command_(SLEEP_OUT);
|
this->write_command_(SLEEP_OUT);
|
||||||
|
|
|
@ -25,6 +25,7 @@ const uint8_t INVERT_ON = 0x21;
|
||||||
const uint8_t DISPLAY_ON = 0x29;
|
const uint8_t DISPLAY_ON = 0x29;
|
||||||
const uint8_t CMD2_BKSEL = 0xFF;
|
const uint8_t CMD2_BKSEL = 0xFF;
|
||||||
const uint8_t CMD2_BK0[5] = {0x77, 0x01, 0x00, 0x00, 0x10};
|
const uint8_t CMD2_BK0[5] = {0x77, 0x01, 0x00, 0x00, 0x10};
|
||||||
|
const uint8_t ST7701S_DELAY_FLAG = 0xFF;
|
||||||
|
|
||||||
class ST7701S : public display::Display,
|
class ST7701S : public display::Display,
|
||||||
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
|
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
|
||||||
|
|
|
@ -38,7 +38,12 @@ display:
|
||||||
hsync_pin: 16
|
hsync_pin: 16
|
||||||
vsync_pin: 17
|
vsync_pin: 17
|
||||||
pclk_pin: 21
|
pclk_pin: 21
|
||||||
init_sequence: 1
|
init_sequence:
|
||||||
|
- 1
|
||||||
|
- [0x23, 0xA, 0xB]
|
||||||
|
- delay 20ms
|
||||||
|
- [0x23, 0xA, 0xB]
|
||||||
|
- delay 0.2s
|
||||||
data_pins:
|
data_pins:
|
||||||
- number: 0
|
- number: 0
|
||||||
ignore_strapping_warning: true
|
ignore_strapping_warning: true
|
||||||
|
|
Loading…
Reference in a new issue