Dual-Role HID Architecture on nRF5340: BT Central Input with Selectable USB or BT HID Output

Hi,

I'm working on a customized version of the nRF Desktop App running on an nRF5340. In my use case, I want to connect Bluetooth HID devices (mouse and keyboard) as input sources in Central role, process or modify the incoming HID reports, and then forward the data either via USB HID (as a composite mouse + keyboard device) or via Bluetooth HID (Peripheral role) to a host.

I do not want both output channels to be active simultaneously — the output should be selectable, i.e., either USB or BT HID, depending on a runtime setting.

I’ve already explored parts of the nrf Desktop App, including modules like hid_state, hid_forward, ble_scan, bt_hids, etc. However, I want to avoid using the built-in HID forwarder, which connects BT input to USB output directly. Instead, I plan to build a custom data flow where:

  • BT HID input devices (keyboard and mouse) connect as Central,

  • Their input is processed and optionally transformed,

  • The resulting reports are sent either to a USB host (via USB HID composite) or to a BT host (via HID Peripheral role), depending on a user-controlled setting.

My questions:

  1. Best practice for switchable HID output:
    What is the recommended way to cleanly implement switchable HID output between USB and BT HID, while ensuring proper init/cleanup and avoiding conflicts?

  2. Combining BT Central and BT Peripheral roles:
    Are there known limitations or pitfalls when combining Central (for input) and Peripheral (for output) roles on the nRF5340?

  3. Reusing parts of the Desktop App:
    Would you suggest reusing existing modules like hid_report, usb_hid, bt_hids, etc. and building a new glue layer for input/output control?
    Or would it be more maintainable to design a custom lightweight HID processing pipeline from scratch?

  4. Multiple BT HID input devices:
    What is the best strategy to connect and handle multiple BT HID input devices (e.g., mouse + keyboard) in parallel in Central role? Do I need to extend or modify the bt_hid_client module to support that?

I’d really appreciate your guidance and suggestions on how to get started with this Dual Role HID architecture on the nRF5340. Thank you for your support!

Best regards,

Parents
  • Hello,

    I am terribly sorry for the late reply. We are a bit short staffed, and we are doing our best to keep the queue down to a minimum.

    The nRF Desktop application is a huge application, that sort of tries to cover everything, but it has become a bit messy. If I understand your request correctly, you want to have a e.g. a keyboard that will send it's data over BLE, but whenever USB is connected, it switches the transport over to USB instead of BLE. 

    It may be possible in the nRF Desktop application, but I am not sure how to do that. I suggest you rather have a look at the following samples:

    NCS\nrf\samples\bluetooth\peripheral_hids_keyboard

    NCS\zephyr\samples\subsys\usb\hid-keyboard

    Between the two, you should have everything you need. You will probably have some event handler whenever something is changing (whether it is a keyboard press, a mouse movement, or whatever you are looking into). Then you should, based on whether the USB is connected or not, and whether BLE is connected or not, pipe the information to either HID over USB, or HID over BLE.

    Best regards,

    Edvin

Reply
  • Hello,

    I am terribly sorry for the late reply. We are a bit short staffed, and we are doing our best to keep the queue down to a minimum.

    The nRF Desktop application is a huge application, that sort of tries to cover everything, but it has become a bit messy. If I understand your request correctly, you want to have a e.g. a keyboard that will send it's data over BLE, but whenever USB is connected, it switches the transport over to USB instead of BLE. 

    It may be possible in the nRF Desktop application, but I am not sure how to do that. I suggest you rather have a look at the following samples:

    NCS\nrf\samples\bluetooth\peripheral_hids_keyboard

    NCS\zephyr\samples\subsys\usb\hid-keyboard

    Between the two, you should have everything you need. You will probably have some event handler whenever something is changing (whether it is a keyboard press, a mouse movement, or whatever you are looking into). Then you should, based on whether the USB is connected or not, and whether BLE is connected or not, pipe the information to either HID over USB, or HID over BLE.

    Best regards,

    Edvin

Children
No Data
Related