mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 11:44:13 +01:00
66761ff340
* Add serveral options for SSD1306 integration * Add SSD1305 support (SSD1305 is similar to SSD1306, it seems SSD1305 has brightness and color register but does not have charge pump) * Add some description when manipulating registers * Add flip, offset and invert option to get more compatibility with various display modules * Fix typo `setup_ssd1036' -> `setup_ssd1306' * Add SSD1306 brightness validation tip * Add more description, limit offset range * Changes according to linter * Fix test * Raise error instead of using warning * Fix wrong logic * Remove logger Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> * Remove logging import Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
34 lines
1 KiB
Python
34 lines
1 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome import pins
|
|
from esphome.components import spi, ssd1306_base
|
|
from esphome.components.ssd1306_base import _validate
|
|
from esphome.const import CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES
|
|
|
|
AUTO_LOAD = ["ssd1306_base"]
|
|
DEPENDENCIES = ["spi"]
|
|
|
|
ssd1306_spi = cg.esphome_ns.namespace("ssd1306_spi")
|
|
SPISSD1306 = ssd1306_spi.class_("SPISSD1306", ssd1306_base.SSD1306, spi.SPIDevice)
|
|
|
|
CONFIG_SCHEMA = cv.All(
|
|
ssd1306_base.SSD1306_SCHEMA.extend(
|
|
{
|
|
cv.GenerateID(): cv.declare_id(SPISSD1306),
|
|
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),
|
|
_validate,
|
|
)
|
|
|
|
|
|
async def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
await ssd1306_base.setup_ssd1306(var, config)
|
|
await spi.register_spi_device(var, config)
|
|
|
|
dc = await cg.gpio_pin_expression(config[CONF_DC_PIN])
|
|
cg.add(var.set_dc_pin(dc))
|