1- use crate :: { svd:: Peripheral , util, Settings } ;
1+ use crate :: { svd:: Peripheral , util, Config , Settings } ;
22use anyhow:: Result ;
33use log:: debug;
44use 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