diff --git a/CHANGELOG.md b/CHANGELOG.md index 01c3195b..537b8974 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Breaking changes +- `void::Void` replaced with `Infallible` where it is possible - Change timer/pwm init API - Remove `set_low` and `set_high` for pins in Alternate output mode - Renames `set_seconds` and `seconds` methods on RTC to `set_time` and `current_time`, respectively diff --git a/README.md b/README.md index b9dd2e05..c7631e56 100644 --- a/README.md +++ b/README.md @@ -110,14 +110,15 @@ fn main() -> ! { // in order to configure the port. For pins 0-7, crl should be passed instead. let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh); // Configure the syst timer to trigger an update every second - let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks); + let mut timer = Timer::syst(cp.SYST, clocks) + .start_count_down(1.hz()); // Wait for the timer to trigger an update and change the state of the LED loop { block!(timer.wait()).unwrap(); - led.set_high(); + led.set_high().unwrap(); block!(timer.wait()).unwrap(); - led.set_low(); + led.set_low().unwrap(); } } ``` diff --git a/src/gpio.rs b/src/gpio.rs index 573ad4ef..8be1c732 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -77,7 +77,7 @@ macro_rules! gpio { ]) => { /// GPIO pub mod $gpiox { - use void::Void; + use core::convert::Infallible; use core::marker::PhantomData; use crate::hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, toggleable}; @@ -164,7 +164,7 @@ macro_rules! gpio { } impl OutputPin for Generic> { - type Error = Void; + type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { // NOTE(unsafe) atomic write to a stateless register Ok(unsafe { (*$GPIOX::ptr()).bsrr.write(|w| w.bits(1 << self.i)) }) @@ -177,7 +177,7 @@ macro_rules! gpio { } impl InputPin for Generic> { - type Error = Void; + type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|b| !b) } @@ -202,7 +202,7 @@ macro_rules! gpio { impl toggleable::Default for Generic> {} impl InputPin for Generic> { - type Error = Void; + type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|b| !b) } @@ -470,7 +470,7 @@ macro_rules! gpio { } impl OutputPin for $PXi> { - type Error = Void; + type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { // NOTE(unsafe) atomic write to a stateless register Ok(unsafe { (*$GPIOX::ptr()).bsrr.write(|w| w.bits(1 << $i)) }) @@ -496,7 +496,7 @@ macro_rules! gpio { impl toggleable::Default for $PXi> {} impl InputPin for $PXi> { - type Error = Void; + type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|b| !b) } @@ -508,7 +508,7 @@ macro_rules! gpio { } impl InputPin for $PXi> { - type Error = Void; + type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|b| !b) } @@ -525,8 +525,8 @@ macro_rules! gpio { macro_rules! impl_pxx { ($(($port:ident :: $pin:ident)),*) => { - use void::Void; use embedded_hal::digital::v2::{InputPin, StatefulOutputPin, OutputPin}; + use core::convert::Infallible; pub enum Pxx { $( @@ -535,14 +535,14 @@ macro_rules! impl_pxx { } impl OutputPin for Pxx> { - type Error = Void; - fn set_high(&mut self) -> Result<(), Void> { + type Error = Infallible; + fn set_high(&mut self) -> Result<(), Infallible> { match self { $(Pxx::$pin(pin) => pin.set_high()),* } } - fn set_low(&mut self) -> Result<(), Void> { + fn set_low(&mut self) -> Result<(), Infallible> { match self { $(Pxx::$pin(pin) => pin.set_low()),* } @@ -564,14 +564,14 @@ macro_rules! impl_pxx { } impl InputPin for Pxx> { - type Error = Void; - fn is_high(&self) -> Result { + type Error = Infallible; + fn is_high(&self) -> Result { match self { $(Pxx::$pin(pin) => pin.is_high()),* } } - fn is_low(&self) -> Result { + fn is_low(&self) -> Result { match self { $(Pxx::$pin(pin) => pin.is_low()),* } diff --git a/src/rtc.rs b/src/rtc.rs index fafac68a..0f7ef528 100644 --- a/src/rtc.rs +++ b/src/rtc.rs @@ -18,7 +18,7 @@ use crate::backup_domain::BackupDomain; use crate::time::Hertz; use nb; -use void::Void; +use core::convert::Infallible; // The LSE runs at at 32 768 hertz unless an external clock is provided const LSE_HERTZ: u32 = 32_768; @@ -170,11 +170,11 @@ impl Rtc { use nb::block; rtc.set_alarm(rtc.read_counts() + 5); - // NOTE: Safe unwrap because Void can't be returned + // NOTE: Safe unwrap because Infallible can't be returned block!(rtc.wait_alarm()).unwrap(); ``` */ - pub fn wait_alarm(&mut self) -> nb::Result<(), Void> { + pub fn wait_alarm(&mut self) -> nb::Result<(), Infallible> { if self.regs.crl.read().alrf().bit() == true { self.regs.crl.modify(|_, w| w.alrf().clear_bit()); Ok(()) diff --git a/src/serial.rs b/src/serial.rs index d0d3bc83..c25ca9f0 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -42,7 +42,7 @@ use core::sync::atomic::{self, Ordering}; use nb; use crate::pac::{USART1, USART2, USART3}; -use void::Void; +use core::convert::Infallible; use embedded_hal::serial::Write; use crate::afio::MAPR; @@ -388,7 +388,7 @@ macro_rules! hal { } impl crate::hal::serial::Write for Tx<$USARTX> { - type Error = Void; + type Error = Infallible; fn flush(&mut self) -> nb::Result<(), Self::Error> { // NOTE(unsafe) atomic read with no side effects