File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 28
28
#include "py/runtime.h"
29
29
30
30
#include "shared-bindings/board/__init__.h"
31
+ #if BOARD_I2C
32
+ #include "shared-bindings/busio/I2C.h"
33
+ #endif
34
+ #if BOARD_SPI
35
+ #include "shared-bindings/busio/SPI.h"
36
+ #endif
31
37
32
38
//| """Board specific pin names
33
39
//|
45
51
#if BOARD_I2C
46
52
mp_obj_t board_i2c (void ) {
47
53
mp_obj_t singleton = common_hal_board_get_i2c ();
48
- if (singleton != NULL ) {
54
+ if (singleton != NULL && ! common_hal_busio_i2c_deinited ( singleton ) ) {
49
55
return singleton ;
50
56
}
51
57
assert_pin_free (DEFAULT_I2C_BUS_SDA );
@@ -69,7 +75,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
69
75
#if BOARD_SPI
70
76
mp_obj_t board_spi (void ) {
71
77
mp_obj_t singleton = common_hal_board_get_spi ();
72
- if (singleton != NULL ) {
78
+ if (singleton != NULL && ! common_hal_busio_spi_deinited ( singleton ) ) {
73
79
return singleton ;
74
80
}
75
81
assert_pin_free (DEFAULT_SPI_BUS_SCK );
Original file line number Diff line number Diff line change @@ -55,9 +55,8 @@ mp_obj_t common_hal_board_get_i2c(void) {
55
55
}
56
56
57
57
mp_obj_t common_hal_board_create_i2c (void ) {
58
- if (i2c_singleton != NULL ) {
59
- return i2c_singleton ;
60
- }
58
+ // All callers have either already verified this or come so early that it can't be otherwise.
59
+ assert (i2c_singleton == NULL || common_hal_busio_i2c_deinited (i2c_singleton ));
61
60
busio_i2c_obj_t * self = & i2c_obj ;
62
61
self -> base .type = & busio_i2c_type ;
63
62
@@ -79,9 +78,8 @@ mp_obj_t common_hal_board_get_spi(void) {
79
78
}
80
79
81
80
mp_obj_t common_hal_board_create_spi (void ) {
82
- if (spi_singleton != NULL ) {
83
- return spi_singleton ;
84
- }
81
+ // All callers have either already verified this or come so early that it can't be otherwise.
82
+ assert (spi_singleton == NULL || common_hal_busio_spi_deinited (spi_singleton ));
85
83
busio_spi_obj_t * self = & spi_obj ;
86
84
self -> base .type = & busio_spi_type ;
87
85
You can’t perform that action at this time.
0 commit comments