Report some buttons
Signed-off-by: fly <merspieler@alwaysdata.com>
This commit is contained in:
parent
55f6b22f7d
commit
aa7b7069d0
1 changed files with 27 additions and 2 deletions
|
@ -15,7 +15,7 @@ use cortex_m::asm::delay;
|
|||
use cortex_m_rt::entry;
|
||||
use stm32f1xx_hal::{
|
||||
adc,
|
||||
gpio::{Analog, Pin},
|
||||
gpio::{Analog, PullDown, Input, Pin},
|
||||
pac,
|
||||
prelude::*,
|
||||
timer::{Channel, Tim2NoRemap},
|
||||
|
@ -35,6 +35,10 @@ const FLASH_LAYOUT_VERSION: u16 = 0;
|
|||
struct MyPins {
|
||||
pa1: Pin<'A', 1, Analog>,
|
||||
pa2: Pin<'A', 2, Analog>,
|
||||
pb0: Pin<'B', 0, Input<PullDown>>,
|
||||
pc1: Pin<'C', 1, Input<PullDown>>,
|
||||
pc3: Pin<'C', 3, Input<PullDown>>,
|
||||
pc15: Pin<'C', 15, Input<PullDown>>,
|
||||
}
|
||||
|
||||
#[derive(Pod)]
|
||||
|
@ -87,6 +91,8 @@ fn main() -> ! {
|
|||
|
||||
// Setup GPIOA
|
||||
let mut gpioa = p.GPIOA.split();
|
||||
let mut gpiob = p.GPIOB.split();
|
||||
let mut gpioc = p.GPIOC.split();
|
||||
|
||||
// configure clock
|
||||
let clocks = rcc
|
||||
|
@ -132,6 +138,10 @@ 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),
|
||||
pc1: gpioc.pc1.into_pull_down_input(&mut gpioc.crl),
|
||||
pc3: gpioc.pc3.into_pull_down_input(&mut gpioc.crl),
|
||||
pc15: gpioc.pc15.into_pull_down_input(&mut gpioc.crh),
|
||||
};
|
||||
|
||||
// let mut last = get_report(&mut input_pins, &mut adc1, &cal);
|
||||
|
@ -236,8 +246,9 @@ fn get_report(pins: &mut MyPins, adc1: &mut adc::Adc<pac::ADC1>, cal: &Calibrati
|
|||
let mut values: [u16; 2] = [0; 2];
|
||||
values[0] = adc1.read(&mut pins.pa1).unwrap();
|
||||
values[1] = adc1.read(&mut pins.pa2).unwrap();
|
||||
let buttons: u16 = 0;
|
||||
let mut buttons: u16 = 0;
|
||||
|
||||
// Axis
|
||||
let mut values_norm: [u16; 2] = [0; 2];
|
||||
let mut i = 0;
|
||||
loop {
|
||||
|
@ -256,6 +267,20 @@ fn get_report(pins: &mut MyPins, adc1: &mut adc::Adc<pac::ADC1>, cal: &Calibrati
|
|||
}
|
||||
}
|
||||
|
||||
// Buttons
|
||||
if pins.pb0.is_high() {
|
||||
buttons += 0x01;
|
||||
}
|
||||
if pins.pc1.is_high() {
|
||||
buttons += 0x02;
|
||||
}
|
||||
if pins.pc3.is_high() {
|
||||
buttons += 0x04;
|
||||
}
|
||||
if pins.pc15.is_high() {
|
||||
buttons += 0x08;
|
||||
}
|
||||
|
||||
CustomInputReport {
|
||||
// report_id: 1,
|
||||
axis: values_norm,
|
||||
|
|
Loading…
Reference in a new issue