Skip to content

games/NXDoom: Add an option to read the keys from a serial terminal. - #3869

Open
wwlapaki310 wants to merge 2 commits into
apache:masterfrom
wwlapaki310:nxdoom-uartkbd
Open

wwlapaki310 wants to merge 2 commits into
apache:masterfrom
wwlapaki310:nxdoom-uartkbd

Conversation

@wwlapaki310

@wwlapaki310 wwlapaki310 commented Oct 18, 2026 •

Copy link
Copy Markdown

Summary

Add CONFIG_GAMES_NXDOOM_UARTKBD, an option that lets NXDoom read its keys from a serial terminal.

NXDoom reads its keys only from a keyboard character driver, so a board without one cannot play it. Some boards, such as the Spresense, have only a serial console. With the option on, NXDoom reads bytes from the tty named by CONFIG_GAMES_NXDOOM_KBDPATH (for example /dev/console) and turns them into the same keyboard events that the driver path produces:

  • W, A, S, D and the arrow keys move, J fires, K runs, L strafes, E or space uses, and Q or Esc opens the menu.
  • A terminal reports a key press but never its release, so each key is released again 250 ms after its last byte.

The option is off by default. The code is in its own file, i_input_uartkbd.c, which is built only when the option is on, so i_input.c has just one call to it; the dead #if 0 block in i_input.c is removed. The key handling follows translate_speckey() in the same file, and the arrow keys are the usual VT100/xterm sequences. No code was copied from another project. Keeping this in the application was the simplest way; a reusable keyboard driver fed from a tty would be another option, and I can move it there if you prefer.

This is one of three pull requests that let NXDoom run on the Spresense: the nuttx configuration and documentation (apache/nuttx#20774) and the memory improvements, which include the option to disable the screen wipe (#3860, by another author, already merged). The nuttx one shows how they fit together, so it may help to read it first. This pull request is rebased onto #3860 and should be merged before the nuttx one.

Impact

  • Users: new option, off by default. Existing configurations are not affected.
  • Build: none. The code is under #ifdef CONFIG_GAMES_NXDOOM_UARTKBD.
  • Hardware: none.
  • Documentation: in the nuttx pull request above.
  • Compatibility: none.
  • Security: none.

Testing

Result: the game starts on a Spresense and is controlled with keys sent over the serial console. Demo video: https://youtu.be/ikh1EEGco8Q

Host: Windows 11, build in a Docker container (Ubuntu 24.04), arm-none-eabi-gcc 13.2.1.
Board: Spresense main board with the extension board and an ILI9340 display, spresense:nxdoom from the nuttx pull request. To try it before that is merged, use the nxdoom-spresense branch of https://github.com/wwlapaki310/nuttx together with this pull request.

With a one-level IWAD in the flash, the game started and keys sent over the console worked: q opened the menu, Enter started a new game, w and s moved, a and d turned, j fired and e used. This was checked on the display.

nsh> nxdoom -iwad /mnt/spif/doom1.wad
                             NXDoom v0.0.0
...
hu_init: Setting up heads up display.
st_init: Init status bar.

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc).
  • My PR is still work in progress (not ready for review).
  • My PR is ready for review and can be safely merged into a codebase.

@wwlapaki310

Copy link
Copy Markdown
Author

This will be rebased onto the Kconfig split in #3860 (the option moves to Kconfig.input) once that is merged.

Comment thread games/NXDoom/src/i_input.c
Comment thread games/NXDoom/src/i_input.c Outdated
Comment thread games/NXDoom/src/i_input.c Outdated
Comment thread games/NXDoom/src/i_input.c Outdated
@wwlapaki310
wwlapaki310 force-pushed the nxdoom-uartkbd branch 3 times, most recently from c44ad9f to 24a4c26 Compare October 19, 2026 15:09
@wwlapaki310

Copy link
Copy Markdown
Author

Thanks for the review! All comments are addressed, and I tested it again on a Spresense.

jerpelea
jerpelea previously approved these changes Oct 20, 2026

@jerpelea jerpelea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove Co-Authored-By: Claude Sonnet 5.5 noreply@anthropic.com

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wwlapaki310

Copy link
Copy Markdown
Author

Fixed the failing CI style check: nxstyle switch indentation in i_input.c (separate commit, indentation only).

@jerpelea jerpelea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove Co-Authored-By: Claude Sonnet 5.5 noreply@anthropic.com

Indent the case labels of the switch statements two columns deeper, as
the coding standard and the current nxstyle require.  Only the
indentation changes.

Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: satoru akita <wwlap24@gmail.com>
NXDoom reads its keys only from a keyboard character driver, so a board
without one cannot play it.  Some boards, such as the Spresense, have
nothing but a serial console.

Add GAMES_NXDOOM_UARTKBD, which reads bytes from the tty named by
GAMES_NXDOOM_KBDPATH (for example /dev/console) and turns them into
keyboard events:

* W, A, S, D and the arrow keys move, J fires, K runs, L strafes,
  E or space uses, and Q or Esc opens the menu.
* A terminal reports a key press but never its release, so each press
  is released again 250 ms after its last byte.

The code is in its own file, i_input_uartkbd.c, which is built only when
the option is on, so that i_input.c has just one call to it.  Also remove
the dead "#if 0" block that was left in i_input.c.

The option is disabled by default, so existing configurations are not
affected.

Tested on a Spresense with an ILI9340 display: the menu opens, moves
and closes from keys sent over the console.

Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: satoru akita <wwlap24@gmail.com>
@wwlapaki310

Copy link
Copy Markdown
Author

Removed, sorry for the extra trailer.

@xiaoxiang781216
xiaoxiang781216 dismissed stale reviews from jerpelea and cederom October 20, 2026 16:18

fxied

@github-actions github-actions Bot removed the Size: M label Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants