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]
@ -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);
}