Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Debug and defmt::Format impls for fieldsets and interrupt enums. #9

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ description = "Peripheral Access Crate (PAC) for Raspberry Pi Silicon chips."
[dependencies]
cortex-m = "0.7.1"
cortex-m-rt = { version = ">=0.6.15,<0.8", optional = true }
defmt = { version = "0.3.10", optional = true }

[features]
default = []
rt = ["cortex-m-rt/device"]
rp2040 = []
rp235x = []
defmt = ["dep:defmt"]

[package.metadata.embassy_docs]
src_base = "https://github.com/embassy-rs/rp-pac/blob/v$VERSION/src/"
Expand Down
173 changes: 173 additions & 0 deletions src/rp2040/adc/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,50 @@ impl Default for Cs {
Cs(0)
}
}
impl core::fmt::Debug for Cs {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Cs")
.field("en", &self.en())
.field("ts_en", &self.ts_en())
.field("start_once", &self.start_once())
.field("start_many", &self.start_many())
.field("ready", &self.ready())
.field("err", &self.err())
.field("err_sticky", &self.err_sticky())
.field("ainsel", &self.ainsel())
.field("rrobin", &self.rrobin())
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for Cs {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct Cs {
en: bool,
ts_en: bool,
start_once: bool,
start_many: bool,
ready: bool,
err: bool,
err_sticky: bool,
ainsel: u8,
rrobin: u8,
}
let proxy = Cs {
en: self.en(),
ts_en: self.ts_en(),
start_once: self.start_once(),
start_many: self.start_many(),
ready: self.ready(),
err: self.err(),
err_sticky: self.err_sticky(),
ainsel: self.ainsel(),
rrobin: self.rrobin(),
};
defmt::write!(f, "{}", proxy)
}
}
#[doc = "Clock divider. If non-zero, CS_START_MANY will start conversions at regular intervals rather than back-to-back. The divider is reset when either of these fields are written. Total period is 1 + INT + FRAC / 256"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -143,6 +187,29 @@ impl Default for Div {
Div(0)
}
}
impl core::fmt::Debug for Div {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Div")
.field("frac", &self.frac())
.field("int", &self.int())
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for Div {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct Div {
frac: u8,
int: u16,
}
let proxy = Div {
frac: self.frac(),
int: self.int(),
};
defmt::write!(f, "{}", proxy)
}
}
#[doc = "FIFO control and status"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -261,6 +328,53 @@ impl Default for Fcs {
Fcs(0)
}
}
impl core::fmt::Debug for Fcs {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Fcs")
.field("en", &self.en())
.field("shift", &self.shift())
.field("err", &self.err())
.field("dreq_en", &self.dreq_en())
.field("empty", &self.empty())
.field("full", &self.full())
.field("under", &self.under())
.field("over", &self.over())
.field("level", &self.level())
.field("thresh", &self.thresh())
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for Fcs {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct Fcs {
en: bool,
shift: bool,
err: bool,
dreq_en: bool,
empty: bool,
full: bool,
under: bool,
over: bool,
level: u8,
thresh: u8,
}
let proxy = Fcs {
en: self.en(),
shift: self.shift(),
err: self.err(),
dreq_en: self.dreq_en(),
empty: self.empty(),
full: self.full(),
under: self.under(),
over: self.over(),
level: self.level(),
thresh: self.thresh(),
};
defmt::write!(f, "{}", proxy)
}
}
#[doc = "Conversion result FIFO"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -293,6 +407,29 @@ impl Default for Fifo {
Fifo(0)
}
}
impl core::fmt::Debug for Fifo {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Fifo")
.field("val", &self.val())
.field("err", &self.err())
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for Fifo {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct Fifo {
val: u16,
err: bool,
}
let proxy = Fifo {
val: self.val(),
err: self.err(),
};
defmt::write!(f, "{}", proxy)
}
}
#[doc = "Interrupt Enable"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
Expand All @@ -316,6 +453,22 @@ impl Default for Int {
Int(0)
}
}
impl core::fmt::Debug for Int {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Int").field("fifo", &self.fifo()).finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for Int {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct Int {
fifo: bool,
}
let proxy = Int { fifo: self.fifo() };
defmt::write!(f, "{}", proxy)
}
}
#[doc = "Result of most recent ADC conversion"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
Expand All @@ -337,3 +490,23 @@ impl Default for Result {
Result(0)
}
}
impl core::fmt::Debug for Result {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Result")
.field("result", &self.result())
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for Result {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct Result {
result: u16,
}
let proxy = Result {
result: self.result(),
};
defmt::write!(f, "{}", proxy)
}
}
95 changes: 92 additions & 3 deletions src/rp2040/busctrl/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@ impl Default for BusPriority {
BusPriority(0)
}
}
impl core::fmt::Debug for BusPriority {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("BusPriority")
.field("proc0", &self.proc0())
.field("proc1", &self.proc1())
.field("dma_r", &self.dma_r())
.field("dma_w", &self.dma_w())
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for BusPriority {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct BusPriority {
proc0: bool,
proc1: bool,
dma_r: bool,
dma_w: bool,
}
let proxy = BusPriority {
proc0: self.proc0(),
proc1: self.proc1(),
dma_r: self.dma_r(),
dma_w: self.dma_w(),
};
defmt::write!(f, "{}", proxy)
}
}
#[doc = "Bus priority acknowledge"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
Expand All @@ -77,18 +106,38 @@ impl Default for BusPriorityAck {
BusPriorityAck(0)
}
}
#[doc = "Bus fabric performance counter 2"]
impl core::fmt::Debug for BusPriorityAck {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("BusPriorityAck")
.field("bus_priority_ack", &self.bus_priority_ack())
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for BusPriorityAck {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct BusPriorityAck {
bus_priority_ack: bool,
}
let proxy = BusPriorityAck {
bus_priority_ack: self.bus_priority_ack(),
};
defmt::write!(f, "{}", proxy)
}
}
#[doc = "Bus fabric performance counter 0"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Perfctr(pub u32);
impl Perfctr {
#[doc = "Busfabric saturating performance counter 2 Count some event signal from the busfabric arbiters. Write any value to clear. Select an event to count using PERFSEL2"]
#[doc = "Busfabric saturating performance counter 0 Count some event signal from the busfabric arbiters. Write any value to clear. Select an event to count using PERFSEL0"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example: Here 2 was replaced with 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, this is expected, it's ok

#[inline(always)]
pub const fn perfctr(&self) -> u32 {
let val = (self.0 >> 0usize) & 0x00ff_ffff;
val as u32
}
#[doc = "Busfabric saturating performance counter 2 Count some event signal from the busfabric arbiters. Write any value to clear. Select an event to count using PERFSEL2"]
#[doc = "Busfabric saturating performance counter 0 Count some event signal from the busfabric arbiters. Write any value to clear. Select an event to count using PERFSEL0"]
#[inline(always)]
pub fn set_perfctr(&mut self, val: u32) {
self.0 = (self.0 & !(0x00ff_ffff << 0usize)) | (((val as u32) & 0x00ff_ffff) << 0usize);
Expand All @@ -100,6 +149,26 @@ impl Default for Perfctr {
Perfctr(0)
}
}
impl core::fmt::Debug for Perfctr {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Perfctr")
.field("perfctr", &self.perfctr())
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for Perfctr {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct Perfctr {
perfctr: u32,
}
let proxy = Perfctr {
perfctr: self.perfctr(),
};
defmt::write!(f, "{}", proxy)
}
}
#[doc = "Bus fabric performance event select for PERFCTR0"]
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq)]
Expand All @@ -123,3 +192,23 @@ impl Default for Perfsel {
Perfsel(0)
}
}
impl core::fmt::Debug for Perfsel {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.debug_struct("Perfsel")
.field("perfsel", &self.perfsel())
.finish()
}
}
#[cfg(feature = "defmt")]
impl defmt::Format for Perfsel {
fn format(&self, f: defmt::Formatter) {
#[derive(defmt :: Format)]
struct Perfsel {
perfsel: super::vals::Perfsel,
}
let proxy = Perfsel {
perfsel: self.perfsel(),
};
defmt::write!(f, "{}", proxy)
}
}
3 changes: 2 additions & 1 deletion src/rp2040/busctrl/vals.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[repr(u8)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Perfsel {
APB_CONTESTED = 0x0,
APB = 0x01,
Expand Down
Loading