From 0b1a2e95f699bb8a9d1902d79f76cc18e087f1fe Mon Sep 17 00:00:00 2001 From: kaidokert Date: Sat, 1 Jan 2022 18:52:31 -0800 Subject: [PATCH 1/6] Changes for embedded-hal alpha6 --- Cargo.toml | 3 ++- src/base.rs | 4 ++-- src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b8414a9..88ca6d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,8 @@ default = [ "std", "util", "driver-pal/hal-cp2130", "driver-pal/hal-linux" ] [dependencies] -embedded-hal = "1.0.0-alpha.5" +embedded-hal = { version= "=1.0.0-alpha.6" } + radio = "0.10.0" modular-bitfield = "0.11.2" log = "0.4.14" diff --git a/src/base.rs b/src/base.rs index c83e85b..eb007ed 100644 --- a/src/base.rs +++ b/src/base.rs @@ -44,7 +44,7 @@ where Rst: OutputPin, //SlpTr: OutputPin, //Irq: InputPin, - Delay: DelayMs + DelayUs, + Delay: DelayUs, SpiErr: Debug, PinErr: Debug, DelayErr: Debug, @@ -72,7 +72,7 @@ where cmd: &[u8], data: &mut [u8], ) -> Result<(), Error> { - let mut t = [Operation::Write(&cmd), Operation::Transfer(data)]; + let mut t = [Operation::Write(&cmd), Operation::TransferInplace(data)]; self.cs.set_low().map_err(Error::Pin)?; diff --git a/src/lib.rs b/src/lib.rs index c2a8720..2127795 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -294,7 +294,7 @@ where } } -impl DelayUs for S2lp +impl DelayUs for S2lp where Hal: Base, SpiErr: Debug, From d793c67bb3c8650129b1daefb3b96058d775f2b9 Mon Sep 17 00:00:00 2001 From: kaidokert Date: Sat, 15 Jan 2022 15:49:25 -0800 Subject: [PATCH 2/6] Make things more defmt friendly --- Cargo.toml | 2 +- src/base.rs | 4 ++++ src/lib.rs | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 88ca6d0..99fa22a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ humantime = { version = "2.1.0", optional = true } tracing = { version = "0.1.25", optional = true } tracing-subscriber = { version = "0.2.16", optional = true } serde = { version = "1.0.130", optional = true } -defmt = { version = "0.2.3", optional = true } +defmt = { version = "0.3.0", optional = true } anyhow = { version = "1.0.44", optional = true } [dev-dependencies] diff --git a/src/base.rs b/src/base.rs index eb007ed..7fc9277 100644 --- a/src/base.rs +++ b/src/base.rs @@ -1,7 +1,11 @@ use core::fmt::Debug; use embedded_hal::{delay::blocking::*, digital::blocking::*, spi::blocking::*}; + +#[cfg(not(feature="defmt"))] use log::{trace}; +#[cfg(feature="defmt")] +use defmt::trace; use crate::{Error}; diff --git a/src/lib.rs b/src/lib.rs index 2127795..b3b24d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,8 +8,13 @@ use core::marker::PhantomData; use embedded_hal::{delay::blocking::DelayUs, spi::{Mode, Phase, Polarity}}; use radio::{BasicChannel, Channel as _, Registers as _}; + +#[cfg(not(feature="defmt"))] use log::debug; +#[cfg(feature="defmt")] +use defmt::debug; + pub mod base; pub use base::{Base, Io}; @@ -151,6 +156,7 @@ where } #[derive(Copy, Clone, PartialEq, Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct Info { pub part_no: u8, pub version: u8, From 4ec2384a6487b8d32d3492a7617da7cd2f898f8e Mon Sep 17 00:00:00 2001 From: kaidokert Date: Thu, 20 Jan 2022 09:16:04 -0800 Subject: [PATCH 3/6] Add valid default unmodulated ModType --- src/device.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/device.rs b/src/device.rs index 59b21f3..11b413a 100644 --- a/src/device.rs +++ b/src/device.rs @@ -339,6 +339,8 @@ pub enum ModType { Mod4Gfsk = 3, /// ASK/OOK ModAskOok = 5, + /// Unmodulated carrier, test mode + ModUnmodulated = 7, /// 2-GFSK BT=0.5 Mod2GfskBt05 = 10, /// 4-GFSK BT=0.5 From e29530335132fdcc6f2537fb8b036ee07bf4c131 Mon Sep 17 00:00:00 2001 From: kaidokert Date: Thu, 20 Jan 2022 09:17:40 -0800 Subject: [PATCH 4/6] Fill in register addresses --- src/device.rs | 202 +++++++++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 101 deletions(-) diff --git a/src/device.rs b/src/device.rs index 11b413a..32a2240 100644 --- a/src/device.rs +++ b/src/device.rs @@ -409,7 +409,7 @@ pub struct Afc2 { } impl radio::Register for Afc2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::AFC2 as u8; type Word = u8; type Error = Infallible; } @@ -423,7 +423,7 @@ pub struct Afc1 { } impl radio::Register for Afc1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::AFC1 as u8; type Word = u8; type Error = Infallible; } @@ -437,7 +437,7 @@ pub struct Afc0 { } impl radio::Register for Afc0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::AFC0 as u8; type Word = u8; type Error = Infallible; } @@ -451,7 +451,7 @@ pub struct RssiFlt { } impl radio::Register for RssiFlt { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RSSI_FLT as u8; type Word = u8; type Error = Infallible; } @@ -465,7 +465,7 @@ pub struct RssiTh { } impl radio::Register for RssiTh { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RSSI_TH as u8; type Word = u8; type Error = Infallible; } @@ -479,7 +479,7 @@ pub struct Agcctrl4 { } impl radio::Register for Agcctrl4 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::AGCCTRL4 as u8; type Word = u8; type Error = Infallible; } @@ -493,7 +493,7 @@ pub struct Agcctrl3 { } impl radio::Register for Agcctrl3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::AGCCTRL3 as u8; type Word = u8; type Error = Infallible; } @@ -507,7 +507,7 @@ pub struct Agcctrl2 { } impl radio::Register for Agcctrl2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::AGCCTRL2 as u8; type Word = u8; type Error = Infallible; } @@ -521,7 +521,7 @@ pub struct Agcctrl1 { } impl radio::Register for Agcctrl1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::AGCCTRL1 as u8; type Word = u8; type Error = Infallible; } @@ -535,7 +535,7 @@ pub struct Agcctrl0 { } impl radio::Register for Agcctrl0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::AGCCTRL0 as u8; type Word = u8; type Error = Infallible; } @@ -549,7 +549,7 @@ pub struct AntSelectConf { } impl radio::Register for AntSelectConf { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::ANT_SELECT_CONF as u8; type Word = u8; type Error = Infallible; } @@ -563,7 +563,7 @@ pub struct Clockrec2 { } impl radio::Register for Clockrec2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CLOCKREC2 as u8; type Word = u8; type Error = Infallible; } @@ -577,7 +577,7 @@ pub struct Clockrec1 { } impl radio::Register for Clockrec1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CLOCKREC1 as u8; type Word = u8; type Error = Infallible; } @@ -591,7 +591,7 @@ pub struct Pcktctrl6 { } impl radio::Register for Pcktctrl6 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKTCTRL6 as u8; type Word = u8; type Error = Infallible; } @@ -605,7 +605,7 @@ pub struct Pcktctrl5 { } impl radio::Register for Pcktctrl5 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKTCTRL5 as u8; type Word = u8; type Error = Infallible; } @@ -619,7 +619,7 @@ pub struct Pcktctrl4 { } impl radio::Register for Pcktctrl4 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKTCTRL4 as u8; type Word = u8; type Error = Infallible; } @@ -633,7 +633,7 @@ pub struct Pcktctrl3 { } impl radio::Register for Pcktctrl3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKTCTRL3 as u8; type Word = u8; type Error = Infallible; } @@ -661,7 +661,7 @@ pub struct Pcktctrl1 { } impl radio::Register for Pcktctrl1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKTCTRL1 as u8; type Word = u8; type Error = Infallible; } @@ -675,7 +675,7 @@ pub struct Pcktlen1 { } impl radio::Register for Pcktlen1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKTLEN1 as u8; type Word = u8; type Error = Infallible; } @@ -689,7 +689,7 @@ pub struct Pcktlen0 { } impl radio::Register for Pcktlen0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKTLEN0 as u8; type Word = u8; type Error = Infallible; } @@ -703,7 +703,7 @@ pub struct Sync3 { } impl radio::Register for Sync3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::SYNC3 as u8; type Word = u8; type Error = Infallible; } @@ -717,7 +717,7 @@ pub struct Sync2 { } impl radio::Register for Sync2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::SYNC2 as u8; type Word = u8; type Error = Infallible; } @@ -731,7 +731,7 @@ pub struct Sync1 { } impl radio::Register for Sync1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::SYNC1 as u8; type Word = u8; type Error = Infallible; } @@ -745,7 +745,7 @@ pub struct Sync0 { } impl radio::Register for Sync0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::SYNC0 as u8; type Word = u8; type Error = Infallible; } @@ -759,7 +759,7 @@ pub struct Qi { } impl radio::Register for Qi { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::QI as u8; type Word = u8; type Error = Infallible; } @@ -773,7 +773,7 @@ pub struct PcktPstmbl { } impl radio::Register for PcktPstmbl { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKT_PSTMBL as u8; type Word = u8; type Error = Infallible; } @@ -815,7 +815,7 @@ pub struct Protocol0 { } impl radio::Register for Protocol0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PROTOCOL0 as u8; type Word = u8; type Error = Infallible; } @@ -829,7 +829,7 @@ pub struct FifoConfig3 { } impl radio::Register for FifoConfig3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::FIFO_CONFIG3 as u8; type Word = u8; type Error = Infallible; } @@ -843,7 +843,7 @@ pub struct FifoConfig2 { } impl radio::Register for FifoConfig2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::FIFO_CONFIG2 as u8; type Word = u8; type Error = Infallible; } @@ -857,7 +857,7 @@ pub struct FifoConfig1 { } impl radio::Register for FifoConfig1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::FIFO_CONFIG1 as u8; type Word = u8; type Error = Infallible; } @@ -871,7 +871,7 @@ pub struct FifoConfig0 { } impl radio::Register for FifoConfig0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::FIFO_CONFIG0 as u8; type Word = u8; type Error = Infallible; } @@ -899,7 +899,7 @@ pub struct PcktFltGoals4 { } impl radio::Register for PcktFltGoals4 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKT_FLT_GOALS4 as u8; type Word = u8; type Error = Infallible; } @@ -913,7 +913,7 @@ pub struct PcktFltGoals3 { } impl radio::Register for PcktFltGoals3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKT_FLT_GOALS3 as u8; type Word = u8; type Error = Infallible; } @@ -927,7 +927,7 @@ pub struct PcktFltGoals2 { } impl radio::Register for PcktFltGoals2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKT_FLT_GOALS2 as u8; type Word = u8; type Error = Infallible; } @@ -941,7 +941,7 @@ pub struct PcktFltGoals1 { } impl radio::Register for PcktFltGoals1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKT_FLT_GOALS1 as u8; type Word = u8; type Error = Infallible; } @@ -955,7 +955,7 @@ pub struct PcktFltGoals0 { } impl radio::Register for PcktFltGoals0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PCKT_FLT_GOALS0 as u8; type Word = u8; type Error = Infallible; } @@ -969,7 +969,7 @@ pub struct Timers5 { } impl radio::Register for Timers5 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::TIMERS5 as u8; type Word = u8; type Error = Infallible; } @@ -983,7 +983,7 @@ pub struct Timers4 { } impl radio::Register for Timers4 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::TIMERS4 as u8; type Word = u8; type Error = Infallible; } @@ -997,7 +997,7 @@ pub struct Timers3 { } impl radio::Register for Timers3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::TIMERS3 as u8; type Word = u8; type Error = Infallible; } @@ -1011,7 +1011,7 @@ pub struct Timers2 { } impl radio::Register for Timers2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::TIMERS2 as u8; type Word = u8; type Error = Infallible; } @@ -1025,7 +1025,7 @@ pub struct Timers1 { } impl radio::Register for Timers1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::TIMERS1 as u8; type Word = u8; type Error = Infallible; } @@ -1039,7 +1039,7 @@ pub struct Timers0 { } impl radio::Register for Timers0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::TIMERS0 as u8; type Word = u8; type Error = Infallible; } @@ -1053,7 +1053,7 @@ pub struct CsmaConf3 { } impl radio::Register for CsmaConf3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CSMA_CONF3 as u8; type Word = u8; type Error = Infallible; } @@ -1067,7 +1067,7 @@ pub struct CsmaConf2 { } impl radio::Register for CsmaConf2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CSMA_CONF2 as u8; type Word = u8; type Error = Infallible; } @@ -1081,7 +1081,7 @@ pub struct CsmaConf1 { } impl radio::Register for CsmaConf1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CSMA_CONF1 as u8; type Word = u8; type Error = Infallible; } @@ -1095,7 +1095,7 @@ pub struct CsmaConf0 { } impl radio::Register for CsmaConf0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CSMA_CONF0 as u8; type Word = u8; type Error = Infallible; } @@ -1109,7 +1109,7 @@ pub struct IrqMask3 { } impl radio::Register for IrqMask3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::IRQ_MASK3 as u8; type Word = u8; type Error = Infallible; } @@ -1123,7 +1123,7 @@ pub struct IrqMask2 { } impl radio::Register for IrqMask2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::IRQ_MASK2 as u8; type Word = u8; type Error = Infallible; } @@ -1137,7 +1137,7 @@ pub struct IrqMask1 { } impl radio::Register for IrqMask1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::IRQ_MASK1 as u8; type Word = u8; type Error = Infallible; } @@ -1151,7 +1151,7 @@ pub struct IrqMask0 { } impl radio::Register for IrqMask0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::IRQ_MASK0 as u8; type Word = u8; type Error = Infallible; } @@ -1165,7 +1165,7 @@ pub struct FastRxTimer { } impl radio::Register for FastRxTimer { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::FAST_RX_TIMER as u8; type Word = u8; type Error = Infallible; } @@ -1179,7 +1179,7 @@ pub struct PaPower8 { } impl radio::Register for PaPower8 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_POWER8 as u8; type Word = u8; type Error = Infallible; } @@ -1193,7 +1193,7 @@ pub struct PaPower7 { } impl radio::Register for PaPower7 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_POWER7 as u8; type Word = u8; type Error = Infallible; } @@ -1207,7 +1207,7 @@ pub struct PaPower6 { } impl radio::Register for PaPower6 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_POWER6 as u8; type Word = u8; type Error = Infallible; } @@ -1221,7 +1221,7 @@ pub struct PaPower5 { } impl radio::Register for PaPower5 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_POWER5 as u8; type Word = u8; type Error = Infallible; } @@ -1235,7 +1235,7 @@ pub struct PaPower4 { } impl radio::Register for PaPower4 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_POWER4 as u8; type Word = u8; type Error = Infallible; } @@ -1249,7 +1249,7 @@ pub struct PaPower3 { } impl radio::Register for PaPower3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_POWER3 as u8; type Word = u8; type Error = Infallible; } @@ -1263,7 +1263,7 @@ pub struct PaPower2 { } impl radio::Register for PaPower2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_POWER2 as u8; type Word = u8; type Error = Infallible; } @@ -1277,7 +1277,7 @@ pub struct PaPower1 { } impl radio::Register for PaPower1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_POWER1 as u8; type Word = u8; type Error = Infallible; } @@ -1291,7 +1291,7 @@ pub struct PaPower0 { } impl radio::Register for PaPower0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_POWER0 as u8; type Word = u8; type Error = Infallible; } @@ -1305,7 +1305,7 @@ pub struct PaConfig1 { } impl radio::Register for PaConfig1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_CONFIG1 as u8; type Word = u8; type Error = Infallible; } @@ -1319,7 +1319,7 @@ pub struct PaConfig0 { } impl radio::Register for PaConfig0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PA_CONFIG0 as u8; type Word = u8; type Error = Infallible; } @@ -1333,7 +1333,7 @@ pub struct SynthConfig2 { } impl radio::Register for SynthConfig2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::SYNTH_CONFIG2 as u8; type Word = u8; type Error = Infallible; } @@ -1347,7 +1347,7 @@ pub struct VcoConfig { } impl radio::Register for VcoConfig { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::VCO_CONFIG as u8; type Word = u8; type Error = Infallible; } @@ -1361,7 +1361,7 @@ pub struct VcoCalibrIn2 { } impl radio::Register for VcoCalibrIn2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::VCO_CALIBR_IN2 as u8; type Word = u8; type Error = Infallible; } @@ -1375,7 +1375,7 @@ pub struct VcoCalibrIn1 { } impl radio::Register for VcoCalibrIn1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::VCO_CALIBR_IN1 as u8; type Word = u8; type Error = Infallible; } @@ -1389,7 +1389,7 @@ pub struct VcoCalibrIn0 { } impl radio::Register for VcoCalibrIn0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::VCO_CALIBR_IN0 as u8; type Word = u8; type Error = Infallible; } @@ -1457,7 +1457,7 @@ pub struct RcoCalibrConf3 { } impl radio::Register for RcoCalibrConf3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RCO_CALIBR_CONF3 as u8; type Word = u8; type Error = Infallible; } @@ -1471,7 +1471,7 @@ pub struct RcoCalibrConf2 { } impl radio::Register for RcoCalibrConf2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RCO_CALIBR_CONF2 as u8; type Word = u8; type Error = Infallible; } @@ -1485,7 +1485,7 @@ pub struct PmConf4 { } impl radio::Register for PmConf4 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PM_CONF4 as u8; type Word = u8; type Error = Infallible; } @@ -1499,7 +1499,7 @@ pub struct PmConf3 { } impl radio::Register for PmConf3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PM_CONF3 as u8; type Word = u8; type Error = Infallible; } @@ -1513,7 +1513,7 @@ pub struct PmConf2 { } impl radio::Register for PmConf2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PM_CONF2 as u8; type Word = u8; type Error = Infallible; } @@ -1527,7 +1527,7 @@ pub struct PmConf1 { } impl radio::Register for PmConf1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PM_CONF1 as u8; type Word = u8; type Error = Infallible; } @@ -1541,7 +1541,7 @@ pub struct PmConf0 { } impl radio::Register for PmConf0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::PM_CONF0 as u8; type Word = u8; type Error = Infallible; } @@ -1555,7 +1555,7 @@ pub struct McState1 { } impl radio::Register for McState1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::MC_STATE1 as u8; type Word = u8; type Error = Infallible; } @@ -1569,7 +1569,7 @@ pub struct McState0 { } impl radio::Register for McState0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::MC_STATE0 as u8; type Word = u8; type Error = Infallible; } @@ -1583,7 +1583,7 @@ pub struct TxFifoStatus { } impl radio::Register for TxFifoStatus { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::TX_FIFO_STATUS as u8; type Word = u8; type Error = Infallible; } @@ -1597,7 +1597,7 @@ pub struct RxFifoStatus { } impl radio::Register for RxFifoStatus { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RX_FIFO_STATUS as u8; type Word = u8; type Error = Infallible; } @@ -1611,7 +1611,7 @@ pub struct RcoCalibrOut4 { } impl radio::Register for RcoCalibrOut4 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RCO_CALIBR_OUT4 as u8; type Word = u8; type Error = Infallible; } @@ -1625,7 +1625,7 @@ pub struct RcoCalibrOut3 { } impl radio::Register for RcoCalibrOut3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RCO_CALIBR_OUT3 as u8; type Word = u8; type Error = Infallible; } @@ -1639,7 +1639,7 @@ pub struct VcoCalibrOut1 { } impl radio::Register for VcoCalibrOut1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::VCO_CALIBR_OUT1 as u8; type Word = u8; type Error = Infallible; } @@ -1653,7 +1653,7 @@ pub struct VcoCalibrOut0 { } impl radio::Register for VcoCalibrOut0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::VCO_CALIBR_OUT0 as u8; type Word = u8; type Error = Infallible; } @@ -1667,7 +1667,7 @@ pub struct TxPcktInfo { } impl radio::Register for TxPcktInfo { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::TX_PCKT_INFO as u8; type Word = u8; type Error = Infallible; } @@ -1681,7 +1681,7 @@ pub struct RxPcktInfo { } impl radio::Register for RxPcktInfo { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RX_PCKT_INFO as u8; type Word = u8; type Error = Infallible; } @@ -1695,7 +1695,7 @@ pub struct AfcCorr { } impl radio::Register for AfcCorr { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::AFC_CORR as u8; type Word = u8; type Error = Infallible; } @@ -1709,7 +1709,7 @@ pub struct LinkQualif2 { } impl radio::Register for LinkQualif2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::LINK_QUALIF2 as u8; type Word = u8; type Error = Infallible; } @@ -1723,7 +1723,7 @@ pub struct LinkQualif1 { } impl radio::Register for LinkQualif1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::LINK_QUALIF1 as u8; type Word = u8; type Error = Infallible; } @@ -1737,7 +1737,7 @@ pub struct RssiLevel { } impl radio::Register for RssiLevel { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RSSI_LEVEL as u8; type Word = u8; type Error = Infallible; } @@ -1751,7 +1751,7 @@ pub struct RxPcktLen1 { } impl radio::Register for RxPcktLen1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RX_PCKT_LEN1 as u8; type Word = u8; type Error = Infallible; } @@ -1765,7 +1765,7 @@ pub struct RxPcktLen0 { } impl radio::Register for RxPcktLen0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RX_PCKT_LEN0 as u8; type Word = u8; type Error = Infallible; } @@ -1779,7 +1779,7 @@ pub struct CrcField3 { } impl radio::Register for CrcField3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CRC_FIELD3 as u8; type Word = u8; type Error = Infallible; } @@ -1793,7 +1793,7 @@ pub struct CrcField2 { } impl radio::Register for CrcField2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CRC_FIELD2 as u8; type Word = u8; type Error = Infallible; } @@ -1807,7 +1807,7 @@ pub struct CrcField1 { } impl radio::Register for CrcField1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CRC_FIELD1 as u8; type Word = u8; type Error = Infallible; } @@ -1821,7 +1821,7 @@ pub struct CrcField0 { } impl radio::Register for CrcField0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::CRC_FIELD0 as u8; type Word = u8; type Error = Infallible; } @@ -1835,7 +1835,7 @@ pub struct RxAddreField1 { } impl radio::Register for RxAddreField1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RX_ADDRE_FIELD1 as u8; type Word = u8; type Error = Infallible; } @@ -1849,7 +1849,7 @@ pub struct RxAddreField0 { } impl radio::Register for RxAddreField0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RX_ADDRE_FIELD0 as u8; type Word = u8; type Error = Infallible; } @@ -1863,7 +1863,7 @@ pub struct RssiLevelRun { } impl radio::Register for RssiLevelRun { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::RSSI_LEVEL_RUN as u8; type Word = u8; type Error = Infallible; } @@ -1905,7 +1905,7 @@ pub struct IrqStatus3 { } impl radio::Register for IrqStatus3 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::IRQ_STATUS3 as u8; type Word = u8; type Error = Infallible; } @@ -1919,7 +1919,7 @@ pub struct IrqStatus2 { } impl radio::Register for IrqStatus2 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::IRQ_STATUS2 as u8; type Word = u8; type Error = Infallible; } @@ -1933,7 +1933,7 @@ pub struct IrqStatus1 { } impl radio::Register for IrqStatus1 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::IRQ_STATUS1 as u8; type Word = u8; type Error = Infallible; } @@ -1947,7 +1947,7 @@ pub struct IrqStatus0 { } impl radio::Register for IrqStatus0 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::IRQ_STATUS0 as u8; type Word = u8; type Error = Infallible; } From 8d0af2b87a6a75d5b4b129f12601d828e4aeb80e Mon Sep 17 00:00:00 2001 From: kaidokert Date: Thu, 20 Jan 2022 09:18:31 -0800 Subject: [PATCH 5/6] Comment fix: active high->low --- src/base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.rs b/src/base.rs index 7fc9277..f80628a 100644 --- a/src/base.rs +++ b/src/base.rs @@ -90,7 +90,7 @@ where } fn reset(&mut self) -> Result<(), Error> { - // Deassert CS pin (active high) + // Deassert CS pin (active low) self.cs.set_high().map_err(Error::Pin)?; // Assert reset pin (active low) From 2be5e6bd367e828e979a03cbb5e7b8bdc7d4c26b Mon Sep 17 00:00:00 2001 From: kaidokert Date: Sat, 22 Jan 2022 20:26:54 -0800 Subject: [PATCH 6/6] Fix bit field lsb/msb ordering --- src/device.rs | 84 +++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/src/device.rs b/src/device.rs index 32a2240..77d083c 100644 --- a/src/device.rs +++ b/src/device.rs @@ -25,10 +25,10 @@ pub const XO_RCO_CONF1_PD_CLKDIV_REGMASK: u8 = 0x10; #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct Gpio0Conf { - pub gpio_select: GpioOutSelect, + pub gpio_mode: GpioMode, #[skip] __: B1, - pub gpio_mode: GpioMode, + pub gpio_select: GpioOutSelect, } impl radio::Register for Gpio0Conf { @@ -42,10 +42,10 @@ impl radio::Register for Gpio0Conf { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct Gpio1Conf { - pub gpio_select: GpioOutSelect, + pub gpio_mode: GpioMode, #[skip] __: B1, - pub gpio_mode: GpioMode, + pub gpio_select: GpioOutSelect, } impl radio::Register for Gpio1Conf { @@ -59,10 +59,10 @@ impl radio::Register for Gpio1Conf { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct Gpio2Conf { - pub gpio_select: GpioOutSelect, + pub gpio_mode: GpioMode, #[skip] __: B1, - pub gpio_mode: GpioMode, + pub gpio_select: GpioOutSelect, } impl radio::Register for Gpio2Conf { @@ -76,10 +76,10 @@ impl radio::Register for Gpio2Conf { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct Gpio3Conf { - pub gpio_select: GpioOutSelect, + pub gpio_mode: GpioMode, #[skip] __: B1, - pub gpio_mode: GpioMode, + pub gpio_select: GpioOutSelect, } impl radio::Register for Gpio3Conf { @@ -155,12 +155,12 @@ pub enum GpioInSelect { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct Synt3 { - /// Set the charge pump current according to the XTAL frequency - pub pll_cp_isel: B3, - /// Synthesizer band select. This parameter selects the out-of loop divide factor of the synthesizer - pub band_sel: B1, /// MSB bits of the PLL programmable divider pub synt_27_24: B4, + /// Synthesizer band select. This parameter selects the out-of loop divide factor of the synthesizer + pub band_sel: bool, + /// Set the charge pump current according to the XTAL frequency + pub pll_cp_isel: B3, } impl radio::Register for Synt3 { @@ -311,10 +311,10 @@ impl radio::Register for Mod3 { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct Mod2 { + /// Datarate exponent + pub datarate_e: B4, /// Modulation type pub mod_type: ModType, - /// Datarate exponent - pub datarate_e: B4 } impl radio::Register for Mod2 { @@ -352,14 +352,14 @@ pub enum ModType { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct Mod1 { - /// enable the PA power interpolator - pub pa_interp_en: bool, - /// enable frequency interpolator for the GFSK shaping - pub mod_interp_en: bool, - /// Select the constellation map for 4-(G)FSK or 2-(G)FSK modulations - pub const_map: B2, /// The exponent value of the frequency deviation equation pub fdev_e: B4, + /// Select the constellation map for 4-(G)FSK or 2-(G)FSK modulations + pub const_map: B2, + /// enable frequency interpolator for the GFSK shaping + pub mod_interp_en: bool, + /// enable the PA power interpolator + pub pa_interp_en: bool, } impl radio::Register for Mod1 { @@ -388,10 +388,10 @@ impl radio::Register for Mod0 { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct ChFlt { - /// The mantissa value of the receiver channel filter - pub chflt_m: B4, /// The exponent value of the receiver channel filter pub chflt_e: B4, + /// The mantissa value of the receiver channel filter + pub chflt_m: B4, } impl radio::Register for ChFlt { @@ -1400,11 +1400,11 @@ impl radio::Register for VcoCalibrIn0 { #[repr(u8)] pub struct XoRcoConf1 { #[skip] - __: B3, + __: B4, /// disable both dividers of digital clock pub pd_clkdiv: bool, #[skip] - __: B4, + __: B3, } impl radio::Register for XoRcoConf1 { @@ -1418,18 +1418,18 @@ impl radio::Register for XoRcoConf1 { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct XoRcoConf0 { - /// Set external reference mode - pub ext_ref: ExtRefMode, - /// Set the driver gm of the XO at start up - pub gm_conf: B3, - /// Enable the the reference clock divider - pub ref_div: bool, - #[skip] - __: B1, - /// Enable external RCO, the 34.7 kHz signal must be supplied from any GPIO - pub ext_rco_osc: bool, /// Enable the automatic RCO calibratio pub rco_calibration: bool, + /// Enable external RCO, the 34.7 kHz signal must be supplied from any GPIO + pub ext_rco_osc: bool, + #[skip] + __: B1, + /// Enable the the reference clock divider + pub ref_div: bool, + /// Set the driver gm of the XO at start up + pub gm_conf: B3, + /// Set external reference mode + pub ext_ref: ExtRefMode, } /// External clock reference mode @@ -1551,7 +1551,18 @@ impl radio::Register for PmConf0 { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct McState1 { - pub raw: u8, + /// RCO calibration error + pub error_lock: bool, + /// RX FIFO is empty + pub rx_fifo_empty: bool, + /// TX FIFO is full + pub tx_fifo_full: bool, + /// Currently selected antenna + pub ant_sel: bool, + /// RCO calibration successfully terminated + pub rca_cal_ok: bool, + #[skip] + __: B3, } impl radio::Register for McState1 { @@ -1565,7 +1576,8 @@ impl radio::Register for McState1 { #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(u8)] pub struct McState0 { - pub raw: u8, + pub xo_on: bool, + pub state: State, } impl radio::Register for McState0 {