diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2018-09-30 23:52:07 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-30 23:52:07 -0700 |
| commit | fb5ca35293141875d007bd61a3f5924dc5815a47 (patch) | |
| tree | 125fbabd5b7f6291a0198a1bd4d9b69d5b75f959 | |
| parent | f09537bbc4c58ed04e240170fd742497a2a3df5a (diff) | |
| parent | 48a3aafdd2152b53efa7ce00116796cbf92f59f6 (diff) | |
Merge pull request #1215 from dhalbert/soft-restart-device-reset
reset I2C and SPI on ctrl-D
| -rw-r--r-- | ports/nrf/common-hal/busio/I2C.c | 6 | ||||
| -rw-r--r-- | ports/nrf/common-hal/busio/I2C.h | 2 | ||||
| -rw-r--r-- | ports/nrf/common-hal/busio/SPI.c | 6 | ||||
| -rw-r--r-- | ports/nrf/common-hal/busio/SPI.h | 2 | ||||
| -rw-r--r-- | ports/nrf/supervisor/port.c | 11 |
5 files changed, 23 insertions, 4 deletions
diff --git a/ports/nrf/common-hal/busio/I2C.c b/ports/nrf/common-hal/busio/I2C.c index ad789c8c1..c2a6cab70 100644 --- a/ports/nrf/common-hal/busio/I2C.c +++ b/ports/nrf/common-hal/busio/I2C.c @@ -54,7 +54,11 @@ STATIC twim_peripheral_t twim_peripherals[] = { #endif }; -#define INST_NO 0 +void i2c_reset(void) { + for (size_t i = 0 ; i < MP_ARRAY_SIZE(twim_peripherals); i++) { + twim_peripherals[i].in_use = false; + } +} static uint8_t twi_error_to_mp(const nrfx_err_t err) { switch (err) { diff --git a/ports/nrf/common-hal/busio/I2C.h b/ports/nrf/common-hal/busio/I2C.h index 5606f46b0..c8ba84418 100644 --- a/ports/nrf/common-hal/busio/I2C.h +++ b/ports/nrf/common-hal/busio/I2C.h @@ -45,4 +45,6 @@ typedef struct { uint8_t sda_pin_number; } busio_i2c_obj_t; +void i2c_reset(void); + #endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_I2C_H diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c index 6e7f33dc7..54ae6e47c 100644 --- a/ports/nrf/common-hal/busio/SPI.c +++ b/ports/nrf/common-hal/busio/SPI.c @@ -59,6 +59,12 @@ STATIC spim_peripheral_t spim_peripherals[] = { #endif }; +void spi_reset(void) { + for (size_t i = 0 ; i < MP_ARRAY_SIZE(spim_peripherals); i++) { + nrfx_spim_uninit(&spim_peripherals[i].spim); + } +} + // Convert frequency to clock-speed-dependent value static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate) { if (baudrate <= 125000) { diff --git a/ports/nrf/common-hal/busio/SPI.h b/ports/nrf/common-hal/busio/SPI.h index c05fb1e18..1b0de8acf 100644 --- a/ports/nrf/common-hal/busio/SPI.h +++ b/ports/nrf/common-hal/busio/SPI.h @@ -45,4 +45,6 @@ typedef struct { uint8_t MISO_pin_number; } busio_spi_obj_t; +void spi_reset(void); + #endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index e6bb25458..c858a3648 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -34,6 +34,8 @@ #include "shared-module/gamepad/__init__.h" #include "common-hal/microcontroller/Pin.h" +#include "common-hal/busio/I2C.h" +#include "common-hal/busio/SPI.h" #include "common-hal/pulseio/PWMOut.h" #include "tick.h" @@ -72,11 +74,14 @@ safe_mode_t port_init(void) { } void reset_port(void) { - #ifdef CIRCUITPY_GAMEPAD_TICKS - gamepad_reset(); - #endif +#ifdef CIRCUITPY_GAMEPAD_TICKS + gamepad_reset(); +#endif + i2c_reset(); + spi_reset(); pwmout_reset(); + reset_all_pins(); } |
