Skip to content

Commit

Permalink
Merge pull request #881 from rust-embedded/defmt-err
Browse files Browse the repository at this point in the history
add missing defmt impls
  • Loading branch information
Emilgardis authored Nov 5, 2024
2 parents 99e3073 + df9ae4d commit e8fddfa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
## [Unreleased]

- Revert #711
- Add `defmt` impls for `TryFromInterruptError`, riscv interrupt enums
- Fix calculating `modifiedWriteValues` bitmasks with field arrays
- Fix building without `yaml` feature
- Compatibility with `riscv` 0.12 and `riscv-rt` 0.13
Expand Down
1 change: 1 addition & 0 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
&d.peripherals,
device_x,
settings.as_ref().unwrap(),
config,
)?);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/generate/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ pub fn render(
}

/// TryFromInterruptError
#defmt
#[derive(Debug, Copy, Clone)]
pub struct TryFromInterruptError(());

Expand All @@ -337,6 +338,7 @@ pub fn render(
#interrupt_enum

/// TryFromInterruptError
#defmt
#[derive(Debug, Copy, Clone)]
pub struct TryFromInterruptError(());

Expand Down
13 changes: 12 additions & 1 deletion src/generate/riscv.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{svd::Peripheral, util, Settings};
use crate::{svd::Peripheral, util, Config, Settings};
use anyhow::Result;
use log::debug;
use proc_macro2::TokenStream;
Expand All @@ -21,9 +21,15 @@ pub fn render(
peripherals: &[Peripheral],
device_x: &mut String,
settings: &Settings,
config: &Config,
) -> Result<TokenStream> {
let mut mod_items = TokenStream::new();

let defmt = config
.impl_defmt
.as_ref()
.map(|feature| quote!(#[cfg_attr(feature = #feature, derive(defmt::Format))]));

if let Some(c) = settings.riscv_config.as_ref() {
if !c.core_interrupts.is_empty() {
debug!("Rendering target-specific core interrupts");
Expand All @@ -48,6 +54,7 @@ pub fn render(
mod_items.extend(quote! {
/// Core interrupts. These interrupts are handled by the core itself.
#[riscv::pac_enum(unsafe CoreInterruptNumber)]
#defmt
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CoreInterrupt {
#(#interrupts)*
Expand Down Expand Up @@ -77,6 +84,7 @@ pub fn render(
mod_items.extend(quote! {
/// Exception sources in the device.
#[riscv::pac_enum(unsafe ExceptionNumber)]
#defmt
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Exception {
#(#exceptions)*
Expand All @@ -102,6 +110,7 @@ pub fn render(
mod_items.extend(quote! {
/// Priority levels in the device
#[riscv::pac_enum(unsafe PriorityNumber)]
#defmt
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Priority {
#(#priorities)*
Expand All @@ -124,6 +133,7 @@ pub fn render(
mod_items.extend(quote! {
/// HARTs in the device
#[riscv::pac_enum(unsafe HartIdNumber)]
#defmt
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Hart {
#(#harts)*
Expand Down Expand Up @@ -197,6 +207,7 @@ pub fn render(
mod_items.extend(quote! {
/// External interrupts. These interrupts are handled by the external peripherals.
#[riscv::pac_enum(unsafe ExternalInterruptNumber)]
#defmt
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ExternalInterrupt {
#(#interrupts)*
Expand Down

0 comments on commit e8fddfa

Please sign in to comment.