Skip to content

Commit dc332ba

Browse files
committed
update common_hal_reset_pin()
1 parent 1b7fbaf commit dc332ba

File tree

10 files changed

+28
-21
lines changed
  • ports
    • atmel-samd/common-hal/microcontroller
    • esp32s2/common-hal
    • litex/common-hal/microcontroller
    • mimxrt10xx/common-hal
    • nrf/common-hal/microcontroller
    • stm/common-hal/microcontroller
  • shared-module/displayio

10 files changed

+28
-21
lines changed

ports/atmel-samd/common-hal/microcontroller/Pin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
169169
}
170170

171171
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
172+
if (pin == NULL) {
173+
return;
174+
}
172175
reset_pin_number(pin->number);
173176
}
174177

ports/esp32s2/common-hal/busio/SPI.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,8 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
248248
spi_bus_free(self->host_id);
249249

250250
common_hal_reset_pin(self->clock_pin);
251-
if (self->MOSI_pin != NULL) {
252-
common_hal_reset_pin(self->MOSI_pin);
253-
}
254-
if (self->MISO_pin != NULL) {
255-
common_hal_reset_pin(self->MISO_pin);
256-
}
251+
common_hal_reset_pin(self->MOSI_pin);
252+
common_hal_reset_pin(self->MISO_pin);
257253
self->clock_pin = NULL;
258254
self->MISO_pin = NULL;
259255
self->MOSI_pin = NULL;

ports/esp32s2/common-hal/microcontroller/Pin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ void reset_pin_number(gpio_num_t pin_number) {
8989
}
9090

9191
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
92+
if (pin == NULL) {
93+
return;
94+
}
9295
reset_pin_number(pin->number);
9396
}
9497

ports/litex/common-hal/microcontroller/Pin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ void reset_pin_number(uint8_t pin_port, uint8_t pin_number) {
4242
}
4343

4444
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
45+
if (pin == NULL) {
46+
return;
47+
}
4548
reset_pin_number(0, pin->number);
4649
}
4750

ports/mimxrt10xx/common-hal/busio/SPI.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,9 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
220220
never_reset_spi[self->clock->bank_idx - 1] = false;
221221

222222
common_hal_reset_pin(self->clock->pin);
223-
if (self->mosi != NULL) {
224-
common_hal_reset_pin(self->mosi->pin);
225-
}
226-
if (self->miso != NULL) {
227-
common_hal_reset_pin(self->miso->pin);
228-
}
223+
common_hal_reset_pin(self->mosi->pin);
224+
common_hal_reset_pin(self->miso->pin);
225+
229226
self->clock = NULL;
230227
self->mosi = NULL;
231228
self->miso = NULL;

ports/mimxrt10xx/common-hal/busio/UART.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,10 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
295295
LPUART_Deinit(self->uart);
296296
gc_free(self->ringbuf);
297297

298-
if (self->rx) {
299-
common_hal_reset_pin(self->rx->pin);
300-
}
301-
if (self->tx) {
302-
common_hal_reset_pin(self->tx->pin);
303-
}
298+
299+
common_hal_reset_pin(self->rx->pin);
300+
common_hal_reset_pin(self->tx->pin);
301+
304302

305303
self->rx = NULL;
306304
self->tx = NULL;

ports/mimxrt10xx/common-hal/microcontroller/Pin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ void reset_all_pins(void) {
6767
// Since i.MX pins need extra register and reset information to reset properly,
6868
// resetting pins by number alone has been removed.
6969
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
70+
if (pin == NULL) {
71+
return;
72+
}
7073
never_reset_pins[pin->mux_idx] = false;
7174
claimed_pins[pin->mux_idx] = false;
7275
*(uint32_t*)pin->mux_reg = pin->mux_reset;

ports/nrf/common-hal/microcontroller/Pin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
134134
}
135135

136136
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
137+
if (pin == NULL) {
138+
return;
139+
}
137140
reset_pin_number(pin->number);
138141
}
139142

ports/stm/common-hal/microcontroller/Pin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ void common_hal_never_reset_pin(const mcu_pin_obj_t* pin) {
125125
}
126126

127127
void common_hal_reset_pin(const mcu_pin_obj_t* pin) {
128+
if (pin == NULL) {
129+
return;
130+
}
128131
reset_pin_number(pin->port, pin->number);
129132
}
130133

shared-module/displayio/FourWire.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self) {
7676

7777
common_hal_reset_pin(self->command.pin);
7878
common_hal_reset_pin(self->chip_select.pin);
79-
if (self->reset.pin) {
80-
common_hal_reset_pin(self->reset.pin);
81-
}
79+
common_hal_reset_pin(self->reset.pin);
8280
}
8381

8482
bool common_hal_displayio_fourwire_reset(mp_obj_t obj) {

0 commit comments

Comments
 (0)