stm32/gpio: expose all functionality as inherent methods.

This commit is contained in:
Dario Nieuwenhuis
2022-01-14 22:02:00 +01:00
parent 52e156b429
commit 58fc64722c
34 changed files with 266 additions and 210 deletions

View File

@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}

View File

@ -9,7 +9,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(1000)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(1000)).await;
}
}

View File

@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[entry]
@ -20,14 +19,14 @@ fn main() -> ! {
let mut led2 = Output::new(p.PE15, Level::High, Speed::Low);
loop {
if unwrap!(button.is_high()) {
if button.is_high() {
info!("high");
unwrap!(led1.set_high());
unwrap!(led2.set_low());
led1.set_high();
led2.set_low();
} else {
info!("low");
unwrap!(led1.set_low());
unwrap!(led2.set_high());
led1.set_low();
led2.set_high();
}
}
}

View File

@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}

View File

@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[entry]
@ -21,14 +20,14 @@ fn main() -> ! {
let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
loop {
if unwrap!(button.is_high()) {
if button.is_high() {
info!("high");
unwrap!(led1.set_high());
unwrap!(led3.set_low());
led1.set_high();
led3.set_low();
} else {
info!("low");
unwrap!(led1.set_low());
unwrap!(led3.set_high());
led1.set_low();
led3.set_high();
}
}
}

View File

@ -11,7 +11,6 @@ use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embedded_hal::blocking::spi::Transfer;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[entry]
@ -35,9 +34,9 @@ fn main() -> ! {
loop {
let mut buf = [0x0Au8; 4];
unwrap!(cs.set_low());
cs.set_low();
unwrap!(spi.transfer(&mut buf));
unwrap!(cs.set_high());
cs.set_high();
info!("xfer {=[u8]:x}", buf);
}
}

View File

@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}

View File

@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[entry]
@ -21,14 +20,14 @@ fn main() -> ! {
let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
loop {
if unwrap!(button.is_high()) {
if button.is_high() {
info!("high");
unwrap!(led1.set_high());
unwrap!(led3.set_low());
led1.set_high();
led3.set_low();
} else {
info!("low");
unwrap!(led1.set_low());
unwrap!(led3.set_high());
led1.set_low();
led3.set_high();
}
}
}

View File

@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}

View File

@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Pull};
use embedded_hal::digital::v2::InputPin;
use example_common::*;
#[entry]
@ -18,7 +17,7 @@ fn main() -> ! {
let button = Input::new(p.PC13, Pull::Up);
loop {
if unwrap!(button.is_high()) {
if button.is_high() {
info!("high");
} else {
info!("low");

View File

@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}

View File

@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Pull};
use embedded_hal::digital::v2::InputPin;
use example_common::*;
#[entry]
@ -18,7 +17,7 @@ fn main() -> ! {
let button = Input::new(p.PC13, Pull::Down);
loop {
if unwrap!(button.is_high()) {
if button.is_high() {
info!("high");
} else {
info!("low");

View File

@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}

View File

@ -11,7 +11,6 @@ use embassy_stm32::interrupt;
use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
use embassy_stm32::time::U32Ext;
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use defmt_rtt as _; // global logger
use panic_probe as _;
@ -114,11 +113,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
defmt::info!("main loop running");
loop {
defmt::info!("high");
defmt::unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(500)).await;
defmt::info!("low");
defmt::unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}

View File

@ -9,7 +9,6 @@ use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -22,11 +21,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}

View File

@ -10,7 +10,6 @@ use embassy::traits::rng::Random;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::rng::Rng;
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -23,11 +22,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high {}", unwrap!(rng.next_u8(16).await));
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low {}", unwrap!(rng.next_u8(16).await));
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}

View File

@ -9,7 +9,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}

View File

@ -7,7 +7,6 @@ mod example_common;
use embassy::executor::Spawner;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[embassy::main]
@ -19,14 +18,14 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let mut led2 = Output::new(p.PB5, Level::High, Speed::Low);
loop {
if unwrap!(button.is_high()) {
if button.is_high() {
info!("high");
unwrap!(led1.set_high());
unwrap!(led2.set_low());
led1.set_high();
led2.set_low();
} else {
info!("low");
unwrap!(led1.set_low());
unwrap!(led2.set_high());
led1.set_low();
led2.set_high();
}
}
}

View File

@ -7,7 +7,6 @@ mod example_common;
use embassy::executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
use embassy_stm32::dma::NoDma;
@ -35,9 +34,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
let mut buf = [0x0Au8; 4];
unwrap!(cs.set_low());
cs.set_low();
unwrap!(spi.transfer(&mut buf));
unwrap!(cs.set_high());
cs.set_high();
info!("xfer {=[u8]:x}", buf);
}
}

View File

@ -9,7 +9,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(1000)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(1000)).await;
}
}

View File

@ -7,7 +7,6 @@ mod example_common;
use embassy::executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
use embassy_stm32::dma::NoDma;
@ -35,9 +34,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
let mut buf = [0x0Au8; 4];
unwrap!(cs.set_low());
cs.set_low();
unwrap!(spi.transfer(&mut buf));
unwrap!(cs.set_high());
cs.set_high();
info!("xfer {=[u8]:x}", buf);
}
}

View File

@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -18,9 +17,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let mut led = Output::new(p.PB14, Level::High, Speed::Low);
loop {
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(300)).await;
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}

View File

@ -5,7 +5,6 @@
#[path = "../example_common.rs"]
mod example_common;
use embassy_stm32::gpio::{Input, Pull};
use embedded_hal::digital::v2::InputPin;
use example_common::*;
#[cortex_m_rt::entry]
@ -17,7 +16,7 @@ fn main() -> ! {
let button = Input::new(p.PC13, Pull::Up);
loop {
if unwrap!(button.is_high()) {
if button.is_high() {
info!("high");
} else {
info!("low");

View File

@ -10,7 +10,6 @@ use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embedded_hal::blocking::spi::Transfer;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[cortex_m_rt::entry]
@ -34,9 +33,9 @@ fn main() -> ! {
loop {
let mut buf = [0x0Au8; 4];
unwrap!(cs.set_low());
cs.set_low();
unwrap!(spi.transfer(&mut buf));
unwrap!(cs.set_high());
cs.set_high();
info!("xfer {=[u8]:x}", buf);
}
}

View File

@ -12,7 +12,6 @@ use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embassy_stm32::Peripherals;
use embassy_traits::{adapter::BlockingAsync, spi::FullDuplex};
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[embassy::main]
@ -41,17 +40,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let ready = Input::new(p.PE1, Pull::Up);
cortex_m::asm::delay(100_000);
unwrap!(reset.set_high());
reset.set_high();
cortex_m::asm::delay(100_000);
while unwrap!(ready.is_low()) {
while ready.is_low() {
info!("waiting for ready");
}
let write = [0x0A; 10];
let mut read = [0; 10];
unwrap!(cs.set_low());
cs.set_low();
spi.read_write(&mut read, &write).await.ok();
unwrap!(cs.set_high());
cs.set_high();
info!("xfer {=[u8]:x}", read);
}

View File

@ -11,7 +11,6 @@ use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embassy_stm32::Peripherals;
use embassy_traits::spi::FullDuplex;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[embassy::main]
@ -38,17 +37,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let ready = Input::new(p.PE1, Pull::Up);
cortex_m::asm::delay(100_000);
unwrap!(reset.set_high());
reset.set_high();
cortex_m::asm::delay(100_000);
while unwrap!(ready.is_low()) {
while ready.is_low() {
info!("waiting for ready");
}
let write = [0x0A; 10];
let mut read = [0; 10];
unwrap!(cs.set_low());
cs.set_low();
spi.read_write(&mut read, &write).await.ok();
unwrap!(cs.set_high());
cs.set_high();
info!("xfer {=[u8]:x}", read);
}

View File

@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}

View File

@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
unwrap!(led.set_high());
led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low");
unwrap!(led.set_low());
led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}

View File

@ -5,7 +5,6 @@
#[path = "../example_common.rs"]
mod example_common;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
use cortex_m_rt::entry;
@ -21,12 +20,12 @@ fn main() -> ! {
let mut led2 = Output::new(p.PB9, Level::High, Speed::Low);
loop {
if button.is_high().unwrap() {
led1.set_high().unwrap();
led2.set_low().unwrap();
if button.is_high() {
led1.set_high();
led2.set_low();
} else {
led1.set_low().unwrap();
led2.set_high().unwrap();
led1.set_low();
led2.set_high();
}
}
}

View File

@ -17,7 +17,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::interrupt;
use embassy_stm32::subghz::*;
use embassy_stm32::Peripherals;
use embedded_hal::digital::v2::OutputPin;
use example_common::unwrap;
const PING_DATA: &str = "PING";
@ -89,9 +88,9 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
defmt::info!("Radio ready for use");
unwrap!(led1.set_low());
led1.set_low();
unwrap!(led2.set_high());
led2.set_high();
unwrap!(radio.set_standby(StandbyClk::Rc));
unwrap!(radio.set_tcxo_mode(&TCXO_MODE));
@ -110,11 +109,11 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
defmt::info!("Status: {:?}", unwrap!(radio.status()));
unwrap!(led2.set_low());
led2.set_low();
loop {
pin.wait_for_rising_edge().await;
unwrap!(led3.set_high());
led3.set_high();
unwrap!(radio.set_irq_cfg(&CfgIrq::new().irq_enable_all(Irq::TxDone)));
unwrap!(radio.write_buffer(TX_BUF_OFFSET, PING_DATA_BYTES));
unwrap!(radio.set_tx(Timeout::DISABLED));
@ -127,6 +126,6 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
defmt::info!("TX done");
}
unwrap!(radio.clear_irq_status(irq_status));
unwrap!(led3.set_low());
led3.set_low();
}
}