Skip to content

Commit

Permalink
Implement defmt::Format everywhere Debug is
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Fresk committed Dec 17, 2024
1 parent a518493 commit 0a74b63
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ optional = true
[dependencies.ral-registers]
version = "0.1.3"

[dependencies.defmt]
workspace = true
optional = true

#######################
# imxrt-rs dependencies
#######################
Expand Down Expand Up @@ -117,6 +121,7 @@ imxrt-log = { path = "logging", default-features = false, features = [
imxrt-ral = "0.6"
imxrt-rt = "0.1.5"
imxrt-usbd = "0.3"
defmt = "0.3"

[workspace.package]
repository = "https://github.com/imxrt-rs/imxrt-hal"
Expand Down Expand Up @@ -154,7 +159,6 @@ imxrt-rt = { workspace = true }
menu = "0.3.2"
rtic = { version = "2.0", features = ["thumbv7-backend"] }
log = "0.4"
defmt = "0.3"
pin-utils = "0.1"
usb-device = { version = "0.3", features = ["test-class-high-speed"] }
usbd-serial = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion board/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod ral_shim;
/// and power settings for these variants. They're
/// typically follow the recommendations in the
/// data sheet.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
#[non_exhaustive]
pub enum RunMode {
/// The fastest, highest-power mode.
Expand Down
5 changes: 5 additions & 0 deletions src/chip/drivers/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use eh02::adc::{Channel, OneShot};

/// The clock input for an ADC
#[allow(non_camel_case_types)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum ClockSelect {
/// IPG clock
Expand All @@ -49,6 +50,7 @@ pub enum ClockSelect {
}

/// How much to divide the clock input
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum ClockDivision {
/// Input clock / 1
Expand All @@ -63,6 +65,7 @@ pub enum ClockDivision {
}

/// Conversion speeds done by clock cycles
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConversionSpeed {
/// 25 ADC clock cycles (24 on imxrt102x)
Expand All @@ -76,6 +79,7 @@ pub enum ConversionSpeed {
}

/// Denotes how much hardware averaging to do
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AveragingCount {
/// 1 sample average.
Expand All @@ -91,6 +95,7 @@ pub enum AveragingCount {
}

/// Specifies the resolution the ADC
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ResolutionBits {
/// 8 bit resolution.
Expand Down
7 changes: 6 additions & 1 deletion src/chip/drivers/ccm_10xx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub mod perclk_clk {
use crate::ral::{self, ccm::CCM};

/// PERCLK clock selection.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
Expand Down Expand Up @@ -136,6 +137,7 @@ pub(crate) fn wait_handshake(ccm: &crate::ral::ccm::CCM) {
///
/// Practically, this affects the processor behavior when you use WFI, WFE, or enter another
/// low-power state. Low-power settings that aren't "run" halt the ARM SYSTICK peripheral.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum LowPowerMode {
Expand Down Expand Up @@ -216,6 +218,7 @@ pub mod uart_clk {
}

/// UART clock selection.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
Expand Down Expand Up @@ -293,6 +296,7 @@ pub mod lpi2c_clk {
}

/// LPI2C clock selections.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
Expand Down Expand Up @@ -372,6 +376,7 @@ pub mod lpspi_clk {
}

/// LPSPI clock selections.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
Expand Down Expand Up @@ -458,7 +463,7 @@ macro_rules! ccm_flexio {
}

#[doc = concat!($desc, " clock selections.")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
/// Derive from PLL4.
Expand Down
1 change: 1 addition & 0 deletions src/chip/drivers/ccm_10xx/ahb_clk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn divider(ccm: &CCM) -> u32 {
}

/// Peripheral clock selection.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
Expand Down
4 changes: 4 additions & 0 deletions src/chip/drivers/ccm_10xx/clock_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
use crate::ral::{self, ccm::CCM};

/// A clock gate setting.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Setting {
Expand Down Expand Up @@ -87,6 +88,7 @@ impl Setting {
}

/// Clock gating register.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(unused)]
#[repr(u8)]
Expand All @@ -104,6 +106,7 @@ enum Register {
use Register::*;

/// Clock gate.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(unused)]
#[repr(u8)]
Expand Down Expand Up @@ -141,6 +144,7 @@ impl Gate {
///
/// These are reachable through the various function
/// provided in this module.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct Locator {
register: Register,
Expand Down
1 change: 1 addition & 0 deletions src/chip/drivers/ccm_10xx/output_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub mod clko1 {
/// The CLKO1 output *pin* can represent either CLKO1 or CLKO2.
/// Use [`set_output`] to set this configuration.
#[repr(u32)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Output {
/// Use CLKO1's selection.
Expand Down
1 change: 1 addition & 0 deletions src/chip/drivers/ccm_10xx/periph_clk2_sel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use crate::ral::{self, ccm::CCM};

/// Peripheral CLK2 selection.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
Expand Down
1 change: 1 addition & 0 deletions src/chip/drivers/ccm_10xx/pre_periph_clk_pll1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::ral::{self, ccm::CCM};

/// Pre-peripheral clock selection.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
Expand Down
1 change: 1 addition & 0 deletions src/chip/drivers/ccm_10xx/pre_periph_clk_pll6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::ral::{self, ccm::CCM};

/// Pre-peripheral clock selection.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Selection {
Expand Down
2 changes: 2 additions & 0 deletions src/chip/drivers/ccm_11xx/clock_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use crate::ral::{self, ccm::CCM};

/// A clock gate setting.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Setting {
Expand All @@ -32,6 +33,7 @@ impl Setting {
}

/// A clock gate locator.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct Locator {
offset: usize,
Expand Down
1 change: 1 addition & 0 deletions src/chip/drivers/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ pub struct Input<P> {
unsafe impl<P: Send> Send for Input<P> {}

/// Input interrupt triggers.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Trigger {
Expand Down
1 change: 1 addition & 0 deletions src/chip/drivers/rgpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ pub struct Input<P> {
unsafe impl<P: Send> Send for Input<P> {}

/// Input interrupt triggers.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum Trigger {
Expand Down
8 changes: 8 additions & 0 deletions src/chip/drivers/snvs/srtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl Disabled {
}

/// Indicates the result of the `try_enable` method
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug)]
pub enum EnabledState {
/// The SRTC was already enabled, and it's currently counting from `seconds`
Expand Down Expand Up @@ -224,3 +225,10 @@ impl fmt::Debug for Srtc {
// very basic, just to prevent compile errors if user puts it in a struct
}
}

#[cfg(feature = "defmt")]
impl defmt::Format for Srtc {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "SRTC {{ ... }}")
}
}
14 changes: 14 additions & 0 deletions src/chip/drivers/tempmon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ use crate::ral;
///
/// If you receive this error, `power_up()` the temperature monitor first,
/// and try again.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PowerDownError(());

Expand Down Expand Up @@ -143,6 +144,19 @@ impl core::fmt::Debug for TempMon {
}
}

#[cfg(feature = "defmt")]
impl defmt::Format for TempMon {
fn format(&self, f: defmt::Formatter) {
defmt::write!(
f,
"TempMon {{ scaler: {}, hot_count: {}, hot_temp: {} }}",
self.scaler,
self.hot_count,
self.hot_temp,
)
}
}

impl TempMon {
/// Initialize and create the temperature monitor.
pub fn new(tempmon: ral::tempmon::TEMPMON) -> Self {
Expand Down
11 changes: 11 additions & 0 deletions src/chip/drivers/trng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use crate::ral::trng;
use crate::ral::{modify_reg, read_reg, write_reg};

/// TRNG sampling mode
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum SampleMode {
Expand Down Expand Up @@ -96,12 +97,20 @@ impl fmt::Debug for Trng {
}
}

#[cfg(feature = "defmt")]
impl defmt::Format for Trng {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "Trng {{ block: {}, index: {} }}", self.block, self.index)
}
}

/// The number of retry attempts.
///
/// Describes the number of times to retry
/// after a test failure before an error is declared. Valid
/// range `1..=15`. The default retry count is the largest
/// possible value.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RetryCount(u32);

Expand Down Expand Up @@ -332,11 +341,13 @@ impl rand_core::RngCore for RngCoreWrapper {
}

/// A TRNG error occurred, such as a statistical test failing.
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Error(pub ErrorFlags);

bitflags::bitflags! {
/// Specific errors that may occur during entropy generation
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ErrorFlags : u32 {
// STATUS register starts here (automatically set from bits)
/// 1-bit run sampling 0s test failed
Expand Down
2 changes: 2 additions & 0 deletions src/chip/imxrt1010.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub(crate) mod config {
pub(crate) mod clko {
/// CLKO1 output clock selections.
#[repr(u32)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Clko1Selection {
/// PLL3 divided by 2.
Expand All @@ -119,6 +120,7 @@ pub(crate) mod config {

/// CLKO2 output clock selections.
#[repr(u32)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Clko2Selection {
/// LPI2C clock root.
Expand Down
2 changes: 2 additions & 0 deletions src/chip/imxrt1020.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub(crate) mod config {
pub(crate) mod clko {
/// CLKO1 output clock selections.
#[repr(u32)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Clko1Selection {
/// PLL3 divided by 2.
Expand All @@ -137,6 +138,7 @@ pub(crate) mod config {

/// CLKO2 output clock selections.
#[repr(u32)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Clko2Selection {
/// USDHC1 clock root.
Expand Down
2 changes: 2 additions & 0 deletions src/chip/imxrt1060.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ pub(crate) mod config {
pub(crate) mod clko {
/// CLKO1 output clock selections.
// #[repr(u32)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

pub enum Clko1Selection {}

/// CLKO2 output clock selections.
// #[repr(u32)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

pub enum Clko2Selection {}
Expand Down
2 changes: 2 additions & 0 deletions src/chip/imxrt1170.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(crate) mod config {
pub(crate) mod clko {
/// CLKO1 output clock selections.
#[repr(u32)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Clko1Selection {
/// 48MHz RC oscillator, divided by 2.
Expand All @@ -59,6 +60,7 @@ pub(crate) mod config {

/// CLKO2 output clock selections.
#[repr(u32)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Clko2Selection {
/// 48MHz RC oscillator, divided by 2.
Expand Down
Loading

0 comments on commit 0a74b63

Please sign in to comment.