mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-05 12:30:28 +02:00
8266 hardware spi enable with just 3 pins (#1617)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user