Skip to content

Commit 9ac0bb4

Browse files
burrbullTheZoq2
authored andcommitted
Replace void with Infallible (#100)
1 parent 420243a commit 9ac0bb4

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616

1717
### Breaking changes
1818

19+
- `void::Void` replaced with `Infallible` where it is possible
1920
- Change timer/pwm init API
2021
- Remove `set_low` and `set_high` for pins in Alternate output mode
2122
- Renames `set_seconds` and `seconds` methods on RTC to `set_time` and `current_time`, respectively

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ fn main() -> ! {
110110
// in order to configure the port. For pins 0-7, crl should be passed instead.
111111
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
112112
// Configure the syst timer to trigger an update every second
113-
let mut timer = Timer::syst(cp.SYST, 1.hz(), clocks);
113+
let mut timer = Timer::syst(cp.SYST, clocks)
114+
.start_count_down(1.hz());
114115

115116
// Wait for the timer to trigger an update and change the state of the LED
116117
loop {
117118
block!(timer.wait()).unwrap();
118-
led.set_high();
119+
led.set_high().unwrap();
119120
block!(timer.wait()).unwrap();
120-
led.set_low();
121+
led.set_low().unwrap();
121122
}
122123
}
123124
```

src/gpio.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ macro_rules! gpio {
7777
]) => {
7878
/// GPIO
7979
pub mod $gpiox {
80-
use void::Void;
80+
use core::convert::Infallible;
8181
use core::marker::PhantomData;
8282

8383
use crate::hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, toggleable};
@@ -164,7 +164,7 @@ macro_rules! gpio {
164164
}
165165

166166
impl<MODE> OutputPin for Generic<Output<MODE>> {
167-
type Error = Void;
167+
type Error = Infallible;
168168
fn set_high(&mut self) -> Result<(), Self::Error> {
169169
// NOTE(unsafe) atomic write to a stateless register
170170
Ok(unsafe { (*$GPIOX::ptr()).bsrr.write(|w| w.bits(1 << self.i)) })
@@ -177,7 +177,7 @@ macro_rules! gpio {
177177
}
178178

179179
impl<MODE> InputPin for Generic<Input<MODE>> {
180-
type Error = Void;
180+
type Error = Infallible;
181181
fn is_high(&self) -> Result<bool, Self::Error> {
182182
self.is_low().map(|b| !b)
183183
}
@@ -202,7 +202,7 @@ macro_rules! gpio {
202202
impl <MODE> toggleable::Default for Generic<Output<MODE>> {}
203203

204204
impl InputPin for Generic<Output<OpenDrain>> {
205-
type Error = Void;
205+
type Error = Infallible;
206206
fn is_high(&self) -> Result<bool, Self::Error> {
207207
self.is_low().map(|b| !b)
208208
}
@@ -470,7 +470,7 @@ macro_rules! gpio {
470470
}
471471

472472
impl<MODE> OutputPin for $PXi<Output<MODE>> {
473-
type Error = Void;
473+
type Error = Infallible;
474474
fn set_high(&mut self) -> Result<(), Self::Error> {
475475
// NOTE(unsafe) atomic write to a stateless register
476476
Ok(unsafe { (*$GPIOX::ptr()).bsrr.write(|w| w.bits(1 << $i)) })
@@ -496,7 +496,7 @@ macro_rules! gpio {
496496
impl<MODE> toggleable::Default for $PXi<Output<MODE>> {}
497497

498498
impl<MODE> InputPin for $PXi<Input<MODE>> {
499-
type Error = Void;
499+
type Error = Infallible;
500500
fn is_high(&self) -> Result<bool, Self::Error> {
501501
self.is_low().map(|b| !b)
502502
}
@@ -508,7 +508,7 @@ macro_rules! gpio {
508508
}
509509

510510
impl InputPin for $PXi<Output<OpenDrain>> {
511-
type Error = Void;
511+
type Error = Infallible;
512512
fn is_high(&self) -> Result<bool, Self::Error> {
513513
self.is_low().map(|b| !b)
514514
}
@@ -525,8 +525,8 @@ macro_rules! gpio {
525525

526526
macro_rules! impl_pxx {
527527
($(($port:ident :: $pin:ident)),*) => {
528-
use void::Void;
529528
use embedded_hal::digital::v2::{InputPin, StatefulOutputPin, OutputPin};
529+
use core::convert::Infallible;
530530

531531
pub enum Pxx<MODE> {
532532
$(
@@ -535,14 +535,14 @@ macro_rules! impl_pxx {
535535
}
536536

537537
impl<MODE> OutputPin for Pxx<Output<MODE>> {
538-
type Error = Void;
539-
fn set_high(&mut self) -> Result<(), Void> {
538+
type Error = Infallible;
539+
fn set_high(&mut self) -> Result<(), Infallible> {
540540
match self {
541541
$(Pxx::$pin(pin) => pin.set_high()),*
542542
}
543543
}
544544

545-
fn set_low(&mut self) -> Result<(), Void> {
545+
fn set_low(&mut self) -> Result<(), Infallible> {
546546
match self {
547547
$(Pxx::$pin(pin) => pin.set_low()),*
548548
}
@@ -564,14 +564,14 @@ macro_rules! impl_pxx {
564564
}
565565

566566
impl<MODE> InputPin for Pxx<Input<MODE>> {
567-
type Error = Void;
568-
fn is_high(&self) -> Result<bool, Void> {
567+
type Error = Infallible;
568+
fn is_high(&self) -> Result<bool, Infallible> {
569569
match self {
570570
$(Pxx::$pin(pin) => pin.is_high()),*
571571
}
572572
}
573573

574-
fn is_low(&self) -> Result<bool, Void> {
574+
fn is_low(&self) -> Result<bool, Infallible> {
575575
match self {
576576
$(Pxx::$pin(pin) => pin.is_low()),*
577577
}

src/rtc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::backup_domain::BackupDomain;
1818
use crate::time::Hertz;
1919

2020
use nb;
21-
use void::Void;
21+
use core::convert::Infallible;
2222

2323
// The LSE runs at at 32 768 hertz unless an external clock is provided
2424
const LSE_HERTZ: u32 = 32_768;
@@ -170,11 +170,11 @@ impl Rtc {
170170
use nb::block;
171171
172172
rtc.set_alarm(rtc.read_counts() + 5);
173-
// NOTE: Safe unwrap because Void can't be returned
173+
// NOTE: Safe unwrap because Infallible can't be returned
174174
block!(rtc.wait_alarm()).unwrap();
175175
```
176176
*/
177-
pub fn wait_alarm(&mut self) -> nb::Result<(), Void> {
177+
pub fn wait_alarm(&mut self) -> nb::Result<(), Infallible> {
178178
if self.regs.crl.read().alrf().bit() == true {
179179
self.regs.crl.modify(|_, w| w.alrf().clear_bit());
180180
Ok(())

src/serial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use core::sync::atomic::{self, Ordering};
4242

4343
use nb;
4444
use crate::pac::{USART1, USART2, USART3};
45-
use void::Void;
45+
use core::convert::Infallible;
4646
use embedded_hal::serial::Write;
4747

4848
use crate::afio::MAPR;
@@ -388,7 +388,7 @@ macro_rules! hal {
388388
}
389389

390390
impl crate::hal::serial::Write<u8> for Tx<$USARTX> {
391-
type Error = Void;
391+
type Error = Infallible;
392392

393393
fn flush(&mut self) -> nb::Result<(), Self::Error> {
394394
// NOTE(unsafe) atomic read with no side effects

0 commit comments

Comments
 (0)