8 #ifdef TEENSY_MIDIUSB_ENABLED
9 #ifndef __AVR_AT90USB1286__ // Probably Teensy 3.x
12 #include <usb_private.h>
14 #elif defined TEENSYDUINO
16 "Teensy: USB MIDI not enabled. Enable it from the Tools > USB Type menu."
20 #if defined(USBCON) && !defined(TEENSYDUINO)
25 #include <gmock-wrapper.h>
29 #if defined(USBCON) || defined(TEENSY_MIDIUSB_ENABLED) || !defined(ARDUINO)
57 W_SUGGEST_OVERRIDE_OFF
60 void(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t));
62 MOCK_METHOD0(readUSBPacket, MIDIUSBPacket_t(
void));
69 MIDIUSBPacket_t
rx_packet = readUSBPacket();
80 #elif defined(TEENSYDUINO)
81 #ifndef __AVR_AT90USB1286__ // Probably Teensy 3.x
84 usb_midi_write_packed((cn << 4) | cin |
90 void writeUSBPacket(uint8_t cn, uint8_t cin, uint8_t d0, uint8_t d1,
92 uint8_t intr_state, timeout;
94 if (!usb_configuration)
98 UENUM = MIDI_TX_ENDPOINT;
99 timeout = UDFNUML + 2;
102 if (UEINTX & (1 << RWAL))
105 if (UDFNUML == timeout)
107 if (!usb_configuration)
111 UENUM = MIDI_TX_ENDPOINT;
113 UEDATX = (cn << 4) | cin;
117 if (!(UEINTX & (1 << RWAL)))
121 #endif // Teensy++ 2.0
126 #elif defined(USBCON)
128 void writeUSBPacket(uint8_t cn, uint8_t cin, uint8_t d0, uint8_t d1,
130 midiEventPacket_t msg = {
131 uint8_t((cn << 4) | cin),
136 MidiUSB.sendMIDI(msg);
139 void flush() { MidiUSB.flush(); }
143 void sendImpl(uint8_t m, uint8_t c, uint8_t d1, uint8_t d2,
144 uint8_t cn)
override {
152 void sendImpl(uint8_t m, uint8_t c, uint8_t d1, uint8_t cn)
override {
156 void sendImpl(
const uint8_t *data,
size_t length, uint8_t cn)
override {
163 case 3:
writeUSBPacket(cn, 0x7, data[0], data[1], data[2]);
break;
181 #if defined(TEENSYDUINO)
182 #ifndef __AVR_AT90USB1286__ // Probably Teensy 3.x
186 if (!usb_configuration)
208 if (index < rx_packet->len) {
222 #else // Teensy++ 2.0
228 uint8_t c, intr_state;
232 if (!usb_configuration) {
236 UENUM = MIDI_RX_ENDPOINT;
239 if (!(c & (1 << RWAL))) {
240 if (c & (1 << RXOUTI)) {
251 if (!(UEINTX & (1 << RWAL)))
262 #endif // Teensy++ 2.0
265 #elif defined(USBCON)
268 midiEventPacket_t midipacket = MidiUSB.read();
269 uint8_t
rx_packet[4] = {midipacket.header, midipacket.byte1,
270 midipacket.byte2, midipacket.byte3};
271 if (!midipacket.header)
283 #if defined(TEENSYDUINO) && !defined(__AVR_AT90USB1286__)
293 #elif !defined(USBCON) && !defined(TEENSYDUINO)