reset I2C and SPI on ctrl-D
This commit is contained in:
parent
f09537bbc4
commit
48a3aafdd2
|
@ -54,7 +54,11 @@ STATIC twim_peripheral_t twim_peripherals[] = {
|
||||||
#endif
|
#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) {
|
static uint8_t twi_error_to_mp(const nrfx_err_t err) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
|
|
|
@ -45,4 +45,6 @@ typedef struct {
|
||||||
uint8_t sda_pin_number;
|
uint8_t sda_pin_number;
|
||||||
} busio_i2c_obj_t;
|
} busio_i2c_obj_t;
|
||||||
|
|
||||||
|
void i2c_reset(void);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_I2C_H
|
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_I2C_H
|
||||||
|
|
|
@ -59,6 +59,12 @@ STATIC spim_peripheral_t spim_peripherals[] = {
|
||||||
#endif
|
#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
|
// Convert frequency to clock-speed-dependent value
|
||||||
static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate) {
|
static nrf_spim_frequency_t baudrate_to_spim_frequency(const uint32_t baudrate) {
|
||||||
if (baudrate <= 125000) {
|
if (baudrate <= 125000) {
|
||||||
|
|
|
@ -45,4 +45,6 @@ typedef struct {
|
||||||
uint8_t MISO_pin_number;
|
uint8_t MISO_pin_number;
|
||||||
} busio_spi_obj_t;
|
} busio_spi_obj_t;
|
||||||
|
|
||||||
|
void spi_reset(void);
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_SPI_H
|
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BUSIO_SPI_H
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
|
|
||||||
#include "shared-module/gamepad/__init__.h"
|
#include "shared-module/gamepad/__init__.h"
|
||||||
#include "common-hal/microcontroller/Pin.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 "common-hal/pulseio/PWMOut.h"
|
||||||
#include "tick.h"
|
#include "tick.h"
|
||||||
|
|
||||||
|
@ -72,11 +74,14 @@ safe_mode_t port_init(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_port(void) {
|
void reset_port(void) {
|
||||||
#ifdef CIRCUITPY_GAMEPAD_TICKS
|
#ifdef CIRCUITPY_GAMEPAD_TICKS
|
||||||
gamepad_reset();
|
gamepad_reset();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
i2c_reset();
|
||||||
|
spi_reset();
|
||||||
pwmout_reset();
|
pwmout_reset();
|
||||||
|
|
||||||
reset_all_pins();
|
reset_all_pins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue