Skip to content

Commit fca3493

Browse files
author
Daniel Campora
committed
cc3200: Add make_new method to the RTC, like in stmhal.
1 parent 5a0c5f8 commit fca3493

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

cc3200/mods/modpyb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
266266
#endif
267267

268268
#if MICROPY_HW_ENABLE_RTC
269-
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_obj },
269+
{ MP_OBJ_NEW_QSTR(MP_QSTR_RTC), (mp_obj_t)&pyb_rtc_type },
270270
#endif
271271

272272
{ MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pin_type },

cc3200/mods/pybrtc.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ typedef struct {
7171
******************************************************************************/
7272
STATIC pybrtc_data_t pybrtc_data;
7373
STATIC const mp_cb_methods_t pybrtc_cb_methods;
74+
STATIC const mp_obj_base_t pyb_rtc_obj = {&pyb_rtc_type};
7475

7576
/******************************************************************************
7677
DECLARE PUBLIC FUNCTIONS
@@ -123,6 +124,16 @@ STATIC void pyb_rtc_callback_enable (mp_obj_t self_in) {
123124
/******************************************************************************/
124125
// Micro Python bindings
125126

127+
/// \classmethod \constructor()
128+
/// Create an RTC object.
129+
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) {
130+
// check arguments
131+
mp_arg_check_num(n_args, n_kw, 0, 0, false);
132+
133+
// return constant object
134+
return (mp_obj_t)&pyb_rtc_obj;
135+
}
136+
126137
/// \method datetime([datetimetuple])
127138
/// Get or set the date and time of the RTC.
128139
///
@@ -235,9 +246,10 @@ STATIC const mp_map_elem_t pyb_rtc_locals_dict_table[] = {
235246
};
236247
STATIC MP_DEFINE_CONST_DICT(pyb_rtc_locals_dict, pyb_rtc_locals_dict_table);
237248

238-
STATIC const mp_obj_type_t pyb_rtc_type = {
249+
const mp_obj_type_t pyb_rtc_type = {
239250
{ &mp_type_type },
240251
.name = MP_QSTR_RTC,
252+
.make_new = pyb_rtc_make_new,
241253
.locals_dict = (mp_obj_t)&pyb_rtc_locals_dict,
242254
};
243255

@@ -246,5 +258,3 @@ STATIC const mp_cb_methods_t pybrtc_cb_methods = {
246258
.enable = pyb_rtc_callback_enable,
247259
.disable = pyb_rtc_callback_disable,
248260
};
249-
250-
const mp_obj_base_t pyb_rtc_obj = {&pyb_rtc_type};

cc3200/mods/pybrtc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define RTC_U16MS_CYCLES(msec) ((msec * 1024) / 1000)
3232
#define RTC_CYCLES_U16MS(cycles) ((cycles * 1000) / 1024)
3333

34-
extern const mp_obj_base_t pyb_rtc_obj;
34+
extern const mp_obj_type_t pyb_rtc_type;
3535

3636
void pybrtc_init(void);
3737
void pyb_rtc_callback_disable (mp_obj_t self_in);

0 commit comments

Comments
 (0)