99*/
1010
1111//use crate::dma::traits::PeriAddress;
12+ use crate :: stasis;
1213pub use crate :: time:: U32Ext as _;
1314use crate :: {
1415 dma:: { mux:: DmaMuxResources , traits:: TargetAddress , PeripheralToMemory } ,
@@ -51,12 +52,16 @@ impl Vref {
5152 Self :: sample_to_millivolts_ext ( sample, VDDA_CALIB , config:: Resolution :: Twelve )
5253 }
5354}
55+ impl stasis:: Freeze for Vref { }
5456
5557/// Vbat internal signal, used for monitoring the battery (if used)
5658pub struct Vbat ;
59+ impl stasis:: Freeze for Vbat { }
5760
5861/// Core temperature internal signal
5962pub struct Temperature ;
63+ impl stasis:: Freeze for Temperature { }
64+
6065impl Temperature {
6166 /// Precompute the inverse of `VTEMP_CAL_VREFANALOG`, in volts,
6267 /// for floating point calculations
@@ -131,39 +136,49 @@ impl Temperature {
131136 }
132137}
133138
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+
134167macro_rules! adc_pins {
135168 ( $( $pin: ty => ( $adc: ident, $chan: expr) ) ,+ $( , ) * ) => {
136169 $(
137- impl Channel <stm32:: $adc> for $pin {
138- type ID = u8 ;
139- fn channel( ) -> u8 { $chan }
140- }
170+ adc_channel_helper!( $adc, $chan, $pin, ) ;
141171 ) +
142172 } ;
143173}
144174
145175macro_rules! adc_opamp {
146176 ( $( $opamp: ty => ( $adc: ident, $chan: expr) ) ,+ $( , ) * ) => {
147177 $(
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 >, ) ;
167182 ) +
168183 } ;
169184}
@@ -1898,7 +1913,7 @@ macro_rules! adc {
18981913 /// to sample for at a given ADC clock frequency
18991914 pub fn configure_channel<CHANNEL >( & mut self , _channel: & CHANNEL , sequence: config:: Sequence , sample_time: config:: SampleTime )
19001915 where
1901- CHANNEL : Channel <stm32:: $adc_type, ID =u8 >
1916+ CHANNEL : Channel <Ad < stm32:: $adc_type> , ID =u8 >
19021917 {
19031918
19041919 //Check the sequence is long enough
@@ -1964,7 +1979,7 @@ macro_rules! adc {
19641979 /// Note that it reconfigures the adc sequence and doesn't restore it
19651980 pub fn convert<PIN >( & mut self , pin: & PIN , sample_time: config:: SampleTime ) -> u16
19661981 where
1967- PIN : Channel <stm32:: $adc_type, ID =u8 >
1982+ PIN : Channel <Ad < stm32:: $adc_type> , ID =u8 >
19681983 {
19691984 let saved_config = self . config;
19701985 unsafe {
@@ -2410,7 +2425,7 @@ macro_rules! adc {
24102425 #[ inline( always) ]
24112426 pub fn configure_channel<CHANNEL >( & mut self , channel: & CHANNEL , sequence: config:: Sequence , sample_time: config:: SampleTime )
24122427 where
2413- CHANNEL : Channel <stm32:: $adc_type, ID =u8 >
2428+ CHANNEL : Channel <Ad < stm32:: $adc_type> , ID =u8 >
24142429 {
24152430 self . adc. configure_channel( channel, sequence, sample_time)
24162431 }
@@ -2420,7 +2435,7 @@ macro_rules! adc {
24202435 #[ inline( always) ]
24212436 pub fn convert<PIN >( & mut self , pin: & PIN , sample_time: config:: SampleTime ) -> u16
24222437 where
2423- PIN : Channel <stm32:: $adc_type, ID =u8 >
2438+ PIN : Channel <Ad < stm32:: $adc_type> , ID =u8 >
24242439 {
24252440 self . adc. convert( pin, sample_time)
24262441 }
@@ -2463,7 +2478,7 @@ macro_rules! adc {
24632478 #[ inline( always) ]
24642479 pub fn convert<PIN >( & mut self , pin: & PIN , sample_time: config:: SampleTime ) -> u16
24652480 where
2466- PIN : Channel <stm32:: $adc_type, ID =u8 >
2481+ PIN : Channel <Ad < stm32:: $adc_type> , ID =u8 >
24672482 {
24682483 self . adc. reset_sequence( ) ;
24692484 self . adc. configure_channel( pin, config:: Sequence :: One , sample_time) ;
@@ -2604,9 +2619,9 @@ macro_rules! adc {
26042619 const REQUEST_LINE : Option <u8 > = Some ( $mux as u8 ) ;
26052620 }
26062621
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 >
26082623 where
2609- PIN : Channel <stm32:: $adc_type, ID =u8 >,
2624+ PIN : Channel <Ad < stm32:: $adc_type> , ID =u8 >,
26102625 {
26112626 type Error = ( ) ;
26122627
0 commit comments