Skip to content

examples/hidcombo: Add USB HID keyboard + mouse combo example - #3911

Merged
acassis merged 1 commit into
apache:masterfrom
acassis:max3421e_hidcombo
Oct 25, 2026
Merged

acassis merged 1 commit into
apache:masterfrom
acassis:max3421e_hidcombo

Conversation

@acassis

@acassis acassis commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an example that reads a USB HID keyboard and a USB HID mouse at the same time from a single task using poll(). It is meant to test devices that expose both a keyboard and a mouse, like the wireless keyboard + touchpad receivers, and uses less memory than running hidkbd and tc side by side, which matters on small boards (e.g. stm32f103-minimum).

Impact

Users will be able to use a HID keyboard with mouse/touchpad on NuttX.

Testing

nsh> hidcombo                                                                     
hidcombo: waiting for 40 events from /dev/kbda and /dev/mouse0                    
MOUSE buttons=00 x=140 y=120                                                      
MOUSE buttons=00 x=120 y=122                                                      
MOUSE buttons=00 x=98 y=125                                                       
MOUSE buttons=00 x=70 y=141                                                       
MOUSE buttons=00 x=43 y=165                                                       
MOUSE buttons=00 x=14 y=189                                                       
MOUSE buttons=00 x=0 y=212                                                        
MOUSE buttons=00 x=0 y=233                                                        
MOUSE buttons=00 x=13 y=240                                                       
MOUSE buttons=00 x=34 y=240                                                       
MOUSE buttons=00 x=57 y=240                                                       
MOUSE buttons=00 x=89 y=238                                                       
MOUSE buttons=00 x=120 y=223                                                      
MOUSE buttons=00 x=146 y=198                                                      
MOUSE buttons=00 x=168 y=168                                                      
MOUSE buttons=00 x=182 y=138                                                      
MOUSE buttons=00 x=185 y=101                                                      
MOUSE buttons=00 x=181 y=66                                                       
MOUSE buttons=00 x=172 y=42                                                       
MOUSE buttons=00 x=161 y=24                                                       
MOUSE buttons=00 x=148 y=13                                                       
MOUSE buttons=00 x=135 y=5                                                        
MOUSE buttons=00 x=123 y=0                                                        
MOUSE buttons=00 x=105 y=0                                                        
KEY   press           code=0x61 'a'                                               
KEY   release         code=0x61 'a'                                               
KEY   press           code=0x69 'i'                                               
KEY   release         code=0x69 'i'                                               
KEY   press           code=0x73 's'                                               
KEY   release         code=0x73 's'                                               
KEY   press           code=0x6a 'j'                                               
KEY   press           code=0x6b 'k'                                               
KEY   release         code=0x6a 'j'                                               
KEY   release         code=0x6b 'k'                                               
KEY   press           code=0x6c 'l'                                               
KEY   release         code=0x6c 'l'                                               
KEY   press           code=0x49 'I'                                               
KEY   release         code=0x49 'I'                                               
KEY   press           code=0x5a 'Z'                                               
KEY   release         code=0x5a 'Z'                                               
hidcombo: 16 key events, 24 mouse events

Add an example that reads a USB HID keyboard and a USB HID mouse at the
same time from a single task using poll().  It is meant to test devices
that expose both a keyboard and a mouse, like the wireless keyboard +
touchpad receivers, and uses less memory than running hidkbd and tc
side by side, which matters on small boards (e.g. stm32f103-minimum).

Signed-off-by: Alan C. Assis <acassis@gmail.com>
Assisted-by: Claude Code Opus 5.5
@cederom

cederom commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Great stuff @acassis :D

My proposition is to use name apps/examples/usbhidcombo-client (to focus on USB in the first place, or hid-combo-usb-client to focus on HID in the first place) because:

  1. This is USB HID example. HID can also use BT.
  2. USB HID Combo somehow implies that we are providing USB HID Mouse and Keyboard (device).. while this code is a "Client" example that reads external Keyboard and Mouse over USB HID right?

@acassis

acassis commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Great stuff @acassis :D

My proposition is to use name apps/examples/usbhidcombo-client (to focus on USB in the first place, or hid-combo-usb-client to focus on HID in the first place) because:

1. This is USB HID example. HID can also use BT.

2. USB HID Combo somehow implies that we are providing USB HID Mouse and Keyboard (device).. while this code is a "Client" example that reads external Keyboard and Mouse over USB HID right?

Thank you @cederom !!!

About the name there is already hidkbd that Greg added many years ago and it is for USB. I think the Kconfig already makes it clean: "USB HID keyboard + mouse combo example".

Probably for Bluetooth people will create a ble_kdb or similar :-)

@cederom

cederom commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Yeah, but does this hidkbd or hidcombo serve as usb hid "device" that will serve user input to the host machine or is it "client" usb "host" that reads user input from the usb hid device? The name on its own is too general and ambiguous, but if you like it it can stay that way ;-)

@acassis

acassis commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Yeah, but does this hidkbd or hidcombo serve as usb hid "device" that will serve user input to the host machine or is it "client" usb "host" that reads user input from the usb hid device? The name on its own is too general and ambiguous, but if you like it it can stay that way ;-)

Actually they are working like on a host device (like in the computer), so to work like a device it needs to mimic a keyboard or a mouse to fake they are device. I kind messing with "client" USB "host" is not a good idea, let the user get it right from the documentation:

https://nuttx.apache.org/docs/latest/applications/examples/hidkbd/index.html

@cederom

cederom commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Yeah, but does this hidkbd or hidcombo serve as usb hid "device" that will serve user input to the host machine or is it "client" usb "host" that reads user input from the usb hid device? The name on its own is too general and ambiguous, but if you like it it can stay that way ;-)

Actually they are working like on a host device (like in the computer), so to work like a device it needs to mimic a keyboard or a mouse to fake they are device. I kind messing with "client" USB "host" is not a good idea, let the user get it right from the documentation:

https://nuttx.apache.org/docs/latest/applications/examples/hidkbd/index.html

This is still confusing, but from the description it may seem like this is universal HID not matter what transport, so we can leave it that way unless someone adds new stuff and update the documentation :-)

I am asking because I was looking for some usb-hid-combo-device example myself :D

@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.

Thank you @acassis :-)

I would love to merge on a passed CI so there are no issues when backporting :-)

Comment thread examples/hidcombo/hidcombo_main.c
Comment thread examples/hidcombo/hidcombo_main.c
@acassis
acassis merged commit 9e01c43 into apache:master Oct 25, 2026
102 of 151 checks passed
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.

3 participants