Working LEDs on new PCBs
Signed-off-by: fly <merspieler@alwaysdata.com>
This commit is contained in:
parent
85165ad750
commit
afb5cd3e99
2 changed files with 35 additions and 15 deletions
|
@ -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<CustomOutputReport, UsbHidError> {
|
||||
let mut data = [0; 5];
|
||||
let mut data = [0; 7];
|
||||
self.interface
|
||||
.read_report(&mut data[..])
|
||||
.map(|_| CustomOutputReport::unpack(&data).unwrap())
|
||||
|
|
|
@ -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<PullDown>>,
|
||||
pb0: Pin<'B', 0, Output<PushPull>>,
|
||||
pc1: Pin<'C', 1, Input<PullDown>>,
|
||||
pc3: Pin<'C', 3, Input<PullDown>>,
|
||||
pc3: Pin<'C', 3, Output<PushPull>>,
|
||||
pc15: Pin<'C', 15, Input<PullDown>>,
|
||||
}
|
||||
|
||||
|
@ -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<pac::ADC1>, 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue