diff --git a/Pedestal/firmware/src/device.rs b/Pedestal/firmware/src/device.rs index 593b857..02749e7 100644 --- a/Pedestal/firmware/src/device.rs +++ b/Pedestal/firmware/src/device.rs @@ -47,6 +47,9 @@ pub const CUSTOM_DESCRIPTOR: &[u8] = &[ 0x09, 0x21, // UsageId(Manual Trigger[0x0021]) 0x27, 0xFF, 0xFF, 0x00, 0x00, // LogicalMaximum(65,535) 0x91, 0x02, // Output(Data, Variable, Absolute, NoWrap, Linear, PreferredState, NoNullPosition, NonVolatile, BitField) + 0x09, 0x21, // UsageId(Manual Trigger[0x0021]) + 0x27, 0xFF, 0xFF, 0x00, 0x00, // LogicalMaximum(65,535) + 0x91, 0x02, // Output(Data, Variable, Absolute, NoWrap, Linear, PreferredState, NoNullPosition, NonVolatile, BitField) 0xC0, // EndCollection() ]; @@ -62,13 +65,14 @@ pub struct CustomInputReport { } #[derive(Clone, Copy, Debug, Eq, PartialEq, Default, PackedStruct)] -#[packed_struct(endian = "lsb", size_bytes = "5")] +#[packed_struct(endian = "lsb", size_bytes = "7")] pub struct CustomOutputReport { #[packed_field] pub report_id: u8, #[packed_field] pub integ_lt: u16, pub generic: u16, + pub leds: u16, } pub struct CustomDevice<'a, B: UsbBus> { @@ -85,7 +89,7 @@ impl<'a, B: UsbBus> CustomDevice<'a, B> { } pub fn read_report(&mut self) -> Result { - let mut data = [0; 5]; + let mut data = [0; 7]; self.interface .read_report(&mut data[..]) .map(|_| CustomOutputReport::unpack(&data).unwrap()) diff --git a/Pedestal/firmware/src/main.rs b/Pedestal/firmware/src/main.rs index 71d02bf..8b5f5fb 100644 --- a/Pedestal/firmware/src/main.rs +++ b/Pedestal/firmware/src/main.rs @@ -15,7 +15,7 @@ use cortex_m::asm::delay; use cortex_m_rt::entry; use stm32f1xx_hal::{ adc, - gpio::{Analog, PullDown, Input, Pin}, + gpio::{Pin, Input, Analog, PullDown, Output, PushPull}, pac, prelude::*, timer::{Channel, Tim2NoRemap}, @@ -35,9 +35,9 @@ const FLASH_LAYOUT_VERSION: u16 = 0; struct MyPins { pa1: Pin<'A', 1, Analog>, pa2: Pin<'A', 2, Analog>, - pb0: Pin<'B', 0, Input>, + pb0: Pin<'B', 0, Output>, pc1: Pin<'C', 1, Input>, - pc3: Pin<'C', 3, Input>, + pc3: Pin<'C', 3, Output>, pc15: Pin<'C', 15, Input>, } @@ -65,7 +65,7 @@ impl CalibrationData { #[derive(Clone)] #[derive(Zeroable)] struct Calibration { - data: [CalibrationData; 2], + data: [CalibrationData; 3], } impl Calibration { @@ -75,7 +75,7 @@ impl Calibration { }; fn new () -> Calibration { return Calibration { - data: [CalibrationData::new(0, CalibrationData::ADC_MAX); 2], + data: [CalibrationData::new(0, CalibrationData::ADC_MAX); 3], }; } } @@ -138,9 +138,9 @@ fn main() -> ! { let mut input_pins = MyPins { pa1: gpioa.pa1.into_analog(&mut gpioa.crl), pa2: gpioa.pa2.into_analog(&mut gpioa.crl), - pb0: gpiob.pb0.into_pull_down_input(&mut gpiob.crl), + pb0: gpiob.pb0.into_push_pull_output(&mut gpiob.crl), pc1: gpioc.pc1.into_pull_down_input(&mut gpioc.crl), - pc3: gpioc.pc3.into_pull_down_input(&mut gpioc.crl), + pc3: gpioc.pc3.into_push_pull_output(&mut gpioc.crl), pc15: gpioc.pc15.into_pull_down_input(&mut gpioc.crh), }; @@ -170,6 +170,8 @@ fn main() -> ! { // last = report; } Err(e) => { + // TODO use a suitable pin once we know the pinout + input_pins.pb0.set_high(); // set as indicator that this has happened core::panic!("Failed to write consumer report: {:?}", e) } } @@ -189,6 +191,20 @@ fn main() -> ! { } pwm.set_duty(Channel::C1, pwm_val); + // LED outputs + if output.leds & 0x1 == 0x1 { + input_pins.pb0.set_high(); + } + else { + input_pins.pb0.set_low(); + } + if output.leds & 0x2 == 0x2 { + input_pins.pc3.set_high(); + } + else { + input_pins.pc3.set_low(); + } + // Check generic input field // Calibration bit if output.generic & 0x1 == 0x1 { @@ -268,15 +284,15 @@ fn get_report(pins: &mut MyPins, adc1: &mut adc::Adc, cal: &Calibrati } // Buttons - if pins.pb0.is_high() { - buttons += 0x01; - } +// if pins.pb0.is_high() { +// buttons += 0x01; +// } if pins.pc1.is_high() { buttons += 0x02; } - if pins.pc3.is_high() { - buttons += 0x04; - } +// if pins.pc3.is_high() { +// buttons += 0x04; +// } if pins.pc15.is_high() { buttons += 0x08; }