Skip to content

Commit

Permalink
add missing defmt impls
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Nov 3, 2024
1 parent 92ff0c7 commit 9161648
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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 9161648

Please sign in to comment.