Skip the table for an empty init sequence; test it

This commit is contained in:
J. Nick Koston
2026-10-03 05:52:13 -05:00
parent 96df32024d
commit 43c18c9e1c
2 changed files with 21 additions and 13 deletions
+3 -2
View File
@@ -181,8 +181,9 @@ async def to_code(config: ConfigType) -> None:
sequence = []
for seq in config[CONF_INIT_SEQUENCE]:
sequence.extend(seq)
table = cg.shared_progmem_array("st7701s_init_sequence", cg.uint8, sequence)
cg.add(var.set_init_sequence(table, len(sequence)))
if sequence:
table = cg.shared_progmem_array("st7701s_init_sequence", cg.uint8, sequence)
cg.add(var.set_init_sequence(table, len(sequence)))
cg.add(var.set_color_mode(COLOR_ORDERS[config[CONF_COLOR_ORDER]]))
cg.add(var.set_invert_colors(config[CONF_INVERT_COLORS]))
cg.add(var.set_hsync_pulse_width(config[CONF_HSYNC_PULSE_WIDTH]))
@@ -17,24 +17,17 @@ spi:
clk_pin: 10
mosi_pin: 11
display:
{displays}
"""
_DISPLAY = """
- platform: st7701s
id: {display_id}
id: panel
dimensions:
width: 480
height: 480
cs_pin: {cs_pin}
cs_pin: 44
de_pin: 18
hsync_pin: 16
vsync_pin: 17
pclk_pin: 21
init_sequence:
- 1
- [0x23, 0xA, 0xB]
- delay 20ms
init_sequence: {init_sequence}
data_pins: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, 38, 39]
"""
@@ -46,7 +39,7 @@ def test_init_sequence_is_progmem_table(
"""The init sequence is a PROGMEM table instead of a vector copied at boot."""
yaml_file = tmp_path / "st7701s.yaml"
yaml_file.write_text(
_YAML.format(displays=_DISPLAY.format(display_id="panel", cs_pin=44))
_YAML.format(init_sequence="[1, [0x23, 0xA, 0xB], delay 20ms]")
)
main_cpp = generate_main(yaml_file)
@@ -59,3 +52,17 @@ def test_init_sequence_is_progmem_table(
)
assert table is not None
assert len(table.group(1).split(",")) == int(call.group(2))
def test_empty_init_sequence_emits_no_table(
generate_main: Callable[[str | Path], str],
tmp_path: Path,
) -> None:
"""An empty init sequence leaves the display without a table instead of a zero length array."""
yaml_file = tmp_path / "st7701s.yaml"
yaml_file.write_text(_YAML.format(init_sequence="[]"))
main_cpp = generate_main(yaml_file)
assert "st7701s_init_sequence" not in main_cpp
assert "set_init_sequence" not in main_cpp