mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +01:00
8266 hardware spi enable with just 3 pins (#1617)
This commit is contained in:
parent
a96b6e7002
commit
b5b2036971
2 changed files with 33 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -98,6 +98,30 @@ class SPIComponent : public Component {
|
|||
this->transfer_<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, false, true>(data);
|
||||
}
|
||||
|
||||
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE>
|
||||
void write_byte16(const uint16_t data) {
|
||||
if (this->hw_spi_ != nullptr) {
|
||||
this->hw_spi_->write16(data);
|
||||
return;
|
||||
}
|
||||
|
||||
this->write_byte<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data >> 8);
|
||||
this->write_byte<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data);
|
||||
}
|
||||
|
||||
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE>
|
||||
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<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE>
|
||||
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<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data);
|
||||
}
|
||||
|
||||
void write_byte16(uint8_t data) {
|
||||
return this->parent_->template write_byte16<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data);
|
||||
}
|
||||
|
||||
void write_array16(const uint16_t *data, size_t length) {
|
||||
this->parent_->template write_array16<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data, length);
|
||||
}
|
||||
|
||||
void write_array(const uint8_t *data, size_t length) {
|
||||
this->parent_->template write_array<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data, length);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue