Skip to content

Commit 6148f8b

Browse files
author
Daniel Campora
committed
cc3200: Add contructor to the HeartBeat class.
1 parent 7628546 commit 6148f8b

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

cc3200/misc/mperror.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "py/mpconfig.h"
3333
#include MICROPY_HAL_H
3434
#include "py/obj.h"
35+
#include "py/runtime.h"
3536
#include "hw_ints.h"
3637
#include "hw_types.h"
3738
#include "hw_gpio.h"
@@ -63,6 +64,8 @@
6364
/******************************************************************************
6465
DECLARE PRIVATE DATA
6566
******************************************************************************/
67+
STATIC const mp_obj_base_t pyb_heartbeat_obj = {&pyb_heartbeat_type};
68+
6669
struct mperror_heart_beat {
6770
uint32_t off_time;
6871
uint32_t on_time;
@@ -198,6 +201,17 @@ void nlr_jump_fail(void *val) {
198201
/******************************************************************************/
199202
// Micro Python bindings
200203

204+
/// \classmethod \constructor()
205+
///
206+
/// Return the heart beat object
207+
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) {
208+
// check arguments
209+
mp_arg_check_num(n_args, n_kw, 0, 0, false);
210+
211+
// return constant object
212+
return (mp_obj_t)&pyb_heartbeat_obj;
213+
}
214+
201215
/// \function enable()
202216
/// Enables the heartbeat signal
203217
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[] = {
220234
};
221235
STATIC MP_DEFINE_CONST_DICT(pyb_heartbeat_locals_dict, pyb_heartbeat_locals_dict_table);
222236

223-
static const mp_obj_type_t pyb_heartbeat_type = {
237+
const mp_obj_type_t pyb_heartbeat_type = {
224238
{ &mp_type_type },
225239
.name = MP_QSTR_HeartBeat,
240+
.make_new = pyb_heartbeat_make_new,
226241
.locals_dict = (mp_obj_t)&pyb_heartbeat_locals_dict,
227242
};
228243

229-
const mp_obj_base_t pyb_heartbeat_obj = {&pyb_heartbeat_type};
230244
#endif

cc3200/misc/mperror.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define MPERROR_H_
3030

3131
#ifndef BOOTLOADER
32-
extern const mp_obj_base_t pyb_heartbeat_obj;
32+
extern const mp_obj_type_t pyb_heartbeat_type;
3333
#endif
3434

3535
extern void NORETURN __fatal_error(const char *msg);

cc3200/mods/modpyb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
287287
{ MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
288288
{ MP_OBJ_NEW_QSTR(MP_QSTR_WDT), (mp_obj_t)&pyb_wdt_type },
289289
{ MP_OBJ_NEW_QSTR(MP_QSTR_Sleep), (mp_obj_t)&pyb_sleep_obj },
290-
{ MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_obj },
290+
{ MP_OBJ_NEW_QSTR(MP_QSTR_HeartBeat), (mp_obj_t)&pyb_heartbeat_type },
291291

292292
#if MICROPY_HW_HAS_SDCARD
293293
{ MP_OBJ_NEW_QSTR(MP_QSTR_SD), (mp_obj_t)&pyb_sd_type },

0 commit comments

Comments
 (0)