diff options
| author | Ulf Lilleengen <[email protected]> | 2022-01-26 22:39:06 +0100 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-01-26 22:39:06 +0100 |
| commit | 4032fc06556312eab27488f05efe1803ade47b45 (patch) | |
| tree | 0b38343758741e5c4074e86da30867595501f9b6 /embassy-lora | |
| parent | cd36e3f7332d08865e670ca5b515d1c6efa1bf85 (diff) | |
Support unstable-trait feature for stm32
Diffstat (limited to 'embassy-lora')
| -rw-r--r-- | embassy-lora/Cargo.toml | 2 | ||||
| -rw-r--r-- | embassy-lora/src/sx127x/mod.rs | 24 | ||||
| -rw-r--r-- | embassy-lora/src/sx127x/sx127x_lora/mod.rs | 9 |
3 files changed, 19 insertions, 16 deletions
diff --git a/embassy-lora/Cargo.toml b/embassy-lora/Cargo.toml index 9f04adabb..c27641521 100644 --- a/embassy-lora/Cargo.toml +++ b/embassy-lora/Cargo.toml | |||
| @@ -18,6 +18,8 @@ log = { version = "0.4.14", optional = true } | |||
| 18 | 18 | ||
| 19 | embassy = { version = "0.1.0", path = "../embassy", default-features = false } | 19 | embassy = { version = "0.1.0", path = "../embassy", default-features = false } |
| 20 | embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } | 20 | embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } |
| 21 | embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.6", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy", optional = true} | ||
| 22 | embedded-hal-async = { version = "0.0.1", git = "https://github.com/embassy-rs/embedded-hal", branch = "embassy"} | ||
| 21 | embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common", default-features = false } | 23 | embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common", default-features = false } |
| 22 | futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } | 24 | futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } |
| 23 | embedded-hal = { version = "0.2", features = ["unproven"] } | 25 | embedded-hal = { version = "0.2", features = ["unproven"] } |
diff --git a/embassy-lora/src/sx127x/mod.rs b/embassy-lora/src/sx127x/mod.rs index c26628b0f..6a15dab82 100644 --- a/embassy-lora/src/sx127x/mod.rs +++ b/embassy-lora/src/sx127x/mod.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | use embassy::traits::gpio::WaitForRisingEdge; | ||
| 3 | use embassy::traits::spi::*; | ||
| 4 | use embedded_hal::digital::v2::OutputPin; | 2 | use embedded_hal::digital::v2::OutputPin; |
| 3 | use embedded_hal_async::digital::Wait; | ||
| 4 | use embedded_hal_async::spi::*; | ||
| 5 | use lorawan_device::async_device::{ | 5 | use lorawan_device::async_device::{ |
| 6 | radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}, | 6 | radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}, |
| 7 | Timings, | 7 | Timings, |
| @@ -20,11 +20,11 @@ pub trait RadioSwitch { | |||
| 20 | /// Semtech Sx127x radio peripheral | 20 | /// Semtech Sx127x radio peripheral |
| 21 | pub struct Sx127xRadio<SPI, CS, RESET, E, I, RFS> | 21 | pub struct Sx127xRadio<SPI, CS, RESET, E, I, RFS> |
| 22 | where | 22 | where |
| 23 | SPI: FullDuplex<u8, Error = E> + 'static, | 23 | SPI: ReadWrite<u8, Error = E> + 'static, |
| 24 | E: 'static, | 24 | E: 'static, |
| 25 | CS: OutputPin + 'static, | 25 | CS: OutputPin + 'static, |
| 26 | RESET: OutputPin + 'static, | 26 | RESET: OutputPin + 'static, |
| 27 | I: WaitForRisingEdge + 'static, | 27 | I: Wait + 'static, |
| 28 | RFS: RadioSwitch + 'static, | 28 | RFS: RadioSwitch + 'static, |
| 29 | { | 29 | { |
| 30 | radio: LoRa<SPI, CS, RESET>, | 30 | radio: LoRa<SPI, CS, RESET>, |
| @@ -42,10 +42,10 @@ pub enum State { | |||
| 42 | 42 | ||
| 43 | impl<SPI, CS, RESET, E, I, RFS> Sx127xRadio<SPI, CS, RESET, E, I, RFS> | 43 | impl<SPI, CS, RESET, E, I, RFS> Sx127xRadio<SPI, CS, RESET, E, I, RFS> |
| 44 | where | 44 | where |
| 45 | SPI: FullDuplex<u8, Error = E> + 'static, | 45 | SPI: ReadWrite<u8, Error = E> + 'static, |
| 46 | CS: OutputPin + 'static, | 46 | CS: OutputPin + 'static, |
| 47 | RESET: OutputPin + 'static, | 47 | RESET: OutputPin + 'static, |
| 48 | I: WaitForRisingEdge + 'static, | 48 | I: Wait + 'static, |
| 49 | RFS: RadioSwitch + 'static, | 49 | RFS: RadioSwitch + 'static, |
| 50 | E: 'static, | 50 | E: 'static, |
| 51 | { | 51 | { |
| @@ -64,10 +64,10 @@ where | |||
| 64 | 64 | ||
| 65 | impl<SPI, CS, RESET, E, I, RFS> Timings for Sx127xRadio<SPI, CS, RESET, E, I, RFS> | 65 | impl<SPI, CS, RESET, E, I, RFS> Timings for Sx127xRadio<SPI, CS, RESET, E, I, RFS> |
| 66 | where | 66 | where |
| 67 | SPI: FullDuplex<u8, Error = E> + 'static, | 67 | SPI: ReadWrite<u8, Error = E> + 'static, |
| 68 | CS: OutputPin + 'static, | 68 | CS: OutputPin + 'static, |
| 69 | RESET: OutputPin + 'static, | 69 | RESET: OutputPin + 'static, |
| 70 | I: WaitForRisingEdge + 'static, | 70 | I: Wait + 'static, |
| 71 | RFS: RadioSwitch + 'static, | 71 | RFS: RadioSwitch + 'static, |
| 72 | { | 72 | { |
| 73 | fn get_rx_window_offset_ms(&self) -> i32 { | 73 | fn get_rx_window_offset_ms(&self) -> i32 { |
| @@ -80,11 +80,11 @@ where | |||
| 80 | 80 | ||
| 81 | impl<SPI, CS, RESET, E, I, RFS> PhyRxTx for Sx127xRadio<SPI, CS, RESET, E, I, RFS> | 81 | impl<SPI, CS, RESET, E, I, RFS> PhyRxTx for Sx127xRadio<SPI, CS, RESET, E, I, RFS> |
| 82 | where | 82 | where |
| 83 | SPI: FullDuplex<u8, Error = E> + 'static, | 83 | SPI: ReadWrite<u8, Error = E> + 'static, |
| 84 | CS: OutputPin + 'static, | 84 | CS: OutputPin + 'static, |
| 85 | E: 'static, | 85 | E: 'static, |
| 86 | RESET: OutputPin + 'static, | 86 | RESET: OutputPin + 'static, |
| 87 | I: WaitForRisingEdge + 'static, | 87 | I: Wait + 'static, |
| 88 | RFS: RadioSwitch + 'static, | 88 | RFS: RadioSwitch + 'static, |
| 89 | { | 89 | { |
| 90 | type PhyError = Sx127xError; | 90 | type PhyError = Sx127xError; |
| @@ -126,7 +126,7 @@ where | |||
| 126 | self.radio.transmit_start(buf).await?; | 126 | self.radio.transmit_start(buf).await?; |
| 127 | 127 | ||
| 128 | loop { | 128 | loop { |
| 129 | self.irq.wait_for_rising_edge().await; | 129 | self.irq.wait_for_rising_edge().await.unwrap(); |
| 130 | self.radio.set_mode(RadioMode::Stdby).await.ok().unwrap(); | 130 | self.radio.set_mode(RadioMode::Stdby).await.ok().unwrap(); |
| 131 | let irq = self.radio.clear_irq().await.ok().unwrap(); | 131 | let irq = self.radio.clear_irq().await.ok().unwrap(); |
| 132 | if (irq & IRQ::IrqTxDoneMask.addr()) != 0 { | 132 | if (irq & IRQ::IrqTxDoneMask.addr()) != 0 { |
| @@ -171,7 +171,7 @@ where | |||
| 171 | self.radio.set_mode(RadioMode::RxContinuous).await?; | 171 | self.radio.set_mode(RadioMode::RxContinuous).await?; |
| 172 | 172 | ||
| 173 | loop { | 173 | loop { |
| 174 | self.irq.wait_for_rising_edge().await; | 174 | self.irq.wait_for_rising_edge().await.unwrap(); |
| 175 | self.radio.set_mode(RadioMode::Stdby).await.ok().unwrap(); | 175 | self.radio.set_mode(RadioMode::Stdby).await.ok().unwrap(); |
| 176 | let irq = self.radio.clear_irq().await.ok().unwrap(); | 176 | let irq = self.radio.clear_irq().await.ok().unwrap(); |
| 177 | if (irq & IRQ::IrqRxDoneMask.addr()) != 0 { | 177 | if (irq & IRQ::IrqRxDoneMask.addr()) != 0 { |
diff --git a/embassy-lora/src/sx127x/sx127x_lora/mod.rs b/embassy-lora/src/sx127x/sx127x_lora/mod.rs index a903779ca..6fbd3a4bd 100644 --- a/embassy-lora/src/sx127x/sx127x_lora/mod.rs +++ b/embassy-lora/src/sx127x/sx127x_lora/mod.rs | |||
| @@ -7,8 +7,8 @@ | |||
| 7 | 7 | ||
| 8 | use bit_field::BitField; | 8 | use bit_field::BitField; |
| 9 | use embassy::time::{Duration, Timer}; | 9 | use embassy::time::{Duration, Timer}; |
| 10 | use embassy::traits::spi::*; | ||
| 11 | use embedded_hal::digital::v2::OutputPin; | 10 | use embedded_hal::digital::v2::OutputPin; |
| 11 | use embedded_hal_async::spi::ReadWrite; | ||
| 12 | 12 | ||
| 13 | mod register; | 13 | mod register; |
| 14 | use self::register::PaConfig; | 14 | use self::register::PaConfig; |
| @@ -36,9 +36,10 @@ pub enum Error<SPI, CS, RESET> { | |||
| 36 | Transmitting, | 36 | Transmitting, |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | use super::sx127x_lora::register::{FskDataModulationShaping, FskRampUpRamDown}; | ||
| 40 | use Error::*; | 39 | use Error::*; |
| 41 | 40 | ||
| 41 | use super::sx127x_lora::register::{FskDataModulationShaping, FskRampUpRamDown}; | ||
| 42 | |||
| 42 | #[cfg(not(feature = "version_0x09"))] | 43 | #[cfg(not(feature = "version_0x09"))] |
| 43 | const VERSION_CHECK: u8 = 0x12; | 44 | const VERSION_CHECK: u8 = 0x12; |
| 44 | 45 | ||
| @@ -47,7 +48,7 @@ const VERSION_CHECK: u8 = 0x09; | |||
| 47 | 48 | ||
| 48 | impl<SPI, CS, RESET, E> LoRa<SPI, CS, RESET> | 49 | impl<SPI, CS, RESET, E> LoRa<SPI, CS, RESET> |
| 49 | where | 50 | where |
| 50 | SPI: FullDuplex<u8, Error = E>, | 51 | SPI: ReadWrite<u8, Error = E>, |
| 51 | CS: OutputPin, | 52 | CS: OutputPin, |
| 52 | RESET: OutputPin, | 53 | RESET: OutputPin, |
| 53 | { | 54 | { |
| @@ -546,7 +547,7 @@ where | |||
| 546 | 547 | ||
| 547 | let _ = self | 548 | let _ = self |
| 548 | .spi | 549 | .spi |
| 549 | .read_write(&mut buffer, &[reg & 0x7f, 0]) | 550 | .transfer(&mut buffer, &[reg & 0x7f, 0]) |
| 550 | .await | 551 | .await |
| 551 | .map_err(SPI)?; | 552 | .map_err(SPI)?; |
| 552 | 553 | ||
