aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Campora2015-05-26 16:50:18 +0200
committerDaniel Campora2015-05-27 09:45:24 +0200
commitfca349344214e1bf7be95b728d64681adf1b4194 (patch)
treea2b93a4f82347da05b45f1efd394f1d2a6613ae2
parent5a0c5f8fea921bdc58c895028c032a3c4d9ebcbb (diff)
cc3200: Add make_new method to the RTC, like in stmhal.
-rw-r--r--cc3200/mods/modpyb.c2
-rw-r--r--cc3200/mods/pybrtc.c16
-rw-r--r--cc3200/mods/pybrtc.h2
3 files changed, 15 insertions, 5 deletions
diff --git a/cc3200/mods/modpyb.c b/cc3200/mods/modpyb.c
index 44fea54b5..05645a47a 100644
--- a/cc3200/mods/modpyb.c
+++ b/cc3200/mods/modpyb.c
@@ -266,7 +266,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
#endif
#if MICROPY_HW_ENABLE_RTC
- { MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pin_type },
diff --git a/cc3200/mods/pybrtc.c b/cc3200/mods/pybrtc.c
index 7a40deb85..1cd0f9b89 100644
--- a/cc3200/mods/pybrtc.c
+++ b/cc3200/mods/pybrtc.c
@@ -71,6 +71,7 @@ typedef struct {
******************************************************************************/
STATIC pybrtc_data_t pybrtc_data;
STATIC const mp_cb_methods_t pybrtc_cb_methods;
+STATIC const mp_obj_base_t pyb_rtc_obj = {&pyb_rtc_type};
/******************************************************************************
DECLARE PUBLIC FUNCTIONS
@@ -123,6 +124,16 @@ STATIC void pyb_rtc_callback_enable (mp_obj_t self_in) {
/******************************************************************************/
// Micro Python bindings
+/// \classmethod \constructor()
+/// Create an RTC object.
+STATIC mp_obj_t pyb_rtc_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_rtc_obj;
+}
+
/// \method datetime([datetimetuple])
/// Get or set the date and time of the RTC.
///
@@ -235,9 +246,10 @@ STATIC const mp_map_elem_t pyb_rtc_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
-STATIC const mp_obj_type_t pyb_rtc_type = {
+const mp_obj_type_t pyb_rtc_type = {
{ &mp_type_type },
.name = MP_QSTR_RTC,
+ .make_new = pyb_rtc_make_new,
.locals_dict = (mp_obj_t)&pyb_rtc_locals_dict,
};
@@ -246,5 +258,3 @@ STATIC const mp_cb_methods_t pybrtc_cb_methods = {
.enable = pyb_rtc_callback_enable,
.disable = pyb_rtc_callback_disable,
};
-
-const mp_obj_base_t pyb_rtc_obj = {&pyb_rtc_type};
diff --git a/cc3200/mods/pybrtc.h b/cc3200/mods/pybrtc.h
index 0c7a6f859..4d76fae77 100644
--- a/cc3200/mods/pybrtc.h
+++ b/cc3200/mods/pybrtc.h
@@ -31,7 +31,7 @@
#define RTC_U16MS_CYCLES(msec) ((msec * 1024) / 1000)
#define RTC_CYCLES_U16MS(cycles) ((cycles * 1000) / 1024)
-extern const mp_obj_base_t pyb_rtc_obj;
+extern const mp_obj_type_t pyb_rtc_type;
void pybrtc_init(void);
void pyb_rtc_callback_disable (mp_obj_t self_in);