Skip to content

Commit

Permalink
fix(core): fix ghost key on macos
Browse files Browse the repository at this point in the history
Signed-off-by: Haobo Gu <[email protected]>
  • Loading branch information
HaoboGu committed Dec 4, 2024
1 parent 7b7db72 commit 6012345
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rmk/src/ble/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) enum BleCompositeReportType {
(usage_page = KEYBOARD, usage_min = 0xE0, usage_max = 0xE7) = {
#[packed_bits 8] #[item_settings data,variable,absolute] modifier=input;
};
(usage_min = 0x00, usage_max = 0xFF) = {
(logical_min = 0,) = {
#[item_settings constant,variable,absolute] reserved=input;
};
(usage_page = LEDS, usage_min = 0x01, usage_max = 0x05) = {
Expand Down
27 changes: 27 additions & 0 deletions rmk/src/usb/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,33 @@ use usbd_hid::descriptor::{
generator_prelude::*, MediaKeyboardReport, MouseReport, SystemControlReport,
};

/// KeyboardReport describes a report and its companion descriptor that can be
/// used to send keyboard button presses to a host and receive the status of the
/// keyboard LEDs.
#[gen_hid_descriptor(
(collection = APPLICATION, usage_page = GENERIC_DESKTOP, usage = KEYBOARD) = {
(usage_page = KEYBOARD, usage_min = 0xE0, usage_max = 0xE7) = {
#[packed_bits 8] #[item_settings data,variable,absolute] modifier=input;
};
(logical_min = 0,) = {
#[item_settings constant,variable,absolute] reserved=input;
};
(usage_page = LEDS, usage_min = 0x01, usage_max = 0x05) = {
#[packed_bits 5] #[item_settings data,variable,absolute] leds=output;
};
(usage_page = KEYBOARD, usage_min = 0x00, usage_max = 0xDD) = {
#[item_settings data,array,absolute] keycodes=input;
};
}
)]
#[allow(dead_code)]
pub struct KeyboardReport {
pub modifier: u8,
pub reserved: u8,
pub leds: u8,
pub keycodes: [u8; 6],
}

#[gen_hid_descriptor(
(collection = APPLICATION, usage_page = 0xFF60, usage = 0x61) = {
(usage = 0x62, logical_min = 0x0) = {
Expand Down
6 changes: 3 additions & 3 deletions rmk/src/usb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use embassy_usb::{
driver::Driver,
Builder, Handler, UsbDevice,
};
use crate::config::KeyboardUsbConfig;
use static_cell::StaticCell;
use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor};
use usbd_hid::descriptor::SerializedDescriptor;

use crate::{
config::KeyboardUsbConfig,
hid::{UsbHidReader, UsbHidReaderWriter, UsbHidWriter},
usb::descriptor::{CompositeReport, ViaReport},
};
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<D: Driver<'static>> KeyboardUsbDevice<'static, D> {
// Initialize two hid interfaces: keyboard & via
static keyboard_request_handler: StaticCell<UsbRequestHandler> = StaticCell::new();
let keyboard_hid_config = Config {
report_descriptor: KeyboardReport::desc(),
report_descriptor: crate::usb::descriptor::KeyboardReport::desc(),
request_handler: Some(keyboard_request_handler.init(UsbRequestHandler {})),
poll_ms: 1,
max_packet_size: 64,
Expand Down

0 comments on commit 6012345

Please sign in to comment.