kirdy/src/device/gpio.rs

85 lines
2.3 KiB
Rust
Raw Normal View History

2022-10-22 15:49:01 +08:00
use crate::laser_diode::current_sources::*;
use fugit::RateExtU32;
use stm32_eth::EthPins;
2022-10-20 20:57:24 +08:00
use stm32f4xx_hal::{
gpio::{Alternate, GpioExt, Speed},
2022-10-20 20:57:24 +08:00
otg_fs::USB,
pac::{GPIOA, GPIOB, GPIOC, GPIOD, OTG_FS_DEVICE, OTG_FS_GLOBAL, OTG_FS_PWRCLK, SPI2},
2022-10-20 20:57:24 +08:00
rcc::Clocks,
2022-10-21 12:05:55 +08:00
spi,
2022-10-22 15:49:01 +08:00
spi::{NoMiso, Spi},
2022-10-20 20:57:24 +08:00
};
2022-10-21 12:05:55 +08:00
2022-11-01 11:16:55 +08:00
use crate::network::network::EthernetPins;
2022-10-20 20:57:24 +08:00
2022-10-21 12:05:55 +08:00
pub fn setup(
clocks: Clocks,
2022-10-22 15:49:01 +08:00
gpioa: GPIOA,
gpiob: GPIOB,
gpioc: GPIOC,
gpiod: GPIOD,
spi2: SPI2,
otg_fs_global: OTG_FS_GLOBAL,
otg_fs_device: OTG_FS_DEVICE,
otg_fs_pwrclk: OTG_FS_PWRCLK,
) -> (
EthernetPins,
USB,
CurrentSourcePhyConstruct<CurrentSourcePhyCh0>,
2022-11-01 11:16:55 +08:00
stm32f4xx_hal::gpio::PA2<Alternate<11>>,
stm32f4xx_hal::gpio::PC1<Alternate<11>>, // photo_diode_phy,
// thermostat_phy
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
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-11-01 11:16:55 +08:00
tx_d0: gpiob.pb12,
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
2022-11-01 11:16:55 +08:00
let mut mdio = gpioa.pa2.into_alternate::<11>();
let mut mdc = gpioc.pc1.into_alternate::<11>();
mdio.set_speed(Speed::VeryHigh);
mdc.set_speed(Speed::VeryHigh);
2022-10-22 15:49:01 +08:00
let current_source_phy = CurrentSourcePhyConstruct {
2022-10-22 01:58:18 +08:00
max5719_spi: Spi::new(
2022-10-22 15:49:01 +08:00
spi2,
(
gpiob.pb10.into_alternate(),
NoMiso {},
gpiob.pb15.into_alternate(),
),
2022-10-22 01:58:18 +08:00
spi::Mode {
polarity: spi::Polarity::IdleLow,
phase: spi::Phase::CaptureOnFirstTransition,
2022-10-22 15:49:01 +08:00
},
10_u32.MHz(),
&clocks,
),
max5719_load: gpiob.pb14.into_push_pull_output(),
max5719_cs: gpiod.pd8.into_push_pull_output(),
2022-10-22 01:58:18 +08:00
current_source_ldo_en: gpiod.pd9.into_push_pull_output(),
2022-10-22 15:49:01 +08:00
current_source_short: gpioa.pa4.into_push_pull_output(),
2022-10-21 12:05:55 +08:00
};
2022-10-20 20:57:24 +08:00
2022-11-01 11:16:55 +08:00
(eth_pins, usb, current_source_phy, mdio, mdc)
2022-10-21 12:05:55 +08:00
}