kirdy/src/laser_diode/ld_drive.rs

95 lines
2.5 KiB
Rust
Raw Normal View History

use miniconf::Miniconf;
use crate::laser_diode::current_sources::CurrentSource;
use core::{marker::PhantomData, f64::NAN};
use uom::si::{
electric_current::{milliampere},
f64::{ElectricPotential, ElectricCurrent, ElectricalResistance},
};
use uom::{si::{ISQ, SI, Quantity}, typenum::*};
// Volt / Ampere
pub type transimpedance_unit = Quantity<ISQ<P2, P1, N3, N2, Z0, Z0, Z0>, SI<f64>, f64>;
// Ampere / Volt
type transconductance_unit = Quantity<ISQ<N2, N1, P3, P2, Z0, Z0, Z0>, SI<f64>, f64>;
// Watt / Ampere
pub type i_to_power_unit = Quantity<ISQ<P2, P1, N3, N1, Z0, Z0, Z0>, SI<f64>, f64>;
impl Settings{
pub const R_SENSE: ElectricalResistance = ElectricalResistance {
dimension: PhantomData,
units: PhantomData,
value: 10.0,
};
pub const DAC_OUT_V_MAX: ElectricPotential = ElectricPotential {
dimension: PhantomData,
units: PhantomData,
value: 4.096,
};
// Unit: A/V
const PD_MON_TRANSCONDUCTANCE: transconductance_unit = transconductance_unit {
dimension: PhantomData,
units: PhantomData,
value: 0.001,
};
const LD_DRIVE_TRANSIMPEDANCE: transimpedance_unit = transimpedance_unit {
dimension: PhantomData,
units: PhantomData,
value: 10.0 / 0.75,
};
}
#[derive(Clone, Debug, Miniconf)]
pub struct Settings {
pub ld_drive_current: ElectricCurrent,
pub pd_i_to_out_pwr: i_to_power_unit,
}
impl Default for Settings {
fn default() -> Self {
Self {
ld_drive_current: ElectricCurrent::new::<milliampere>(0.0),
pd_i_to_out_pwr: i_to_power_unit {dimension: PhantomData, units: PhantomData, value: NAN}
}
}
}
pub struct LD_Drive{
ctrl: CurrentSource,
settings: Settings,
}
impl LD_Drive{
pub fn new(current_source: CurrentSource)-> Self{
LD_Drive {
ctrl: current_source,
settings: Settings::default()
}
}
pub fn power_up(&mut self){
self.ctrl.power_up();
}
pub fn power_down(&mut self){
self.ctrl.power_down();
}
pub fn ld_short(&mut self) {
self.ctrl.ld_short_enable();
}
pub fn ld_open(&mut self) {
self.ctrl.ld_short_disable();
}
pub fn ld_set_i(&mut self, i: ElectricCurrent) -> ElectricCurrent {
let ld_i_set = self.ctrl.set_i(i, Settings::LD_DRIVE_TRANSIMPEDANCE, Settings::DAC_OUT_V_MAX);
self.settings.ld_drive_current = ld_i_set;
ld_i_set
}
}