Skip to content

Commit be53d89

Browse files
ports/esp32: Move default I2C initialization.
Signed-off-by: Malcolm McKellips <[email protected]>
1 parent 9d6d2b4 commit be53d89

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

ports/esp32/machine_i2c.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ mp_obj_t machine_hw_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
150150
// Parse args
151151
enum { ARG_id, ARG_scl, ARG_sda, ARG_freq, ARG_timeout };
152152
static const mp_arg_t allowed_args[] = {
153-
{ MP_QSTR_id, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
153+
{ MP_QSTR_id, MP_ARG_INT, {.u_int = I2C_NUM_0} },
154154
{ MP_QSTR_scl, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
155155
{ MP_QSTR_sda, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
156156
{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 400000} },
@@ -160,13 +160,7 @@ mp_obj_t machine_hw_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
160160
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
161161

162162
// Get I2C bus
163-
// Bus ID - use I2C bus 0 as default
164-
mp_int_t i2c_id = I2C_NUM_0;
165-
166-
// User provided a value?
167-
if (args[ARG_id].u_obj != MP_OBJ_NULL) {
168-
i2c_id = mp_obj_get_int(args[ARG_id].u_obj);
169-
}
163+
mp_int_t i2c_id = args[ARG_id].u_int;
170164

171165
// Check if the I2C bus is valid
172166
if (!(I2C_NUM_0 <= i2c_id && i2c_id < I2C_NUM_MAX)) {

0 commit comments

Comments
 (0)