summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Pinot <texitoi@texitoi.eu>2020-08-28 10:24:22 +0200
committerGuillaume Pinot <texitoi@texitoi.eu>2020-08-28 10:24:22 +0200
commite69a3af13925467a5ee2e997e8e90a2ea6862d3d (patch)
tree634044c5eb92302572b8123e1a9386232938e957
parentfe2909f2237d56a85154ab64abe020a7d3ba9188 (diff)
Higher priority for RX, better but still losing events
-rw-r--r--firmware/src/main.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/firmware/src/main.rs b/firmware/src/main.rs
index d16eb71..7aae184 100644
--- a/firmware/src/main.rs
+++ b/firmware/src/main.rs
@@ -220,7 +220,7 @@ const APP: () = {
}
}
- #[task(priority = 3, resources = [usb_dev, usb_class])]
+ #[task(priority = 3, capacity = 3, resources = [usb_dev, usb_class])]
fn handle_report(mut c: handle_report::Context, report: KbHidReport) {
if !c
.resources
@@ -241,7 +241,7 @@ const APP: () = {
spawn = [handle_report],
resources = [matrix, debouncer, layout, timer, &transpose, tx],
)]
- fn tick(c: tick::Context) {
+ fn tick(mut c: tick::Context) {
c.resources.timer.wait().ok();
for event in c
@@ -254,27 +254,29 @@ const APP: () = {
block!(c.resources.tx.write(b)).get();
}
c.spawn
- .handle_report(c.resources.layout.event(event).collect())
+ .handle_report(c.resources.layout.lock(|l| l.event(event).collect()))
.unwrap();
}
c.spawn
- .handle_report(c.resources.layout.tick().collect())
+ .handle_report(c.resources.layout.lock(|l| l.tick().collect()))
.unwrap();
}
- #[task(binds = USART1, priority = 1, spawn = [handle_report], resources = [layout, rx])]
- fn rx(mut c: rx::Context) {
+ #[task(binds = USART1, priority = 5, spawn = [handle_report], resources = [layout, rx])]
+ fn rx(c: rx::Context) {
static mut BUF: [u8; 4] = [0; 4];
- while BUF[3] != b'\n' {
- if let Ok(b) = nb::block!(c.resources.rx.read()) {
- BUF.rotate_left(1);
- BUF[3] = b;
- }
+
+ if let Ok(b) = c.resources.rx.read() {
+ BUF.rotate_left(1);
+ BUF[3] = b;
}
- if let Ok(event) = de(&BUF[..]) {
- c.spawn
- .handle_report(c.resources.layout.lock(|l| l.event(event).collect()))
- .unwrap();
+
+ if BUF[3] == b'\n' {
+ if let Ok(event) = de(&BUF[..]) {
+ c.spawn
+ .handle_report(c.resources.layout.event(event).collect())
+ .unwrap();
+ }
}
}