diff --git a/Cargo.toml b/Cargo.toml index c7105d2..03606e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,18 +33,16 @@ default = [ "std", "util", "serde", "driver-pal/hal-cp2130", "driver-pal/hal-lin [dependencies] radio = { version = "0.11.0", default_features = false } embedded-hal = "1.0.0" -defmt = {version = "0.3.5", optional = true } - -driver-pal = { version = "0.8.0", default_features = false, optional=true } +embedded-hal-bus = "0.1.0" +driver-pal = { version = "0.9.0", default_features = false, optional=true } +defmt = {version = "0.3.5", optional = true } bitflags = "2.4.0" libc = "0.2.123" log = { version = "0.4.17", default_features = false } strum = { version = "0.26.2", default_features = false, features = [ "derive" ] } - crc16 = { version = "0.4.0", optional = true } hex = { version = "0.4.2", optional = true } - humantime = { version = "2.0.1", optional = true } clap = { version = "4.4.7", optional = true, features = [ "derive", "env" ] } thiserror = { version = "1.0.30", optional = true } diff --git a/src/base.rs b/src/base.rs index 91da6fd..2823030 100644 --- a/src/base.rs +++ b/src/base.rs @@ -151,26 +151,23 @@ where /// Base interface for radio device pub struct Base< Spi: SpiDevice, - Cs: OutputPin, Busy: InputPin, Ready: InputPin, Sdn: OutputPin, Delay: DelayNs, > { pub spi: Spi, - pub cs: Cs, pub busy: Busy, pub ready: Ready, pub sdn: Sdn, pub delay: Delay, } -impl Hal for Base +impl Hal for Base where Spi: SpiDevice, ::Error: Debug + 'static, - Cs: OutputPin, Busy: InputPin, Ready: InputPin, Sdn: OutputPin, @@ -212,12 +209,12 @@ where /// Delay for the specified time fn delay_ms(&mut self, ms: u32) { - self.delay_us(ms * 1000); + self.delay.delay_ms(ms); } /// Delay for the specified time fn delay_us(&mut self, us: u32) { - self.delay_ns(us * 1000); + self.delay.delay_us(us); } fn delay_ns(&mut self, ns: u32) { @@ -230,16 +227,10 @@ where prefix: &[u8], data: &[u8], ) -> Result<(), Error> { - self.cs.set_low().map_err(Error::Pin)?; - - let r = self + self .spi .transaction(&mut [Operation::Write(prefix), Operation::Write(data)]) - .map_err(Error::Comms); - - self.cs.set_high().map_err(Error::Pin)?; - - r + .map_err(Error::Comms) } /// Read data with prefix, asserting CS as required @@ -248,16 +239,10 @@ where prefix: &[u8], data: &mut [u8], ) -> Result<(), Error> { - self.cs.set_low().map_err(Error::Pin)?; - - let r = self + self .spi .transaction(&mut [Operation::Write(prefix), Operation::Read(data)]) - .map_err(Error::Comms); - - self.cs.set_high().map_err(Error::Pin)?; - - r + .map_err(Error::Comms) } /// Write the specified command and data diff --git a/src/lib.rs b/src/lib.rs index 01175c5..f15fb59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -144,16 +144,15 @@ pub enum Error { NoComms, } -pub type Sx128xSpi = - Sx128x>; +pub type Sx128xSpi = + Sx128x>; -impl - Sx128x> +impl + Sx128x> where Spi: SpiDevice, ::Error: Debug, - CsPin: OutputPin, BusyPin: InputPin, ReadyPin: InputPin, SdnPin: OutputPin, @@ -164,7 +163,6 @@ where /// Create an Sx128x with the provided `Spi` implementation and pins pub fn spi( spi: Spi, - cs: CsPin, busy: BusyPin, ready: ReadyPin, sdn: SdnPin, @@ -174,7 +172,6 @@ where // Create SpiWrapper over spi/cs/busy let hal = Base { spi, - cs, sdn, busy, ready, diff --git a/src/util/main.rs b/src/util/main.rs index 93eac75..757cdab 100644 --- a/src/util/main.rs +++ b/src/util/main.rs @@ -46,7 +46,6 @@ fn main() { info!("Initialising Radio"); let mut radio = Sx128x::spi( spi, - pins.cs, pins.busy, pins.ready, pins.reset, diff --git a/tests/integration.rs b/tests/integration.rs index be8911f..efac1d0 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -13,7 +13,7 @@ use driver_pal::hal::*; use radio::{Receive, Transmit}; use radio_sx128x::{base::Base, prelude::*}; -pub type SpiWrapper = Base; +pub type SpiWrapper = Base; pub type Radio = Sx128x; @@ -31,7 +31,6 @@ fn load_radio(rf_config: &Config, device_config: &DeviceConfig) -> Radio { let radio = Sx128x::spi( spi, - pins.cs, pins.busy, pins.ready, pins.reset,