Add all pins and fix pwm timers for Pedestal Box
Signed-off-by: fly <merspieler@alwaysdata.net>
This commit is contained in:
parent
d27d15b255
commit
27cd9a1f2a
1 changed files with 130 additions and 32 deletions
|
@ -18,11 +18,13 @@ use stm32f1xx_hal::{
|
|||
gpio::{Pin, Input, Analog, PullDown, Output, PushPull},
|
||||
pac,
|
||||
prelude::*,
|
||||
timer::{Channel, Tim2NoRemap},
|
||||
timer::{Channel, Tim2NoRemap, Tim2FullRemap},
|
||||
flash::{FlashWriter, FlashSize, SectorSize},
|
||||
usb::{Peripheral, UsbBus},
|
||||
};
|
||||
|
||||
// TODO SPI
|
||||
|
||||
use usb_device::prelude::*;
|
||||
use usbd_human_interface_device::prelude::*;
|
||||
|
||||
|
@ -66,13 +68,59 @@ macro_rules! define_ecam_output_states_col {
|
|||
}
|
||||
|
||||
struct MyPins {
|
||||
pa1: Pin<'A', 1, Analog>,
|
||||
pa2: Pin<'A', 2, Analog>,
|
||||
pb0: Pin<'B', 0, Output<PushPull>>,
|
||||
pb12: Pin<'B', 12, Output<PushPull>>,
|
||||
pc1: Pin<'C', 1, Input<PullDown>>,
|
||||
pc3: Pin<'C', 3, Analog>,
|
||||
pc15: Pin<'C', 15, Input<PullDown>>,
|
||||
// Analog Inputs
|
||||
pa2: Pin<'A', 2, Analog>, // Speed Brake
|
||||
pa3: Pin<'A', 3, Analog>, // Parking Brake
|
||||
pa5: Pin<'A', 5, Analog>, // Flaps
|
||||
pa6: Pin<'A', 6, Analog>, // Gravity Gear Extension
|
||||
pa7: Pin<'A', 7, Analog>, // Flood Light Pedestal
|
||||
pb0: Pin<'B', 0, Analog>, // Upper ECAM Brightness
|
||||
pb1: Pin<'B', 1, Analog>, // Lower ECAM Brightness
|
||||
pc0: Pin<'C', 0, Analog>, // Flood Light MIP
|
||||
pc1: Pin<'C', 1, Analog>, // Integ Light
|
||||
pc2: Pin<'C', 2, Analog>, // Weather Radar Tilt
|
||||
pc3: Pin<'C', 3, Analog>, // Weather Radar Gain
|
||||
|
||||
// Inputs
|
||||
pa0: Pin<'A', 0, Input<PullDown>>, // Rudder Trim Reset
|
||||
pa1: Pin<'A', 1, Input<PullDown>>, // Rudder Trim Left
|
||||
pa4: Pin<'A', 4, Input<PullDown>>, // Spoiler Arm
|
||||
pa8: Pin<'A', 8, Input<PullDown>>, // Switching ATT Captain
|
||||
pa9: Pin<'A', 9, Input<PullDown>>, // Switching AIR Captain
|
||||
pa10: Pin<'A', 10, Input<PullDown>>, // Switching ATT FO
|
||||
// pb4: Pin<'B', 4, Input<PullDown>>, // Weather Radar MAP
|
||||
pb5: Pin<'B', 5, Input<PullDown>>, // Weather Radar PWS
|
||||
pb8: Pin<'B', 8, Input<PullDown>>, // Door Unlock
|
||||
pb9: Pin<'B', 9, Input<PullDown>>, // Door Lock
|
||||
pc4: Pin<'C', 4, Input<PullDown>>, // DFDR
|
||||
pc5: Pin<'C', 5, Input<PullDown>>, // AIDS
|
||||
pc6: Pin<'C', 6, Input<PullDown>>, // Switching EIS Captain
|
||||
pc9: Pin<'C', 9, Input<PullDown>>, // Switching AIR FO
|
||||
pc13: Pin<'C', 13, Input<PullDown>>, // Engine Mode Crank
|
||||
pc14: Pin<'C', 14, Input<PullDown>>, // Engine Mode Start
|
||||
pc15: Pin<'C', 15, Input<PullDown>>, // Rudder Trim Right
|
||||
pd1: Pin<'D', 1, Input<PullDown>>, // Weather Radar System 1
|
||||
pd3: Pin<'D', 3, Input<PullDown>>, // Weather Radar System 2
|
||||
pd4: Pin<'D', 4, Input<PullDown>>, // Weather Radar Multiscan
|
||||
pd5: Pin<'D', 5, Input<PullDown>>, // Weather Radar WX+T
|
||||
pd6: Pin<'D', 6, Input<PullDown>>, // Weather Radar CCS
|
||||
pd7: Pin<'D', 7, Input<PullDown>>, // Weather Radar TURB
|
||||
pd13: Pin<'D', 13, Input<PullDown>>, // Switching ECAM FO
|
||||
pd14: Pin<'D', 14, Input<PullDown>>, // Switching ECAM Captain
|
||||
pd15: Pin<'D', 15, Input<PullDown>>, // Switching EIS FO
|
||||
pe0: Pin<'E', 0, Input<PullDown>>, // Door Video
|
||||
pe5: Pin<'E', 5, Input<PullDown>>, // Engine 1 Master
|
||||
pe6: Pin<'E', 6, Input<PullDown>>, // Engine 2 Master
|
||||
|
||||
// Outputs
|
||||
pb6: Pin<'B', 6, Output<PushPull>>, // Door Fault Light
|
||||
pb7: Pin<'B', 7, Output<PushPull>>, // Door Open Light
|
||||
pe1: Pin<'E', 1, Output<PushPull>>, // Engine 1 Fire
|
||||
pe2: Pin<'E', 2, Output<PushPull>>, // Engine 1 Fault
|
||||
pe3: Pin<'E', 3, Output<PushPull>>, // Engine 2 Fault
|
||||
pe4: Pin<'E', 4, Output<PushPull>>, // Engine 2 Fire
|
||||
|
||||
// TODO ECAM matrix pins
|
||||
}
|
||||
|
||||
#[derive(Pod)]
|
||||
|
@ -138,6 +186,9 @@ fn main() -> ! {
|
|||
.pclk1(24.MHz())
|
||||
.freeze(&mut flash.acr);
|
||||
|
||||
let mut afio = p.AFIO.constrain();
|
||||
let (pa15, pb3, pb4) = afio.mapr.disable_jtag(gpioa.pa15, gpiob.pb3, gpiob.pb4); // To allow us to use pa15 and pb4
|
||||
|
||||
// ====================== USB setup =================
|
||||
assert!(clocks.usbclk_valid());
|
||||
let mut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh);
|
||||
|
@ -158,7 +209,7 @@ fn main() -> ! {
|
|||
let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
|
||||
.manufacturer("FLC Meow")
|
||||
.product("Pedestal box")
|
||||
.serial_number("01189998819991197253")
|
||||
.serial_number("01189998819991197250")
|
||||
.build();
|
||||
|
||||
// ====================== ADC setup =================
|
||||
|
@ -172,30 +223,72 @@ fn main() -> ! {
|
|||
|
||||
// ====================== Pin setup =================
|
||||
let mut io_pins = MyPins {
|
||||
pa1: gpioa.pa1.into_analog(&mut gpioa.crl),
|
||||
// Analog Inputs
|
||||
pa2: gpioa.pa2.into_analog(&mut gpioa.crl),
|
||||
pb0: gpiob.pb0.into_push_pull_output(&mut gpiob.crl),
|
||||
pb12: gpiob.pb12.into_push_pull_output(&mut gpiob.crh),
|
||||
pc1: gpioc.pc1.into_pull_down_input(&mut gpioc.crl),
|
||||
pa3: gpioa.pa3.into_analog(&mut gpioa.crl),
|
||||
pa5: gpioa.pa5.into_analog(&mut gpioa.crl),
|
||||
pa6: gpioa.pa6.into_analog(&mut gpioa.crl),
|
||||
pa7: gpioa.pa7.into_analog(&mut gpioa.crl),
|
||||
pb0: gpiob.pb0.into_analog(&mut gpiob.crl),
|
||||
pb1: gpiob.pb1.into_analog(&mut gpiob.crl),
|
||||
pc0: gpioc.pc0.into_analog(&mut gpioc.crl),
|
||||
pc1: gpioc.pc1.into_analog(&mut gpioc.crl),
|
||||
pc2: gpioc.pc2.into_analog(&mut gpioc.crl),
|
||||
pc3: gpioc.pc3.into_analog(&mut gpioc.crl),
|
||||
|
||||
// Inputs
|
||||
pa0: gpioa.pa0.into_pull_down_input(&mut gpioa.crl),
|
||||
pa1: gpioa.pa1.into_pull_down_input(&mut gpioa.crl),
|
||||
pa4: gpioa.pa4.into_pull_down_input(&mut gpioa.crl),
|
||||
pa8: gpioa.pa8.into_pull_down_input(&mut gpioa.crh),
|
||||
pa9: gpioa.pa9.into_pull_down_input(&mut gpioa.crh),
|
||||
pa10: gpioa.pa10.into_pull_down_input(&mut gpioa.crh),
|
||||
// pb4: gpiob.pb4.into_pull_down_input(&mut gpiob.crl),
|
||||
pb5: gpiob.pb5.into_pull_down_input(&mut gpiob.crl),
|
||||
pb8: gpiob.pb8.into_pull_down_input(&mut gpiob.crh),
|
||||
pb9: gpiob.pb9.into_pull_down_input(&mut gpiob.crh),
|
||||
pc4: gpioc.pc4.into_pull_down_input(&mut gpioc.crl),
|
||||
pc5: gpioc.pc5.into_pull_down_input(&mut gpioc.crl),
|
||||
pc6: gpioc.pc6.into_pull_down_input(&mut gpioc.crl),
|
||||
pc9: gpioc.pc9.into_pull_down_input(&mut gpioc.crh),
|
||||
pc13: gpioc.pc13.into_pull_down_input(&mut gpioc.crh),
|
||||
pc14: gpioc.pc14.into_pull_down_input(&mut gpioc.crh),
|
||||
pc15: gpioc.pc15.into_pull_down_input(&mut gpioc.crh),
|
||||
pd1: gpiod.pd1.into_pull_down_input(&mut gpiod.crl),
|
||||
pd3: gpiod.pd3.into_pull_down_input(&mut gpiod.crl),
|
||||
pd4: gpiod.pd4.into_pull_down_input(&mut gpiod.crl),
|
||||
pd5: gpiod.pd5.into_pull_down_input(&mut gpiod.crl),
|
||||
pd6: gpiod.pd6.into_pull_down_input(&mut gpiod.crl),
|
||||
pd7: gpiod.pd7.into_pull_down_input(&mut gpiod.crl),
|
||||
pd13: gpiod.pd13.into_pull_down_input(&mut gpiod.crh),
|
||||
pd14: gpiod.pd14.into_pull_down_input(&mut gpiod.crh),
|
||||
pd15: gpiod.pd15.into_pull_down_input(&mut gpiod.crh),
|
||||
pe0: gpioe.pe0.into_pull_down_input(&mut gpioe.crl),
|
||||
pe5: gpioe.pe5.into_pull_down_input(&mut gpioe.crl),
|
||||
pe6: gpioe.pe6.into_pull_down_input(&mut gpioe.crl),
|
||||
|
||||
// Outputs
|
||||
pb6: gpiob.pb6.into_push_pull_output(&mut gpiob.crl),
|
||||
pb7: gpiob.pb7.into_push_pull_output(&mut gpiob.crl),
|
||||
pe1: gpioe.pe1.into_push_pull_output(&mut gpioe.crl),
|
||||
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),
|
||||
};
|
||||
|
||||
// let mut last = get_report(&mut io_pins, &mut adc1, &cal);
|
||||
|
||||
// ====================== PWM setup =================
|
||||
let mut afio = p.AFIO.constrain();
|
||||
let c1 = gpioa.pa0.into_alternate_push_pull(&mut gpioa.crl);
|
||||
let mut integ_lt_pwm = p
|
||||
let c1 = pa15.into_alternate_push_pull(&mut gpioa.crh);
|
||||
let c3 = gpiob.pb10.into_alternate_push_pull(&mut gpiob.crh);
|
||||
let (mut integ_lt_pwm, mut rudder_trim_display_pwm) = p
|
||||
.TIM2
|
||||
.pwm_hz::<Tim2NoRemap, _, _>(c1, &mut afio.mapr, 1.kHz(), &clocks);
|
||||
integ_lt_pwm.enable(Channel::C1);
|
||||
//TODO
|
||||
// let c3 = gpiob.pb10.into_alternate_push_pull(&mut gpiob.crh);
|
||||
.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::<Tim2NoRemap, _, _>(c3, &mut afio.mapr, 1.kHz(), &clocks);
|
||||
// rudder_trim_display_pwm.enable(Channel::C3);
|
||||
// .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 ===============
|
||||
|
@ -236,7 +329,7 @@ fn main() -> ! {
|
|||
else {
|
||||
pwm_val = output.integ_lt;
|
||||
}
|
||||
integ_lt_pwm.set_duty(Channel::C1, pwm_val);
|
||||
integ_lt_pwm.set_duty(pwm_val);
|
||||
|
||||
// LED outputs
|
||||
// ECAM
|
||||
|
@ -253,7 +346,7 @@ fn main() -> ! {
|
|||
if output.leds & 0xC00 != 0 { ecam_col[4] = 1; }
|
||||
if output.leds & 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!(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_col!(0, pd9, ecam_row, io_pins); // Col 1
|
||||
|
@ -268,22 +361,24 @@ fn main() -> ! {
|
|||
// define_output_states!(0x8000, pe2, output, io_pins); // ENG 1 FAULT
|
||||
// define_output_states!(0x10000, pe1, output, io_pins); // ENG 1 FIRE
|
||||
// define_output_states!(0x20000, pe3, output, io_pins); // ENG 2 FAULT
|
||||
// define_output_states!(0x40000, pe4, output, io_pins); // ENG 2 FIRE
|
||||
|
||||
// Check generic input field
|
||||
// Calibration bit
|
||||
if output.generic & 0x1 == 0x1 {
|
||||
calibration_active = true;
|
||||
if !calibration_min_done && output.generic & 0x2 == 0x2 {
|
||||
cal.data[0].min = adc1.read(&mut io_pins.pa1).unwrap();
|
||||
cal.data[1].min = adc1.read(&mut io_pins.pa2).unwrap();
|
||||
// TODO all pins
|
||||
cal.data[0].min = adc1.read(&mut io_pins.pa2).unwrap();
|
||||
cal.data[1].min = adc1.read(&mut io_pins.pa3).unwrap();
|
||||
calibration_min_done = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if calibration_active {
|
||||
let mut values: [u16; 2] = [0; 2];
|
||||
values[0] = adc1.read(&mut io_pins.pa1).unwrap();
|
||||
values[1] = adc1.read(&mut io_pins.pa2).unwrap();
|
||||
let mut values: [u16; 11] = [0; 11];
|
||||
values[0] = adc1.read(&mut io_pins.pa2).unwrap();
|
||||
values[1] = adc1.read(&mut io_pins.pa3).unwrap();
|
||||
let mut i = 0;
|
||||
loop {
|
||||
if values[i] > cal.data[i].min {
|
||||
|
@ -300,7 +395,7 @@ fn main() -> ! {
|
|||
}
|
||||
let save_success = save_calibration(&mut flash_writer, &cal);
|
||||
if save_success {
|
||||
integ_lt_pwm.set_duty(Channel::C1, pwm_max);
|
||||
integ_lt_pwm.set_duty(pwm_max);
|
||||
}
|
||||
}
|
||||
calibration_active = false;
|
||||
|
@ -325,8 +420,9 @@ fn calculate_factor(min: u16, max: u16) -> f32 {
|
|||
fn get_report(pins: &mut MyPins, adc1: &mut adc::Adc<pac::ADC1>, cal: &Calibration) -> CustomInputReport {
|
||||
// Read axis
|
||||
let mut values: [u16; 11] = [0; 11];
|
||||
values[0] = adc1.read(&mut pins.pa1).unwrap();
|
||||
values[1] = adc1.read(&mut pins.pc3).unwrap();
|
||||
// TODO all pins
|
||||
values[0] = adc1.read(&mut pins.pa2).unwrap();
|
||||
values[1] = adc1.read(&mut pins.pa3).unwrap();
|
||||
|
||||
// Apply calibration to axis data
|
||||
let mut values_norm: [u16; 11] = [0; 11];
|
||||
|
@ -351,6 +447,8 @@ fn get_report(pins: &mut MyPins, adc1: &mut adc::Adc<pac::ADC1>, cal: &Calibrati
|
|||
let mut buttons: u16 = 0;
|
||||
// if pins.pb0.is_high() { buttons += 0x1; }
|
||||
|
||||
// ECAM Keyboard matrix
|
||||
|
||||
CustomInputReport {
|
||||
report_id: 1,
|
||||
axis: values_norm,
|
||||
|
|
Loading…
Add table
Reference in a new issue