From 11d6f3b9eb8c9e7e6133f780956d969b71c4e610 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 22 Feb 2024 01:59:25 +0100 Subject: [PATCH] OOch --- .cargo/config.toml | 4 +- src/main.rs | 307 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 304 insertions(+), 7 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 377fbe9..69c44f7 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,8 +1,8 @@ [unstable] # enabling these breaks the float tests during linking, with intrinsics # duplicated between embassy-rp and compilter_builtins -#build-std = ["core"] -#build-std-features = ["panic_immediate_abort"] +# build-std = ["core"] +# build-std-features = ["panic_immediate_abort"] [target.'cfg(all(target_arch = "arm", target_os = "none"))'] runner = "elf2uf2-rs -d" diff --git a/src/main.rs b/src/main.rs index 6d6be88..91a4ca5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #![no_std] #![no_main] -use core::sync::atomic::{AtomicBool, Ordering}; +use core::sync::atomic::{AtomicBool, AtomicU32, Ordering}; // use embassy_sync::blocking_mutex::Mutex as BlockingMutex; @@ -23,6 +23,290 @@ bind_interrupts!(struct Irqs { USBCTRL_IRQ => InterruptHandler; }); +static KEYMASK: AtomicU32 = AtomicU32::new(0); +#[repr(u32)] +enum Keyboard { + A1 = 0b1, + A2 = 0b10, + A3 = 0b100, + A4 = 0b1000, + B1 = 0b10000, + B2 = 0b100000, + B3 = 0b1000000, + B4 = 0b10000000, + C1 = 0b100000000, + C2 = 0b1000000000, + C3 = 0b10000000000, + C4 = 0b100000000000, +} +#[repr(u32)] +enum KeyboardMask { + A1 = 0b0, + A2 = 0b01, + A3 = 0b011, + A4 = 0b0111, + B1 = 0b01111, + B2 = 0b011111, + B3 = 0b0111111, + B4 = 0b01111111, + C1 = 0b011111111, + C2 = 0b0111111111, + C3 = 0b01111111111, + C4 = 0b011111111111, +} +#[repr(u8)] +pub enum KeyCode { + /// The "no" key, a placeholder to express nothing. + No = 0x00, + /// Error if too much keys are pressed at the same time. + ErrorRollOver, + /// The POST fail error. + PostFail, + /// An undefined error occured. + ErrorUndefined, + /// `a` and `A`. + A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, // 0x10 + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z, + /// `1` and `!`. + Kb1, + /// `2` and `@`. + Kb2, + /// `3` and `#`. + Kb3, // 0x20 + /// `4` and `$`. + Kb4, + /// `5` and `%`. + Kb5, + /// `6` and `^`. + Kb6, + /// `7` and `&`. + Kb7, + /// `8` and `*`. + Kb8, + /// `9` and `(`. + Kb9, + /// `0` and `)`. + Kb0, + Enter, + Escape, + BSpace, + Tab, + Space, + /// `-` and `_`. + Minus, + /// `=` and `+`. + Equal, + /// `[` and `{`. + LBracket, + /// `]` and `}`. + RBracket, // 0x30 + /// `\` and `|`. + Bslash, + /// Non-US `#` and `~` (Typically near the Enter key). + NonUsHash, + /// `;` and `:`. + SColon, + /// `'` and `"`. + Quote, + // How to have ` as code? + /// \` and `~`. + Grave, + /// `,` and `<`. + Comma, + /// `.` and `>`. + Dot, + /// `/` and `?`. + Slash, + CapsLock, + F1, + F2, + F3, + F4, + F5, + F6, + F7, // 0x40 + F8, + F9, + F10, + F11, + F12, + PScreen, + ScrollLock, + Pause, + Insert, + Home, + PgUp, + Delete, + End, + PgDown, + Right, + Left, // 0x50 + Down, + Up, + NumLock, + /// Keypad `/` + KpSlash, + /// Keypad `*` + KpAsterisk, + /// Keypad `-`. + KpMinus, + /// Keypad `+`. + KpPlus, + /// Keypad enter. + KpEnter, + /// Keypad 1. + Kp1, + Kp2, + Kp3, + Kp4, + Kp5, + Kp6, + Kp7, + Kp8, // 0x60 + Kp9, + Kp0, + KpDot, + /// Non-US `\` and `|` (Typically near the Left-Shift key) + NonUsBslash, + Application, // 0x65 + /// not a key, used for errors + Power, + /// Keypad `=`. + KpEqual, + F13, + F14, + F15, + F16, + F17, + F18, + F19, + F20, + F21, // 0x70 + F22, + F23, + F24, + Execute, + Help, + Menu, + Select, + Stop, + Again, + Undo, + Cut, + Copy, + Paste, + Find, + Mute, + VolUp, // 0x80 + VolDown, + /// Deprecated. + LockingCapsLock, + /// Deprecated. + LockingNumLock, + /// Deprecated. + LockingScrollLock, + /// Keypad `,`, also used for the brazilian keypad period (.) key. + KpComma, + /// Used on AS/400 keyboard + KpEqualSign, + Intl1, + Intl2, + Intl3, + Intl4, + Intl5, + Intl6, + Intl7, + Intl8, + Intl9, + Lang1, // 0x90 + Lang2, + Lang3, + Lang4, + Lang5, + Lang6, + Lang7, + Lang8, + Lang9, + AltErase, + SysReq, + Cancel, + Clear, + Prior, + Return, + Separator, + Out, // 0xA0 + Oper, + ClearAgain, + CrSel, + ExSel, + + // According to QMK, 0xA5-0xDF are not usable on modern keyboards + + // Modifiers + /// Left Control. + LCtrl = 0xE0, + /// Left Shift. + LShift, + /// Left Alt. + LAlt, + /// Left GUI (the Windows key). + LGui, + /// Right Control. + RCtrl, + /// Right Shift. + RShift, + /// Right Alt (or Alt Gr). + RAlt, + /// Right GUI (the Windows key). + RGui, // 0xE7 + + // Unofficial + MediaPlayPause = 0xE8, + MediaStopCD, + MediaPreviousSong, + MediaNextSong, + MediaEjectCD, + MediaVolUp, + MediaVolDown, + MediaMute, + MediaWWW, // 0xF0 + MediaBack, + MediaForward, + MediaStop, + MediaFind, + MediaScrollUp, + MediaScrollDown, + MediaEdit, + MediaSleep, + MediaCoffee, + MediaRefresh, + MediaCalc, // 0xFB +} + #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_rp::init(Default::default()); @@ -30,7 +314,7 @@ async fn main(_spawner: Spawner) { let driver = Driver::new(p.USB, Irqs); // Create embassy-usb Config - let mut config = Config::new(0xdada, 0xcafe); + let mut config = Config::new(0x27db, 0x16c0); config.manufacturer = Some("Dan"); config.product = Some("Dandaboard SplitSimple"); config.serial_number = Some("DDB-SSK-0001a"); @@ -86,14 +370,16 @@ async fn main(_spawner: Spawner) { // Do stuff with the class! let in_fut = async { loop { - info!("Waiting for HIGH on pin 16"); + info!("Waiting for HIGH on pin 1"); pin.wait_for_high().await; info!("HIGH DETECTED"); // Create a report with the A key pressed. (no shift modifier) + let a1 = KEYMASK.load(Ordering::Relaxed) & Keyboard::A1 as u32; + KEYMASK.store(a1, Ordering::Relaxed); let report = KeyboardReport { - keycodes: [53, 0, 0, 0, 0, 0], + keycodes: [KeyCode::Kb6 as u8, KeyCode::K as u8, 0, 0, 0, 0], leds: 0, - modifier: 0, + modifier: 1 << (KeyCode::LShift as u8 - KeyCode::LCtrl as u8), reserved: 0, }; // Send the report. @@ -101,6 +387,17 @@ async fn main(_spawner: Spawner) { Ok(()) => {} Err(e) => warn!("Failed to send report: {:?}", e), }; + // let report = KeyboardReport { + // keycodes: [55, 0, 0, 0, 0, 0], + // leds: 0, + // modifier: 0, + // reserved: 0, + // }; + // // Send the report. + // match writer.write_serialize(&report).await { + // Ok(()) => {} + // Err(e) => warn!("Failed to send report: {:?}", e), + // }; pin.wait_for_low().await; info!("LOW DETECTED"); let report = KeyboardReport {