diff options
-rw-r--r-- | py/builtin.h | 4 | ||||
-rw-r--r-- | py/builtinimport.c | 2 | ||||
-rw-r--r-- | py/obj.c | 28 | ||||
-rw-r--r-- | py/obj.h | 4 | ||||
-rw-r--r-- | stmhal/Makefile | 1 | ||||
-rw-r--r-- | stmhal/accel.c | 29 | ||||
-rw-r--r-- | stmhal/accel.h | 2 | ||||
-rw-r--r-- | stmhal/help.c | 90 | ||||
-rw-r--r-- | stmhal/led.c | 46 | ||||
-rw-r--r-- | stmhal/led.h | 2 | ||||
-rw-r--r-- | stmhal/main.c | 31 | ||||
-rw-r--r-- | stmhal/mpconfigport.h | 2 | ||||
-rw-r--r-- | stmhal/pybmodule.c | 6 | ||||
-rw-r--r-- | stmhal/servo.c | 55 | ||||
-rw-r--r-- | stmhal/servo.h | 3 |
15 files changed, 207 insertions, 98 deletions
diff --git a/py/builtin.h b/py/builtin.h index d9414045de..69b94e0181 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -1,4 +1,4 @@ -mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args); +mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args); MP_DECLARE_CONST_FUN_OBJ(mp_builtin___build_class___obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin___import___obj); @@ -6,7 +6,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin___repl_print___obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_abs_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_all_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_any_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_bytes_obj); // Temporary hack MP_DECLARE_CONST_FUN_OBJ(mp_builtin_callable_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_dir_obj); @@ -30,7 +29,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_range_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_repr_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sorted_obj); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sum_obj); -MP_DECLARE_CONST_FUN_OBJ(mp_builtin_str_obj); MP_DECLARE_CONST_FUN_OBJ(mp_namedtuple_obj); diff --git a/py/builtinimport.c b/py/builtinimport.c index 2b9b3a30b9..d4d56b5171 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -128,7 +128,7 @@ void do_load(mp_obj_t module_obj, vstr_t *file) { rt_globals_set(old_globals); } -mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) { +mp_obj_t mp_builtin___import__(uint n_args, mp_obj_t *args) { /* printf("import:\n"); for (int i = 0; i < n_args; i++) { @@ -206,21 +206,29 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) { } #endif -mp_obj_t *mp_obj_get_array_fixed_n(mp_obj_t o_in, machine_int_t n) { - if (MP_OBJ_IS_TYPE(o_in, &tuple_type) || MP_OBJ_IS_TYPE(o_in, &list_type)) { +void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) { + if (MP_OBJ_IS_TYPE(o, &tuple_type)) { + mp_obj_tuple_get(o, len, items); + } else if (MP_OBJ_IS_TYPE(o, &list_type)) { + mp_obj_list_get(o, len, items); + } else { + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o))); + } +} + +void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items) { + if (MP_OBJ_IS_TYPE(o, &tuple_type) || MP_OBJ_IS_TYPE(o, &list_type)) { uint seq_len; - mp_obj_t *seq_items; - if (MP_OBJ_IS_TYPE(o_in, &tuple_type)) { - mp_obj_tuple_get(o_in, &seq_len, &seq_items); + if (MP_OBJ_IS_TYPE(o, &tuple_type)) { + mp_obj_tuple_get(o, &seq_len, items); } else { - mp_obj_list_get(o_in, &seq_len, &seq_items); + mp_obj_list_get(o, &seq_len, items); } - if (seq_len != n) { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "requested length %d but object has length %d", n, seq_len)); + if (seq_len != len) { + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_IndexError, "requested length %d but object has length %d", len, seq_len)); } - return seq_items; } else { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o_in))); + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object '%s' is not a tuple or list", mp_obj_get_type_str(o))); } } @@ -175,7 +175,6 @@ struct _mp_obj_type_t { abs float complex hash bool int none str equal int str - get_array_n tuple list unpack seq list tuple */ @@ -311,7 +310,8 @@ mp_float_t mp_obj_get_float(mp_obj_t self_in); void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag); #endif //qstr mp_obj_get_qstr(mp_obj_t arg); -mp_obj_t *mp_obj_get_array_fixed_n(mp_obj_t o, machine_int_t n); +void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items); +void mp_obj_get_array_fixed_n(mp_obj_t o, uint len, mp_obj_t **items); uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice); mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); /* may return NULL */ diff --git a/stmhal/Makefile b/stmhal/Makefile index 292bfdd61c..fbe8a450b8 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -72,6 +72,7 @@ SRC_C = \ malloc0.c \ gccollect.c \ pyexec.c \ + help.c \ input.c \ pybmodule.c \ osmodule.c \ diff --git a/stmhal/accel.c b/stmhal/accel.c index cd513b3fe8..b58b7c4db4 100644 --- a/stmhal/accel.c +++ b/stmhal/accel.c @@ -3,6 +3,7 @@ #include <stm32f4xx_hal.h> +#include "nlr.h" #include "misc.h" #include "mpconfig.h" #include "qstr.h" @@ -99,6 +100,19 @@ typedef struct _pyb_accel_obj_t { 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")); + } + + // init accel object + pyb_accel_obj.base.type = &pyb_accel_type; + accel_init_device(); + + return &pyb_accel_obj; +} + STATIC mp_obj_t read_axis(int axis) { uint8_t data[1]; HAL_I2C_Mem_Read(&I2cHandle, MMA_ADDR, axis, I2C_MEMADD_SIZE_8BIT, data, 1, 200); @@ -171,7 +185,7 @@ STATIC mp_obj_t pyb_accel_write_reg(mp_obj_t self_in, mp_obj_t reg, mp_obj_t val MP_DEFINE_CONST_FUN_OBJ_3(pyb_accel_write_reg_obj, pyb_accel_write_reg); -STATIC const mp_method_t accel_methods[] = { +STATIC const mp_method_t pyb_accel_methods[] = { { "x", &pyb_accel_x_obj }, { "y", &pyb_accel_y_obj }, { "z", &pyb_accel_z_obj }, @@ -182,16 +196,9 @@ STATIC const mp_method_t accel_methods[] = { { NULL, NULL }, }; -STATIC const mp_obj_type_t accel_obj_type = { +const mp_obj_type_t pyb_accel_type = { { &mp_type_type }, .name = MP_QSTR_Accel, - .methods = accel_methods, + .make_new = pyb_accel_make_new, + .methods = pyb_accel_methods, }; - -STATIC mp_obj_t pyb_Accel(void) { - pyb_accel_obj.base.type = &accel_obj_type; - accel_init_device(); - return &pyb_accel_obj; -} - -MP_DEFINE_CONST_FUN_OBJ_0(pyb_Accel_obj, pyb_Accel); diff --git a/stmhal/accel.h b/stmhal/accel.h index b2c0fd6b19..88fabfd543 100644 --- a/stmhal/accel.h +++ b/stmhal/accel.h @@ -1,3 +1,3 @@ void accel_init(void); -MP_DECLARE_CONST_FUN_OBJ(pyb_Accel_obj); +extern const mp_obj_type_t pyb_accel_type; diff --git a/stmhal/help.c b/stmhal/help.c new file mode 100644 index 0000000000..9efe374524 --- /dev/null +++ b/stmhal/help.c @@ -0,0 +1,90 @@ +#include <stdio.h> + +#include "nlr.h" +#include "misc.h" +#include "mpconfig.h" +#include "qstr.h" +#include "obj.h" +#include "map.h" + +STATIC const char *help_text = +"Welcome to Micro Python!\n" +"\n" +"For online help please visit http://micropython.org/help/.\n" +"\n" +"Specific commands for the board:\n" +" pyb.info() -- print some general information\n" +" pyb.gc() -- run the garbage collector\n" +" pyb.repl_info(<val>) -- enable/disable printing of info after each command\n" +" pyb.delay(<n>) -- wait for n milliseconds\n" +" pyb.udelay(<n>) -- wait for n microseconds\n" +" pyb.switch() -- return True/False if switch pressed or not\n" +" pyb.Led(<n>) -- create Led object for LED n (n=1,2,3,4)\n" +" Led methods: on(), off(), toggle(), intensity(<n>)\n" +" pyb.Servo(<n>) -- create Servo object for servo n (n=1,2,3,4)\n" +" Servo methods: angle(<x>)\n" +" pyb.Accel() -- create an Accelerometer object\n" +" Accelerometer methods: x(), y(), z(), tilt()\n" +" pyb.rng() -- get a 30-bit hardware random number\n" +" pyb.gpio(<port>) -- get port value (port='A4' for example)\n" +" pyb.gpio(<port>, <val>) -- set port value, True or False, 1 or 0\n" +" pyb.ADC(<port>) -- make an analog port object (port='C0' for example)\n" +" ADC methods: read()\n" +"\n" +"Control commands:\n" +" CTRL-A -- on a blank line, enter raw REPL mode\n" +" CTRL-B -- on a blank line, enter normal REPL mode\n" +" CTRL-C -- interrupt a running program\n" +" CTRL-D -- on a blank line, do a soft reset of the board\n" +; + +STATIC void pyb_help_print_info_about_object(mp_obj_t name_o, const char *name_str, mp_obj_t value) { + if (name_o != MP_OBJ_NULL) { + printf(" "); + mp_obj_print(name_o, PRINT_STR); + printf(" -- "); + } else { + printf(" %s -- ", name_str); + } + mp_obj_print(value, PRINT_STR); + printf("\n"); +} + +STATIC mp_obj_t pyb_help(uint n_args, const mp_obj_t *args) { + if (n_args == 0) { + // print a general help message + printf("%s", help_text); + + } else { + // try to print something sensible about the given object + + printf("object "); + mp_obj_print(args[0], PRINT_STR); + printf(" is of type %s\n", mp_obj_get_type_str(args[0])); + + mp_obj_type_t *type = mp_obj_get_type(args[0]); + mp_map_t *map = NULL; + if (type == &mp_type_module) { + map = mp_obj_module_get_globals(args[0]); + } else if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &dict_type)) { + map = mp_obj_dict_get_map(type->locals_dict); + } + if (map != NULL) { + for (uint i = 0; i < map->alloc; i++) { + if (map->table[i].key != MP_OBJ_NULL) { + pyb_help_print_info_about_object(map->table[i].key, NULL, map->table[i].value); + } + } + } + + if (type->methods != NULL) { + for (const mp_method_t *meth = type->methods; meth->name != NULL; meth++) { + pyb_help_print_info_about_object(MP_OBJ_NULL, meth->name, (mp_obj_t)meth->fun); + } + } + } + + return mp_const_none; +} + +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_help_obj, 0, 1, pyb_help); diff --git a/stmhal/led.c b/stmhal/led.c index 102cbac5a7..688daefc81 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -3,6 +3,7 @@ #include "usbd_cdc_msc.h" #include "usbd_cdc_interface.h" +#include "nlr.h" #include "misc.h" #include "mpconfig.h" #include "qstr.h" @@ -183,14 +184,45 @@ void led_debug(int n, int delay) { typedef struct _pyb_led_obj_t { mp_obj_base_t base; - uint led_id; + machine_uint_t led_id; } pyb_led_obj_t; +STATIC const pyb_led_obj_t pyb_led_obj[NUM_LEDS] = { + {{&pyb_led_type}, 1}, +#if defined(PYB_LED2) + {{&pyb_led_type}, 2}, +#if defined(PYB_LED3) + {{&pyb_led_type}, 3}, +#if defined(PYB_LED4) + {{&pyb_led_type}, 4}, +#endif +#endif +#endif +}; + void led_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { pyb_led_obj_t *self = self_in; print(env, "<LED %lu>", self->led_id); } +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")); + } + + // get led number + machine_int_t led_id = mp_obj_get_int(args[0]) - 1; + + // check led number + if (!(0 <= led_id && led_id < NUM_LEDS)) { + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Led %d does not exist", led_id)); + } + + // return static led object + return (mp_obj_t)&pyb_led_obj[led_id]; +} + mp_obj_t led_obj_on(mp_obj_t self_in) { pyb_led_obj_t *self = self_in; led_state(self->led_id, 1); @@ -232,18 +264,10 @@ STATIC const mp_method_t led_methods[] = { { NULL, NULL }, }; -STATIC const mp_obj_type_t led_obj_type = { +const mp_obj_type_t pyb_led_type = { { &mp_type_type }, .name = MP_QSTR_Led, .print = led_obj_print, + .make_new = led_obj_make_new, .methods = led_methods, }; - -STATIC mp_obj_t pyb_Led(mp_obj_t led_id) { - pyb_led_obj_t *o = m_new_obj(pyb_led_obj_t); - o->base.type = &led_obj_type; - o->led_id = mp_obj_get_int(led_id); - return o; -} - -MP_DEFINE_CONST_FUN_OBJ_1(pyb_Led_obj, pyb_Led); diff --git a/stmhal/led.h b/stmhal/led.h index b3762271c1..ab2b2ea14e 100644 --- a/stmhal/led.h +++ b/stmhal/led.h @@ -21,4 +21,4 @@ void led_state(pyb_led_t led, int state); void led_toggle(pyb_led_t led); void led_debug(int value, int delay); -MP_DECLARE_CONST_FUN_OBJ(pyb_Led_obj); +extern const mp_obj_type_t pyb_led_type; diff --git a/stmhal/main.c b/stmhal/main.c index 9d88206978..0a70512692 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -121,34 +121,6 @@ static const char fresh_main_py[] = "# main.py -- put your code here!\n" ; -static const char *help_text = -"Welcome to Micro Python!\n\n" -"This is a *very* early version of Micro Python and has minimal functionality.\n\n" -"Specific commands for the board:\n" -" pyb.info() -- print some general information\n" -" pyb.gc() -- run the garbage collector\n" -" pyb.repl_info(<val>) -- enable/disable printing of info after each command\n" -" pyb.delay(<n>) -- wait for n milliseconds\n" -" pyb.udelay(<n>) -- wait for n microseconds\n" -" pyb.Led(<n>) -- create Led object for LED n (n=1,2)\n" -" Led methods: on(), off()\n" -" pyb.Servo(<n>) -- create Servo object for servo n (n=1,2,3,4)\n" -" Servo methods: angle(<x>)\n" -" pyb.switch() -- return True/False if switch pressed or not\n" -" pyb.accel() -- get accelerometer values\n" -" pyb.rand() -- get a 16-bit random number\n" -" pyb.gpio(<port>) -- get port value (port='A4' for example)\n" -" pyb.gpio(<port>, <val>) -- set port value, True or False, 1 or 0\n" -" pyb.ADC(<port>) -- make an analog port object (port='C0' for example)\n" -" ADC methods: read()\n" -; - -// get some help about available functions -static mp_obj_t pyb_help(void) { - printf("%s", help_text); - return mp_const_none; -} - int main(void) { // TODO disable JTAG @@ -268,9 +240,6 @@ soft_reset: pin_map_init(); - // add some functions to the builtin Python namespace - rt_store_name(MP_QSTR_help, rt_make_function_n(0, pyb_help)); - // we pre-import the pyb module // probably shouldn't do this, so we are compatible with CPython rt_store_name(MP_QSTR_pyb, (mp_obj_t)&pyb_module); diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 59c91942a0..edaee63158 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -19,9 +19,11 @@ #define MICROPY_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ // extra built in names to add to the global namespace +extern const struct _mp_obj_fun_native_t mp_builtin_help_obj; extern const struct _mp_obj_fun_native_t mp_builtin_input_obj; extern const struct _mp_obj_fun_native_t mp_builtin_open_obj; #define MICROPY_EXTRA_BUILTINS \ + { MP_QSTR_help, (mp_obj_t)&mp_builtin_help_obj }, \ { MP_QSTR_input, (mp_obj_t)&mp_builtin_input_obj }, \ { MP_QSTR_open, (mp_obj_t)&mp_builtin_open_obj }, diff --git a/stmhal/pybmodule.c b/stmhal/pybmodule.c index 00a8c321db..fda6b3d0b3 100644 --- a/stmhal/pybmodule.c +++ b/stmhal/pybmodule.c @@ -242,7 +242,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = { #if MICROPY_HW_ENABLE_SERVO { MP_OBJ_NEW_QSTR(MP_QSTR_pwm), (mp_obj_t)&pyb_pwm_set_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_servo), (mp_obj_t)&pyb_servo_set_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_Servo), (mp_obj_t)&pyb_Servo_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_Servo), (mp_obj_t)&pyb_servo_type }, #endif #if MICROPY_HW_HAS_SWITCH @@ -254,13 +254,13 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = { #endif #if MICROPY_HW_HAS_MMA7660 - { MP_OBJ_NEW_QSTR(MP_QSTR_Accel), (mp_obj_t)&pyb_Accel_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_Accel), (mp_obj_t)&pyb_accel_type }, #endif #if 0 { MP_OBJ_NEW_QSTR(MP_QSTR_hid), (mp_obj_t)&pyb_hid_send_report_obj }, #endif - { MP_OBJ_NEW_QSTR(MP_QSTR_Led), (mp_obj_t)&pyb_Led_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_Led), (mp_obj_t)&pyb_led_type }, #if 0 { MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_I2C_obj }, #endif diff --git a/stmhal/servo.c b/stmhal/servo.c index b0e0e8695d..81b290bf52 100644 --- a/stmhal/servo.c +++ b/stmhal/servo.c @@ -148,12 +148,35 @@ STATIC mp_obj_t pyb_pwm_set(mp_obj_t period, mp_obj_t pulse) { MP_DEFINE_CONST_FUN_OBJ_2(pyb_pwm_set_obj, pyb_pwm_set); -STATIC void servo_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { +STATIC void pyb_servo_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { pyb_servo_obj_t *self = self_in; print(env, "<Servo %lu at %lu>", self->servo_id, self->pulse_cur); } -STATIC mp_obj_t servo_obj_angle(uint n_args, 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 + if (!(n_args == 1 && n_kw == 0)) { + nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "Servo accepts 1 argument")); + } + + // get servo number + machine_int_t servo_id = mp_obj_get_int(args[0]) - 1; + + // check servo number + if (!(0 <= servo_id && servo_id < PYB_SERVO_NUM)) { + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id)); + } + + // get and init servo object + pyb_servo_obj_t *s = &pyb_servo_obj[servo_id]; + s->pulse_dest = s->pulse_cur; + s->time_left = 0; + servo_init_channel(s); + + return s; +} + +STATIC mp_obj_t pyb_servo_angle(uint n_args, const mp_obj_t *args) { pyb_servo_obj_t *self = args[0]; if (n_args == 1) { // get angle @@ -180,31 +203,17 @@ STATIC mp_obj_t servo_obj_angle(uint n_args, const mp_obj_t *args) { } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(servo_obj_angle_obj, 1, 3, servo_obj_angle); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_servo_angle_obj, 1, 3, pyb_servo_angle); -STATIC const mp_method_t servo_methods[] = { - { "angle", &servo_obj_angle_obj }, +STATIC const mp_method_t pyb_servo_methods[] = { + { "angle", &pyb_servo_angle_obj }, { NULL, NULL }, }; -STATIC const mp_obj_type_t servo_obj_type = { +const mp_obj_type_t pyb_servo_type = { { &mp_type_type }, .name = MP_QSTR_Servo, - .print = servo_obj_print, - .methods = servo_methods, + .print = pyb_servo_print, + .make_new = pyb_servo_make_new, + .methods = pyb_servo_methods, }; - -STATIC mp_obj_t pyb_Servo(mp_obj_t servo_id_o) { - machine_int_t servo_id = mp_obj_get_int(servo_id_o) - 1; - if (0 <= servo_id && servo_id < PYB_SERVO_NUM) { - pyb_servo_obj_t *s = &pyb_servo_obj[servo_id]; - s->pulse_dest = s->pulse_cur; - s->time_left = 0; - servo_init_channel(s); - return s; - } else { - nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Servo %d does not exist", servo_id)); - } -} - -MP_DEFINE_CONST_FUN_OBJ_1(pyb_Servo_obj, pyb_Servo); diff --git a/stmhal/servo.h b/stmhal/servo.h index 753ca49598..d5fb6a8505 100644 --- a/stmhal/servo.h +++ b/stmhal/servo.h @@ -3,6 +3,7 @@ extern TIM_HandleTypeDef TIM2_Handle; void servo_init(void); void servo_timer_irq_callback(void); +extern const mp_obj_type_t pyb_servo_type; + MP_DECLARE_CONST_FUN_OBJ(pyb_servo_set_obj); MP_DECLARE_CONST_FUN_OBJ(pyb_pwm_set_obj); -MP_DECLARE_CONST_FUN_OBJ(pyb_Servo_obj); |