Compare commits

...
22 changed files with 66 additions and 55 deletions

No files matched your search

@@ -2,11 +2,16 @@ from collections.abc import Iterable
from dataclasses import dataclass, field
from pathlib import Path
import esphome.codegen as cg
from esphome.core import CORE
CODEOWNERS = ["@esphome/core"]
DOMAIN = "epaper_spi"
register_enable_pin = cg.slot_list(
"EPAPER_SPI_ENABLE_PIN_COUNT", "register_enable_pin", DOMAIN
)
# The source file that every model needs.
BASE_SOURCE_FILE = "epaper_spi.cpp"
+3 -4
View File
@@ -42,7 +42,7 @@ from esphome.const import (
)
from esphome.cpp_generator import RawExpression
from . import models, register_sources
from . import models, register_enable_pin, register_sources
AUTO_LOAD = ["split_buffer"]
DEPENDENCIES = ["spi"]
@@ -249,9 +249,8 @@ async def to_code(config):
await display.add_writer(var, config)
await cg.add_pin(var.set_reset_pin, config.get(CONF_RESET_PIN))
await cg.add_pin(var.set_busy_pin, config.get(CONF_BUSY_PIN))
if enable_pin := config.get(CONF_ENABLE_PIN):
enable = [await cg.gpio_pin_expression(pin) for pin in enable_pin]
cg.add(var.set_enable_pins(enable))
for pin in config.get(CONF_ENABLE_PIN, ()):
cg.add(register_enable_pin(var, await cg.gpio_pin_expression(pin)))
cg.add(var.set_full_update_every(config[CONF_FULL_UPDATE_EVERY]))
cg.add_optional(var.set_reset_duration, config.get(CONF_RESET_DURATION))
if transform := config.get(CONF_TRANSFORM):
+1 -2
View File
@@ -57,7 +57,7 @@ class EPaperBase : public Display,
float get_setup_priority() const override;
void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; }
void set_busy_pin(GPIOPin *busy) { this->busy_pin_ = busy; }
void set_enable_pins(std::vector<GPIOPin *> enable_pins) { this->enable_pins_ = std::move(enable_pins); }
SLOT_LIST(GPIOPin, enable_pins_, register_enable_pin, EPAPER_SPI_ENABLE_PIN_COUNT)
void set_reset_duration(uint32_t reset_duration) { this->reset_duration_ = reset_duration; }
void set_transform(uint8_t transform) {
this->transform_ = transform;
@@ -227,7 +227,6 @@ class EPaperBase : public Display,
GPIOPin *dc_pin_{};
GPIOPin *busy_pin_{};
GPIOPin *reset_pin_{};
std::vector<GPIOPin *> enable_pins_{};
bool waiting_for_idle_{};
HighFrequencyLoopRequester high_frequency_loop_;
uint32_t delay_until_{}; // timestamp until which to delay processing
+6
View File
@@ -1,2 +1,8 @@
import esphome.codegen as cg
CODEOWNERS = ["@Passific", "@koosoli", "@limengdu"]
DOMAIN = "it8951"
register_enable_pin = cg.slot_list(
"IT8951_ENABLE_PIN_COUNT", "register_enable_pin", DOMAIN
)
+4 -6
View File
@@ -39,6 +39,8 @@ from esphome.const import (
from esphome.cpp_generator import RawExpression
from esphome.types import ConfigType
from . import register_enable_pin
AUTO_LOAD = ["split_buffer"]
DEPENDENCIES = ["spi"]
@@ -367,12 +369,8 @@ async def to_code(config: ConfigType) -> None:
await display.add_writer(var, config)
await cg.add_pin(var.set_reset_pin, config.get(CONF_RESET_PIN))
await cg.add_pin(var.set_busy_pin, config.get(CONF_BUSY_PIN))
if enable_pins := config.get(CONF_ENABLE_PIN):
cg.add(
var.set_enable_pins(
[await cg.gpio_pin_expression(pin) for pin in enable_pins]
)
)
for pin in config.get(CONF_ENABLE_PIN, ()):
cg.add(register_enable_pin(var, await cg.gpio_pin_expression(pin)))
cg.add(var.set_full_update_every(config[CONF_FULL_UPDATE_EVERY]))
cg.add_optional(var.set_reset_duration, config.get(CONF_RESET_DURATION))
if config.get(CONF_INVERT_COLORS):
+1
View File
@@ -2,6 +2,7 @@
#include <algorithm>
#include <cstring>
#include <utility>
#include "esphome/core/application.h"
#include "esphome/core/hal.h"
+2 -5
View File
@@ -1,8 +1,6 @@
#pragma once
#include <cstddef>
#include <utility>
#include <vector>
#include "esphome/components/display/display.h"
#include "esphome/components/spi/spi.h"
@@ -104,7 +102,8 @@ class IT8951Display : public Display,
// --- Config setters (called from generated code) ---
void set_reset_pin(GPIOPin *pin) { this->reset_pin_ = pin; }
void set_busy_pin(GPIOPin *pin) { this->busy_pin_ = pin; }
void set_enable_pins(std::vector<GPIOPin *> pins) { this->enable_pins_ = std::move(pins); }
// GPIOs driven high during setup to power on the panel.
SLOT_LIST(GPIOPin, enable_pins_, register_enable_pin, IT8951_ENABLE_PIN_COUNT)
void set_reset_duration(uint32_t ms) { this->reset_duration_ = ms; }
void set_full_update_every(uint8_t n) {
this->full_update_every_ = n;
@@ -281,8 +280,6 @@ class IT8951Display : public Display,
UpdateMode default_update_mode_{UPDATE_MODE_NONE};
GPIOPin *reset_pin_{nullptr};
GPIOPin *busy_pin_{nullptr};
// GPIOs driven high during setup to power on the panel (empty if unused).
std::vector<GPIOPin *> enable_pins_;
// Dirty region (pixel coordinates of bounding box of changes since last update)
uint16_t x_low_{0}, y_low_{0}, x_high_{0}, y_high_{0};
+4
View File
@@ -3,4 +3,8 @@ import esphome.codegen as cg
CODEOWNERS = ["@clydebarrow"]
DOMAIN = "mipi_dsi"
register_enable_pin = cg.slot_list(
"MIPI_DSI_ENABLE_PIN_COUNT", "register_enable_pin", DOMAIN
)
mipi_dsi_ns = cg.esphome_ns.namespace("mipi_dsi")
+3 -4
View File
@@ -63,7 +63,7 @@ from esphome.core import CORE
from esphome.final_validate import full_config
from esphome.types import ConfigType
from . import mipi_dsi_ns, models
from . import mipi_dsi_ns, models, register_enable_pin
from .models import DsiDriverChip
# Currently only ESP32-P4 is supported, so esp_ldo and psram are required
@@ -227,9 +227,8 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_lanes(int(config[CONF_LANES])))
cg.add(var.set_lane_bit_rate(config[CONF_LANE_BIT_RATE] / 1.0e6))
await cg.add_pin(var.set_reset_pin, config.get(CONF_RESET_PIN))
if enable_pin := config.get(CONF_ENABLE_PIN):
enable = [await cg.gpio_pin_expression(pin) for pin in enable_pin]
cg.add(var.set_enable_pins(enable))
for pin in config.get(CONF_ENABLE_PIN, ()):
cg.add(register_enable_pin(var, await cg.gpio_pin_expression(pin)))
if model.rotation_as_transform(config):
config[CONF_ROTATION] = 0
+1 -2
View File
@@ -48,7 +48,7 @@ class MipiDsi final : public display::Display {
display::DisplayType get_display_type() override { return display::DisplayType::DISPLAY_TYPE_COLOR; }
void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
void set_enable_pins(std::vector<GPIOPin *> enable_pins) { this->enable_pins_ = std::move(enable_pins); }
SLOT_LIST(GPIOPin, enable_pins_, register_enable_pin, MIPI_DSI_ENABLE_PIN_COUNT)
void set_pclk_frequency(float pclk_frequency) { this->pclk_frequency_ = pclk_frequency; }
int get_width_internal() override { return this->width_; }
int get_height_internal() override { return this->height_; }
@@ -114,7 +114,6 @@ class MipiDsi final : public display::Display {
return this->big_endian_ ? convert_big_endian(rgb565) : rgb565;
}
GPIOPin *reset_pin_{nullptr};
std::vector<GPIOPin *> enable_pins_{};
size_t width_{};
size_t height_{};
uint16_t hsync_pulse_width_ = 10;
+6
View File
@@ -1,2 +1,8 @@
import esphome.codegen as cg
CODEOWNERS = ["@clydebarrow"]
DOMAIN = "mipi_rgb"
register_enable_pin = cg.slot_list(
"MIPI_RGB_ENABLE_PIN_COUNT", "register_enable_pin", DOMAIN
)
+3 -4
View File
@@ -79,7 +79,7 @@ from esphome.const import (
from esphome.final_validate import full_config
from esphome.types import ConfigType
from . import models
from . import models, register_enable_pin
from .models import RgbDriverChip
DEPENDENCIES = ["esp32"]
@@ -276,9 +276,8 @@ async def to_code(config: ConfigType) -> None:
)
var = cg.new_Pvariable(config[CONF_ID], width, height)
cg.add(var.set_model(model.name))
if enable_pin := config.get(CONF_ENABLE_PIN):
enable = [await cg.gpio_pin_expression(pin) for pin in enable_pin]
cg.add(var.set_enable_pins(enable))
for pin in config.get(CONF_ENABLE_PIN, ()):
cg.add(register_enable_pin(var, await cg.gpio_pin_expression(pin)))
if CONF_SPI_ID in config:
await spi.register_spi_device(var, config, write_only=True)
+2 -3
View File
@@ -2,12 +2,12 @@
#if defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32P4) || defined(USE_ESP32_VARIANT_ESP32S31)
#include "esphome/core/gpio.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#include "esphome/components/display/display.h"
#include "esphome/components/display/display_color_utils.h"
#include "mipi_rgb_blitter.h"
#include <esp_lcd_panel_rgb.h>
#include <utility>
#ifdef USE_SPI
#include "esphome/components/spi/spi.h"
#endif
@@ -61,7 +61,7 @@ class MipiRgb : public display::Display {
void set_vsync_pulse_width(uint16_t vsync_pulse_width) { this->vsync_pulse_width_ = vsync_pulse_width; }
void set_vsync_back_porch(uint16_t vsync_back_porch) { this->vsync_back_porch_ = vsync_back_porch; }
void set_vsync_front_porch(uint16_t vsync_front_porch) { this->vsync_front_porch_ = vsync_front_porch; }
void set_enable_pins(std::vector<GPIOPin *> enable_pins) { this->enable_pins_ = std::move(enable_pins); }
SLOT_LIST(GPIOPin, enable_pins_, register_enable_pin, MIPI_RGB_ENABLE_PIN_COUNT)
display::DisplayType get_display_type() override { return display::DisplayType::DISPLAY_TYPE_COLOR; }
int get_width_internal() override { return this->width_; }
int get_height_internal() override { return this->height_; }
@@ -111,7 +111,6 @@ class MipiRgb : public display::Display {
size_t width_;
size_t height_;
uint16_t *buffer_{nullptr};
std::vector<GPIOPin *> enable_pins_{};
uint16_t x_low_{1};
uint16_t y_low_{1};
uint16_t x_high_{0};
+6
View File
@@ -1,6 +1,12 @@
import esphome.codegen as cg
CODEOWNERS = ["@clydebarrow"]
DOMAIN = "mipi_spi"
register_enable_pin = cg.slot_list(
"MIPI_SPI_ENABLE_PIN_COUNT", "register_enable_pin", DOMAIN
)
CONF_SPI_16 = "spi_16"
CONF_BUS_MODE = "bus_mode"
+3 -4
View File
@@ -56,7 +56,7 @@ from esphome.cpp_generator import MockObjClass, TemplateArguments
from esphome.final_validate import full_config
from esphome.types import ConfigType
from . import CONF_BUS_MODE, CONF_SPI_16, DOMAIN, models
from . import CONF_BUS_MODE, CONF_SPI_16, DOMAIN, models, register_enable_pin
DEPENDENCIES = ["spi"]
@@ -397,9 +397,8 @@ async def to_code(config: ConfigType) -> None:
table = cg.shared_progmem_array("mipi_spi_init_sequence", cg.uint8, init_sequence)
cg.add(var.set_init_sequence(table, len(init_sequence)))
cg.add(var.set_model(config[CONF_MODEL]))
if enable_pin := config.get(CONF_ENABLE_PIN):
enable = [await cg.gpio_pin_expression(pin) for pin in enable_pin]
cg.add(var.set_enable_pins(enable))
for pin in config.get(CONF_ENABLE_PIN, ()):
cg.add(register_enable_pin(var, await cg.gpio_pin_expression(pin)))
await cg.add_pin(var.set_reset_pin, config.get(CONF_RESET_PIN))
await cg.add_pin(var.set_dc_pin, config.get(CONF_DC_PIN))
+1 -3
View File
@@ -2,7 +2,6 @@
#include <algorithm>
#include <cstring>
#include <utility>
#include "esphome/components/spi/spi.h"
#include "esphome/components/display/display.h"
@@ -107,7 +106,7 @@ class MipiSpi : public display::Display,
void draw_pixel_at(int x, int y, Color color) override {}
void set_model(const char *model) { this->model_ = model; }
void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
void set_enable_pins(std::vector<GPIOPin *> enable_pins) { this->enable_pins_ = std::move(enable_pins); }
SLOT_LIST(GPIOPin, enable_pins_, register_enable_pin, MIPI_SPI_ENABLE_PIN_COUNT)
void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; }
void set_invert_colors(bool invert_colors) {
this->invert_colors_ = invert_colors;
@@ -486,7 +485,6 @@ class MipiSpi : public display::Display,
// GPIO pins
GPIOPin *reset_pin_{nullptr};
std::vector<GPIOPin *> enable_pins_{};
GPIOPin *dc_pin_{nullptr};
// other properties set by configuration
+5
View File
@@ -198,12 +198,17 @@
#define USE_MDNS_STORE_SERVICES
#define USE_MOTION_TAP
#define ETHERNET_INFO_IP_SENSOR_COUNT 5
#define EPAPER_SPI_ENABLE_PIN_COUNT 2
#define GPS_LISTENER_COUNT 1
#define IT8951_ENABLE_PIN_COUNT 2
#define HDMI_CEC_MESSAGE_CALLBACK_COUNT 2
#define I2C_PORT_FREQUENCY_COUNT 1
#define LD600X_AREA_KINDS 3
#define LD600X_MAX_TARGETS 3
#define MDNS_SERVICE_COUNT 3
#define MIPI_DSI_ENABLE_PIN_COUNT 2
#define MIPI_RGB_ENABLE_PIN_COUNT 2
#define MIPI_SPI_ENABLE_PIN_COUNT 2
#define USE_MDNS_DYNAMIC_TXT
#define USE_MDNS_EXTRA_SERVICES
#define MDNS_DYNAMIC_TXT_COUNT 2
@@ -6,12 +6,11 @@ import re
def _enable_pin_numbers(main_cpp: str) -> list[int]:
"""Get the GPIO numbers passed to set_enable_pins() in the generated code."""
match = re.search(r"epaper_display->set_enable_pins\(\{(.*)\}\);", main_cpp)
if match is None:
return []
"""Get the GPIO numbers passed to register_enable_pin() in the generated code."""
numbers = []
for pin_id in match.group(1).split(", "):
for pin_id in re.findall(
r"epaper_display->register_enable_pin\((\w+)\);", main_cpp
):
pin = re.search(rf"{pin_id}->set_pin\(::GPIO_NUM_(\d+)\);", main_cpp)
assert pin is not None
numbers.append(int(pin.group(1)))
@@ -986,9 +986,8 @@ def test_enable_pin_code_generation(
pin_25 = pin_var_for(25)
pin_26 = pin_var_for(26)
# Both pin objects must be passed to the display via set_enable_pins() as a
# std::vector initializer list, in the configured order.
assert f"set_enable_pins({{{pin_25}, {pin_26}}});" in main_cpp
# Both pin objects must be registered with the display, in the configured order.
assert re.findall(r"->register_enable_pin\((\w+)\);", main_cpp) == [pin_25, pin_26]
def test_full_update_next_action_code_generation(
+1 -3
View File
@@ -37,9 +37,7 @@ def test_reterminal_e1003_enable_pin_used_elsewhere(
"""A default enable pin used by a switch is left out, and the other is still applied."""
main_cpp = generate_main(component_fixture_path("enable_pins.yaml"))
match = re.search(r"epaper_display->set_enable_pins\(\{(.*)\}\);", main_cpp)
assert match is not None
pin_ids = match.group(1).split(", ")
pin_ids = re.findall(r"epaper_display->register_enable_pin\((\w+)\);", main_cpp)
assert len(pin_ids) == 1
assert f"{pin_ids[0]}->set_pin(::GPIO_NUM_11);" in main_cpp
assert "logic_supply->set_pin(" in main_cpp
@@ -32,9 +32,7 @@ def test_default_enable_pins_by_address(
main_cpp = generate_main(component_fixture_path("enable_pins_address.yaml"))
match = re.search(r"default_pins->set_enable_pins\(\{(.*)\}\);", main_cpp)
assert match is not None
pin_ids = match.group(1).split(", ")
pin_ids = re.findall(r"default_pins->register_enable_pin\((\w+)\);", main_cpp)
assert len(pin_ids) == 1
assert f"{pin_ids[0]}->set_parent(pi4ioe1);" in main_cpp
assert f"{pin_ids[0]}->set_pin(1);" in main_cpp
@@ -6,11 +6,9 @@ import re
def _enable_pin_numbers(main_cpp: str) -> list[int]:
"""Get the expander pin numbers passed to set_enable_pins() in the generated code."""
match = re.search(r"default_pins->set_enable_pins\(\{(.*)\}\);", main_cpp)
assert match is not None
"""Get the expander pin numbers passed to register_enable_pin() in the generated code."""
numbers = []
for pin_id in match.group(1).split(", "):
for pin_id in re.findall(r"default_pins->register_enable_pin\((\w+)\);", main_cpp):
pin = re.search(rf"{pin_id}->set_pin\((\d+)\);", main_cpp)
assert pin is not None
numbers.append(int(pin.group(1)))