9
9
*/
10
10
11
11
//use crate::dma::traits::PeriAddress;
12
+ use crate :: stasis;
12
13
pub use crate :: time:: U32Ext as _;
13
14
use crate :: {
14
15
dma:: { mux:: DmaMuxResources , traits:: TargetAddress , PeripheralToMemory } ,
@@ -51,12 +52,16 @@ impl Vref {
51
52
Self :: sample_to_millivolts_ext ( sample, VDDA_CALIB , config:: Resolution :: Twelve )
52
53
}
53
54
}
55
+ impl stasis:: Freeze for Vref { }
54
56
55
57
/// Vbat internal signal, used for monitoring the battery (if used)
56
58
pub struct Vbat ;
59
+ impl stasis:: Freeze for Vbat { }
57
60
58
61
/// Core temperature internal signal
59
62
pub struct Temperature ;
63
+ impl stasis:: Freeze for Temperature { }
64
+
60
65
impl Temperature {
61
66
/// Precompute the inverse of `VTEMP_CAL_VREFANALOG`, in volts,
62
67
/// for floating point calculations
@@ -131,39 +136,49 @@ impl Temperature {
131
136
}
132
137
}
133
138
139
+ // TODO: Is there any way to avoid this wrapper to overcome the orphan rule
140
+ /// Wrapper to side step orphan rule
141
+ pub struct Ad < T > ( T ) ;
142
+ macro_rules! adc_channel_helper {
143
+ ( $adc: ident, $chan: expr, $r: ty, $( $a: ident) ,* ) => {
144
+ impl <$( $a, ) * > Channel <Ad <stm32:: $adc>> for stasis:: Entitlement <$r> {
145
+ type ID = u8 ;
146
+ fn channel( ) -> u8 {
147
+ $chan
148
+ }
149
+ }
150
+
151
+ impl <const N : usize , $( $a, ) * > Channel <Ad <stm32:: $adc>> for stasis:: Frozen <$r, N > {
152
+ type ID = u8 ;
153
+ fn channel( ) -> u8 {
154
+ $chan
155
+ }
156
+ }
157
+
158
+ impl <$( $a, ) * > Channel <Ad <stm32:: $adc>> for $r {
159
+ type ID = u8 ;
160
+ fn channel( ) -> u8 {
161
+ $chan
162
+ }
163
+ }
164
+ } ;
165
+ }
166
+
134
167
macro_rules! adc_pins {
135
168
( $( $pin: ty => ( $adc: ident, $chan: expr) ) ,+ $( , ) * ) => {
136
169
$(
137
- impl Channel <stm32:: $adc> for $pin {
138
- type ID = u8 ;
139
- fn channel( ) -> u8 { $chan }
140
- }
170
+ adc_channel_helper!( $adc, $chan, $pin, ) ;
141
171
) +
142
172
} ;
143
173
}
144
174
145
175
macro_rules! adc_opamp {
146
176
( $( $opamp: ty => ( $adc: ident, $chan: expr) ) ,+ $( , ) * ) => {
147
177
$(
148
- impl <A > Channel <stm32:: $adc> for opamp:: Follower <$opamp, A , InternalOutput > {
149
- type ID = u8 ;
150
- fn channel( ) -> u8 { $chan }
151
- }
152
-
153
- impl <A , B > Channel <stm32:: $adc> for opamp:: OpenLoop <$opamp, A , B , InternalOutput > {
154
- type ID = u8 ;
155
- fn channel( ) -> u8 { $chan }
156
- }
157
-
158
- impl <A > Channel <stm32:: $adc> for opamp:: Pga <$opamp, A , InternalOutput > {
159
- type ID = u8 ;
160
- fn channel( ) -> u8 { $chan }
161
- }
162
-
163
- impl Channel <stm32:: $adc> for opamp:: Locked <$opamp, InternalOutput > {
164
- type ID = u8 ;
165
- fn channel( ) -> u8 { $chan }
166
- }
178
+ adc_channel_helper!( $adc, $chan, opamp:: Follower <$opamp, A , InternalOutput >, A ) ;
179
+ adc_channel_helper!( $adc, $chan, opamp:: OpenLoop <$opamp, A , B , InternalOutput >, A , B ) ;
180
+ adc_channel_helper!( $adc, $chan, opamp:: Pga <$opamp, A , InternalOutput >, A ) ;
181
+ adc_channel_helper!( $adc, $chan, opamp:: Locked <$opamp, InternalOutput >, ) ;
167
182
) +
168
183
} ;
169
184
}
@@ -1898,7 +1913,7 @@ macro_rules! adc {
1898
1913
/// to sample for at a given ADC clock frequency
1899
1914
pub fn configure_channel<CHANNEL >( & mut self , _channel: & CHANNEL , sequence: config:: Sequence , sample_time: config:: SampleTime )
1900
1915
where
1901
- CHANNEL : Channel <stm32:: $adc_type, ID =u8 >
1916
+ CHANNEL : Channel <Ad < stm32:: $adc_type> , ID =u8 >
1902
1917
{
1903
1918
1904
1919
//Check the sequence is long enough
@@ -1964,7 +1979,7 @@ macro_rules! adc {
1964
1979
/// Note that it reconfigures the adc sequence and doesn't restore it
1965
1980
pub fn convert<PIN >( & mut self , pin: & PIN , sample_time: config:: SampleTime ) -> u16
1966
1981
where
1967
- PIN : Channel <stm32:: $adc_type, ID =u8 >
1982
+ PIN : Channel <Ad < stm32:: $adc_type> , ID =u8 >
1968
1983
{
1969
1984
let saved_config = self . config;
1970
1985
unsafe {
@@ -2410,7 +2425,7 @@ macro_rules! adc {
2410
2425
#[ inline( always) ]
2411
2426
pub fn configure_channel<CHANNEL >( & mut self , channel: & CHANNEL , sequence: config:: Sequence , sample_time: config:: SampleTime )
2412
2427
where
2413
- CHANNEL : Channel <stm32:: $adc_type, ID =u8 >
2428
+ CHANNEL : Channel <Ad < stm32:: $adc_type> , ID =u8 >
2414
2429
{
2415
2430
self . adc. configure_channel( channel, sequence, sample_time)
2416
2431
}
@@ -2420,7 +2435,7 @@ macro_rules! adc {
2420
2435
#[ inline( always) ]
2421
2436
pub fn convert<PIN >( & mut self , pin: & PIN , sample_time: config:: SampleTime ) -> u16
2422
2437
where
2423
- PIN : Channel <stm32:: $adc_type, ID =u8 >
2438
+ PIN : Channel <Ad < stm32:: $adc_type> , ID =u8 >
2424
2439
{
2425
2440
self . adc. convert( pin, sample_time)
2426
2441
}
@@ -2463,7 +2478,7 @@ macro_rules! adc {
2463
2478
#[ inline( always) ]
2464
2479
pub fn convert<PIN >( & mut self , pin: & PIN , sample_time: config:: SampleTime ) -> u16
2465
2480
where
2466
- PIN : Channel <stm32:: $adc_type, ID =u8 >
2481
+ PIN : Channel <Ad < stm32:: $adc_type> , ID =u8 >
2467
2482
{
2468
2483
self . adc. reset_sequence( ) ;
2469
2484
self . adc. configure_channel( pin, config:: Sequence :: One , sample_time) ;
@@ -2604,9 +2619,9 @@ macro_rules! adc {
2604
2619
const REQUEST_LINE : Option <u8 > = Some ( $mux as u8 ) ;
2605
2620
}
2606
2621
2607
- impl <PIN > OneShot <stm32:: $adc_type, u16 , PIN > for Adc <stm32:: $adc_type, Disabled >
2622
+ impl <PIN > OneShot <Ad < stm32:: $adc_type> , u16 , PIN > for Adc <stm32:: $adc_type, Disabled >
2608
2623
where
2609
- PIN : Channel <stm32:: $adc_type, ID =u8 >,
2624
+ PIN : Channel <Ad < stm32:: $adc_type> , ID =u8 >,
2610
2625
{
2611
2626
type Error = ( ) ;
2612
2627
0 commit comments