laser: Add driver and fn to get termination status

This commit is contained in:
linuswck 2024-01-30 13:01:33 +08:00
parent f6677d874c
commit 4e0d14def2
4 changed files with 15 additions and 2 deletions

View File

@ -82,6 +82,7 @@ pub fn setup(
gpiob.pb14.into_push_pull_output(),
),
current_source_short_pin: gpioa.pa4.into_push_pull_output(),
termination_status_pin: gpiod.pd7.internal_pull_up(true),
};
let pd_mon_phy = LdPwrExcProtectorPhy {

View File

@ -174,4 +174,8 @@ impl LdDrive{
pub fn set_pd_i_limit(&mut self, i: ElectricCurrent){
LdPwrExcProtector::set_trigger_threshold_v(i / Settings::PD_MON_TRANSCONDUCTANCE);
}
pub fn get_term_status(&mut self)->bool{
self.ctrl.get_term_status()
}
}

View File

@ -1,6 +1,6 @@
use stm32f4xx_hal::{
gpio::{gpioa::*, gpiob::*, gpiod::*, Alternate, Output, PushPull},
hal::{blocking::spi::Transfer, digital::v2::OutputPin},
gpio::{gpioa::*, gpiob::*, gpiod::*, Alternate, Input, Output, PushPull},
hal::{blocking::spi::Transfer, digital::{v2::OutputPin, v2::InputPin}},
pac::SPI2,
spi::{NoMiso, Spi, TransferModeNormal},
};
@ -15,6 +15,7 @@ use crate::laser_diode::laser_diode::TransimpedanceUnit;
pub trait ChannelPins {
type CurrentSourceShort: OutputPin;
type TerminationStatus: InputPin;
type Max5719Load: OutputPin;
type Max5719Cs: OutputPin;
type Max5719Spi: Transfer<u8>;
@ -23,11 +24,13 @@ pub trait ChannelPins {
pub struct LdCtrlPhy<C: ChannelPins> {
pub dac: Dac<C::Max5719Spi, C::Max5719Cs, C::Max5719Load>,
pub current_source_short_pin: C::CurrentSourceShort,
pub termination_status_pin: C::TerminationStatus
}
pub struct Channel0;
impl ChannelPins for Channel0 {
type CurrentSourceShort = PA4<Output<PushPull>>;
type TerminationStatus = PD7<Input>;
type Max5719Load = DacLoad;
type Max5719Cs = DacCs;
type Max5719Spi = DacSpi;
@ -58,6 +61,10 @@ impl LdCtrl {
self.phy.current_source_short_pin.set_high();
}
pub fn get_term_status(&mut self)-> bool{
self.phy.termination_status_pin.is_high()
}
pub fn set_dac(&mut self, voltage: ElectricPotential, dac_out_v_max: ElectricPotential) -> ElectricPotential {
let value = ((voltage / dac_out_v_max).get::<ratio>()
* (max5719::MAX_VALUE as f64)) as u32;

View File

@ -84,6 +84,7 @@ fn main() -> ! {
info!("pd_mon_v: {:?}", volt_fmt.with(laser.pd_mon_status().v));
info!("power_excursion: {:?}", laser.pd_mon_status().pwr_excursion);
info!("Termination Status: {:?}", laser.get_term_status());
sys_timer::sleep(500);
}
}