Skip to content

Commit 49b2974

Browse files
author
pythcoiner
committed
add any
1 parent b0cead1 commit 49b2974

File tree

2 files changed

+140
-1
lines changed

2 files changed

+140
-1
lines changed

.idea/workspace.xml

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/serial.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ pub enum Event {
137137
// /// [`Serial::set_wakeup_from_stopmode_reason()`]
138138
// #[doc(alias = "WUF")]
139139
// WakeupFromStopMode,
140+
/// Any of the above events occurred
141+
Any,
140142
}
141143

142144
/// Serial error
@@ -490,7 +492,8 @@ where
490492
self.configure_interrupt(event, Switch::Off);
491493
}
492494

493-
/// Enable or disable the interrupt for the specified [`Event`].
495+
/// Enable or disable the interrupt for the specified [`Event`], if passing [`Event::Any`]
496+
/// , it will be apply to all events.
494497
#[inline]
495498
pub fn configure_interrupt(&mut self, event: Event, enable: impl Into<Switch>) {
496499
// Do a round way trip to be convert Into<Switch> -> bool
@@ -513,7 +516,28 @@ where
513516
Event::ReceiverTimeout => self.usart.cr1.modify(|_, w| w.rtoie().bit(enable)),
514517
// Event::EndOfBlock => self.usart.cr1.modify(|_, w| w.eobie().bit(enable)),
515518
// Event::WakeupFromStopMode => self.usart.cr3.modify(|_, w| w.wufie().bit(enable)),
519+
Event::Any => {
520+
self.usart.cr1.modify(|_, w| {
521+
w.txeie().bit(enable);
522+
w.tcie().bit(enable);
523+
w.rxneie().bit(enable);
524+
w.peie().bit(enable);
525+
w.idleie().bit(enable);
526+
w.cmie().bit(enable);
527+
w.rtoie().bit(enable)
528+
// w.eobie().bit(enable);
529+
});
530+
self.usart.cr2.modify(|_, w| {
531+
w.lbdie().bit(enable)
532+
});
533+
self.usart.cr3.modify(|_, w| {
534+
w.ctsie().bit(enable);
535+
w.eie().bit(enable)
536+
// w.wufie().bit(enable);
537+
})
538+
}
516539
};
540+
517541
}
518542

519543
/// Enable or disable interrupt for the specified [`Event`]s.
@@ -550,6 +574,7 @@ where
550574
Event::ReceiverTimeout => self.usart.cr1.read().rtoie().is_enabled(),
551575
// Event::EndOfBlock => self.usart.cr1.read().eobie().is_enabled(),
552576
// Event::WakeupFromStopMode => self.usart.cr3.read().wufie().is_enabled(),
577+
Event::Any => false, // FIXME: should handle if any of previous cases
553578
}
554579
}
555580

@@ -588,6 +613,8 @@ where
588613
Event::ReceiverTimeout => isr.rtof().bit(),
589614
// Event::EndOfBlock => isr.eobf().bit(),
590615
// Event::WakeupFromStopMode => isr.wuf().bit(),
616+
Event::Any => isr.bits() != 0, // TODO: should we return true if any of ISR bit is 1?
617+
591618
}
592619
}
593620

@@ -640,6 +667,21 @@ where
640667
// Do nothing with this event (only useful for Smartcard, which is not
641668
// supported right now)
642669
Event::TransmitDataRegisterEmtpy => w,
670+
Event::Any => {
671+
w.ctscf().clear();
672+
w.tccf().clear();
673+
w.orecf().clear();
674+
w.idlecf().clear();
675+
w.pecf().clear();
676+
w.pecf().clear();
677+
w.lbdcf().clear();
678+
w.ncf().clear();
679+
w.fecf().clear();
680+
w.cmcf().clear();
681+
w.rtocf().clear();
682+
self.usart.rqr.write(|w| w.rxfrq().set_bit());
683+
w
684+
}
643685
});
644686
}
645687

0 commit comments

Comments
 (0)