esphome/esphome/components/ssd1331_spi/display.py

35 lines
1 KiB
Python
Raw Normal View History

2020-11-18 07:34:53 +01:00
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import spi, ssd1331_base
from esphome.const import CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES
CODEOWNERS = ["@kbx81"]
2020-11-18 07:34:53 +01:00
AUTO_LOAD = ["ssd1331_base"]
DEPENDENCIES = ["spi"]
2020-11-18 07:34:53 +01:00
ssd1331_spi = cg.esphome_ns.namespace("ssd1331_spi")
SPISSD1331 = ssd1331_spi.class_("SPISSD1331", ssd1331_base.SSD1331, spi.SPIDevice)
2020-11-18 07:34:53 +01:00
CONFIG_SCHEMA = cv.All(
ssd1331_base.SSD1331_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(SPISSD1331),
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
}
)
.extend(cv.COMPONENT_SCHEMA)
.extend(spi.spi_device_schema()),
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA),
)
2020-11-18 07:34:53 +01:00
async def to_code(config):
2020-11-18 07:34:53 +01:00
var = cg.new_Pvariable(config[CONF_ID])
await ssd1331_base.setup_ssd1331(var, config)
await spi.register_spi_device(var, config)
2020-11-18 07:34:53 +01:00
dc = await cg.gpio_pin_expression(config[CONF_DC_PIN])
2020-11-18 07:34:53 +01:00
cg.add(var.set_dc_pin(dc))