pub use embedded_hal;
pub use stm32h7xx_hal as hal;
pub mod adc;
pub mod afe;
pub mod cpu_temp_sensor;
pub mod dac;
pub mod delay;
pub mod design_parameters;
mod eeprom;
pub mod flash;
pub mod input_stamper;
pub mod metadata;
pub mod platform;
pub mod pounder;
pub mod setup;
pub mod shared_adc;
pub mod signal_generator;
pub mod timers;
pub type AFE0 = afe::ProgrammableGainAmplifier<
hal::gpio::gpiof::PF2<hal::gpio::Output<hal::gpio::PushPull>>,
hal::gpio::gpiof::PF5<hal::gpio::Output<hal::gpio::PushPull>>,
>;
pub type AFE1 = afe::ProgrammableGainAmplifier<
hal::gpio::gpiod::PD14<hal::gpio::Output<hal::gpio::PushPull>>,
hal::gpio::gpiod::PD15<hal::gpio::Output<hal::gpio::PushPull>>,
>;
pub type UsbBus = stm32h7xx_hal::usb_hs::UsbBus<stm32h7xx_hal::usb_hs::USB2>;
pub type UsbDevice = usb_device::device::UsbDevice<'static, UsbBus>;
pub type DigitalInput0 = hal::gpio::gpiog::PG9<hal::gpio::Input>;
pub type DigitalInput1 = hal::gpio::gpioc::PC15<hal::gpio::Input>;
pub type EemDigitalInput0 = hal::gpio::gpiod::PD1<hal::gpio::Input>;
pub type EemDigitalInput1 = hal::gpio::gpiod::PD2<hal::gpio::Input>;
pub type EemDigitalOutput0 = hal::gpio::gpiod::PD3<hal::gpio::Output>;
pub type EemDigitalOutput1 = hal::gpio::gpiod::PD4<hal::gpio::Output>;
const TX_DESRING_CNT: usize = 4;
const RX_DESRING_CNT: usize = 4;
pub type NetworkStack = smoltcp_nal::NetworkStack<
'static,
hal::ethernet::EthernetDMA<TX_DESRING_CNT, RX_DESRING_CNT>,
SystemTimer,
>;
pub type NetworkManager = smoltcp_nal::shared::NetworkManager<
'static,
hal::ethernet::EthernetDMA<TX_DESRING_CNT, RX_DESRING_CNT>,
SystemTimer,
>;
pub type EthernetPhy = hal::ethernet::phy::LAN8742A<hal::ethernet::EthernetMAC>;
pub const MONOTONIC_FREQUENCY: u32 = 1_000;
pub type Systick = rtic_monotonics::systick::Systick;
pub type SystemTimer = mono_clock::MonoClock<u32, MONOTONIC_FREQUENCY>;
pub type I2c1 = hal::i2c::I2c<hal::stm32::I2C1>;
pub type I2c1Proxy =
shared_bus::I2cProxy<'static, shared_bus::AtomicCheckMutex<I2c1>>;
pub type SerialPort = usbd_serial::SerialPort<
'static,
crate::hardware::UsbBus,
&'static mut [u8],
&'static mut [u8],
>;
pub type SerialTerminal<C, const Y: usize> = serial_settings::Runner<
'static,
crate::settings::SerialSettingsPlatform<C, Y>,
Y,
>;
pub enum HardwareVersion {
Rev1_0,
Rev1_1,
Rev1_2,
Rev1_3,
Unknown(u8),
}
impl From<u8> for HardwareVersion {
fn from(bitfield: u8) -> Self {
match bitfield {
0b000 => HardwareVersion::Rev1_0,
0b001 => HardwareVersion::Rev1_1,
0b010 => HardwareVersion::Rev1_2,
0b011 => HardwareVersion::Rev1_3,
other => HardwareVersion::Unknown(other),
}
}
}
impl core::fmt::Display for HardwareVersion {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
HardwareVersion::Rev1_0 => write!(f, "v1.0"),
HardwareVersion::Rev1_1 => write!(f, "v1.1"),
HardwareVersion::Rev1_2 => write!(f, "v1.2"),
HardwareVersion::Rev1_3 => write!(f, "v1.3"),
HardwareVersion::Unknown(other) => {
write!(f, "Unknown ({:#b})", other)
}
}
}
}
impl serde::Serialize for HardwareVersion {
fn serialize<S: serde::Serializer>(
&self,
serializer: S,
) -> Result<S::Ok, S::Error> {
use core::fmt::Write;
let mut version_string: heapless::String<32> = heapless::String::new();
write!(&mut version_string, "{}", self).unwrap();
serializer.serialize_str(&version_string)
}
}
#[inline(never)]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
use core::{
fmt::Write,
sync::atomic::{AtomicBool, Ordering},
};
use cortex_m::asm;
use rtt_target::{ChannelMode, UpChannel};
cortex_m::interrupt::disable();
static PANICKED: AtomicBool = AtomicBool::new(false);
while PANICKED.load(Ordering::Relaxed) {
asm::bkpt();
}
PANICKED.store(true, Ordering::Relaxed);
let gpiod = unsafe { &*hal::stm32::GPIOD::ptr() };
gpiod.odr.modify(|_, w| w.odr6().high().odr12().high());
if let Some(mut channel) = unsafe { UpChannel::conjure(0) } {
channel.set_mode(ChannelMode::BlockIfFull);
writeln!(channel, "{info}").ok();
}
panic_persist::report_panic_info(info);
asm::udf();
}
#[cortex_m_rt::exception]
unsafe fn HardFault(ef: &cortex_m_rt::ExceptionFrame) -> ! {
panic!("HardFault at {:#?}", ef);
}
#[cortex_m_rt::exception]
unsafe fn DefaultHandler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}