diff --git a/examples/blinky.rs b/examples/blinky.rs
index 05a0a6fb..35c8caeb 100644
--- a/examples/blinky.rs
+++ b/examples/blinky.rs
@@ -29,12 +29,12 @@ fn main() -> ! {
loop {
info!("Set Led low");
for _ in 0..10_000_000 {
- led.set_low().unwrap();
+ led.set_low();
}
info!("Set Led High");
for _ in 0..10_000_000 {
- led.set_high().unwrap();
+ led.set_high();
}
}
}
diff --git a/examples/blinky_delay.rs b/examples/blinky_delay.rs
index 8b55119f..35e9b5ea 100644
--- a/examples/blinky_delay.rs
+++ b/examples/blinky_delay.rs
@@ -40,11 +40,11 @@ fn main() -> ! {
loop {
info!("Toggle");
- led.toggle().unwrap();
+ led.toggle();
info!("SYST delay");
delay_syst.delay(1000.millis());
info!("Toggle");
- led.toggle().unwrap();
+ led.toggle();
info!("TIM2 delay");
delay_tim2.delay_ms(1000);
}
diff --git a/examples/button.rs b/examples/button.rs
index 7064e363..766cf33a 100644
--- a/examples/button.rs
+++ b/examples/button.rs
@@ -14,7 +14,6 @@ use core::cell::RefCell;
use core::sync::atomic::{AtomicBool, Ordering};
use cortex_m::{asm::wfi, interrupt::Mutex};
use cortex_m_rt::entry;
-use embedded_hal::digital::OutputPin;
type ButtonPin = gpio::PC13>;
@@ -86,10 +85,10 @@ fn main() -> ! {
if G_LED_ON.load(Ordering::Relaxed) {
println!("Turn Led On!");
- led.set_high().unwrap();
+ led.set_high();
} else {
println!("Turn Led Off!");
- led.set_low().unwrap();
+ led.set_low();
}
}
}
diff --git a/examples/can-echo.rs b/examples/can-echo.rs
index 3126e0d4..5301ad8a 100644
--- a/examples/can-echo.rs
+++ b/examples/can-echo.rs
@@ -57,8 +57,8 @@ fn main() -> ! {
let can1 = {
info!("Init CAN 1");
- let rx = gpiob.pb8.into_alternate().set_speed(Speed::VeryHigh);
- let tx = gpiob.pb9.into_alternate().set_speed(Speed::VeryHigh);
+ let rx = gpiob.pb8.into_alternate().speed(Speed::VeryHigh);
+ let tx = gpiob.pb9.into_alternate().speed(Speed::VeryHigh);
info!("-- Create CAN 1 instance");
let mut can = dp.FDCAN1.fdcan(tx, rx, &rcc);
@@ -82,8 +82,8 @@ fn main() -> ! {
// let can2 = {
// info!("Init CAN 2");
- // let rx = gpiob.pb5.into_alternate().set_speed(Speed::VeryHigh);
- // let tx = gpiob.pb13.into_alternate().set_speed(Speed::VeryHigh);
+ // let rx = gpiob.pb5.into_alternate().speed(Speed::VeryHigh);
+ // let tx = gpiob.pb13.into_alternate().speed(Speed::VeryHigh);
// info!("-- Create CAN 2 instance");
// let mut can = dp.FDCAN2.fdcan(tx, rx, &rcc);
diff --git a/examples/comp.rs b/examples/comp.rs
index e06635ec..1b4deb5a 100644
--- a/examples/comp.rs
+++ b/examples/comp.rs
@@ -17,7 +17,6 @@ use rt::entry;
fn main() -> ! {
use hal::comparator::{refint_input, ComparatorExt, ComparatorSplit, Config, Hysteresis};
use hal::gpio::GpioExt;
- use hal::prelude::OutputPin;
use hal::rcc::RccExt;
use hal::stm32;
use stm32g4xx_hal as hal;
@@ -55,8 +54,8 @@ fn main() -> ! {
loop {
// Read comp1 output and update led1 accordingly
match comp1.output() {
- true => led1.set_high().unwrap(),
- false => led1.set_low().unwrap(),
+ true => led1.set_high(),
+ false => led1.set_low(),
}
}
}
diff --git a/examples/spi-example.rs b/examples/spi-example.rs
index 33b86c2b..34194167 100644
--- a/examples/spi-example.rs
+++ b/examples/spi-example.rs
@@ -45,7 +45,7 @@ fn main() -> ! {
.SPI1
.spi((sclk, miso, mosi), spi::MODE_0, 400.kHz(), &mut rcc);
let mut cs = gpioa.pa8.into_push_pull_output();
- cs.set_high().unwrap();
+ cs.set_high();
// "Hello world!"
let message = b"Hello world!";
@@ -53,10 +53,10 @@ fn main() -> ! {
loop {
for &byte in message {
- cs.set_low().unwrap();
+ cs.set_low();
spi.send(byte).unwrap();
received_byte = nb::block!(FullDuplex::read(&mut spi)).unwrap();
- cs.set_high().unwrap();
+ cs.set_high();
info!("{}", received_byte as char);
}
diff --git a/examples/spi-sd.rs b/examples/spi-sd.rs
index 6a98d877..89305077 100644
--- a/examples/spi-sd.rs
+++ b/examples/spi-sd.rs
@@ -35,7 +35,7 @@ fn main() -> ! {
let cs = {
let mut cs = gpiof.pf8.into_push_pull_output();
- cs.set_high().unwrap();
+ cs.set_high();
cs
};
diff --git a/examples/uart-dma-tx.rs b/examples/uart-dma-tx.rs
index 544e84ec..c52b10e6 100644
--- a/examples/uart-dma-tx.rs
+++ b/examples/uart-dma-tx.rs
@@ -75,7 +75,7 @@ fn main() -> ! {
while !transfer.get_transfer_complete_flag() {}
delay_syst.delay(1000.millis());
- led.toggle().unwrap();
+ led.toggle();
transfer.restart(|_tx| {});
}
}
diff --git a/examples/usb_serial.rs b/examples/usb_serial.rs
index 59e43328..96cc320e 100644
--- a/examples/usb_serial.rs
+++ b/examples/usb_serial.rs
@@ -31,7 +31,7 @@ fn main() -> ! {
let gpioa = dp.GPIOA.split(&mut rcc);
let mut led = gpioa.pa5.into_push_pull_output();
- led.set_low().ok();
+ led.set_low();
let usb_dm = gpioa.pa11.into_alternate();
let usb_dp = gpioa.pa12.into_alternate();
@@ -63,7 +63,7 @@ fn main() -> ! {
match serial.read(&mut buf) {
Ok(count) if count > 0 => {
- led.set_high().ok();
+ led.set_high();
// Echo back in upper case
for c in buf[0..count].iter_mut() {
@@ -85,6 +85,6 @@ fn main() -> ! {
_ => {}
}
- led.set_low().ok();
+ led.set_low();
}
}
diff --git a/src/gpio.rs b/src/gpio.rs
index dddf0af1..9f374b0d 100644
--- a/src/gpio.rs
+++ b/src/gpio.rs
@@ -5,6 +5,8 @@ use crate::rcc::{Enable, Rcc, Reset};
use crate::stm32::EXTI;
use crate::syscfg::SysCfg;
+use crate::pac;
+
/// Default pin mode
pub type DefaultMode = Input;
@@ -49,17 +51,39 @@ pub struct Output {
pub struct PushPull;
/// GPIO Pin speed selection
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Speed {
+ /// Low speed
Low = 0,
+ /// Medium speed
Medium = 1,
+ /// High speed
High = 2,
+ /// Very high speed
VeryHigh = 3,
}
-/// Trigger edgw
+impl From for pac::gpioa::ospeedr::OUTPUT_SPEED {
+ fn from(value: Speed) -> Self {
+ match value {
+ Speed::Low => Self::LowSpeed,
+ Speed::Medium => Self::MediumSpeed,
+ Speed::High => Self::HighSpeed,
+ Speed::VeryHigh => Self::VeryHighSpeed,
+ }
+ }
+}
+
+/// GPIO interrupt trigger edge selection
+#[cfg_attr(feature = "defmt", derive(defmt::Format))]
+#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SignalEdge {
+ /// Rising edge of voltage
Rising,
+ /// Falling edge of voltage
Falling,
+ /// Rising and falling edge of voltage
RisingFalling,
}
@@ -250,7 +274,6 @@ macro_rules! gpio {
/// GPIO
pub mod $gpiox {
use core::marker::PhantomData;
- use embedded_hal_old::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin};
use crate::stm32::{EXTI, $GPIOX};
use crate::exti::{ExtiExt, Event};
use crate::rcc::Rcc;
@@ -284,126 +307,150 @@ macro_rules! gpio {
_mode: PhantomData,
}
- impl OutputPin for $PXx