Skip to content

Commit

Permalink
fix defmt compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jun 27, 2023
1 parent 58edb9b commit b7b589e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"rust-analyzer.check.allTargets": false,
"rust-analyzer.check.targets": "thumbv7em-none-eabihf",
"rust-analyzer.cargo.features": [
"defmt",
"rtic",
"stm32f411"
],
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

- enable `defmt` feature for VSCode
- `set_alarm` takes `Into<AlarmDay>`

### Fixed

- Compilation with `defmt` feature enabled

## [v0.16.1] - 2023-06-24

- bors bot replaced with GH merge queue
Expand Down
16 changes: 14 additions & 2 deletions src/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,25 @@ impl From<Alarm> for Event {
}
}

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum AlarmDay {
Date(Date),
Weekday(Weekday),
EveryDay,
}

impl From<Date> for AlarmDay {
fn from(date: Date) -> Self {
Self::Date(date)
}
}

impl From<Weekday> for AlarmDay {
fn from(day: Weekday) -> Self {
Self::Weekday(day)
}
}

/// RTC clock source LSE oscillator clock (type state)
pub struct Lse;
/// RTC clock source LSI oscillator clock (type state)
Expand Down Expand Up @@ -599,7 +610,8 @@ impl<CS> Rtc<CS> {

/// Sets the time at which an alarm will be triggered
/// This also clears the alarm flag if it is set
pub fn set_alarm(&mut self, alarm: Alarm, date: AlarmDay, time: Time) -> Result<(), Error> {
pub fn set_alarm(&mut self, alarm: Alarm, date: impl Into<AlarmDay>, time: Time) -> Result<(), Error> {
let date = date.into();
let (daymask, wdsel, (dt, du)) = match date {
AlarmDay::Date(date) => (false, false, bcd2_encode(date.day().into())?),
AlarmDay::Weekday(weekday) => (false, true, (0, weekday.number_days_from_monday())),
Expand Down

0 comments on commit b7b589e

Please sign in to comment.