[spi] Send ESP8266 writes through transferBytes instead of a heap copy (#19265)

This commit is contained in:
J. Nick Koston
2026-09-13 19:28:24 -05:00
committed by GitHub
parent f5afd141de
commit e431bfcb38
+2 -10
View File
@@ -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