mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +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);
|
let diff = self.write_index.diff(self.cap(), &self.read_index);
|
||||||
|
|
||||||
if diff < 0 {
|
if diff < 0 {
|
||||||
return Err(Error::DmaUnsynced);
|
Err(Error::DmaUnsynced)
|
||||||
}
|
} else if diff > self.cap() as isize {
|
||||||
|
|
||||||
if diff > self.cap() as isize {
|
|
||||||
Err(Error::Overrun)
|
Err(Error::Overrun)
|
||||||
} else {
|
} else {
|
||||||
Ok(diff as usize)
|
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);
|
let diff = self.write_index.diff(self.cap(), &self.read_index);
|
||||||
|
|
||||||
if diff > self.cap() as isize {
|
|
||||||
return Err(Error::DmaUnsynced);
|
|
||||||
}
|
|
||||||
if diff < 0 {
|
if diff < 0 {
|
||||||
Err(Error::Overrun)
|
Err(Error::Overrun)
|
||||||
|
} else if diff > self.cap() as isize {
|
||||||
|
Err(Error::DmaUnsynced)
|
||||||
} else {
|
} else {
|
||||||
Ok(self.cap().saturating_sub(diff as usize))
|
Ok(self.cap().saturating_sub(diff as usize))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user