Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
USBMIDI_Teensy2.hpp
Go to the documentation of this file.
2
4#include <Settings/NamespaceSettings.hpp>
5
7
15
17
18#ifdef TEENSY_MIDIUSB_ENABLED
19
20#include <usb_private.h>
21
23
26 // https://github.com/PaulStoffregen/cores/blob/73ea157600a7082686d9cc48786a73caa7567da9/usb_midi/usb_api.cpp#L195
28
30 cli();
31 if (!usb_configuration) {
33 return MIDIUSBPacket_t {0};
34 }
36retry:
37 c = UEINTX;
38 if (!(c & (1 << RWAL))) {
39 if (c & (1 << RXOUTI)) {
40 UEINTX = 0x6B;
41 goto retry;
42 }
44 return MIDIUSBPacket_t {0};
45 }
46 MIDIUSBPacket_t packet;
47 packet.data[0] = UEDATX;
48 packet.data[1] = UEDATX;
49 packet.data[2] = UEDATX;
50 packet.data[3] = UEDATX;
51 if (!(UEINTX & (1 << RWAL)))
52 UEINTX = 0x6B;
54
55 return packet;
56}
57
59 uint8_t intr_state, timeout;
60
62 return;
64 cli();
66 timeout = UDFNUML + 2;
67 while (1) {
68 // are we ready to transmit?
69 if (UEINTX & (1 << RWAL))
70 break;
72 if (UDFNUML == timeout)
73 return;
75 return;
77 cli();
79 }
80 UEDATX = data.data[0];
81 UEDATX = data.data[1];
82 UEDATX = data.data[2];
83 UEDATX = data.data[3];
84 if (!(UEINTX & (1 << RWAL)))
85 UEINTX = 0x3A;
87}
88
90 // TODO: I think the UEINTX = 0x3A actually sends/flushes the data, but I'm
91 // not sure, and I don't have the right hardware to test it.
92}
93
95 return false;
96}
97
99
100#endif
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Array< T, N > copyAs(const Array< U, N > &src)
Copy an Array to an Array of a different type.
T data[N]
Definition Array.hpp:33
void write(MIDIUSBPacket_t data)