rtc implementation for rp2040

This commit is contained in:
microDev 2021-02-02 00:00:00 +05:30
parent 0c0b517112
commit ec03267035
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
8 changed files with 124 additions and 3 deletions

View File

@ -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 ""

View File

@ -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 \

View File

@ -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"));
}

View File

@ -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

View File

@ -0,0 +1 @@
// No RTC module functions

View File

@ -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.

View File

@ -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();

View File

@ -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);