use stm32f4xx_hal::{ adc::{ config::{self, AdcConfig}, Adc, }, gpio::{gpioa::*, gpiob::*, gpiod::*, Alternate, Output, PushPull, Analog, PD9}, hal::{blocking::spi::Transfer, digital::v2::OutputPin}, pac::{SPI2, ADC2}, spi::{NoMiso, Spi, TransferModeNormal}, }; use crate::laser_diode::max5719::{self, Dac}; pub trait ChannelPins { type PdMonPin; type CurrentSourceLdoEn: OutputPin; type CurrentSourceShort: OutputPin; type Max5719Load: OutputPin; type Max5719Cs: OutputPin; type Max5719Spi: Transfer; } pub struct CurrentSourcePhy { pub dac: Dac, pub current_source_ldo_en_pin: C::CurrentSourceLdoEn, pub current_source_short_pin: C::CurrentSourceShort, pub pd_mon_pin : C::PdMonPin, } pub struct Channel0; impl ChannelPins for Channel0 { type PdMonPin = PA3; type CurrentSourceLdoEn = PD9>; type CurrentSourceShort = PA4>; type Max5719Load = DacLoad; type Max5719Cs = DacCs; type Max5719Spi = DacSpi; } type DacSpi = Spi>, NoMiso, PB15>), TransferModeNormal>; type DacCs = PD8>; type DacLoad = PB14>; pub struct CurrentSource{ pub phy: CurrentSourcePhy, pub pins_adc: Adc } impl CurrentSource { pub fn new(phy_ch0: CurrentSourcePhy, adc2: ADC2) -> Self { let config = AdcConfig::default() .clock(config::Clock::Pclk2_div_2) .default_sample_time(config::SampleTime::Cycles_480); let pins_adc = Adc::adc2(adc2, true, config); CurrentSource { phy: phy_ch0, pins_adc: pins_adc, } } }