Skip to content

Commit b0d2bc5

Browse files
committed
Add RTC Alarm setters
1 parent 580c76b commit b0d2bc5

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

src/Arduino_LowPowerPortentaC33.cpp

+46-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,56 @@ void LowPower::sleep(){
2020
void LowPower::deepSleep(){
2121
RenesasLowPowerConfig.low_power_mode = LPM_MODE_DEEP;
2222

23-
24-
2523
R_LPM_Open(&RenesasLowPowerControlBlock, &RenesasLowPowerConfig);
2624
R_LPM_LowPowerModeEnter(&RenesasLowPowerControlBlock);
2725
}
2826

27+
bool LowPower::setWakeUpAlarm(RTCTime alarmTime){
28+
this->enableWakeupFromRTC();
29+
30+
if(!RTC.isRunning()){
31+
return false;
32+
}
33+
34+
RTCTime currentTime;
35+
if (!RTC.getTime(currentTime)) {
36+
return false; // Failed to get current time
37+
}
38+
39+
// Configure the alarm match criteria
40+
AlarmMatch match;
41+
match.addMatchSecond(); // Trigger the alarm when the seconds match
42+
match.addMatchMinute(); // Trigger the alarm when the minutes match
43+
match.addMatchHour(); // Trigger the alarm when the hours match
44+
match.addMatchDay(); // Trigger the alarm when the days match
45+
match.addMatchMonth(); // Trigger the alarm when the months match
46+
match.addMatchYear(); // Trigger the alarm when the years match
47+
48+
return RTC.setAlarm(alarmTime, match);
49+
}
50+
51+
bool LowPower::setWakeUpAlarm(uint8_t hours, uint8_t minutes, uint8_t seconds){
52+
53+
if(!RTC.isRunning()){
54+
return false;
55+
}
56+
57+
// Get the current time from the RTC
58+
RTCTime currentTime;
59+
if (!RTC.getTime(currentTime)) {
60+
return false; // Failed to get current time
61+
}
62+
63+
// Convert current time to UNIX timestamp and add the desired interval
64+
time_t currentTimestamp = currentTime.getUnixTime();
65+
currentTimestamp += hours * 3600 + minutes * 60 + seconds;
66+
67+
// Convert back to RTCTime
68+
RTCTime alarmTime(currentTimestamp);
69+
70+
return this->setWakeUpAlarm(alarmTime);
71+
}
72+
2973
void LowPower::enableWakeupFromRTC(){
3074
RenesasLowPowerConfig.deep_standby_cancel_source = LPM_DEEP_STANDBY_CANCEL_SOURCE_RTC_ALARM;
3175
RenesasLowPowerConfig.standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM;

src/Arduino_LowPowerPortentaC33.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "r_lpm.h"
55
#include "Arduino.h"
6+
#include "RTC.h"
67

78

89
/**
@@ -40,13 +41,15 @@ class LowPower {
4041
*/
4142
bool enableWakeupFromPin(uint8_t pin, PinStatus direction);
4243

44+
bool setWakeUpAlarm(RTCTime alarmTime);
45+
bool setWakeUpAlarm(uint8_t hours, uint8_t minutes, uint8_t seconds);
46+
47+
private:
4348
/**
4449
* Enables wake-up of the device based on the Real-Time Clock (RTC).
4550
*/
4651
void enableWakeupFromRTC();
4752

48-
49-
private:
5053
/**
5154
* Retrieves the IRQ channel associated with a standby wake-up source for a given pin.
5255
* @param pin The pin number.

0 commit comments

Comments
 (0)