mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-06 04:48:27 +02:00
Renaming and extending the ili9341 to the ili9xxx component (#4275)
* - Removed cleaning the screen twice. \Should be handled by `DisplayBuffer::init_internal_();` - Made ili9341::initalize() protected and renamed \ it to ili9341::initalize(). - ili9341::initalize() should only init the display \ and set the width and heigth. * removed to much * clang format fixes * removing trailing underscors for protected virtual methods * removed the "override" on display() * clang fixes * restored old changes * Renamed the ili9341 platform to ili9xxx and added multiple drivers as well. including PR #3848 * fixed most of the clang reported issues * fixed reported issues * last fixes * Setting the right codeowners * missing changes * fixed naming Display() method. * clang again * clang fix * fixes reported by @jesserockz & @gpambrozio * a change to display.py removing an unneeded var * re-introduce **backlight** option. * update the ili9488 initialization * update the ili9488 initialization and fix typo * fixed typo * add missing constants * swap height and width back for the ili9488 * init fixes ili9488 * fixed lint issue testing the init code * oeps * init fixes ili9488 * fixed wrong define * fixed wrong define again * removed some spaces * revert to ili9341 * Remove parts that where used for the switchplate * lint fixes and removing unused function * fix error and introducing 16bit color option * fix error and introducing 16bit color option * fix clang issue * clang fix * clang issue again * is this what clang exprect * clang fix * clang fix * try again * let try again * and again * and the last clang fix * remove the need of wifi * update dimentions * update ili8488 init code. * update dimentions * allow to change height and width * dump color mode config * fix * fix * modify logging * referd back unrelated change * code formatting commit and moving functions around * add missing ; * update code * update code * use the correct write_array for sending uint16_t * fix panic loop * fix panic loop * - update the test file - fixed sending display data * clang fixes * clang fixes * clang fixes again * remove .gitignore items * remove .gitignore items * make sure Update() can can not be called while called * clang correction * adding a test yaml for the ili9341 * Update ili9341 example * Make test ili9xxx/tests only local * restore back old ili9341 driver code * Add a new config for the M5Core * fix clang request * reverd to restore of the old ili9341 there is no proper way to say it is depricated. * Remove the backlight/led pin from the config. You need to use a proper light platform component * Ili9488init changes (#88) Fixed ILI9488 init settings, and adjusted pixel handling code to push pixels in 18 bit format. This does not change the internal 16-bit representation. * fixed some leftover clang issues from the merge. * fixed the slang-tidy request. * remove `backlight_pin` warning. --------- Co-authored-by: JD Steffen <jdsteffen81@gmail.com>
This commit is contained in:
@@ -1,153 +1,5 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import core, pins
|
||||
from esphome.components import display, spi
|
||||
from esphome.const import (
|
||||
CONF_COLOR_PALETTE,
|
||||
CONF_DC_PIN,
|
||||
CONF_ID,
|
||||
CONF_LAMBDA,
|
||||
CONF_MODEL,
|
||||
CONF_PAGES,
|
||||
CONF_RAW_DATA_ID,
|
||||
CONF_RESET_PIN,
|
||||
|
||||
CONFIG_SCHEMA = cv.invalid(
|
||||
"The ili9341 platform component has been renamed to ili9xxx."
|
||||
)
|
||||
from esphome.core import CORE, HexInt
|
||||
|
||||
DEPENDENCIES = ["spi"]
|
||||
|
||||
CONF_COLOR_PALETTE_IMAGES = "color_palette_images"
|
||||
CONF_LED_PIN = "led_pin"
|
||||
|
||||
ili9341_ns = cg.esphome_ns.namespace("ili9341")
|
||||
ili9341 = ili9341_ns.class_(
|
||||
"ILI9341Display", cg.PollingComponent, spi.SPIDevice, display.DisplayBuffer
|
||||
)
|
||||
ILI9341M5Stack = ili9341_ns.class_("ILI9341M5Stack", ili9341)
|
||||
ILI9341TFT24 = ili9341_ns.class_("ILI9341TFT24", ili9341)
|
||||
ILI9341TFT24R = ili9341_ns.class_("ILI9341TFT24R", ili9341)
|
||||
|
||||
ILI9341Model = ili9341_ns.enum("ILI9341Model")
|
||||
ILI9341ColorMode = ili9341_ns.enum("ILI9341ColorMode")
|
||||
|
||||
MODELS = {
|
||||
"M5STACK": ILI9341Model.M5STACK,
|
||||
"TFT_2.4": ILI9341Model.TFT_24,
|
||||
"TFT_2.4R": ILI9341Model.TFT_24R,
|
||||
}
|
||||
|
||||
ILI9341_MODEL = cv.enum(MODELS, upper=True, space="_")
|
||||
|
||||
COLOR_PALETTE = cv.one_of("NONE", "GRAYSCALE", "IMAGE_ADAPTIVE")
|
||||
|
||||
|
||||
def _validate(config):
|
||||
if config.get(CONF_COLOR_PALETTE) == "IMAGE_ADAPTIVE" and not config.get(
|
||||
CONF_COLOR_PALETTE_IMAGES
|
||||
):
|
||||
raise cv.Invalid(
|
||||
"Color palette in IMAGE_ADAPTIVE mode requires at least one 'color_palette_images' entry to generate palette"
|
||||
)
|
||||
if (
|
||||
config.get(CONF_COLOR_PALETTE_IMAGES)
|
||||
and config.get(CONF_COLOR_PALETTE) != "IMAGE_ADAPTIVE"
|
||||
):
|
||||
raise cv.Invalid(
|
||||
"Providing color palette images requires palette mode to be 'IMAGE_ADAPTIVE'"
|
||||
)
|
||||
return config
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
display.FULL_DISPLAY_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(ili9341),
|
||||
cv.Required(CONF_MODEL): ILI9341_MODEL,
|
||||
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_LED_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_COLOR_PALETTE, default="NONE"): COLOR_PALETTE,
|
||||
cv.Optional(CONF_COLOR_PALETTE_IMAGES, default=[]): cv.ensure_list(
|
||||
cv.file_
|
||||
),
|
||||
cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_id(cg.uint8),
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("1s"))
|
||||
.extend(spi.spi_device_schema(False)),
|
||||
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA),
|
||||
_validate,
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
if config[CONF_MODEL] == "M5STACK":
|
||||
lcd_type = ILI9341M5Stack
|
||||
if config[CONF_MODEL] == "TFT_2.4":
|
||||
lcd_type = ILI9341TFT24
|
||||
if config[CONF_MODEL] == "TFT_2.4R":
|
||||
lcd_type = ILI9341TFT24R
|
||||
rhs = lcd_type.new()
|
||||
var = cg.Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
await spi.register_spi_device(var, config)
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
dc = await cg.gpio_pin_expression(config[CONF_DC_PIN])
|
||||
cg.add(var.set_dc_pin(dc))
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void
|
||||
)
|
||||
cg.add(var.set_writer(lambda_))
|
||||
if CONF_RESET_PIN in config:
|
||||
reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
if CONF_LED_PIN in config:
|
||||
led_pin = await cg.gpio_pin_expression(config[CONF_LED_PIN])
|
||||
cg.add(var.set_led_pin(led_pin))
|
||||
|
||||
rhs = None
|
||||
if config[CONF_COLOR_PALETTE] == "GRAYSCALE":
|
||||
cg.add(var.set_buffer_color_mode(ILI9341ColorMode.BITS_8_INDEXED))
|
||||
rhs = []
|
||||
for x in range(256):
|
||||
rhs.extend([HexInt(x), HexInt(x), HexInt(x)])
|
||||
elif config[CONF_COLOR_PALETTE] == "IMAGE_ADAPTIVE":
|
||||
cg.add(var.set_buffer_color_mode(ILI9341ColorMode.BITS_8_INDEXED))
|
||||
from PIL import Image
|
||||
|
||||
def load_image(filename):
|
||||
path = CORE.relative_config_path(filename)
|
||||
try:
|
||||
return Image.open(path)
|
||||
except Exception as e:
|
||||
raise core.EsphomeError(f"Could not load image file {path}: {e}")
|
||||
|
||||
# make a wide horizontal combined image.
|
||||
images = [load_image(x) for x in config[CONF_COLOR_PALETTE_IMAGES]]
|
||||
total_width = sum(i.width for i in images)
|
||||
max_height = max(i.height for i in images)
|
||||
|
||||
ref_image = Image.new("RGB", (total_width, max_height))
|
||||
x = 0
|
||||
for i in images:
|
||||
ref_image.paste(i, (x, 0))
|
||||
x = x + i.width
|
||||
|
||||
# reduce the colors on combined image to 256.
|
||||
converted = ref_image.convert("P", palette=Image.ADAPTIVE, colors=256)
|
||||
# if you want to verify how the images look use
|
||||
# ref_image.save("ref_in.png")
|
||||
# converted.save("ref_out.png")
|
||||
palette = converted.getpalette()
|
||||
assert len(palette) == 256 * 3
|
||||
rhs = palette
|
||||
else:
|
||||
cg.add(var.set_buffer_color_mode(ILI9341ColorMode.BITS_8))
|
||||
|
||||
if rhs is not None:
|
||||
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
|
||||
cg.add(var.set_palette(prog_arr))
|
||||
|
||||
Reference in New Issue
Block a user