kirdy/src/main.rs

87 lines
2.8 KiB
Rust

#![cfg_attr(not(test), no_main)]
#![cfg_attr(not(test), no_std)]
use cortex_m_rt::entry;
use log::info;
use stm32f4xx_hal::pac::{CorePeripherals, Peripherals};
mod device;
mod laser_diode;
mod thermostat;
use device::{boot::bootup, log_setup, sys_timer};
use uom::fmt::DisplayStyle::Abbreviation;
use uom::si::electric_potential::volt;
use uom::si::electric_current::{ampere, milliampere};
use uom::si::power::milliwatt;
use uom::si::f64::{ElectricPotential, ElectricCurrent, Power};
// If RTT is used, print panic info through RTT
#[cfg(all(feature = "RTT", not(test)))]
use {core::panic::PanicInfo, rtt_target::rprintln};
#[cfg(all(feature = "RTT", not(test)))]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
rprintln!("{}", info);
loop {}
}
// Otherwise use panic halt
#[cfg(all(not(feature = "RTT"), not(test)))]
use panic_halt as _;
#[cfg(not(test))]
#[entry]
fn main() -> ! {
log_setup::init_log();
info!("Kirdy init");
let core_perif = CorePeripherals::take().unwrap();
let perif = Peripherals::take().unwrap();
let (mut wd, mut flash_store, mut laser, mut thermostat,) = bootup(core_perif, perif);
let key = "test";
info!("Read the Flash Content Stored");
match flash_store.read(key).unwrap() {
Some(val) => {info!("Flash Valued Read: {:?}", val)}
_ => {info!("Key does not match")}
}
info!("Erasing Flash");
flash_store.erase().unwrap();
match flash_store.read(key).unwrap() {
Some(val) => {info!("Flash Valued Read: {:?}", val)}
_ => {info!("Key does not match")}
}
info!("Writing Flash");
let buf = [1, 2, 3, 4];
flash_store.write(key, &buf).unwrap();
info!("Reading Flash");
match flash_store.read(key).unwrap() {
Some(val) => {info!("Val: {:?}", val)}
_ => {info!("Key does not match")}
};
// https://github.com/iliekturtles/uom/blob/master/examples/si.rs
let volt_fmt = ElectricPotential::format_args(volt, Abbreviation);
let amp_fmt = ElectricCurrent::format_args(ampere, Abbreviation);
let mili_amp_fmt = ElectricCurrent::format_args(milliampere, Abbreviation);
let mili_watt_fmt = Power::format_args(milliwatt, Abbreviation);
loop {
wd.feed();
info!("looping");
info!("curr_ld_power: {:?}", mili_watt_fmt.with(laser.get_ld_power_output()));
info!("curr_ld_drive_cuurent: {:?}", mili_amp_fmt.with(laser.get_ld_drive_current()));
info!("curr_dac_vfb: {:?}", volt_fmt.with(thermostat.get_dac_vfb()));
info!("curr_vref: {:?}", volt_fmt.with(thermostat.get_vref()));
info!("curr_tec_i: {:?}", amp_fmt.with(thermostat.get_tec_i()));
info!("curr_tec_v: {:?}", volt_fmt.with(thermostat.get_tec_v()));
sys_timer::sleep(10);
}
}