Clean up warnings

This commit is contained in:
linuswck 2024-01-09 16:53:34 +08:00
parent 59f2385ecf
commit e48f1979f0
6 changed files with 26 additions and 39 deletions

View File

@ -1,7 +1,8 @@
use core::marker::PhantomData;
use super::{gpio, sys_timer, usb}; use super::{gpio, sys_timer, usb};
use crate::laser_diode::current_sources::{*, self}; use crate::laser_diode::current_sources::{*};
use crate::laser_diode::ld_drive::LD_Drive; use crate::laser_diode::ld_drive::{self, LdDrive};
use crate::thermostat::max1968::{MAX1968}; use crate::thermostat::max1968::MAX1968;
use crate::thermostat::thermostat::Thermostat; use crate::thermostat::thermostat::Thermostat;
use fugit::ExtU32; use fugit::ExtU32;
use log::info; use log::info;
@ -22,7 +23,7 @@ const WATCHDOG_PERIOD: u32 = 30000;
pub fn bootup( pub fn bootup(
mut core_perif: CorePeripherals, mut core_perif: CorePeripherals,
perif: Peripherals, perif: Peripherals,
) -> (IndependentWatchdog, LD_Drive, Thermostat) { ) -> (IndependentWatchdog, LdDrive, Thermostat) {
core_perif.SCB.enable_icache(); core_perif.SCB.enable_icache();
core_perif.SCB.enable_dcache(&mut core_perif.CPUID); core_perif.SCB.enable_dcache(&mut core_perif.CPUID);
@ -58,13 +59,15 @@ pub fn bootup(
let current_source = CurrentSource::new(current_source_phy, perif.ADC2); let current_source = CurrentSource::new(current_source_phy, perif.ADC2);
let mut laser = LD_Drive::new(current_source); let mut laser = LdDrive::new(current_source);
laser.setup(); laser.setup();
laser.ld_open(); laser.ld_open();
laser.power_up(); laser.power_up();
laser.ld_set_i(ElectricCurrent::new::<ampere>(0.15)); laser.ld_set_i(ElectricCurrent::new::<ampere>(0.15));
// Set a non-zero value so that there is a non NAN power reading
laser.set_pd_i_to_out_pwr(ld_drive::IToPowerUnit {dimension: PhantomData, units: PhantomData, value: 0.001});
let tec_driver = MAX1968::new(max1968_phy, perif.ADC1); let tec_driver = MAX1968::new(max1968_phy, perif.ADC1);

View File

@ -2,7 +2,6 @@ use crate::laser_diode::current_sources::{self, CurrentSourcePhy};
use crate::laser_diode::max5719; use crate::laser_diode::max5719;
use crate::thermostat::ad5680; use crate::thermostat::ad5680;
use crate::thermostat::max1968::{self, MAX1968PinSet, MAX1968Phy, PWM_FREQ_KHZ}; use crate::thermostat::max1968::{self, MAX1968PinSet, MAX1968Phy, PWM_FREQ_KHZ};
use fugit::RateExtU32;
use stm32_eth::EthPins; use stm32_eth::EthPins;
use stm32f4xx_hal::{ use stm32f4xx_hal::{
gpio::{gpioa::*, gpiob::*, gpioc::*, gpiog::*, GpioExt, Input}, gpio::{gpioa::*, gpiob::*, gpioc::*, gpiog::*, GpioExt, Input},
@ -12,7 +11,6 @@ use stm32f4xx_hal::{
TIM4, TIM4,
}, },
rcc::Clocks, rcc::Clocks,
spi,
spi::{NoMiso, Spi}, spi::{NoMiso, Spi},
timer::pwm::PwmExt, timer::pwm::PwmExt,
}; };

View File

@ -16,7 +16,7 @@ use uom::si::{
}; };
use crate::laser_diode::max5719::{self, Dac}; use crate::laser_diode::max5719::{self, Dac};
use crate::laser_diode::ld_drive::transimpedance_unit; use crate::laser_diode::ld_drive::TransimpedanceUnit;
pub trait ChannelPins { pub trait ChannelPins {
type PdMonPin; type PdMonPin;
@ -106,7 +106,7 @@ impl CurrentSource {
voltage voltage
} }
pub fn set_i(&mut self, current: ElectricCurrent, transimpedance: transimpedance_unit, dac_out_v_max: ElectricPotential) -> ElectricCurrent { pub fn set_i(&mut self, current: ElectricCurrent, transimpedance: TransimpedanceUnit, dac_out_v_max: ElectricPotential) -> ElectricCurrent {
self.set_dac(current * transimpedance, dac_out_v_max) / transimpedance self.set_dac(current * transimpedance, dac_out_v_max) / transimpedance
} }
} }

View File

@ -3,26 +3,20 @@ use crate::laser_diode::current_sources::CurrentSource;
use core::{marker::PhantomData, f64::NAN}; use core::{marker::PhantomData, f64::NAN};
use uom::si::{ use uom::si::{
electric_current::{milliampere}, electric_current::milliampere,
f64::{ElectricPotential, ElectricCurrent, ElectricalResistance, Power}, f64::{ElectricPotential, ElectricCurrent, Power},
}; };
use uom::{si::{ISQ, SI, Quantity}, typenum::*}; use uom::{si::{ISQ, SI, Quantity}, typenum::*};
// Volt / Ampere // Volt / Ampere
pub type transimpedance_unit = Quantity<ISQ<P2, P1, N3, N2, Z0, Z0, Z0>, SI<f64>, f64>; pub type TransimpedanceUnit = Quantity<ISQ<P2, P1, N3, N2, Z0, Z0, Z0>, SI<f64>, f64>;
// Ampere / Volt // Ampere / Volt
type transconductance_unit = Quantity<ISQ<N2, N1, P3, P2, Z0, Z0, Z0>, SI<f64>, f64>; type TransconductanceUnit = Quantity<ISQ<N2, N1, P3, P2, Z0, Z0, Z0>, SI<f64>, f64>;
// Watt / Ampere // Watt / Ampere
pub type i_to_power_unit = Quantity<ISQ<P2, P1, N3, N1, Z0, Z0, Z0>, SI<f64>, f64>; pub type IToPowerUnit = Quantity<ISQ<P2, P1, N3, N1, Z0, Z0, Z0>, SI<f64>, f64>;
impl Settings{ impl Settings{
pub const R_SENSE: ElectricalResistance = ElectricalResistance {
dimension: PhantomData,
units: PhantomData,
value: 10.0,
};
pub const DAC_OUT_V_MAX: ElectricPotential = ElectricPotential { pub const DAC_OUT_V_MAX: ElectricPotential = ElectricPotential {
dimension: PhantomData, dimension: PhantomData,
units: PhantomData, units: PhantomData,
@ -30,13 +24,13 @@ impl Settings{
}; };
// Unit: A/V // Unit: A/V
const PD_MON_TRANSCONDUCTANCE: transconductance_unit = transconductance_unit { const PD_MON_TRANSCONDUCTANCE: TransconductanceUnit = TransconductanceUnit {
dimension: PhantomData, dimension: PhantomData,
units: PhantomData, units: PhantomData,
value: 0.001, value: 0.001,
}; };
const LD_DRIVE_TRANSIMPEDANCE: transimpedance_unit = transimpedance_unit { const LD_DRIVE_TRANSIMPEDANCE: TransimpedanceUnit = TransimpedanceUnit {
dimension: PhantomData, dimension: PhantomData,
units: PhantomData, units: PhantomData,
value: 10.0 / 0.75, value: 10.0 / 0.75,
@ -46,26 +40,26 @@ impl Settings{
#[derive(Clone, Debug, Miniconf)] #[derive(Clone, Debug, Miniconf)]
pub struct Settings { pub struct Settings {
ld_drive_current: ElectricCurrent, ld_drive_current: ElectricCurrent,
pd_i_to_out_pwr: i_to_power_unit, pd_i_to_out_pwr: IToPowerUnit,
} }
impl Default for Settings { impl Default for Settings {
fn default() -> Self { fn default() -> Self {
Self { Self {
ld_drive_current: ElectricCurrent::new::<milliampere>(0.0), ld_drive_current: ElectricCurrent::new::<milliampere>(0.0),
pd_i_to_out_pwr: i_to_power_unit {dimension: PhantomData, units: PhantomData, value: NAN} pd_i_to_out_pwr: IToPowerUnit {dimension: PhantomData, units: PhantomData, value: NAN}
} }
} }
} }
pub struct LD_Drive{ pub struct LdDrive{
ctrl: CurrentSource, ctrl: CurrentSource,
settings: Settings, settings: Settings,
} }
impl LD_Drive{ impl LdDrive{
pub fn new(current_source: CurrentSource)-> Self{ pub fn new(current_source: CurrentSource)-> Self{
LD_Drive { LdDrive {
ctrl: current_source, ctrl: current_source,
settings: Settings::default() settings: Settings::default()
} }
@ -89,7 +83,7 @@ impl LD_Drive{
self.settings.ld_drive_current self.settings.ld_drive_current
} }
pub fn set_pd_i_to_out_pwr(&mut self, val: i_to_power_unit){ pub fn set_pd_i_to_out_pwr(&mut self, val: IToPowerUnit){
self.settings.pd_i_to_out_pwr = val; self.settings.pd_i_to_out_pwr = val;
} }

View File

@ -1,9 +1,5 @@
use core::marker::PhantomData;
use core::u16; use core::u16;
use crate::thermostat::ad5680; use crate::thermostat::ad5680;
use crate::thermostat::thermostat::Settings;
use fugit::KilohertzU32; use fugit::KilohertzU32;
use stm32f4xx_hal::{ use stm32f4xx_hal::{
adc::{ adc::{
@ -13,16 +9,13 @@ use stm32f4xx_hal::{
gpio::{gpioa::*, gpiob::*, gpioc::*, Alternate, Analog, Output, PushPull}, gpio::{gpioa::*, gpiob::*, gpioc::*, Alternate, Analog, Output, PushPull},
hal::{self, blocking::spi::Transfer, digital::v2::OutputPin}, hal::{self, blocking::spi::Transfer, digital::v2::OutputPin},
pac::{ADC1, SPI1, TIM4}, pac::{ADC1, SPI1, TIM4},
rcc::Clocks,
spi::{NoMiso, Spi, TransferModeNormal}, spi::{NoMiso, Spi, TransferModeNormal},
timer::pwm::{PwmChannel, PwmExt}, timer::pwm::PwmChannel,
}; };
use uom::si::{ use uom::si::{
electric_current::ampere, electric_potential::millivolt,
electric_potential::{millivolt, volt}, f64::ElectricPotential,
electrical_resistance::ohm,
f64::{ElectricCurrent, ElectricPotential, ElectricalResistance},
ratio::ratio, ratio::ratio,
}; };

View File

@ -3,7 +3,6 @@ use crate::sys_timer;
use crate::thermostat::ad5680; use crate::thermostat::ad5680;
use crate::thermostat::max1968::{MAX1968, AdcReadTarget, PwmPinsEnum}; use crate::thermostat::max1968::{MAX1968, AdcReadTarget, PwmPinsEnum};
use log::info; use log::info;
use miniconf::serde::de::value;
use uom::si::{ use uom::si::{
electric_current::ampere, electric_current::ampere,
electric_potential::volt, electric_potential::volt,