Refactor into files
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#include "MidiDriver.h"
|
||||
|
||||
// MIDI UART Pins (GP0/GP1)
|
||||
#define PIN_MIDI_TX 0
|
||||
|
||||
MidiDriver midi;
|
||||
|
||||
MidiDriver::MidiDriver() {
|
||||
}
|
||||
|
||||
void MidiDriver::begin() {
|
||||
mutex_init(&_mutex);
|
||||
Serial1.setTX(PIN_MIDI_TX);
|
||||
Serial1.begin(31250);
|
||||
Serial.println(F("MIDI Serial initialized on GP0/GP1"));
|
||||
}
|
||||
|
||||
void MidiDriver::lock() {
|
||||
mutex_enter_blocking(&_mutex);
|
||||
}
|
||||
|
||||
void MidiDriver::unlock() {
|
||||
mutex_exit(&_mutex);
|
||||
}
|
||||
|
||||
void MidiDriver::sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel) {
|
||||
uint8_t status = 0x90 | (channel - 1);
|
||||
Serial1.write(status);
|
||||
Serial1.write(note);
|
||||
Serial1.write(velocity);
|
||||
}
|
||||
|
||||
void MidiDriver::sendNoteOff(uint8_t note, uint8_t channel) {
|
||||
uint8_t status = 0x80 | (channel - 1);
|
||||
Serial1.write(status);
|
||||
Serial1.write(note);
|
||||
Serial1.write((uint8_t)0);
|
||||
}
|
||||
|
||||
void MidiDriver::sendRealtime(uint8_t status) {
|
||||
Serial1.write(status);
|
||||
}
|
||||
|
||||
void MidiDriver::panic(uint8_t channel) {
|
||||
uint8_t status = 0xB0 | (channel - 1);
|
||||
Serial1.write(status);
|
||||
Serial1.write(123); // All Notes Off
|
||||
Serial1.write((uint8_t)0);
|
||||
}
|
||||
Reference in New Issue
Block a user