FastLED 3.9.7
Loading...
Searching...
No Matches
serialMIDI.h
Go to the documentation of this file.
1
27 #pragma once
28
29#include "midi_Namespace.h"
30
31BEGIN_MIDI_NAMESPACE
32
34{
39 static const long BaudRate = 31250;
40};
41
42template <class SerialPort, class _Settings = DefaultSerialSettings>
44{
45 typedef _Settings Settings;
46
47public:
48 SerialMIDI(SerialPort& inSerial)
49 : mSerial(inSerial)
50 {
51 };
52
53public:
54 static const bool thruActivated = true;
55
56 void begin()
57 {
58 // Initialise the Serial port
59 #if defined(AVR_CAKE)
60 mSerial. template open<Settings::BaudRate>();
61 #else
62 mSerial.begin(Settings::BaudRate);
63 #endif
64 }
65
66 bool beginTransmission(MidiType)
67 {
68 return true;
69 };
70
71 void write(byte value)
72 {
73 mSerial.write(value);
74 };
75
76 void endTransmission()
77 {
78 };
79
80 byte read()
81 {
82 return mSerial.read();
83 };
84
85 unsigned available()
86 {
87 return mSerial.available();
88 };
89
90private:
91 SerialPort& mSerial;
92};
93
99#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
100 MIDI_NAMESPACE::SerialMIDI<Type> serial##Name(SerialPort);\
101 MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type>> Name((MIDI_NAMESPACE::SerialMIDI<Type>&)serial##Name);
102
103#if defined(ARDUINO_SAM_DUE) || defined(USBCON) || defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
104 // Leonardo, Due and other USB boards use Serial1 by default.
105 #define MIDI_CREATE_DEFAULT_INSTANCE() \
106 MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
107#else
112 #define MIDI_CREATE_DEFAULT_INSTANCE() \
113 MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
114#endif
115
121#define MIDI_CREATE_CUSTOM_INSTANCE(Type, SerialPort, Name, Settings) \
122 MIDI_NAMESPACE::SerialMIDI<Type, Settings> serial##Name(SerialPort);\
123 MIDI_NAMESPACE::MidiInterface<MIDI_NAMESPACE::SerialMIDI<Type, Settings>> Name((MIDI_NAMESPACE::SerialMIDI<Type, Settings>&)serial##Name);
124
125END_MIDI_NAMESPACE
MidiType
Definition midi_Defs.h:95
MIDI Library for the Arduino - Namespace declaration.
static const long BaudRate
Definition serialMIDI.h:39