Added MIDI via USBHOST-Serial at 38400 bps.

dev
Holger Wirtz 1 year ago
parent 4f8790ee8f
commit 44b32fa27b
  1. 11
      config.h
  2. 48
      midi_devices.hpp

@ -60,7 +60,7 @@
// //
// Information about memory layout, etc.: https://www.pjrc.com/store/teensy41.html // Information about memory layout, etc.: https://www.pjrc.com/store/teensy41.html
#define VERSION "1.2.8" #define VERSION "1.2.9"
//************************************************************************************************* //*************************************************************************************************
//* DEVICE SETTINGS //* DEVICE SETTINGS
@ -71,13 +71,18 @@
//************************************************************************************************* //*************************************************************************************************
#define MIDI_DEVICE_DIN Serial1 #define MIDI_DEVICE_DIN Serial1
#define MIDI_DEVICE_USB 1 #define MIDI_DEVICE_USB 1
#define MIDI_DEVICE_USB_HOST 1 //#define MIDI_DEVICE_USB_HOST 1
#define MIDI_DEVICE_USB_HOST_SERIAL 1
#ifdef MIDI_DEVICE_USB_HOST #ifdef MIDI_DEVICE_USB_HOST_SERIAL
#define USB_HOST_SERIAL_BAUD 38400 #define USB_HOST_SERIAL_BAUD 38400
#define USB_HOST_SERIAL_FORMAT USBHOST_SERIAL_8N1 #define USB_HOST_SERIAL_FORMAT USBHOST_SERIAL_8N1
#endif #endif
/*#if defined(MIDI_DEVICE_USB_HOST) && defined(MIDI_DEVICE_USB_HOST_SERIAL)
#error Only MIDI_DEVICE_USB_HOST or MIDI_DEVICE_USB_HOST_SERIAL is possible to enable at the same time!
#endif */
//************************************************************************************************* //*************************************************************************************************
//* AUDIO HARDWARE SETTINGS //* AUDIO HARDWARE SETTINGS
//************************************************************************************************* //*************************************************************************************************

@ -28,13 +28,23 @@
extern config_t configuration; extern config_t configuration;
#ifdef MIDI_DEVICE_USB_HOST #if defined(MIDI_DEVICE_USB_HOST) || defined(MIDI_DEVICE_USB_HOST_SERIAL)
#include <USBHost_t36.h> #include <USBHost_t36.h>
#endif #endif
// override default sysex size settings // override default sysex size settings
struct MicroDexedSettings : public midi::DefaultSettings { struct MicroDexedSettings : public midi::DefaultSettings {
static const unsigned SysExMaxSize = 4104; // Accept SysEx messages up to 1024 bytes long. static const bool UseRunningStatus = false;
static const bool HandleNullVelocityNoteOnAsNoteOff = true;
static const bool Use1ByteParsing = true;
static const unsigned SysExMaxSize = 4104;
static const bool UseSenderActiveSensing = false;
static const bool UseReceiverActiveSensing = false;
static const uint16_t SenderActiveSensingPeriodicity = 0;
};
struct CustomBaudRateSettings : public MIDI_NAMESPACE::DefaultSerialSettings {
static const long BaudRate = 38400;
}; };
#ifdef MIDI_DEVICE_DIN #ifdef MIDI_DEVICE_DIN
@ -44,8 +54,17 @@ MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, MIDI_DEVICE_DIN, midi_serial, MicroD
#ifdef MIDI_DEVICE_USB_HOST #ifdef MIDI_DEVICE_USB_HOST
USBHost usb_host; USBHost usb_host;
MIDIDevice midi_usb(usb_host); MIDIDevice midi_usb(usb_host);
USBSerial userial(usb_host); #endif
MIDI_CREATE_CUSTOM_INSTANCE(USBSerial, userial, usbhost_midi_serial, MicroDexedSettings);
#ifdef MIDI_DEVICE_USB_HOST_SERIAL
USBHost usb_host;
USBHub hub1(usb_host);
USBHub hub2(usb_host);
USBHub hub3(usb_host);
USBHub hub4(usb_host);
USBSerial_BigBuffer userial(usb_host,1);
MIDI_NAMESPACE::SerialMIDI<USBSerial_BigBuffer, CustomBaudRateSettings> serialMIDI(userial);
MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<USBSerial_BigBuffer, CustomBaudRateSettings>> usbhost_midi_serial((MIDI_NAMESPACE::SerialMIDI<USBSerial_BigBuffer, CustomBaudRateSettings>&)serialMIDI);
#endif #endif
void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity); void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity);
@ -685,11 +704,9 @@ void handleSystemReset_MIDI_DEVICE_USB_HOST(void) {
handleRealTimeSystem_generic(inRealTime, MIDI_USB_HOST); handleRealTimeSystem_generic(inRealTime, MIDI_USB_HOST);
} */ } */
#endif // MIDI_DEVICE_USB_HOST
#ifdef MIDI_DEVICE_USB_HOST_SERIAL
void handleNoteOn_MIDI_DEVICE_USB_HOST_SERIAL(byte inChannel, byte inNoteNumber, byte inVelocity) { void handleNoteOn_MIDI_DEVICE_USB_HOST_SERIAL(byte inChannel, byte inNoteNumber, byte inVelocity) {
handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::NoteOn); handle_generic(inChannel, inNoteNumber, inVelocity, MIDI_BY_USB_HOST, midi::NoteOn);
} }
@ -788,7 +805,7 @@ void handleSystemReset_MIDI_DEVICE_USB_HOST_SERIAL(void) {
{ {
handleRealTimeSystem_generic(inRealTime, MIDI_USB_HOST); handleRealTimeSystem_generic(inRealTime, MIDI_USB_HOST);
} */ } */
#endif // MIDI_DEVICE_USB_HOST #endif // MIDI_DEVICE_USB_HOST_SERIAL
/***************************************** /*****************************************
MIDI_DEVICE_USB MIDI_DEVICE_USB
@ -979,7 +996,13 @@ FLASHMEM void setup_midi_devices(void) {
midi_usb.setHandleActiveSensing(handleActiveSensing_MIDI_DEVICE_USB_HOST); midi_usb.setHandleActiveSensing(handleActiveSensing_MIDI_DEVICE_USB_HOST);
midi_usb.setHandleSystemReset(handleSystemReset_MIDI_DEVICE_USB_HOST); midi_usb.setHandleSystemReset(handleSystemReset_MIDI_DEVICE_USB_HOST);
//midi_usb.setHandleRealTimeSystem(handleRealTimeSystem_MIDI_DEVICE_USB_HOST); //midi_usb.setHandleRealTimeSystem(handleRealTimeSystem_MIDI_DEVICE_USB_HOST);
#ifdef DEBUG
Serial.println(F("MIDI_DEVICE_USB_HOST enabled."));
#endif
#endif
#ifdef MIDI_DEVICE_USB_HOST_SERIAL
usb_host.begin();
userial.begin(USB_HOST_SERIAL_BAUD, USB_HOST_SERIAL_FORMAT); userial.begin(USB_HOST_SERIAL_BAUD, USB_HOST_SERIAL_FORMAT);
usbhost_midi_serial.setHandleNoteOn(handleNoteOn_MIDI_DEVICE_USB_HOST_SERIAL); usbhost_midi_serial.setHandleNoteOn(handleNoteOn_MIDI_DEVICE_USB_HOST_SERIAL);
usbhost_midi_serial.setHandleNoteOff(handleNoteOff_MIDI_DEVICE_USB_HOST_SERIAL); usbhost_midi_serial.setHandleNoteOff(handleNoteOff_MIDI_DEVICE_USB_HOST_SERIAL);
@ -1001,8 +1024,10 @@ FLASHMEM void setup_midi_devices(void) {
usbhost_midi_serial.setHandleSystemReset(handleSystemReset_MIDI_DEVICE_USB_HOST_SERIAL); usbhost_midi_serial.setHandleSystemReset(handleSystemReset_MIDI_DEVICE_USB_HOST_SERIAL);
//usbhost_midi_serial.setHandleRealTimeSystem(handleRealTimeSystem_MIDI_DEVICE_USB_HOST_SERIAL); //usbhost_midi_serial.setHandleRealTimeSystem(handleRealTimeSystem_MIDI_DEVICE_USB_HOST_SERIAL);
usbhost_midi_serial.begin(MIDI_CHANNEL_OMNI);
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("MIDI_DEVICE_USB_HOST enabled.")); Serial.println(F("MIDI_DEVICE_USB_HOST_SERIAL enabled."));
#endif #endif
#endif #endif
@ -1044,6 +1069,9 @@ FLASHMEM void check_midi_devices(void) {
#ifdef MIDI_DEVICE_USB_HOST #ifdef MIDI_DEVICE_USB_HOST
usb_host.Task(); usb_host.Task();
midi_usb.read(); midi_usb.read();
#endif
#ifdef MIDI_DEVICE_USB_HOST_SERIAL
usb_host.Task();
usbhost_midi_serial.read(); usbhost_midi_serial.read();
#endif #endif
} }

Loading…
Cancel
Save