Fix lost board.SPI and board.I2C after explicitly deiniting them.
After calling board.SPI().deinit(), calling board.SPI() again would return the unusable deinited object and there was no way of getting it back into an initialized state until the end of the session.
This commit is contained in:
parent
f4f80e07ca
commit
99a3750a2c
@ -28,6 +28,12 @@
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
#if BOARD_I2C
|
||||
#include "shared-bindings/busio/I2C.h"
|
||||
#endif
|
||||
#if BOARD_SPI
|
||||
#include "shared-bindings/busio/SPI.h"
|
||||
#endif
|
||||
|
||||
//| """Board specific pin names
|
||||
//|
|
||||
@ -45,7 +51,7 @@
|
||||
#if BOARD_I2C
|
||||
mp_obj_t board_i2c(void) {
|
||||
mp_obj_t singleton = common_hal_board_get_i2c();
|
||||
if (singleton != NULL) {
|
||||
if (singleton != NULL && !common_hal_busio_i2c_deinited(singleton)) {
|
||||
return singleton;
|
||||
}
|
||||
assert_pin_free(DEFAULT_I2C_BUS_SDA);
|
||||
@ -69,7 +75,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
|
||||
#if BOARD_SPI
|
||||
mp_obj_t board_spi(void) {
|
||||
mp_obj_t singleton = common_hal_board_get_spi();
|
||||
if (singleton != NULL) {
|
||||
if (singleton != NULL && !common_hal_busio_spi_deinited(singleton)) {
|
||||
return singleton;
|
||||
}
|
||||
assert_pin_free(DEFAULT_SPI_BUS_SCK);
|
||||
|
@ -55,9 +55,8 @@ mp_obj_t common_hal_board_get_i2c(void) {
|
||||
}
|
||||
|
||||
mp_obj_t common_hal_board_create_i2c(void) {
|
||||
if (i2c_singleton != NULL) {
|
||||
return i2c_singleton;
|
||||
}
|
||||
// All callers have either already verified this or come so early that it can't be otherwise.
|
||||
assert(i2c_singleton == NULL || common_hal_busio_i2c_deinited(i2c_singleton));
|
||||
busio_i2c_obj_t *self = &i2c_obj;
|
||||
self->base.type = &busio_i2c_type;
|
||||
|
||||
@ -79,9 +78,8 @@ mp_obj_t common_hal_board_get_spi(void) {
|
||||
}
|
||||
|
||||
mp_obj_t common_hal_board_create_spi(void) {
|
||||
if (spi_singleton != NULL) {
|
||||
return spi_singleton;
|
||||
}
|
||||
// All callers have either already verified this or come so early that it can't be otherwise.
|
||||
assert(spi_singleton == NULL || common_hal_busio_spi_deinited(spi_singleton));
|
||||
busio_spi_obj_t *self = &spi_obj;
|
||||
self->base.type = &busio_spi_type;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user