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
27 uint8_t c, intr_state;
28
29 intr_state = SREG;
30 cli();
31 if (!usb_configuration) {
32 SREG = intr_state;
33 return MIDIUSBPacket_t {0};
34 }
35 UENUM = MIDI_RX_ENDPOINT;
36retry:
37 c = UEINTX;
38 if (!(c & (1 << RWAL))) {
39 if (c & (1 << RXOUTI)) {
40 UEINTX = 0x6B;
41 goto retry;
42 }
43 SREG = intr_state;
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;
53 SREG = intr_state;
54
55 return packet;
56}
57
59 uint8_t intr_state, timeout;
60
61 if (!usb_configuration)
62 return;
63 intr_state = SREG;
64 cli();
65 UENUM = MIDI_TX_ENDPOINT;
66 timeout = UDFNUML + 2;
67 while (1) {
68 // are we ready to transmit?
69 if (UEINTX & (1 << RWAL))
70 break;
71 SREG = intr_state;
72 if (UDFNUML == timeout)
73 return;
74 if (!usb_configuration)
75 return;
76 intr_state = SREG;
77 cli();
78 UENUM = MIDI_TX_ENDPOINT;
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;
86 SREG = intr_state;
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
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
T data[N]
Definition Array.hpp:33
void write(MIDIUSBPacket_t data)