Skip to content

Commit 8789a2c

Browse files
authored
Merge pull request #4110 from microDev1/rtc-rp
RP2040: Support for RTC
2 parents ced3dc7 + ec03267 commit 8789a2c

File tree

8 files changed

+124
-3
lines changed

8 files changed

+124
-3
lines changed

locale/circuitpython.pot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,7 @@ msgstr ""
18041804

18051805
#: ports/cxd56/common-hal/rtc/RTC.c ports/esp32s2/common-hal/rtc/RTC.c
18061806
#: ports/mimxrt10xx/common-hal/rtc/RTC.c ports/nrf/common-hal/rtc/RTC.c
1807+
#: ports/raspberrypi/common-hal/rtc/RTC.c
18071808
msgid "RTC calibration is not supported on this board"
18081809
msgstr ""
18091810

ports/raspberrypi/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ INC += -I. \
8484
-isystem sdk/src/rp2_common/hardware_pio/include/ \
8585
-isystem sdk/src/rp2_common/hardware_pll/include/ \
8686
-isystem sdk/src/rp2_common/hardware_resets/include/ \
87+
-isystem sdk/src/rp2_common/hardware_rtc/include/ \
8788
-isystem sdk/src/rp2_common/hardware_spi/include/ \
8889
-isystem sdk/src/rp2_common/hardware_sync/include/ \
8990
-isystem sdk/src/rp2_common/hardware_timer/include/ \
@@ -166,6 +167,7 @@ SRC_SDK := \
166167
src/rp2_common/hardware_irq/irq.c \
167168
src/rp2_common/hardware_pio/pio.c \
168169
src/rp2_common/hardware_pll/pll.c \
170+
src/rp2_common/hardware_rtc/rtc.c \
169171
src/rp2_common/hardware_spi/spi.c \
170172
src/rp2_common/hardware_sync/sync.c \
171173
src/rp2_common/hardware_timer/timer.c \
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright 2020 microDev
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
#include "shared-bindings/rtc/RTC.h"
27+
28+
#include <sys/time.h>
29+
30+
#include "py/runtime.h"
31+
#include "src/rp2_common/hardware_rtc/include/hardware/rtc.h"
32+
33+
void common_hal_rtc_init(void) {
34+
rtc_init();
35+
}
36+
37+
void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
38+
datetime_t t;
39+
rtc_get_datetime(&t);
40+
41+
tm->tm_year = t.year;
42+
tm->tm_mon = t.month;
43+
tm->tm_mday = t.day;
44+
tm->tm_wday = t.dotw;
45+
tm->tm_hour = t.hour;
46+
tm->tm_min = t.min;
47+
tm->tm_sec = t.sec;
48+
49+
if (tm->tm_wday == 0) {
50+
tm->tm_wday = 6;
51+
} else {
52+
tm->tm_wday-=1;
53+
}
54+
}
55+
56+
void common_hal_rtc_set_time(timeutils_struct_time_t *tm) {
57+
if (tm->tm_wday == 6) {
58+
tm->tm_wday = 0;
59+
} else {
60+
tm->tm_wday+=1;
61+
}
62+
63+
datetime_t t = {
64+
.year = tm->tm_year,
65+
.month = tm->tm_mon,
66+
.day = tm->tm_mday,
67+
.dotw = tm->tm_wday,
68+
.hour = tm->tm_hour,
69+
.min = tm->tm_min,
70+
.sec = tm->tm_sec
71+
};
72+
rtc_set_datetime(&t);
73+
}
74+
75+
int common_hal_rtc_get_calibration(void) {
76+
return 0;
77+
}
78+
79+
void common_hal_rtc_set_calibration(int calibration) {
80+
mp_raise_NotImplementedError(translate("RTC calibration is not supported on this board"));
81+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 microDev
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_RTC_RTC_H
28+
#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_RTC_RTC_H
29+
30+
extern void common_hal_rtc_init(void);
31+
32+
#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_RTC_RTC_H
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// No RTC module functions

ports/raspberrypi/mpconfigport.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ CIRCUITPY_I2CPERIPHERAL = 0
3535
CIRCUITPY_NVM = 0
3636
CIRCUITPY_PULSEIO = 0 # Use PIO interally
3737
CIRCUITPY_ROTARYIO = 0 # Use PIO interally
38-
CIRCUITPY_RTC = 0
3938
CIRCUITPY_WATCHDOG = 1
4039

4140
# Things that are unsupported by the hardware.

ports/raspberrypi/supervisor/port.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,16 @@ void reset_port(void) {
9494
reset_spi();
9595
#endif
9696

97+
#if CIRCUITPY_PWMIO
98+
pwmout_reset();
99+
#endif
100+
97101
#if CIRCUITPY_RP2PIO
98102
reset_rp2pio_statemachine();
99103
#endif
100104

101-
#if CIRCUITPY_PWMIO
102-
pwmout_reset();
105+
#if CIRCUITPY_RTC
106+
rtc_reset();
103107
#endif
104108

105109
reset_all_pins();

shared-bindings/rtc/RTC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <stdint.h>
3131
#include <stdbool.h>
3232

33+
#include "py/obj.h"
3334
#include "lib/timeutils/timeutils.h"
3435

3536
extern void common_hal_rtc_get_time(timeutils_struct_time_t *tm);

0 commit comments

Comments
 (0)