🛠 Build a USB HID Macro Pad with the Romu Board
Objectifs
This advanced tutorial aims to configure the Romu board as a USB HID (Human Interface Device) peripheral. You will learn to utilize the physical buttons on the board to send complex key combinations to the host computer, creating a compact macro pad. We will cover input event handling and keyboard simulation via the USB protocol.
Matériel nécessaire
- Romu development board (Bitmerse)
- Computer with USB-A port
- Development environment compatible with RP2354A (MicroPython or C/C++ SDK)
- USB-A cable for initial flashing (if required by board state)
Étapes
Install the programming tool suitable for the RP2354A microcontroller. Ensure BOOTSEL mode is accessible if the board needs resetting. Connect the Romu to your PC via its integrated USB Type-A connector.
- Environment Preparation
In your IDE, create a new project based on the USB HID library. Define the device descriptor so it is recognized as a standard keyboard. This ensures plug-and-play compatibility with most operating systems without specific driver installation.
- HID Project Configuration
Identify the internal GPIOs associated with the Romu board's buttons. Write a function to read the state of these buttons. For example, map Button 1 to the Ctrl+Shift+T macro and Button 2 to Ctrl+C. Use timers to avoid hardware debouncing issues.
- Physical Button Mapping
Code the key code sending sequence. For each press, the board must send the modifier key presses (Ctrl, Shift), then the main key, followed by releasing the keys in reverse order. Here is a logical structure example: ``c if (button_pressed(BTN_1)) { send_key_mod(KC_MOD_CTRL, KC_MOD_SHIFT); send_key(KC_T); release_keys(); } ``
- Macro Logic Implementation
Compile the code for the RP2354A target. Transfer the binary to the Romu board. Once flashing is complete, the board will automatically reconnect to the USB bus.
- Compilation and Flashing
Vérification
Open a text editor or browser. Press the configured macro button. If text is inserted or the corresponding action triggers (like closing a tab with Ctrl+Shift+T), the HID configuration is successful. Also verify that no additional drivers are required in the device manager.
Pour aller plus loin
Integrate the RGB LED to indicate macro states or active modes. You can also explore using Arm Trustzone security to protect sensitive macros from unauthorized reading, turning the Romu into a physical authentication key.
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)