Skip to content

Commit 9d6d2b4

Browse files
ports/rp2: Move default I2C check.
Signed-off-by: Malcolm McKellips <[email protected]>
1 parent 53f1a3a commit 9d6d2b4

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

ports/rp2/machine_i2c.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ static void machine_i2c_print(const mp_print_t *print, mp_obj_t self_in, mp_prin
9797
mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
9898
enum { ARG_id, ARG_freq, ARG_scl, ARG_sda, ARG_timeout };
9999
static const mp_arg_t allowed_args[] = {
100-
{ MP_QSTR_id, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
100+
#ifdef PICO_DEFAULT_I2C
101+
{ MP_QSTR_id, MP_ARG_INT, {.u_int = PICO_DEFAULT_I2C} },
102+
#else
103+
{ MP_QSTR_id, MP_ARG_INT, {.u_int = -1} },
104+
#endif
101105
{ MP_QSTR_freq, MP_ARG_INT, {.u_int = DEFAULT_I2C_FREQ} },
102106
{ MP_QSTR_scl, MICROPY_I2C_PINS_ARG_OPTS | MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
103107
{ MP_QSTR_sda, MICROPY_I2C_PINS_ARG_OPTS | MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
@@ -108,18 +112,7 @@ mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
108112
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
109113
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
110114

111-
// Bus ID - use the default I2C bus as default
112-
#ifdef PICO_DEFAULT_I2C
113-
int i2c_id = PICO_DEFAULT_I2C;
114-
#else
115-
// invalid value
116-
int i2c_id = -1;
117-
#endif
118-
119-
// User provide a value?
120-
if (args[ARG_id].u_obj != mp_const_none) {
121-
i2c_id = mp_obj_get_int(args[ARG_id].u_obj);
122-
}
115+
int i2c_id = args[ARG_id].u_int;
123116

124117
// Check if the I2C bus is valid
125118
if (i2c_id < 0 || i2c_id >= MP_ARRAY_SIZE(machine_i2c_obj)) {

0 commit comments

Comments
 (0)