@@ -22,6 +22,14 @@ use crate::{
22
22
use pac:: { ADC1 , ADC_COMMON } ;
23
23
use stable_deref_trait:: StableDeref ;
24
24
25
+ #[ cfg( any(
26
+ feature = "stm32l471" ,
27
+ feature = "stm32l475" ,
28
+ feature = "stm32l476" ,
29
+ feature = "stm32l486"
30
+ ) ) ]
31
+ use crate :: gpio:: AnalogPin ;
32
+
25
33
/// Vref internal signal, used for calibration
26
34
pub struct Vref ;
27
35
@@ -31,6 +39,42 @@ pub struct Vbat;
31
39
/// Core temperature internal signal
32
40
pub struct Temperature ;
33
41
42
+ // TODO: Avoid this hack
43
+ #[ cfg( any(
44
+ feature = "stm32l471" ,
45
+ feature = "stm32l475" ,
46
+ feature = "stm32l476" ,
47
+ feature = "stm32l486"
48
+ ) ) ]
49
+ impl AnalogPin for Vref {
50
+ fn connect_adc ( & mut self ) { }
51
+ fn disconnect_adc ( & mut self ) { }
52
+ }
53
+
54
+ // TODO: Avoid this hack
55
+ #[ cfg( any(
56
+ feature = "stm32l471" ,
57
+ feature = "stm32l475" ,
58
+ feature = "stm32l476" ,
59
+ feature = "stm32l486"
60
+ ) ) ]
61
+ impl AnalogPin for Vbat {
62
+ fn connect_adc ( & mut self ) { }
63
+ fn disconnect_adc ( & mut self ) { }
64
+ }
65
+
66
+ // TODO: Avoid this hack
67
+ #[ cfg( any(
68
+ feature = "stm32l471" ,
69
+ feature = "stm32l475" ,
70
+ feature = "stm32l476" ,
71
+ feature = "stm32l486"
72
+ ) ) ]
73
+ impl AnalogPin for Temperature {
74
+ fn connect_adc ( & mut self ) { }
75
+ fn disconnect_adc ( & mut self ) { }
76
+ }
77
+
34
78
/// Analog to Digital converter interface
35
79
pub struct ADC {
36
80
pub ( crate ) adc : ADC1 ,
@@ -447,6 +491,15 @@ where
447
491
self . start_conversion ( ) ;
448
492
while !self . has_completed_sequence ( ) { }
449
493
494
+ #[ cfg( any(
495
+ feature = "stm32l471" ,
496
+ feature = "stm32l475" ,
497
+ feature = "stm32l476" ,
498
+ feature = "stm32l486"
499
+ ) ) ]
500
+ // Connect the pin to the ADC
501
+ channel. connect_adc ( ) ;
502
+
450
503
// Read ADC value first time and discard it, as per errata sheet.
451
504
// The errata states that if we do conversions slower than 1 kHz, the
452
505
// first read ADC value can be corrupted, so we discard it and measure again.
@@ -458,6 +511,15 @@ where
458
511
// Read ADC value
459
512
let val = self . get_data ( ) ;
460
513
514
+ #[ cfg( any(
515
+ feature = "stm32l471" ,
516
+ feature = "stm32l475" ,
517
+ feature = "stm32l476" ,
518
+ feature = "stm32l486"
519
+ ) ) ]
520
+ // Disconnect the pin from the ADC
521
+ channel. disconnect_adc ( ) ;
522
+
461
523
// Disable ADC
462
524
self . disable ( ) ;
463
525
@@ -638,11 +700,28 @@ impl Default for SampleTime {
638
700
}
639
701
}
640
702
703
+ #[ cfg( not( any(
704
+ feature = "stm32l471" ,
705
+ feature = "stm32l475" ,
706
+ feature = "stm32l476" ,
707
+ feature = "stm32l486"
708
+ ) ) ) ]
641
709
/// Implemented for all types that represent ADC channels
642
710
pub trait Channel : EmbeddedHalChannel < ADC , ID = u8 > {
643
711
fn set_sample_time ( & mut self , adc : & ADC1 , sample_time : SampleTime ) ;
644
712
}
645
713
714
+ #[ cfg( any(
715
+ feature = "stm32l471" ,
716
+ feature = "stm32l475" ,
717
+ feature = "stm32l476" ,
718
+ feature = "stm32l486"
719
+ ) ) ]
720
+ /// Implemented for all types that represent ADC channels
721
+ pub trait Channel : EmbeddedHalChannel < ADC , ID = u8 > + AnalogPin {
722
+ fn set_sample_time ( & mut self , adc : & ADC1 , sample_time : SampleTime ) ;
723
+ }
724
+
646
725
macro_rules! adc_pins {
647
726
(
648
727
$(
0 commit comments