Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
Signed-off-by: Leah <github.leah@hrmny.sh>
  • Loading branch information
ForsakenHarmony committed Apr 25, 2021
1 parent 316252c commit 31ebfb0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ macro_rules! dma {
pub fn partial_peek<R, F, T>(&mut self, f: F) -> Result<R, Error>
where
F: FnOnce(&[T], Half) -> Result<(usize, R), ()>,
H: AsRef<[T]>,
B: AsRef<[T]>,
{
// this inverts expectation and returns the half being _written_
let buf = match self.readable_half {
Expand Down Expand Up @@ -746,7 +746,7 @@ macro_rules! dma {
pub fn peek<R, F, T>(&mut self, f: F) -> Result<R, Error>
where
F: FnOnce(&[T], Half) -> R,
H: AsRef<[T]>,
B: AsRef<[T]>,
{
let half_being_read = self.readable_half()?;
let buf = match half_being_read {
Expand Down Expand Up @@ -884,14 +884,13 @@ macro_rules! dma {
{
pub fn peek<T>(&self) -> &[T]
where
BUFFER: AsSlice<Element=T>,
BUFFER: AsRef<[T]>,
{
let pending = self.payload.channel.get_cndtr() as usize;

let slice = self.buffer.as_slice();
let capacity = slice.len();
let capacity = self.buffer.as_ref().len();

&slice[..(capacity - pending)]
&self.buffer.as_ref()[..(capacity - pending)]
}
}

Expand Down
32 changes: 32 additions & 0 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,38 @@ macro_rules! hal {
channel,
}
}

/// Check for, and return, any errors
///
/// The `read` methods can only return one error at a time, but
/// there might actually be multiple errors. This method will
/// return and clear a currently active error. Once it returns
/// `Ok(())`, it should be possible to proceed with the next
/// `read` call unimpeded.
pub fn check_for_error(&mut self) -> Result<(), Error> {
// NOTE(unsafe): Only used for atomic access.
let isr = unsafe { (*pac::$USARTX::ptr()).isr.read() };
let icr = unsafe { &(*pac::$USARTX::ptr()).icr };

if isr.pe().bit_is_set() {
icr.write(|w| w.pecf().clear());
return Err(Error::Parity);
}
if isr.fe().bit_is_set() {
icr.write(|w| w.fecf().clear());
return Err(Error::Framing);
}
if isr.nf().bit_is_set() {
icr.write(|w| w.ncf().clear());
return Err(Error::Noise);
}
if isr.ore().bit_is_set() {
icr.write(|w| w.orecf().clear());
return Err(Error::Overrun);
}

Ok(())
}
}

impl Tx<pac::$USARTX> {
Expand Down

0 comments on commit 31ebfb0

Please sign in to comment.