diff --git a/firmware/src/board/pwm.rs b/firmware/src/board/pwm.rs index 0cbdd46..89880f1 100644 --- a/firmware/src/board/pwm.rs +++ b/firmware/src/board/pwm.rs @@ -44,6 +44,7 @@ pwm_peripheral!(TIMER5, T5CCP0, T5CCP1); pub trait PwmChannel { fn configure(&mut self); + fn get(&mut self) -> (u16, u16); fn set(&mut self, width: u16, total: u16); } @@ -72,6 +73,12 @@ macro_rules! pwm_channel_a { }); } + fn get(&mut self) -> (u16, u16) { + let timer = unsafe { &*tm4c129x::$TIMER::ptr() }; + (timer.tamatchr.read().bits() as u16, + timer.tailr.read().bits() as u16) + } + fn set(&mut self, width: u16, total: u16) { let timer = unsafe { &*tm4c129x::$TIMER::ptr() }; timer.tamatchr.write(|w| unsafe { w.bits(width.into()) }); @@ -106,6 +113,12 @@ macro_rules! pwm_channel_b { }); } + fn get(&mut self) -> (u16, u16) { + let timer = unsafe { &*tm4c129x::$TIMER::ptr() }; + (timer.tbmatchr.read().bits() as u16, + timer.tbilr.read().bits() as u16) + } + fn set(&mut self, width: u16, total: u16) { let timer = unsafe { &*tm4c129x::$TIMER::ptr() }; timer.tbmatchr.write(|w| unsafe { w.bits(width.into()) }); diff --git a/firmware/src/main.rs b/firmware/src/main.rs index c82d555..cd80b00 100644 --- a/firmware/src/main.rs +++ b/firmware/src/main.rs @@ -314,13 +314,20 @@ fn main() -> ! { } } Command::Show(ShowCommand::Pwm) => { - // TODO: show all pwms, show actual state for (channel, state) in states.iter().enumerate() { let _ = writeln!( socket, "PWM {}: PID {}", channel, if state.pid_enabled { "engaged" } else { "disengaged" } ); + for pin in TecPin::VALID_VALUES { + let (width, total) = match channel { + 0 => tec0.get(*pin), + 1 => tec1.get(*pin), + _ => unreachable!(), + }; + let _ = writeln!(socket, "- {}={}/{}", pin, width, total); + } } } Command::Show(ShowCommand::PostFilter) => { diff --git a/firmware/src/tec.rs b/firmware/src/tec.rs index d2c1193..12b4b36 100644 --- a/firmware/src/tec.rs +++ b/firmware/src/tec.rs @@ -1,3 +1,4 @@ +use core::fmt; use crate::board::pwm::{self, PwmChannel, PwmPeripheral}; #[derive(Clone, Copy, Debug)] @@ -8,6 +9,30 @@ pub enum TecPin { MaxV, } +impl TecPin { + pub const VALID_VALUES: &'static [TecPin] = &[ + TecPin::ISet, + TecPin::MaxIPos, + TecPin::MaxINeg, + TecPin::MaxV, + ]; +} + +impl fmt::Display for TecPin { + fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match self { + TecPin::ISet => + "i_set".fmt(fmt), + TecPin::MaxIPos => + "max_i_pos".fmt(fmt), + TecPin::MaxINeg => + "max_i_neg".fmt(fmt), + TecPin::MaxV => + "max_v".fmt(fmt), + } + } +} + /// Thermo-Electric Cooling device controlled through four PWM /// channels pub struct Tec { @@ -45,6 +70,19 @@ impl Tec { impl Tec { + pub fn get(&mut self, pin: TecPin) -> (u16, u16) { + match pin { + TecPin::MaxIPos => + self.max_i_pos.get(), + TecPin::MaxINeg => + self.max_i_neg.get(), + TecPin::ISet => + self.i_set.get(), + TecPin::MaxV => + self.max_v.get(), + } + } + pub fn set(&mut self, pin: TecPin, width: u16, total: u16) { match pin { TecPin::MaxIPos =>