File tree Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ use core::convert::Infallible;
4
4
5
5
use embedded_hal:: blocking:: rng:: Read ;
6
6
7
- use crate :: pac:: RNG ;
7
+ use crate :: {
8
+ peripheral:: { Peripheral , PeripheralRef } ,
9
+ peripherals:: RNG ,
10
+ } ;
8
11
9
12
/// Random Number Generator
10
13
///
@@ -28,14 +31,15 @@ use crate::pac::RNG;
28
31
///
29
32
/// For more information, please refer to the ESP-IDF documentation:
30
33
/// <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/random.html>
31
- #[ derive( Debug ) ]
32
- pub struct Rng {
33
- rng : RNG ,
34
+ pub struct Rng < ' d > {
35
+ rng : PeripheralRef < ' d , RNG > ,
34
36
}
35
37
36
- impl Rng {
38
+ impl < ' d > Rng < ' d > {
37
39
/// Create a new random number generator instance
38
- pub fn new ( rng : RNG ) -> Self {
40
+ pub fn new ( rng : impl Peripheral < P = RNG > + ' d ) -> Self {
41
+ crate :: into_ref!( rng) ;
42
+
39
43
Self { rng }
40
44
}
41
45
@@ -44,14 +48,9 @@ impl Rng {
44
48
pub fn random ( & mut self ) -> u32 {
45
49
self . rng . data . read ( ) . bits ( )
46
50
}
47
-
48
- /// Return the raw interface to the underlying `Rng` instance
49
- pub fn free ( self ) -> RNG {
50
- self . rng
51
- }
52
51
}
53
52
54
- impl Read for Rng {
53
+ impl Read for Rng < ' _ > {
55
54
type Error = Infallible ;
56
55
57
56
fn read ( & mut self , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > {
You can’t perform that action at this time.
0 commit comments