Skip to content

Commit

Permalink
fix(matrix): fix async public trait
Browse files Browse the repository at this point in the history
Signed-off-by: Haobo Gu <[email protected]>
  • Loading branch information
HaoboGu committed Jan 3, 2025
1 parent d3768a3 commit e01373e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions rmk/src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
keyboard::KEY_EVENT_CHANNEL,
CONNECTION_STATE,
};
use core::future::Future;
use defmt::{info, Format};
use embassy_time::{Instant, Timer};
use embedded_hal::digital::{InputPin, OutputPin};
Expand All @@ -20,24 +21,28 @@ pub trait MatrixTrait {
const COL: usize;

Check failure on line 22 in rmk/src/matrix.rs

View workflow job for this annotation

GitHub Actions / binary-size

use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
// Wait for USB or BLE really connected
async fn wait_for_connected(&self) {
while !CONNECTION_STATE.load(core::sync::atomic::Ordering::Acquire) {
embassy_time::Timer::after_millis(100).await;
fn wait_for_connected(&self) -> impl Future<Output = ()> {
async {
while !CONNECTION_STATE.load(core::sync::atomic::Ordering::Acquire) {
embassy_time::Timer::after_millis(100).await;
}
info!("Connected, start scanning matrix");
}

Check failure on line 30 in rmk/src/matrix.rs

View workflow job for this annotation

GitHub Actions / binary-size

use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
info!("Connected, start scanning matrix");
}

// Run the matrix
async fn run(&mut self) {
// We don't check disconnected state because disconnection means the task will be dropped
loop {
self.wait_for_connected().await;
self.scan().await;
fn run(&mut self) -> impl Future<Output = ()> {
async {
// We don't check disconnected state because disconnection means the task will be dropped
loop {
self.wait_for_connected().await;
self.scan().await;

Check failure on line 39 in rmk/src/matrix.rs

View workflow job for this annotation

GitHub Actions / binary-size

use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
}
}
}

// Do matrix scanning, save the result in matrix's key_state field.
async fn scan(&mut self);
fn scan(&mut self) -> impl Future<Output = ()>;

// Read key state at position (row, col)
fn get_key_state(&mut self, row: usize, col: usize) -> KeyState;
Expand All @@ -56,7 +61,7 @@ pub trait MatrixTrait {
}

#[cfg(feature = "async_matrix")]
async fn wait_for_key(&mut self);
fn wait_for_key(&mut self) -> impl Future<Output = ()>;
}

/// KeyState represents the state of a key.
Expand Down

0 comments on commit e01373e

Please sign in to comment.