thermostat/src/channel.rs

40 lines
996 B
Rust
Raw Normal View History

2020-05-13 05:16:57 +08:00
use crate::pins::{ChannelPins, ChannelPinSet};
use crate::channel_state::ChannelState;
use crate::ad5680;
/// Marker type for the first channel
pub struct Channel0;
/// Marker type for the second channel
pub struct Channel1;
pub struct Channel<C: ChannelPins> {
pub state: ChannelState,
2020-05-17 01:36:00 +08:00
/// for `i_set`
2020-05-13 05:16:57 +08:00
pub dac: ad5680::Dac<C::DacSpi, C::DacSync>,
pub shdn: C::Shdn,
2020-05-17 05:59:31 +08:00
/// stm32f4 integrated adc
pub adc: C::Adc,
pub itec_pin: C::ItecPin,
2020-05-17 01:36:00 +08:00
/// feedback from `dac` output
pub dac_loopback_pin: C::DacLoopbackPin,
2020-05-13 05:16:57 +08:00
}
impl<C: ChannelPins> Channel<C> {
pub fn new(pins: ChannelPinSet<C>) -> Self {
let state = ChannelState::default();
let mut dac = ad5680::Dac::new(pins.dac_spi, pins.dac_sync);
let _ = dac.set(0);
Channel {
state,
dac,
shdn: pins.shdn,
2020-05-17 05:59:31 +08:00
adc: pins.adc,
itec_pin: pins.itec_pin,
2020-05-17 01:36:00 +08:00
dac_loopback_pin: pins.dac_loopback_pin,
2020-05-13 05:16:57 +08:00
}
}
}