mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
St7789v and SPI data rate (#5472)
This commit is contained in:
parent
4e8cba49f1
commit
b6d5cb4142
7 changed files with 34 additions and 14 deletions
|
@ -13,7 +13,6 @@ from esphome.const import (
|
|||
CONF_PAGES,
|
||||
CONF_RESET_PIN,
|
||||
CONF_DIMENSIONS,
|
||||
CONF_DATA_RATE,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["spi"]
|
||||
|
@ -100,11 +99,10 @@ CONFIG_SCHEMA = cv.All(
|
|||
cv.Optional(CONF_COLOR_PALETTE_IMAGES, default=[]): cv.ensure_list(
|
||||
cv.file_
|
||||
),
|
||||
cv.Optional(CONF_DATA_RATE, default="40MHz"): spi.SPI_DATA_RATE_SCHEMA,
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("1s"))
|
||||
.extend(spi.spi_device_schema(False)),
|
||||
.extend(spi.spi_device_schema(False, "40MHz")),
|
||||
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA),
|
||||
_validate,
|
||||
)
|
||||
|
@ -177,4 +175,3 @@ async def to_code(config):
|
|||
if rhs is not None:
|
||||
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
|
||||
cg.add(var.set_palette(prog_arr))
|
||||
cg.add(var.set_data_rate(config[CONF_DATA_RATE]))
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace max6675 {
|
|||
class MAX6675Sensor : public sensor::Sensor,
|
||||
public PollingComponent,
|
||||
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING,
|
||||
spi::DATA_RATE_1KHZ> {
|
||||
spi::DATA_RATE_1MHZ> {
|
||||
public:
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
|
|
@ -25,6 +25,7 @@ from esphome.const import (
|
|||
KEY_CORE,
|
||||
KEY_TARGET_PLATFORM,
|
||||
KEY_VARIANT,
|
||||
CONF_DATA_RATE,
|
||||
)
|
||||
from esphome.core import coroutine_with_priority, CORE
|
||||
|
||||
|
@ -33,6 +34,7 @@ spi_ns = cg.esphome_ns.namespace("spi")
|
|||
SPIComponent = spi_ns.class_("SPIComponent", cg.Component)
|
||||
SPIDevice = spi_ns.class_("SPIDevice")
|
||||
SPIDataRate = spi_ns.enum("SPIDataRate")
|
||||
SPIMode = spi_ns.enum("SPIMode")
|
||||
|
||||
SPI_DATA_RATE_OPTIONS = {
|
||||
80e6: SPIDataRate.DATA_RATE_80MHZ,
|
||||
|
@ -50,6 +52,18 @@ SPI_DATA_RATE_OPTIONS = {
|
|||
}
|
||||
SPI_DATA_RATE_SCHEMA = cv.All(cv.frequency, cv.enum(SPI_DATA_RATE_OPTIONS))
|
||||
|
||||
SPI_MODE_OPTIONS = {
|
||||
"MODE0": SPIMode.MODE0,
|
||||
"MODE1": SPIMode.MODE1,
|
||||
"MODE2": SPIMode.MODE2,
|
||||
"MODE3": SPIMode.MODE3,
|
||||
0: SPIMode.MODE0,
|
||||
1: SPIMode.MODE1,
|
||||
2: SPIMode.MODE2,
|
||||
3: SPIMode.MODE3,
|
||||
}
|
||||
|
||||
CONF_SPI_MODE = "spi_mode"
|
||||
CONF_FORCE_SW = "force_sw"
|
||||
CONF_INTERFACE = "interface"
|
||||
CONF_INTERFACE_INDEX = "interface_index"
|
||||
|
@ -286,13 +300,20 @@ async def to_code(configs):
|
|||
cg.add_library("SPI", None)
|
||||
|
||||
|
||||
def spi_device_schema(cs_pin_required=True):
|
||||
def spi_device_schema(
|
||||
cs_pin_required=True, default_data_rate=cv.UNDEFINED, default_mode=cv.UNDEFINED
|
||||
):
|
||||
"""Create a schema for an SPI device.
|
||||
:param cs_pin_required: If true, make the CS_PIN required in the config.
|
||||
:param default_data_rate: Optional data_rate to use as default
|
||||
:return: The SPI device schema, `extend` this in your config schema.
|
||||
"""
|
||||
schema = {
|
||||
cv.GenerateID(CONF_SPI_ID): cv.use_id(SPIComponent),
|
||||
cv.Optional(CONF_DATA_RATE, default=default_data_rate): SPI_DATA_RATE_SCHEMA,
|
||||
cv.Optional(CONF_SPI_MODE, default=default_mode): cv.enum(
|
||||
SPI_MODE_OPTIONS, upper=True
|
||||
),
|
||||
}
|
||||
if cs_pin_required:
|
||||
schema[cv.Required(CONF_CS_PIN)] = pins.gpio_output_pin_schema
|
||||
|
@ -307,6 +328,10 @@ async def register_spi_device(var, config):
|
|||
if CONF_CS_PIN in config:
|
||||
pin = await cg.gpio_pin_expression(config[CONF_CS_PIN])
|
||||
cg.add(var.set_cs_pin(pin))
|
||||
if CONF_DATA_RATE in config:
|
||||
cg.add(var.set_data_rate(config[CONF_DATA_RATE]))
|
||||
if CONF_SPI_MODE in config:
|
||||
cg.add(var.set_mode(config[CONF_SPI_MODE]))
|
||||
|
||||
|
||||
def final_validate_device_schema(name: str, *, require_mosi: bool, require_miso: bool):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import spi
|
||||
from esphome.const import CONF_ID, CONF_DATA_RATE, CONF_MODE
|
||||
from esphome.const import CONF_ID, CONF_MODE
|
||||
|
||||
DEPENDENCIES = ["spi"]
|
||||
CODEOWNERS = ["@clydebarrow"]
|
||||
|
@ -33,17 +33,15 @@ CONF_BIT_ORDER = "bit_order"
|
|||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(spi_device),
|
||||
cv.Optional(CONF_DATA_RATE, default="1MHz"): spi.SPI_DATA_RATE_SCHEMA,
|
||||
cv.Optional(CONF_BIT_ORDER, default="msb_first"): cv.enum(ORDERS, lower=True),
|
||||
cv.Optional(CONF_MODE, default="0"): cv.enum(MODES, upper=True),
|
||||
}
|
||||
).extend(spi.spi_device_schema(False))
|
||||
).extend(spi.spi_device_schema(False, "1MHz"))
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
cg.add(var.set_data_rate(config[CONF_DATA_RATE]))
|
||||
cg.add(var.set_mode(config[CONF_MODE]))
|
||||
cg.add(var.set_bit_order(config[CONF_BIT_ORDER]))
|
||||
await spi.register_spi_device(var, config)
|
||||
|
|
|
@ -2,7 +2,7 @@ import esphome.codegen as cg
|
|||
import esphome.config_validation as cv
|
||||
from esphome.components import light
|
||||
from esphome.components import spi
|
||||
from esphome.const import CONF_OUTPUT_ID, CONF_NUM_LEDS, CONF_DATA_RATE
|
||||
from esphome.const import CONF_OUTPUT_ID, CONF_NUM_LEDS
|
||||
|
||||
spi_led_strip_ns = cg.esphome_ns.namespace("spi_led_strip")
|
||||
SpiLedStrip = spi_led_strip_ns.class_(
|
||||
|
@ -13,14 +13,12 @@ CONFIG_SCHEMA = light.ADDRESSABLE_LIGHT_SCHEMA.extend(
|
|||
{
|
||||
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(SpiLedStrip),
|
||||
cv.Optional(CONF_NUM_LEDS, default=1): cv.positive_not_null_int,
|
||||
cv.Optional(CONF_DATA_RATE, default="1MHz"): spi.SPI_DATA_RATE_SCHEMA,
|
||||
}
|
||||
).extend(spi.spi_device_schema(False))
|
||||
).extend(spi.spi_device_schema(False, "1MHz"))
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
|
||||
cg.add(var.set_data_rate(spi.SPI_DATA_RATE_OPTIONS[config[CONF_DATA_RATE]]))
|
||||
cg.add(var.set_num_leds(config[CONF_NUM_LEDS]))
|
||||
await light.register_light(var, config)
|
||||
await spi.register_spi_device(var, config)
|
||||
|
|
|
@ -133,6 +133,7 @@ void ST7789V::dump_config() {
|
|||
LOG_PIN(" Reset Pin: ", this->reset_pin_);
|
||||
LOG_PIN(" B/L Pin: ", this->backlight_pin_);
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
ESP_LOGCONFIG(TAG, " Data rate: %dMHz", (unsigned) (this->data_rate_ / 1000000));
|
||||
#ifdef USE_POWER_SUPPLY
|
||||
ESP_LOGCONFIG(TAG, " Power Supply Configured: yes");
|
||||
#endif
|
||||
|
|
|
@ -724,6 +724,7 @@ interval:
|
|||
display:
|
||||
- platform: st7789v
|
||||
model: LILYGO_T-EMBED_170X320
|
||||
spi_mode: mode0
|
||||
height: 320
|
||||
width: 170
|
||||
offset_height: 35
|
||||
|
|
Loading…
Reference in a new issue