Commit eed6f26b authored by Damien George's avatar Damien George
Browse files

stmhal: Use rt_check_nargs to check number of arguments.

parent f61a072f
...@@ -76,9 +76,7 @@ STATIC pyb_accel_obj_t pyb_accel_obj; ...@@ -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) { 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 // check arguments
if (!(n_args == 0 && n_kw == 0)) { rt_check_nargs(n_args, 0, 0, n_kw, false);
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Accel accepts no arguments"));
}
// init accel object // init accel object
pyb_accel_obj.base.type = &pyb_accel_type; pyb_accel_obj.base.type = &pyb_accel_type;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "qstr.h" #include "qstr.h"
#include "obj.h" #include "obj.h"
#include "map.h" #include "map.h"
#include "runtime.h"
#include "adc.h" #include "adc.h"
#include "pin.h" #include "pin.h"
#include "build/pins.h" #include "build/pins.h"
...@@ -118,9 +119,7 @@ STATIC void adc_print(void (*print)(void *env, const char *fmt, ...), void *env, ...@@ -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) { 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 // check number of arguments
if (!(n_args == 1 && n_kw == 0)) { rt_check_nargs(n_args, 1, 1, n_kw, false);
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "ADC accepts 1 argument"));
}
// 1st argument is the pin name // 1st argument is the pin name
mp_obj_t pin_obj = args[0]; mp_obj_t pin_obj = args[0];
......
...@@ -65,9 +65,7 @@ STATIC pyb_dac_obj_t pyb_dac_channel_2 = {{&pyb_dac_type}, DAC_CHANNEL_2, DMA1_S ...@@ -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) { 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 // check arguments
if (!(n_args == 1 && n_kw == 0)) { rt_check_nargs(n_args, 1, 1, n_kw, false);
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Dac accepts 1 argument"));
}
machine_int_t dac_id = mp_obj_get_int(args[0]); machine_int_t dac_id = mp_obj_get_int(args[0]);
uint32_t pin; uint32_t pin;
......
...@@ -262,7 +262,7 @@ STATIC MP_DEFINE_CONST_DICT(exti_locals_dict, exti_locals_dict_table); ...@@ -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) { 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 // 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); exti_obj_t *self = m_new_obj(exti_obj_t);
self->base.type = type_in; self->base.type = type_in;
......
...@@ -80,9 +80,7 @@ STATIC pyb_i2c_obj_t pyb_i2c_obj[PYB_NUM_I2C] = {{{&pyb_i2c_type}, &I2cHandle_X} ...@@ -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) { 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 // check arguments
if (!(n_args == 1 && n_kw == 0)) { rt_check_nargs(n_args, 1, 1, n_kw, false);
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "I2C accepts 1 argument"));
}
// get i2c number // get i2c number
machine_int_t i2c_id = mp_obj_get_int(args[0]) - 1; machine_int_t i2c_id = mp_obj_get_int(args[0]) - 1;
......
...@@ -208,9 +208,7 @@ void led_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp ...@@ -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) { 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 // check arguments
if (!(n_args == 1 && n_kw == 0)) { rt_check_nargs(n_args, 1, 1, n_kw, false);
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Led accepts 1 argument"));
}
// get led number // get led number
machine_int_t led_id = mp_obj_get_int(args[0]) - 1; machine_int_t led_id = mp_obj_get_int(args[0]) - 1;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "qstr.h" #include "qstr.h"
#include "obj.h" #include "obj.h"
#include "map.h" #include "map.h"
#include "runtime.h"
#include "servo.h" #include "servo.h"
// this servo driver uses hardware PWM to drive servos on PA0, PA1, PA2, PA3 = X1, X2, X3, X4 // 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 ...@@ -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) { 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 // check arguments
if (!(n_args == 1 && n_kw == 0)) { rt_check_nargs(n_args, 1, 1, n_kw, false);
nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Servo accepts 1 argument"));
}
// get servo number // get servo number
machine_int_t servo_id = mp_obj_get_int(args[0]) - 1; machine_int_t servo_id = mp_obj_get_int(args[0]) - 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment