Address @Dirbaio's comments

This commit is contained in:
Justin Beaurivage 2024-02-05 18:05:59 -05:00
parent cc12eb9680
commit 2575f597cc

View file

@ -66,18 +66,16 @@ bitflags::bitflags! {
} }
} }
impl TryFrom<ErrorSource> for () { impl ErrorSource {
type Error = Error;
#[inline] #[inline]
fn try_from(errors: ErrorSource) -> Result<Self, Self::Error> { fn check(self) -> Result<(), Error> {
if errors.contains(ErrorSource::OVERRUN) { if self.contains(ErrorSource::OVERRUN) {
Err(Error::Overrun) Err(Error::Overrun)
} else if errors.contains(ErrorSource::PARITY) { } else if self.contains(ErrorSource::PARITY) {
Err(Error::Parity) Err(Error::Parity)
} else if errors.contains(ErrorSource::FRAMING) { } else if self.contains(ErrorSource::FRAMING) {
Err(Error::Framing) Err(Error::Framing)
} else if errors.contains(ErrorSource::BREAK) { } else if self.contains(ErrorSource::BREAK) {
Err(Error::Break) Err(Error::Break)
} else { } else {
Ok(()) Ok(())
@ -539,7 +537,7 @@ impl<'d, T: Instance> UarteRx<'d, T> {
let r = T::regs(); let r = T::regs();
let err_bits = r.errorsrc.read().bits(); let err_bits = r.errorsrc.read().bits();
r.errorsrc.write(|w| unsafe { w.bits(err_bits) }); r.errorsrc.write(|w| unsafe { w.bits(err_bits) });
ErrorSource::from_bits_truncate(err_bits).try_into() ErrorSource::from_bits_truncate(err_bits).check()
} }
fn new_inner( fn new_inner(
@ -677,6 +675,7 @@ impl<'d, T: Instance> UarteRx<'d, T> {
s.endrx_waker.register(cx.waker()); s.endrx_waker.register(cx.waker());
if let Err(e) = self.check_and_clear_errors() { if let Err(e) = self.check_and_clear_errors() {
r.tasks_stoprx.write(|w| unsafe { w.bits(1) });
return Poll::Ready(Err(e)); return Poll::Ready(Err(e));
} }
if r.events_endrx.read().bits() != 0 { if r.events_endrx.read().bits() != 0 {
@ -823,6 +822,7 @@ impl<'d, T: Instance, U: TimerInstance> UarteRxWithIdle<'d, T, U> {
s.endrx_waker.register(cx.waker()); s.endrx_waker.register(cx.waker());
if let Err(e) = self.rx.check_and_clear_errors() { if let Err(e) = self.rx.check_and_clear_errors() {
r.tasks_stoprx.write(|w| unsafe { w.bits(1) });
return Poll::Ready(Err(e)); return Poll::Ready(Err(e));
} }
if r.events_endrx.read().bits() != 0 { if r.events_endrx.read().bits() != 0 {