stm32/gpio: expose all functionality as inherent methods.
This commit is contained in:
parent
52e156b429
commit
58fc64722c
34 changed files with 266 additions and 210 deletions
|
@ -16,7 +16,6 @@ use embassy_stm32::{
|
|||
TxParams,
|
||||
},
|
||||
};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use lorawan_device::async_device::{
|
||||
radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig},
|
||||
Timings,
|
||||
|
@ -329,22 +328,22 @@ impl<'a> RadioSwitch<'a> {
|
|||
}
|
||||
|
||||
pub(crate) fn set_rx(&mut self) {
|
||||
self.ctrl1.set_high().unwrap();
|
||||
self.ctrl2.set_low().unwrap();
|
||||
self.ctrl3.set_high().unwrap();
|
||||
self.ctrl1.set_high();
|
||||
self.ctrl2.set_low();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
|
||||
pub(crate) fn set_tx_lp(&mut self) {
|
||||
self.ctrl1.set_high().unwrap();
|
||||
self.ctrl2.set_high().unwrap();
|
||||
self.ctrl3.set_high().unwrap();
|
||||
self.ctrl1.set_high();
|
||||
self.ctrl2.set_high();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn set_tx_hp(&mut self) {
|
||||
self.ctrl2.set_high().unwrap();
|
||||
self.ctrl1.set_low().unwrap();
|
||||
self.ctrl3.set_high().unwrap();
|
||||
self.ctrl2.set_high();
|
||||
self.ctrl1.set_low();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,17 +94,25 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> {
|
|||
pub fn new(pin: Input<'d, T>, _ch: impl Unborrow<Target = T::ExtiChannel> + 'd) -> Self {
|
||||
Self { pin }
|
||||
}
|
||||
|
||||
pub fn is_high(&self) -> bool {
|
||||
self.pin.is_high()
|
||||
}
|
||||
|
||||
pub fn is_low(&self) -> bool {
|
||||
self.pin.is_low()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
self.pin.is_high()
|
||||
Ok(self.is_high())
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
self.pin.is_low()
|
||||
Ok(self.is_low())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use core::convert::Infallible;
|
|||
use core::marker::PhantomData;
|
||||
use embassy::util::Unborrow;
|
||||
use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
|
||||
use embedded_hal::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin};
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
|
||||
|
||||
use crate::pac;
|
||||
use crate::pac::gpio::{self, vals};
|
||||
|
@ -113,6 +113,15 @@ impl<'d, T: Pin> Input<'d, T> {
|
|||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_high(&self) -> bool {
|
||||
!self.is_low()
|
||||
}
|
||||
|
||||
pub fn is_low(&self) -> bool {
|
||||
let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
|
||||
state == vals::Idr::LOW
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> Drop for Input<'d, T> {
|
||||
|
@ -132,19 +141,6 @@ impl<'d, T: Pin> Drop for Input<'d, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> InputPin for Input<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
self.is_low().map(|v| !v)
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
|
||||
Ok(state == vals::Idr::LOW)
|
||||
}
|
||||
}
|
||||
|
||||
/// Digital input or output level.
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
|
@ -191,6 +187,36 @@ impl<'d, T: Pin> Output<'d, T> {
|
|||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the output as high.
|
||||
pub fn set_high(&mut self) {
|
||||
self.pin.set_high();
|
||||
}
|
||||
|
||||
/// Set the output as low.
|
||||
pub fn set_low(&mut self) {
|
||||
self.pin.set_low();
|
||||
}
|
||||
|
||||
/// Is the output pin set as high?
|
||||
pub fn is_set_high(&self) -> bool {
|
||||
!self.is_set_low()
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
pub fn is_set_low(&self) -> bool {
|
||||
let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
|
||||
state == vals::Odr::LOW
|
||||
}
|
||||
|
||||
/// Toggle pin output
|
||||
pub fn toggle(&mut self) {
|
||||
if self.is_set_low() {
|
||||
self.set_high()
|
||||
} else {
|
||||
self.set_low()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> Drop for Output<'d, T> {
|
||||
|
@ -214,37 +240,6 @@ impl<'d, T: Pin> Drop for Output<'d, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> OutputPin for Output<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
/// Set the output as high.
|
||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||
self.pin.set_high();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the output as low.
|
||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||
self.pin.set_low();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
|
||||
/// Is the output pin set as high?
|
||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||
self.is_set_low().map(|v| !v)
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||
let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
|
||||
Ok(state == vals::Odr::LOW)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> toggleable::Default for Output<'d, T> {}
|
||||
|
||||
/// GPIO output open-drain driver.
|
||||
pub struct OutputOpenDrain<'d, T: Pin> {
|
||||
pub(crate) pin: T,
|
||||
|
@ -294,6 +289,45 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
|
|||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_high(&self) -> bool {
|
||||
!self.is_low()
|
||||
}
|
||||
|
||||
pub fn is_low(&self) -> bool {
|
||||
let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
|
||||
state == vals::Idr::LOW
|
||||
}
|
||||
|
||||
/// Set the output as high.
|
||||
pub fn set_high(&mut self) {
|
||||
self.pin.set_high();
|
||||
}
|
||||
|
||||
/// Set the output as low.
|
||||
pub fn set_low(&mut self) {
|
||||
self.pin.set_low();
|
||||
}
|
||||
|
||||
/// Is the output pin set as high?
|
||||
pub fn is_set_high(&self) -> bool {
|
||||
!self.is_set_low()
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
pub fn is_set_low(&self) -> bool {
|
||||
let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
|
||||
state == vals::Odr::LOW
|
||||
}
|
||||
|
||||
/// Toggle pin output
|
||||
pub fn toggle(&mut self) {
|
||||
if self.is_set_low() {
|
||||
self.set_high()
|
||||
} else {
|
||||
self.set_low()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
|
||||
|
@ -317,36 +351,6 @@ impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
/// Set the output as high.
|
||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||
self.pin.set_high();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the output as low.
|
||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||
self.pin.set_low();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> InputPin for OutputOpenDrain<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
self.is_low().map(|v| !v)
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
// NOTE(safety) Atomic read
|
||||
let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as usize) };
|
||||
Ok(state == vals::Idr::LOW)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod sealed {
|
||||
use super::*;
|
||||
|
||||
|
@ -612,3 +616,79 @@ pub(crate) unsafe fn init() {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
mod eh02 {
|
||||
use super::*;
|
||||
|
||||
impl<'d, T: Pin> InputPin for Input<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_high())
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> OutputPin for Output<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.set_high())
|
||||
}
|
||||
|
||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.set_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
|
||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_high())
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> {
|
||||
type Error = Infallible;
|
||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.toggle())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.set_high())
|
||||
}
|
||||
|
||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.set_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> StatefulOutputPin for OutputOpenDrain<'d, T> {
|
||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_high())
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> ToggleableOutputPin for OutputOpenDrain<'d, T> {
|
||||
type Error = Infallible;
|
||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.toggle())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ use defmt::assert;
|
|||
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(config = "config()")]
|
||||
|
@ -35,12 +34,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||
{
|
||||
let _a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
assert!(b.is_low());
|
||||
}
|
||||
{
|
||||
let _a = Output::new(&mut a, Level::High, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,38 +50,38 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||
|
||||
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
a.set_high().unwrap();
|
||||
assert!(b.is_low());
|
||||
a.set_high();
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
}
|
||||
|
||||
// Test input pulldown
|
||||
{
|
||||
let b = Input::new(&mut b, Pull::Down);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
assert!(b.is_low());
|
||||
|
||||
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
a.set_high().unwrap();
|
||||
assert!(b.is_low());
|
||||
a.set_high();
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
}
|
||||
|
||||
// Test input pullup
|
||||
{
|
||||
let b = Input::new(&mut b, Pull::Up);
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
|
||||
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
a.set_high().unwrap();
|
||||
assert!(b.is_low());
|
||||
a.set_high();
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
}
|
||||
|
||||
info!("Test OK");
|
||||
|
|
Loading…
Reference in a new issue