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

drivers: rtc: rpi_pico: Add support for the Raspberry Pi Pico RTC #64939

Merged
merged 3 commits into from
Mar 6, 2024
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
6 changes: 6 additions & 0 deletions boards/raspberrypi/rpi_pico/rpi_pico-common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
};

aliases {
rtc = &rtc;
watchdog0 = &wdt0;
};

Expand Down Expand Up @@ -133,6 +134,11 @@
status = "okay";
};

&rtc {
clocks = <&clocks RPI_PICO_CLKID_CLK_RTC>;
status = "okay";
};

&adc {
status = "okay";
pinctrl-0 = <&adc_default>;
Expand Down
3 changes: 3 additions & 0 deletions drivers/rtc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/drivers/rtc.h)

zephyr_library()

zephyr_library_sources(rtc_utils.c)

zephyr_library_sources_ifdef(CONFIG_RTC_AM1805 rtc_am1805.c)
zephyr_library_sources_ifdef(CONFIG_RTC_DS1307 rtc_ds1307.c)
zephyr_library_sources_ifdef(CONFIG_USERSPACE rtc_handlers.c)
Expand All @@ -17,3 +19,4 @@ zephyr_library_sources_ifdef(CONFIG_RTC_SHELL rtc_shell.c)
zephyr_library_sources_ifdef(CONFIG_RTC_FAKE rtc_fake.c)
zephyr_library_sources_ifdef(CONFIG_RTC_SMARTBOND rtc_smartbond.c)
zephyr_library_sources_ifdef(CONFIG_RTC_ATMEL_SAM rtc_sam.c)
zephyr_library_sources_ifdef(CONFIG_RTC_RPI_PICO rtc_rpi_pico.c)
5 changes: 3 additions & 2 deletions drivers/rtc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ source "drivers/rtc/Kconfig.am1805"
source "drivers/rtc/Kconfig.ds1307"
source "drivers/rtc/Kconfig.emul"
source "drivers/rtc/Kconfig.fake"
source "drivers/rtc/Kconfig.mc146818"
source "drivers/rtc/Kconfig.pcf8523"
source "drivers/rtc/Kconfig.pcf8563"
source "drivers/rtc/Kconfig.mc146818"
source "drivers/rtc/Kconfig.rpi_pico"
source "drivers/rtc/Kconfig.sam"
source "drivers/rtc/Kconfig.stm32"
source "drivers/rtc/Kconfig.smartbond"
source "drivers/rtc/Kconfig.stm32"

endif # RTC
9 changes: 9 additions & 0 deletions drivers/rtc/Kconfig.rpi_pico
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023 Andrew Featherstone
# SPDX-License-Identifier: Apache-2.0

config RTC_RPI_PICO
bool "Raspberry Pi Pico RTC driver"
default y
depends on DT_HAS_RASPBERRYPI_PICO_RTC_ENABLED
select PICOSDK_USE_RTC
depends on RESET
41 changes: 3 additions & 38 deletions drivers/rtc/rtc_emul.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <zephyr/device.h>
#include <zephyr/drivers/rtc.h>

#include "rtc_utils.h"

struct rtc_emul_data;

struct rtc_emul_work_delayable {
Expand Down Expand Up @@ -67,43 +69,6 @@ static bool rtc_emul_is_leap_year(struct rtc_time *datetime)
return false;
}

#ifdef CONFIG_RTC_ALARM
static bool rtc_emul_validate_alarm_time(const struct rtc_time *timeptr, uint32_t mask)
{
if ((mask & RTC_ALARM_TIME_MASK_SECOND) &&
(timeptr->tm_sec < 0 || timeptr->tm_sec > 59)) {
return false;
}

if ((mask & RTC_ALARM_TIME_MASK_MINUTE) &&
(timeptr->tm_min < 0 || timeptr->tm_min > 59)) {
return false;
}

if ((mask & RTC_ALARM_TIME_MASK_HOUR) &&
(timeptr->tm_hour < 0 || timeptr->tm_hour > 23)) {
return false;
}

if ((mask & RTC_ALARM_TIME_MASK_MONTH) &&
(timeptr->tm_mon < 0 || timeptr->tm_mon > 11)) {
return false;
}

if ((mask & RTC_ALARM_TIME_MASK_MONTHDAY) &&
(timeptr->tm_mday < 1 || timeptr->tm_mday > 31)) {
return false;
}

if ((mask & RTC_ALARM_TIME_MASK_YEAR) &&
(timeptr->tm_year < 0 || timeptr->tm_year > 199)) {
return false;
}

return true;
}
#endif /* CONFIG_RTC_ALARM */

static int rtc_emul_get_days_in_month(struct rtc_time *datetime)
{
const uint8_t *dim = (rtc_emul_is_leap_year(datetime) == true) ?
Expand Down Expand Up @@ -346,7 +311,7 @@ static int rtc_emul_alarm_set_time(const struct device *dev, uint16_t id, uint16
}

if (mask > 0) {
if (rtc_emul_validate_alarm_time(timeptr, mask) == false) {
if (rtc_utils_validate_rtc_time(timeptr, mask) == false) {
return -EINVAL;
}
}
Expand Down
Loading
Loading