Revert to single MIDI interface (working USB detection)

- Dual interface broke USB enumeration
- Back to working single interface with Novation Launchpad X VID/PID
- Buttons work, MIDI OUT works
This commit is contained in:
2026-06-25 23:17:18 +00:00
parent a209b48720
commit 90bbfa7b84
+15 -46
View File
@@ -2,8 +2,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "Adafruit_TinyUSB.h" #include "Adafruit_TinyUSB.h"
static Adafruit_USBD_MIDI usb_midi_daw; // Interface 1: DAW/Session static Adafruit_USBD_MIDI usb_midi;
static Adafruit_USBD_MIDI usb_midi_midi; // Interface 2: MIDI/Programmer
UsbMidiTransport::UsbMidiTransport() : initialized(false) { UsbMidiTransport::UsbMidiTransport() : initialized(false) {
} }
@@ -12,32 +11,27 @@ UsbMidiTransport::~UsbMidiTransport() {
} }
bool UsbMidiTransport::begin() { bool UsbMidiTransport::begin() {
Serial.println("[MIDI] Setting up USB MIDI device (dual interface)..."); Serial.println("[MIDI] Setting up USB MIDI device...");
TinyUSBDevice.setManufacturerDescriptor("Novation"); TinyUSBDevice.setManufacturerDescriptor("Novation");
TinyUSBDevice.setProductDescriptor("Launchpad X"); TinyUSBDevice.setProductDescriptor("Launchpad X");
TinyUSBDevice.setSerialDescriptor("LPX00001"); TinyUSBDevice.setSerialDescriptor("LPX00001");
TinyUSBDevice.begin(0); TinyUSBDevice.begin(0);
// Initialize both MIDI interfaces if (!usb_midi.begin()) {
if (!usb_midi_daw.begin()) { Serial.println("[MIDI] ERROR: USB MIDI init failed");
Serial.println("[MIDI] ERROR: DAW MIDI init failed");
return false;
}
if (!usb_midi_midi.begin()) {
Serial.println("[MIDI] ERROR: MIDI MIDI init failed");
return false; return false;
} }
if (TinyUSBDevice.mounted()) { if (TinyUSBDevice.mounted()) {
Serial.println("[MIDI] Re-enumerating with dual MIDI interface..."); Serial.println("[MIDI] Re-enumerating with MIDI interface...");
TinyUSBDevice.detach(); TinyUSBDevice.detach();
delay(10); delay(10);
TinyUSBDevice.attach(); TinyUSBDevice.attach();
} }
initialized = true; initialized = true;
Serial.println("[MIDI] USB MIDI ready - dual interface enumerating..."); Serial.println("[MIDI] USB MIDI ready - enumerating...");
return true; return true;
} }
@@ -52,10 +46,9 @@ void UsbMidiTransport::update() {
TinyUSBDevice.mounted() ? "YES" : "NO"); TinyUSBDevice.mounted() ? "YES" : "NO");
} }
// Poll DAW interface (interface 1) while (usb_midi.available()) {
while (usb_midi_daw.available()) {
uint8_t packet[4]; uint8_t packet[4];
if (usb_midi_daw.readPacket(packet)) { if (usb_midi.readPacket(packet)) {
MidiEvent event; MidiEvent event;
parse_midi_packet(packet, 4, event); parse_midi_packet(packet, 4, event);
@@ -68,31 +61,7 @@ void UsbMidiTransport::update() {
case MidiEvent::PITCH_BEND: type_str = "PB"; break; case MidiEvent::PITCH_BEND: type_str = "PB"; break;
default: break; default: break;
} }
Serial.printf("[MIDI IN DAW] Ch:%d %s:%d:%d\n", event.channel, type_str, event.data1, event.data2); Serial.printf("[MIDI IN] Ch:%d %s:%d:%d\n", event.channel, type_str, event.data1, event.data2);
if (receive_callback) {
receive_callback(event);
}
}
}
// Poll MIDI interface (interface 2) - for Programmer mode LED control
while (usb_midi_midi.available()) {
uint8_t packet[4];
if (usb_midi_midi.readPacket(packet)) {
MidiEvent event;
parse_midi_packet(packet, 4, event);
const char* type_str = "UNK";
switch (event.type) {
case MidiEvent::NOTE_ON: type_str = "NOTE_ON"; break;
case MidiEvent::NOTE_OFF: type_str = "NOTE_OFF"; break;
case MidiEvent::CONTROL_CHANGE: type_str = "CC"; break;
case MidiEvent::PROGRAM_CHANGE: type_str = "PC"; break;
case MidiEvent::PITCH_BEND: type_str = "PB"; break;
default: break;
}
Serial.printf("[MIDI IN MIDI] Ch:%d %s:%d:%d\n", event.channel, type_str, event.data1, event.data2);
if (receive_callback) { if (receive_callback) {
receive_callback(event); receive_callback(event);
@@ -108,22 +77,22 @@ void UsbMidiTransport::on_midi_receive(std::function<void(const MidiEvent&)> cal
void UsbMidiTransport::send_note_on(uint8_t channel, uint8_t note, uint8_t velocity) { void UsbMidiTransport::send_note_on(uint8_t channel, uint8_t note, uint8_t velocity) {
if (!initialized) return; if (!initialized) return;
uint8_t packet[4] = {0x09, (uint8_t)(0x90 | (channel - 1)), note, velocity}; uint8_t packet[4] = {0x09, (uint8_t)(0x90 | (channel - 1)), note, velocity};
usb_midi_daw.writePacket(packet); usb_midi.writePacket(packet);
Serial.printf("[MIDI OUT DAW] Ch:%d NOTE_ON:%d:%d\n", channel, note, velocity); Serial.printf("[MIDI OUT] Ch:%d NOTE_ON:%d:%d\n", channel, note, velocity);
} }
void UsbMidiTransport::send_note_off(uint8_t channel, uint8_t note, uint8_t velocity) { void UsbMidiTransport::send_note_off(uint8_t channel, uint8_t note, uint8_t velocity) {
if (!initialized) return; if (!initialized) return;
uint8_t packet[4] = {0x08, (uint8_t)(0x80 | (channel - 1)), note, velocity}; uint8_t packet[4] = {0x08, (uint8_t)(0x80 | (channel - 1)), note, velocity};
usb_midi_daw.writePacket(packet); usb_midi.writePacket(packet);
Serial.printf("[MIDI OUT DAW] Ch:%d NOTE_OFF:%d:%d\n", channel, note, velocity); Serial.printf("[MIDI OUT] Ch:%d NOTE_OFF:%d:%d\n", channel, note, velocity);
} }
void UsbMidiTransport::send_cc(uint8_t channel, uint8_t cc, uint8_t value) { void UsbMidiTransport::send_cc(uint8_t channel, uint8_t cc, uint8_t value) {
if (!initialized) return; if (!initialized) return;
uint8_t packet[4] = {0x0B, (uint8_t)(0xB0 | (channel - 1)), cc, value}; uint8_t packet[4] = {0x0B, (uint8_t)(0xB0 | (channel - 1)), cc, value};
usb_midi_daw.writePacket(packet); usb_midi.writePacket(packet);
Serial.printf("[MIDI OUT DAW] Ch:%d CC:%d:%d\n", channel, cc, value); Serial.printf("[MIDI OUT] Ch:%d CC:%d:%d\n", channel, cc, value);
} }
bool UsbMidiTransport::is_connected() { bool UsbMidiTransport::is_connected() {