mirror of
https://github.com/esphome/esphome.git
synced 2024-12-18 15:57:58 +01:00
SPI transfer fix. Use write when no miso pin is set (#1563)
This commit is contained in:
parent
f34c9b33fc
commit
a96b6e7002
@ -112,21 +112,35 @@ class SPIComponent : public Component {
|
|||||||
|
|
||||||
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE>
|
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE>
|
||||||
uint8_t transfer_byte(uint8_t data) {
|
uint8_t transfer_byte(uint8_t data) {
|
||||||
|
if (this->miso_ != nullptr) {
|
||||||
if (this->hw_spi_ != nullptr) {
|
if (this->hw_spi_ != nullptr) {
|
||||||
return this->hw_spi_->transfer(data);
|
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>
|
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE>
|
||||||
void transfer_array(uint8_t *data, size_t length) {
|
void transfer_array(uint8_t *data, size_t length) {
|
||||||
if (this->hw_spi_ != nullptr) {
|
if (this->hw_spi_ != nullptr) {
|
||||||
|
if (this->miso_ != nullptr) {
|
||||||
this->hw_spi_->transfer(data, length);
|
this->hw_spi_->transfer(data, length);
|
||||||
|
} else {
|
||||||
|
this->hw_spi_->writeBytes(data, length);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->miso_ != nullptr) {
|
||||||
for (size_t i = 0; i < length; i++) {
|
for (size_t i = 0; i < length; i++) {
|
||||||
data[i] = this->transfer_byte<BIT_ORDER, CLOCK_POLARITY, CLOCK_PHASE>(data[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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, uint32_t DATA_RATE>
|
template<SPIBitOrder BIT_ORDER, SPIClockPolarity CLOCK_POLARITY, SPIClockPhase CLOCK_PHASE, uint32_t DATA_RATE>
|
||||||
|
Loading…
Reference in New Issue
Block a user