Skip to content

Commit 30c0891

Browse files
committed
cleanup post instance parameter removal
1 parent 2f6ef76 commit 30c0891

File tree

3 files changed

+25
-48
lines changed

3 files changed

+25
-48
lines changed

shared-bindings/board/__init__.c

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -51,42 +51,21 @@
5151
//| circuitpython, as well as on circuitpython.org.
5252
//| Example: "hallowing_m0_express"."""
5353

54-
#if CIRCUITPY_BOARD_I2C || CIRCUITPY_BOARD_SPI || CIRCUITPY_BOARD_UART
55-
STATIC mp_int_t board_get_instance(size_t n_args, const mp_obj_t *args, const mp_int_t bus_in) {
56-
if (n_args == 0) {
57-
return 0;
58-
}
59-
const mp_int_t instance = mp_obj_get_int(args[0]);
60-
if (instance >= bus_in || instance < 0) {
61-
mp_raise_ValueError_varg(translate("No default %q bus"), MP_QSTR_UART);
62-
}
63-
return instance;
64-
}
65-
#endif
66-
6754
//| def I2C() -> busio.I2C:
6855
//| """Returns the `busio.I2C` object for the board's designated I2C bus(es).
6956
//| The object created is a singleton, and uses the default parameter values for `busio.I2C`."""
7057
//| ...
7158
//|
7259
#if CIRCUITPY_BOARD_I2C
73-
mp_obj_t board_i2c(size_t n_args, const mp_obj_t *args) {
74-
const mp_int_t instance = board_get_instance(n_args, args, CIRCUITPY_BOARD_I2C);
75-
const mp_obj_t singleton = common_hal_board_get_i2c(instance);
76-
if (singleton != NULL && !common_hal_busio_i2c_deinited(singleton)) {
77-
return singleton;
78-
}
79-
return common_hal_board_create_i2c(instance);
60+
STATIC mp_obj_t board_i2c_0(void) {
61+
return common_hal_board_create_i2c(0);
8062
}
8163
#else
82-
mp_obj_t board_i2c(size_t n_args, const mp_obj_t *args) {
64+
STATIC mp_obj_t board_i2c_0(void) {
8365
mp_raise_NotImplementedError_varg(translate("No default %q bus"), MP_QSTR_I2C);
8466
return MP_ROM_NONE;
8567
}
8668
#endif
87-
STATIC mp_obj_t board_i2c_0(void) {
88-
return board_i2c(0, NULL);
89-
}
9069
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c_0);
9170

9271
//| def SPI() -> busio.SPI:
@@ -95,23 +74,15 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c_0);
9574
//| ...
9675
//|
9776
#if CIRCUITPY_BOARD_SPI
98-
mp_obj_t board_spi(size_t n_args, const mp_obj_t *args) {
99-
const mp_int_t instance = board_get_instance(n_args, args, CIRCUITPY_BOARD_SPI);
100-
const mp_obj_t singleton = common_hal_board_get_spi(instance);
101-
if (singleton != NULL && !common_hal_busio_spi_deinited(singleton)) {
102-
return singleton;
103-
}
104-
return common_hal_board_create_spi(instance);
77+
STATIC mp_obj_t board_spi_0(void) {
78+
return common_hal_board_create_spi(0);
10579
}
10680
#else
107-
mp_obj_t board_spi(size_t n_args, const mp_obj_t *args) {
81+
STATIC mp_obj_t board_spi_0(void) {
10882
mp_raise_NotImplementedError_varg(translate("No default %q bus"), MP_QSTR_SPI);
10983
return MP_ROM_NONE;
11084
}
11185
#endif
112-
STATIC mp_obj_t board_spi_0(void) {
113-
return board_spi(0, NULL);
114-
}
11586
MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi_0);
11687

11788
//| def UART() -> busio.UART:
@@ -120,23 +91,15 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi_0);
12091
//| ...
12192
//|
12293
#if CIRCUITPY_BOARD_UART
123-
mp_obj_t board_uart(size_t n_args, const mp_obj_t *args) {
124-
const mp_int_t instance = board_get_instance(n_args, args, CIRCUITPY_BOARD_UART);
125-
const mp_obj_t singleton = common_hal_board_get_uart(instance);
126-
if (singleton != NULL && !common_hal_busio_uart_deinited(singleton)) {
127-
return singleton;
128-
}
129-
return common_hal_board_create_uart(instance);
94+
STATIC mp_obj_t board_uart_0(void) {
95+
return common_hal_board_create_uart(0);
13096
}
13197
#else
132-
mp_obj_t board_uart(size_t n_args, const mp_obj_t *args) {
98+
STATIC mp_obj_t board_uart_0(void) {
13399
mp_raise_NotImplementedError_varg(translate("No default %q bus"), MP_QSTR_UART);
134100
return MP_ROM_NONE;
135101
}
136102
#endif
137-
STATIC mp_obj_t board_uart_0(void) {
138-
return board_uart(0, NULL);
139-
}
140103
MP_DEFINE_CONST_FUN_OBJ_0(board_uart_obj, board_uart_0);
141104

142105
const mp_obj_module_t board_module = {

shared-bindings/board/__init__.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ MP_DECLARE_CONST_FUN_OBJ_0(board_uart_obj);
5555

5656
#define CIRCUITPY_BOARD_BUS_SINGLETON(name, bus, instance) \
5757
STATIC mp_obj_t board_##name(void) { \
58-
const mp_obj_t inst = mp_obj_new_int_from_uint(instance); \
59-
return board_##bus(1, &inst); \
58+
return common_hal_board_create_##bus(instance); \
6059
} \
6160
MP_DEFINE_CONST_FUN_OBJ_0(board_##name##_obj, board_##name);
6261

shared-module/board/__init__.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ mp_obj_t common_hal_board_get_i2c(const mp_int_t instance) {
7272
}
7373

7474
mp_obj_t common_hal_board_create_i2c(const mp_int_t instance) {
75+
const mp_obj_t singleton = common_hal_board_get_i2c(instance);
76+
if (singleton != NULL && !common_hal_busio_i2c_deinited(singleton)) {
77+
return singleton;
78+
}
79+
7580
busio_i2c_obj_t *self = &i2c_obj[instance];
7681
self->base.type = &busio_i2c_type;
7782

@@ -111,6 +116,11 @@ mp_obj_t common_hal_board_get_spi(const mp_int_t instance) {
111116
}
112117

113118
mp_obj_t common_hal_board_create_spi(const mp_int_t instance) {
119+
const mp_obj_t singleton = common_hal_board_get_spi(instance);
120+
if (singleton != NULL && !common_hal_busio_spi_deinited(singleton)) {
121+
return singleton;
122+
}
123+
114124
busio_spi_obj_t *self = &spi_obj[instance];
115125
self->base.type = &busio_spi_type;
116126

@@ -148,6 +158,11 @@ mp_obj_t common_hal_board_get_uart(const mp_int_t instance) {
148158
}
149159

150160
mp_obj_t common_hal_board_create_uart(const mp_int_t instance) {
161+
const mp_obj_t singleton = common_hal_board_get_uart(instance);
162+
if (singleton != NULL && !common_hal_busio_uart_deinited(singleton)) {
163+
return singleton;
164+
}
165+
151166
busio_uart_obj_t *self = &uart_obj[instance];
152167
self->base.type = &busio_uart_type;
153168

0 commit comments

Comments
 (0)