mirror of
https://github.com/esphome/esphome.git
synced 2026-09-17 18:18:43 +00:00
[spi] Send ESP8266 writes through transferBytes instead of a heap copy (#19265)
This commit is contained in:
@@ -44,16 +44,8 @@ class SPIDelegateHw : public SPIDelegate {
|
||||
#ifdef USE_RP2
|
||||
this->channel_->transfer(ptr, nullptr, length);
|
||||
#elif defined(USE_ESP8266)
|
||||
// ESP8266 SPI library requires the pointer to be word aligned, but the data may not be
|
||||
// so we need to copy the data to a temporary buffer
|
||||
if (reinterpret_cast<uintptr_t>(ptr) & 0x3) {
|
||||
ESP_LOGVV(TAG, "SPI write buffer not word aligned, copying to temporary buffer");
|
||||
auto txbuf = std::vector<uint8_t>(length);
|
||||
memcpy(txbuf.data(), ptr, length);
|
||||
this->channel_->writeBytes(txbuf.data(), length);
|
||||
} else {
|
||||
this->channel_->writeBytes(ptr, length);
|
||||
}
|
||||
// writeBytes() needs a word aligned pointer; transferBytes() bounces unaligned chunks through a stack buffer
|
||||
this->channel_->transferBytes(ptr, nullptr, length);
|
||||
#else
|
||||
this->channel_->writeBytes(ptr, length);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user