You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.5 KiB

7 months ago
#include "board.hpp"
7 months ago
#include "midix.hpp"
#include "sysex.hpp"
7 months ago
#include <avrstuff/serial_avrdx.hpp>
7 months ago
#include <avrstuff/spi_avrdx.hpp>
7 months ago
#include <avr/interrupt.h>
7 months ago
#include <avr/pgmspace.h>
7 months ago
#include <assert.h>
7 months ago
#include <string.h>
7 months ago
7 months ago
static ringbuf<struct midi_message, 4> midi_q;
static serial_avrdx<2, 8> usbmidi_usart;
7 months ago
static midix midi(usbmidi_usart, midi_q);
7 months ago
// Plan: main pulls from an event queue. Events are generated from the MIDI
// receive vectors as well as from other sources (e.g. timers to implement
// portamento), in close to raw MIDI format via a struct. "Proprietary"
// commands are sent as a SysEx message with an ASCII command string. There is
// one global SysEx buffer per MIDI receiver, so a second message may not be
// sent until the acknowledge is received.
int main(void)
{
board_pins_init();
board_peripherals_init();
7 months ago
7 months ago
usbmidi_usart.set_baud(31250);
7 months ago
usbmidi_usart.start(true, true, 'N', false);
sei();
7 months ago
spi_avrdx<0> hspi;
hspi.init(spi_avrdx<0>::clockdiv::div2, true, 0);
usbmidi_usart.rxcie(true);
7 months ago
for (;;)
{
7 months ago
char info[64];
struct midi_message m;
if (!midi_q.pop(m))
continue;
uint8_t cmd = MIDI_CMD(m.command);
uint8_t chan = MIDI_CMD_CHAN(m.command);
if (cmd == MIDI_ICMD_SYSEX)
{
sysex_handle(&m);
7 months ago
m.source->sysex_release_buffer(m.content);
}
else
{
}
7 months ago
}
}
void operator delete(void * p, unsigned int sz)
{
assert(false && "ouch!");
for(;;);
}
ISR(USART2_DRE_vect)
{
midi.dre();
7 months ago
}
ISR(USART2_RXC_vect)
{
7 months ago
midi.rxc();
7 months ago
}