Skip to content

Commit

Permalink
update to e-h 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankurte committed Apr 17, 2024
1 parent 76f088e commit 3fda64e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
21 changes: 7 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ 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-alpha.10"
embedded-hal = "1.0.0"
defmt = {version = "0.3.5", optional = true }

driver-pal = { version = "0.8.0-alpha.6", default_features = false, optional=true }
driver-pal = { version = "0.8.0", default_features = false, optional=true }

bitflags = "1.0.4"
bitflags = "2.4.0"
libc = "0.2.123"
log = { version = "0.4.17", default_features = false }
strum = { version = "0.24.0", default_features = false, features = [ "derive" ] }
strum = { version = "0.26.2", default_features = false, features = [ "derive" ] }

crc16 = { version = "0.4.0", optional = true }
hex = { version = "0.4.2", optional = true }
Expand All @@ -52,23 +52,16 @@ failure = { version = "0.1.7", features = [ "derive" ], default-features = false
serde = { version = "1.0.144", optional = true , features = ["derive"]}

tracing = { version = "0.1.34", optional = true }
tracing-subscriber = { version = "0.2.16", optional = true }
tracing-subscriber = { version = "0.3.18", optional = true, features = [ "env-filter" ] }


[dev-dependencies]
color-backtrace = "0.5.0"
toml = "0.5.8"
color-backtrace = "0.6.1"
toml = "0.8.12"
serde = { version = "1.0.144", features = [ "derive" ] }
serde_derive = "1.0.0"

[[bin]]
name = "sx128x-util"
path = "src/util/main.rs"
required-features = ["util"]


[patch.crates-io]
linux-embedded-hal = { git = "https://github.com/rust-embedded/linux-embedded-hal" }
radio = { git = "https://github.com/rust-iot/radio" }
driver-pal = { git = "https://github.com/rust-iot/driver-pal" }
driver-cp2130 = { git = "https://github.com/rust-iot/rust-driver-cp2130" }
19 changes: 13 additions & 6 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::fmt::Debug;
use log::{error, trace};

use embedded_hal::{
delay::DelayUs,
delay::DelayNs,
digital::{InputPin, OutputPin, PinState},
spi::{ErrorType, Operation, SpiDevice},
};
Expand All @@ -32,6 +32,9 @@ pub trait Hal {
/// Delay for the specified time
fn delay_us(&mut self, us: u32);

/// Delay for the specified time
fn delay_ns(&mut self, ns: u32);

/// Write the specified command and data
fn write_cmd(
&mut self,
Expand Down Expand Up @@ -152,7 +155,7 @@ pub struct Base<
Busy: InputPin,
Ready: InputPin,
Sdn: OutputPin,
Delay: DelayUs,
Delay: DelayNs,
> {
pub spi: Spi,
pub cs: Cs,
Expand All @@ -173,7 +176,7 @@ where
Sdn: OutputPin<Error = PinError>,
PinError: Debug + 'static,

Delay: DelayUs,
Delay: DelayNs,
{
type CommsError = <Spi as ErrorType>::Error;
type PinError = PinError;
Expand Down Expand Up @@ -209,12 +212,16 @@ where

/// Delay for the specified time
fn delay_ms(&mut self, ms: u32) {
self.delay.delay_ms(ms);
self.delay_us(ms * 1000);
}

/// Delay for the specified time
fn delay_us(&mut self, ms: u32) {
self.delay.delay_us(ms);
fn delay_us(&mut self, us: u32) {
self.delay_ns(us * 1000);
}

fn delay_ns(&mut self, ns: u32) {
self.delay.delay_ns(ns);
}

/// Write data with prefix, asserting CS as required
Expand Down
5 changes: 5 additions & 0 deletions src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ pub enum AutoTx {

bitflags! {
/// Interrupt flags register
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Irq: u16 {
const TX_DONE = 0x0001;
Expand All @@ -502,6 +503,7 @@ pub type DioMask = Irq;

bitflags! {
/// Packet status register
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PacketStatus: u8 {
/// Top flag value unknown due to lack of complete datasheet
Expand All @@ -518,6 +520,7 @@ bitflags! {

bitflags! {
/// TxRx status packet status byte
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct TxRxStatus: u8 {
/// Top flag value unknown due to lack of complete datasheet
Expand All @@ -528,6 +531,7 @@ bitflags! {

bitflags! {
/// TxRx status register
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SyncAddrStatus: u8 {
const SYNC_ERROR = (1 << 6);
Expand All @@ -536,6 +540,7 @@ bitflags! {

bitflags! {
/// Radio calibration parameters
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct CalibrationParams: u8 {
const ADCBulkPEnable = (1 << 5);
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use log::{debug, error, trace, warn};
use defmt::{debug, error, trace, warn};

use embedded_hal::{
delay::DelayUs,
delay::DelayNs,
digital::{InputPin, OutputPin},
spi::{ErrorType, Mode as SpiMode, Phase, Polarity, SpiDevice},
};
Expand Down Expand Up @@ -159,7 +159,7 @@ where
SdnPin: OutputPin<Error = PinError>,
PinError: Debug,

Delay: DelayUs,
Delay: DelayNs,
{
/// Create an Sx128x with the provided `Spi` implementation and pins
pub fn spi(
Expand Down Expand Up @@ -622,12 +622,12 @@ where
}
}

impl<Hal> DelayUs for Sx128x<Hal>
impl<Hal> DelayNs for Sx128x<Hal>
where
Hal: base::Hal,
{
fn delay_us(&mut self, t: u32) {
self.hal.delay_us(t);
fn delay_ns(&mut self, t: u32) {
self.hal.delay_ns(t);
}
}

Expand Down

0 comments on commit 3fda64e

Please sign in to comment.