Commit acec7613 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Group midi initialization

parent 2a1d8332
......@@ -9,18 +9,6 @@ UART I/O and MIDI parsing.
#include "midi.h"
#include <avr/io.h>
void
midi_init()
{
UBRR0H = 0;
UBRR0L = 31;
UCSR0B = _BV(RXEN0);
// Enable pull-up resistor on RX pin
PORTD |= _BV(PORTD0);
}
static uint8_t midi_channel;
void
......@@ -29,9 +17,9 @@ midi_set_channel(uint8_t channel)
midi_channel = channel & 0xf;
}
uint8_t status = MIDI_NUM_STATUSES;
uint16_t data = 0;
static uint8_t parsed_len = 0;
uint8_t status;
uint16_t data;
static uint8_t parsed_len;
const uint8_t statuses[MIDI_NUM_STATUSES] = {
0b1001, // note on
......@@ -62,6 +50,19 @@ midi_available(void)
return (status < MIDI_NUM_STATUSES) && (data_len(status) == parsed_len);
}
void
clear_data()
{
parsed_len = 0;
data = 0;
}
void
reset_status()
{
status = MIDI_NUM_STATUSES;
}
void
midi_parse(uint8_t midi_byte)
{
......@@ -82,14 +83,13 @@ midi_parse(uint8_t midi_byte)
}
if (midi_byte & 0x80) {
status = MIDI_NUM_STATUSES;
data = 0;
reset_status();
clear_data();
return;
}
if (parsed_len >= 2) {
data = 0;
parsed_len = 0;
clear_data();
}
switch (parsed_len ) {
......@@ -104,6 +104,21 @@ midi_parse(uint8_t midi_byte)
}
}
void
midi_init()
{
UBRR0H = 0;
UBRR0L = 31;
UCSR0B = _BV(RXEN0);
// Enable pull-up resistor on RX pin
PORTD |= _BV(PORTD0);
clear_data();
reset_status();
}
uint8_t
midi_read(void)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment