Control Surface
main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
src
MIDI_Interfaces
USBMIDI
USBMIDI.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#ifndef CS_USB_MIDI_NOT_SUPPORTED
4
5
#include <
AH/Containers/Array.hpp
>
6
#include <AH/STL/cstdint>
7
#include <Settings/NamespaceSettings.hpp>
8
9
#ifdef ARDUINO_ARCH_ESP32
10
#include <esp_arduino_version.h>
11
#include <sdkconfig.h>
12
#endif
13
14
BEGIN_CS_NAMESPACE
15
16
inline
AH::Array<uint8_t, 4>
u32_to_bytes
(uint32_t u) {
17
return
{{
18
uint8_t((u >> 0) & 0xFF),
19
uint8_t((u >> 8) & 0xFF),
20
uint8_t((u >> 16) & 0xFF),
21
uint8_t((u >> 24) & 0xFF),
22
}};
23
}
24
25
inline
uint32_t
bytes_to_u32
(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3) {
26
return
(uint32_t(b0) << 0) |
//
27
(uint32_t(b1) << 8) |
//
28
(uint32_t(b2) << 16) |
//
29
(uint32_t(b3) << 24);
//
30
}
31
32
inline
uint32_t
bytes_to_u32
(
AH::Array<uint8_t, 4>
b) {
33
return
(uint32_t(b.data[0]) << 0) |
//
34
(uint32_t(b.data[1]) << 8) |
//
35
(uint32_t(b.data[2]) << 16) |
//
36
(uint32_t(b.data[3]) << 24);
//
37
}
38
39
END_CS_NAMESPACE
40
41
#ifdef ARDUINO
42
43
#if defined(TEENSYDUINO)
44
45
#if defined(__AVR__)
/* Teensy 2.x */
46
#include "
USBMIDI_Teensy2.hpp
"
47
BEGIN_CS_NAMESPACE
48
using
USBDeviceMIDIBackend
=
Teensy2_USBDeviceMIDIBackend
;
49
END_CS_NAMESPACE
50
51
#elif defined(__MK20DX128__)
/* Teensy 3.0 */
\
52
|| defined(__MK20DX256__)
/* Teensy 3.1/3.2 */
\
53
|| defined(__MK64FX512__)
/* Teensy 3.5 */
\
54
|| defined(__MK66FX1M0__)
/* Teensy 3.6 */
55
#include "
USBMIDI_Teensy3.hpp
"
56
BEGIN_CS_NAMESPACE
57
using
USBDeviceMIDIBackend
=
Teensy3_USBDeviceMIDIBackend
;
58
END_CS_NAMESPACE
59
60
#elif defined(__IMXRT1062__) || defined(__IMXRT1052__)
/* Teensy 4.0 */
61
#include "
USBMIDI_Teensy4.hpp
"
62
BEGIN_CS_NAMESPACE
63
using
USBDeviceMIDIBackend
=
Teensy4_USBDeviceMIDIBackend
;
64
END_CS_NAMESPACE
65
66
#elif defined(__MKL26Z64__)
/* Teensy LC */
67
#include "
USBMIDI_TeensyLC.hpp
"
68
BEGIN_CS_NAMESPACE
69
using
USBDeviceMIDIBackend
=
TeensyLC_USBDeviceMIDIBackend
;
70
END_CS_NAMESPACE
71
72
#else
73
#warning "Unknown Teensy board, please open an issue on GitHub" \
74
"https://github.com/tttapa/Arduino-Helpers"
75
// Fall back to the MIDIUSB library and hope for the best
76
#include "
USBMIDI_MIDIUSB.hpp
"
77
BEGIN_CS_NAMESPACE
78
using
USBDeviceMIDIBackend
=
MIDIUSB_USBDeviceMIDIBackend
;
79
END_CS_NAMESPACE
80
#endif
81
82
#elif defined(ARDUINO_ARCH_ESP32) && (ESP_ARDUINO_VERSION_MAJOR >= 3) && \
83
(CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3)
84
85
#ifndef ARDUINO_USB_MODE
86
#error "ESP32-S2/S3 expects ARDUINO_USB_MODE to be set"
87
#endif
88
#if ARDUINO_USB_MODE != 1
89
#include "
USBMIDI_ESP32.hpp
"
90
BEGIN_CS_NAMESPACE
91
using
USBDeviceMIDIBackend
=
ESP32_USBDeviceMIDIBackend
;
92
END_CS_NAMESPACE
93
#else
94
#define CS_USB_MIDI_NOT_SUPPORTED 1
95
#pragma message( \
96
"ESP32-S2/S3: USB MIDI not enabled. Set the Tools > USB Type setting to \"USB-OTG\" to enable it.")
97
#endif
98
99
#elif defined(ARDUINO_ARCH_MBED)
100
101
#include "
USBMIDI_Arduino_mbed.hpp
"
102
BEGIN_CS_NAMESPACE
103
using
USBDeviceMIDIBackend
=
Arduino_mbed_USBDeviceMIDIBackend
;
104
END_CS_NAMESPACE
105
106
#elif defined(ARDUINO_ARCH_RP2040) && defined(USE_TINYUSB)
107
108
#include "
USBMIDI_Adafruit_TinyUSB.hpp
"
109
BEGIN_CS_NAMESPACE
110
using
USBDeviceMIDIBackend
=
Adafruit_TinyUSB_USBDeviceMIDIBackend
;
111
END_CS_NAMESPACE
112
113
#else
114
115
#include <
AH/Arduino-Wrapper.h
>
116
#ifdef USBCON
117
#include "
USBMIDI_MIDIUSB.hpp
"
118
BEGIN_CS_NAMESPACE
119
using
USBDeviceMIDIBackend
=
MIDIUSB_USBDeviceMIDIBackend
;
120
END_CS_NAMESPACE
121
#else
122
#define CS_USB_MIDI_NOT_SUPPORTED 1
123
#endif
124
125
#endif
126
127
#else
128
129
#include "
USBMIDI_Mock.hpp
"
130
131
#endif
132
133
#endif
// CS_USB_MIDI_NOT_SUPPORTED
Arduino-Wrapper.h
Array.hpp
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:14
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:11
u32_to_bytes
AH::Array< uint8_t, 4 > u32_to_bytes(uint32_t u)
Definition
USBMIDI.hpp:16
bytes_to_u32
uint32_t bytes_to_u32(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3)
Definition
USBMIDI.hpp:25
USBMIDI_Adafruit_TinyUSB.hpp
USBMIDI_Arduino_mbed.hpp
USBMIDI_ESP32.hpp
USBMIDI_MIDIUSB.hpp
USBMIDI_Mock.hpp
USBMIDI_Teensy2.hpp
USBMIDI_Teensy3.hpp
USBMIDI_Teensy4.hpp
Teensy4_USBDeviceMIDIBackend
Teensy3_USBDeviceMIDIBackend Teensy4_USBDeviceMIDIBackend
Definition
USBMIDI_Teensy4.hpp:3
USBMIDI_TeensyLC.hpp
TeensyLC_USBDeviceMIDIBackend
Teensy3_USBDeviceMIDIBackend TeensyLC_USBDeviceMIDIBackend
Definition
USBMIDI_TeensyLC.hpp:3
AH::SPIShiftRegisterOut
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
Definition
SPIShiftRegisterOut.hpp:28
Adafruit_TinyUSB_USBDeviceMIDIBackend
Definition
USBMIDI_Adafruit_TinyUSB.hpp:8
Arduino_mbed_USBDeviceMIDIBackend
Definition
USBMIDI_Arduino_mbed.hpp:8
ESP32_USBDeviceMIDIBackend
Definition
USBMIDI_ESP32.hpp:9
MIDIUSB_USBDeviceMIDIBackend
Definition
USBMIDI_MIDIUSB.hpp:8
Teensy2_USBDeviceMIDIBackend
Definition
USBMIDI_Teensy2.hpp:8
Teensy3_USBDeviceMIDIBackend
Definition
USBMIDI_Teensy3.hpp:7
USBDeviceMIDIBackend
Definition
USBMIDI_Mock.hpp:8
Generated by
1.10.0