Support unstable-trait feature for stm32

This commit is contained in:
Ulf Lilleengen
2022-01-26 22:39:06 +01:00
parent cd36e3f733
commit 4032fc0655
32 changed files with 604 additions and 673 deletions

View File

@ -18,6 +18,8 @@ log = { version = "0.4.14", optional = true }
embassy = { version = "0.1.0", path = "../embassy", default-features = false }
embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true }
embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.6", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true}
embedded-hal-async = { version = "0.0.1", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy"}
embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common", default-features = false }
futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] }
embedded-hal = { version = "0.2", features = ["unproven"] }

View File

@ -1,7 +1,7 @@
use core::future::Future;
use embassy::traits::gpio::WaitForRisingEdge;
use embassy::traits::spi::*;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal_async::digital::Wait;
use embedded_hal_async::spi::*;
use lorawan_device::async_device::{
radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig},
Timings,
@ -20,11 +20,11 @@ pub trait RadioSwitch {
/// Semtech Sx127x radio peripheral
pub struct Sx127xRadio<SPI, CS, RESET, E, I, RFS>
where
SPI: FullDuplex<u8, Error = E> + 'static,
SPI: ReadWrite<u8, Error = E> + 'static,
E: 'static,
CS: OutputPin + 'static,
RESET: OutputPin + 'static,
I: WaitForRisingEdge + 'static,
I: Wait + 'static,
RFS: RadioSwitch + 'static,
{
radio: LoRa<SPI, CS, RESET>,
@ -42,10 +42,10 @@ pub enum State {
impl<SPI, CS, RESET, E, I, RFS> Sx127xRadio<SPI, CS, RESET, E, I, RFS>
where
SPI: FullDuplex<u8, Error = E> + 'static,
SPI: ReadWrite<u8, Error = E> + 'static,
CS: OutputPin + 'static,
RESET: OutputPin + 'static,
I: WaitForRisingEdge + 'static,
I: Wait + 'static,
RFS: RadioSwitch + 'static,
E: 'static,
{
@ -64,10 +64,10 @@ where
impl<SPI, CS, RESET, E, I, RFS> Timings for Sx127xRadio<SPI, CS, RESET, E, I, RFS>
where
SPI: FullDuplex<u8, Error = E> + 'static,
SPI: ReadWrite<u8, Error = E> + 'static,
CS: OutputPin + 'static,
RESET: OutputPin + 'static,
I: WaitForRisingEdge + 'static,
I: Wait + 'static,
RFS: RadioSwitch + 'static,
{
fn get_rx_window_offset_ms(&self) -> i32 {
@ -80,11 +80,11 @@ where
impl<SPI, CS, RESET, E, I, RFS> PhyRxTx for Sx127xRadio<SPI, CS, RESET, E, I, RFS>
where
SPI: FullDuplex<u8, Error = E> + 'static,
SPI: ReadWrite<u8, Error = E> + 'static,
CS: OutputPin + 'static,
E: 'static,
RESET: OutputPin + 'static,
I: WaitForRisingEdge + 'static,
I: Wait + 'static,
RFS: RadioSwitch + 'static,
{
type PhyError = Sx127xError;
@ -126,7 +126,7 @@ where
self.radio.transmit_start(buf).await?;
loop {
self.irq.wait_for_rising_edge().await;
self.irq.wait_for_rising_edge().await.unwrap();
self.radio.set_mode(RadioMode::Stdby).await.ok().unwrap();
let irq = self.radio.clear_irq().await.ok().unwrap();
if (irq & IRQ::IrqTxDoneMask.addr()) != 0 {
@ -171,7 +171,7 @@ where
self.radio.set_mode(RadioMode::RxContinuous).await?;
loop {
self.irq.wait_for_rising_edge().await;
self.irq.wait_for_rising_edge().await.unwrap();
self.radio.set_mode(RadioMode::Stdby).await.ok().unwrap();
let irq = self.radio.clear_irq().await.ok().unwrap();
if (irq & IRQ::IrqRxDoneMask.addr()) != 0 {

View File

@ -7,8 +7,8 @@
use bit_field::BitField;
use embassy::time::{Duration, Timer};
use embassy::traits::spi::*;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal_async::spi::ReadWrite;
mod register;
use self::register::PaConfig;
@ -36,9 +36,10 @@ pub enum Error<SPI, CS, RESET> {
Transmitting,
}
use super::sx127x_lora::register::{FskDataModulationShaping, FskRampUpRamDown};
use Error::*;
use super::sx127x_lora::register::{FskDataModulationShaping, FskRampUpRamDown};
#[cfg(not(feature = "version_0x09"))]
const VERSION_CHECK: u8 = 0x12;
@ -47,7 +48,7 @@ const VERSION_CHECK: u8 = 0x09;
impl<SPI, CS, RESET, E> LoRa<SPI, CS, RESET>
where
SPI: FullDuplex<u8, Error = E>,
SPI: ReadWrite<u8, Error = E>,
CS: OutputPin,
RESET: OutputPin,
{
@ -546,7 +547,7 @@ where
let _ = self
.spi
.read_write(&mut buffer, &[reg & 0x7f, 0])
.transfer(&mut buffer, &[reg & 0x7f, 0])
.await
.map_err(SPI)?;