1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::analog::{ADC1, ADC2};
use embedded_hal::adc::Channel;
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum Resolution {
Resolution9Bit = 0b00,
Resolution10Bit = 0b01,
Resolution11Bit = 0b10,
Resolution12Bit = 0b11,
}
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum Attenuation {
Attenuation0dB = 0b00,
Attenuation2p5dB = 0b01,
Attenuation6dB = 0b10,
Attenuation11dB = 0b11,
}
pub struct Adc1Config {
pub resolution: Resolution,
pub hall_sensor: bool,
pub attenuations: [Option<Attenuation>; 10],
}
impl Adc1Config {
pub fn new() -> Adc1Config {
Adc1Config {
resolution: Resolution::Resolution12Bit,
hall_sensor: false,
attenuations: [None; 10],
}
}
pub fn enable_pin<PIN: Channel<ADC1, ID = u8>>(
&mut self,
_pin: &PIN,
attenuation: Attenuation,
) {
self.attenuations[PIN::channel() as usize] = Some(attenuation);
}
pub fn enable_hall_sensor(&mut self) {
self.hall_sensor = true;
}
}
pub struct Adc2Config {
pub resolution: Resolution,
pub attenuations: [Option<Attenuation>; 10],
}
impl Adc2Config {
pub fn new() -> Adc2Config {
Adc2Config {
resolution: Resolution::Resolution12Bit,
attenuations: [None; 10],
}
}
pub fn enable_pin<PIN: Channel<ADC2, ID = u8>>(
&mut self,
_pin: &PIN,
attenuation: Attenuation,
) {
self.attenuations[PIN::channel() as usize] = Some(attenuation);
}
}