show pwm config of each tec channel

This commit is contained in:
Astro 2019-09-24 01:45:11 +02:00
parent 18e3e95615
commit fca427cb5a
3 changed files with 59 additions and 1 deletions

View File

@ -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()) });

View File

@ -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) => {

View File

@ -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<MaxIPos: PwmChannel, MaxINeg: PwmChannel, ISet: PwmChannel, MaxV: PwmChannel> {
@ -45,6 +70,19 @@ impl Tec<pwm::T4CCP0, pwm::T4CCP1, pwm::T5CCP0, pwm::T5CCP1> {
impl<MaxIPos: PwmChannel, MaxINeg: PwmChannel, ISet: PwmChannel, MaxV: PwmChannel> Tec<MaxIPos, MaxINeg, ISet, MaxV> {
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 =>