Skip to content

Commit f09b42c

Browse files
authored
Merge pull request #10592 from PaggieZ/ports/analog/add-rtc
Add RTC module to ports/analog for MAX32690_apard
2 parents def1107 + 57b25b5 commit f09b42c

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

ports/analog/common-hal/rtc/RTC.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2019 Nick Moore for Adafruit Industries
4+
// SPDX-FileCopyrightText: Copyright (c) 2019 Artur Pacholec
5+
// SPDX-FileCopyrightText: Copyright (c) 2025 Peggy Zhu, Analog Devices, Inc.
6+
//
7+
// SPDX-License-Identifier: MIT
8+
9+
#include <stdlib.h>
10+
11+
#include "py/obj.h"
12+
#include "py/runtime.h"
13+
#include "shared/timeutils/timeutils.h"
14+
#include "supervisor/port.h"
15+
16+
// This is the time in seconds since 2000 that the RTC was started.
17+
// TODO: Change the offset to ticks so that it can be a subsecond adjustment.
18+
static uint32_t rtc_offset = 0;
19+
20+
void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
21+
uint64_t ticks_s = port_get_raw_ticks(NULL) / 1024;
22+
timeutils_seconds_since_2000_to_struct_time(rtc_offset + ticks_s, tm);
23+
}
24+
25+
void common_hal_rtc_set_time(timeutils_struct_time_t *tm) {
26+
uint64_t ticks_s = port_get_raw_ticks(NULL) / 1024;
27+
uint32_t epoch_s = timeutils_seconds_since_2000(
28+
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec
29+
);
30+
rtc_offset = epoch_s - ticks_s;
31+
}
32+
33+
// the calibration function will be implemented in near future
34+
// the RTC oscillator on my MAX32690-APARD is only off by 0.001 second
35+
// the inaccuracy is still tolerable
36+
int common_hal_rtc_get_calibration(void) {
37+
return 0;
38+
}
39+
40+
void common_hal_rtc_set_calibration(int calibration) {
41+
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_calibration);
42+
}

ports/analog/common-hal/rtc/RTC.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2018 Noralf Trønnes
4+
// SPDX-FileCopyrightText: Copyright (c) 2019 Artur Pacholec
5+
// SPDX-FileCopyrightText: Copyright (c) 2025 Peggy Zhu, Analog Devices, Inc.
6+
//
7+
// SPDX-License-Identifier: MIT
8+
9+
#pragma once
10+
11+
extern void rtc_reset(void);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Adafruit Industries LLC
4+
// SPDX-FileCopyrightText: Copyright (c) 2025 Peggy Zhu, Analog Devices, Inc.
5+
//
6+
// SPDX-License-Identifier: MIT

ports/analog/mpconfigport.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ INTERNAL_FLASH_FILESYSTEM = 1
2424

2525
# Plan to implement
2626
CIRCUITPY_BUSIO ?= 0
27-
CIRCUITPY_RTC ?= 0
27+
CIRCUITPY_RTC ?= 1
2828

2929
# Other modules (may or may not implement):
3030
CIRCUITPY_ANALOGIO ?= 0

0 commit comments

Comments
 (0)