fn write_slice(sercom: &RegisterBlock, buf: &[u8], duplex: bool) -> Result<(), Error> {
    let mut to_send = buf.iter();
    let mut to_recv: usize = to_send.len();
    while to_recv > 0 {
        let errors = sercom.spim().status.read();
        if duplex && errors.bufovf().bit_is_set() {
            return Err(Error::Overflow);
        }
        if errors.lenerr().bit_is_set() {
            return Err(Error::LengthError);
        }
        let flags = sercom.spim().intflag.read();
        // Send the word
        if to_send.len() > 0 && flags.dre().bit_is_set() {
            let mut bytes = [0; 4];
            for byte in &mut bytes {
                match to_send.next() {
                    Some(d) => *byte = *d,
                    None => break,
                }
            }
            let word = u32::from_le_bytes(bytes);
            sercom.spim().data.write(|w| unsafe { w.data().bits(word) });
        }
        if duplex && to_recv > to_send.len() && flags.rxc().bit_is_set() {
            sercom.spim().data.read().data().bits();
            let diff = to_recv - to_send.len();
            to_recv -= if diff < 4 { diff } else { 4 };
        }
    }
    Ok(())
}
/// Write a `[u8]` four bytes at a time
///
/// This function exists to avoid both code duplication and monomorphization
/// bloat. It will take a `[u8]` and write four bytes at a time to the SPI on
/// every DRE flag. If the `duplex` argument is true, it will read as many times
/// as it writes. Otherwise, it will skip reading the `DATA` register entirely.
/// If `duplex` is false, buffer overflow errors are ignored
Write a `[u8]` four bytes at a time
This function exists to avoid both code duplication and monomorphization
bloat. It will take a `[u8]` and write four bytes at a time to the SPI on
every DRE flag. If the `duplex` argument is true, it will read as many times
as it writes. Otherwise, it will skip reading the `DATA` register entirely.
If `duplex` is false, buffer overflow errors are ignored
Write a ` [ u8 ] ` four bytes at a time This function exists to avoid both code duplication and monomorphization bloat . It will take a ` [ u8 ] ` and write four bytes at a time to the SPI on every DRE flag . If the ` duplex ` argument is true it will read as many times as it writes . Otherwise it will skip reading the ` DATA ` register entirely . If ` duplex ` is false buffer overflow errors are ignored
fn write_slice(sercom: &RegisterBlock, buf: &[u8], duplex: bool) -> Result<(), Error> {
    let mut to_send = buf.iter();
    let mut to_recv: usize = to_send.len();
    while to_recv > 0 {
        let errors = sercom.spim().status.read();
        if duplex && errors.bufovf().bit_is_set() {
            return Err(Error::Overflow);
        }
        if errors.lenerr().bit_is_set() {
            return Err(Error::LengthError);
        }
        let flags = sercom.spim().intflag.read();
        // Send the word
        if to_send.len() > 0 && flags.dre().bit_is_set() {
            let mut bytes = [0; 4];
            for byte in &mut bytes {
                match to_send.next() {
                    Some(d) => *byte = *d,
                    None => break,
                }
            }
            let word = u32::from_le_bytes(bytes);
            sercom.spim().data.write(|w| unsafe { w.data().bits(word) });
        }
        if duplex && to_recv > to_send.len() && flags.rxc().bit_is_set() {
            sercom.spim().data.read().data().bits();
            let diff = to_recv - to_send.len();
            to_recv -= if diff < 4 { diff } else { 4 };
        }
    }
    Ok(())
}
fn write_slice ( sercom : & RegisterBlock , buf : & [ u8 ] , duplex : bool ) -> Result < ( ) , Error > { let mut to_send = buf . iter ( ) ; let mut to_recv : usize = to_send . len ( ) ; while to_recv > 0 { let errors = sercom . spim ( ) . status . read ( ) ; if duplex && errors . bufovf ( ) . bit_is_set ( ) { return Err ( Error :: Overflow ) ; } if errors . lenerr ( ) . bit_is_set ( ) { return Err ( Error :: LengthError ) ; } let flags = sercom . spim ( ) . intflag . read ( ) ; // Send the word if to_send . len ( ) > 0 && flags . dre ( ) . bit_is_set ( ) { let mut bytes = [ 0 ; 4 ] ; for byte in & mut bytes { match to_send . next ( ) { Some ( d ) => * byte = * d , None => break , } } let word = u32 :: from_le_bytes ( bytes ) ; sercom . spim ( ) . data . write ( | w | unsafe { w . data ( ) . bits ( word ) } ) ; } if duplex && to_recv > to_send . len ( ) && flags . rxc ( ) . bit_is_set ( ) { sercom . spim ( ) . data . read ( ) . data ( ) . bits ( ) ; let diff = to_recv - to_send . len ( ) ; to_recv -= if diff < 4 { diff } else { 4 } ; } } Ok ( ( ) ) }
Write a `[u8]` four bytes at a time
This function exists to avoid both code duplication and monomorphization
bloat.
Write a ` [ u8 ] ` four bytes at a time This function exists to avoid both code duplication and monomorphization bloat .
sercom
&RegisterBlock
buf
&[u8]
duplex
bool
sercom
&RegisterBlock
buf
&[u8]
duplex
bool