🛠 Create a custom HID device with Romu
Objectifs
This tutorial guides you through creating a simple Human Interface Device (HID) using the Romu board. You will learn to send keyboard commands via USB without external cables, utilizing the board's physical buttons. This use case demonstrates automating repetitive tasks or creating custom shortcuts.
Matériel nécessaire
- A Bitmerse Romu board.
- A computer with an available USB Type-A port.
- A development environment compatible with RP2350/RP2354 (MicroPython or C/C++ with Pico SDK).
- A USB cable for initial programming (via debug pads or bootloader).
Étapes
Install picotool and the Raspberry Pi SDK. Ensure your compiler is configured for the Arm Cortex-M33 or RISC-V target as chosen.
- Environment Setup
Use the SDK's HID library to define a device descriptor. Here is a C example using the TinyUSB library:
- Writing the HID Code
#include "tusb.h"
// Define buttons as internal GPIO inputs
#define BTN_A 0
#define BTN_B 1
void setup() {
gpio_init(BTN_A); gpio_set_dir(BTN_A, GPIO_IN);
gpio_init(BTN_B); gpio_set_dir(BTN_B, GPIO_IN);
tusb_init();
}
void loop() {
tud_task(); // Handle USB events
if (!gpio_get(BTN_A) && tud_hid_ready()) {
uint8_t report[2] = {0x00, 0x04}; // Key 'a' pressed
tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, report);
} else if (tud_hid_ready()) {
uint8_t report[2] = {0x00, 0x00}; // Release
tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, report);
}
sleep_ms(10);
}
Compile the project for the Romu board. Connect the board to your PC via the integrated USB Type-A connector. If the bootloader is active, the board will appear as a mass storage device. Copy the compiled .uf2 file to the drive.
- Compilation and Flashing
Unplug and replug the board. No cable is needed for final use. Open a text editor and press the corresponding button to verify character transmission.
- Plug-and-Play Test
Vérification
- The RGB LED can indicate USB connection status (on if enumerated).
- Open your OS device manager to confirm detection of a "USB Keyboard" or generic HID device.
- Test button responsiveness: each press should produce the configured character.
Pour aller plus loin
Explore sending key combinations (Ctrl+C) or implementing a USB MIDI controller. Arm TrustZone security can be enabled to protect firmware from unauthorized reading, crucial for authentication keys.
Other tutorials for this board
Code examples for this board
romu-rgb-led-pwm.inoC/C++ (Pico SDK)romu-hid-keyboard-macro.inoC/C++ (TinyUSB)romu-internal-flash-storage.inoC/C++ (Pico SDK)romu-midi-controller.inoC/C++ (TinyUSB)romu-secure-boot-check.inoC/C++ (Pico SDK)romu-hid-custom-keyboard.inoC++ (Arduino)