From 2ad43d73afe0dfef24d358165c7fc4f6001e2384 Mon Sep 17 00:00:00 2001 From: fly Date: Sat, 30 Nov 2024 01:01:26 +0100 Subject: [PATCH] Make the ECAM page lights work Signed-off-by: fly --- .../PedestalConnectBox/firmware/src/main.rs | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/Pedestal/PedestalConnectBox/firmware/src/main.rs b/Pedestal/PedestalConnectBox/firmware/src/main.rs index a12a24d..f0f945d 100644 --- a/Pedestal/PedestalConnectBox/firmware/src/main.rs +++ b/Pedestal/PedestalConnectBox/firmware/src/main.rs @@ -17,7 +17,7 @@ use cortex_m::asm::delay; use cortex_m_rt::entry; use stm32f1xx_hal::{ adc, - gpio::{Pin, Input, Analog, PullDown, Output, PushPull}, + gpio::{Pin, Input, Analog, PullDown, Output, PushPull, Dynamic}, pac, prelude::*, timer::{Tim2FullRemap, Timer}, @@ -48,12 +48,12 @@ macro_rules! define_output_states { } macro_rules! define_ecam_output_states_row { - ($index:literal, $pin:ident, $ecam_row:ident, $io_pins:ident) => { + ($index:literal, $pin:ident, $ecam_row:ident, $io_pins:ident, &mut $cr_base:ident, &mut $cr_part:ident) => { if $ecam_row[$index] == 1 { - $io_pins.$pin.set_high(); + $io_pins.$pin.make_push_pull_output(&mut $cr_base.$cr_part); } else { - $io_pins.$pin.set_low(); + $io_pins.$pin.make_pull_down_input(&mut $cr_base.$cr_part); } }; } @@ -118,7 +118,6 @@ struct MyPins { pb6: Pin<'B', 6, Output>, // Door Fault Light pb7: Pin<'B', 7, Output>, // Door Open Light pb11: Pin<'B', 11, Output>, // ECAM LEDs Column 6 - pb12: Pin<'B', 12, Output>, // ECAM LEDs Row 1 pc7: Pin<'C', 7, Output>, // ECAM LEDs Column 2 pc8: Pin<'C', 8, Output>, // ECAM LEDs Column 3 pd8: Pin<'D', 8, Output>, // ECAM LEDs Column 5 @@ -128,8 +127,11 @@ struct MyPins { pe2: Pin<'E', 2, Output>, // Engine 1 Fault pe3: Pin<'E', 3, Output>, // Engine 2 Fault pe4: Pin<'E', 4, Output>, // Engine 2 Fire - pe9: Pin<'E', 9, Output>, // ECAM LEDs Row 3 - pe13: Pin<'E', 13, Output>, // ECAM LEDs Row 2 + + // ECAM LEDs row select + pb12: Pin<'B', 12, Dynamic>, // ECAM LEDs Row 1 + pe9: Pin<'E', 9, Dynamic>, // ECAM LEDs Row 3 + pe13: Pin<'E', 13, Dynamic>, // ECAM LEDs Row 2 // ECAM matrix read row pe12: Pin<'E', 12, Input>, // ECAM Keys Row 1 @@ -296,7 +298,6 @@ fn main() -> ! { pb6: gpiob.pb6.into_push_pull_output(&mut gpiob.crl), pb7: gpiob.pb7.into_push_pull_output(&mut gpiob.crl), pb11: gpiob.pb11.into_push_pull_output(&mut gpiob.crh), - pb12: gpiob.pb12.into_push_pull_output(&mut gpiob.crh), pc7: gpioc.pc7.into_push_pull_output(&mut gpioc.crl), pc8: gpioc.pc8.into_push_pull_output(&mut gpioc.crh), pd8: gpiod.pd8.into_push_pull_output(&mut gpiod.crh), @@ -306,8 +307,11 @@ fn main() -> ! { pe2: gpioe.pe2.into_push_pull_output(&mut gpioe.crl), pe3: gpioe.pe3.into_push_pull_output(&mut gpioe.crl), pe4: gpioe.pe4.into_push_pull_output(&mut gpioe.crl), - pe9: gpioe.pe9.into_push_pull_output(&mut gpioe.crh), - pe13: gpioe.pe13.into_push_pull_output(&mut gpioe.crh), + + // ECAM LEDs row select + pb12: gpiob.pb12.into_dynamic(&mut gpiob.crh), + pe9: gpioe.pe9.into_dynamic(&mut gpioe.crh), + pe13: gpioe.pe13.into_dynamic(&mut gpioe.crh), // ECAM matrix read row pe12: gpioe.pe12.into_pull_down_input(&mut gpioe.crh), @@ -494,8 +498,8 @@ fn main() -> ! { let mut ecam_row = [0; 3]; let mut ecam_col = [0; 6]; // Match row and col - if output.leds_ecam & 0x54A != 0 { ecam_row[0] = 1; } - if output.leds_ecam & 0x1A94 != 0 { ecam_row[1] = 1; } + if output.leds_ecam & 0x1A94 != 0 { ecam_row[0] = 1; } + if output.leds_ecam & 0x54A != 0 { ecam_row[1] = 1; } if output.leds_ecam & 0x21 != 0 { ecam_row[2] = 1; } if output.leds_ecam & 0x6 != 0 { ecam_col[0] = 1; } if output.leds_ecam & 0x18 != 0 { ecam_col[1] = 1; } @@ -504,9 +508,9 @@ fn main() -> ! { if output.leds_ecam & 0xC00 != 0 { ecam_col[4] = 1; } if output.leds_ecam & 0x1001 != 0 { ecam_col[5] = 1; } // Set ECAM Out - define_ecam_output_states_row!(0, pb12, ecam_row, io_pins); // Row 1 - define_ecam_output_states_row!(1, pe13, ecam_row, io_pins); // Row 2 - define_ecam_output_states_row!(2, pe9, ecam_row, io_pins); // Row 3 + define_ecam_output_states_row!(0, pb12, ecam_row, io_pins, &mut gpiob, &mut crh); // Row 1 + define_ecam_output_states_row!(1, pe13, ecam_row, io_pins, &mut gpioe, &mut crh); // Row 2 + define_ecam_output_states_row!(2, pe9, ecam_row, io_pins, &mut gpioe, &mut crh); // Row 3 define_ecam_output_states_col!(0, pd9, ecam_col, io_pins); // Col 1 define_ecam_output_states_col!(1, pc7, ecam_col, io_pins); // Col 2 define_ecam_output_states_col!(2, pc8, ecam_col, io_pins); // Col 3