8000 esp32/machine_rtc: machine.RTC().usermem() returns bytearray · micropython/micropython@5319c12 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5319c12

Browse files
committed
esp32/machine_rtc: machine.RTC().usermem() returns bytearray
1 parent 321d189 commit 5319c12

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ports/esp32/machine_rtc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ STATIC mp_obj_t machine_rtc_init(mp_obj_t self_in, mp_obj_t date) {
142142
STATIC MP_DEFINE_CONST_FUN_OBJ_2(machine_rtc_init_obj, machine_rtc_init);
143143

144144
#if MICROPY_HW_RTC_USER_MEM_MAX > 0
145+
/*
146+
* both RTC().usermem() and RTC().memory() refer to the same area in memory.
147+
* RTC().memory() is here for backward compatibility.
148+
*/
149+
150+
// returns a bytearray referencing the whole user memory.
151+
STATIC mp_obj_t machine_rtc_usermem(mp_obj_t self_in) {
152+
// mp_obj_t *self = MP_OBJ_TO_PTR(self_in);
153+
return mp_obj_new_bytearray_by_ref(MICROPY_HW_RTC_USER_MEM_MAX, (void *)rtc_user_mem_data);
154+
}
155+
MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_usermem_obj, machine_rtc_usermem);
156+
157+
145158
STATIC mp_obj_t machine_rtc_memory(mp_uint_t n_args, const mp_obj_t *args) {
146159
if (n_args == 1) {
147160
// read RTC memory
@@ -169,6 +182,7 @@ STATIC const mp_rom_map_elem_t machine_rtc_locals_dict_table[] = {
169182
{ MP_ROM_QSTR(MP_QSTR_datetime), MP_ROM_PTR(&machine_rtc_datetime_obj) },
170183
#if MICROPY_HW_RTC_USER_MEM_MAX > 0
171184
{ MP_ROM_QSTR(MP_QSTR_memory), MP_ROM_PTR(&machine_rtc_memory_obj) },
185+
{ MP_ROM_QSTR(MP_QSTR_usermem), MP_ROM_PTR(&machine_rtc_usermem_obj) },
172186
#endif
173187
};
174188
STATIC MP_DEFINE_CONST_DICT(machine_rtc_locals_dict, machine_rtc_locals_dict_table);

0 commit comments

Comments
 (0)
0