78 rx_buffer =
config.rx_buffer;
79 rx_buffer_size =
config.rx_buffer_size;
82 std::fill(rx_buffer, rx_buffer + rx_buffer_size, 0);
91 parse_context_ = context;
96 rx_buffer, rx_buffer_size, MidiUartTransport::rxCallback,
this);
111 size_t rx_buffer_size;
112 void* parse_context_;
124 static void rxCallback(
uint8_t* data,
134 if(transport->parse_callback_)
136 transport->parse_callback_(
137 data,
size, transport->parse_context_);
151template <
typename Transport>
177 transport_.StartRx(MidiHandler::ParseCallback,
this);
186 if(!transport_.RxActive())
189 transport_.FlushRx();
197 bool HasEvents()
const {
return event_q_.GetNumElements() > 0; }
225 event_q_.PushBack(
event);
235 static void ParseCallback(
uint8_t* data,
size_t size,
void* context)
238 for(
size_t i = 0;
i <
size;
i++)
Definition leddriver.h:33
void Init(I2CHandle i2c, const uint8_t(&addresses)[numDrivers], DmaBuffer dma_buffer_a, DmaBuffer dma_buffer_b, Pin oe_pin=Pin(PORTX, 0))
Definition leddriver.h:65
Simple MIDI Handler Parses bytes from an input into valid MidiEvents. The MidiEvents fill a FIFO qu...
Definition midi.h:153
void StartReceive()
Definition midi.h:175
MidiEvent PopEvent()
Definition midi.h:204
void Listen()
Definition midi.h:181
void SendMessage(uint8_t *bytes, size_t size)
Definition midi.h:209
MidiHandler()
Definition midi.h:155
bool RxActive()
Definition midi.h:199
void Parse(uint8_t byte)
Definition midi.h:220
bool HasEvents() const
Definition midi.h:197
void Init(Config config)
Definition midi.h:166
~MidiHandler()
Definition midi.h:156
Utility class for parsing raw byte streams into MIDI messages.
Definition midi_parser.h:16
void Reset()
Reset parser to default state.
bool Parse(uint8_t byte, MidiEvent *event_out)
Parse one MIDI byte. If the byte completes a parsed event, its value will be assigned to the derefere...
void Init()
Definition midi_parser.h:21
Transport layer for sending and receiving MIDI data over UART.
Definition midi.h:25
void StartRx(MidiRxParseCallback parse_callback, void *context)
Start the UART peripheral in listening mode. This will fill an internal data structure in the backgro...
Definition midi.h:89
void Tx(uint8_t *buff, size_t size)
sends the buffer of bytes out of the UART peripheral
Definition midi.h:106
~MidiUartTransport()
Definition midi.h:32
void FlushRx()
This is a no-op for UART transport - Rx is via DMA callback with circular buffer.
Definition midi.h:103
void(* MidiRxParseCallback)(uint8_t *data, size_t size, void *context)
Definition midi.h:27
MidiUartTransport()
Definition midi.h:31
bool RxActive()
returns whether the UART peripheral is actively listening in the background or not
Definition midi.h:100
void Init(Config config)
Initialization of UART using config struct.
Definition midi.h:62
Result DmaListenStart(uint8_t *buff, size_t size, CircularRxCallbackFunctionPtr cb, void *callback_context)
Result PollTx(uint8_t *buff, size_t size)
Result Init(const Config &config)
Result
Definition uart.h:103
void dsy_dma_clear_cache_for_buffer(uint8_t *buffer, size_t size)
Hardware defines and helpers for daisy field platform.
Definition index.h:2
Definition MidiEvent.h:240
Transport::Config transport_config
Definition midi.h:160
Configuration structure for UART MIDI.
Definition midi.h:36
Pin tx
Definition midi.h:39
Pin rx
Definition midi.h:38
UartHandler::Config::Peripheral periph
Definition midi.h:37
size_t rx_buffer_size
Definition midi.h:56
uint8_t * rx_buffer
Definition midi.h:48
representation of hardware port/pin combination
Definition daisy_core.h:193
Peripheral
Definition uart.h:32