From 19a3a2c6c03166e32e5b44b729a66bafdb3fe8b9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 13 Feb 2025 14:43:46 +0100 Subject: [PATCH] add more defmt features --- va108xx-hal/src/clock.rs | 1 + va108xx-hal/src/gpio/dynpin.rs | 1 + va108xx-hal/src/i2c.rs | 8 ++++++++ va108xx-hal/src/lib.rs | 1 + va108xx-hal/src/pwm.rs | 4 +++- va108xx-hal/src/spi.rs | 3 +++ va108xx-hal/src/timer.rs | 2 ++ va108xx-hal/src/uart/mod.rs | 9 +++++++-- 8 files changed, 26 insertions(+), 3 deletions(-) diff --git a/va108xx-hal/src/clock.rs b/va108xx-hal/src/clock.rs index f068fec..3383145 100644 --- a/va108xx-hal/src/clock.rs +++ b/va108xx-hal/src/clock.rs @@ -11,6 +11,7 @@ static SYS_CLOCK: Mutex> = Mutex::new(OnceCell::new()); pub type PeripheralClocks = PeripheralSelect; #[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum FilterClkSel { SysClk = 0, Clk1 = 1, diff --git a/va108xx-hal/src/gpio/dynpin.rs b/va108xx-hal/src/gpio/dynpin.rs index 57c7b6d..5b56505 100644 --- a/va108xx-hal/src/gpio/dynpin.rs +++ b/va108xx-hal/src/gpio/dynpin.rs @@ -69,6 +69,7 @@ use crate::{clock::FilterClkSel, enable_nvic_interrupt, pac, FunSel, InterruptCo /// Value-level `enum` for disabled configurations #[derive(PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum DynDisabled { Floating, PullDown, diff --git a/va108xx-hal/src/i2c.rs b/va108xx-hal/src/i2c.rs index f888468..e33e93f 100644 --- a/va108xx-hal/src/i2c.rs +++ b/va108xx-hal/src/i2c.rs @@ -18,6 +18,7 @@ const CLK_400K: Hertz = Hertz::from_raw(400_000); const MIN_CLK_400K: Hertz = Hertz::from_raw(8_000_000); #[derive(Debug, PartialEq, Eq, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum FifoEmptyMode { Stall = 0, EndTransaction = 1, @@ -89,18 +90,21 @@ enum I2cCmd { } #[derive(Debug, PartialEq, Eq, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum I2cSpeed { Regular100khz = 0, Fast400khz = 1, } #[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum I2cDirection { Send = 0, Read = 1, } #[derive(Debug, PartialEq, Eq, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum I2cAddress { Regular(u8), TenBit(u16), @@ -141,9 +145,12 @@ impl Instance for pac::I2cb { // Config //================================================================================================== +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct TrTfThighTlow(u8, u8, u8, u8); +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct TsuStoTsuStaThdStaTBuf(u8, u8, u8, u8); +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct TimingCfg { // 4 bit max width tr: u8, @@ -218,6 +225,7 @@ impl Default for TimingCfg { } } +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct MasterConfig { pub tx_fe_mode: FifoEmptyMode, pub rx_fe_mode: FifoEmptyMode, diff --git a/va108xx-hal/src/lib.rs b/va108xx-hal/src/lib.rs index a1d04cd..9da8768 100644 --- a/va108xx-hal/src/lib.rs +++ b/va108xx-hal/src/lib.rs @@ -77,6 +77,7 @@ impl InterruptConfig { pub type IrqCfg = InterruptConfig; #[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct InvalidPin(pub(crate) ()); /// Can be used to manually manipulate the function select of port pins diff --git a/va108xx-hal/src/pwm.rs b/va108xx-hal/src/pwm.rs index 5fa487b..b3f1de0 100644 --- a/va108xx-hal/src/pwm.rs +++ b/va108xx-hal/src/pwm.rs @@ -15,7 +15,9 @@ use crate::{clock::enable_peripheral_clock, gpio::DynPinId}; const DUTY_MAX: u16 = u16::MAX; -pub struct PwmCommon { +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +pub(crate) struct PwmCommon { sys_clk: Hertz, /// For PWMB, this is the upper limit current_duty: u16, diff --git a/va108xx-hal/src/spi.rs b/va108xx-hal/src/spi.rs index 7607d70..48052ef 100644 --- a/va108xx-hal/src/spi.rs +++ b/va108xx-hal/src/spi.rs @@ -37,6 +37,7 @@ pub const BMSTART_BMSTOP_MASK: u32 = 1 << 31; pub const DEFAULT_CLK_DIV: u16 = 2; #[derive(Debug, PartialEq, Eq, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum HwChipSelectId { Id0 = 0, Id1 = 1, @@ -50,6 +51,7 @@ pub enum HwChipSelectId { } #[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum SpiPort { Porta = 0, Portb = 1, @@ -58,6 +60,7 @@ pub enum SpiPort { } #[derive(Debug, PartialEq, Eq, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum WordSize { OneBit = 0x00, FourBits = 0x03, diff --git a/va108xx-hal/src/timer.rs b/va108xx-hal/src/timer.rs index 0cf285e..d356671 100644 --- a/va108xx-hal/src/timer.rs +++ b/va108xx-hal/src/timer.rs @@ -79,6 +79,7 @@ pub enum Event { } #[derive(Default, Debug, PartialEq, Eq, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct CascadeCtrl { /// Enable Cascade 0 signal active as a requirement for counting pub enb_start_src_csd0: bool, @@ -108,6 +109,7 @@ pub struct CascadeCtrl { } #[derive(Debug, PartialEq, Eq)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum CascadeSel { Csd0 = 0, Csd1 = 1, diff --git a/va108xx-hal/src/uart/mod.rs b/va108xx-hal/src/uart/mod.rs index 39cd72b..6337d2b 100644 --- a/va108xx-hal/src/uart/mod.rs +++ b/va108xx-hal/src/uart/mod.rs @@ -23,6 +23,7 @@ use crate::{ use embedded_hal_nb::serial::Read; #[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Bank { A = 0, B = 1, @@ -237,6 +238,7 @@ impl From for Config { //================================================================================================== #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct IrqContextTimeoutOrMaxSize { rx_idx: usize, mode: IrqReceptionMode, @@ -262,6 +264,7 @@ impl IrqContextTimeoutOrMaxSize { /// This struct is used to return the default IRQ handler result to the user #[derive(Debug, Default)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct IrqResult { pub bytes_read: usize, pub errors: Option, @@ -269,6 +272,7 @@ pub struct IrqResult { /// This struct is used to return the default IRQ handler result to the user #[derive(Debug, Default)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] pub struct IrqResultMaxSizeOrTimeout { complete: bool, timeout: bool, @@ -319,6 +323,7 @@ impl IrqResultMaxSizeOrTimeout { } #[derive(Debug, PartialEq, Copy, Clone)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] enum IrqReceptionMode { Idle, Pending, @@ -407,7 +412,7 @@ impl Instance for pac::Uarta { } #[inline(always)] fn ptr() -> *const uart_base::RegisterBlock { - pac::Uarta::ptr() as *const _ + Self::ptr() as *const _ } } @@ -422,7 +427,7 @@ impl Instance for pac::Uartb { } #[inline(always)] fn ptr() -> *const uart_base::RegisterBlock { - pac::Uartb::ptr() as *const _ + Self::ptr() as *const _ } }