diff --git a/firmware/src/key_scan.rs b/firmware/src/key_scan.rs index d0cadac..2b28c08 100644 --- a/firmware/src/key_scan.rs +++ b/firmware/src/key_scan.rs @@ -6,7 +6,6 @@ use core::{convert::Infallible, ops::Deref}; use cortex_m::delay::Delay; use embedded_hal::digital::InputPin; -use usbd_hid::descriptor::KeyboardReport; use crate::{debounce::Debounce, key_codes::KeyCode}; @@ -49,6 +48,30 @@ impl KeyScan { } } +#[derive(Copy, Clone, PartialEq)] +pub struct KeyboardReport { + pub modifier: u8, + pub reserved: u8, + pub leds: u8, + pub keycodes: [u8; 6], +} + +impl KeyboardReport { + pub fn as_raw_input(&self) -> [u8; 8] { + [ + self.modifier, + 0x0, // Reserved byte + // Keycodes + self.keycodes[0], + self.keycodes[1], + self.keycodes[2], + self.keycodes[3], + self.keycodes[4], + self.keycodes[5], + ] + } +} + impl From> for KeyboardReport { diff --git a/firmware/src/main.rs b/firmware/src/main.rs index 3748f2e..c49c142 100644 --- a/firmware/src/main.rs +++ b/firmware/src/main.rs @@ -4,7 +4,7 @@ #![no_main] #![no_std] -use crate::key_scan::TRANSPOSED_NORMAL_LAYER_MAPPING; +use crate::key_scan::{KeyboardReport, TRANSPOSED_NORMAL_LAYER_MAPPING}; use cortex_m::prelude::_embedded_hal_timer_CountDown; use usb_device::class::UsbClass; mod debounce; @@ -26,11 +26,8 @@ use rp2040_hal::{ Clock, Watchdog, }; use usb_device::{bus::UsbBusAllocator, device::UsbDeviceBuilder, prelude::*}; -use usbd_hid::{ - descriptor::KeyboardReport, - hid_class::{ - HIDClass, HidClassSettings, HidCountryCode, HidProtocol, HidSubClass, ProtocolModeConfig, - }, +use usbd_hid::hid_class::{ + HIDClass, HidClassSettings, HidCountryCode, HidProtocol, HidSubClass, ProtocolModeConfig, }; use debounce::Debounce; @@ -233,7 +230,7 @@ unsafe fn USBCTRL_IRQ() { } let report = critical_section::with(|cs| *KEYBOARD_REPORT.borrow_ref(cs)); - if let Err(err) = usb_hid.push_input(&report) { + if let Err(err) = usb_hid.push_raw_input(&report.as_raw_input()) { match err { UsbError::WouldBlock => warn!("UsbError::WouldBlock"), UsbError::ParseError => error!("UsbError::ParseError"),