@@ -62,14 +62,15 @@ pub enum SampleTime {
62
62
}
63
63
64
64
/// Analog to Digital converter interface
65
- pub struct Adc {
65
+ pub struct Adc < State > {
66
66
rb : ADC ,
67
67
sample_time : SampleTime ,
68
68
align : Align ,
69
69
precision : Precision ,
70
+ _state : State ,
70
71
}
71
72
72
- impl Adc {
73
+ impl Adc < Ready > {
73
74
pub fn new ( adc : ADC , rcc : & mut Rcc ) -> Self {
74
75
// Enable ADC clocks
75
76
rcc. rb . apb2enr . modify ( |_, w| w. adcen ( ) . set_bit ( ) ) ;
@@ -80,6 +81,7 @@ impl Adc {
80
81
sample_time : SampleTime :: T_1_5 ,
81
82
align : Align :: Right ,
82
83
precision : Precision :: B_12 ,
84
+ _state : Ready ,
83
85
}
84
86
}
85
87
@@ -122,19 +124,19 @@ impl Adc {
122
124
}
123
125
124
126
pub trait AdcExt {
125
- fn constrain ( self , rcc : & mut Rcc ) -> Adc ;
127
+ fn constrain ( self , rcc : & mut Rcc ) -> Adc < Ready > ;
126
128
}
127
129
128
130
impl AdcExt for ADC {
129
- fn constrain ( self , rcc : & mut Rcc ) -> Adc {
131
+ fn constrain ( self , rcc : & mut Rcc ) -> Adc < Ready > {
130
132
Adc :: new ( self , rcc)
131
133
}
132
134
}
133
135
134
- impl < WORD , PIN > OneShot < Adc , WORD , PIN > for Adc
136
+ impl < WORD , PIN > OneShot < Adc < Ready > , WORD , PIN > for Adc < Ready >
135
137
where
136
138
WORD : From < u16 > ,
137
- PIN : Channel < Adc , ID = u8 > ,
139
+ PIN : Channel < Adc < Ready > , ID = u8 > ,
138
140
{
139
141
type Error = ( ) ;
140
142
@@ -173,6 +175,11 @@ where
173
175
}
174
176
}
175
177
178
+
179
+ /// Indicates that the ADC peripheral is ready
180
+ pub struct Ready ;
181
+
182
+
176
183
macro_rules! int_adc {
177
184
( $( $Chan: ident: ( $chan: expr, $en: ident) ) ,+ $( , ) * ) => {
178
185
$(
@@ -183,16 +190,16 @@ macro_rules! int_adc {
183
190
Self { }
184
191
}
185
192
186
- pub fn enable( & mut self , adc: & mut Adc ) {
193
+ pub fn enable( & mut self , adc: & mut Adc < Ready > ) {
187
194
adc. rb. ccr. modify( |_, w| w. $en( ) . set_bit( ) ) ;
188
195
}
189
196
190
- pub fn disable( & mut self , adc: & mut Adc ) {
197
+ pub fn disable( & mut self , adc: & mut Adc < Ready > ) {
191
198
adc. rb. ccr. modify( |_, w| w. $en( ) . clear_bit( ) ) ;
192
199
}
193
200
}
194
201
195
- impl Channel <Adc > for $Chan {
202
+ impl Channel <Adc < Ready > > for $Chan {
196
203
type ID = u8 ;
197
204
198
205
fn channel( ) -> u8 {
@@ -206,7 +213,7 @@ macro_rules! int_adc {
206
213
macro_rules! adc_pins {
207
214
( $( $Chan: ty: ( $pin: ty, $chan: expr) ) ,+ $( , ) * ) => {
208
215
$(
209
- impl Channel <Adc > for $pin {
216
+ impl Channel <Adc < Ready > > for $pin {
210
217
type ID = u8 ;
211
218
212
219
fn channel( ) -> u8 { $chan }
0 commit comments