Testing
This commit is contained in:
parent
bafeb3803a
commit
9d683b8850
@ -2,8 +2,8 @@
|
||||
#![no_main]
|
||||
|
||||
use core::convert::Infallible;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_hal::digital::v2::*;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
use smart_leds::{SmartLedsWrite, RGB8};
|
||||
@ -25,7 +25,6 @@ use waveshare_rp2040_zero::{
|
||||
};
|
||||
use ws2812_pio::Ws2812;
|
||||
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let mut pac = pac::Peripherals::take().unwrap();
|
||||
@ -85,22 +84,26 @@ fn main() -> ! {
|
||||
timer.count_down(),
|
||||
);
|
||||
|
||||
let keys: &[&dyn InputPin<Error = core::convert::Infallible>] = &[
|
||||
let matrix_rows: &[&dyn InputPin<Error = core::convert::Infallible>] = &[
|
||||
&pins.gp0.into_pull_up_input(),
|
||||
&pins.gp1.into_pull_up_input(),
|
||||
&pins.gp2.into_pull_up_input(),
|
||||
&pins.gp3.into_pull_up_input(),
|
||||
&pins.gp4.into_readable_output(),
|
||||
&pins.gp5.into_readable_output(),
|
||||
&pins.gp6.into_readable_output(),
|
||||
&pins.gp7.into_readable_output(),
|
||||
&pins.gp8.into_readable_output(),
|
||||
&pins.gp9.into_readable_output(),
|
||||
&pins.gp10.into_readable_output(),
|
||||
&pins.gp11.into_readable_output(),
|
||||
&pins.gp12.into_readable_output(),
|
||||
&pins.gp13.into_readable_output(),
|
||||
&pins.gp14.into_readable_output(),
|
||||
];
|
||||
|
||||
let matrix_cols: &[&dyn OutputPin<Error = core::convert::Infallible>] = &[
|
||||
&pins.gp4.into_push_pull_output(),
|
||||
&pins.gp5.into_push_pull_output(),
|
||||
&pins.gp6.into_push_pull_output(),
|
||||
&pins.gp7.into_push_pull_output(),
|
||||
&pins.gp8.into_push_pull_output(),
|
||||
&pins.gp9.into_push_pull_output(),
|
||||
&pins.gp10.into_push_pull_output(),
|
||||
&pins.gp11.into_push_pull_output(),
|
||||
&pins.gp12.into_push_pull_output(),
|
||||
&pins.gp13.into_push_pull_output(),
|
||||
&pins.gp14.into_push_pull_output(),
|
||||
&pins.gp15.into_push_pull_output(),
|
||||
];
|
||||
|
||||
let mut input_count_down = timer.count_down();
|
||||
@ -111,22 +114,19 @@ fn main() -> ! {
|
||||
|
||||
let color_purple: RGB8 = (0, 10, 10).into();
|
||||
let color_red: RGB8 = (0, 10, 0).into();
|
||||
let color_green: RGB8 = (10, 0, 0).into();
|
||||
let color_blue: RGB8 = (0, 0, 10).into();
|
||||
// let color_green: RGB8 = (10, 0, 0).into();
|
||||
// let color_blue: RGB8 = (0, 0, 10).into();
|
||||
let color_none: RGB8 = (0, 0, 0).into();
|
||||
|
||||
// Infinite colour wheel loop
|
||||
loop {
|
||||
// ws.write([color_purple].iter().copied()).unwrap();
|
||||
|
||||
if input_count_down.wait().is_ok() {
|
||||
let keys = get_keys(keys);
|
||||
|
||||
match keyboard.device().write_report(keys) {
|
||||
match keyboard.device().write_report([Keyboard::NoEventIndicated; 12]) {
|
||||
Err(UsbHidError::WouldBlock) => {}
|
||||
Err(UsbHidError::Duplicate) => {}
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
ws.write([color_red].iter().copied()).unwrap();
|
||||
core::panic!("Failed to write keyboard report: {:?}", e)
|
||||
}
|
||||
};
|
||||
@ -138,6 +138,7 @@ fn main() -> ! {
|
||||
Err(UsbHidError::WouldBlock) => {}
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
ws.write([color_red].iter().copied()).unwrap();
|
||||
core::panic!("Failed to process keyboard tick: {:?}", e)
|
||||
}
|
||||
};
|
||||
@ -149,11 +150,12 @@ fn main() -> ! {
|
||||
//do nothing
|
||||
}
|
||||
Err(e) => {
|
||||
ws.write([color_red].iter().copied()).unwrap();
|
||||
core::panic!("Failed to read keyboard report: {:?}", e)
|
||||
}
|
||||
Ok(leds) => {
|
||||
if leds.caps_lock == true {
|
||||
ws.write([color_red].iter().copied()).unwrap();
|
||||
ws.write([color_purple].iter().copied()).unwrap();
|
||||
} else {
|
||||
ws.write([color_none].iter().copied()).unwrap();
|
||||
}
|
||||
@ -162,68 +164,3 @@ fn main() -> ! {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_keys(keys: &[&dyn InputPin<Error = Infallible>]) -> [Keyboard; 12] {
|
||||
[
|
||||
if keys[0].is_low().unwrap() {
|
||||
Keyboard::KeypadNumLockAndClear
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //Numlock
|
||||
if keys[1].is_low().unwrap() {
|
||||
Keyboard::UpArrow
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //Up
|
||||
if keys[2].is_low().unwrap() {
|
||||
Keyboard::F12
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //F12
|
||||
if keys[3].is_low().unwrap() {
|
||||
Keyboard::LeftArrow
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //Left
|
||||
if keys[4].is_low().unwrap() {
|
||||
Keyboard::DownArrow
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //Down
|
||||
if keys[5].is_low().unwrap() {
|
||||
Keyboard::RightArrow
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //Right
|
||||
if keys[6].is_low().unwrap() {
|
||||
Keyboard::A
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //A
|
||||
if keys[7].is_low().unwrap() {
|
||||
Keyboard::B
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //B
|
||||
if keys[8].is_low().unwrap() {
|
||||
Keyboard::C
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //C
|
||||
if keys[9].is_low().unwrap() {
|
||||
Keyboard::LeftControl
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //LCtrl
|
||||
if keys[10].is_low().unwrap() {
|
||||
Keyboard::LeftShift
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //LShift
|
||||
if keys[11].is_low().unwrap() {
|
||||
Keyboard::ReturnEnter
|
||||
} else {
|
||||
Keyboard::NoEventIndicated
|
||||
}, //Enter
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user