From 9de8d77a2493180a94f85cdd78506d2c9020dc8a Mon Sep 17 00:00:00 2001 From: Harry Ho Date: Tue, 27 Apr 2021 16:14:22 +0800 Subject: [PATCH] Restore embedded_hal DelayUs for device init --- src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7ffe179..0cc484e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ pub mod spi; use embedded_hal::{ blocking::{ spi::Transfer, + delay::DelayUs, }, digital::v2::OutputPin, }; @@ -61,14 +62,14 @@ impl , } } - pub fn init(&mut self) -> Result<(), Error> { - self.reset()?; + pub fn init(&mut self, delay: &mut impl DelayUs) -> Result<(), Error> { + self.reset(delay)?; self.init_rxbuf()?; self.init_txbuf()?; Ok(()) } - pub fn reset(&mut self) -> Result<(), Error> { + pub fn reset(&mut self, delay: &mut impl DelayUs) -> Result<(), Error> { // Write 0x1234 to EUDAST self.spi_port.write_reg_16b(spi::addrs::EUDAST, 0x1234)?; // Verify that EUDAST is 0x1234 @@ -83,13 +84,13 @@ impl , } // Issue system reset - set ETHRST (ECON2<4>) to 1 self.spi_port.send_opcode(spi::opcodes::SETETHRST)?; - self.spi_port.delay_us(25); + delay.delay_us(25); // Verify that EUDAST is 0x0000 eudast = self.spi_port.read_reg_16b(spi::addrs::EUDAST)?; if eudast != 0x0000 { return Err(Error::RegisterError) } - self.spi_port.delay_us(256); + delay.delay_us(256); Ok(()) }