Switch to ESP32 Arduino core native USB MIDI API (USB.h + USBMIDI.h), remove Adafruit TinyUSB dependency
This commit is contained in:
+10
-17
@@ -1,8 +1,9 @@
|
||||
#include "midi_transport.h"
|
||||
#include <Arduino.h>
|
||||
#include "Adafruit_TinyUSB.h"
|
||||
#include "USB.h"
|
||||
#include "USBMIDI.h"
|
||||
|
||||
static Adafruit_USBD_MIDI usb_midi;
|
||||
static USBMIDI usb_midi;
|
||||
|
||||
UsbMidiTransport::UsbMidiTransport() : initialized(false) {
|
||||
}
|
||||
@@ -18,14 +19,10 @@ bool UsbMidiTransport::begin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TinyUSBDevice.mounted()) {
|
||||
Serial.println("[MIDI] Re-enumerating with MIDI interface...");
|
||||
TinyUSBDevice.detach();
|
||||
delay(10);
|
||||
TinyUSBDevice.attach();
|
||||
}
|
||||
USB.begin();
|
||||
|
||||
initialized = true;
|
||||
Serial.println("[MIDI] USB MIDI ready - enumerating...");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -36,8 +33,7 @@ void UsbMidiTransport::update() {
|
||||
uint32_t now = millis();
|
||||
if (now - last_status > 5000) {
|
||||
last_status = now;
|
||||
Serial.printf("[MIDI] USB mounted: %s\n",
|
||||
TinyUSBDevice.mounted() ? "YES" : "NO");
|
||||
Serial.printf("[MIDI] USB ready: %s\n", USB.ready() ? "YES" : "NO");
|
||||
}
|
||||
|
||||
while (usb_midi.available()) {
|
||||
@@ -70,27 +66,24 @@ 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) {
|
||||
if (!initialized) return;
|
||||
uint8_t packet[4] = {0x09, (uint8_t)(0x90 | (channel - 1)), note, velocity};
|
||||
usb_midi.writePacket(packet);
|
||||
usb_midi.noteOn(note, velocity, channel);
|
||||
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;
|
||||
uint8_t packet[4] = {0x08, (uint8_t)(0x80 | (channel - 1)), note, velocity};
|
||||
usb_midi.writePacket(packet);
|
||||
usb_midi.noteOff(note, velocity, channel);
|
||||
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;
|
||||
uint8_t packet[4] = {0x0B, (uint8_t)(0xB0 | (channel - 1)), cc, value};
|
||||
usb_midi.writePacket(packet);
|
||||
usb_midi.controlChange(cc, value, channel);
|
||||
Serial.printf("[MIDI OUT] Ch:%d CC:%d:%d\n", channel, cc, value);
|
||||
}
|
||||
|
||||
bool UsbMidiTransport::is_connected() {
|
||||
return initialized && TinyUSBDevice.mounted();
|
||||
return initialized && USB.ready();
|
||||
}
|
||||
|
||||
void UsbMidiTransport::parse_midi_packet(const uint8_t* buffer, uint32_t size, MidiEvent& event) {
|
||||
|
||||
Reference in New Issue
Block a user