56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "MIDI_Interface.hpp"
|
|
#include <MIDI_Parsers/SerialMIDI_Parser.hpp>
|
|
|
|
#include "hardware/uart.h"
|
|
|
|
BEGIN_CS_NAMESPACE
|
|
|
|
struct UARTPuller {
|
|
uart_inst_t *uart;
|
|
bool pull(uint8_t &byte) {
|
|
if (!uart_is_readable(uart))
|
|
return false;
|
|
byte = uart_getc(uart);
|
|
return true;
|
|
}
|
|
};
|
|
|
|
class HardwareSerialMIDI_Interface : public MIDI_Interface {
|
|
public:
|
|
HardwareSerialMIDI_Interface(uart_inst_t *uart, uint tx_pin, uint rx_pin)
|
|
: uart(uart), txPin(tx_pin), rxPin(rx_pin) {}
|
|
|
|
void begin() override;
|
|
void update() override;
|
|
|
|
MIDIReadEvent read();
|
|
ChannelMessage getChannelMessage() const;
|
|
SysCommonMessage getSysCommonMessage() const;
|
|
RealTimeMessage getRealTimeMessage() const;
|
|
SysExMessage getSysExMessage() const;
|
|
|
|
protected:
|
|
void sendChannelMessageImpl(ChannelMessage msg) override;
|
|
void sendSysCommonImpl(SysCommonMessage msg) override;
|
|
void sendSysExImpl(SysExMessage msg) override;
|
|
void sendRealTimeImpl(RealTimeMessage msg) override;
|
|
void sendNowImpl() override {}
|
|
|
|
private:
|
|
#if !DISABLE_PIPES
|
|
void handleStall() override { MIDI_Interface::handleStall(this); }
|
|
#ifdef DEBUG_OUT
|
|
const char *getName() const override { return "serial"; }
|
|
#endif
|
|
#endif
|
|
|
|
SerialMIDI_Parser parser;
|
|
uart_inst_t *uart;
|
|
uint txPin;
|
|
uint rxPin;
|
|
};
|
|
|
|
END_CS_NAMESPACE
|