romu-midi-controller.ino
Creates a compact USB MIDI device for music production or DAW control.
Romu board is ideal for MIDI controllers due to its size. This example uses TinyUSB to emulate a MIDI interface. No external GPIOs needed for basic example, but debug pads could be used to add physical buttons later.
romu-midi-controller.ino
#include "pico/stdlib.h"
#include "tusb.h"
#include "class/midi/midi_device.h"
// Descripteur MIDI
uint8_t const desc_hid_report[] = {
TUD_MIDI_DESC_EP(HID_EPIN_ADDR, 64, 0x01)
};
const uint8_t desc_configuration[] = {
TUD_CONFIG_DESCRIPTOR(1, 1, 0, TUD_CONFIG_DESC_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
TUD_MIDI_DESCRIPTOR(0, 0, HID_EPIN_ADDR, HID_EPIN_SIZE, 0x81, 10)
};
uint8_t const *tud_midi_descriptor_report_cb(uint8_t instance) {
return desc_hid_report;
}
void tud_midi_rx_cb(uint8_t ep_addr) {
// Réception MIDI (non utilisée ici)
}
int main() {
tusb_init();
uint8_t note = 60; // C4
while (true) {
tud_task();
if (tud_mounted()) {
static uint32_t last_time = 0;
uint32_t now = time_us_32();
if (now - last_time > 500000) { // 500ms
last_time = now;
// Note On
uint8_t packet[4] = {0x90, note, 100}; // Canal 0, Note, Vélocité
tud_midi_write_packet(0, packet, 4);
sleep_ms(100);
// Note Off
packet[0] = 0x80;
packet[2] = 0;
tud_midi_write_packet(0, packet, 4);
note = (note % 12) + 60; // Boucle sur une octave
}
}
}
}