From 6148f8b7d266a61768a15f0b27d841c12346d9c0 Mon Sep 17 00:00:00 2001 From: Daniel Campora Date: Tue, 9 Jun 2015 10:46:50 +0200 Subject: [PATCH] cc3200: Add contructor to the HeartBeat class. --- cc3200/misc/mperror.c | 18 ++++++++++++++++-- cc3200/misc/mperror.h | 2 +- cc3200/mods/modpyb.c | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cc3200/misc/mperror.c b/cc3200/misc/mperror.c index ca729b2a23..46520361f2 100644 --- a/cc3200/misc/mperror.c +++ b/cc3200/misc/mperror.c @@ -32,6 +32,7 @@ #include "py/mpconfig.h" #include MICROPY_HAL_H #include "py/obj.h" +#include "py/runtime.h" #include "hw_ints.h" #include "hw_types.h" #include "hw_gpio.h" @@ -63,6 +64,8 @@ /****************************************************************************** DECLARE PRIVATE DATA ******************************************************************************/ +STATIC const mp_obj_base_t pyb_heartbeat_obj = {&pyb_heartbeat_type}; + struct mperror_heart_beat { uint32_t off_time; uint32_t on_time; @@ -198,6 +201,17 @@ void nlr_jump_fail(void *val) { /******************************************************************************/ // Micro Python bindings +/// \classmethod \constructor() +/// +/// Return the heart beat object +STATIC mp_obj_t pyb_heartbeat_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { + // check arguments + mp_arg_check_num(n_args, n_kw, 0, 0, false); + + // return constant object + return (mp_obj_t)&pyb_heartbeat_obj; +} + /// \function enable() /// Enables the heartbeat signal STATIC mp_obj_t pyb_enable_heartbeat(mp_obj_t self) { @@ -220,11 +234,11 @@ STATIC const mp_map_elem_t pyb_heartbeat_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(pyb_heartbeat_locals_dict, pyb_heartbeat_locals_dict_table); -static const mp_obj_type_t pyb_heartbeat_type = { +const mp_obj_type_t pyb_heartbeat_type = { { &mp_type_type }, .name = MP_QSTR_HeartBeat, + .make_new = pyb_heartbeat_make_new, .locals_dict = (mp_obj_t)&pyb_heartbeat_locals_dict, }; -const mp_obj_base_t pyb_heartbeat_obj = {&pyb_heartbeat_type}; #endif diff --git a/cc3200/misc/mperror.h b/cc3200/misc/mperror.h index 7f0a634d80..70a69c5288 100644 --- a/cc3200/misc/mperror.h +++ b/cc3200/misc/mperror.h @@ -29,7 +29,7 @@ #define MPERROR_H_ #ifndef BOOTLOADER -extern const mp_obj_base_t pyb_heartbeat_obj; +extern const mp_obj_type_t pyb_heartbeat_type; #endif extern void NORETURN __fatal_error(const char *msg); diff --git a/cc3200/mods/modpyb.c b/cc3200/mods/modpyb.c index 5f38bc69cf..1e8dc1f0ee 100644 --- a/cc3200/mods/modpyb.c +++ b/cc3200/mods/modpyb.c @@ -287,7 +287,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type }, { MP_OBJ_NEW_QSTR(MP_QSTR_Sleep), (mp_obj_t)&pyb_sleep_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_type }, #if MICROPY_HW_HAS_SDCARD { MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },