From a7261ae059f171e9677a86c59c7f7ed9e24b7ace Mon Sep 17 00:00:00 2001 From: Daniel Campora Date: Sun, 27 Sep 2015 09:28:27 +0200 Subject: [PATCH] cc3200/mods: Use mp_obj_get_array_fixed_n() where applicable. --- cc3200/mods/pybi2c.c | 8 ++------ cc3200/mods/pybsd.c | 8 ++------ cc3200/mods/pybspi.c | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/cc3200/mods/pybi2c.c b/cc3200/mods/pybi2c.c index 0bf054f559..75316e23fe 100644 --- a/cc3200/mods/pybi2c.c +++ b/cc3200/mods/pybi2c.c @@ -292,17 +292,13 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self, const mp_arg_val_t *arg mp_obj_t pins_o = args[2].u_obj; if (pins_o != mp_const_none) { mp_obj_t *pins; - mp_uint_t n_pins = 2; if (pins_o == MP_OBJ_NULL) { // use the default pins pins = (mp_obj_t *)pyb_i2c_def_pin; } else { - mp_obj_get_array(pins_o, &n_pins, &pins); - if (n_pins != 2) { - goto invalid_args; - } + mp_obj_get_array_fixed_n(pins_o, 2, &pins); } - pin_assign_pins_af (pins, n_pins, PIN_TYPE_STD_PU, PIN_FN_I2C, 0); + pin_assign_pins_af (pins, 2, PIN_TYPE_STD_PU, PIN_FN_I2C, 0); } // init the I2C bus diff --git a/cc3200/mods/pybsd.c b/cc3200/mods/pybsd.c index 55dc98ae80..04125ef69f 100644 --- a/cc3200/mods/pybsd.c +++ b/cc3200/mods/pybsd.c @@ -95,17 +95,13 @@ STATIC mp_obj_t pyb_sd_init_helper (pybsd_obj_t *self, const mp_arg_val_t *args) mp_obj_t pins_o = args[0].u_obj; if (pins_o != mp_const_none) { mp_obj_t *pins; - mp_uint_t n_pins = MP_ARRAY_SIZE(pyb_sd_def_pin); if (pins_o == MP_OBJ_NULL) { // use the default pins pins = (mp_obj_t *)pyb_sd_def_pin; } else { - mp_obj_get_array(pins_o, &n_pins, &pins); - if (n_pins != MP_ARRAY_SIZE(pyb_sd_def_pin)) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments)); - } + mp_obj_get_array_fixed_n(pins_o, MP_ARRAY_SIZE(pyb_sd_def_pin), &pins); } - pin_assign_pins_af (pins, n_pins, PIN_TYPE_STD_PU, PIN_FN_SD, 0); + pin_assign_pins_af (pins, MP_ARRAY_SIZE(pyb_sd_def_pin), PIN_TYPE_STD_PU, PIN_FN_SD, 0); // save the pins clock self->pin_clk = pin_find(pins[0]); } diff --git a/cc3200/mods/pybspi.c b/cc3200/mods/pybspi.c index 94387bcfbb..a248cfcff7 100644 --- a/cc3200/mods/pybspi.c +++ b/cc3200/mods/pybspi.c @@ -201,17 +201,13 @@ STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, const mp_arg_val_t *arg mp_obj_t pins_o = args[6].u_obj; if (pins_o != mp_const_none) { mp_obj_t *pins; - mp_uint_t n_pins = 3; if (pins_o == MP_OBJ_NULL) { // use the default pins pins = (mp_obj_t *)pyb_spi_def_pin; } else { - mp_obj_get_array(pins_o, &n_pins, &pins); - if (n_pins != 3) { - goto invalid_args; - } + mp_obj_get_array_fixed_n(pins_o, 3, &pins); } - pin_assign_pins_af (pins, n_pins, PIN_TYPE_STD_PU, PIN_FN_SPI, 0); + pin_assign_pins_af (pins, 3, PIN_TYPE_STD_PU, PIN_FN_SPI, 0); } // init the bus