@@ -210,6 +210,18 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
210210
211211bool common_hal_busio_spi_configure (busio_spi_obj_t * self ,
212212 uint32_t baudrate , uint8_t polarity , uint8_t phase , uint8_t bits ) {
213+
214+ LPSPI_Enable (self -> spi , false);
215+ uint32_t tcrPrescaleValue ;
216+ self -> baudrate = LPSPI_MasterSetBaudRate (self -> spi , baudrate , LPSPI_MASTER_CLK_FREQ , & tcrPrescaleValue );
217+ LPSPI_Enable (self -> spi , true);
218+
219+ if ((polarity == common_hal_busio_spi_get_polarity (self )) &&
220+ (phase == common_hal_busio_spi_get_phase (self )) &&
221+ (bits == ((self -> spi -> TCR & LPSPI_TCR_FRAMESZ_MASK ) >> LPSPI_TCR_FRAMESZ_SHIFT )) + 1 ) {
222+ return true;
223+ }
224+
213225 lpspi_master_config_t config = { 0 };
214226 LPSPI_MasterGetDefaultConfig (& config );
215227
@@ -221,11 +233,6 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
221233 LPSPI_Deinit (self -> spi );
222234 LPSPI_MasterInit (self -> spi , & config , LPSPI_MASTER_CLK_FREQ );
223235
224- LPSPI_Enable (self -> spi , false);
225- uint32_t tcrPrescaleValue ;
226- self -> baudrate = LPSPI_MasterSetBaudRate (self -> spi , config .baudRate , LPSPI_MASTER_CLK_FREQ , & tcrPrescaleValue );
227- LPSPI_Enable (self -> spi , true);
228-
229236 return true;
230237}
231238
0 commit comments