68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
#include "SerialMIDI_Interface.hpp"
|
|
#include "hardware/gpio.h"
|
|
|
|
BEGIN_CS_NAMESPACE
|
|
|
|
void HardwareSerialMIDI_Interface::begin() {
|
|
uart_init(uart, MIDI_BAUD);
|
|
gpio_set_function(txPin, GPIO_FUNC_UART);
|
|
gpio_set_function(rxPin, GPIO_FUNC_UART);
|
|
}
|
|
|
|
void HardwareSerialMIDI_Interface::update() {
|
|
MIDI_Interface::updateIncoming(this);
|
|
}
|
|
|
|
MIDIReadEvent HardwareSerialMIDI_Interface::read() {
|
|
return parser.pull(UARTPuller{uart});
|
|
}
|
|
|
|
ChannelMessage HardwareSerialMIDI_Interface::getChannelMessage() const {
|
|
return parser.getChannelMessage();
|
|
}
|
|
|
|
SysCommonMessage HardwareSerialMIDI_Interface::getSysCommonMessage() const {
|
|
return parser.getSysCommonMessage();
|
|
}
|
|
|
|
RealTimeMessage HardwareSerialMIDI_Interface::getRealTimeMessage() const {
|
|
return parser.getRealTimeMessage();
|
|
}
|
|
|
|
SysExMessage HardwareSerialMIDI_Interface::getSysExMessage() const {
|
|
return parser.getSysExMessage();
|
|
}
|
|
|
|
void HardwareSerialMIDI_Interface::sendChannelMessageImpl(ChannelMessage msg) {
|
|
if (msg.hasTwoDataBytes()) {
|
|
uint8_t buf[3] = {msg.header, msg.data1, msg.data2};
|
|
uart_write_blocking(uart, buf, 3);
|
|
} else {
|
|
uint8_t buf[2] = {msg.header, msg.data1};
|
|
uart_write_blocking(uart, buf, 2);
|
|
}
|
|
}
|
|
|
|
void HardwareSerialMIDI_Interface::sendSysCommonImpl(SysCommonMessage msg) {
|
|
uint8_t ndata = msg.getNumberOfDataBytes();
|
|
if (ndata == 2) {
|
|
uint8_t buf[3] = {msg.header, msg.data1, msg.data2};
|
|
uart_write_blocking(uart, buf, 3);
|
|
} else if (ndata == 1) {
|
|
uint8_t buf[2] = {msg.header, msg.data1};
|
|
uart_write_blocking(uart, buf, 2);
|
|
} else {
|
|
uart_write_blocking(uart, &msg.header, 1);
|
|
}
|
|
}
|
|
|
|
void HardwareSerialMIDI_Interface::sendSysExImpl(SysExMessage msg) {
|
|
uart_write_blocking(uart, msg.data, msg.length);
|
|
}
|
|
|
|
void HardwareSerialMIDI_Interface::sendRealTimeImpl(RealTimeMessage msg) {
|
|
uart_write_blocking(uart, &msg.message, 1);
|
|
}
|
|
|
|
END_CS_NAMESPACE
|