Skip to content

Commit 267a693

Browse files
author
Johannes Draaijer
committed
Expose receiver timeout and operation error through RxDma
1 parent 9cba0fb commit 267a693

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/dma.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ pub trait CharacterMatch {
3838
fn check_character_match(&mut self, clear: bool) -> bool;
3939
}
4040

41+
pub trait ReceiverTimeout {
42+
/// Check to see if the peripheral has detected a
43+
/// receiver timeout and clears the flag
44+
fn check_receiver_timeout(&mut self, clear: bool) -> bool;
45+
}
46+
47+
pub trait OperationError<O, E> {
48+
/// Check to see if the peripheral has detected some
49+
/// sort of error while performing an operation
50+
fn check_operation_error(&mut self) -> Result<O, E>;
51+
}
52+
4153
/// Frame reader "worker", access and handling of frame reads is made through this structure.
4254
pub struct FrameReader<BUFFER, PAYLOAD, const N: usize>
4355
where
@@ -77,6 +89,28 @@ where
7789
}
7890
}
7991

92+
impl<BUFFER, PAYLOAD, CHANNEL, const N: usize> FrameReader<BUFFER, RxDma<PAYLOAD, CHANNEL>, N>
93+
where
94+
BUFFER: Sized + StableDeref<Target = DMAFrame<N>> + DerefMut + 'static,
95+
PAYLOAD: ReceiverTimeout,
96+
{
97+
pub fn check_receiver_timeout(&mut self, clear: bool) -> bool {
98+
self.payload.payload.check_receiver_timeout(clear)
99+
}
100+
}
101+
102+
impl<BUFFER, PAYLOAD, CHANNEL, const N: usize> FrameReader<BUFFER, RxDma<PAYLOAD, CHANNEL>, N>
103+
where
104+
BUFFER: Sized + StableDeref<Target = DMAFrame<N>> + DerefMut + 'static,
105+
{
106+
pub fn check_operation_error<O, E>(&mut self) -> Result<O, E>
107+
where
108+
PAYLOAD: OperationError<O, E>,
109+
{
110+
self.payload.payload.check_operation_error()
111+
}
112+
}
113+
80114
/// Frame sender "worker", access and handling of frame transmissions is made through this
81115
/// structure.
82116
pub struct FrameSender<BUFFER, PAYLOAD, const N: usize>

src/serial.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,18 @@ macro_rules! hal {
634634
}
635635
}
636636

637+
impl crate::dma::ReceiverTimeout for Rx<pac::$USARTX> {
638+
fn check_receiver_timeout(&mut self, clear: bool) -> bool {
639+
self.is_receiver_timeout(clear)
640+
}
641+
}
642+
643+
impl crate::dma::OperationError<(), Error> for Rx<pac::$USARTX>{
644+
fn check_operation_error(&mut self) -> Result<(), Error> {
645+
self.check_for_error()
646+
}
647+
}
648+
637649
impl Tx<pac::$USARTX> {
638650
pub fn with_dma(self, channel: $dmatxch) -> $txdma {
639651
TxDma {

0 commit comments

Comments
 (0)