🛠 Create a custom HID device with Romu

Bitmerse Romu Compact USB Development Board (RP2354A) · debutant · Transformez votre carte Romu en un pavé macro USB compact grâce à ses boutons intégrés et son connecteur Type-A.

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

Étapes

Install picotool and the Raspberry Pi SDK. Ensure your compiler is configured for the Arm Cortex-M33 or RISC-V target as chosen.

  1. Environment Setup

Use the SDK's HID library to define a device descriptor. Here is a C example using the TinyUSB library:

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

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

  1. Plug-and-Play Test

Vérification

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

← Back to the board 🛠 All tutorials