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 missing defmt impls #881

Merged
merged 1 commit into from
Nov 5, 2024
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
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
Loading