@@ -33,28 +33,6 @@ static SPI1_Type *aux_spi[NUM_SPI] = {NULL, SPI1, SPI2};
3333static bool never_reset_spi [NUM_SPI ];
3434static bool spi_in_use [NUM_SPI ];
3535
36- void reset_spi (void ) {
37- for (size_t i = 0 ; i < NUM_SPI ; i ++ ) {
38- if (never_reset_spi [i ]) {
39- continue ;
40- }
41-
42- if (i == 1 || i == 2 ) {
43- if (i == 1 ) {
44- AUX -> ENABLES_b .SPI_1 = false;
45- } else {
46- AUX -> ENABLES_b .SPI_2 = false;
47- }
48- aux_spi [i ]-> CNTL0 = 0 ;
49- } else {
50- // Set CS back to default. All 0 except read enable.
51- spi [i ]-> CS = SPI0_CS_REN_Msk ;
52- }
53-
54- spi_in_use [i ] = false;
55- }
56- }
57-
5836void common_hal_busio_spi_construct (busio_spi_obj_t * self ,
5937 const mcu_pin_obj_t * clock , const mcu_pin_obj_t * mosi ,
6038 const mcu_pin_obj_t * miso , bool half_duplex ) {
@@ -67,6 +45,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
6745 mp_raise_NotImplementedError (MP_ERROR_TEXT ("Half duplex SPI is not implemented" ));
6846 }
6947
48+ // Ensure the object starts in its deinit state.
49+ common_hal_busio_spi_mark_deinit (self );
50+
7051 // BCM_VERSION != 2711 have 3 SPI but as listed in peripherals/gen/pins.c two are on
7152 // index 0, once one index 0 SPI is found the other will throw an invalid_pins error.
7253 for (size_t i = 0 ; i < NUM_SPI ; i ++ ) {
@@ -129,6 +110,10 @@ bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
129110 return self -> clock == NULL ;
130111}
131112
113+ void common_hal_busio_spi_mark_deinit (busio_spi_obj_t * self ) {
114+ self -> clock = NULL ;
115+ }
116+
132117void common_hal_busio_spi_deinit (busio_spi_obj_t * self ) {
133118 if (common_hal_busio_spi_deinited (self )) {
134119 return ;
@@ -138,7 +123,7 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
138123 common_hal_reset_pin (self -> clock );
139124 common_hal_reset_pin (self -> MOSI );
140125 common_hal_reset_pin (self -> MISO );
141- self -> clock = NULL ;
126+
142127 spi_in_use [self -> index ] = false;
143128
144129 if (self -> index == 1 ||
@@ -149,7 +134,12 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
149134 } else if (self -> index == 2 ) {
150135 AUX -> ENABLES_b .SPI_2 = false;
151136 }
137+ } else {
138+ // Set CS back to default. All 0 except read enable.
139+ spi [i ]-> CS = SPI0_CS_REN_Msk ;
152140 }
141+
142+ common_hal_busio_spi_mark_deinit (self );
153143}
154144
155145bool common_hal_busio_spi_configure (busio_spi_obj_t * self ,
0 commit comments