Map most IO pins in Pedestal Box firmware
Signed-off-by: fly <merspieler@alwaysdata.net>
This commit is contained in:
parent
27cd9a1f2a
commit
a481513470
3 changed files with 106 additions and 30 deletions
|
@ -51,7 +51,7 @@ usage = ['Generic Desktop', 'Z']
|
|||
logicalValueRange = [0, 65535]
|
||||
|
||||
[[applicationCollection.inputReport.variableItem]]
|
||||
usageRange = ['Button', 'Button 1', 'Button 16']
|
||||
usageRange = ['Button', 'Button 1', 'Button 32']
|
||||
logicalValueRange = [0, 1]
|
||||
|
||||
[[applicationCollection.outputReport]]
|
||||
|
@ -60,6 +60,10 @@ logicalValueRange = [0, 1]
|
|||
usage = ['Haptics', 'Manual Trigger']
|
||||
logicalValueRange = [0, 48000]
|
||||
|
||||
[[applicationCollection.outputReport.variableItem]]
|
||||
usage = ['Haptics', 'Manual Trigger']
|
||||
logicalValueRange = [0, 48000]
|
||||
|
||||
[[applicationCollection.outputReport.variableItem]]
|
||||
usage = ['Haptics', 'Manual Trigger']
|
||||
logicalValueRange = [0, 65535]
|
||||
|
|
|
@ -41,7 +41,7 @@ pub const CUSTOM_DESCRIPTOR: &[u8] = &[
|
|||
0xC0, // EndCollection()
|
||||
0x05, 0x09, // UsagePage(Button[0x0009])
|
||||
0x19, 0x01, // UsageIdMin(Button 1[0x0001])
|
||||
0x29, 0x10, // UsageIdMax(Button 16[0x0010])
|
||||
0x29, 0x20, // UsageIdMax(Button 32[0x0020])
|
||||
0x25, 0x01, // LogicalMaximum(1)
|
||||
0x95, 0x10, // ReportCount(16)
|
||||
0x75, 0x01, // ReportSize(1)
|
||||
|
@ -49,7 +49,7 @@ pub const CUSTOM_DESCRIPTOR: &[u8] = &[
|
|||
0x05, 0x0E, // UsagePage(Haptics[0x000E])
|
||||
0x09, 0x21, // UsageId(Manual Trigger[0x0021])
|
||||
0x27, 0x80, 0xBB, 0x00, 0x00, // LogicalMaximum(48,000)
|
||||
0x95, 0x01, // ReportCount(1)
|
||||
0x95, 0x02, // ReportCount(2)
|
||||
0x75, 0x10, // ReportSize(16)
|
||||
0x91, 0x02, // Output(Data, Variable, Absolute, NoWrap, Linear, PreferredState, NoNullPosition, NonVolatile, BitField)
|
||||
0x09, 0x21, // UsageId(Manual Trigger[0x0021])
|
||||
|
@ -62,23 +62,24 @@ pub const CUSTOM_DESCRIPTOR: &[u8] = &[
|
|||
];
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Default, PackedStruct)]
|
||||
#[packed_struct(endian = "lsb", size_bytes = "25")] // MUST be <= 64 else we get problem cause InBytes64 or OutBytes64
|
||||
#[packed_struct(endian = "lsb", size_bytes = "27")] // MUST be <= 64 else we get problem cause InBytes64 or OutBytes64
|
||||
pub struct CustomInputReport {
|
||||
#[packed_field]
|
||||
pub report_id: u8,
|
||||
#[packed_field]
|
||||
pub axis: [u16; 11],
|
||||
#[packed_field]
|
||||
pub buttons: u16,
|
||||
pub buttons: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Default, PackedStruct)]
|
||||
#[packed_struct(endian = "lsb", size_bytes = "9")]
|
||||
#[packed_struct(endian = "lsb", size_bytes = "11")]
|
||||
pub struct CustomOutputReport {
|
||||
#[packed_field]
|
||||
pub report_id: u8,
|
||||
#[packed_field]
|
||||
pub integ_lt: u16,
|
||||
pub rudder_trim_brightness: u16,
|
||||
pub generic: u16,
|
||||
pub leds: u32,
|
||||
}
|
||||
|
@ -97,7 +98,7 @@ impl<'a, B: UsbBus> CustomDevice<'a, B> {
|
|||
}
|
||||
|
||||
pub fn read_report(&mut self) -> Result<CustomOutputReport, UsbHidError> {
|
||||
let mut data = [0; 9];
|
||||
let mut data = [0; 11];
|
||||
self.interface
|
||||
.read_report(&mut data[..])
|
||||
.map(|_| CustomOutputReport::unpack(&data).unwrap())
|
||||
|
|
|
@ -18,7 +18,7 @@ use stm32f1xx_hal::{
|
|||
gpio::{Pin, Input, Analog, PullDown, Output, PushPull},
|
||||
pac,
|
||||
prelude::*,
|
||||
timer::{Channel, Tim2NoRemap, Tim2FullRemap},
|
||||
timer::{Tim2FullRemap},
|
||||
flash::{FlashWriter, FlashSize, SectorSize},
|
||||
usb::{Peripheral, UsbBus},
|
||||
};
|
||||
|
@ -88,7 +88,7 @@ struct MyPins {
|
|||
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
|
||||
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
|
||||
|
@ -115,10 +115,19 @@ struct MyPins {
|
|||
// Outputs
|
||||
pb6: Pin<'B', 6, Output<PushPull>>, // Door Fault Light
|
||||
pb7: Pin<'B', 7, Output<PushPull>>, // Door Open Light
|
||||
pb11: Pin<'B', 11, Output<PushPull>>, // ECAM LEDs Column 6
|
||||
pb12: Pin<'B', 12, Output<PushPull>>, // ECAM LEDs Row 1
|
||||
pc7: Pin<'C', 7, Output<PushPull>>, // ECAM LEDs Column 2
|
||||
pc8: Pin<'C', 8, Output<PushPull>>, // ECAM LEDs Column 3
|
||||
pd8: Pin<'D', 8, Output<PushPull>>, // ECAM LEDs Column 5
|
||||
pd9: Pin<'D', 9, Output<PushPull>>, // ECAM LEDs Column 1
|
||||
pd10: Pin<'D', 10, Output<PushPull>>, // ECAM LEDs Column 4
|
||||
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
|
||||
pe9: Pin<'E', 9, Output<PushPull>>, // ECAM LEDs Row 3
|
||||
pe13: Pin<'E', 13, Output<PushPull>>, // ECAM LEDs Row 2
|
||||
|
||||
// TODO ECAM matrix pins
|
||||
}
|
||||
|
@ -187,7 +196,7 @@ fn main() -> ! {
|
|||
.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
|
||||
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());
|
||||
|
@ -243,7 +252,7 @@ fn main() -> ! {
|
|||
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),
|
||||
pb4: 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),
|
||||
|
@ -270,10 +279,19 @@ fn main() -> ! {
|
|||
// Outputs
|
||||
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),
|
||||
pd9: gpiod.pd9.into_push_pull_output(&mut gpiod.crh),
|
||||
pd10: gpiod.pd10.into_push_pull_output(&mut gpiod.crh),
|
||||
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),
|
||||
pe9: gpioe.pe9.into_push_pull_output(&mut gpioe.crh),
|
||||
pe13: gpioe.pe13.into_push_pull_output(&mut gpioe.crh),
|
||||
};
|
||||
|
||||
// let mut last = get_report(&mut io_pins, &mut adc1, &cal);
|
||||
|
@ -346,31 +364,39 @@ 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!(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
|
||||
// define_ecam_output_states_col!(1, pc7, ecam_row, io_pins); // Col 2
|
||||
// define_ecam_output_states_col!(2, pc8, ecam_row, io_pins); // Col 3
|
||||
// define_ecam_output_states_col!(3, pd10, ecam_row, io_pins); // Col 4
|
||||
// define_ecam_output_states_col!(4, pd8, ecam_row, io_pins); // Col 5
|
||||
// define_ecam_output_states_col!(5, pb11, ecam_row, io_pins); // Col 6
|
||||
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_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
|
||||
define_ecam_output_states_col!(3, pd10, ecam_col, io_pins); // Col 4
|
||||
define_ecam_output_states_col!(4, pd8, ecam_col, io_pins); // Col 5
|
||||
define_ecam_output_states_col!(5, pb11, ecam_col, io_pins); // Col 6
|
||||
// Other Indicators
|
||||
// define_output_states!(0x2000, pb7, output, io_pins); // DOOR OPEN
|
||||
// define_output_states!(0x4000, pb6, output, io_pins); // DOOR FAULT
|
||||
// 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
|
||||
define_output_states!(0x2000, pb7, output, io_pins); // DOOR OPEN
|
||||
define_output_states!(0x4000, pb6, output, io_pins); // DOOR FAULT
|
||||
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 {
|
||||
// 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();
|
||||
cal.data[2].min = adc1.read(&mut io_pins.pa5).unwrap();
|
||||
cal.data[3].min = adc1.read(&mut io_pins.pa6).unwrap();
|
||||
cal.data[4].min = adc1.read(&mut io_pins.pa7).unwrap();
|
||||
cal.data[5].min = adc1.read(&mut io_pins.pb0).unwrap();
|
||||
cal.data[6].min = adc1.read(&mut io_pins.pb1).unwrap();
|
||||
cal.data[7].min = adc1.read(&mut io_pins.pc0).unwrap();
|
||||
cal.data[8].min = adc1.read(&mut io_pins.pc1).unwrap();
|
||||
cal.data[9].min = adc1.read(&mut io_pins.pc2).unwrap();
|
||||
cal.data[10].min = adc1.read(&mut io_pins.pc3).unwrap();
|
||||
calibration_min_done = true;
|
||||
}
|
||||
}
|
||||
|
@ -379,6 +405,15 @@ fn main() -> ! {
|
|||
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();
|
||||
values[2] = adc1.read(&mut io_pins.pa5).unwrap();
|
||||
values[3] = adc1.read(&mut io_pins.pa6).unwrap();
|
||||
values[4] = adc1.read(&mut io_pins.pa7).unwrap();
|
||||
values[5] = adc1.read(&mut io_pins.pb0).unwrap();
|
||||
values[6] = adc1.read(&mut io_pins.pb1).unwrap();
|
||||
values[7] = adc1.read(&mut io_pins.pc0).unwrap();
|
||||
values[8] = adc1.read(&mut io_pins.pc1).unwrap();
|
||||
values[9] = adc1.read(&mut io_pins.pc2).unwrap();
|
||||
values[10] = adc1.read(&mut io_pins.pc3).unwrap();
|
||||
let mut i = 0;
|
||||
loop {
|
||||
if values[i] > cal.data[i].min {
|
||||
|
@ -420,9 +455,17 @@ 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];
|
||||
// TODO all pins
|
||||
values[0] = adc1.read(&mut pins.pa2).unwrap();
|
||||
values[1] = adc1.read(&mut pins.pa3).unwrap();
|
||||
values[2] = adc1.read(&mut pins.pa5).unwrap();
|
||||
values[3] = adc1.read(&mut pins.pa6).unwrap();
|
||||
values[4] = adc1.read(&mut pins.pa7).unwrap();
|
||||
values[5] = adc1.read(&mut pins.pb0).unwrap();
|
||||
values[6] = adc1.read(&mut pins.pb1).unwrap();
|
||||
values[7] = adc1.read(&mut pins.pc0).unwrap();
|
||||
values[8] = adc1.read(&mut pins.pc1).unwrap();
|
||||
values[9] = adc1.read(&mut pins.pc2).unwrap();
|
||||
values[10] = adc1.read(&mut pins.pc3).unwrap();
|
||||
|
||||
// Apply calibration to axis data
|
||||
let mut values_norm: [u16; 11] = [0; 11];
|
||||
|
@ -444,8 +487,36 @@ fn get_report(pins: &mut MyPins, adc1: &mut adc::Adc<pac::ADC1>, cal: &Calibrati
|
|||
}
|
||||
|
||||
// Buttons
|
||||
let mut buttons: u16 = 0;
|
||||
// if pins.pb0.is_high() { buttons += 0x1; }
|
||||
let mut buttons: u32 = 0;
|
||||
if pins.pa0.is_high() { buttons += 0x1; }
|
||||
if pins.pa1.is_high() { buttons += 0x2; }
|
||||
if pins.pa4.is_high() { buttons += 0x4; }
|
||||
if pins.pa8.is_high() { buttons += 0x8; }
|
||||
if pins.pa9.is_high() { buttons += 0x10; }
|
||||
if pins.pa10.is_high() { buttons += 0x20; }
|
||||
if pins.pb4.is_high() { buttons += 0x40; }
|
||||
if pins.pb5.is_high() { buttons += 0x80; }
|
||||
if pins.pb8.is_high() { buttons += 0x100; }
|
||||
if pins.pb9.is_high() { buttons += 0x200; }
|
||||
if pins.pc4.is_high() { buttons += 0x400; }
|
||||
if pins.pc5.is_high() { buttons += 0x800; }
|
||||
if pins.pc6.is_high() { buttons += 0x1000; }
|
||||
if pins.pc9.is_high() { buttons += 0x0200; }
|
||||
if pins.pc13.is_high() { buttons += 0x4000; }
|
||||
if pins.pc14.is_high() { buttons += 0x8000; }
|
||||
if pins.pc15.is_high() { buttons += 0x10000; }
|
||||
if pins.pd1.is_high() { buttons += 0x20000; }
|
||||
if pins.pd3.is_high() { buttons += 0x40000; }
|
||||
if pins.pd4.is_high() { buttons += 0x80000; }
|
||||
if pins.pd5.is_high() { buttons += 0x100000; }
|
||||
if pins.pd6.is_high() { buttons += 0x200000; }
|
||||
if pins.pd7.is_high() { buttons += 0x400000; }
|
||||
if pins.pd13.is_high() { buttons += 0x800000; }
|
||||
if pins.pd14.is_high() { buttons += 0x1000000; }
|
||||
if pins.pd15.is_high() { buttons += 0x2000000; }
|
||||
if pins.pe0.is_high() { buttons += 0x4000000; }
|
||||
if pins.pe5.is_high() { buttons += 0x8000000; }
|
||||
if pins.pe6.is_high() { buttons += 0x10000000; }
|
||||
|
||||
// ECAM Keyboard matrix
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue