1 | #![allow (clippy::missing_safety_doc)] |
2 | #![allow (clippy::identity_op)] |
3 | #![allow (clippy::unnecessary_cast)] |
4 | #![allow (clippy::erasing_op)] |
5 | |
6 | #[doc = "Random number generator" ] |
7 | #[derive (Copy, Clone, Eq, PartialEq)] |
8 | pub struct Rng { |
9 | ptr: *mut u8, |
10 | } |
11 | unsafe impl Send for Rng {} |
12 | unsafe impl Sync for Rng {} |
13 | impl Rng { |
14 | #[inline (always)] |
15 | pub const unsafe fn from_ptr(ptr: *mut ()) -> Self { |
16 | Self { ptr: ptr as _ } |
17 | } |
18 | #[inline (always)] |
19 | pub const fn as_ptr(&self) -> *mut () { |
20 | self.ptr as _ |
21 | } |
22 | #[doc = "control register" ] |
23 | #[inline (always)] |
24 | pub const fn cr(self) -> crate::common::Reg<regs::Cr, crate::common::RW> { |
25 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x0usize) as _) } |
26 | } |
27 | #[doc = "status register" ] |
28 | #[inline (always)] |
29 | pub const fn sr(self) -> crate::common::Reg<regs::Sr, crate::common::RW> { |
30 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x04usize) as _) } |
31 | } |
32 | #[doc = "data register" ] |
33 | #[inline (always)] |
34 | pub const fn dr(self) -> crate::common::Reg<u32, crate::common::R> { |
35 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x08usize) as _) } |
36 | } |
37 | #[doc = "health test control register" ] |
38 | #[inline (always)] |
39 | pub const fn htcr(self) -> crate::common::Reg<regs::Htcr, crate::common::RW> { |
40 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x10usize) as _) } |
41 | } |
42 | } |
43 | pub mod regs { |
44 | #[doc = "control register" ] |
45 | #[repr (transparent)] |
46 | #[derive (Copy, Clone, Eq, PartialEq)] |
47 | pub struct Cr(pub u32); |
48 | impl Cr { |
49 | #[doc = "Random number generator enable" ] |
50 | #[inline (always)] |
51 | pub const fn rngen(&self) -> bool { |
52 | let val = (self.0 >> 2usize) & 0x01; |
53 | val != 0 |
54 | } |
55 | #[doc = "Random number generator enable" ] |
56 | #[inline (always)] |
57 | pub fn set_rngen(&mut self, val: bool) { |
58 | self.0 = (self.0 & !(0x01 << 2usize)) | (((val as u32) & 0x01) << 2usize); |
59 | } |
60 | #[doc = "Interrupt enable" ] |
61 | #[inline (always)] |
62 | pub const fn ie(&self) -> bool { |
63 | let val = (self.0 >> 3usize) & 0x01; |
64 | val != 0 |
65 | } |
66 | #[doc = "Interrupt enable" ] |
67 | #[inline (always)] |
68 | pub fn set_ie(&mut self, val: bool) { |
69 | self.0 = (self.0 & !(0x01 << 3usize)) | (((val as u32) & 0x01) << 3usize); |
70 | } |
71 | #[doc = "Clock error detection" ] |
72 | #[inline (always)] |
73 | pub const fn ced(&self) -> bool { |
74 | let val = (self.0 >> 5usize) & 0x01; |
75 | val != 0 |
76 | } |
77 | #[doc = "Clock error detection" ] |
78 | #[inline (always)] |
79 | pub fn set_ced(&mut self, val: bool) { |
80 | self.0 = (self.0 & !(0x01 << 5usize)) | (((val as u32) & 0x01) << 5usize); |
81 | } |
82 | #[doc = "Auto reset disable" ] |
83 | #[inline (always)] |
84 | pub const fn ardis(&self) -> bool { |
85 | let val = (self.0 >> 7usize) & 0x01; |
86 | val != 0 |
87 | } |
88 | #[doc = "Auto reset disable" ] |
89 | #[inline (always)] |
90 | pub fn set_ardis(&mut self, val: bool) { |
91 | self.0 = (self.0 & !(0x01 << 7usize)) | (((val as u32) & 0x01) << 7usize); |
92 | } |
93 | #[doc = "RNG configuration 3" ] |
94 | #[inline (always)] |
95 | pub const fn rng_config3(&self) -> super::vals::RngConfig3 { |
96 | let val = (self.0 >> 8usize) & 0x0f; |
97 | super::vals::RngConfig3::from_bits(val as u8) |
98 | } |
99 | #[doc = "RNG configuration 3" ] |
100 | #[inline (always)] |
101 | pub fn set_rng_config3(&mut self, val: super::vals::RngConfig3) { |
102 | self.0 = (self.0 & !(0x0f << 8usize)) | (((val.to_bits() as u32) & 0x0f) << 8usize); |
103 | } |
104 | #[doc = "Non NIST compliant" ] |
105 | #[inline (always)] |
106 | pub const fn nistc(&self) -> super::vals::Nistc { |
107 | let val = (self.0 >> 12usize) & 0x01; |
108 | super::vals::Nistc::from_bits(val as u8) |
109 | } |
110 | #[doc = "Non NIST compliant" ] |
111 | #[inline (always)] |
112 | pub fn set_nistc(&mut self, val: super::vals::Nistc) { |
113 | self.0 = (self.0 & !(0x01 << 12usize)) | (((val.to_bits() as u32) & 0x01) << 12usize); |
114 | } |
115 | #[doc = "RNG configuration 2" ] |
116 | #[inline (always)] |
117 | pub const fn rng_config2(&self) -> super::vals::RngConfig2 { |
118 | let val = (self.0 >> 13usize) & 0x07; |
119 | super::vals::RngConfig2::from_bits(val as u8) |
120 | } |
121 | #[doc = "RNG configuration 2" ] |
122 | #[inline (always)] |
123 | pub fn set_rng_config2(&mut self, val: super::vals::RngConfig2) { |
124 | self.0 = (self.0 & !(0x07 << 13usize)) | (((val.to_bits() as u32) & 0x07) << 13usize); |
125 | } |
126 | #[doc = "Clock divider factor" ] |
127 | #[inline (always)] |
128 | pub const fn clkdiv(&self) -> super::vals::Clkdiv { |
129 | let val = (self.0 >> 16usize) & 0x0f; |
130 | super::vals::Clkdiv::from_bits(val as u8) |
131 | } |
132 | #[doc = "Clock divider factor" ] |
133 | #[inline (always)] |
134 | pub fn set_clkdiv(&mut self, val: super::vals::Clkdiv) { |
135 | self.0 = (self.0 & !(0x0f << 16usize)) | (((val.to_bits() as u32) & 0x0f) << 16usize); |
136 | } |
137 | #[doc = "RNG configuration 1" ] |
138 | #[inline (always)] |
139 | pub const fn rng_config1(&self) -> super::vals::RngConfig1 { |
140 | let val = (self.0 >> 20usize) & 0x3f; |
141 | super::vals::RngConfig1::from_bits(val as u8) |
142 | } |
143 | #[doc = "RNG configuration 1" ] |
144 | #[inline (always)] |
145 | pub fn set_rng_config1(&mut self, val: super::vals::RngConfig1) { |
146 | self.0 = (self.0 & !(0x3f << 20usize)) | (((val.to_bits() as u32) & 0x3f) << 20usize); |
147 | } |
148 | #[doc = "Conditioning soft reset" ] |
149 | #[inline (always)] |
150 | pub const fn condrst(&self) -> bool { |
151 | let val = (self.0 >> 30usize) & 0x01; |
152 | val != 0 |
153 | } |
154 | #[doc = "Conditioning soft reset" ] |
155 | #[inline (always)] |
156 | pub fn set_condrst(&mut self, val: bool) { |
157 | self.0 = (self.0 & !(0x01 << 30usize)) | (((val as u32) & 0x01) << 30usize); |
158 | } |
159 | #[doc = "Config Lock" ] |
160 | #[inline (always)] |
161 | pub const fn configlock(&self) -> bool { |
162 | let val = (self.0 >> 31usize) & 0x01; |
163 | val != 0 |
164 | } |
165 | #[doc = "Config Lock" ] |
166 | #[inline (always)] |
167 | pub fn set_configlock(&mut self, val: bool) { |
168 | self.0 = (self.0 & !(0x01 << 31usize)) | (((val as u32) & 0x01) << 31usize); |
169 | } |
170 | } |
171 | impl Default for Cr { |
172 | #[inline (always)] |
173 | fn default() -> Cr { |
174 | Cr(0) |
175 | } |
176 | } |
177 | impl core::fmt::Debug for Cr { |
178 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
179 | f.debug_struct("Cr" ) |
180 | .field("rngen" , &self.rngen()) |
181 | .field("ie" , &self.ie()) |
182 | .field("ced" , &self.ced()) |
183 | .field("ardis" , &self.ardis()) |
184 | .field("rng_config3" , &self.rng_config3()) |
185 | .field("nistc" , &self.nistc()) |
186 | .field("rng_config2" , &self.rng_config2()) |
187 | .field("clkdiv" , &self.clkdiv()) |
188 | .field("rng_config1" , &self.rng_config1()) |
189 | .field("condrst" , &self.condrst()) |
190 | .field("configlock" , &self.configlock()) |
191 | .finish() |
192 | } |
193 | } |
194 | #[cfg (feature = "defmt" )] |
195 | impl defmt::Format for Cr { |
196 | fn format(&self, f: defmt::Formatter) { |
197 | #[derive (defmt :: Format)] |
198 | struct Cr { |
199 | rngen: bool, |
200 | ie: bool, |
201 | ced: bool, |
202 | ardis: bool, |
203 | rng_config3: super::vals::RngConfig3, |
204 | nistc: super::vals::Nistc, |
205 | rng_config2: super::vals::RngConfig2, |
206 | clkdiv: super::vals::Clkdiv, |
207 | rng_config1: super::vals::RngConfig1, |
208 | condrst: bool, |
209 | configlock: bool, |
210 | } |
211 | let proxy = Cr { |
212 | rngen: self.rngen(), |
213 | ie: self.ie(), |
214 | ced: self.ced(), |
215 | ardis: self.ardis(), |
216 | rng_config3: self.rng_config3(), |
217 | nistc: self.nistc(), |
218 | rng_config2: self.rng_config2(), |
219 | clkdiv: self.clkdiv(), |
220 | rng_config1: self.rng_config1(), |
221 | condrst: self.condrst(), |
222 | configlock: self.configlock(), |
223 | }; |
224 | defmt::write!(f, "{}" , proxy) |
225 | } |
226 | } |
227 | #[doc = "Health test control register" ] |
228 | #[repr (transparent)] |
229 | #[derive (Copy, Clone, Eq, PartialEq)] |
230 | pub struct Htcr(pub u32); |
231 | impl Htcr { |
232 | #[doc = "Health test configuration" ] |
233 | #[inline (always)] |
234 | pub const fn htcfg(&self) -> super::vals::Htcfg { |
235 | let val = (self.0 >> 0usize) & 0xffff_ffff; |
236 | super::vals::Htcfg::from_bits(val as u32) |
237 | } |
238 | #[doc = "Health test configuration" ] |
239 | #[inline (always)] |
240 | pub fn set_htcfg(&mut self, val: super::vals::Htcfg) { |
241 | self.0 = (self.0 & !(0xffff_ffff << 0usize)) | (((val.to_bits() as u32) & 0xffff_ffff) << 0usize); |
242 | } |
243 | } |
244 | impl Default for Htcr { |
245 | #[inline (always)] |
246 | fn default() -> Htcr { |
247 | Htcr(0) |
248 | } |
249 | } |
250 | impl core::fmt::Debug for Htcr { |
251 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
252 | f.debug_struct("Htcr" ).field("htcfg" , &self.htcfg()).finish() |
253 | } |
254 | } |
255 | #[cfg (feature = "defmt" )] |
256 | impl defmt::Format for Htcr { |
257 | fn format(&self, f: defmt::Formatter) { |
258 | #[derive (defmt :: Format)] |
259 | struct Htcr { |
260 | htcfg: super::vals::Htcfg, |
261 | } |
262 | let proxy = Htcr { htcfg: self.htcfg() }; |
263 | defmt::write!(f, "{}" , proxy) |
264 | } |
265 | } |
266 | #[doc = "status register" ] |
267 | #[repr (transparent)] |
268 | #[derive (Copy, Clone, Eq, PartialEq)] |
269 | pub struct Sr(pub u32); |
270 | impl Sr { |
271 | #[doc = "Data ready" ] |
272 | #[inline (always)] |
273 | pub const fn drdy(&self) -> bool { |
274 | let val = (self.0 >> 0usize) & 0x01; |
275 | val != 0 |
276 | } |
277 | #[doc = "Data ready" ] |
278 | #[inline (always)] |
279 | pub fn set_drdy(&mut self, val: bool) { |
280 | self.0 = (self.0 & !(0x01 << 0usize)) | (((val as u32) & 0x01) << 0usize); |
281 | } |
282 | #[doc = "Clock error current status" ] |
283 | #[inline (always)] |
284 | pub const fn cecs(&self) -> bool { |
285 | let val = (self.0 >> 1usize) & 0x01; |
286 | val != 0 |
287 | } |
288 | #[doc = "Clock error current status" ] |
289 | #[inline (always)] |
290 | pub fn set_cecs(&mut self, val: bool) { |
291 | self.0 = (self.0 & !(0x01 << 1usize)) | (((val as u32) & 0x01) << 1usize); |
292 | } |
293 | #[doc = "Seed error current status" ] |
294 | #[inline (always)] |
295 | pub const fn secs(&self) -> bool { |
296 | let val = (self.0 >> 2usize) & 0x01; |
297 | val != 0 |
298 | } |
299 | #[doc = "Seed error current status" ] |
300 | #[inline (always)] |
301 | pub fn set_secs(&mut self, val: bool) { |
302 | self.0 = (self.0 & !(0x01 << 2usize)) | (((val as u32) & 0x01) << 2usize); |
303 | } |
304 | #[doc = "Clock error interrupt status" ] |
305 | #[inline (always)] |
306 | pub const fn ceis(&self) -> bool { |
307 | let val = (self.0 >> 5usize) & 0x01; |
308 | val != 0 |
309 | } |
310 | #[doc = "Clock error interrupt status" ] |
311 | #[inline (always)] |
312 | pub fn set_ceis(&mut self, val: bool) { |
313 | self.0 = (self.0 & !(0x01 << 5usize)) | (((val as u32) & 0x01) << 5usize); |
314 | } |
315 | #[doc = "Seed error interrupt status" ] |
316 | #[inline (always)] |
317 | pub const fn seis(&self) -> bool { |
318 | let val = (self.0 >> 6usize) & 0x01; |
319 | val != 0 |
320 | } |
321 | #[doc = "Seed error interrupt status" ] |
322 | #[inline (always)] |
323 | pub fn set_seis(&mut self, val: bool) { |
324 | self.0 = (self.0 & !(0x01 << 6usize)) | (((val as u32) & 0x01) << 6usize); |
325 | } |
326 | } |
327 | impl Default for Sr { |
328 | #[inline (always)] |
329 | fn default() -> Sr { |
330 | Sr(0) |
331 | } |
332 | } |
333 | impl core::fmt::Debug for Sr { |
334 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
335 | f.debug_struct("Sr" ) |
336 | .field("drdy" , &self.drdy()) |
337 | .field("cecs" , &self.cecs()) |
338 | .field("secs" , &self.secs()) |
339 | .field("ceis" , &self.ceis()) |
340 | .field("seis" , &self.seis()) |
341 | .finish() |
342 | } |
343 | } |
344 | #[cfg (feature = "defmt" )] |
345 | impl defmt::Format for Sr { |
346 | fn format(&self, f: defmt::Formatter) { |
347 | #[derive (defmt :: Format)] |
348 | struct Sr { |
349 | drdy: bool, |
350 | cecs: bool, |
351 | secs: bool, |
352 | ceis: bool, |
353 | seis: bool, |
354 | } |
355 | let proxy = Sr { |
356 | drdy: self.drdy(), |
357 | cecs: self.cecs(), |
358 | secs: self.secs(), |
359 | ceis: self.ceis(), |
360 | seis: self.seis(), |
361 | }; |
362 | defmt::write!(f, "{}" , proxy) |
363 | } |
364 | } |
365 | } |
366 | pub mod vals { |
367 | #[repr (u8)] |
368 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
369 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
370 | pub enum Clkdiv { |
371 | #[doc = "Internal RNG clock after divider is similar to incoming RNG clock" ] |
372 | NO_DIV = 0x0, |
373 | #[doc = "Divide RNG clock by 2^1" ] |
374 | DIV_2_1 = 0x01, |
375 | #[doc = "Divide RNG clock by 2^2" ] |
376 | DIV_2_2 = 0x02, |
377 | #[doc = "Divide RNG clock by 2^3" ] |
378 | DIV_2_3 = 0x03, |
379 | #[doc = "Divide RNG clock by 2^4" ] |
380 | DIV_2_4 = 0x04, |
381 | #[doc = "Divide RNG clock by 2^5" ] |
382 | DIV_2_5 = 0x05, |
383 | #[doc = "Divide RNG clock by 2^6" ] |
384 | DIV_2_6 = 0x06, |
385 | #[doc = "Divide RNG clock by 2^7" ] |
386 | DIV_2_7 = 0x07, |
387 | #[doc = "Divide RNG clock by 2^8" ] |
388 | DIV_2_8 = 0x08, |
389 | #[doc = "Divide RNG clock by 2^9" ] |
390 | DIV_2_9 = 0x09, |
391 | #[doc = "Divide RNG clock by 2^10" ] |
392 | DIV_2_10 = 0x0a, |
393 | #[doc = "Divide RNG clock by 2^11" ] |
394 | DIV_2_11 = 0x0b, |
395 | #[doc = "Divide RNG clock by 2^12" ] |
396 | DIV_2_12 = 0x0c, |
397 | #[doc = "Divide RNG clock by 2^13" ] |
398 | DIV_2_13 = 0x0d, |
399 | #[doc = "Divide RNG clock by 2^14" ] |
400 | DIV_2_14 = 0x0e, |
401 | #[doc = "Divide RNG clock by 2^15" ] |
402 | DIV_2_15 = 0x0f, |
403 | } |
404 | impl Clkdiv { |
405 | #[inline (always)] |
406 | pub const fn from_bits(val: u8) -> Clkdiv { |
407 | unsafe { core::mem::transmute(val & 0x0f) } |
408 | } |
409 | #[inline (always)] |
410 | pub const fn to_bits(self) -> u8 { |
411 | unsafe { core::mem::transmute(self) } |
412 | } |
413 | } |
414 | impl From<u8> for Clkdiv { |
415 | #[inline (always)] |
416 | fn from(val: u8) -> Clkdiv { |
417 | Clkdiv::from_bits(val) |
418 | } |
419 | } |
420 | impl From<Clkdiv> for u8 { |
421 | #[inline (always)] |
422 | fn from(val: Clkdiv) -> u8 { |
423 | Clkdiv::to_bits(val) |
424 | } |
425 | } |
426 | #[repr (transparent)] |
427 | #[derive (Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
428 | pub struct Htcfg(pub u32); |
429 | impl Htcfg { |
430 | #[doc = "Recommended value for RNG certification (0x0000_AA74)" ] |
431 | pub const RECOMMENDED: Self = Self(0xaa74); |
432 | #[doc = "Magic number to be written before any write (0x1759_0ABC)" ] |
433 | pub const MAGIC: Self = Self(0x1759_0abc); |
434 | } |
435 | impl Htcfg { |
436 | pub const fn from_bits(val: u32) -> Htcfg { |
437 | Self(val & 0xffff_ffff) |
438 | } |
439 | pub const fn to_bits(self) -> u32 { |
440 | self.0 |
441 | } |
442 | } |
443 | impl core::fmt::Debug for Htcfg { |
444 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
445 | match self.0 { |
446 | 0xaa74 => f.write_str("RECOMMENDED" ), |
447 | 0x1759_0abc => f.write_str("MAGIC" ), |
448 | other => core::write!(f, "0x {:02X}" , other), |
449 | } |
450 | } |
451 | } |
452 | #[cfg (feature = "defmt" )] |
453 | impl defmt::Format for Htcfg { |
454 | fn format(&self, f: defmt::Formatter) { |
455 | match self.0 { |
456 | 0xaa74 => defmt::write!(f, "RECOMMENDED" ), |
457 | 0x1759_0abc => defmt::write!(f, "MAGIC" ), |
458 | other => defmt::write!(f, "0x{:02X}" , other), |
459 | } |
460 | } |
461 | } |
462 | impl From<u32> for Htcfg { |
463 | #[inline (always)] |
464 | fn from(val: u32) -> Htcfg { |
465 | Htcfg::from_bits(val) |
466 | } |
467 | } |
468 | impl From<Htcfg> for u32 { |
469 | #[inline (always)] |
470 | fn from(val: Htcfg) -> u32 { |
471 | Htcfg::to_bits(val) |
472 | } |
473 | } |
474 | #[repr (u8)] |
475 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
476 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
477 | pub enum Nistc { |
478 | #[doc = "Hardware default values for NIST compliant RNG. In this configuration per 128-bit output two conditioning loops are performed and 256 bits of noise source are used" ] |
479 | DEFAULT = 0x0, |
480 | #[doc = "Custom values for NIST compliant RNG" ] |
481 | CUSTOM = 0x01, |
482 | } |
483 | impl Nistc { |
484 | #[inline (always)] |
485 | pub const fn from_bits(val: u8) -> Nistc { |
486 | unsafe { core::mem::transmute(val & 0x01) } |
487 | } |
488 | #[inline (always)] |
489 | pub const fn to_bits(self) -> u8 { |
490 | unsafe { core::mem::transmute(self) } |
491 | } |
492 | } |
493 | impl From<u8> for Nistc { |
494 | #[inline (always)] |
495 | fn from(val: u8) -> Nistc { |
496 | Nistc::from_bits(val) |
497 | } |
498 | } |
499 | impl From<Nistc> for u8 { |
500 | #[inline (always)] |
501 | fn from(val: Nistc) -> u8 { |
502 | Nistc::to_bits(val) |
503 | } |
504 | } |
505 | #[repr (transparent)] |
506 | #[derive (Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
507 | pub struct RngConfig1(pub u8); |
508 | impl RngConfig1 { |
509 | #[doc = "Recommended value for config A (NIST certifiable)" ] |
510 | pub const CONFIG_A: Self = Self(0x0f); |
511 | #[doc = "Recommended value for config B (not NIST certifiable)" ] |
512 | pub const CONFIG_B: Self = Self(0x18); |
513 | } |
514 | impl RngConfig1 { |
515 | pub const fn from_bits(val: u8) -> RngConfig1 { |
516 | Self(val & 0x3f) |
517 | } |
518 | pub const fn to_bits(self) -> u8 { |
519 | self.0 |
520 | } |
521 | } |
522 | impl core::fmt::Debug for RngConfig1 { |
523 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
524 | match self.0 { |
525 | 0x0f => f.write_str("CONFIG_A" ), |
526 | 0x18 => f.write_str("CONFIG_B" ), |
527 | other => core::write!(f, "0x {:02X}" , other), |
528 | } |
529 | } |
530 | } |
531 | #[cfg (feature = "defmt" )] |
532 | impl defmt::Format for RngConfig1 { |
533 | fn format(&self, f: defmt::Formatter) { |
534 | match self.0 { |
535 | 0x0f => defmt::write!(f, "CONFIG_A" ), |
536 | 0x18 => defmt::write!(f, "CONFIG_B" ), |
537 | other => defmt::write!(f, "0x{:02X}" , other), |
538 | } |
539 | } |
540 | } |
541 | impl From<u8> for RngConfig1 { |
542 | #[inline (always)] |
543 | fn from(val: u8) -> RngConfig1 { |
544 | RngConfig1::from_bits(val) |
545 | } |
546 | } |
547 | impl From<RngConfig1> for u8 { |
548 | #[inline (always)] |
549 | fn from(val: RngConfig1) -> u8 { |
550 | RngConfig1::to_bits(val) |
551 | } |
552 | } |
553 | #[repr (u8)] |
554 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
555 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
556 | pub enum RngConfig2 { |
557 | #[doc = "Recommended value for config A and B" ] |
558 | CONFIG_A_B = 0x0, |
559 | _RESERVED_1 = 0x01, |
560 | _RESERVED_2 = 0x02, |
561 | _RESERVED_3 = 0x03, |
562 | _RESERVED_4 = 0x04, |
563 | _RESERVED_5 = 0x05, |
564 | _RESERVED_6 = 0x06, |
565 | _RESERVED_7 = 0x07, |
566 | } |
567 | impl RngConfig2 { |
568 | #[inline (always)] |
569 | pub const fn from_bits(val: u8) -> RngConfig2 { |
570 | unsafe { core::mem::transmute(val & 0x07) } |
571 | } |
572 | #[inline (always)] |
573 | pub const fn to_bits(self) -> u8 { |
574 | unsafe { core::mem::transmute(self) } |
575 | } |
576 | } |
577 | impl From<u8> for RngConfig2 { |
578 | #[inline (always)] |
579 | fn from(val: u8) -> RngConfig2 { |
580 | RngConfig2::from_bits(val) |
581 | } |
582 | } |
583 | impl From<RngConfig2> for u8 { |
584 | #[inline (always)] |
585 | fn from(val: RngConfig2) -> u8 { |
586 | RngConfig2::to_bits(val) |
587 | } |
588 | } |
589 | #[repr (u8)] |
590 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
591 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
592 | pub enum RngConfig3 { |
593 | #[doc = "Recommended value for config B (not NIST certifiable)" ] |
594 | CONFIG_B = 0x0, |
595 | _RESERVED_1 = 0x01, |
596 | _RESERVED_2 = 0x02, |
597 | _RESERVED_3 = 0x03, |
598 | _RESERVED_4 = 0x04, |
599 | _RESERVED_5 = 0x05, |
600 | _RESERVED_6 = 0x06, |
601 | _RESERVED_7 = 0x07, |
602 | _RESERVED_8 = 0x08, |
603 | _RESERVED_9 = 0x09, |
604 | _RESERVED_a = 0x0a, |
605 | _RESERVED_b = 0x0b, |
606 | _RESERVED_c = 0x0c, |
607 | #[doc = "Recommended value for config A (NIST certifiable)" ] |
608 | CONFIG_A = 0x0d, |
609 | _RESERVED_e = 0x0e, |
610 | _RESERVED_f = 0x0f, |
611 | } |
612 | impl RngConfig3 { |
613 | #[inline (always)] |
614 | pub const fn from_bits(val: u8) -> RngConfig3 { |
615 | unsafe { core::mem::transmute(val & 0x0f) } |
616 | } |
617 | #[inline (always)] |
618 | pub const fn to_bits(self) -> u8 { |
619 | unsafe { core::mem::transmute(self) } |
620 | } |
621 | } |
622 | impl From<u8> for RngConfig3 { |
623 | #[inline (always)] |
624 | fn from(val: u8) -> RngConfig3 { |
625 | RngConfig3::from_bits(val) |
626 | } |
627 | } |
628 | impl From<RngConfig3> for u8 { |
629 | #[inline (always)] |
630 | fn from(val: RngConfig3) -> u8 { |
631 | RngConfig3::to_bits(val) |
632 | } |
633 | } |
634 | } |
635 | |