diff --git a/esphome/components/spi/spi.cpp b/esphome/components/spi/spi.cpp index ea6f8d68f6..d2850b8e7d 100644 --- a/esphome/components/spi/spi.cpp +++ b/esphome/components/spi/spi.cpp @@ -38,7 +38,7 @@ void SPIComponent::setup() { #ifdef ARDUINO_ARCH_ESP8266 if (clk_pin == 6 && miso_pin == 7 && mosi_pin == 8) { // pass - } else if (clk_pin == 14 && miso_pin == 12 && mosi_pin == 13) { + } else if (clk_pin == 14 && (!has_miso || miso_pin == 12) && (!has_mosi || mosi_pin == 13)) { // pass } else { use_hw_spi = false; diff --git a/esphome/components/spi/spi.h b/esphome/components/spi/spi.h index 05c64150cc..a4a2e11def 100644 --- a/esphome/components/spi/spi.h +++ b/esphome/components/spi/spi.h @@ -98,6 +98,30 @@ class SPIComponent : public Component { this->transfer_(data); } + template + void write_byte16(const uint16_t data) { + if (this->hw_spi_ != nullptr) { + this->hw_spi_->write16(data); + return; + } + + this->write_byte(data >> 8); + this->write_byte(data); + } + + template + void write_array16(const uint16_t *data, size_t length) { + if (this->hw_spi_ != nullptr) { + for (size_t i = 0; i < length; i++) { + this->hw_spi_->write16(data[i]); + } + return; + } + for (size_t i = 0; i < length; i++) { + this->write_byte16(data[i]); + } + } + template void write_array(const uint8_t *data, size_t length) { if (this->hw_spi_ != nullptr) { @@ -222,6 +246,14 @@ class SPIDevice { return this->parent_->template write_byte(data); } + void write_byte16(uint8_t data) { + return this->parent_->template write_byte16(data); + } + + void write_array16(const uint16_t *data, size_t length) { + this->parent_->template write_array16(data, length); + } + void write_array(const uint8_t *data, size_t length) { this->parent_->template write_array(data, length); }