diff --git a/Cargo.toml b/Cargo.toml index b8414a9..99fa22a 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" @@ -26,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 c83e85b..f80628a 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}; @@ -44,7 +48,7 @@ where Rst: OutputPin, //SlpTr: OutputPin, //Irq: InputPin, - Delay: DelayMs + DelayUs, + Delay: DelayUs, SpiErr: Debug, PinErr: Debug, DelayErr: Debug, @@ -72,7 +76,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)?; @@ -86,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) diff --git a/src/device.rs b/src/device.rs index 59b21f3..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 { @@ -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 @@ -350,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 { @@ -386,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 { @@ -407,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; } @@ -421,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; } @@ -435,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; } @@ -449,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; } @@ -463,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; } @@ -477,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; } @@ -491,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; } @@ -505,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; } @@ -519,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; } @@ -533,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; } @@ -547,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; } @@ -561,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; } @@ -575,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; } @@ -589,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; } @@ -603,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; } @@ -617,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; } @@ -631,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; } @@ -659,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; } @@ -673,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; } @@ -687,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; } @@ -701,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; } @@ -715,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; } @@ -729,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; } @@ -743,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; } @@ -757,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; } @@ -771,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; } @@ -813,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; } @@ -827,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; } @@ -841,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; } @@ -855,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; } @@ -869,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; } @@ -897,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; } @@ -911,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; } @@ -925,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; } @@ -939,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; } @@ -953,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; } @@ -967,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; } @@ -981,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; } @@ -995,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; } @@ -1009,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; } @@ -1023,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; } @@ -1037,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; } @@ -1051,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; } @@ -1065,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; } @@ -1079,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; } @@ -1093,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; } @@ -1107,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; } @@ -1121,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; } @@ -1135,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; } @@ -1149,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; } @@ -1163,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; } @@ -1177,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; } @@ -1191,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; } @@ -1205,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; } @@ -1219,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; } @@ -1233,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; } @@ -1247,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; } @@ -1261,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; } @@ -1275,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; } @@ -1289,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; } @@ -1303,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; } @@ -1317,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; } @@ -1331,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; } @@ -1345,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; } @@ -1359,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; } @@ -1373,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; } @@ -1387,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; } @@ -1398,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 { @@ -1416,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 @@ -1455,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; } @@ -1469,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; } @@ -1483,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; } @@ -1497,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; } @@ -1511,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; } @@ -1525,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; } @@ -1539,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; } @@ -1549,11 +1551,22 @@ 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 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::MC_STATE1 as u8; type Word = u8; type Error = Infallible; } @@ -1563,11 +1576,12 @@ 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 { - const ADDRESS: u8 = 0u8; + const ADDRESS: u8 = Registers::MC_STATE0 as u8; type Word = u8; type Error = Infallible; } @@ -1581,7 +1595,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; } @@ -1595,7 +1609,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; } @@ -1609,7 +1623,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; } @@ -1623,7 +1637,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; } @@ -1637,7 +1651,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; } @@ -1651,7 +1665,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; } @@ -1665,7 +1679,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; } @@ -1679,7 +1693,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; } @@ -1693,7 +1707,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; } @@ -1707,7 +1721,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; } @@ -1721,7 +1735,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; } @@ -1735,7 +1749,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; } @@ -1749,7 +1763,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; } @@ -1763,7 +1777,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; } @@ -1777,7 +1791,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; } @@ -1791,7 +1805,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; } @@ -1805,7 +1819,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; } @@ -1819,7 +1833,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; } @@ -1833,7 +1847,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; } @@ -1847,7 +1861,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; } @@ -1861,7 +1875,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; } @@ -1903,7 +1917,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; } @@ -1917,7 +1931,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; } @@ -1931,7 +1945,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; } @@ -1945,7 +1959,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; } diff --git a/src/lib.rs b/src/lib.rs index c2a8720..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, @@ -294,7 +300,7 @@ where } } -impl DelayUs for S2lp +impl DelayUs for S2lp where Hal: Base, SpiErr: Debug,