use super::DayOfWeek;
use crate::pac::rtc::regs::{IrqSetup0, IrqSetup1};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DateTimeFilter {
pub year: Option<u16>,
pub month: Option<u8>,
pub day: Option<u8>,
pub day_of_week: Option<DayOfWeek>,
pub hour: Option<u8>,
pub minute: Option<u8>,
pub second: Option<u8>,
}
impl DateTimeFilter {
pub fn year(mut self, year: u16) -> Self {
self.year = Some(year);
self
}
pub fn month(mut self, month: u8) -> Self {
self.month = Some(month);
self
}
pub fn day(mut self, day: u8) -> Self {
self.day = Some(day);
self
}
pub fn day_of_week(mut self, day_of_week: DayOfWeek) -> Self {
self.day_of_week = Some(day_of_week);
self
}
pub fn hour(mut self, hour: u8) -> Self {
self.hour = Some(hour);
self
}
pub fn minute(mut self, minute: u8) -> Self {
self.minute = Some(minute);
self
}
pub fn second(mut self, second: u8) -> Self {
self.second = Some(second);
self
}
}
impl DateTimeFilter {
pub(super) fn write_setup_0(&self, w: &mut IrqSetup0) {
if let Some(year) = self.year {
w.set_year_ena(true);
w.set_year(year);
}
if let Some(month) = self.month {
w.set_month_ena(true);
w.set_month(month);
}
if let Some(day) = self.day {
w.set_day_ena(true);
w.set_day(day);
}
}
pub(super) fn write_setup_1(&self, w: &mut IrqSetup1) {
if let Some(day_of_week) = self.day_of_week {
w.set_dotw_ena(true);
let bits = super::conversions::day_of_week_to_u8(day_of_week);
w.set_dotw(bits);
}
if let Some(hour) = self.hour {
w.set_hour_ena(true);
w.set_hour(hour);
}
if let Some(minute) = self.minute {
w.set_min_ena(true);
w.set_min(minute);
}
if let Some(second) = self.second {
w.set_sec_ena(true);
w.set_sec(second);
}
}
}