diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-26 22:46:03 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-26 22:46:03 +0000 |
commit | eed6f26bed82969e3c9954159b17fe2733f4cb42 (patch) | |
tree | 204b135703111e810149f8f9fd0c786cc57c45ab | |
parent | f61a072f68c59a7acf560e2ead948fb7658c523d (diff) | |
download | micropython-eed6f26bed82969e3c9954159b17fe2733f4cb42.tar.gz micropython-eed6f26bed82969e3c9954159b17fe2733f4cb42.zip |
stmhal: Use rt_check_nargs to check number of arguments.
-rw-r--r-- | stmhal/accel.c | 4 | ||||
-rw-r--r-- | stmhal/adc.c | 5 | ||||
-rw-r--r-- | stmhal/dac.c | 4 | ||||
-rw-r--r-- | stmhal/exti.c | 2 | ||||
-rw-r--r-- | stmhal/i2c.c | 4 | ||||
-rw-r--r-- | stmhal/led.c | 4 | ||||
-rw-r--r-- | stmhal/servo.c | 5 |
7 files changed, 9 insertions, 19 deletions
diff --git a/stmhal/accel.c b/stmhal/accel.c index f4fd5469bd..c77ec5c511 100644 --- a/stmhal/accel.c +++ b/stmhal/accel.c @@ -76,9 +76,7 @@ STATIC pyb_accel_obj_t pyb_accel_obj; STATIC mp_obj_t pyb_accel_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // check arguments - if (!(n_args == 0 && n_kw == 0)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Accel accepts no arguments")); - } + rt_check_nargs(n_args, 0, 0, n_kw, false); // init accel object pyb_accel_obj.base.type = &pyb_accel_type; diff --git a/stmhal/adc.c b/stmhal/adc.c index f05e7823dd..d28392c894 100644 --- a/stmhal/adc.c +++ b/stmhal/adc.c @@ -8,6 +8,7 @@ #include "qstr.h" #include "obj.h" #include "map.h" +#include "runtime.h" #include "adc.h" #include "pin.h" #include "build/pins.h" @@ -118,9 +119,7 @@ STATIC void adc_print(void (*print)(void *env, const char *fmt, ...), void *env, STATIC mp_obj_t adc_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // check number of arguments - if (!(n_args == 1 && n_kw == 0)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "ADC accepts 1 argument")); - } + rt_check_nargs(n_args, 1, 1, n_kw, false); // 1st argument is the pin name mp_obj_t pin_obj = args[0]; diff --git a/stmhal/dac.c b/stmhal/dac.c index caf8beeecb..8bbab35be9 100644 --- a/stmhal/dac.c +++ b/stmhal/dac.c @@ -65,9 +65,7 @@ STATIC pyb_dac_obj_t pyb_dac_channel_2 = {{&pyb_dac_type}, DAC_CHANNEL_2, DMA1_S STATIC mp_obj_t pyb_dac_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // check arguments - if (!(n_args == 1 && n_kw == 0)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Dac accepts 1 argument")); - } + rt_check_nargs(n_args, 1, 1, n_kw, false); machine_int_t dac_id = mp_obj_get_int(args[0]); uint32_t pin; diff --git a/stmhal/exti.c b/stmhal/exti.c index 384691c916..c5378d835e 100644 --- a/stmhal/exti.c +++ b/stmhal/exti.c @@ -262,7 +262,7 @@ STATIC MP_DEFINE_CONST_DICT(exti_locals_dict, exti_locals_dict_table); STATIC mp_obj_t exti_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // type_in == exti_obj_type - rt_check_nargs(n_args, 4, 4, n_kw, 0); + rt_check_nargs(n_args, 4, 4, n_kw, false); exti_obj_t *self = m_new_obj(exti_obj_t); self->base.type = type_in; diff --git a/stmhal/i2c.c b/stmhal/i2c.c index 9bf7799f40..9556e32c9c 100644 --- a/stmhal/i2c.c +++ b/stmhal/i2c.c @@ -80,9 +80,7 @@ STATIC pyb_i2c_obj_t pyb_i2c_obj[PYB_NUM_I2C] = {{{&pyb_i2c_type}, &I2cHandle_X} STATIC mp_obj_t pyb_i2c_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // check arguments - if (!(n_args == 1 && n_kw == 0)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "I2C accepts 1 argument")); - } + rt_check_nargs(n_args, 1, 1, n_kw, false); // get i2c number machine_int_t i2c_id = mp_obj_get_int(args[0]) - 1; diff --git a/stmhal/led.c b/stmhal/led.c index 13dc81d18e..557f54538e 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -208,9 +208,7 @@ void led_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp STATIC mp_obj_t led_obj_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // check arguments - if (!(n_args == 1 && n_kw == 0)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Led accepts 1 argument")); - } + rt_check_nargs(n_args, 1, 1, n_kw, false); // get led number machine_int_t led_id = mp_obj_get_int(args[0]) - 1; diff --git a/stmhal/servo.c b/stmhal/servo.c index ad33db75c2..5955328580 100644 --- a/stmhal/servo.c +++ b/stmhal/servo.c @@ -8,6 +8,7 @@ #include "qstr.h" #include "obj.h" #include "map.h" +#include "runtime.h" #include "servo.h" // this servo driver uses hardware PWM to drive servos on PA0, PA1, PA2, PA3 = X1, X2, X3, X4 @@ -156,9 +157,7 @@ STATIC void pyb_servo_print(void (*print)(void *env, const char *fmt, ...), void STATIC mp_obj_t pyb_servo_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { // check arguments - if (!(n_args == 1 && n_kw == 0)) { - nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Servo accepts 1 argument")); - } + rt_check_nargs(n_args, 1, 1, n_kw, false); // get servo number machine_int_t servo_id = mp_obj_get_int(args[0]) - 1; |