diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2021-02-01 19:47:44 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-01 19:47:44 -0800 |
| commit | 8789a2c8a9c73b9cd22140307160d5a87a65adc6 (patch) | |
| tree | dd31d334e0de07d6cfd0446c2701e3ab77739744 /ports | |
| parent | ced3dc70fff6049702a409d359850ecd89672192 (diff) | |
| parent | ec03267035d84c0cb0ba7ed645a487b059401946 (diff) | |
Merge pull request #4110 from microDev1/rtc-rp
RP2040: Support for RTC
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/raspberrypi/Makefile | 2 | ||||
| -rw-r--r-- | ports/raspberrypi/common-hal/rtc/RTC.c | 81 | ||||
| -rw-r--r-- | ports/raspberrypi/common-hal/rtc/RTC.h | 32 | ||||
| -rw-r--r-- | ports/raspberrypi/common-hal/rtc/__init__.c | 1 | ||||
| -rw-r--r-- | ports/raspberrypi/mpconfigport.mk | 1 | ||||
| -rw-r--r-- | ports/raspberrypi/supervisor/port.c | 8 |
6 files changed, 122 insertions, 3 deletions
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(); |
