diff --git a/Cargo.toml b/Cargo.toml index 66b0d43..87a77a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,7 @@ categories = ["embedded", "no-std"] nb = "0.1" [dependencies.embedded-hal] -version = "0.2.3" -features = ["unproven"] +version = "=1.0.0-alpha.1" [dev-dependencies.stm32f1xx-hal] version = "0.5.3" diff --git a/examples/i2c-eeprom24x.rs b/examples/i2c-eeprom24x.rs index 2f3448e..e122da5 100644 --- a/examples/i2c-eeprom24x.rs +++ b/examples/i2c-eeprom24x.rs @@ -41,13 +41,13 @@ fn main() -> ! { for addr in addrs.iter() { eeprom.write_byte(*addr, byte).unwrap(); // need to wait before next write - block!(delay.wait()).ok(); + block!(delay.try_wait()).ok(); } loop { for addr in addrs.iter() { let _ = eeprom.read_byte(*addr).unwrap(); - block!(delay.wait()).ok(); + block!(delay.try_wait()).ok(); } } } diff --git a/examples/serial.rs b/examples/serial.rs index f40e105..c32e4b7 100644 --- a/examples/serial.rs +++ b/examples/serial.rs @@ -36,7 +36,7 @@ fn main() -> ! { loop { for byte in b"Hello, World!\r\n" { - block!(serial.write(*byte)).unwrap(); + block!(serial.try_write(*byte)).unwrap(); } delay.delay_ms(1000u16); diff --git a/src/i2c.rs b/src/i2c.rs index 690a87b..66121f9 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -50,8 +50,7 @@ ``` */ -use embedded_hal::blocking::i2c::{Read, Write, WriteRead}; -use embedded_hal::digital::v2::{InputPin, OutputPin}; +use embedded_hal::digital::{InputPin, OutputPin}; use embedded_hal::timer::{CountDown, Periodic}; use nb::block; @@ -118,7 +117,7 @@ where self.set_scl_high()?; self.wait_for_clk(); - let ack = self.sda.is_low().map_err(Error::Bus)?; + let ack = self.sda.try_is_low().map_err(Error::Bus)?; self.set_scl_low()?; self.set_sda_low()?; @@ -136,7 +135,7 @@ where self.set_scl_high()?; self.wait_for_clk(); - if self.sda.is_high().map_err(Error::Bus)? { + if self.sda.try_is_high().map_err(Error::Bus)? { byte |= 1 << (7 - bit_offset); } @@ -201,27 +200,27 @@ where #[inline] fn set_scl_high(&mut self) -> Result<(), crate::i2c::Error> { - self.scl.set_high().map_err(Error::Bus) + self.scl.try_set_high().map_err(Error::Bus) } #[inline] fn set_scl_low(&mut self) -> Result<(), crate::i2c::Error> { - self.scl.set_low().map_err(Error::Bus) + self.scl.try_set_low().map_err(Error::Bus) } #[inline] fn set_sda_high(&mut self) -> Result<(), crate::i2c::Error> { - self.sda.set_high().map_err(Error::Bus) + self.sda.try_set_high().map_err(Error::Bus) } #[inline] fn set_sda_low(&mut self) -> Result<(), crate::i2c::Error> { - self.sda.set_low().map_err(Error::Bus) + self.sda.try_set_low().map_err(Error::Bus) } #[inline] fn wait_for_clk(&mut self) { - block!(self.clk.wait()).ok(); + block!(self.clk.try_wait()).ok(); } #[inline] @@ -242,7 +241,7 @@ where { type Error = crate::i2c::Error; - fn write(&mut self, addr: u8, output: &[u8]) -> Result<(), Self::Error> { + fn try_write(&mut self, addr: u8, output: &[u8]) -> Result<(), Self::Error> { if output.is_empty() { return Ok(()); } @@ -269,7 +268,7 @@ where { type Error = crate::i2c::Error; - fn read(&mut self, addr: u8, input: &mut [u8]) -> Result<(), Self::Error> { + fn try_read(&mut self, addr: u8, input: &mut [u8]) -> Result<(), Self::Error> { if input.is_empty() { return Ok(()); } @@ -296,7 +295,7 @@ where { type Error = crate::i2c::Error; - fn write_read(&mut self, addr: u8, output: &[u8], input: &mut [u8]) -> Result<(), Self::Error> { + fn try_write_read(&mut self, addr: u8, output: &[u8], input: &mut [u8]) -> Result<(), Self::Error> { if output.is_empty() || input.is_empty() { return Err(Error::InvalidData); } diff --git a/src/serial.rs b/src/serial.rs index 51b1e6b..c974391 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -8,7 +8,7 @@ //! The timer must be configured to twice the desired communication frequency. //! -use embedded_hal::digital::v2::{InputPin, OutputPin}; +use embedded_hal::digital::{InputPin, OutputPin}; use embedded_hal::serial; use embedded_hal::timer::{CountDown, Periodic}; use nb::block; @@ -45,7 +45,7 @@ where #[inline] fn wait_for_timer(&mut self) { - block!(self.timer.wait()).ok(); + block!(self.timer.try_wait()).ok(); } } @@ -57,25 +57,25 @@ where { type Error = crate::serial::Error; - fn write(&mut self, byte: u8) -> nb::Result<(), Self::Error> { + fn try_write(&mut self, byte: u8) -> nb::Result<(), Self::Error> { let mut data_out = byte; - self.tx.set_low().map_err(Error::Bus)?; // start bit + self.tx.try_set_low().map_err(Error::Bus)?; // start bit self.wait_for_timer(); for _bit in 0..8 { if data_out & 1 == 1 { - self.tx.set_high().map_err(Error::Bus)?; + self.tx.try_set_high().map_err(Error::Bus)?; } else { - self.tx.set_low().map_err(Error::Bus)?; + self.tx.try_set_low().map_err(Error::Bus)?; } data_out >>= 1; self.wait_for_timer(); } - self.tx.set_high().map_err(Error::Bus)?; // stop bit + self.tx.try_set_high().map_err(Error::Bus)?; // stop bit self.wait_for_timer(); Ok(()) } - fn flush(&mut self) -> nb::Result<(), Self::Error> { + fn try_flush(&mut self) -> nb::Result<(), Self::Error> { Ok(()) } } @@ -88,14 +88,14 @@ where { type Error = crate::serial::Error; - fn read(&mut self) -> nb::Result { + fn try_read(&mut self) -> nb::Result { let mut data_in = 0; // wait for start bit - while self.rx.is_high().map_err(Error::Bus)? {} + while self.rx.try_is_high().map_err(Error::Bus)? {} self.wait_for_timer(); for _bit in 0..8 { data_in <<= 1; - if self.rx.is_high().map_err(Error::Bus)? { + if self.rx.try_is_high().map_err(Error::Bus)? { data_in |= 1 } self.wait_for_timer(); diff --git a/src/spi.rs b/src/spi.rs index 3ee9dc3..264066d 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -15,7 +15,7 @@ pub use embedded_hal::spi::{MODE_0, MODE_1, MODE_2, MODE_3}; -use embedded_hal::digital::v2::{InputPin, OutputPin}; +use embedded_hal::digital::{InputPin, OutputPin}; use embedded_hal::spi::{FullDuplex, Mode, Polarity}; use embedded_hal::timer::{CountDown, Periodic}; use nb::block; @@ -83,8 +83,8 @@ where }; match mode.polarity { - Polarity::IdleLow => spi.sck.set_low(), - Polarity::IdleHigh => spi.sck.set_high(), + Polarity::IdleLow => spi.sck.try_set_low(), + Polarity::IdleHigh => spi.sck.try_set_high(), } .unwrap_or(()); @@ -97,7 +97,7 @@ where } fn read_bit(&mut self) -> nb::Result<(), crate::spi::Error> { - let is_miso_high = self.miso.is_high().map_err(Error::Bus)?; + let is_miso_high = self.miso.try_is_high().map_err(Error::Bus)?; let shifted_value = self.read_val.unwrap_or(0) << 1; if is_miso_high { self.read_val = Some(shifted_value | 1); @@ -109,17 +109,17 @@ where #[inline] fn set_clk_high(&mut self) -> Result<(), crate::spi::Error> { - self.sck.set_high().map_err(Error::Bus) + self.sck.try_set_high().map_err(Error::Bus) } #[inline] fn set_clk_low(&mut self) -> Result<(), crate::spi::Error> { - self.sck.set_low().map_err(Error::Bus) + self.sck.try_set_low().map_err(Error::Bus) } #[inline] fn wait_for_timer(&mut self) { - block!(self.timer.wait()).ok(); + block!(self.timer.try_wait()).ok(); } } @@ -133,14 +133,14 @@ where type Error = crate::spi::Error; #[inline] - fn read(&mut self) -> nb::Result { + fn try_read(&mut self) -> nb::Result { match self.read_val { Some(val) => Ok(val), None => Err(nb::Error::Other(crate::spi::Error::NoData)), } } - fn send(&mut self, byte: u8) -> nb::Result<(), Self::Error> { + fn try_send(&mut self, byte: u8) -> nb::Result<(), Self::Error> { for bit_offset in 0..8 { let out_bit = match self.bit_order { BitOrder::MSBFirst => (byte >> (7 - bit_offset)) & 0b1, @@ -148,9 +148,9 @@ where }; if out_bit == 1 { - self.mosi.set_high().map_err(Error::Bus)?; + self.mosi.try_set_high().map_err(Error::Bus)?; } else { - self.mosi.set_low().map_err(Error::Bus)?; + self.mosi.try_set_low().map_err(Error::Bus)?; } match self.mode {