2024-01-09 15:53:24 +08:00
|
|
|
use miniconf::Miniconf;
|
|
|
|
use crate::laser_diode::current_sources::CurrentSource;
|
2024-01-09 16:10:14 +08:00
|
|
|
use core::{marker::PhantomData, f64::NAN};
|
2024-01-09 15:53:24 +08:00
|
|
|
|
|
|
|
use uom::si::{
|
2024-01-09 16:53:34 +08:00
|
|
|
electric_current::milliampere,
|
|
|
|
f64::{ElectricPotential, ElectricCurrent, Power},
|
2024-01-09 15:53:24 +08:00
|
|
|
};
|
|
|
|
|
2024-01-09 15:58:31 +08:00
|
|
|
use uom::{si::{ISQ, SI, Quantity}, typenum::*};
|
|
|
|
|
|
|
|
// Volt / Ampere
|
2024-01-09 16:53:34 +08:00
|
|
|
pub type TransimpedanceUnit = Quantity<ISQ<P2, P1, N3, N2, Z0, Z0, Z0>, SI<f64>, f64>;
|
2024-01-09 15:58:31 +08:00
|
|
|
// Ampere / Volt
|
2024-01-09 16:53:34 +08:00
|
|
|
type TransconductanceUnit = Quantity<ISQ<N2, N1, P3, P2, Z0, Z0, Z0>, SI<f64>, f64>;
|
2024-01-09 15:58:31 +08:00
|
|
|
// Watt / Ampere
|
2024-01-09 16:53:34 +08:00
|
|
|
pub type IToPowerUnit = Quantity<ISQ<P2, P1, N3, N1, Z0, Z0, Z0>, SI<f64>, f64>;
|
2024-01-09 15:58:31 +08:00
|
|
|
|
|
|
|
impl Settings{
|
|
|
|
pub const DAC_OUT_V_MAX: ElectricPotential = ElectricPotential {
|
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 4.096,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Unit: A/V
|
2024-01-09 16:53:34 +08:00
|
|
|
const PD_MON_TRANSCONDUCTANCE: TransconductanceUnit = TransconductanceUnit {
|
2024-01-09 15:58:31 +08:00
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 0.001,
|
|
|
|
};
|
|
|
|
|
2024-01-09 16:53:34 +08:00
|
|
|
const LD_DRIVE_TRANSIMPEDANCE: TransimpedanceUnit = TransimpedanceUnit {
|
2024-01-09 15:58:31 +08:00
|
|
|
dimension: PhantomData,
|
|
|
|
units: PhantomData,
|
|
|
|
value: 10.0 / 0.75,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-01-09 15:53:24 +08:00
|
|
|
#[derive(Clone, Debug, Miniconf)]
|
|
|
|
pub struct Settings {
|
2024-01-09 16:31:58 +08:00
|
|
|
ld_drive_current: ElectricCurrent,
|
2024-01-09 16:53:34 +08:00
|
|
|
pd_i_to_out_pwr: IToPowerUnit,
|
2024-01-09 15:53:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Settings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
ld_drive_current: ElectricCurrent::new::<milliampere>(0.0),
|
2024-01-09 16:53:34 +08:00
|
|
|
pd_i_to_out_pwr: IToPowerUnit {dimension: PhantomData, units: PhantomData, value: NAN}
|
2024-01-09 15:53:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:53:34 +08:00
|
|
|
pub struct LdDrive{
|
2024-01-09 15:53:24 +08:00
|
|
|
ctrl: CurrentSource,
|
|
|
|
settings: Settings,
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:53:34 +08:00
|
|
|
impl LdDrive{
|
2024-01-09 15:53:24 +08:00
|
|
|
pub fn new(current_source: CurrentSource)-> Self{
|
2024-01-09 16:53:34 +08:00
|
|
|
LdDrive {
|
2024-01-09 15:53:24 +08:00
|
|
|
ctrl: current_source,
|
|
|
|
settings: Settings::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:13:42 +08:00
|
|
|
pub fn setup(&mut self) {
|
|
|
|
self.power_down();
|
|
|
|
self.ld_set_i(ElectricCurrent::new::<milliampere>(0.0));
|
|
|
|
self.ld_short();
|
|
|
|
}
|
|
|
|
|
2024-01-09 15:53:24 +08:00
|
|
|
pub fn power_up(&mut self){
|
|
|
|
self.ctrl.power_up();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn power_down(&mut self){
|
|
|
|
self.ctrl.power_down();
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:31:58 +08:00
|
|
|
pub fn get_ld_drive_current(&mut self) -> ElectricCurrent{
|
|
|
|
self.settings.ld_drive_current
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:53:34 +08:00
|
|
|
pub fn set_pd_i_to_out_pwr(&mut self, val: IToPowerUnit){
|
2024-01-09 16:31:58 +08:00
|
|
|
self.settings.pd_i_to_out_pwr = val;
|
|
|
|
}
|
|
|
|
|
2024-01-09 15:53:24 +08:00
|
|
|
pub fn ld_short(&mut self) {
|
|
|
|
self.ctrl.ld_short_enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ld_open(&mut self) {
|
|
|
|
self.ctrl.ld_short_disable();
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:11:50 +08:00
|
|
|
pub fn get_ld_power_output(&mut self) -> Power {
|
|
|
|
let pd_i = self.get_pd_i();
|
|
|
|
pd_i * self.settings.pd_i_to_out_pwr
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_pd_i(&mut self) -> ElectricCurrent {
|
|
|
|
self.ctrl.get_pd_mon_v() * Settings::PD_MON_TRANSCONDUCTANCE
|
|
|
|
}
|
|
|
|
|
2024-01-09 16:02:17 +08:00
|
|
|
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
|
|
|
|
}
|
2024-01-09 15:53:24 +08:00
|
|
|
}
|