Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RP2040: Support for RTC #4110

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down
2 changes: 2 additions & 0 deletions ports/raspberrypi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/ \
Expand Down Expand Up @@ -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 \
Expand Down
81 changes: 81 additions & 0 deletions ports/raspberrypi/common-hal/rtc/RTC.c
Original file line number Diff line number Diff line change
@@ -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"));
}
32 changes: 32 additions & 0 deletions ports/raspberrypi/common-hal/rtc/RTC.h
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions ports/raspberrypi/common-hal/rtc/__init__.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// No RTC module functions
1 change: 0 additions & 1 deletion ports/raspberrypi/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions ports/raspberrypi/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ void reset_port(void) {
reset_spi();
#endif

#if CIRCUITPY_PWMIO
pwmout_reset();
tannewt marked this conversation as resolved.
Show resolved Hide resolved
#endif

#if CIRCUITPY_RP2PIO
reset_rp2pio_statemachine();
#endif

#if CIRCUITPY_PWMIO
pwmout_reset();
#if CIRCUITPY_RTC
rtc_reset();
#endif

reset_all_pins();
Expand Down
1 change: 1 addition & 0 deletions shared-bindings/rtc/RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down