@@ -42,14 +42,14 @@ cfg_if! {
4242const MAX_ADVREGEN_STARTUP_US : u32 = 10 ;
4343
4444#[ derive( Clone , Copy , PartialEq ) ]
45- pub enum AdcDevice {
46- One ,
47- Two ,
48- Three ,
49- #[ cfg( feature = "g4" ) ] // todo: Check the specifics.
50- Four ,
45+ enum AdcDevice {
46+ ADC1 ,
47+ ADC2 ,
48+ ADC3 ,
49+ #[ cfg( any ( feature = "g4" , feature = "f303" ) ) ] // todo: Check the specifics.
50+ ADC4 ,
5151 #[ cfg( feature = "g4" ) ]
52- Five ,
52+ ADC5 ,
5353}
5454
5555cfg_if ! {
@@ -101,6 +101,28 @@ cfg_if! {
101101 Tim8Trgo = 0b1110 ,
102102 Exti11 = 0b1111 ,
103103 }
104+ } else if #[ cfg( any( feature = "l4x5" , feature="l4x6" ) ) ] {
105+ /// Select a trigger. Sets CFGR reg, EXTSEL field. See L4 RM, table 108: External triggers for regular channels
106+ #[ derive( Clone , Copy ) ]
107+ #[ repr( u8 ) ]
108+ pub enum Trigger {
109+ Tim1Cc1 = 0b0000 ,
110+ Tim1Cc2 = 0b0001 ,
111+ Tim1Cc3 = 0b0010 ,
112+ Tim2Cc2 = 0b0011 ,
113+ Tim3Trgo = 0b0100 ,
114+ Tim4Cc4 = 0b0101 ,
115+ Exti11 = 0b0110 ,
116+ Tim8Trgo = 0b0111 ,
117+ Tim8Trgo2 = 0b1000 ,
118+ Tim1Trgo = 0b1001 ,
119+ Tim1Trgo2 = 0b1010 ,
120+ Tim2Trgo = 0b1011 ,
121+ Tim4Trgo = 0b1100 ,
122+ Tim6Trgo = 0b1101 ,
123+ Tim15Trgo = 0b1110 ,
124+ Tim3Cc4 = 0b1111 ,
125+ }
104126 } else {
105127 pub enum Trigger { }
106128 }
@@ -372,7 +394,6 @@ pub struct Adc<R> {
372394 pub regs : R ,
373395 // Note: We don't own the common regs; pass them mutably where required, since they may be used
374396 // by a different ADC.
375- device : AdcDevice ,
376397 pub cfg : AdcConfig ,
377398 /// This field is managed internally, and is set up on init.
378399 pub vdda_calibrated : f32 ,
@@ -392,13 +413,11 @@ macro_rules! hal {
392413 /// it's VDDA value (`vdda_calibrated` field), and update the ADC in question with it.
393414 pub fn [ <new_ $adc>] (
394415 regs: pac:: $ADC,
395- device: AdcDevice ,
396416 cfg: AdcConfig ,
397417 ahb_freq: u32 , // Used for blocking delays in init.
398418 ) -> Result <Self > {
399419 let mut adc = Self {
400420 regs,
401- device,
402421 cfg,
403422 vdda_calibrated: 0.
404423 } ;
@@ -416,17 +435,19 @@ macro_rules! hal {
416435 } else if #[ cfg( feature = "f4" ) ] {
417436 rcc_en_reset!( 2 , [ <adc $rcc_num>] , rcc) ;
418437 } else if #[ cfg( feature = "h7" ) ] {
419- match device {
420- AdcDevice :: One | AdcDevice :: Two => {
438+ match AdcDevice :: $ADC {
439+ AdcDevice :: ADC1 | AdcDevice :: ADC2 => {
421440 rcc. ahb1enr( ) . modify( |_, w| w. adc12en( ) . bit( true ) ) ;
422441 }
423- AdcDevice :: Three => {
442+ AdcDevice :: ADC3 => {
424443 rcc. ahb4enr( ) . modify( |_, w| w. adc3en( ) . bit( true ) ) ;
425444 }
426445 }
427446 } else if #[ cfg( any( feature = "g4" ) ) ] {
428447 rcc. ahb2enr( ) . modify( |_, w| w. adc12en( ) . bit( true ) ) ;
429448 // rcc_en_reset!(ahb2, [<adc $rcc_num>], rcc);
449+ } else if #[ cfg( any( feature = "l4x5" , feature="l4x6" ) ) ] {
450+ rcc. ahb2enr( ) . modify( |_, w| w. adcen( ) . bit( true ) ) ;
430451 } else { // ie L4, L5, G0(?)
431452 rcc_en_reset!( ahb2, adc, rcc) ;
432453 }
@@ -922,7 +943,7 @@ macro_rules! hal {
922943 // todo: On H7, you may need to use ADC3 for this...
923944
924945 // Regardless of which ADC we're on, we take this reading using ADC1.
925- self . vdda_calibrated = if self . device != AdcDevice :: One {
946+ self . vdda_calibrated = if AdcDevice :: $ADC != AdcDevice :: ADC1 {
926947 // todo: What if ADC1 is already enabled and configured differently?
927948 // todo: Either way, if you're also using ADC1, this will screw things up⋅.
928949
@@ -1155,9 +1176,9 @@ macro_rules! hal {
11551176 // L44 RM, Table 41. "DMA1 requests for each channel
11561177 // todo: DMA2 support.
11571178 #[ cfg( any( feature = "f3" , feature = "l4" ) ) ]
1158- let dma_channel = match self . device {
1159- AdcDevice :: One => DmaInput :: Adc1 . dma1_channel( ) ,
1160- AdcDevice :: Two => DmaInput :: Adc2 . dma1_channel( ) ,
1179+ let dma_channel = match AdcDevice :: $ADC {
1180+ AdcDevice :: ADC1 => DmaInput :: Adc1 . dma1_channel( ) ,
1181+ AdcDevice :: ADC2 => DmaInput :: Adc2 . dma1_channel( ) ,
11611182 _ => panic!( "DMA on ADC beyond 2 is not supported. If it is for your MCU, please submit an issue \
11621183 or PR on Github.")
11631184 } ;
@@ -1166,17 +1187,17 @@ macro_rules! hal {
11661187 match dma_periph {
11671188 dma:: DmaPeriph :: Dma1 => {
11681189 let mut regs = unsafe { & ( * pac:: DMA1 :: ptr( ) ) } ;
1169- match self . device {
1170- AdcDevice :: One => dma:: channel_select( & mut regs, DmaInput :: Adc1 ) ,
1171- AdcDevice :: Two => dma:: channel_select( & mut regs, DmaInput :: Adc2 ) ,
1190+ match AdcDevice :: $ADC {
1191+ AdcDevice :: ADC1 => dma:: channel_select( & mut regs, DmaInput :: Adc1 ) ,
1192+ AdcDevice :: ADC2 => dma:: channel_select( & mut regs, DmaInput :: Adc2 ) ,
11721193 _ => unimplemented!( ) ,
11731194 }
11741195 }
11751196 dma:: DmaPeriph :: Dma2 => {
11761197 let mut regs = unsafe { & ( * pac:: DMA2 :: ptr( ) ) } ;
1177- match self . device {
1178- AdcDevice :: One => dma:: channel_select( & mut regs, DmaInput :: Adc1 ) ,
1179- AdcDevice :: Two => dma:: channel_select( & mut regs, DmaInput :: Adc2 ) ,
1198+ match AdcDevice :: $ADC {
1199+ AdcDevice :: ADC1 => dma:: channel_select( & mut regs, DmaInput :: Adc1 ) ,
1200+ AdcDevice :: ADC2 => dma:: channel_select( & mut regs, DmaInput :: Adc2 ) ,
11801201 _ => unimplemented!( ) ,
11811202 }
11821203 }
0 commit comments