| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #pragma once
- // Minimal SPIClass/SPISettings substitute so GxEPD2 compiles under ESP-IDF,
- // backed by esphome::spi::SPIDevice underneath. GxEPD2 always drives
- // chip-select itself around each transfer, so this only needs to own the
- // clock/data lines - which is what lets a gxepd2 instance share one spi:
- // bus with other devices, each with its own SPIDevice registration.
- #include <cstdint>
- #include "esphome/components/spi/spi.h"
- class SPISettings {
- public:
- SPISettings() = default;
- SPISettings(uint32_t clock, uint8_t bit_order, uint8_t data_mode) {}
- };
- #define MSBFIRST 0
- #define SPI_MODE0 0
- class SPIClass : public esphome::spi::SPIDevice<esphome::spi::BIT_ORDER_MSB_FIRST, esphome::spi::CLOCK_POLARITY_LOW,
- esphome::spi::CLOCK_PHASE_LEADING, esphome::spi::DATA_RATE_4MHZ> {
- public:
- void begin() {}
- void end() {}
- void beginTransaction(SPISettings settings) { this->enable(); }
- void endTransaction() { this->disable(); }
- // GxEPD2 panels (all but the IT8951-based ones, which aren't supported -
- // see display.py) never read anything back over MISO; e-paper wiring
- // normally leaves it unconnected, and esphome's spi: bus then registers
- // this device as write-only. transfer_byte()/delegate transfer() ask for
- // a real bidirectional exchange regardless, which a write-only device
- // refuses outright - it doesn't just skip the read, it drops the write
- // too (see SPIDelegateHw::transfer in spi_esp_idf.cpp), silently bricking
- // every panel command. write_byte() only ever asks to write, so it works
- // whether or not MISO is wired.
- uint8_t transfer(uint8_t data) {
- this->write_byte(data);
- return 0;
- }
- };
- // Unused: every gxepd2 instance overrides this via selectSPI() with its own
- // SPIClass member - see gxepd2_display.h.
- inline SPIClass SPI; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|