2024-01-18 16:13:08 +08:00
|
|
|
use crate::laser_diode::ld_ctrl::{self, LdCtrlPhy};
|
2024-01-09 15:39:31 +08:00
|
|
|
use crate::laser_diode::max5719;
|
2024-01-26 11:43:53 +08:00
|
|
|
use crate::laser_diode::ld_pwr_exc_protector::LdPwrExcProtectorPhy;
|
2023-12-20 12:08:48 +08:00
|
|
|
use crate::thermostat::ad5680;
|
2024-01-09 15:39:31 +08:00
|
|
|
use crate::thermostat::max1968::{self, MAX1968PinSet, MAX1968Phy, PWM_FREQ_KHZ};
|
2024-01-16 17:36:16 +08:00
|
|
|
use crate::thermostat::ad7172;
|
2022-10-22 15:49:01 +08:00
|
|
|
use stm32_eth::EthPins;
|
2022-10-20 20:57:24 +08:00
|
|
|
use stm32f4xx_hal::{
|
2022-10-22 15:49:01 +08:00
|
|
|
gpio::{gpioa::*, gpiob::*, gpioc::*, gpiog::*, GpioExt, Input},
|
2022-10-20 20:57:24 +08:00
|
|
|
otg_fs::USB,
|
2023-12-20 12:08:48 +08:00
|
|
|
pac::{
|
2024-01-16 17:36:16 +08:00
|
|
|
GPIOA, GPIOB, GPIOC, GPIOD, GPIOG, OTG_FS_DEVICE, OTG_FS_GLOBAL, OTG_FS_PWRCLK, SPI1, SPI2, SPI3,
|
2023-12-20 12:08:48 +08:00
|
|
|
TIM4,
|
|
|
|
},
|
2022-10-20 20:57:24 +08:00
|
|
|
rcc::Clocks,
|
2022-10-22 15:49:01 +08:00
|
|
|
spi::{NoMiso, Spi},
|
2023-12-20 12:08:48 +08:00
|
|
|
timer::pwm::PwmExt,
|
2022-10-20 20:57:24 +08:00
|
|
|
};
|
2022-10-21 12:05:55 +08:00
|
|
|
|
2022-10-22 15:49:01 +08:00
|
|
|
pub type EthernetPins =
|
|
|
|
EthPins<PA1<Input>, PA7<Input>, PB11<Input>, PG13<Input>, PB13<Input>, PC4<Input>, PC5<Input>>;
|
2022-10-20 20:57:24 +08:00
|
|
|
|
2022-10-21 12:05:55 +08:00
|
|
|
pub fn setup(
|
|
|
|
clocks: Clocks,
|
2023-12-20 12:08:48 +08:00
|
|
|
tim4: TIM4,
|
2022-10-22 15:49:01 +08:00
|
|
|
gpioa: GPIOA,
|
|
|
|
gpiob: GPIOB,
|
|
|
|
gpioc: GPIOC,
|
|
|
|
gpiod: GPIOD,
|
|
|
|
gpiog: GPIOG,
|
2023-12-20 12:08:48 +08:00
|
|
|
spi1: SPI1,
|
2022-10-22 15:49:01 +08:00
|
|
|
spi2: SPI2,
|
2024-01-16 17:36:16 +08:00
|
|
|
spi3: SPI3,
|
2022-10-22 15:49:01 +08:00
|
|
|
otg_fs_global: OTG_FS_GLOBAL,
|
|
|
|
otg_fs_device: OTG_FS_DEVICE,
|
|
|
|
otg_fs_pwrclk: OTG_FS_PWRCLK,
|
|
|
|
) -> (
|
|
|
|
EthernetPins,
|
|
|
|
USB,
|
2024-01-18 16:13:08 +08:00
|
|
|
LdCtrlPhy<ld_ctrl::Channel0>,
|
2024-01-16 17:36:16 +08:00
|
|
|
ad7172::AdcPhy,
|
2024-01-09 15:39:31 +08:00
|
|
|
MAX1968Phy<max1968::Channel0>,
|
2024-01-26 11:43:53 +08:00
|
|
|
LdPwrExcProtectorPhy
|
2022-10-21 12:05:55 +08:00
|
|
|
) {
|
|
|
|
let gpioa = gpioa.split();
|
|
|
|
let gpiob = gpiob.split();
|
|
|
|
let gpioc = gpioc.split();
|
|
|
|
let gpiod = gpiod.split();
|
2022-10-22 15:49:01 +08:00
|
|
|
let gpiog = gpiog.split();
|
|
|
|
|
2022-10-21 12:05:55 +08:00
|
|
|
let usb = USB {
|
|
|
|
usb_global: otg_fs_global,
|
|
|
|
usb_device: otg_fs_device,
|
|
|
|
usb_pwrclk: otg_fs_pwrclk,
|
|
|
|
pin_dm: gpioa.pa11.into_alternate(),
|
|
|
|
pin_dp: gpioa.pa12.into_alternate(),
|
|
|
|
hclk: clocks.hclk(),
|
|
|
|
};
|
2022-10-20 20:57:24 +08:00
|
|
|
|
2022-10-21 12:05:55 +08:00
|
|
|
let eth_pins = EthPins {
|
2022-10-22 15:49:01 +08:00
|
|
|
ref_clk: gpioa.pa1,
|
|
|
|
crs: gpioa.pa7,
|
2022-10-21 12:05:55 +08:00
|
|
|
tx_en: gpiob.pb11,
|
2022-10-22 15:49:01 +08:00
|
|
|
tx_d0: gpiog.pg13,
|
2022-10-21 12:05:55 +08:00
|
|
|
tx_d1: gpiob.pb13,
|
2022-10-22 15:49:01 +08:00
|
|
|
rx_d0: gpioc.pc4,
|
2022-10-21 12:05:55 +08:00
|
|
|
rx_d1: gpioc.pc5,
|
|
|
|
};
|
2022-10-22 15:49:01 +08:00
|
|
|
|
2024-01-18 16:13:08 +08:00
|
|
|
let current_source_phy = LdCtrlPhy {
|
2024-01-09 15:39:31 +08:00
|
|
|
dac: max5719::Dac::new(Spi::new(
|
|
|
|
spi2,
|
|
|
|
(
|
|
|
|
gpiob.pb10.into_alternate(),
|
|
|
|
NoMiso {},
|
|
|
|
gpiob.pb15.into_alternate(),
|
|
|
|
),
|
|
|
|
max5719::SPI_MODE,
|
|
|
|
max5719::SPI_CLOCK_MHZ.convert(),
|
|
|
|
&clocks,
|
|
|
|
), gpiod.pd8.into_push_pull_output(),
|
|
|
|
gpiob.pb14.into_push_pull_output(),
|
2022-10-22 15:49:01 +08:00
|
|
|
),
|
2024-01-09 15:39:31 +08:00
|
|
|
current_source_short_pin: gpioa.pa4.into_push_pull_output(),
|
2024-01-30 13:01:33 +08:00
|
|
|
termination_status_pin: gpiod.pd7.internal_pull_up(true),
|
2022-10-21 12:05:55 +08:00
|
|
|
};
|
2022-10-20 20:57:24 +08:00
|
|
|
|
2024-01-26 11:43:53 +08:00
|
|
|
let pd_mon_phy = LdPwrExcProtectorPhy {
|
2024-01-24 12:10:53 +08:00
|
|
|
_pd_mon_ch0: gpioa.pa3.into_analog(),
|
|
|
|
pwr_en_ch0: gpiod.pd9.into_push_pull_output(),
|
|
|
|
};
|
2024-01-05 15:00:50 +08:00
|
|
|
|
2023-12-20 12:08:48 +08:00
|
|
|
let pwm_chs = (
|
|
|
|
gpiob.pb6.into_alternate(),
|
|
|
|
gpiob.pb7.into_alternate(),
|
|
|
|
gpiob.pb8.into_alternate(),
|
|
|
|
);
|
|
|
|
let (max_i_neg0, max_v0, max_i_pos0) =
|
2023-12-21 13:13:06 +08:00
|
|
|
tim4.pwm_hz(pwm_chs, PWM_FREQ_KHZ.convert(), &clocks).split();
|
2023-12-20 12:08:48 +08:00
|
|
|
|
2023-12-21 13:13:06 +08:00
|
|
|
let max1968_phy = MAX1968Phy::new(MAX1968PinSet {
|
|
|
|
dac: ad5680::Dac::new(
|
|
|
|
Spi::new(
|
|
|
|
spi1,
|
|
|
|
(
|
|
|
|
gpiob.pb3.into_alternate(),
|
|
|
|
NoMiso {},
|
|
|
|
gpiob.pb5.into_alternate(),
|
|
|
|
),
|
|
|
|
ad5680::SPI_MODE,
|
|
|
|
ad5680::SPI_CLOCK_MHZ.convert(),
|
|
|
|
&clocks,
|
2023-12-20 12:08:48 +08:00
|
|
|
),
|
2023-12-21 13:13:06 +08:00
|
|
|
gpiob.pb4.into_push_pull_output(),
|
2023-12-20 12:08:48 +08:00
|
|
|
),
|
|
|
|
shdn: gpioa.pa5.into_push_pull_output(),
|
2023-12-21 13:13:06 +08:00
|
|
|
vref_pin: gpioa.pa6.into_analog(),
|
|
|
|
itec_pin: gpiob.pb1.into_analog(),
|
2024-01-24 11:21:34 +08:00
|
|
|
dac_feedback_pin: gpioc.pc0.into_analog(),
|
2023-12-21 13:13:06 +08:00
|
|
|
vtec_pin: gpiob.pb0.into_analog(),
|
|
|
|
max_v: max_v0,
|
|
|
|
max_i_pos: max_i_pos0,
|
|
|
|
max_i_neg: max_i_neg0,
|
|
|
|
});
|
2023-12-20 12:08:48 +08:00
|
|
|
|
2024-01-16 17:36:16 +08:00
|
|
|
let ad7172_phy = ad7172::Adc::new(
|
|
|
|
Spi::new(spi3,
|
|
|
|
(
|
|
|
|
gpioc.pc10.into_alternate(),
|
|
|
|
gpioc.pc11.into_alternate(),
|
|
|
|
gpioc.pc12.into_alternate(),
|
|
|
|
),
|
|
|
|
ad7172::SPI_MODE,
|
|
|
|
ad7172::SPI_CLOCK_MHZ.convert(),
|
|
|
|
&clocks
|
|
|
|
),
|
2024-01-24 11:19:47 +08:00
|
|
|
gpioa.pa15.into_push_pull_output(),
|
2024-01-16 17:36:16 +08:00
|
|
|
).unwrap();
|
|
|
|
|
2024-01-24 12:10:53 +08:00
|
|
|
(eth_pins, usb, current_source_phy, ad7172_phy, max1968_phy, pd_mon_phy)
|
2022-10-21 12:05:55 +08:00
|
|
|
}
|