@@ -40,11 +40,10 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
40
40
( false , name_snake_case. clone ( ) , BlockPath :: new ( & p. name ) )
41
41
} ;
42
42
43
- let feature_attribute = if config. feature_group && p. group_name . is_some ( ) {
43
+ let mut feature_attribute = TokenStream :: new ( ) ;
44
+ if config. feature_group && p. group_name . is_some ( ) {
44
45
let feature_name = p. group_name . as_ref ( ) . unwrap ( ) . to_sanitized_snake_case ( ) ;
45
- quote ! ( #[ cfg( feature = #feature_name) ] )
46
- } else {
47
- quote ! { }
46
+ feature_attribute. extend ( quote ! { #[ cfg( feature = #feature_name) ] } ) ;
48
47
} ;
49
48
50
49
match & p {
@@ -54,18 +53,28 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
54
53
let names_constant_case = names_str. clone ( ) . map ( |n| Ident :: new ( & n, span) ) ;
55
54
let addresses =
56
55
( 0 ..=dim. dim ) . map ( |i| util:: hex ( p. base_address + ( i * dim. dim_increment ) as u64 ) ) ;
57
-
56
+ let snake_names = names
57
+ . iter ( )
58
+ . map ( |p_name| p_name. to_sanitized_snake_case ( ) )
59
+ . collect :: < Vec < _ > > ( ) ;
60
+ let feature_attribute_n = snake_names. iter ( ) . map ( |p_snake| {
61
+ let mut feature_attribute = feature_attribute. clone ( ) ;
62
+ if config. feature_peripheral {
63
+ feature_attribute. extend ( quote ! { #[ cfg( feature = #p_snake) ] } )
64
+ } ;
65
+ feature_attribute
66
+ } ) ;
58
67
// Insert the peripherals structure
59
68
out. extend ( quote ! {
60
69
#(
61
70
#[ doc = #description]
62
- #feature_attribute
71
+ #feature_attribute_n
63
72
pub struct #names_constant_case { _marker: PhantomData <* const ( ) > }
64
73
65
- #feature_attribute
74
+ #feature_attribute_n
66
75
unsafe impl Send for #names_constant_case { }
67
76
68
- #feature_attribute
77
+ #feature_attribute_n
69
78
impl #names_constant_case {
70
79
///Pointer to the register block
71
80
pub const PTR : * const #base:: RegisterBlock = #addresses as * const _;
@@ -77,7 +86,7 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
77
86
}
78
87
}
79
88
80
- #feature_attribute
89
+ #feature_attribute_n
81
90
impl Deref for #names_constant_case {
82
91
type Target = #base:: RegisterBlock ;
83
92
@@ -87,16 +96,34 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
87
96
}
88
97
}
89
98
90
- #feature_attribute
99
+ #feature_attribute_n
91
100
impl core:: fmt:: Debug for #names_constant_case {
92
101
fn fmt( & self , f: & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
93
102
f. debug_struct( #names_str) . finish( )
94
103
}
95
104
}
96
105
) *
97
106
} ) ;
107
+
108
+ let feature_any_attribute = quote ! { #[ cfg( any( #( feature = #snake_names) , * ) ) ] } ;
109
+
110
+ // Derived peripherals may not require re-implementation, and will instead
111
+ // use a single definition of the non-derived version.
112
+ if derive_regs {
113
+ // re-export the base module to allow deriveFrom this one
114
+ out. extend ( quote ! {
115
+ #[ doc = #description]
116
+ #feature_any_attribute
117
+ pub use #base as #name_snake_case;
118
+ } ) ;
119
+ return Ok ( out) ;
120
+ }
98
121
}
99
- _ => {
122
+ Peripheral :: Single ( _) => {
123
+ let p_snake = name. to_sanitized_snake_case ( ) ;
124
+ if config. feature_peripheral {
125
+ feature_attribute. extend ( quote ! { #[ cfg( feature = #p_snake) ] } )
126
+ } ;
100
127
// Insert the peripheral structure
101
128
out. extend ( quote ! {
102
129
#[ doc = #description]
@@ -135,19 +162,19 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
135
162
}
136
163
}
137
164
} ) ;
138
- }
139
- }
140
165
141
- // Derived peripherals may not require re-implementation, and will instead
142
- // use a single definition of the non-derived version.
143
- if derive_regs {
144
- // re-export the base module to allow deriveFrom this one
145
- out. extend ( quote ! {
146
- #[ doc = #description]
147
- #feature_attribute
148
- pub use #base as #name_snake_case;
149
- } ) ;
150
- return Ok ( out) ;
166
+ // Derived peripherals may not require re-implementation, and will instead
167
+ // use a single definition of the non-derived version.
168
+ if derive_regs {
169
+ // re-export the base module to allow deriveFrom this one
170
+ out. extend ( quote ! {
171
+ #[ doc = #description]
172
+ #feature_attribute
173
+ pub use #base as #name_snake_case;
174
+ } ) ;
175
+ return Ok ( out) ;
176
+ }
177
+ }
151
178
}
152
179
153
180
let description = util:: escape_brackets (
0 commit comments