display.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """ESPHome display platform driving GxEPD2_213_Z98c via a native chunked
  2. refresh engine (see cycle_engine.h) instead of GxEPD2's own C++ classes.
  3. Only this one panel is wired up so far - this is the first slice of
  4. replacing the old GxEPD2-template/FreeRTOS-task component; see the plan
  5. this was implemented from. catalog.json/vendor/arduino_compat stay in the
  6. tree as reference material for later panels but aren't used by this file.
  7. """
  8. import esphome.codegen as cg
  9. import esphome.config_validation as cv
  10. from esphome import pins
  11. from esphome.components import display, spi
  12. from esphome.const import CONF_BUSY_PIN, CONF_CS_PIN, CONF_DC_PIN, CONF_ID, CONF_RESET_PIN, CONF_SPI_ID, Framework
  13. from esphome.types import ConfigType
  14. CODEOWNERS = ["@zib"]
  15. DEPENDENCIES = ["spi"]
  16. gxepd2_ns = cg.esphome_ns.namespace("gxepd2")
  17. GxEPD2Display = gxepd2_ns.class_("GxEPD2Display", display.DisplayBuffer)
  18. CONFIG_SCHEMA = cv.All(
  19. display.FULL_DISPLAY_SCHEMA.extend(
  20. {
  21. cv.GenerateID(): cv.declare_id(GxEPD2Display),
  22. cv.GenerateID(CONF_SPI_ID): cv.use_id(spi.SPIComponent),
  23. cv.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
  24. cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
  25. cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
  26. cv.Optional(CONF_BUSY_PIN): pins.gpio_input_pin_schema,
  27. }
  28. ),
  29. cv.only_with_framework(Framework.ESP_IDF),
  30. )
  31. async def to_code(config: ConfigType) -> None:
  32. var = cg.new_Pvariable(config[CONF_ID])
  33. cg.add(var.set_cs_pin(await cg.gpio_pin_expression(config[CONF_CS_PIN])))
  34. cg.add(var.set_dc_pin(await cg.gpio_pin_expression(config[CONF_DC_PIN])))
  35. if reset_pin := config.get(CONF_RESET_PIN):
  36. cg.add(var.set_reset_pin(await cg.gpio_pin_expression(reset_pin)))
  37. if busy_pin := config.get(CONF_BUSY_PIN):
  38. cg.add(var.set_busy_pin(await cg.gpio_pin_expression(busy_pin)))
  39. spi_parent = await cg.get_variable(config[CONF_SPI_ID])
  40. cg.add(var.set_spi_parent(spi_parent))
  41. await display.register_display(var, config)