st7735_conf_fixes (#1530)

This commit is contained in:
SenexCrenshaw 2021-02-14 00:21:43 -05:00 committed by GitHub
parent b52f7cfe86
commit a342302114
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 40 deletions

View file

@ -4,50 +4,67 @@ from esphome import pins
from esphome.components import spi from esphome.components import spi
from esphome.components import display from esphome.components import display
from esphome.core import coroutine from esphome.core import coroutine
from esphome.const import CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_MODEL, CONF_RESET_PIN, CONF_PAGES from esphome.const import (
CONF_DC_PIN,
CONF_ID,
CONF_LAMBDA,
CONF_MODEL,
CONF_RESET_PIN,
CONF_PAGES,
)
from . import st7735_ns from . import st7735_ns
CODEOWNERS = ['@SenexCrenshaw'] CODEOWNERS = ["@SenexCrenshaw"]
DEPENDENCIES = ['spi'] DEPENDENCIES = ["spi"]
CONF_DEVICEWIDTH = 'devicewidth' CONF_DEVICE_WIDTH = "device_width"
CONF_DEVICEHEIGHT = 'deviceheight' CONF_DEVICE_HEIGHT = "device_height"
CONF_ROWSTART = 'rowstart' CONF_ROW_START = "row_start"
CONF_COLSTART = 'colstart' CONF_COL_START = "col_start"
CONF_EIGHTBITCOLOR = 'eightbitcolor' CONF_EIGHT_BIT_COLOR = "eight_bit_color"
CONF_USEBGR = 'usebgr' CONF_USE_BGR = "use_bgr"
SPIST7735 = st7735_ns.class_('ST7735', cg.PollingComponent, display.DisplayBuffer, spi.SPIDevice) SPIST7735 = st7735_ns.class_(
ST7735Model = st7735_ns.enum('ST7735Model') "ST7735", cg.PollingComponent, display.DisplayBuffer, spi.SPIDevice
)
ST7735Model = st7735_ns.enum("ST7735Model")
MODELS = { MODELS = {
'INITR_GREENTAB': ST7735Model.ST7735_INITR_GREENTAB, "INITR_GREENTAB": ST7735Model.ST7735_INITR_GREENTAB,
'INITR_REDTAB': ST7735Model.ST7735_INITR_REDTAB, "INITR_REDTAB": ST7735Model.ST7735_INITR_REDTAB,
'INITR_BLACKTAB': ST7735Model.ST7735_INITR_BLACKTAB, "INITR_BLACKTAB": ST7735Model.ST7735_INITR_BLACKTAB,
'INITR_MINI160X80': ST7735Model.ST7735_INITR_MINI_160X80, "INITR_MINI160X80": ST7735Model.ST7735_INITR_MINI_160X80,
'INITR_18BLACKTAB': ST7735Model.ST7735_INITR_18BLACKTAB, "INITR_18BLACKTAB": ST7735Model.ST7735_INITR_18BLACKTAB,
'INITR_18REDTAB': ST7735Model.ST7735_INITR_18REDTAB "INITR_18REDTAB": ST7735Model.ST7735_INITR_18REDTAB,
} }
ST7735_MODEL = cv.enum(MODELS, upper=True, space="_") ST7735_MODEL = cv.enum(MODELS, upper=True, space="_")
ST7735_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend({ ST7735_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend(
cv.Required(CONF_MODEL): ST7735_MODEL, {
cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema cv.Required(CONF_MODEL): ST7735_MODEL,
}).extend(cv.polling_component_schema('1s')) cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
}
).extend(cv.polling_component_schema("1s"))
CONFIG_SCHEMA = cv.All(ST7735_SCHEMA.extend({ CONFIG_SCHEMA = cv.All(
cv.GenerateID(): cv.declare_id(SPIST7735), ST7735_SCHEMA.extend(
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema, {
cv.Required(CONF_DEVICEWIDTH): cv.int_, cv.GenerateID(): cv.declare_id(SPIST7735),
cv.Required(CONF_DEVICEHEIGHT): cv.int_, cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
cv.Required(CONF_COLSTART): cv.int_, cv.Required(CONF_DEVICE_WIDTH): cv.int_,
cv.Required(CONF_ROWSTART): cv.int_, cv.Required(CONF_DEVICE_HEIGHT): cv.int_,
cv.Optional(CONF_EIGHTBITCOLOR, default=False): cv.boolean, cv.Required(CONF_COL_START): cv.int_,
cv.Optional(CONF_USEBGR, default=False): cv.boolean, cv.Required(CONF_ROW_START): cv.int_,
}).extend(cv.COMPONENT_SCHEMA).extend(spi.spi_device_schema()), cv.Optional(CONF_EIGHT_BIT_COLOR, default=False): cv.boolean,
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA)) cv.Optional(CONF_USE_BGR, default=False): cv.boolean,
}
)
.extend(cv.COMPONENT_SCHEMA)
.extend(spi.spi_device_schema()),
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA),
)
@coroutine @coroutine
@ -60,14 +77,22 @@ def setup_st7735(var, config):
cg.add(var.set_reset_pin(reset)) cg.add(var.set_reset_pin(reset))
if CONF_LAMBDA in config: if CONF_LAMBDA in config:
lambda_ = yield cg.process_lambda( lambda_ = yield cg.process_lambda(
config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')], return_type=cg.void) config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void
)
cg.add(var.set_writer(lambda_)) cg.add(var.set_writer(lambda_))
def to_code(config): def to_code(config):
var = cg.new_Pvariable(config[CONF_ID], config[CONF_MODEL], config[CONF_DEVICEWIDTH], var = cg.new_Pvariable(
config[CONF_DEVICEHEIGHT], config[CONF_COLSTART], config[CONF_ROWSTART], config[CONF_ID],
config[CONF_EIGHTBITCOLOR], config[CONF_USEBGR]) config[CONF_MODEL],
config[CONF_DEVICE_WIDTH],
config[CONF_DEVICE_HEIGHT],
config[CONF_COL_START],
config[CONF_ROW_START],
config[CONF_EIGHT_BIT_COLOR],
config[CONF_USE_BGR],
)
yield setup_st7735(var, config) yield setup_st7735(var, config)
yield spi.register_spi_device(var, config) yield spi.register_spi_device(var, config)

View file

@ -1825,10 +1825,10 @@ display:
dc_pin: GPIO16 dc_pin: GPIO16
reset_pin: GPIO23 reset_pin: GPIO23
rotation: 0 rotation: 0
devicewidth: 128 device_width: 128
deviceheight: 160 device_height: 160
colstart: 0 col_start: 0
rowstart: 0 row_start: 0
lambda: |- lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height()); it.rectangle(0, 0, it.get_width(), it.get_height());
tm1651: tm1651: