summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorMarc Poulhiès <dkm@kataplop.net>2020-12-17 21:36:11 +0100
committerMarc Poulhiès <dkm@kataplop.net>2020-12-17 21:36:11 +0100
commitf26c24e094dcd8634a9333ae0048e0688e799cc1 (patch)
tree9fc03fc9705651ff32e14182710cc2179ca3246c /firmware
parentd4fc554abb32a0cefdb38945d1b5bf7df0153424 (diff)
Update code after keyberon update
Simply port current firmware. No CustomAction yet.
Diffstat (limited to 'firmware')
-rw-r--r--firmware/src/main.rs49
1 files changed, 23 insertions, 26 deletions
diff --git a/firmware/src/main.rs b/firmware/src/main.rs
index b806b3f..fa75e5f 100644
--- a/firmware/src/main.rs
+++ b/firmware/src/main.rs
@@ -29,9 +29,9 @@ use keyberon::debounce::Debouncer;
use keyberon::impl_heterogenous_array;
use keyberon::key_code::KbHidReport;
use keyberon::key_code::KeyCode::*;
+use keyberon::key_code::KeyCode::{self, *};
use keyberon::layout::{Event, Layout};
use keyberon::matrix::{Matrix, PressedKeys};
-
use rtic::app;
use stm32f0xx_hal as hal;
use usb_device::bus::UsbBusAllocator;
@@ -280,41 +280,38 @@ const APP: () = {
}
}
- #[task(priority = 3, capacity = 8, resources = [usb_dev, usb_class, layout])]
- fn handle_event(mut c: handle_event::Context, event: Option<Event>) {
- let report: KbHidReport = match event {
- None => c.resources.layout.tick().collect(),
- Some(e) => c.resources.layout.event(e).collect(),
- };
- if !c
- .resources
- .usb_class
- .lock(|k| k.device_mut().set_keyboard_report(report.clone()))
- {
- return;
- }
- if c.resources.usb_dev.lock(|d| d.state()) != UsbDeviceState::Configured {
- return;
- }
- while let Ok(0) = c.resources.usb_class.lock(|k| k.write(report.as_bytes())) {}
- }
-
#[task(
binds = TIM3,
priority = 2,
- spawn = [handle_event],
- resources = [matrix, debouncer, timer],
+ resources = [matrix, debouncer, timer, layout, usb_class],
)]
- fn tick(c: tick::Context) {
+ fn tick(mut c: tick::Context) {
c.resources.timer.wait().ok();
- for event in c.resources.debouncer.events(c.resources.matrix.get().get()) {
- c.spawn.handle_event(Some(event)).unwrap();
+ for event in c
+ .resources
+ .debouncer
+ .events(c.resources.matrix.get().unwrap())
+ {
+ c.resources.layout.event(event);
}
- c.spawn.handle_event(None).unwrap();
+ match c.resources.layout.tick() {
+ _ => (),
+ }
+
+ c.resources.layout.tick();
+ send_report(c.resources.layout.keycodes(), &mut c.resources.usb_class);
}
extern "C" {
fn CEC_CAN();
}
};
+
+fn send_report(iter: impl Iterator<Item = KeyCode>, usb_class: &mut resources::usb_class<'_>) {
+ use rtic::Mutex;
+ let report: KbHidReport = iter.collect();
+ if usb_class.lock(|k| k.device_mut().set_keyboard_report(report.clone())) {
+ while let Ok(0) = usb_class.lock(|k| k.write(report.as_bytes())) {}
+ }
+}