SPI transfer fix. Use write when no miso pin is set (#1563)

This commit is contained in:
SenexCrenshaw 2021-03-17 20:54:58 -04:00 committed by GitHub
parent f34c9b33fc
commit a96b6e7002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -112,20 +112,34 @@ class SPIComponent : public Component {
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE>
uint8_t transfer_byte(uint8_t data) {
if (this->hw_spi_ != nullptr) {
return this->hw_spi_->transfer(data);
if (this->miso_ != nullptr) {
if (this->hw_spi_ != nullptr) {
return this->hw_spi_->transfer(data);
} else {
return this->transfer_<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, true, true>(data);
}
}
return this->transfer_<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE, true, true>(data);
this->write_byte<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data);
return 0;
}
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE>
void transfer_array(uint8_t *data, size_t length) {
if (this->hw_spi_ != nullptr) {
this->hw_spi_->transfer(data, length);
if (this->miso_ != nullptr) {
this->hw_spi_->transfer(data, length);
} else {
this->hw_spi_->writeBytes(data, length);
}
return;
}
for (size_t i = 0; i < length; i++) {
data[i] = this->transfer_byte<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data[i]);
if (this->miso_ != nullptr) {
for (size_t i = 0; i < length; i++) {
data[i] = this->transfer_byte<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data[i]);
}
} else {
this->write_array<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data, length);
}
}