Skip to content

Conversation

@FelipeMdeO
Copy link
Contributor

Note: Please adhere to Contributing Guidelines.

Summary

Add a generic keyboard matrix (kmatrix) lower-half driver with polling/debounce, plus an STM32 GPIO board adapter and public API to expose /dev/kbdN. Include a 4x3 keypad keymap example and documentation/test helper.
I2C interface to used keypad was done but not tested yet.
The IRQ feature will be done as soon as possible. This is a first step development.

This change solve this request: apache/nuttx-apps#1764

Please @acassis , help me to verify if I followed all standards.

Impact

Optional input driver; no behavior change unless enabled. Enabling kmatrix adds periodic GPIO scanning and keyboard events on /dev/kbd0.

Testing

Host: Ubuntu 24.04.3 LTS x86_64.
Board: STM32F4Discovery + 4x3 membrane keypad (GPIO). See picture of keypad used below:
image

Build: stm32f4discovery:nsh with:

  • CONFIG_INPUT=y
  • CONFIG_INPUT_KMATRIX=y
  • CONFIG_EXAMPLES_KEYBOARD=y
  • CONFIG_EXAMPLES_KEYBOARD_DEVPATH="/dev/kbd0"
  • CONFIG_INPUT_KMATRIX_POLL_MS=10 (default)
  • CONFIG_INPUT_KMATRIX_DEBOUNCE=3 (default)
  • CONFIG_INPUT_KMATRIX_BUFSIZE=64 (default)

Runtime: Ran kbd and observed key press/release events.
Logs:

nsh> kbd
kbd_main: nsamples: 0
kbd_main: Opening /dev/kbd0
Sample :
code : 49
type : 0
Sample :
code : 49
type : 1
Sample :
code : 50
type : 0
Sample :
code : 50
type : 1
Sample :
code : 51
type : 0
Sample :
code : 51
type : 1
Sample :
code : 52
type : 0
Sample :
code : 52
type : 1
Sample :
code : 53
type : 0
Sample :
code : 53
type : 1
Sample :
code : 54
type : 0
Sample :
code : 54
type : 1
Sample :
code : 55
type : 0
Sample :
code : 55
type : 1
Sample :
code : 56
type : 0
Sample :
code : 56
type : 1
Sample :
code : 57
type : 0
Sample :
code : 57
type : 1
Sample :
code : 42
type : 0
Sample :
code : 42
type : 1
Sample :
code : 48
type : 0
Sample :
code : 48
type : 1
Sample :
code : 35
type : 0
Sample :
code : 35
type : 1

@github-actions github-actions bot added Arch: simulator Issues related to the SIMulator Area: Drivers Drivers issues Board: arm Board: simulator Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Feb 8, 2026
@FelipeMdeO FelipeMdeO force-pushed the feature/kbd-driver branch 2 times, most recently from 8e7d651 to b9b64f9 Compare February 8, 2026 14:49
@github-actions github-actions bot removed the Arch: simulator Issues related to the SIMulator label Feb 8, 2026

/* Format string for /dev/kbdN device */

#define DEV_FORMAT "/dev/kbd%d"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: use /dev/keypad%d or similar, /dev/kdb%d is already used by real keyboard, not an big issue, but could have some incompatibilities (if it is a /dev/kbd0 for example, it should be 100% compatible with a real keyboard, including scanning encoding support)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I will solve this.

Copy link
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

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

@FelipeMdeO also since you are adding a new feature, we need Documentation/ to this matrix keyboard/keypad. Explain the purpose of this matrix keyboard, why it uses polling instead of interruptions, etc. Also drivers which functions a board needs to implement in order to support it (use the current stm32f4discovery implementation as reference)

@FelipeMdeO
Copy link
Contributor Author

Hello @acassis , I don't know how to proceed with documentation.
I found the doc: https://nuttx.apache.org/docs/latest/components/drivers/character/input/keypad.html
But its seems not outdated.
Can you give some tips, please?

@FelipeMdeO FelipeMdeO force-pushed the feature/kbd-driver branch 3 times, most recently from 0e7d5be to 88ffb4a Compare February 9, 2026 02:17
@github-actions github-actions bot added the Area: Documentation Improvements or additions to documentation label Feb 9, 2026
@FelipeMdeO
Copy link
Contributor Author

I did a documentation, please check if it is enough.

jerpelea
jerpelea previously approved these changes Feb 9, 2026
Copy link
Contributor

@michallenc michallenc left a comment

Choose a reason for hiding this comment

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

Nice work!

michallenc
michallenc previously approved these changes Feb 9, 2026
@FelipeMdeO FelipeMdeO requested a review from simbit18 February 9, 2026 10:56
simbit18
simbit18 previously approved these changes Feb 9, 2026
@acassis
Copy link
Contributor

acassis commented Feb 9, 2026

@FelipeMdeO you can add your kmatrix driver inside Documentation/components/drivers/character/input/

Yes, that documentation is very old and needs to be updated later.

Please create a Documentation giving context about your driver, what is its purpose, why is was created, how to add it to your board, etc.

The Documentation is written in ReStructuredText (similar to Markdown) and you can use this document to verify if everything is fine:
https://nuttx.apache.org/docs/latest/contributing/documentation.html

Copy link
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

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

Very good @FelipeMdeO !!!
In your KMATRIX Documentation you can include that phone keypad to illustrate the idea ;-)

events into the text data stream. The function interfaces that
comprise that encoding/decoding layer are defined in the header
file ``include/nuttx/input/kbd_code.h``. These functions provide
an matched set of (a) driver encoding interfaces, and (b)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
an matched set of (a) driver encoding interfaces, and (b)
a matched set of (a) driver encoding interfaces, and (b)

@acassis
Copy link
Contributor

acassis commented Feb 9, 2026

I did a documentation, please check if it is enough.

Yes, your Documentation seems very good, I just suggested adding the keypad image after the title to illustrate the idea. Normally it makes the article more pleasant for someone reading the text.

@FelipeMdeO FelipeMdeO dismissed stale reviews from simbit18 and michallenc via 58d5a51 February 9, 2026 17:27
@FelipeMdeO FelipeMdeO requested a review from acassis February 9, 2026 17:27
acassis
acassis previously approved these changes Feb 9, 2026
simbit18
simbit18 previously approved these changes Feb 9, 2026
Add a generic kmatrix lower-half with polling/debounce, STM32 board adapters, Kconfig options, a public API header, and a test example/documentation.

Signed-off-by: Felipe Moura <[email protected]>

decouple kbd / keypad.

Fix some comments

add documentation

fix rule issues

Update CMakeLists.txt

update documentation.

improve documentation
@FelipeMdeO FelipeMdeO dismissed stale reviews from simbit18 and acassis via 652f764 February 9, 2026 19:34
@github-actions
Copy link

github-actions bot commented Feb 9, 2026

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@acassis
Copy link
Contributor

acassis commented Feb 9, 2026

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

I think we can ignore this warning. Probably some new rule to avoid big commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Area: Drivers Drivers issues Board: arm Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants