diff --git a/firmware/src/tec.rs b/firmware/src/tec.rs index 1d58103..643bffe 100644 --- a/firmware/src/tec.rs +++ b/firmware/src/tec.rs @@ -35,44 +35,47 @@ impl fmt::Display for TecPin { } } -fn enable_shdn(gpio: G) +fn setup_shdn(gpio: G) -> GpioOutput where G: Gpio, GpioOutput: OutputPin, { let mut pin = gpio.into_output(); - let _ = pin.set_high(); + // keep off until first use + let _ = pin.set_low(); + pin } /// Thermo-Electric Cooling device controlled through four PWM /// channels -pub struct Tec { +pub struct Tec { max_i_pos: MaxIPos, max_i_neg: MaxINeg, i_set: ISet, max_v: MaxV, + shdn: SHDN, } -impl Tec { +impl Tec> { pub fn tec0() -> Self { let (max_i_pos, max_i_neg) = tm4c129x::TIMER2::split(); let (i_set, max_v) = tm4c129x::TIMER3::split(); - enable_shdn(PP4); - Tec { max_i_pos, max_i_neg, i_set, max_v } + let shdn = setup_shdn(PP4); + Tec { max_i_pos, max_i_neg, i_set, max_v, shdn } } } -impl Tec { +impl Tec> { pub fn tec1() -> Self { let (max_i_pos, max_i_neg) = tm4c129x::TIMER4::split(); let (i_set, max_v) = tm4c129x::TIMER5::split(); - enable_shdn(PP5); - Tec { max_i_pos, max_i_neg, i_set, max_v } + let shdn = setup_shdn(PP5); + Tec { max_i_pos, max_i_neg, i_set, max_v, shdn } } } -impl Tec { +impl Tec { pub fn setup(mut self, max: u16) -> Self { self.max_i_pos.set(max, max); self.max_i_neg.set(max, max); @@ -99,8 +102,11 @@ impl self.max_i_neg.set(width, total), - TecPin::ISet => - self.i_set.set(width, total), + TecPin::ISet => { + self.i_set.set(width, total); + // enable on first use + let _ = self.shdn.set_high(); + } TecPin::MaxV => self.max_v.set(width, total), }