This tutorial is aimed at implementing the nRF Desktop application on the nRF52840 Development Kit (DK) using the nRF Connect SDK, thereby allowing it to work either as a gaming mouse, keyboard, or dongle.
The nRF Desktop is a Human Interface Device (HID) reference design that connects to a host via Bluetooth® Low Energy, USB, or both. This application can run on a desktop mouse, gaming mouse, keyboard, or connection dongle depending on how it is configured. The reference design includes both software and hardware implementations. The software for the nRF Desktop is by default embedded in the nRF Connect SDK, while the hardware (HW) kit is described here (where it is also possible to download the schematic). This tutorial aims to help you test the nRF Desktop application without having access to the full HW kit, by using simple DevKits. The nRF Desktop application can also be helpful for those designing other types of Bluetooth LE applications, since it implements many complex modules that can potentially be reused for other applications. Full nRF Desktop documentation is available here.
The architecture of the nRF Desktop application is based on the Common Application Framework (CAF). Thus the application uses individual modules that communicate with each other using application events which are controlled by the Event Manager. One application event can be submitted by multiple modules and can have multiple listeners.
Depending on the device required (mouse, keyboard, dongle), the set of modules also differ. Hence, not all modules are required for every device. The code has been designed to be very modular, with one codebase that can be configured to be used for different boards or types of devices. Depending on your hardware, different configuration build types can be selected to configure the application to work for different use-cases.
The nRF Desktop application is intended to run on hardware such as a computer mouse or a keyboard. However, if these devices are not available to you, the application also supports the nRF52840 DK as a gaming mouse, keyboard or dongle or the nRF52833 DK as a dongle. This tutorial will show how you can configure the nRF Desktop application for a specific build type and to test it on the nRF52840 DK, to emulate a mouse, keyboard or dongle.
Application configured as Gaming mouse
When using an nRF52840 DK, the nRF Desktop application is by default configured to function as a gaming mouse. It can be configured to function as a keyboard as well as a dongle by including the required configuration (.conf) files which have the set modules required for that application. These files can be found in the specific folder for the DK (nrf_desktop/configuration/nrf52840dk_nrf52840): gaming mouse (prj.conf), keyboard (prj_keyboard.conf) and dongle (prj_dongle.conf).
Passing the correct configuration file to the compiler when building the project enables you to make the DK function as whichever HID peripheral you require. Once you are familiar with the code, it is possible to create new configuration files as well, to enable or disable specific features.
The samples in this blog post are tested with nRF Connect SDK v1.8.0 and the nRF52840 DK.
This example requires the following:
The application can be built and run in 3 separate ways which are all supported by the nRF Connect SDK:
NOTE: nRF Connect SDK is IDE agnostic, i.e. you can use any IDE, however we only support the IDEs listed above.
If configuring the application as a dongle, build one nRF52840 DK with the dongle configuration and the other with the configuration of the required peripheral (mouse or keyboard).
-DCONF_FILE=<build_type>
where <build_type> can be:
west build -b nrf52840dk_nrf52840 -d build -- -DCONF_FILE=<build_type>
west flash
Now that we have configured the nRF Desktop application to fit our use-case and flashed it to the nRF52840 DKs, the testing can be done as follows.
What makes this configuration act as a gaming mouse is the fact that the LLPM (Low Latency Packet Mode) is enabled (see CONFIG_BT_CTLR_LLPM=y, allowing the mouse to decrease the connection interval of the Bluetooth LE connection down to 1ms when connected to another device (e.g. dongle) supporting the same feature.
The gaming mouse in the nRF Desktop can support three communication channels: Bluetooth LE to PC/mobile, Bluetooth LE to dongle using Nordic LLPM feature (1ms report rate), USB. In this section, only standard Bluetooth LE to PC and USB are explored. For demonstrating LLPM, a new tutorial covering advanced features will be released later.
These steps describe how to test the nRF52840 as a gaming mouse over a Bluetooth LE connection to a PC/mobile/tablet.
To test the USB connection, perform the following steps:
To prepare the DK for a new connection to the dongle over Bluetooth LE (which is presented in section 4.3), you must unpair the device from your PC/mobile:
The device will Erase the peers if the previous peer (PC/mobile) is not found. LED 1 lights up and LED 2 starts breathing (blinking slowly) indicating that the device is advertising, ready for new connection.
These steps describe how to test the nRF52840 as a keyboard over a Bluetooth LE connection.
flash the application to the DK again.
These steps describe how to test the nRF52840 as a dongle over a Bluetooth LE connection.
You can observe that LED 1 lights up.
NOTE: if you have three DKs available (one as a dongle, one as a keyboard and one as a gaming mouse), you can have both the gaming mouse and the keyboard advertising at the same time. When the dongle turns on for first time, it will scan and connect to both peripherals and keep scanning. However, the dongle stops scanning as soon as one of the connected devices is used. To start scanning for both bonded and non-bonded Bluetooth Peripherals, Short-press Button 1 (less than 0.5 seconds). The scan is interrupted if another peripheral connected to the dongle is in use. On the contrary, Long-press Button 1 (more than 5 seconds). to initialize peer erase. When LED2 starts blinking rapidly, double-press Button 1 to confirm the operation. After the confirmation, all the Bluetooth bonds are removed for the dongle. It is now possible to connect new devices.
The nRF Desktop includes many interesting features that can be tested and can be used when building HID devices, or other applications. These can become topics for future blogs and tutorials. Meanwhile, it is worth mentioning a selection of features here: