LED Outputs for MCDU
Signed-off-by: fly <merspieler@alwaysdata.net>
This commit is contained in:
parent
f45380aa3c
commit
6449f537fb
2 changed files with 32 additions and 20 deletions
|
@ -1,14 +1,16 @@
|
|||
# MCDU
|
||||
## USB HID
|
||||
### Output
|
||||
One byte output, they match to indications as follows
|
||||
* 0x01: FM
|
||||
* 0x02: FAIL
|
||||
* 0x04: FM2
|
||||
* 0x08: RDY
|
||||
* 0x0F: MENU
|
||||
* 0x10: IND
|
||||
* 0x20: FM1
|
||||
2 Byte output, consisting of
|
||||
* 1 Byte for the reportId (always value 1)
|
||||
* 1 Byte for indicator LEDs, each bit controls one item:
|
||||
* 0x01: FM
|
||||
* 0x02: FAIL
|
||||
* 0x04: FM2
|
||||
* 0x08: RDY
|
||||
* 0x10: MENU
|
||||
* 0x20: IND
|
||||
* 0x40: FM1
|
||||
|
||||
## Display
|
||||
I couldn't find a matching display which fits between all the components on the front so I created a cutout in the PCB and put the display behind the PCB.
|
||||
|
|
|
@ -26,6 +26,17 @@ use usbd_human_interface_device::prelude::*;
|
|||
|
||||
use crate::device::{CustomConfig, CustomInputReport};
|
||||
|
||||
macro_rules! define_output_states {
|
||||
($bit:literal, $pin:ident, $output:ident, $io_pins:ident) => {
|
||||
if $output.leds & $bit == $bit {
|
||||
$io_pins.$pin.set_high();
|
||||
}
|
||||
else {
|
||||
$io_pins.$pin.set_low();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// TODO compiler throws error when initializing pa15 and pb4
|
||||
struct MyPins {
|
||||
// Input Col select
|
||||
|
@ -128,7 +139,7 @@ fn main() -> ! {
|
|||
};
|
||||
|
||||
// ====================== Pin setup =================
|
||||
let mut input_pins = MyPins {
|
||||
let mut io_pins = MyPins {
|
||||
// Inputs Col Select
|
||||
pa4: gpioa.pa4.into_push_pull_output(&mut gpioa.crl),
|
||||
pa5: gpioa.pa5.into_push_pull_output(&mut gpioa.crl),
|
||||
|
@ -169,7 +180,7 @@ fn main() -> ! {
|
|||
pc14: gpioc.pc14.into_push_pull_output(&mut gpioc.crh), // FM1
|
||||
};
|
||||
|
||||
// let mut last = get_report(&mut input_pins);
|
||||
// let mut last = get_report(&mut io_pins);
|
||||
|
||||
// ====================== Timer setup ===============
|
||||
// let timer = Instant;
|
||||
|
@ -177,7 +188,7 @@ fn main() -> ! {
|
|||
|
||||
// ====================== Main loop =================
|
||||
loop {
|
||||
let report = get_report(&mut input_pins);
|
||||
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) {
|
||||
|
@ -189,7 +200,7 @@ fn main() -> ! {
|
|||
// last = report;
|
||||
}
|
||||
Err(e) => {
|
||||
input_pins.pa10.set_high(); // set as indicator that this has happened
|
||||
io_pins.pa10.set_high(); // set as indicator that this has happened
|
||||
core::panic!("Failed to write consumer report: {:?}", e)
|
||||
}
|
||||
}
|
||||
|
@ -200,14 +211,13 @@ fn main() -> ! {
|
|||
Err(UsbHidError::WouldBlock) => {}
|
||||
Ok(output) => {
|
||||
// LED outputs
|
||||
// FM
|
||||
if output.leds & 0x1 == 0x1 {
|
||||
input_pins.pa9.set_high();
|
||||
}
|
||||
else {
|
||||
input_pins.pa9.set_low();
|
||||
}
|
||||
// TODO rest of LEDs
|
||||
define_output_states!(0x1, pa9, output, io_pins); // FM
|
||||
define_output_states!(0x2, pa10, output, io_pins); // FAIL
|
||||
define_output_states!(0x4, pb8, output, io_pins); // FM2
|
||||
define_output_states!(0x8, pb9, output, io_pins); // RDY
|
||||
define_output_states!(0x10, pc12, output, io_pins); // MENU
|
||||
define_output_states!(0x20, pc13, output, io_pins); // IND
|
||||
define_output_states!(0x40, pc14, output, io_pins); // FM1
|
||||
}
|
||||
Err(e) => {
|
||||
core::panic!("Failed to write consumer report: {:?}", e)
|
||||
|
|
Loading…
Add table
Reference in a new issue