Skip to content

Commit

Permalink
c_sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dhylands committed Dec 14, 2016
1 parent ee7ad7e commit 15ef679
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions stmhal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ SRC_C = \
can.c \
usb.c \
wdt.c \
c_sample.c \
gccollect.c \
pybstdio.c \
help.c \
Expand Down
30 changes: 30 additions & 0 deletions stmhal/c_sample.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "py/nlr.h"
#include "py/obj.h"
#include "py/runtime.h"
#include "py/binary.h"
#include "portmodules.h"

STATIC mp_obj_t c_sample_set_callback(mp_obj_t callback_obj) {
MP_STATE_PORT(c_sample_callback_obj) = callback_obj;
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(c_sample_set_callback_obj, c_sample_set_callback);

STATIC mp_obj_t c_sample_call_callback(void) {
return mp_call_function_0(MP_STATE_PORT(c_sample_callback_obj));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(c_sample_call_callback_obj, c_sample_call_callback);

STATIC const mp_map_elem_t c_sample_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_c_sample) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_callback), (mp_obj_t)&c_sample_set_callback_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_call_callback), (mp_obj_t)&c_sample_call_callback_obj },
};

STATIC MP_DEFINE_CONST_DICT(mp_module_c_sample_globals, c_sample_globals_table);

const mp_obj_module_t mp_module_c_sample = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t*)&mp_module_c_sample_globals,
};

5 changes: 5 additions & 0 deletions stmhal/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ extern const struct _mp_obj_module_t mp_module_uos;
extern const struct _mp_obj_module_t mp_module_utime;
extern const struct _mp_obj_module_t mp_module_usocket;
extern const struct _mp_obj_module_t mp_module_network;
extern const struct _mp_obj_module_t mp_module_c_sample;

#if MICROPY_PY_USOCKET
#define SOCKET_BUILTIN_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_usocket },
Expand All @@ -169,6 +170,7 @@ extern const struct _mp_obj_module_t mp_module_network;
{ MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \
SOCKET_BUILTIN_MODULE \
NETWORK_BUILTIN_MODULE \
{ MP_OBJ_NEW_QSTR(MP_QSTR_c_sample), (mp_obj_t)&mp_module_c_sample }, \

#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
{ MP_OBJ_NEW_QSTR(MP_QSTR_binascii), (mp_obj_t)&mp_module_ubinascii }, \
Expand Down Expand Up @@ -231,6 +233,9 @@ extern const struct _mp_obj_module_t mp_module_network;
\
/* list of registered NICs */ \
mp_obj_list_t mod_network_nic_list; \
\
/* C Sample callback obj */ \
mp_obj_t c_sample_callback_obj; \

// type definitions for the specific machine

Expand Down

0 comments on commit 15ef679

Please sign in to comment.