@@ -21,6 +21,7 @@ pub fn render(device: &Device, target: &Target, peripherals: &[Peripheral]) -> R
21
21
interrupts. sort_by_key ( |i| i. value ) ;
22
22
23
23
let mut arms = vec ! [ ] ;
24
+ let mut from_arms = vec ! [ ] ;
24
25
let mut elements = vec ! [ ] ;
25
26
let mut names = vec ! [ ] ;
26
27
let mut variants = vec ! [ ] ;
@@ -60,6 +61,10 @@ pub fn render(device: &Device, target: &Target, peripherals: &[Peripheral]) -> R
60
61
Interrupt :: #name_uc => #value,
61
62
} ) ;
62
63
64
+ from_arms. push ( quote ! {
65
+ #value => Ok ( Interrupt :: #name_uc) ,
66
+ } ) ;
67
+
63
68
elements. push ( quote ! ( Some ( #name_uc) ) ) ;
64
69
names. push ( name_uc) ;
65
70
}
@@ -187,6 +192,23 @@ pub fn render(device: &Device, target: &Target, peripherals: &[Peripheral]) -> R
187
192
}
188
193
}
189
194
}
195
+
196
+ use core:: convert:: TryFrom ;
197
+
198
+ #[ derive( Debug , Copy , Clone ) ]
199
+ pub struct TryFromInterruptError ( ( ) ) ;
200
+
201
+ impl TryFrom <u8 > for Interrupt {
202
+ type Error = TryFromInterruptError ;
203
+
204
+ #[ inline]
205
+ fn try_from( value: u8 ) -> Result <Self , Self :: Error > {
206
+ match value {
207
+ #( #from_arms) *
208
+ _ => Err ( TryFromInterruptError ( ( ) ) ) ,
209
+ }
210
+ }
211
+ }
190
212
} ) ;
191
213
192
214
if * target != Target :: None {
0 commit comments