esphome/esphome/components/ssd1325_spi/display.py
igg 821c1a8bbd
making SPI CS optional (#988)
* making SPI CS optional

* CS pin should be declared as optional or required in CONFIG_SCHEMA

* changed SPI_DEVICE_SCHEMA to a function, like i2c

* added spi_device_schema() to pcd8544, lint fixes

* updated max31856 with new spi_device_schema()

* cleanup imports

Co-authored-by: Ilya Goldberg <iggie@mac.com>
2020-06-10 17:03:11 -03:00

26 lines
963 B
Python

import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import spi, ssd1325_base
from esphome.const import CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES
AUTO_LOAD = ['ssd1325_base']
DEPENDENCIES = ['spi']
ssd1325_spi = cg.esphome_ns.namespace('ssd1325_spi')
SPISSD1325 = ssd1325_spi.class_('SPISSD1325', ssd1325_base.SSD1325, spi.SPIDevice)
CONFIG_SCHEMA = cv.All(ssd1325_base.SSD1325_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(SPISSD1325),
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))
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield ssd1325_base.setup_ssd1036(var, config)
yield spi.register_spi_device(var, config)
dc = yield cg.gpio_pin_expression(config[CONF_DC_PIN])
cg.add(var.set_dc_pin(dc))