-
Notifications
You must be signed in to change notification settings - Fork 0
/
peripherals.rs
54 lines (49 loc) · 1.38 KB
/
peripherals.rs
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
use esp_idf_hal::{
adc::ADC1,
gpio::{AnyIOPin, AnyInputPin, AnyOutputPin, Gpio2},
i2c::I2C0,
modem::Modem,
prelude::Peripherals,
};
pub struct SystemPeripherals<I2C, ADC, GP> {
pub i2c: I2cPeripherals<I2C>,
pub rot: RotaryPeripherals,
pub temperature: ThermometerPeripherals<ADC, GP>,
pub modem: Modem,
}
impl SystemPeripherals<I2C0, ADC1, Gpio2> {
pub fn take() -> Self {
let peripherals = Peripherals::take().unwrap();
SystemPeripherals {
i2c: I2cPeripherals {
i2c: peripherals.i2c0,
sda: peripherals.pins.gpio5.into(),
scl: peripherals.pins.gpio6.into(),
},
rot: RotaryPeripherals {
pin_a: peripherals.pins.gpio10.into(),
pin_b: peripherals.pins.gpio11.into(),
},
temperature: ThermometerPeripherals {
adc: peripherals.adc1,
voltage: peripherals.pins.gpio2,
vcc: peripherals.pins.gpio7.into(),
},
modem: peripherals.modem,
}
}
}
pub struct I2cPeripherals<I2C> {
pub i2c: I2C,
pub sda: AnyIOPin,
pub scl: AnyIOPin,
}
pub struct RotaryPeripherals {
pub pin_a: AnyInputPin,
pub pin_b: AnyInputPin,
}
pub struct ThermometerPeripherals<ADC, GP> {
pub adc: ADC,
pub voltage: GP,
pub vcc: AnyOutputPin,
}