mirror of
https://github.com/esphome/esphome.git
synced 2026-08-23 06:36:23 +00:00
[mipi][mipi_spi] SWRESET handling improved (#17504)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
parent
9f62cf9243
commit
e6525b5d93
@@ -361,7 +361,8 @@ def test_native_generation(
|
||||
"mipi_spi::MipiSpiBuffer<uint16_t, mipi_spi::PIXEL_MODE_16, true, mipi_spi::PIXEL_MODE_16, mipi_spi::BUS_TYPE_QUAD, 360, 360, 0, 1, 0, 0, 0, true, 1, 1>()"
|
||||
in main_cpp
|
||||
)
|
||||
assert "set_init_sequence({240, 1, 8, 242" in main_cpp
|
||||
# A 10ms post-reset delay ({10, 255}) is prepended ahead of the model commands.
|
||||
assert "set_init_sequence({10, 255, 240, 1, 8, 242" in main_cpp
|
||||
assert "show_test_card();" in main_cpp
|
||||
assert "set_write_only(true);" in main_cpp
|
||||
|
||||
@@ -377,6 +378,76 @@ def test_lvgl_generation(
|
||||
"mipi_spi::MipiSpi<uint16_t, mipi_spi::PIXEL_MODE_16, true, mipi_spi::PIXEL_MODE_16, mipi_spi::BUS_TYPE_SINGLE, 128, 160, 0, 0, 0, 0, 0, true>();"
|
||||
in main_cpp
|
||||
)
|
||||
assert "set_init_sequence({177, 3, 1, 44, 45, 178" in main_cpp
|
||||
# A 10ms post-reset delay ({10, 255}) is prepended ahead of the model commands.
|
||||
assert "set_init_sequence({10, 255, 177, 3, 1, 44, 45, 178" in main_cpp
|
||||
assert "show_test_card();" not in main_cpp
|
||||
assert "set_auto_clear(false);" in main_cpp
|
||||
|
||||
|
||||
# A 10ms delay (flattened to {10, 0xFF}, where 0xFF is the delay marker byte) is
|
||||
# always prepended to the init sequence, since both a software and a hardware reset
|
||||
# need to settle before further commands. A custom model has no reset_pin default
|
||||
# and does not set no_swreset, so when no reset pin is configured the SWRESET command
|
||||
# ({1, 0}: command 0x01 with no parameters) is prepended ahead of that delay.
|
||||
_SWRESET_YAML = """
|
||||
esphome:
|
||||
name: swreset-test
|
||||
esp32:
|
||||
board: esp32-s3-devkitc-1
|
||||
framework:
|
||||
type: esp-idf
|
||||
spi:
|
||||
clk_pin: 1
|
||||
mosi_pin: 2
|
||||
display:
|
||||
- platform: mipi_spi
|
||||
model: custom
|
||||
id: {display_id}
|
||||
dc_pin: 4
|
||||
cs_pin: 8
|
||||
dimensions:
|
||||
width: 320
|
||||
height: 240
|
||||
init_sequence:
|
||||
- [0xA0, 0x01]
|
||||
{reset_line}
|
||||
"""
|
||||
|
||||
|
||||
def test_swreset_prepended_without_reset_pin(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""A model with no reset pin (and no no_swreset) gets SWRESET prepended."""
|
||||
yaml_file = tmp_path / "swreset.yaml"
|
||||
yaml_file.write_text(
|
||||
_SWRESET_YAML.format(display_id="swreset_display", reset_line="")
|
||||
)
|
||||
|
||||
main_cpp = generate_main(yaml_file)
|
||||
|
||||
# SWRESET ({1, 0}) followed by a 10ms delay ({10, 255}) is inserted ahead of
|
||||
# the model's own commands.
|
||||
assert "swreset_display->set_init_sequence({1, 0, 10, 255, 160, 1, 1," in main_cpp
|
||||
|
||||
|
||||
def test_swreset_not_prepended_with_reset_pin(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""A hardware reset pin performs the reset, so SWRESET must not be prepended.
|
||||
|
||||
The post-reset delay is still required, so the sequence starts with the delay.
|
||||
"""
|
||||
yaml_file = tmp_path / "hwreset.yaml"
|
||||
yaml_file.write_text(
|
||||
_SWRESET_YAML.format(
|
||||
display_id="hwreset_display", reset_line=" reset_pin: 5"
|
||||
)
|
||||
)
|
||||
|
||||
main_cpp = generate_main(yaml_file)
|
||||
|
||||
# The delay ({10, 255}) is still present, but no leading SWRESET ({1, 0}).
|
||||
assert "hwreset_display->set_init_sequence({10, 255, 160, 1, 1," in main_cpp
|
||||
assert "hwreset_display->set_init_sequence({1, 0," not in main_cpp
|
||||
|
||||
Reference in New Issue
Block a user