-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utilities.h
80 lines (71 loc) · 2.3 KB
/
Utilities.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// This file is part of Necroware's GamePort adapter firmware.
// Copyright (C) 2021 Necroware
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <Arduino.h>
//#include <SoftwareSerial.h>
#include <stdarg.h>
#include <stdio.h>
/// Debug messages on serial port are turned off by default. Comment the following
/// line to enable logging to the serial port.
/// Arduino Micro seems somehow to share the serial port with the USB interface.
/// If the serial port will be activated, the operating system will no longer
/// recognize the USB device!
//#define NDEBUG
#ifdef NDEBUG
#define initLog()
#define log(...)
#else
inline void initLog() {
Serial.begin(9600);
while(!Serial);
}
inline void log(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
char buffer[512];
vsnprintf(buffer, sizeof(buffer), fmt, args);
va_end(args);
Serial.println(buffer);
}
#endif // !NDEBUG
/// Interrupt guard (RAII).
///
/// This class is used to deactivate the interrupts in performance
/// critical sections. The interrupt is reactivated as soon as this
/// guard runs out of scope.
struct InterruptStopper {
InterruptStopper() { noInterrupts(); }
~InterruptStopper() { interrupts(); }
InterruptStopper(const InterruptStopper&) = delete;
InterruptStopper(InterruptStopper&&) = delete;
InterruptStopper& operator=(const InterruptStopper&) = delete;
InterruptStopper& operator=(InterruptStopper&&) = delete;
};
/*
#define MIDI_TX 5
#define MIDI_RX 9
SoftwareSerial serialMidi = SoftwareSerial(MIDI_RX, MIDI_TX);
void serialMidiInit()
{
//log("Initializing MIDI serial...");
serialMidi.begin(31250);
while (!serialMidi.available()) {}
}
*/
void serialMidiInit()
{
Serial1.begin(31250, SERIAL_8N1);
}