mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 14:22:33 +00:00
simplify if/else handling on ringbuffer
This commit is contained in:
parent
f0d2ebdc7e
commit
2ec05da5dd
@ -111,10 +111,8 @@ impl<'a, W: Word> ReadableDmaRingBuffer<'a, W> {
|
||||
let diff = self.write_index.diff(self.cap(), &self.read_index);
|
||||
|
||||
if diff < 0 {
|
||||
return Err(Error::DmaUnsynced);
|
||||
}
|
||||
|
||||
if diff > self.cap() as isize {
|
||||
Err(Error::DmaUnsynced)
|
||||
} else if diff > self.cap() as isize {
|
||||
Err(Error::Overrun)
|
||||
} else {
|
||||
Ok(diff as usize)
|
||||
@ -223,11 +221,10 @@ impl<'a, W: Word> WritableDmaRingBuffer<'a, W> {
|
||||
|
||||
let diff = self.write_index.diff(self.cap(), &self.read_index);
|
||||
|
||||
if diff > self.cap() as isize {
|
||||
return Err(Error::DmaUnsynced);
|
||||
}
|
||||
if diff < 0 {
|
||||
Err(Error::Overrun)
|
||||
} else if diff > self.cap() as isize {
|
||||
Err(Error::DmaUnsynced)
|
||||
} else {
|
||||
Ok(self.cap().saturating_sub(diff as usize))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user