summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormicroDev <70126934+microDev1@users.noreply.github.com>2021-02-02 00:00:00 +0530
committermicroDev <70126934+microDev1@users.noreply.github.com>2021-02-02 00:00:00 +0530
commitec03267035d84c0cb0ba7ed645a487b059401946 (patch)
tree58f7ce449c25d41a1594e51ffa7bdc1c6c1eef5a
parent0c0b517112100c1ec90ed66fba8bc315bc5440d0 (diff)
rtc implementation for rp2040
-rw-r--r--locale/circuitpython.pot1
-rw-r--r--ports/raspberrypi/Makefile2
-rw-r--r--ports/raspberrypi/common-hal/rtc/RTC.c81
-rw-r--r--ports/raspberrypi/common-hal/rtc/RTC.h32
-rw-r--r--ports/raspberrypi/common-hal/rtc/__init__.c1
-rw-r--r--ports/raspberrypi/mpconfigport.mk1
-rw-r--r--ports/raspberrypi/supervisor/port.c8
-rw-r--r--shared-bindings/rtc/RTC.h1
8 files changed, 124 insertions, 3 deletions
diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot
index 8443fb85b..a7e2fbf44 100644
--- a/locale/circuitpython.pot
+++ b/locale/circuitpython.pot
@@ -1800,6 +1800,7 @@ msgstr ""
#: ports/cxd56/common-hal/rtc/RTC.c ports/esp32s2/common-hal/rtc/RTC.c
#: ports/mimxrt10xx/common-hal/rtc/RTC.c ports/nrf/common-hal/rtc/RTC.c
+#: ports/raspberrypi/common-hal/rtc/RTC.c
msgid "RTC calibration is not supported on this board"
msgstr ""
diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile
index a604acb47..eab7deee6 100644
--- a/ports/raspberrypi/Makefile
+++ b/ports/raspberrypi/Makefile
@@ -84,6 +84,7 @@ INC += -I. \
-isystem sdk/src/rp2_common/hardware_pio/include/ \
-isystem sdk/src/rp2_common/hardware_pll/include/ \
-isystem sdk/src/rp2_common/hardware_resets/include/ \
+ -isystem sdk/src/rp2_common/hardware_rtc/include/ \
-isystem sdk/src/rp2_common/hardware_spi/include/ \
-isystem sdk/src/rp2_common/hardware_sync/include/ \
-isystem sdk/src/rp2_common/hardware_timer/include/ \
@@ -166,6 +167,7 @@ SRC_SDK := \
src/rp2_common/hardware_irq/irq.c \
src/rp2_common/hardware_pio/pio.c \
src/rp2_common/hardware_pll/pll.c \
+ src/rp2_common/hardware_rtc/rtc.c \
src/rp2_common/hardware_spi/spi.c \
src/rp2_common/hardware_sync/sync.c \
src/rp2_common/hardware_timer/timer.c \
diff --git a/ports/raspberrypi/common-hal/rtc/RTC.c b/ports/raspberrypi/common-hal/rtc/RTC.c
new file mode 100644
index 000000000..89c23fc19
--- /dev/null
+++ b/ports/raspberrypi/common-hal/rtc/RTC.c
@@ -0,0 +1,81 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright 2020 microDev
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "shared-bindings/rtc/RTC.h"
+
+#include <sys/time.h>
+
+#include "py/runtime.h"
+#include "src/rp2_common/hardware_rtc/include/hardware/rtc.h"
+
+void common_hal_rtc_init(void) {
+ rtc_init();
+}
+
+void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
+ datetime_t t;
+ rtc_get_datetime(&t);
+
+ tm->tm_year = t.year;
+ tm->tm_mon = t.month;
+ tm->tm_mday = t.day;
+ tm->tm_wday = t.dotw;
+ tm->tm_hour = t.hour;
+ tm->tm_min = t.min;
+ tm->tm_sec = t.sec;
+
+ if (tm->tm_wday == 0) {
+ tm->tm_wday = 6;
+ } else {
+ tm->tm_wday-=1;
+ }
+}
+
+void common_hal_rtc_set_time(timeutils_struct_time_t *tm) {
+ if (tm->tm_wday == 6) {
+ tm->tm_wday = 0;
+ } else {
+ tm->tm_wday+=1;
+ }
+
+ datetime_t t = {
+ .year = tm->tm_year,
+ .month = tm->tm_mon,
+ .day = tm->tm_mday,
+ .dotw = tm->tm_wday,
+ .hour = tm->tm_hour,
+ .min = tm->tm_min,
+ .sec = tm->tm_sec
+ };
+ rtc_set_datetime(&t);
+}
+
+int common_hal_rtc_get_calibration(void) {
+ return 0;
+}
+
+void common_hal_rtc_set_calibration(int calibration) {
+ mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board"));
+}
diff --git a/ports/raspberrypi/common-hal/rtc/RTC.h b/ports/raspberrypi/common-hal/rtc/RTC.h
new file mode 100644
index 000000000..426a4ec7a
--- /dev/null
+++ b/ports/raspberrypi/common-hal/rtc/RTC.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_RTC_RTC_H
+#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_RTC_RTC_H
+
+extern void common_hal_rtc_init(void);
+
+#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_RTC_RTC_H
diff --git a/ports/raspberrypi/common-hal/rtc/__init__.c b/ports/raspberrypi/common-hal/rtc/__init__.c
new file mode 100644
index 000000000..f5e6b6bdd
--- /dev/null
+++ b/ports/raspberrypi/common-hal/rtc/__init__.c
@@ -0,0 +1 @@
+// No RTC module functions
diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk
index 5c930d7cc..d0a21a7b4 100644
--- a/ports/raspberrypi/mpconfigport.mk
+++ b/ports/raspberrypi/mpconfigport.mk
@@ -35,7 +35,6 @@ CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NVM = 0
CIRCUITPY_PULSEIO = 0 # Use PIO interally
CIRCUITPY_ROTARYIO = 0 # Use PIO interally
-CIRCUITPY_RTC = 0
CIRCUITPY_WATCHDOG = 1
# Things that are unsupported by the hardware.
diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c
index b2f73c7b4..b14f5173d 100644
--- a/ports/raspberrypi/supervisor/port.c
+++ b/ports/raspberrypi/supervisor/port.c
@@ -94,12 +94,16 @@ void reset_port(void) {
reset_spi();
#endif
+ #if CIRCUITPY_PWMIO
+ pwmout_reset();
+ #endif
+
#if CIRCUITPY_RP2PIO
reset_rp2pio_statemachine();
#endif
- #if CIRCUITPY_PWMIO
- pwmout_reset();
+ #if CIRCUITPY_RTC
+ rtc_reset();
#endif
reset_all_pins();
diff --git a/shared-bindings/rtc/RTC.h b/shared-bindings/rtc/RTC.h
index 76510bd72..02bf54f50 100644
--- a/shared-bindings/rtc/RTC.h
+++ b/shared-bindings/rtc/RTC.h
@@ -30,6 +30,7 @@
#include <stdint.h>
#include <stdbool.h>
+#include "py/obj.h"
#include "lib/timeutils/timeutils.h"
extern void common_hal_rtc_get_time(timeutils_struct_time_t *tm);