Skip to content

Commit a861223

Browse files
Gadgetoiddpgeorge
authored andcommitted
rp2/machine_spi: Make SPI ID optional.
If the "spi_id" arg is not supplied and then the board default specified by PICO_DEFAULT_SPI will be used. Signed-off-by: Phil Howard <[email protected]>
1 parent f315a37 commit a861223

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ports/rp2/machine_spi.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ static void machine_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
128128
mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
129129
enum { ARG_id, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit, ARG_sck, ARG_mosi, ARG_miso };
130130
static const mp_arg_t allowed_args[] = {
131-
{ MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_OBJ },
131+
#ifdef PICO_DEFAULT_SPI
132+
{ MP_QSTR_id, MP_ARG_INT, {.u_int = PICO_DEFAULT_SPI} },
133+
#else
134+
{ MP_QSTR_id, MP_ARG_REQUIRED | MP_ARG_INT, },
135+
#endif
132136
{ MP_QSTR_baudrate, MP_ARG_INT, {.u_int = DEFAULT_SPI_BAUDRATE} },
133137
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_SPI_POLARITY} },
134138
{ MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DEFAULT_SPI_PHASE} },
@@ -144,7 +148,7 @@ mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
144148
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
145149

146150
// Get the SPI bus id.
147-
int spi_id = mp_obj_get_int(args[ARG_id].u_obj);
151+
int spi_id = args[ARG_id].u_int;
148152
if (spi_id < 0 || spi_id >= MP_ARRAY_SIZE(machine_spi_obj)) {
149153
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("SPI(%d) doesn't exist"), spi_id);
150154
}

0 commit comments

Comments
 (0)