2022-10-20 20:57:24 +08:00
|
|
|
use stm32f4xx_hal::{
|
|
|
|
adc::Adc,
|
|
|
|
gpio::{
|
2022-10-21 12:05:55 +08:00
|
|
|
AF5, Alternate, Analog, Input,
|
2022-10-20 20:57:24 +08:00
|
|
|
gpioa::*,
|
|
|
|
gpiob::*,
|
|
|
|
gpioc::*,
|
2022-10-21 12:05:55 +08:00
|
|
|
gpiod::*,
|
2022-10-20 20:57:24 +08:00
|
|
|
gpioe::*,
|
|
|
|
gpiof::*,
|
|
|
|
gpiog::*,
|
|
|
|
GpioExt,
|
|
|
|
Output, PushPull,
|
|
|
|
},
|
|
|
|
hal::{self, blocking::spi::Transfer, digital::v2::OutputPin},
|
|
|
|
otg_fs::USB,
|
|
|
|
rcc::Clocks,
|
2022-10-21 12:05:55 +08:00
|
|
|
spi,
|
2022-10-20 20:57:24 +08:00
|
|
|
spi::{Spi, NoMiso, TransferModeNormal},
|
|
|
|
pac::{
|
|
|
|
ADC1,
|
|
|
|
GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG,
|
|
|
|
OTG_FS_GLOBAL, OTG_FS_DEVICE, OTG_FS_PWRCLK,
|
|
|
|
SPI1, SPI2, SPI3,
|
|
|
|
TIM4
|
|
|
|
},
|
|
|
|
timer::Timer,
|
|
|
|
time::U32Ext,
|
2022-10-21 12:05:55 +08:00
|
|
|
time::MegaHertz
|
2022-10-20 20:57:24 +08:00
|
|
|
};
|
2022-10-21 12:05:55 +08:00
|
|
|
use fugit::RateExtU32;
|
2022-10-20 20:57:24 +08:00
|
|
|
use stm32_eth::EthPins;
|
2022-10-21 12:05:55 +08:00
|
|
|
use crate::laser_diode::current_sources::*;
|
|
|
|
|
2022-10-20 20:57:24 +08:00
|
|
|
pub type EthernetPins = EthPins<
|
2022-10-21 12:05:55 +08:00
|
|
|
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,
|
|
|
|
tim4: TIM4,
|
|
|
|
gpioa: GPIOA, gpiob: GPIOB, gpioc: GPIOC, gpiod: GPIOD, gpioe: GPIOE, gpiof: GPIOF, gpiog: GPIOG,
|
|
|
|
spi1: SPI1, spi2: SPI2, spi3: SPI3,
|
|
|
|
adc1: ADC1,
|
|
|
|
otg_fs_global: OTG_FS_GLOBAL, otg_fs_device: OTG_FS_DEVICE, otg_fs_pwrclk: OTG_FS_PWRCLK,
|
|
|
|
) -> (
|
|
|
|
EthernetPins,
|
|
|
|
USB,
|
|
|
|
current_source_construct<current_source_0>,
|
|
|
|
// photo_diode_phy,
|
|
|
|
// thermostat_phy
|
|
|
|
) {
|
2022-10-20 20:57:24 +08:00
|
|
|
|
2022-10-21 12:05:55 +08:00
|
|
|
let gpioa = gpioa.split();
|
|
|
|
let gpiob = gpiob.split();
|
|
|
|
let gpioc = gpioc.split();
|
|
|
|
let gpiod = gpiod.split();
|
|
|
|
let gpioe = gpioe.split();
|
|
|
|
let gpiof = gpiof.split();
|
|
|
|
let gpiog = gpiog.split();
|
|
|
|
|
|
|
|
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 {
|
|
|
|
ref_clk: gpioa.pa1,
|
|
|
|
crs: gpioa.pa7,
|
|
|
|
tx_en: gpiob.pb11,
|
|
|
|
tx_d0: gpiog.pg13,
|
|
|
|
tx_d1: gpiob.pb13,
|
|
|
|
rx_d0: gpioc.pc4,
|
|
|
|
rx_d1: gpioc.pc5,
|
|
|
|
};
|
2022-10-20 20:57:24 +08:00
|
|
|
|
2022-10-21 12:05:55 +08:00
|
|
|
let sck = gpiob.pb10.into_alternate();
|
|
|
|
let mosi = gpiob.pb15.into_alternate();
|
|
|
|
let mode = spi::Mode {
|
|
|
|
polarity: spi::Polarity::IdleHigh,
|
|
|
|
phase: spi::Phase::CaptureOnSecondTransition,
|
|
|
|
};
|
|
|
|
let spi2 = Spi::new(
|
|
|
|
spi2,
|
|
|
|
(sck, NoMiso {}, mosi),
|
|
|
|
mode,
|
|
|
|
10_u32.MHz(),
|
|
|
|
&clocks);
|
2022-10-20 20:57:24 +08:00
|
|
|
|
2022-10-21 12:05:55 +08:00
|
|
|
|
|
|
|
let current_source: current_source_construct<current_source_0> = current_source_construct {
|
|
|
|
max5719_spi: spi2,
|
|
|
|
max5719_load: gpioe.pe4.into_push_pull_output(),
|
|
|
|
current_source_ldo_en: gpioe.pe10.into_push_pull_output(),
|
|
|
|
current_source_short: gpioa.pa4.into_push_pull_output(),
|
|
|
|
output_current: 0.0
|
|
|
|
};
|
|
|
|
|
|
|
|
(eth_pins, usb, current_source)
|
2022-10-20 20:57:24 +08:00
|
|
|
|
2022-10-21 12:05:55 +08:00
|
|
|
}
|
2022-10-20 20:57:24 +08:00
|
|
|
|