Unverified Commit 02c272b0 authored by Nerradia's avatar Nerradia Committed by GitHub

Skip SPI re-init if clock frequency doesn't change (#1934)

parent 2a74250a
...@@ -184,15 +184,18 @@ void SPIClassRP2040::beginTransaction(SPISettings settings) { ...@@ -184,15 +184,18 @@ void SPIClassRP2040::beginTransaction(SPISettings settings) {
if (_initted && settings == _spis) { if (_initted && settings == _spis) {
DEBUGSPI("SPI: Reusing existing initted SPI\n"); DEBUGSPI("SPI: Reusing existing initted SPI\n");
} else { } else {
_spis = settings; /* Only de-init if the clock changes frequency */
if (_initted) { if (settings.getClockFreq() != _spis.getClockFreq()) {
DEBUGSPI("SPI: deinitting currently active SPI\n"); if (_initted) {
spi_deinit(_spi); DEBUGSPI("SPI: deinitting currently active SPI\n");
spi_deinit(_spi);
}
DEBUGSPI("SPI: initting SPI\n");
spi_init(_spi, settings.getClockFreq());
DEBUGSPI("SPI: actual baudrate=%u\n", spi_get_baudrate(_spi));
} }
DEBUGSPI("SPI: initting SPI\n"); _spis = settings;
spi_init(_spi, _spis.getClockFreq());
spi_set_format(_spi, 8, cpol(), cpha(), SPI_MSB_FIRST); spi_set_format(_spi, 8, cpol(), cpha(), SPI_MSB_FIRST);
DEBUGSPI("SPI: actual baudrate=%u\n", spi_get_baudrate(_spi));
_initted = true; _initted = true;
} }
// Disable any IRQs that are being used for SPI // Disable any IRQs that are being used for SPI
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment