@@ -6,21 +6,14 @@ use embedded_hal::adc::{Channel, OneShot};
66#[ cfg( all( feature = "stm32f103" , any( feature = "high" , feature = "xl" , ) , ) ) ]
77use crate :: dma:: dma2;
88use crate :: dma:: { dma1, CircBuffer , Receive , RxDma , Transfer , TransferPayload , W } ;
9- #[ cfg( all( feature = "stm32f103" , any( feature = "high" , feature = "xl" , ) , ) ) ]
10- use crate :: gpio:: gpiof;
11- use crate :: gpio:: Analog ;
12- use crate :: gpio:: { gpioa, gpiob, gpioc} ;
9+ use crate :: gpio:: { self , Analog } ;
1310use crate :: rcc:: { Clocks , Enable , Reset } ;
1411use crate :: time:: kHz;
1512use core:: sync:: atomic:: { self , Ordering } ;
1613use cortex_m:: asm:: delay;
1714use embedded_dma:: StaticWriteBuffer ;
1815
19- #[ cfg( any( feature = "stm32f103" , feature = "connectivity" ) ) ]
20- use crate :: pac:: ADC2 ;
21- #[ cfg( all( feature = "stm32f103" , any( feature = "high" , feature = "xl" ) ) ) ]
22- use crate :: pac:: ADC3 ;
23- use crate :: pac:: { ADC1 , RCC } ;
16+ use crate :: pac:: { self , RCC } ;
2417
2518/// Continuous mode
2619pub struct Continuous ;
@@ -108,7 +101,7 @@ impl From<Align> for bool {
108101}
109102
110103macro_rules! adc_pins {
111- ( $ADC: ident , $( $pin: ty => $chan: expr) ,+ $( , ) * ) => {
104+ ( $ADC: ty , $( $pin: ty => $chan: expr) ,+ $( , ) * ) => {
112105 $(
113106 impl Channel <$ADC> for $pin {
114107 type ID = u8 ;
@@ -119,60 +112,60 @@ macro_rules! adc_pins {
119112 } ;
120113}
121114
122- adc_pins ! ( ADC1 ,
123- gpioa :: PA0 <Analog > => 0_u8 ,
124- gpioa :: PA1 <Analog > => 1_u8 ,
125- gpioa :: PA2 <Analog > => 2_u8 ,
126- gpioa :: PA3 <Analog > => 3_u8 ,
127- gpioa :: PA4 <Analog > => 4_u8 ,
128- gpioa :: PA5 <Analog > => 5_u8 ,
129- gpioa :: PA6 <Analog > => 6_u8 ,
130- gpioa :: PA7 <Analog > => 7_u8 ,
131- gpiob :: PB0 <Analog > => 8_u8 ,
132- gpiob :: PB1 <Analog > => 9_u8 ,
133- gpioc :: PC0 <Analog > => 10_u8 ,
134- gpioc :: PC1 <Analog > => 11_u8 ,
135- gpioc :: PC2 <Analog > => 12_u8 ,
136- gpioc :: PC3 <Analog > => 13_u8 ,
137- gpioc :: PC4 <Analog > => 14_u8 ,
138- gpioc :: PC5 <Analog > => 15_u8 ,
115+ adc_pins ! ( pac :: ADC1 ,
116+ gpio :: PA0 <Analog > => 0_u8 ,
117+ gpio :: PA1 <Analog > => 1_u8 ,
118+ gpio :: PA2 <Analog > => 2_u8 ,
119+ gpio :: PA3 <Analog > => 3_u8 ,
120+ gpio :: PA4 <Analog > => 4_u8 ,
121+ gpio :: PA5 <Analog > => 5_u8 ,
122+ gpio :: PA6 <Analog > => 6_u8 ,
123+ gpio :: PA7 <Analog > => 7_u8 ,
124+ gpio :: PB0 <Analog > => 8_u8 ,
125+ gpio :: PB1 <Analog > => 9_u8 ,
126+ gpio :: PC0 <Analog > => 10_u8 ,
127+ gpio :: PC1 <Analog > => 11_u8 ,
128+ gpio :: PC2 <Analog > => 12_u8 ,
129+ gpio :: PC3 <Analog > => 13_u8 ,
130+ gpio :: PC4 <Analog > => 14_u8 ,
131+ gpio :: PC5 <Analog > => 15_u8 ,
139132) ;
140133
141134#[ cfg( any( feature = "stm32f103" , feature = "connectivity" ) ) ]
142- adc_pins ! ( ADC2 ,
143- gpioa :: PA0 <Analog > => 0_u8 ,
144- gpioa :: PA1 <Analog > => 1_u8 ,
145- gpioa :: PA2 <Analog > => 2_u8 ,
146- gpioa :: PA3 <Analog > => 3_u8 ,
147- gpioa :: PA4 <Analog > => 4_u8 ,
148- gpioa :: PA5 <Analog > => 5_u8 ,
149- gpioa :: PA6 <Analog > => 6_u8 ,
150- gpioa :: PA7 <Analog > => 7_u8 ,
151- gpiob :: PB0 <Analog > => 8_u8 ,
152- gpiob :: PB1 <Analog > => 9_u8 ,
153- gpioc :: PC0 <Analog > => 10_u8 ,
154- gpioc :: PC1 <Analog > => 11_u8 ,
155- gpioc :: PC2 <Analog > => 12_u8 ,
156- gpioc :: PC3 <Analog > => 13_u8 ,
157- gpioc :: PC4 <Analog > => 14_u8 ,
158- gpioc :: PC5 <Analog > => 15_u8 ,
135+ adc_pins ! ( pac :: ADC2 ,
136+ gpio :: PA0 <Analog > => 0_u8 ,
137+ gpio :: PA1 <Analog > => 1_u8 ,
138+ gpio :: PA2 <Analog > => 2_u8 ,
139+ gpio :: PA3 <Analog > => 3_u8 ,
140+ gpio :: PA4 <Analog > => 4_u8 ,
141+ gpio :: PA5 <Analog > => 5_u8 ,
142+ gpio :: PA6 <Analog > => 6_u8 ,
143+ gpio :: PA7 <Analog > => 7_u8 ,
144+ gpio :: PB0 <Analog > => 8_u8 ,
145+ gpio :: PB1 <Analog > => 9_u8 ,
146+ gpio :: PC0 <Analog > => 10_u8 ,
147+ gpio :: PC1 <Analog > => 11_u8 ,
148+ gpio :: PC2 <Analog > => 12_u8 ,
149+ gpio :: PC3 <Analog > => 13_u8 ,
150+ gpio :: PC4 <Analog > => 14_u8 ,
151+ gpio :: PC5 <Analog > => 15_u8 ,
159152) ;
160153
161154#[ cfg( all( feature = "stm32f103" , any( feature = "high" , feature = "xl" , ) , ) ) ]
162- adc_pins ! ( ADC3 ,
163- gpioa :: PA0 <Analog > => 0_u8 ,
164- gpioa :: PA1 <Analog > => 1_u8 ,
165- gpioa :: PA2 <Analog > => 2_u8 ,
166- gpioa :: PA3 <Analog > => 3_u8 ,
167- gpiof :: PF6 <Analog > => 4_u8 ,
168- gpiof :: PF7 <Analog > => 5_u8 ,
169- gpiof :: PF8 <Analog > => 6_u8 ,
170- gpiof :: PF9 <Analog > => 7_u8 ,
171- gpiof :: PF10 <Analog > => 8_u8 ,
172- gpioc :: PC0 <Analog > => 10_u8 ,
173- gpioc :: PC1 <Analog > => 11_u8 ,
174- gpioc :: PC2 <Analog > => 12_u8 ,
175- gpioc :: PC3 <Analog > => 13_u8 ,
155+ adc_pins ! ( pac :: ADC3 ,
156+ gpio :: PA0 <Analog > => 0_u8 ,
157+ gpio :: PA1 <Analog > => 1_u8 ,
158+ gpio :: PA2 <Analog > => 2_u8 ,
159+ gpio :: PA3 <Analog > => 3_u8 ,
160+ gpio :: PF6 <Analog > => 4_u8 ,
161+ gpio :: PF7 <Analog > => 5_u8 ,
162+ gpio :: PF8 <Analog > => 6_u8 ,
163+ gpio :: PF9 <Analog > => 7_u8 ,
164+ gpio :: PF10 <Analog > => 8_u8 ,
165+ gpio :: PC0 <Analog > => 10_u8 ,
166+ gpio :: PC1 <Analog > => 11_u8 ,
167+ gpio :: PC2 <Analog > => 12_u8 ,
168+ gpio :: PC3 <Analog > => 13_u8 ,
176169) ;
177170
178171/// Stored ADC config can be restored using the `Adc::restore_cfg` method
@@ -181,7 +174,7 @@ pub struct StoredConfig(SampleTime, Align);
181174
182175macro_rules! adc_hal {
183176 ( $(
184- $ADC: ident : ( $adc: ident) ,
177+ $ADC: ty : ( $adc: ident) ,
185178 ) +) => {
186179 $(
187180
@@ -279,17 +272,17 @@ macro_rules! adc_hal {
279272
280273 fn reset( & mut self ) {
281274 let rcc = unsafe { & ( * RCC :: ptr( ) ) } ;
282- $ADC:: reset( rcc) ;
275+ < $ADC> :: reset( rcc) ;
283276 }
284277
285278 fn enable_clock( & mut self ) {
286279 let rcc = unsafe { & ( * RCC :: ptr( ) ) } ;
287- $ADC:: enable( rcc) ;
280+ < $ADC> :: enable( rcc) ;
288281 }
289282
290283 fn disable_clock( & mut self ) {
291284 let rcc = unsafe { & ( * RCC :: ptr( ) ) } ;
292- $ADC:: disable( rcc) ;
285+ < $ADC> :: disable( rcc) ;
293286 }
294287
295288 fn calibrate( & mut self ) {
@@ -461,7 +454,7 @@ macro_rules! adc_hal {
461454 }
462455}
463456
464- impl Adc < ADC1 > {
457+ impl Adc < pac :: ADC1 > {
465458 fn read_aux ( & mut self , chan : u8 ) -> u16 {
466459 let tsv_off = if self . rb . cr2 . read ( ) . tsvrefe ( ) . bit_is_clear ( ) {
467460 self . rb . cr2 . modify ( |_, w| w. tsvrefe ( ) . set_bit ( ) ) ;
@@ -545,17 +538,17 @@ impl Adc<ADC1> {
545538}
546539
547540adc_hal ! {
548- ADC1 : ( adc1) ,
541+ pac :: ADC1 : ( adc1) ,
549542}
550543
551544#[ cfg( any( feature = "stm32f103" , feature = "connectivity" ) ) ]
552545adc_hal ! {
553- ADC2 : ( adc2) ,
546+ pac :: ADC2 : ( adc2) ,
554547}
555548
556549#[ cfg( all( feature = "stm32f103" , any( feature = "high" , feature = "xl" , ) , ) ) ]
557550adc_hal ! {
558- ADC3 : ( adc3) ,
551+ pac :: ADC3 : ( adc3) ,
559552}
560553
561554pub struct AdcPayload < ADC , PINS , MODE > {
@@ -608,7 +601,7 @@ pub trait SetChannels<PINS>: ChannelTimeSequence {
608601pub type AdcDma < ADC , PINS , MODE , CHANNEL > = RxDma < AdcPayload < ADC , PINS , MODE > , CHANNEL > ;
609602
610603macro_rules! adcdma {
611- ( $ADCX: ident : (
604+ ( $ADCX: ty : (
612605 $rxdma: ident,
613606 $dmarxch: ty,
614607 ) ) => {
@@ -750,7 +743,7 @@ macro_rules! adcdma {
750743 // until the end of the transfer.
751744 let ( ptr, len) = unsafe { buffer. static_write_buffer( ) } ;
752745 self . channel. set_peripheral_address(
753- unsafe { & ( * $ADCX:: ptr( ) ) . dr as * const _ as u32 } ,
746+ unsafe { & ( * < $ADCX> :: ptr( ) ) . dr as * const _ as u32 } ,
754747 false ,
755748 ) ;
756749 self . channel. set_memory_address( ptr as u32 , true ) ;
@@ -789,7 +782,7 @@ macro_rules! adcdma {
789782 // until the end of the transfer.
790783 let ( ptr, len) = unsafe { buffer. static_write_buffer( ) } ;
791784 self . channel. set_peripheral_address(
792- unsafe { & ( * $ADCX:: ptr( ) ) . dr as * const _ as u32 } ,
785+ unsafe { & ( * < $ADCX> :: ptr( ) ) . dr as * const _ as u32 } ,
793786 false ,
794787 ) ;
795788 self . channel. set_memory_address( ptr as u32 , true ) ;
@@ -819,15 +812,15 @@ macro_rules! adcdma {
819812}
820813
821814adcdma ! {
822- ADC1 : (
815+ pac :: ADC1 : (
823816 AdcDma1 ,
824817 dma1:: C1 ,
825818 )
826819}
827820
828821#[ cfg( all( feature = "stm32f103" , any( feature = "high" , feature = "xl" , ) , ) ) ]
829822adcdma ! {
830- ADC3 : (
823+ pac :: ADC3 : (
831824 AdcDma3 ,
832825 dma2:: C5 ,
833826 )
0 commit comments