diff --git a/pw_spi_linux/public/pw_spi_linux/spi.h b/pw_spi_linux/public/pw_spi_linux/spi.h index 1b15840f12..70edc44613 100644 --- a/pw_spi_linux/public/pw_spi_linux/spi.h +++ b/pw_spi_linux/public/pw_spi_linux/spi.h @@ -15,6 +15,7 @@ #pragma once #include +#include #include "pw_bytes/span.h" #include "pw_spi/chip_selector.h" @@ -39,6 +40,7 @@ class LinuxInitiator : public Initiator { private: uint32_t max_speed_hz_; int fd_; + std::optional current_config_; }; // Linux userspace implementation of SPI ChipSelector diff --git a/pw_spi_linux/spi.cc b/pw_spi_linux/spi.cc index fc482de350..92175f3536 100644 --- a/pw_spi_linux/spi.cc +++ b/pw_spi_linux/spi.cc @@ -34,6 +34,11 @@ LinuxInitiator::~LinuxInitiator() { } Status LinuxInitiator::Configure(const Config& config) { + if (current_config_ == config) { + // Don't waste time issuing ioctls if the config is not actually changing. + return OkStatus(); + } + // Map clock polarity/phase to Linux userspace equivalents uint32_t mode = 0; if (config.polarity == ClockPolarity::kActiveLow) { @@ -70,6 +75,7 @@ Status LinuxInitiator::Configure(const Config& config) { return Status::InvalidArgument(); } + current_config_ = config; return OkStatus(); }