Skip to content

Commit c8c1d15

Browse files
committed
RTC: add nano connect support
1 parent 231179c commit c8c1d15

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

libraries/RTC/RTC.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int Rtc::getSeconds() {
153153
return -1;
154154
}
155155

156-
#ifdef CONFIG_RTC_STM32
156+
#if defined(CONFIG_RTC_STM32) || defined(CONFIG_RTC_RPI_PICO)
157157

158158
#if DT_NODE_EXISTS(DT_NODELABEL(rtc))
159159
#define RTC_NODE DT_NODELABEL(rtc)
@@ -165,7 +165,7 @@ int Rtc::getSeconds() {
165165
/**
166166
* @brief Rtc library constructor
167167
*
168-
* Constructor used with the STM32 microcontroller based boards (OPTA, PORTENTA H7, GIGA R1)
168+
* Constructor used with STM32 and RP2040-based boards using Zephyr RTC drivers
169169
*
170170
*/
171171
Rtc::Rtc() {
@@ -401,10 +401,14 @@ void Rtc::alarmCallbackWrapper([[maybe_unused]] const struct device *dev,
401401
* @param void *user_data is a void pointer the user can set when registering the callback
402402
*/
403403
int Rtc::setUpdateCallback(RtcUpdateCallback cb, void *user_data) {
404+
#if defined(CONFIG_RTC_RPI_PICO)
405+
return -1;
406+
#else
404407
userUpdateCallback = cb;
405408
userUpdateCallbackData = user_data;
406409

407410
return rtc_update_set_callback(rtc_dev, Rtc::updateCallbackWrapper, this);
411+
#endif
408412
}
409413

410414
/**
@@ -434,7 +438,11 @@ void Rtc::updateCallbackWrapper([[maybe_unused]] const struct device *dev, void
434438
* @return 0 if successful, or a negative error code on failure.
435439
*/
436440
int Rtc::setCalibration(int32_t calibration) {
441+
#if defined(CONFIG_RTC_RPI_PICO)
442+
return -1;
443+
#else
437444
return rtc_set_calibration(rtc_dev, calibration);
445+
#endif
438446
}
439447

440448
/**
@@ -447,13 +455,19 @@ int Rtc::setCalibration(int32_t calibration) {
447455
* @return 0 if successful, or a negative error code on failure.
448456
*/
449457
int Rtc::getCalibration(int32_t &calibration) {
458+
#if defined(CONFIG_RTC_RPI_PICO)
459+
return -1;
460+
#else
450461
return rtc_get_calibration(rtc_dev, &calibration);
462+
#endif
451463
}
452464

453-
#else // For non-STM32 platforms (nordic), we must use the generic counter API to implement RTC
465+
#elif defined(CONFIG_COUNTER_NRF_RTC) // For other platforms (nordic), we must use the counter API to implement RTC
454466
// functionality
455467

456-
#if DT_NODE_EXISTS(DT_NODELABEL(rtc2))
468+
#if DT_NODE_EXISTS(DT_NODELABEL(rtc1))
469+
#define COUNTER_NODE DT_NODELABEL(rtc1)
470+
#elif DT_NODE_EXISTS(DT_NODELABEL(rtc2))
457471
#define COUNTER_NODE DT_NODELABEL(rtc2)
458472
#else
459473
#warning "RTC node not found in devicetree"
@@ -796,4 +810,6 @@ void Rtc::epochToDatetime(time_t t, int &year, int &month, int &day, int &hour,
796810
month = m + 1;
797811
day = days + 1;
798812
}
799-
#endif /* CONFIG_RTC_STM32*/
813+
#else
814+
#error "Unsupported RTC configuration"
815+
#endif /* CONFIG_RTC_STM32 || CONFIG_RTC_RPI_PICO */

libraries/RTC/RTC.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class Rtc {
217217
*/
218218
int getTime(int &year, int &month, int &day, int &hour, int &minute, int &second);
219219

220-
#ifdef CONFIG_RTC_STM32
220+
#if defined(CONFIG_RTC_STM32) || defined(CONFIG_RTC_RPI_PICO)
221221
/**
222222
* @brief Schedules an alarm for a specific time.
223223
*
@@ -308,7 +308,7 @@ class Rtc {
308308
int getCalibration([[maybe_unused]] int32_t &calibration);
309309
#endif
310310

311-
#ifdef CONFIG_RTC_STM32
311+
#if defined(CONFIG_RTC_STM32) || defined(CONFIG_RTC_RPI_PICO)
312312
/**
313313
* @brief Retrieves the currently configured alarm time.
314314
*
@@ -358,7 +358,7 @@ class Rtc {
358358
#endif
359359

360360
private:
361-
#ifdef CONFIG_RTC_STM32
361+
#if defined(CONFIG_RTC_STM32) || defined(CONFIG_RTC_RPI_PICO)
362362
/** @brief Pointer to the Zephyr RTC device. */
363363
const struct device *rtc_dev;
364364

@@ -377,7 +377,7 @@ class Rtc {
377377

378378
uint16_t alarmId = 0; /**< Default alarm identifier. */
379379

380-
#else
380+
#else // For boards without a dedicated RTC, we use the counter API to implement RTC functionality
381381
/** @brief Pointer to the Zephyr counter device used as RTC backend. */
382382
const struct device *counter_dev;
383383

variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
status = "okay";
3232

3333
clocks = <&rcc STM32_CLOCK(APB4, 16U)>,
34-
<&rcc STM32_SRC_LSE RTC_SEL(0)>;
34+
<&rcc STM32_SRC_LSE RTC_SEL(1)>;
3535
};
3636

3737
&i2c4 {

0 commit comments

Comments
 (0)