[spi] Enable host-platform builds for unit testing (#15188)

This commit is contained in:
Javier Peletier
2026-04-05 12:11:49 +02:00
committed by GitHub
parent 9ea27e68ee
commit 2d7eb116f2
2 changed files with 11 additions and 3 deletions

View File

@@ -68,7 +68,7 @@ void SPIComponent::dump_config() {
LOG_PIN(" SDI Pin: ", this->sdi_pin_);
LOG_PIN(" SDO Pin: ", this->sdo_pin_);
for (size_t i = 0; i != this->data_pins_.size(); i++) {
ESP_LOGCONFIG(TAG, " Data pin %u: GPIO%d", i, this->data_pins_[i]);
ESP_LOGCONFIG(TAG, " Data pin %zu: GPIO%d", i, this->data_pins_[i]);
}
if (this->spi_bus_->is_hw()) {
ESP_LOGCONFIG(TAG, " Using HW SPI: %s", this->interface_name_);
@@ -118,4 +118,12 @@ uint16_t SPIDelegateBitBash::transfer_(uint16_t data, size_t num_bits) {
return out_data;
}
#if !defined(USE_ESP32) && !defined(USE_ARDUINO)
// Stub for unsupported platforms (host, Zephyr, etc.) - hardware SPI is unavailable
SPIBus *SPIComponent::get_bus(SPIInterface interface, GPIOPin *clk, GPIOPin *sdo, GPIOPin *sdi,
const std::vector<uint8_t> &data_pins) {
return nullptr;
}
#endif
} // namespace esphome::spi

View File

@@ -23,9 +23,9 @@ using SPIInterface = SPIClassRP2040 *;
using SPIInterface = SPIClass *;
#endif
#elif defined(CLANG_TIDY)
#elif defined(USE_HOST) || defined(CLANG_TIDY)
using SPIInterface = void *; // Stub for platforms without SPI (e.g., Zephyr)
using SPIInterface = void *; // Stub for platforms without SPI (e.g., host, Zephyr)
#endif // USE_ESP32 / USE_ARDUINO