Skip to content

Commit

Permalink
feat(core): add mouse event
Browse files Browse the repository at this point in the history
Signed-off-by: Haobo Gu <[email protected]>
  • Loading branch information
HaoboGu committed Dec 26, 2024
1 parent 5a91d3a commit 4a3597c
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion rmk/src/direct_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::debounce::fast_debouncer::RapidDebouncer;
use crate::debounce::DebounceState;
use crate::debounce::DebouncerTrait;
use crate::keyboard::KEY_EVENT_CHANNEL;
use crate::keyboard::KeyEvent;
use crate::event::KeyEvent;
use crate::matrix::KeyState;
use crate::MatrixTrait;
use crate::RmkConfig;
Expand Down
20 changes: 20 additions & 0 deletions rmk/src/event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use defmt::Format;
use postcard::experimental::max_size::MaxSize;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Copy, Debug, Format, MaxSize)]
pub struct KeyEvent {
pub row: u8,
pub col: u8,
pub pressed: bool,
}


#[derive(Serialize, Deserialize, Clone, Copy, Debug, Format, MaxSize)]
pub struct MouseEvent {
pub buttons: u8,
pub x: i8,
pub y: i8,
pub wheel: i8, // Scroll down (negative) or up (positive) this many units
pub pan: i8, // Scroll left (negative) or right (positive) this many units
}
3 changes: 2 additions & 1 deletion rmk/src/input_device/rotary_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use embedded_hal::digital::InputPin;
#[cfg(feature = "async_matrix")]
use embedded_hal_async::digital::Wait;

use crate::keyboard::{KeyEvent, KEY_EVENT_CHANNEL};
use crate::event::KeyEvent;
use crate::keyboard::KEY_EVENT_CHANNEL;

use super::InputDevice;

Expand Down
19 changes: 4 additions & 15 deletions rmk/src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::config::BehaviorConfig;
use crate::event::KeyEvent;
use crate::CONNECTION_STATE;
use crate::{
action::{Action, KeyAction},
Expand All @@ -10,31 +11,19 @@ use crate::{
KEYBOARD_STATE,
};
use core::cell::RefCell;
use defmt::{debug, error, info, warn, Format};
use defmt::{debug, error, info, warn};
use embassy_futures::{select::select, yield_now};
use embassy_sync::{
blocking_mutex::raw::CriticalSectionRawMutex,
channel::{Channel, Receiver, Sender},
};
use embassy_time::{Instant, Timer};
use heapless::{FnvIndexMap, Vec};
use postcard::experimental::max_size::MaxSize;
use serde::{Deserialize, Serialize};
use usbd_hid::descriptor::KeyboardReport;


#[derive(Serialize, Deserialize, Clone, Copy, Debug, Format, MaxSize)]
pub struct KeyEvent {
pub row: u8,
pub col: u8,
pub pressed: bool,
}
pub(crate) const EVENT_CHANNEL_SIZE: usize = 32;
pub static KEY_EVENT_CHANNEL: Channel<
CriticalSectionRawMutex,
KeyEvent,
EVENT_CHANNEL_SIZE,
> = Channel::new();
pub static KEY_EVENT_CHANNEL: Channel<CriticalSectionRawMutex, KeyEvent, EVENT_CHANNEL_SIZE> =
Channel::new();

pub(crate) const REPORT_CHANNEL_SIZE: usize = 32;
pub(crate) static KEYBOARD_REPORT_CHANNEL: Channel<
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/keymap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
action::KeyAction,
keyboard::KeyEvent,
event::KeyEvent,
keyboard_macro::{MacroOperation, MACRO_SPACE_SIZE},
keycode::KeyCode,
reboot_keyboard,
Expand Down
1 change: 1 addition & 0 deletions rmk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ pub mod ble;
pub mod config;
mod debounce;
pub mod direct_pin;
pub mod event;
mod flash;
mod hid;
pub mod input_device;
Expand Down
4 changes: 1 addition & 3 deletions rmk/src/matrix.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::{
debounce::{DebounceState, DebouncerTrait},
keyboard::{KEY_EVENT_CHANNEL, KeyEvent},
CONNECTION_STATE,
debounce::{DebounceState, DebouncerTrait}, event::KeyEvent, keyboard::KEY_EVENT_CHANNEL, CONNECTION_STATE
};
use defmt::{info, Format};
use embassy_time::{Instant, Timer};
Expand Down
3 changes: 2 additions & 1 deletion rmk/src/split/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use crate::debounce::default_bouncer::DefaultDebouncer;
#[cfg(feature = "rapid_debouncer")]
use crate::debounce::fast_debouncer::RapidDebouncer;
use crate::debounce::{DebounceState, DebouncerTrait};
use crate::keyboard::{KEY_EVENT_CHANNEL, KEYBOARD_REPORT_CHANNEL, KeyEvent, Keyboard};
use crate::event::KeyEvent;
use crate::keyboard::{Keyboard, KEYBOARD_REPORT_CHANNEL, KEY_EVENT_CHANNEL};
use crate::keymap::KeyMap;
use crate::light::LightService;
use crate::matrix::{KeyState, MatrixTrait};
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/split/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::sync::atomic::Ordering;
///! The abstracted driver layer of the split keyboard.
///!
use super::SplitMessage;
use crate::keyboard::{KEY_EVENT_CHANNEL, KeyEvent};
use crate::{event::KeyEvent, keyboard::KEY_EVENT_CHANNEL};
use crate::CONNECTION_STATE;
use defmt::{debug, error, warn};
use embassy_futures::select::select;
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/split/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use postcard::experimental::max_size::MaxSize;
use serde::{Deserialize, Serialize};

use crate::keyboard::KeyEvent;
use crate::event::KeyEvent;

pub mod central;
/// Common abstraction layer of split driver
Expand Down

0 comments on commit 4a3597c

Please sign in to comment.