mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
[mipi_rgb] Fix rotation with custom model (#11585)
This commit is contained in:
@@ -384,6 +384,18 @@ class DriverChip:
|
|||||||
transform[CONF_TRANSFORM] = True
|
transform[CONF_TRANSFORM] = True
|
||||||
return transform
|
return transform
|
||||||
|
|
||||||
|
def swap_xy_schema(self):
|
||||||
|
uses_swap = self.get_default(CONF_SWAP_XY, None) != cv.UNDEFINED
|
||||||
|
|
||||||
|
def validator(value):
|
||||||
|
if value:
|
||||||
|
raise cv.Invalid("Axis swapping not supported by this model")
|
||||||
|
return cv.boolean(value)
|
||||||
|
|
||||||
|
if uses_swap:
|
||||||
|
return {cv.Required(CONF_SWAP_XY): cv.boolean}
|
||||||
|
return {cv.Optional(CONF_SWAP_XY, default=False): validator}
|
||||||
|
|
||||||
def add_madctl(self, sequence: list, config: dict):
|
def add_madctl(self, sequence: list, config: dict):
|
||||||
# Add the MADCTL command to the sequence based on the configuration.
|
# Add the MADCTL command to the sequence based on the configuration.
|
||||||
use_flip = config.get(CONF_USE_AXIS_FLIPS)
|
use_flip = config.get(CONF_USE_AXIS_FLIPS)
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ from esphome.const import (
|
|||||||
CONF_DATA_RATE,
|
CONF_DATA_RATE,
|
||||||
CONF_DC_PIN,
|
CONF_DC_PIN,
|
||||||
CONF_DIMENSIONS,
|
CONF_DIMENSIONS,
|
||||||
|
CONF_DISABLED,
|
||||||
CONF_ENABLE_PIN,
|
CONF_ENABLE_PIN,
|
||||||
CONF_GREEN,
|
CONF_GREEN,
|
||||||
CONF_HSYNC_PIN,
|
CONF_HSYNC_PIN,
|
||||||
@@ -117,16 +118,16 @@ def data_pin_set(length):
|
|||||||
|
|
||||||
def model_schema(config):
|
def model_schema(config):
|
||||||
model = MODELS[config[CONF_MODEL].upper()]
|
model = MODELS[config[CONF_MODEL].upper()]
|
||||||
if transforms := model.transforms:
|
transform = cv.Any(
|
||||||
transform = cv.Schema({cv.Required(x): cv.boolean for x in transforms})
|
cv.Schema(
|
||||||
for x in (CONF_SWAP_XY, CONF_MIRROR_X, CONF_MIRROR_Y):
|
{
|
||||||
if x not in transforms:
|
cv.Required(CONF_MIRROR_X): cv.boolean,
|
||||||
transform = transform.extend(
|
cv.Required(CONF_MIRROR_Y): cv.boolean,
|
||||||
{cv.Optional(x): cv.invalid(f"{x} not supported by this model")}
|
**model.swap_xy_schema(),
|
||||||
)
|
}
|
||||||
else:
|
),
|
||||||
transform = cv.invalid("This model does not support transforms")
|
cv.one_of(CONF_DISABLED, lower=True),
|
||||||
|
)
|
||||||
# RPI model does not use an init sequence, indicates with empty list
|
# RPI model does not use an init sequence, indicates with empty list
|
||||||
if model.initsequence is None:
|
if model.initsequence is None:
|
||||||
# Custom model requires an init sequence
|
# Custom model requires an init sequence
|
||||||
@@ -135,12 +136,16 @@ def model_schema(config):
|
|||||||
else:
|
else:
|
||||||
iseqconf = cv.Optional(CONF_INIT_SEQUENCE)
|
iseqconf = cv.Optional(CONF_INIT_SEQUENCE)
|
||||||
uses_spi = CONF_INIT_SEQUENCE in config or len(model.initsequence) != 0
|
uses_spi = CONF_INIT_SEQUENCE in config or len(model.initsequence) != 0
|
||||||
swap_xy = config.get(CONF_TRANSFORM, {}).get(CONF_SWAP_XY, False)
|
# Dimensions are optional if the model has a default width and the x-y transform is not overridden
|
||||||
|
transform_config = config.get(CONF_TRANSFORM, {})
|
||||||
# Dimensions are optional if the model has a default width and the swap_xy transform is not overridden
|
is_swapped = (
|
||||||
cv_dimensions = (
|
isinstance(transform_config, dict)
|
||||||
cv.Optional if model.get_default(CONF_WIDTH) and not swap_xy else cv.Required
|
and transform_config.get(CONF_SWAP_XY, False) is True
|
||||||
)
|
)
|
||||||
|
cv_dimensions = (
|
||||||
|
cv.Optional if model.get_default(CONF_WIDTH) and not is_swapped else cv.Required
|
||||||
|
)
|
||||||
|
|
||||||
pixel_modes = (PIXEL_MODE_16BIT, PIXEL_MODE_18BIT, "16", "18")
|
pixel_modes = (PIXEL_MODE_16BIT, PIXEL_MODE_18BIT, "16", "18")
|
||||||
schema = display.FULL_DISPLAY_SCHEMA.extend(
|
schema = display.FULL_DISPLAY_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
@@ -157,7 +162,7 @@ def model_schema(config):
|
|||||||
model.option(CONF_PIXEL_MODE, PIXEL_MODE_16BIT): cv.one_of(
|
model.option(CONF_PIXEL_MODE, PIXEL_MODE_16BIT): cv.one_of(
|
||||||
*pixel_modes, lower=True
|
*pixel_modes, lower=True
|
||||||
),
|
),
|
||||||
model.option(CONF_TRANSFORM, cv.UNDEFINED): transform,
|
cv.Optional(CONF_TRANSFORM): transform,
|
||||||
cv.Required(CONF_MODEL): cv.one_of(model.name, upper=True),
|
cv.Required(CONF_MODEL): cv.one_of(model.name, upper=True),
|
||||||
model.option(CONF_INVERT_COLORS, False): cv.boolean,
|
model.option(CONF_INVERT_COLORS, False): cv.boolean,
|
||||||
model.option(CONF_USE_AXIS_FLIPS, True): cv.boolean,
|
model.option(CONF_USE_AXIS_FLIPS, True): cv.boolean,
|
||||||
@@ -270,7 +275,6 @@ async def to_code(config):
|
|||||||
cg.add(var.set_vsync_front_porch(config[CONF_VSYNC_FRONT_PORCH]))
|
cg.add(var.set_vsync_front_porch(config[CONF_VSYNC_FRONT_PORCH]))
|
||||||
cg.add(var.set_pclk_inverted(config[CONF_PCLK_INVERTED]))
|
cg.add(var.set_pclk_inverted(config[CONF_PCLK_INVERTED]))
|
||||||
cg.add(var.set_pclk_frequency(config[CONF_PCLK_FREQUENCY]))
|
cg.add(var.set_pclk_frequency(config[CONF_PCLK_FREQUENCY]))
|
||||||
index = 0
|
|
||||||
dpins = []
|
dpins = []
|
||||||
if CONF_RED in config[CONF_DATA_PINS]:
|
if CONF_RED in config[CONF_DATA_PINS]:
|
||||||
red_pins = config[CONF_DATA_PINS][CONF_RED]
|
red_pins = config[CONF_DATA_PINS][CONF_RED]
|
||||||
|
|||||||
@@ -131,19 +131,6 @@ def denominator(config):
|
|||||||
) from StopIteration
|
) from StopIteration
|
||||||
|
|
||||||
|
|
||||||
def swap_xy_schema(model):
|
|
||||||
uses_swap = model.get_default(CONF_SWAP_XY, None) != cv.UNDEFINED
|
|
||||||
|
|
||||||
def validator(value):
|
|
||||||
if value:
|
|
||||||
raise cv.Invalid("Axis swapping not supported by this model")
|
|
||||||
return cv.boolean(value)
|
|
||||||
|
|
||||||
if uses_swap:
|
|
||||||
return {cv.Required(CONF_SWAP_XY): cv.boolean}
|
|
||||||
return {cv.Optional(CONF_SWAP_XY, default=False): validator}
|
|
||||||
|
|
||||||
|
|
||||||
def model_schema(config):
|
def model_schema(config):
|
||||||
model = MODELS[config[CONF_MODEL]]
|
model = MODELS[config[CONF_MODEL]]
|
||||||
bus_mode = config[CONF_BUS_MODE]
|
bus_mode = config[CONF_BUS_MODE]
|
||||||
@@ -152,7 +139,7 @@ def model_schema(config):
|
|||||||
{
|
{
|
||||||
cv.Required(CONF_MIRROR_X): cv.boolean,
|
cv.Required(CONF_MIRROR_X): cv.boolean,
|
||||||
cv.Required(CONF_MIRROR_Y): cv.boolean,
|
cv.Required(CONF_MIRROR_Y): cv.boolean,
|
||||||
**swap_xy_schema(model),
|
**model.swap_xy_schema(),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
cv.one_of(CONF_DISABLED, lower=True),
|
cv.one_of(CONF_DISABLED, lower=True),
|
||||||
|
|||||||
Reference in New Issue
Block a user