diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-04-06 13:51:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-06 13:51:41 -0700 |
| commit | 2900d922357e6e239f48e585f09b5a3e4bc2d972 (patch) | |
| tree | c580e5ba374638c725842d112b310d693844c950 | |
| parent | e6f11947cb053fc4a9da844a3689c6af5881590d (diff) | |
| parent | 08f369ea9671e49196fc5ca9e699632798b47f84 (diff) | |
Merge pull request #2747 from arturo182/imx-spi-init-check
mimxrt1011: Only re-init SPI when it's actually needed
| -rw-r--r-- | ports/mimxrt10xx/common-hal/busio/SPI.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ports/mimxrt10xx/common-hal/busio/SPI.c b/ports/mimxrt10xx/common-hal/busio/SPI.c index b262d1a46..24a6dbff6 100644 --- a/ports/mimxrt10xx/common-hal/busio/SPI.c +++ b/ports/mimxrt10xx/common-hal/busio/SPI.c @@ -210,6 +210,18 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { bool common_hal_busio_spi_configure(busio_spi_obj_t *self, uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) { + + LPSPI_Enable(self->spi, false); + uint32_t tcrPrescaleValue; + self->baudrate = LPSPI_MasterSetBaudRate(self->spi, baudrate, LPSPI_MASTER_CLK_FREQ, &tcrPrescaleValue); + LPSPI_Enable(self->spi, true); + + if ((polarity == common_hal_busio_spi_get_polarity(self)) && + (phase == common_hal_busio_spi_get_phase(self)) && + (bits == ((self->spi->TCR & LPSPI_TCR_FRAMESZ_MASK) >> LPSPI_TCR_FRAMESZ_SHIFT)) + 1) { + return true; + } + lpspi_master_config_t config = { 0 }; LPSPI_MasterGetDefaultConfig(&config); @@ -221,11 +233,6 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self, LPSPI_Deinit(self->spi); LPSPI_MasterInit(self->spi, &config, LPSPI_MASTER_CLK_FREQ); - LPSPI_Enable(self->spi, false); - uint32_t tcrPrescaleValue; - self->baudrate = LPSPI_MasterSetBaudRate(self->spi, config.baudRate, LPSPI_MASTER_CLK_FREQ, &tcrPrescaleValue); - LPSPI_Enable(self->spi, true); - return true; } |
