Fix timer in MCDU firmware

Signed-off-by: fly <merspieler@alwaysdata.net>
This commit is contained in:
fly 2024-09-23 23:18:29 +02:00
parent a5e70075f6
commit deaeebcebb

View file

@ -11,13 +11,15 @@ mod device;
use panic_halt as _;
use nb::block;
use cortex_m::asm::delay;
use cortex_m_rt::entry;
use stm32f1xx_hal::{
gpio::{Pin, Input, PullDown, Output, PushPull},
pac,
prelude::*,
// timer::{Channel},
timer::Timer,
usb::{Peripheral, UsbBus},
};
@ -82,6 +84,7 @@ struct MyPins {
fn main() -> ! {
// ====================== general setup =================
// Acquire peripherals
let cp = cortex_m::Peripherals::take().unwrap();
let p = pac::Peripherals::take().unwrap();
let mut flash = p.FLASH.constrain();
let rcc = p.RCC.constrain();
@ -182,31 +185,26 @@ fn main() -> ! {
pc14: gpioc.pc14.into_push_pull_output(&mut gpioc.crh), // FM1
};
// let mut last = get_report(&mut io_pins);
// ====================== Timer setup ===============
// let timer = Instant;
// let mut last_report_sent = timer.elapsed();
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
timer.start(1.kHz()).unwrap();
// ====================== Main loop =================
loop {
block!(timer.wait()).unwrap();
let report = get_report(&mut io_pins);
// TODO figure out timer and only send in like 1ms intervals or on change
// if report != last {
match consumer.device().write_report(&report) {
Err(UsbHidError::WouldBlock) => {}
Err(UsbHidError::UsbError(usb_device::UsbError::BufferOverflow)) => {
core::panic!("Failed to write consumer report, report is too big")
}
Ok(_) => {
// last = report;
}
Err(e) => {
io_pins.pa10.set_high(); // set as indicator that this has happened
core::panic!("Failed to write consumer report: {:?}", e)
}
match consumer.device().write_report(&report) {
Err(UsbHidError::WouldBlock) => {}
Err(UsbHidError::UsbError(usb_device::UsbError::BufferOverflow)) => {
core::panic!("Failed to write consumer report, report is too big")
}
// }
Ok(_) => {
}
Err(e) => {
io_pins.pa10.set_high(); // set as indicator that this has happened
core::panic!("Failed to write consumer report: {:?}", e)
}
}
if usb_dev.poll(&mut [&mut consumer]) {
match consumer.device().read_report() {