[ili9xxx] Allow config of spi data rate. (#4701)

* Allow 80MHz ili9xxx display.

* python foo.

* update based on feedback.

* Change python

---------

Co-authored-by: Your Name <you@example.com>
This commit is contained in:
Fabian 2023-07-05 09:53:14 +02:00 committed by GitHub
parent 5bf2fa5c56
commit a326dcaf0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 1 deletions

View File

@ -13,6 +13,7 @@ from esphome.const import (
CONF_PAGES,
CONF_RESET_PIN,
CONF_DIMENSIONS,
CONF_DATA_RATE,
)
DEPENDENCIES = ["spi"]
@ -98,6 +99,7 @@ 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"))
@ -176,3 +178,6 @@ 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))
spi_data_rate = str(spi.SPI_DATA_RATE_OPTIONS[config[CONF_DATA_RATE]])
cg.add_define("ILI9XXXDisplay_DATA_RATE", cg.RawExpression(spi_data_rate))

View File

@ -15,10 +15,14 @@ enum ILI9XXXColorMode {
BITS_16 = 0x10,
};
#ifndef ILI9XXXDisplay_DATA_RATE
#define ILI9XXXDisplay_DATA_RATE spi::DATA_RATE_40MHZ
#endif // ILI9XXXDisplay_DATA_RATE
class ILI9XXXDisplay : public PollingComponent,
public display::DisplayBuffer,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_40MHZ> {
spi::CLOCK_PHASE_LEADING, ILI9XXXDisplay_DATA_RATE> {
public:
void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
float get_setup_priority() const override;

View File

@ -16,6 +16,22 @@ CODEOWNERS = ["@esphome/core"]
spi_ns = cg.esphome_ns.namespace("spi")
SPIComponent = spi_ns.class_("SPIComponent", cg.Component)
SPIDevice = spi_ns.class_("SPIDevice")
SPIDataRate = spi_ns.enum("SPIDataRate")
SPI_DATA_RATE_OPTIONS = {
80e6: SPIDataRate.DATA_RATE_80MHZ,
40e6: SPIDataRate.DATA_RATE_40MHZ,
20e6: SPIDataRate.DATA_RATE_20MHZ,
10e6: SPIDataRate.DATA_RATE_10MHZ,
5e6: SPIDataRate.DATA_RATE_5MHZ,
2e6: SPIDataRate.DATA_RATE_2MHZ,
1e6: SPIDataRate.DATA_RATE_1MHZ,
2e5: SPIDataRate.DATA_RATE_200KHZ,
75e3: SPIDataRate.DATA_RATE_75KHZ,
1e3: SPIDataRate.DATA_RATE_1KHZ,
}
SPI_DATA_RATE_SCHEMA = cv.All(cv.frequency, cv.enum(SPI_DATA_RATE_OPTIONS))
MULTI_CONF = True
CONF_FORCE_SW = "force_sw"

View File

@ -67,6 +67,7 @@ enum SPIDataRate : uint32_t {
DATA_RATE_10MHZ = 10000000,
DATA_RATE_20MHZ = 20000000,
DATA_RATE_40MHZ = 40000000,
DATA_RATE_80MHZ = 80000000,
};
class SPIComponent : public Component {