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;
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;
......
......@@ -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];
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
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