Compare commits
No commits in common. "4a301af6aec92a17f53ce8c4fa5664c7347f1482" and "a5e70075f66bd044c2b20b5b44258e3cb035886e" have entirely different histories.
4a301af6ae
...
a5e70075f6
2 changed files with 45 additions and 38 deletions
|
@ -11,15 +11,13 @@ 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::Timer,
|
||||
// timer::{Channel},
|
||||
usb::{Peripheral, UsbBus},
|
||||
};
|
||||
|
||||
|
@ -84,7 +82,6 @@ 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();
|
||||
|
@ -185,26 +182,31 @@ fn main() -> ! {
|
|||
pc14: gpioc.pc14.into_push_pull_output(&mut gpioc.crh), // FM1
|
||||
};
|
||||
|
||||
// let mut last = get_report(&mut io_pins);
|
||||
|
||||
// ====================== Timer setup ===============
|
||||
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
|
||||
timer.start(1.kHz()).unwrap();
|
||||
// let timer = Instant;
|
||||
// let mut last_report_sent = timer.elapsed();
|
||||
|
||||
// ====================== Main loop =================
|
||||
loop {
|
||||
block!(timer.wait()).unwrap();
|
||||
let report = get_report(&mut io_pins);
|
||||
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")
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
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() {
|
||||
|
|
|
@ -11,8 +11,6 @@ mod device;
|
|||
|
||||
use panic_halt as _;
|
||||
|
||||
use nb::block;
|
||||
|
||||
use cortex_m::asm::delay;
|
||||
use cortex_m_rt::entry;
|
||||
use stm32f1xx_hal::{
|
||||
|
@ -20,7 +18,7 @@ use stm32f1xx_hal::{
|
|||
gpio::{Pin, Input, Analog, PullDown, Output, PushPull},
|
||||
pac,
|
||||
prelude::*,
|
||||
timer::{Tim2FullRemap, Timer},
|
||||
timer::{Tim2FullRemap},
|
||||
flash::{FlashWriter, FlashSize, SectorSize},
|
||||
usb::{Peripheral, UsbBus},
|
||||
};
|
||||
|
@ -178,7 +176,6 @@ impl Calibration {
|
|||
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();
|
||||
|
@ -297,6 +294,8 @@ fn main() -> ! {
|
|||
pe13: gpioe.pe13.into_push_pull_output(&mut gpioe.crh),
|
||||
};
|
||||
|
||||
// let mut last = get_report(&mut io_pins, &mut adc1, &cal);
|
||||
|
||||
// ====================== PWM setup =================
|
||||
let c1 = pa15.into_alternate_push_pull(&mut gpioa.crh);
|
||||
let c3 = gpiob.pb10.into_alternate_push_pull(&mut gpiob.crh);
|
||||
|
@ -304,31 +303,37 @@ fn main() -> ! {
|
|||
.TIM2
|
||||
.pwm_hz::<Tim2FullRemap, _, _>((c1, c3), &mut afio.mapr, 1.kHz(), &clocks).split();
|
||||
integ_lt_pwm.enable();
|
||||
// let mut rudder_trim_display_pwm = p
|
||||
// .TIM2
|
||||
// .pwm_hz::<Tim2FullRemap, _, _>(c3, &mut afio.mapr, 1.kHz(), &clocks);
|
||||
rudder_trim_display_pwm.enable();
|
||||
let pwm_max = integ_lt_pwm.get_max_duty(); //48000 in our case
|
||||
|
||||
// ====================== Timer setup ===============
|
||||
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
|
||||
timer.start(1.kHz()).unwrap();
|
||||
// let timer = Instant;
|
||||
// let mut last_report_sent = timer.elapsed();
|
||||
|
||||
// ====================== Main loop =================
|
||||
loop {
|
||||
block!(timer.wait()).unwrap();
|
||||
let report = get_report(&mut io_pins, &mut adc1, &cal);
|
||||
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")
|
||||
// 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) => {
|
||||
// set as indicator that this has happened
|
||||
// io_pins.pe1.set_high();
|
||||
// io_pins.pe4.set_high();
|
||||
core::panic!("Failed to write consumer report: {:?}", e)
|
||||
}
|
||||
}
|
||||
Ok(_) => {
|
||||
}
|
||||
Err(e) => {
|
||||
// set as indicator that this has happened
|
||||
io_pins.pe1.set_high();
|
||||
io_pins.pe4.set_high();
|
||||
core::panic!("Failed to write consumer report: {:?}", e)
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
if usb_dev.poll(&mut [&mut consumer]) {
|
||||
match consumer.device().read_report() {
|
||||
|
|
Loading…
Reference in a new issue