8266 hardware spi enable with just 3 pins (#1617)

This commit is contained in:
SenexCrenshaw 2021-03-17 20:59:47 -04:00 committed by GitHub
parent a96b6e7002
commit b5b2036971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -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;

View File

@ -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);
}