2024-01-09 15:53:24 +08:00
|
|
|
use miniconf::Miniconf;
|
|
|
|
use crate::laser_diode::current_sources::CurrentSource;
|
2024-01-09 15:58:31 +08:00
|
|
|
use core::marker::PhantomData;
|
2024-01-09 15:53:24 +08:00
|
|
|
|
|
|
|
use uom::si::{
|
|
|
|
electric_current::{milliampere},
|
2024-01-09 15:58:31 +08:00
|
|
|
f64::{ElectricPotential, ElectricCurrent, ElectricalResistance},
|
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
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-01-09 15:53:24 +08:00
|
|
|
#[derive(Clone, Debug, Miniconf)]
|
|
|
|
pub struct Settings {
|
|
|
|
pub ld_drive_current: ElectricCurrent,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Settings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
ld_drive_current: ElectricCurrent::new::<milliampere>(0.0),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|