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