Skip to content
Snippets Groups Projects
Commit b5c95bdb authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

[SPI] Avoid unnecessarily reconfiguring the bus

parent 018b78be
Branches
Tags gh-5186
No related merge requests found
...@@ -168,14 +168,19 @@ public: ...@@ -168,14 +168,19 @@ public:
private: private:
SPI spi; SPI spi;
SPIBusConfig config{}; SPIBusConfig config{};
bool firstConfigApplied = false;
}; };
inline SPIBus::SPIBus(SPIType* spi) : spi(spi) {} inline SPIBus::SPIBus(SPIType* spi) : spi(spi) {}
inline void SPIBus::configure(SPIBusConfig newConfig) inline void SPIBus::configure(SPIBusConfig newConfig)
{
// Do not reconfigure if already in the correct configuration.
if (!firstConfigApplied || newConfig != config)
{ {
// Save the new configuration // Save the new configuration
config = newConfig; config = newConfig;
firstConfigApplied = true;
// Wait until the peripheral is done before changing configuration // Wait until the peripheral is done before changing configuration
spi.waitPeripheral(); spi.waitPeripheral();
...@@ -200,6 +205,7 @@ inline void SPIBus::configure(SPIBusConfig newConfig) ...@@ -200,6 +205,7 @@ inline void SPIBus::configure(SPIBusConfig newConfig)
// Enable the peripheral // Enable the peripheral
spi.enable(); spi.enable();
} }
}
inline void SPIBus::select(GpioType& cs) inline void SPIBus::select(GpioType& cs)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment