use super::DayOfWeek;
use rp2040_pac::rtc::{irq_setup_0, irq_setup_1};
#[derive(Default)]
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 irq_setup_0::W) {
if let Some(year) = self.year {
w.year_ena().set_bit();
unsafe {
w.year().bits(year);
}
}
if let Some(month) = self.month {
w.month_ena().set_bit();
unsafe {
w.month().bits(month);
}
}
if let Some(day) = self.day {
w.day_ena().set_bit();
unsafe {
w.day().bits(day);
}
}
}
pub(super) fn write_setup_1(&self, w: &mut irq_setup_1::W) {
if let Some(day_of_week) = self.day_of_week {
w.dotw_ena().set_bit();
let bits = super::datetime::day_of_week_to_u8(day_of_week);
unsafe {
w.dotw().bits(bits);
}
}
if let Some(hour) = self.hour {
w.hour_ena().set_bit();
unsafe {
w.hour().bits(hour);
}
}
if let Some(minute) = self.minute {
w.min_ena().set_bit();
unsafe {
w.min().bits(minute);
}
}
if let Some(second) = self.second {
w.sec_ena().set_bit();
unsafe {
w.sec().bits(second);
}
}
}
}