Skip to content

Commit

Permalink
Added delay us and ns
Browse files Browse the repository at this point in the history
  • Loading branch information
David-OConnor committed Dec 15, 2023
1 parent 98252b3 commit f7914cd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,20 @@ pub fn delay_ms(num_ms: u32, ahb_freq: u32) {
delay.delay_ms(num_ms);
}

/// A blocking delay, for a specified time in μs.
pub fn delay_us(num_us: u32, ahb_freq: u32) {
let cp = unsafe { cortex_m::Peripherals::steal() };
let mut delay = Delay::new(cp.SYST, ahb_freq);
delay.delay_us(num_us);
}

/// A blocking delay, for a specified time in ns.
pub fn delay_ns(num_ns: u32, ahb_freq: u32) {
let cp = unsafe { cortex_m::Peripherals::steal() };
let mut delay = Delay::new(cp.SYST, ahb_freq);
delay.delay_ns(num_ns);
}

/// In the prelude, we export helper macros.
pub mod prelude {
pub use access_global;
Expand Down
23 changes: 17 additions & 6 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,16 +613,27 @@ where
#[cfg(not(any(feature = "h5", feature = "h7")))]
pub fn transfer_type2<'w>(&mut self, write_buf: &'w [u8], read_buf: &'w mut [u8]) -> Result<(), SpiError> {
println!("Write buf: {:?}, Read buf: {:?}", write_buf, read_buf);

let mut i_read = 0;

for (i_write, word) in write_buf.iter().enumerate() {
self.write_one(*word)?;
// let i_read = i + write_buf.len();
if i_write >= write_buf.len() - 1 {
let i_read = i_write - write_buf.len() + 1;
read_buf[i_read] = self.read()?;
println!("read: {:?}", read_buf[i_read]);
}
read_buf[i_write] = self.read()?;
println!("read: {}", read_buf[i_write]);
}

// for (i_write, word) in write_buf.iter().enumerate() {
// self.write_one(*word)?;
// // let i_read = i + write_buf.len();
//
// if i_write >= write_buf.len() - 1 {
// // let i_read = i_write - write_buf.len() + 1;
// read_buf[i_read] = self.read()?;
// println!("read. i:{} v:{:?}", i_read, read_buf[i_read]);
// i_read += 1;
// }
// }

Ok(())
}

Expand Down

0 comments on commit f7914cd

Please sign in to comment.