Skip to content

Commit c307c04

Browse files
author
Connor Truono
committed
Remove Datetime conversions from set_alarm APIs
1 parent 7bef2e4 commit c307c04

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/rtc.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ impl<'r> RtcDatetimeClock<'r> {
133133
.get_datetime_in_secs()?
134134
.checked_add(secs_from_now)
135135
.ok_or(DatetimeClockError::UnsupportedDatetime)?;
136-
self.set_alarm_at(Datetime::from_unix_time_seconds(secs))
136+
self.set_alarm_at(secs)?;
137+
Ok(secs)
137138
}
138139

139140
/// Sets the RTC wake alarm via the match register to wake at the given Datetime.
@@ -147,22 +148,20 @@ impl<'r> RtcDatetimeClock<'r> {
147148
///
148149
/// # Parameters
149150
///
150-
/// * `alarm_time` - An absolute Datetime at which the alarm should fire.
151+
/// * `alarm_time` - An absolute RTC time in seconds at which the alarm should fire.
151152
///
152153
/// # Returns
153154
///
154155
/// `u64` - The absolute RTC time in seconds at which the alarm is scheduled to fire.
155156
/// This is the `alarm_time` argument converted into u64
156-
pub fn set_alarm_at(&mut self, alarm_time: Datetime) -> Result<u64, DatetimeClockError> {
157-
let secs_u64 = alarm_time.to_unix_time_seconds();
158-
157+
pub fn set_alarm_at(&mut self, unix_time_secs: u64) -> Result<(), DatetimeClockError> {
159158
// Check that the alarm end time is not in the past
160-
if self.get_datetime_in_secs()? > secs_u64 {
159+
if self.get_datetime_in_secs()? > unix_time_secs {
161160
return Err(DatetimeClockError::UnsupportedDatetime);
162161
}
163162

164163
// Convert seconds to u32 to interface with 32 bit hardware RTC
165-
let secs: u32 = secs_u64
164+
let secs: u32 = unix_time_secs
166165
.try_into()
167166
.map_err(|_| DatetimeClockError::UnsupportedDatetime)?;
168167

@@ -188,7 +187,7 @@ impl<'r> RtcDatetimeClock<'r> {
188187
}
189188
});
190189

191-
Ok(secs_u64)
190+
Ok(())
192191
}
193192

194193
/// Clears the RTC 1Hz alarm by resetting related registers

0 commit comments

Comments
 (0)