4ec8c7a935
The 2 ms reset of ESPHome's expander support (0.2.81) left the chip silent: "Calibration error" with the PCA9557 answering at 0x18. A component of smart_display's (elecrow_touch_reset.h, setup priority 700: after the I2C bus, before the GT911 driver) writes the expander as Elecrow's V3.0 ESPHome example does: every pin an output and low, 20 ms, the reset released, 100 ms, the interrupt line back to an input. The driver's reset and interrupt pins are gone.
70 lines
3.0 KiB
Python
70 lines
3.0 KiB
Python
"""Runtime tile configuration transported through the normal ESPHome API.
|
|
|
|
`smart_display: language: nl` (app 0.2.90) builds the screen's texts in that language: the `screen` section of
|
|
screen_manager/translations/nl.json, with English for any key it lacks, becomes one table in main.cpp
|
|
(screen_text_gen.py, screen_text.h). The shared core sets it from the LANGUAGE substitution, which ESP Screens writes
|
|
into a screen's YAML.
|
|
|
|
`smart_display: partitions: 4mb_wide_slots` (firmware 0.2.79) builds with one of the partition tables of partitions.py
|
|
instead of ESPHome's own: two update slots of 1,984 KB on a 4 MB ESP32-S3, which the Elecrow CrowPanel 7.0" needs.
|
|
|
|
`smart_display: elecrow_touch_reset: {i2c_id: ..., address: 0x18}` (firmware 0.2.82) brings the GT911 of the Elecrow
|
|
CrowPanel 7.0" V3.0 out of reset through its PCA9557 before the touch driver runs (elecrow_touch_reset.h).
|
|
"""
|
|
import logging
|
|
|
|
import esphome.codegen as cg
|
|
from esphome.components import esp32, i2c
|
|
import esphome.config_validation as cv
|
|
from esphome.const import CONF_ID
|
|
from esphome.core import CORE
|
|
from esphome.helpers import write_file_if_changed
|
|
|
|
from . import partitions, screen_text_gen
|
|
|
|
CODEOWNERS = []
|
|
AUTO_LOAD = ["json"]
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
CONF_LANGUAGE = "language"
|
|
CONF_PARTITIONS = "partitions"
|
|
CONF_ELECROW_TOUCH_RESET = "elecrow_touch_reset"
|
|
|
|
elecrow_ns = cg.global_ns.namespace("elecrow")
|
|
TouchReset = elecrow_ns.class_("TouchReset", cg.Component, i2c.I2CDevice)
|
|
|
|
|
|
def _language(value):
|
|
value = cv.string_strict(value).strip()
|
|
if not screen_text_gen.LANGUAGE_CODE.fullmatch(value):
|
|
raise cv.Invalid("Expected a language code such as en, nl or pt-BR")
|
|
return value
|
|
|
|
|
|
CONFIG_SCHEMA = cv.Schema({
|
|
cv.Optional(CONF_LANGUAGE, default="en"): _language,
|
|
cv.Optional(CONF_PARTITIONS): cv.one_of(*partitions.TABLES, lower=True),
|
|
cv.Optional(CONF_ELECROW_TOUCH_RESET): cv.Schema({cv.GenerateID(): cv.declare_id(TouchReset)})
|
|
.extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x18)),
|
|
})
|
|
|
|
|
|
async def to_code(config):
|
|
wanted = config[CONF_LANGUAGE]
|
|
language, code = screen_text_gen.definitions(wanted)
|
|
if language != wanted:
|
|
# ESP Screens only writes languages it has; a hand-written one it lacks builds in the nearest it does have.
|
|
_LOGGER.warning("No translation for %s yet; the screen's texts are in %s", wanted, language)
|
|
cg.add_global(cg.RawStatement(code))
|
|
if CONF_PARTITIONS in config:
|
|
# ESPHome writes no partitions.csv of its own when one is among the extra build files (esp32.copy_files).
|
|
table = CORE.relative_build_path("smart_display_partitions.csv")
|
|
write_file_if_changed(table, partitions.TABLES[config[CONF_PARTITIONS]])
|
|
esp32.add_extra_build_file("partitions.csv", table)
|
|
if CONF_ELECROW_TOUCH_RESET in config:
|
|
conf = config[CONF_ELECROW_TOUCH_RESET]
|
|
reset = cg.new_Pvariable(conf[CONF_ID])
|
|
await cg.register_component(reset, conf)
|
|
await i2c.register_i2c_device(reset, conf)
|
|
cg.add_build_flag("-DESP_SCREENS_ELECROW_TOUCH_RESET=1")
|