From f736c0b3596fff218285525d2b79d33267821104 Mon Sep 17 00:00:00 2001
From: Ferdinand Bachmann <theferdi265@gmail.com>
Date: Sat, 31 Aug 2019 00:07:05 +0200
Subject: [PATCH] pycardium/utime: add unix_time and unix_time_ms

---
 pycardium/modules/qstrdefs.h |  2 ++
 pycardium/modules/utime.c    | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h
index 0430d4d7..d4a83022 100644
--- a/pycardium/modules/qstrdefs.h
+++ b/pycardium/modules/qstrdefs.h
@@ -52,6 +52,8 @@ Q(monotonic)
 Q(monotonic_ms)
 Q(time)
 Q(time_ms)
+Q(unix_time)
+Q(unix_time_ms)
 Q(set_time)
 Q(set_unix_time)
 
diff --git a/pycardium/modules/utime.c b/pycardium/modules/utime.c
index 9f71eef5..99bb52f9 100644
--- a/pycardium/modules/utime.c
+++ b/pycardium/modules/utime.c
@@ -51,6 +51,20 @@ static mp_obj_t time_time_ms(void)
 }
 MP_DEFINE_CONST_FUN_OBJ_0(time_time_ms_obj, time_time_ms);
 
+static mp_obj_t time_unix_time(void)
+{
+	mp_int_t seconds = epic_rtc_get_seconds();
+	return mp_obj_new_int(seconds);
+}
+MP_DEFINE_CONST_FUN_OBJ_0(time_unix_time_obj, time_unix_time);
+
+static mp_obj_t time_unix_time_ms(void)
+{
+	uint64_t milliseconds = epic_rtc_get_milliseconds();
+	return mp_obj_new_int_from_ull(milliseconds);
+}
+MP_DEFINE_CONST_FUN_OBJ_0(time_unix_time_ms_obj, time_unix_time_ms);
+
 static mp_obj_t time_monotonic(void)
 {
 	mp_int_t seconds;
@@ -146,6 +160,9 @@ static const mp_rom_map_elem_t time_module_globals_table[] = {
 	{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) },
 	{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) },
 	{ MP_ROM_QSTR(MP_QSTR_time_ms), MP_ROM_PTR(&time_time_ms_obj) },
+	{ MP_ROM_QSTR(MP_QSTR_unix_time), MP_ROM_PTR(&time_unix_time_obj) },
+	{ MP_ROM_QSTR(MP_QSTR_unix_time_ms),
+	  MP_ROM_PTR(&time_unix_time_ms_obj) },
 	{ MP_ROM_QSTR(MP_QSTR_monotonic), MP_ROM_PTR(&time_monotonic_obj) },
 	{ MP_ROM_QSTR(MP_QSTR_monotonic_ms),
 	  MP_ROM_PTR(&time_monotonic_ms_obj) },
-- 
GitLab