Skip to content

Commit e8fddfa

Browse files
authored
Merge pull request #881 from rust-embedded/defmt-err
add missing defmt impls
2 parents 99e3073 + df9ae4d commit e8fddfa

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
88
## [Unreleased]
99

1010
- Revert #711
11+
- Add `defmt` impls for `TryFromInterruptError`, riscv interrupt enums
1112
- Fix calculating `modifiedWriteValues` bitmasks with field arrays
1213
- Fix building without `yaml` feature
1314
- Compatibility with `riscv` 0.12 and `riscv-rt` 0.13

src/generate/device.rs

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
217217
&d.peripherals,
218218
device_x,
219219
settings.as_ref().unwrap(),
220+
config,
220221
)?);
221222
}
222223
}

src/generate/interrupt.rs

+2
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ pub fn render(
316316
}
317317

318318
/// TryFromInterruptError
319+
#defmt
319320
#[derive(Debug, Copy, Clone)]
320321
pub struct TryFromInterruptError(());
321322

@@ -337,6 +338,7 @@ pub fn render(
337338
#interrupt_enum
338339

339340
/// TryFromInterruptError
341+
#defmt
340342
#[derive(Debug, Copy, Clone)]
341343
pub struct TryFromInterruptError(());
342344

src/generate/riscv.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{svd::Peripheral, util, Settings};
1+
use crate::{svd::Peripheral, util, Config, Settings};
22
use anyhow::Result;
33
use log::debug;
44
use proc_macro2::TokenStream;
@@ -21,9 +21,15 @@ pub fn render(
2121
peripherals: &[Peripheral],
2222
device_x: &mut String,
2323
settings: &Settings,
24+
config: &Config,
2425
) -> Result<TokenStream> {
2526
let mut mod_items = TokenStream::new();
2627

28+
let defmt = config
29+
.impl_defmt
30+
.as_ref()
31+
.map(|feature| quote!(#[cfg_attr(feature = #feature, derive(defmt::Format))]));
32+
2733
if let Some(c) = settings.riscv_config.as_ref() {
2834
if !c.core_interrupts.is_empty() {
2935
debug!("Rendering target-specific core interrupts");
@@ -48,6 +54,7 @@ pub fn render(
4854
mod_items.extend(quote! {
4955
/// Core interrupts. These interrupts are handled by the core itself.
5056
#[riscv::pac_enum(unsafe CoreInterruptNumber)]
57+
#defmt
5158
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5259
pub enum CoreInterrupt {
5360
#(#interrupts)*
@@ -77,6 +84,7 @@ pub fn render(
7784
mod_items.extend(quote! {
7885
/// Exception sources in the device.
7986
#[riscv::pac_enum(unsafe ExceptionNumber)]
87+
#defmt
8088
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8189
pub enum Exception {
8290
#(#exceptions)*
@@ -102,6 +110,7 @@ pub fn render(
102110
mod_items.extend(quote! {
103111
/// Priority levels in the device
104112
#[riscv::pac_enum(unsafe PriorityNumber)]
113+
#defmt
105114
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
106115
pub enum Priority {
107116
#(#priorities)*
@@ -124,6 +133,7 @@ pub fn render(
124133
mod_items.extend(quote! {
125134
/// HARTs in the device
126135
#[riscv::pac_enum(unsafe HartIdNumber)]
136+
#defmt
127137
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
128138
pub enum Hart {
129139
#(#harts)*
@@ -197,6 +207,7 @@ pub fn render(
197207
mod_items.extend(quote! {
198208
/// External interrupts. These interrupts are handled by the external peripherals.
199209
#[riscv::pac_enum(unsafe ExternalInterruptNumber)]
210+
#defmt
200211
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
201212
pub enum ExternalInterrupt {
202213
#(#interrupts)*

0 commit comments

Comments
 (0)