diff options
| author | Christian Walther <cwalther@gmx.ch> | 2020-10-24 17:50:11 +0200 |
|---|---|---|
| committer | Christian Walther <cwalther@gmx.ch> | 2020-10-26 22:44:38 +0100 |
| commit | 99a3750a2cfd1da8cdd266ca9a0367f0c3a54092 (patch) | |
| tree | c5460670d31cad290d9223d494bcfae345e9ffde /shared-module | |
| parent | f4f80e07ca3dc2f5a93484e5342540837a94a505 (diff) | |
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.
Diffstat (limited to 'shared-module')
| -rw-r--r-- | shared-module/board/__init__.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index 967b430d2..2f1c34e56 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -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; |
