-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from qwandor/features
Add methods for match register and interrupts, and optional chrono support
- Loading branch information
Showing
5 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::Rtc; | ||
use chrono::{DateTime, TimeZone as _, Utc}; | ||
use core::num::TryFromIntError; | ||
|
||
impl Rtc { | ||
/// Returns the current time. | ||
pub fn get_time(&self) -> DateTime<Utc> { | ||
Utc.timestamp_opt(self.get_unix_timestamp().into(), 0) | ||
.unwrap() | ||
} | ||
|
||
/// Sets the current time. | ||
/// | ||
/// Returns an error if the given time is beyond the bounds supported by the RTC. | ||
pub fn set_time(&mut self, time: DateTime<Utc>) -> Result<(), TryFromIntError> { | ||
self.set_unix_timestamp(time.timestamp().try_into()?); | ||
Ok(()) | ||
} | ||
|
||
/// Sets the match register to the given time. When the RTC value matches this then an interrupt | ||
/// will be generated (if it is enabled). | ||
pub fn set_match(&mut self, match_time: DateTime<Utc>) -> Result<(), TryFromIntError> { | ||
self.set_match_timestamp(match_time.timestamp().try_into()?); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters