1
0
forked from M-Labs/kirdy
kirdy-firmware/src/main.rs

87 lines
2.7 KiB
Rust
Raw Normal View History

#![cfg_attr(not(test), no_main)]
#![cfg_attr(not(test), no_std)]
2022-10-20 15:17:43 +08:00
use cortex_m_rt::entry;
2022-10-20 20:57:24 +08:00
use log::info;
2022-10-22 15:49:01 +08:00
use stm32f4xx_hal::pac::{CorePeripherals, Peripherals};
2022-10-20 20:57:24 +08:00
mod device;
2022-10-21 12:05:55 +08:00
mod laser_diode;
mod thermostat;
mod pid;
2022-10-22 21:00:17 +08:00
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};
2022-10-22 21:00:17 +08:00
// 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)))]
2022-10-22 21:00:17 +08:00
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
rprintln!("{}", info);
loop {}
}
// Otherwise use panic halt
#[cfg(all(not(feature = "RTT"), not(test)))]
2022-10-22 21:00:17 +08:00
use panic_halt as _;
2022-10-20 15:17:43 +08:00
#[cfg(not(test))]
2022-10-20 15:17:43 +08:00
#[entry]
fn main() -> ! {
2022-10-22 21:00:17 +08:00
log_setup::init_log();
info!("Kirdy init");
2022-10-22 15:49:01 +08:00
let core_perif = CorePeripherals::take().unwrap();
2022-10-20 20:57:24 +08:00
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);
2022-10-20 20:57:24 +08:00
loop {
wd.feed();
2022-10-20 21:21:01 +08:00
info!("looping");
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()));
2022-10-20 21:21:01 +08:00
sys_timer::sleep(10);
2022-10-20 20:57:24 +08:00
}
2022-10-22 15:49:01 +08:00
}