From 4a3597ca44495a127d34f84f0766fe360d44003e Mon Sep 17 00:00:00 2001 From: Haobo Gu Date: Thu, 26 Dec 2024 21:42:51 +0800 Subject: [PATCH] feat(core): add mouse event Signed-off-by: Haobo Gu --- rmk/src/direct_pin.rs | 2 +- rmk/src/event.rs | 20 ++++++++++++++++++++ rmk/src/input_device/rotary_encoder.rs | 3 ++- rmk/src/keyboard.rs | 19 ++++--------------- rmk/src/keymap.rs | 2 +- rmk/src/lib.rs | 1 + rmk/src/matrix.rs | 4 +--- rmk/src/split/central.rs | 3 ++- rmk/src/split/driver.rs | 2 +- rmk/src/split/mod.rs | 2 +- 10 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 rmk/src/event.rs diff --git a/rmk/src/direct_pin.rs b/rmk/src/direct_pin.rs index 3bd0df32..04423785 100644 --- a/rmk/src/direct_pin.rs +++ b/rmk/src/direct_pin.rs @@ -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; diff --git a/rmk/src/event.rs b/rmk/src/event.rs new file mode 100644 index 00000000..857602cc --- /dev/null +++ b/rmk/src/event.rs @@ -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 +} diff --git a/rmk/src/input_device/rotary_encoder.rs b/rmk/src/input_device/rotary_encoder.rs index 89a2aa07..d5cd5490 100644 --- a/rmk/src/input_device/rotary_encoder.rs +++ b/rmk/src/input_device/rotary_encoder.rs @@ -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; diff --git a/rmk/src/keyboard.rs b/rmk/src/keyboard.rs index bd227da9..c50fa2a0 100644 --- a/rmk/src/keyboard.rs +++ b/rmk/src/keyboard.rs @@ -1,4 +1,5 @@ use crate::config::BehaviorConfig; +use crate::event::KeyEvent; use crate::CONNECTION_STATE; use crate::{ action::{Action, KeyAction}, @@ -10,7 +11,7 @@ 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, @@ -18,23 +19,11 @@ use embassy_sync::{ }; 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 = + Channel::new(); pub(crate) const REPORT_CHANNEL_SIZE: usize = 32; pub(crate) static KEYBOARD_REPORT_CHANNEL: Channel< diff --git a/rmk/src/keymap.rs b/rmk/src/keymap.rs index b4674eb8..c5bcf84c 100644 --- a/rmk/src/keymap.rs +++ b/rmk/src/keymap.rs @@ -1,6 +1,6 @@ use crate::{ action::KeyAction, - keyboard::KeyEvent, + event::KeyEvent, keyboard_macro::{MacroOperation, MACRO_SPACE_SIZE}, keycode::KeyCode, reboot_keyboard, diff --git a/rmk/src/lib.rs b/rmk/src/lib.rs index cdf446f5..2198c638 100644 --- a/rmk/src/lib.rs +++ b/rmk/src/lib.rs @@ -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; diff --git a/rmk/src/matrix.rs b/rmk/src/matrix.rs index bdf28c1b..0df62da7 100644 --- a/rmk/src/matrix.rs +++ b/rmk/src/matrix.rs @@ -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}; diff --git a/rmk/src/split/central.rs b/rmk/src/split/central.rs index 1dfe9dab..17eb53f5 100644 --- a/rmk/src/split/central.rs +++ b/rmk/src/split/central.rs @@ -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}; diff --git a/rmk/src/split/driver.rs b/rmk/src/split/driver.rs index e3556c0f..a47652c8 100644 --- a/rmk/src/split/driver.rs +++ b/rmk/src/split/driver.rs @@ -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; diff --git a/rmk/src/split/mod.rs b/rmk/src/split/mod.rs index 0396807a..c758200f 100644 --- a/rmk/src/split/mod.rs +++ b/rmk/src/split/mod.rs @@ -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