From 22572b9baa0ac7b5ef01b6346e2c0e10fea95c02 Mon Sep 17 00:00:00 2001 From: Ashley Strahle Date: Tue, 23 Jun 2026 13:12:32 +0000 Subject: [PATCH] Fix Adafruit TinyUSB API: TinyUSBDevice, writePacket, mounted() --- platformio.ini | 1 - src/midi_transport.cpp | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/platformio.ini b/platformio.ini index 79713ed..88a9ee4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,7 +11,6 @@ lib_deps = adafruit/Adafruit NeoPixel build_flags = - -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=1 monitor_speed = 115200 diff --git a/src/midi_transport.cpp b/src/midi_transport.cpp index e810ff4..ac6e80b 100644 --- a/src/midi_transport.cpp +++ b/src/midi_transport.cpp @@ -13,16 +13,16 @@ UsbMidiTransport::~UsbMidiTransport() { bool UsbMidiTransport::begin() { Serial.println("[MIDI] Initializing USB MIDI..."); - USBDevice.setManufacturerDescriptor("Ashley Strahle"); - USBDevice.setProductDescriptor("Loopy Foot Controller"); - USBDevice.setSerialDescriptor("LFMIDI001"); + TinyUSBDevice.setManufacturerDescriptor("Ashley Strahle"); + TinyUSBDevice.setProductDescriptor("Loopy Foot Controller"); + TinyUSBDevice.setSerialDescriptor("LFMIDI001"); if (!usb_midi.begin(32)) { Serial.println("[MIDI] ERROR: USB MIDI init failed"); return false; } - USB.begin(); + TinyUSBDevice.begin(); initialized = true; Serial.println("[MIDI] USB MIDI initialized - waiting for host"); return true; @@ -61,24 +61,27 @@ void UsbMidiTransport::on_midi_receive(std::function cal void UsbMidiTransport::send_note_on(uint8_t channel, uint8_t note, uint8_t velocity) { if (!initialized) return; - usb_midi.sendNoteOn(note, velocity, channel); + uint8_t packet[4] = {0x09, (uint8_t)(0x90 | (channel - 1)), note, velocity}; + usb_midi.writePacket(packet); 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) { if (!initialized) return; - usb_midi.sendNoteOff(note, velocity, channel); + uint8_t packet[4] = {0x08, (uint8_t)(0x80 | (channel - 1)), note, velocity}; + usb_midi.writePacket(packet); 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) { if (!initialized) return; - usb_midi.sendControlChange(cc, value, channel); + uint8_t packet[4] = {0x0B, (uint8_t)(0xB0 | (channel - 1)), cc, value}; + usb_midi.writePacket(packet); Serial.printf("[MIDI OUT] Ch:%d CC:%d:%d\n", channel, cc, value); } bool UsbMidiTransport::is_connected() { - return initialized && usb_midi.isMounted(); + return initialized && TinyUSBDevice.mounted(); } void UsbMidiTransport::parse_midi_packet(const uint8_t* buffer, uint32_t size, MidiEvent& event) {