...
 
Commits (2)
......@@ -106,7 +106,7 @@ main(void)
prev_clock = clock;
uint8_t status, data1, data2;
if (midi_read(&status, &data1, &data2) == MIDI_READ_NO_DATA) {
if (midi_read(&status, &data1, &data2) != MIDI_READ_OK) {
continue;
}
......
......@@ -18,7 +18,7 @@ midi_set_channel(uint8_t channel)
midi_channel = channel & 0xf;
}
uint8_t status;
uint8_t _status;
enum {
MIDI_MAX_DATA_LEN = 2,
......@@ -55,19 +55,27 @@ clear_data()
uint8_t
midi_status(void)
{
return status;
return _status;
}
uint8_t
midi_available(void)
void
midi_set_status(uint8_t status)
{
return (status < MIDI_NUM_STATUSES) && (data_len(status) == parsed_len);
_status = status;
}
void
reset_status()
status_init(void)
{
clear_data();
midi_set_status(MIDI_NUM_STATUSES);
}
uint8_t
midi_available(void)
{
status = MIDI_NUM_STATUSES;
uint8_t status = midi_status();
return (status < MIDI_NUM_STATUSES) && (data_len(status) == parsed_len);
}
void
......@@ -80,20 +88,21 @@ midi_parse(uint8_t midi_byte)
for (uint8_t i = 0; i < MIDI_NUM_STATUSES; i++) {
if (midi_byte == ((statuses[i] << 4) | midi_channel)) {
status = i;
midi_set_status(i);
clear_data();
return;
}
}
uint8_t status = midi_status();
if (status == MIDI_NUM_STATUSES) {
return;
}
if (midi_byte >= 128) {
// We were expecting a 7-bit midi data value. Something is wrong.
reset_status();
clear_data();
status_init();
return;
}
......@@ -105,13 +114,6 @@ midi_parse(uint8_t midi_byte)
data[parsed_len++] = midi_byte;
}
void
status_init(void)
{
clear_data();
reset_status();
}
void
midi_init()
{
......