1
0
mirror of https://github.com/esphome/esphome.git synced 2025-01-18 12:05:41 +00:00

[ili9xxx] psram and 8 bit changes (#8084)

This commit is contained in:
Clyde Stubbs 2025-01-15 09:53:44 +11:00 committed by GitHub
parent c3412df169
commit e8d2ad4ce8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 17 deletions

View File

@ -1,9 +1,12 @@
import logging
from esphome import core, pins from esphome import core, pins
import esphome.codegen as cg import esphome.codegen as cg
from esphome.components import display, spi from esphome.components import display, spi
from esphome.components.display import validate_rotation from esphome.components.display import validate_rotation
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.const import ( from esphome.const import (
CONF_AUTO_CLEAR_ENABLED,
CONF_COLOR_ORDER, CONF_COLOR_ORDER,
CONF_COLOR_PALETTE, CONF_COLOR_PALETTE,
CONF_DC_PIN, CONF_DC_PIN,
@ -27,17 +30,12 @@ from esphome.const import (
CONF_WIDTH, CONF_WIDTH,
) )
from esphome.core import CORE, HexInt from esphome.core import CORE, HexInt
from esphome.final_validate import full_config
DEPENDENCIES = ["spi"] DEPENDENCIES = ["spi"]
def AUTO_LOAD():
if CORE.is_esp32:
return ["psram"]
return []
CODEOWNERS = ["@nielsnl68", "@clydebarrow"] CODEOWNERS = ["@nielsnl68", "@clydebarrow"]
LOGGER = logging.getLogger(__name__)
ili9xxx_ns = cg.esphome_ns.namespace("ili9xxx") ili9xxx_ns = cg.esphome_ns.namespace("ili9xxx")
ILI9XXXDisplay = ili9xxx_ns.class_( ILI9XXXDisplay = ili9xxx_ns.class_(
@ -84,7 +82,7 @@ COLOR_ORDERS = {
"BGR": ColorOrder.COLOR_ORDER_BGR, "BGR": ColorOrder.COLOR_ORDER_BGR,
} }
COLOR_PALETTE = cv.one_of("NONE", "GRAYSCALE", "IMAGE_ADAPTIVE") COLOR_PALETTE = cv.one_of("NONE", "GRAYSCALE", "IMAGE_ADAPTIVE", "8BIT", upper=True)
CONF_LED_PIN = "led_pin" CONF_LED_PIN = "led_pin"
CONF_COLOR_PALETTE_IMAGES = "color_palette_images" CONF_COLOR_PALETTE_IMAGES = "color_palette_images"
@ -195,9 +193,27 @@ CONFIG_SCHEMA = cv.All(
_validate, _validate,
) )
FINAL_VALIDATE_SCHEMA = spi.final_validate_device_schema(
"ili9xxx", require_miso=False, require_mosi=True def final_validate(config):
) global_config = full_config.get()
# Ideally would calculate buffer size here, but that info is not available on the Python side
needs_buffer = (
CONF_LAMBDA in config or CONF_PAGES in config or config[CONF_AUTO_CLEAR_ENABLED]
)
if (
CORE.is_esp32
and config[CONF_COLOR_PALETTE] == "NONE"
and "psram" not in global_config
and needs_buffer
):
LOGGER.info("Consider enabling PSRAM if available for the display buffer")
return spi.final_validate_device_schema(
"ili9xxx", require_miso=False, require_mosi=True
)
FINAL_VALIDATE_SCHEMA = final_validate
async def to_code(config): async def to_code(config):
@ -283,6 +299,8 @@ async def to_code(config):
palette = converted.getpalette() palette = converted.getpalette()
assert len(palette) == 256 * 3 assert len(palette) == 256 * 3
rhs = palette rhs = palette
elif config[CONF_COLOR_PALETTE] == "8BIT":
cg.add(var.set_buffer_color_mode(ILI9XXXColorMode.BITS_8))
else: else:
cg.add(var.set_buffer_color_mode(ILI9XXXColorMode.BITS_16)) cg.add(var.set_buffer_color_mode(ILI9XXXColorMode.BITS_16))

View File

@ -66,12 +66,9 @@ void ILI9XXXDisplay::setup() {
void ILI9XXXDisplay::alloc_buffer_() { void ILI9XXXDisplay::alloc_buffer_() {
if (this->buffer_color_mode_ == BITS_16) { if (this->buffer_color_mode_ == BITS_16) {
this->init_internal_(this->get_buffer_length_() * 2); this->init_internal_(this->get_buffer_length_() * 2);
if (this->buffer_ != nullptr) { } else {
return; this->init_internal_(this->get_buffer_length_());
}
this->buffer_color_mode_ = BITS_8;
} }
this->init_internal_(this->get_buffer_length_());
if (this->buffer_ == nullptr) { if (this->buffer_ == nullptr) {
this->mark_failed(); this->mark_failed();
} }

View File

@ -98,7 +98,8 @@ class ILI9XXXDisplay : public display::DisplayBuffer,
protected: protected:
inline bool check_buffer_() { inline bool check_buffer_() {
if (this->buffer_ == nullptr) { if (this->buffer_ == nullptr) {
this->alloc_buffer_(); if (!this->is_failed())
this->alloc_buffer_();
return !this->is_failed(); return !this->is_failed();
} }
return true; return true;

View File

@ -20,6 +20,7 @@ display:
it.rectangle(0, 0, it.get_width(), it.get_height()); it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: ili9xxx - platform: ili9xxx
invert_colors: false invert_colors: false
color_palette: 8bit
dimensions: dimensions:
width: 320 width: 320
height: 240 height: 240