Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyboard support #4

Merged
merged 3 commits into from
Jan 26, 2024
Merged

Add keyboard support #4

merged 3 commits into from
Jan 26, 2024

Conversation

LinusCDE
Copy link
Owner

@LinusCDE LinusCDE commented Jan 20, 2024

Part 1 of solving #2

@Eeems could you test out whether this works on the rM 1? I could test adding and removing keyboards, but broke my flimsy, only Micro-USB-OTG adapter before I could test the new mappings I added:

fn map_evdev_key_to_doom(key: Key) -> Option<u8> {
// https://github.com/ozkl/doomgeneric/blob/613f870b6fa83ede448a247de5a2571092fa729d/doomgeneric/doomkeys.h
Some(match key {
Key::KEY_A => 'a' as u8,
Key::KEY_B => 'b' as u8,
Key::KEY_C => 'c' as u8,
Key::KEY_D => 'd' as u8,
Key::KEY_E => 'e' as u8,
Key::KEY_F => 'f' as u8,
Key::KEY_G => 'g' as u8,
Key::KEY_H => 'h' as u8,
Key::KEY_I => 'i' as u8,
Key::KEY_J => 'j' as u8,
Key::KEY_K => 'k' as u8,
Key::KEY_L => 'l' as u8,
Key::KEY_M => 'm' as u8,
Key::KEY_N => 'n' as u8,
Key::KEY_O => 'o' as u8,
Key::KEY_P => 'p' as u8,
Key::KEY_Q => 'q' as u8,
Key::KEY_R => 'r' as u8,
Key::KEY_S => 's' as u8,
Key::KEY_T => 't' as u8,
Key::KEY_U => 'u' as u8,
Key::KEY_V => 'v' as u8,
Key::KEY_W => 'w' as u8,
Key::KEY_X => 'x' as u8,
Key::KEY_Y => 'y' as u8,
Key::KEY_Z => 'z' as u8,
Key::KEY_0 => '0' as u8,
Key::KEY_1 => '1' as u8,
Key::KEY_2 => '2' as u8,
Key::KEY_3 => '3' as u8,
Key::KEY_4 => '4' as u8,
Key::KEY_5 => '5' as u8,
Key::KEY_6 => '6' as u8,
Key::KEY_7 => '7' as u8,
Key::KEY_8 => '8' as u8,
Key::KEY_9 => '9' as u8,
Key::KEY_RIGHT => 0xae,
Key::KEY_LEFT => 0xac,
Key::KEY_UP => 0xad,
Key::KEY_DOWN => 0xaf,
Key::KEY_DOT => 0xa0, // Strafe left
Key::KEY_COMMA => 0xa1, // Strafe right
Key::KEY_SPACE => 0xa2, // Use
Key::KEY_LEFTCTRL => 0xa3, // Fire... i think
Key::KEY_ESC => 27,
Key::KEY_ENTER => 13,
Key::KEY_TAB => 9,
Key::KEY_F1 => 0x80 + 0x3b,
Key::KEY_F2 => 0x80 + 0x3c,
Key::KEY_F3 => 0x80 + 0x3d,
Key::KEY_F4 => 0x80 + 0x3e,
Key::KEY_F5 => 0x80 + 0x3f,
Key::KEY_F6 => 0x80 + 0x40,
Key::KEY_F7 => 0x80 + 0x41,
Key::KEY_F8 => 0x80 + 0x42,
Key::KEY_F9 => 0x80 + 0x43,
Key::KEY_F10 => 0x80 + 0x44,
Key::KEY_F11 => 0x80 + 0x57,
Key::KEY_F12 => 0x80 + 0x58,
Key::KEY_BACKSPACE => 0x7f,
Key::KEY_PAUSE => 0xff,
Key::KEY_EQUAL => 0x3d,
Key::KEY_MINUS => 0x2d,
Key::KEY_LEFTSHIFT => 0x80 + 0x36, // Does this have a different key for doom?
Key::KEY_RIGHTSHIFT => 0x80 + 0x36,
Key::KEY_RIGHTCTRL => 0x80 + 0x1d,
Key::KEY_LEFTALT => 0x80 + 0x38u8,
Key::KEY_RIGHTALT => 0x80 + 0x38,
Key::KEY_CAPSLOCK => 0x80 + 0x3a,
Key::KEY_NUMLOCK => 0x80 + 0x45,
Key::KEY_SCROLLLOCK => 0x80 + 0x46,
Key::KEY_PRINT => 0x80 + 0x59, // Is Print == PRINTSCR?
Key::KEY_HOME => 0x80 + 0x47,
Key::KEY_END => 0x80 + 0x4f,
Key::KEY_PAGEUP => 0x80 + 0x49,
Key::KEY_PAGEDOWN => 0x80 + 0x51,
Key::KEY_INSERT => 0x80 + 0x52,
Key::KEY_DELETE => 0x80 + 0x53,
Key::KEY_KP0 => 0,
Key::KEY_KP1 => return map_evdev_key_to_doom(Key::KEY_END),
Key::KEY_KP2 => return map_evdev_key_to_doom(Key::KEY_DOWN),
Key::KEY_KP3 => return map_evdev_key_to_doom(Key::KEY_PAGEDOWN),
Key::KEY_KP4 => return map_evdev_key_to_doom(Key::KEY_LEFT),
Key::KEY_KP5 => '5' as u8,
Key::KEY_KP6 => return map_evdev_key_to_doom(Key::KEY_RIGHT),
Key::KEY_KP7 => return map_evdev_key_to_doom(Key::KEY_HOME),
Key::KEY_KP8 => return map_evdev_key_to_doom(Key::KEY_UP),
Key::KEY_KP9 => return map_evdev_key_to_doom(Key::KEY_PAGEUP),
Key::KEY_KPSLASH => '/' as u8,
Key::KEY_KPPLUS => '+' as u8,
Key::KEY_KPMINUS => '-' as u8,
Key::KEY_KPASTERISK => '*' as u8,
Key::KEY_KPDOT => 0,
Key::KEY_KPENTER => return map_evdev_key_to_doom(Key::KEY_ENTER),
_ => return None,
})
}

Mappings are based on doomkeys.h, with some guesswork based on this wiki article.

I do not have a folio, and plugging a USB-C-OTG Adapter in didn't make the keyboard appear for me like it did on the rM 1.

@LinusCDE
Copy link
Owner Author

Binary based on commit 82a6c47 (using command cross build --target=armv7-unknown-linux-gnueabihf --release): doomarkable.zip

@Eeems
Copy link

Eeems commented Jan 20, 2024

I_Init: Setting up machine state.
[2024-01-20T19:02:26Z INFO  doomarkable::evdev_keyboard] Keyboard at "/dev/input/event3" detected: keyd virtual keyboard
M_Init: Init miscellaneous info.
thread '<unnamed>' panicked at src/main.rs:282:76:
called `Result::unwrap()` on an `Err` value: PoisonError { .. }
R_Init: Init DOOM refresh daemon - ...................
P_Init: Init Playloop state.
S_Init: Setting up sound.
D_CheckNetGame: Checking network game status.
startskill 2  deathmatch: 0  startmap: 1  startepisode: 1
player 1 of 1 (1 nodes)
Emulating the behavior of the 'Doom 1.9' executable.
HU_Init: Setting up heads up display.
ST_Init: Init status bar.
I_InitGraphics: framebuffer: x_res: 640, y_res: 400, x_virtual: 640, y_virtual: 400, bpp: 32
I_InitGraphics: framebuffer: RGBA: 8888, red_off: 16, green_off: 8, blue_off: 0, transp_off: 24
I_InitGraphics: DOOM screen size: w x h: 320 x 200
I_InitGraphics: Auto-scaling factor: 2

This is on my rM2 with keyd running and the folio connected, but after forgetting to run with rm2fb-clien. The app never quits, but never displays. Running with rm2fb-client works as expected. I thought I didn't need to for things built with libremarkable.

On my rM1 it opens and runs fine, but I'm not setup for a fake keyboard unfortunately, so I can't really test that side of the functionality. I'm sure it'll work though if it's working with keyd on the rM2.

@LinusCDE
Copy link
Owner Author

This is on my rM2 with keyd running and the folio connected, but after forgetting to run with rm2fb-clien. The app never quits, but never displays. Running with rm2fb-client works as expected. I thought I didn't need to for things built with libremarkable.

I think I'm using an older version of libremarkable here, which didn't include the integrated swtfb client. I created an issue to update it.

@LinusCDE
Copy link
Owner Author

LinusCDE commented Jan 20, 2024

On my rM1 it opens and runs fine, but I'm not setup for a fake keyboard unfortunately, so I can't really test that side of the functionality. I'm sure it'll work though if it's working with keyd on the rM2.

Sounds good. I don't expect things like A-Z not to work. But maybe some edge-cases like certain symbols. Some might be missing, but some might also be wrongly mapped. Especially in regards to the keys for the doom controls not being where expected.

When running doomarkable with RUST_LOG=debug (or better something like RUST_LOG=debug:evdev_keyboard,info to filter out the frame debug messages) it should show if keys were discarded because no mapping was present.

@LinusCDE
Copy link
Owner Author

I should probably also take a look into keyd. Is that purely a software keyboard or does it require the folio?

@Eeems
Copy link

Eeems commented Jan 20, 2024

I should probably also take a look into keyd. Is that purely a software keyboard or does it require the folio?

Purely software. It requires the uinput module, and then it grabs all keyboard devices and emits its own events based off of what was pressed and it's mappings to a new evdev device created by uinput. uinput also handles things like key repeat automatically.

toltec-dev/toltec#744 Here is a working package you can use.

You should be able to ignore virtual keyboards when checking to see if a physical keyboard is connected by just checking what bus it's on. I haven't implemented that quite yet, but my code in oxide does filter out keyd specifically:
https://github.com/Eeems-Org/oxide/blob/3ed1bad7a028861e586e703a50cc05fce39a6ec5/shared/liboxide/devicesettings.cpp#L226-L296

I also ignore anything with a vendor or product identifier of 0x0000, which most of the build in input has for some reason.

@LinusCDE
Copy link
Owner Author

Got to test it now. Seems solid. Makes one really feel the latency now, but still plays way better than with touch.

@LinusCDE LinusCDE merged commit fd98003 into main Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants