Commit bf40d446 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Invert midi_read return value

parent d77229c0
......@@ -32,7 +32,7 @@ void uart_buffer_push(uint8_t x) {
uint8_t uart_buffer_pop(uint8_t *x) {
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
if (uart_buffer.head == uart_buffer.tail) {
return 1; // error: uart_buffer is empty
return false; // error: uart_buffer is empty
}
*x = uart_buffer.data[uart_buffer.head];
......@@ -40,7 +40,7 @@ uint8_t uart_buffer_pop(uint8_t *x) {
(uart_buffer.head + 1) % ARRAY_SIZE(uart_buffer.data);
}
return 0;
return true;
}
ISR(USART_RX_vect) {
......@@ -171,13 +171,13 @@ int main(void) {
do_clock_update();
uint8_t status, data1, data2;
if (midi_read(&status, &data1, &data2) != MIDI_READ_OK) {
if (!midi_read(&status, &data1, &data2)) {
continue;
}
switch (status) {
case MIDI_NOTE_ON:
if (data2 > 0) {
if (data2) {
programs[current_program].note_on(data1);
} else {
programs[current_program].note_off(data1);
......
......@@ -13,8 +13,8 @@ uint8_t midi_load(uint8_t *status, uint8_t *data1, uint8_t *data2);
{ \
uint8_t _status, _avail, _data1, _data2; \
_avail = midi_load(&_status, &_data1, &_data2); \
assert((_avail != MIDI_READ_OK) == !avail); \
if (_avail == MIDI_READ_OK) { \
assert(!_avail == !avail); \
if (_avail) { \
assert(((_data1 << 8) | _data2) == data); \
assert(_status == status); \
} \
......@@ -24,8 +24,8 @@ uint8_t midi_load(uint8_t *status, uint8_t *data1, uint8_t *data2);
{ \
uint8_t _status, _avail, _data1, _data2; \
_avail = midi_load(&_status, &_data1, &_data2); \
assert((_avail != MIDI_READ_OK) == !avail); \
if (_avail == MIDI_READ_OK) { \
assert(!_avail == !avail); \
if (_avail) { \
assert((_data1 << 8) == data1); \
assert(_status == status); \
} \
......
......@@ -18,7 +18,7 @@ const uint8_t statuses[] = {
[MIDI_PITCH_BEND] = 0b1110,
};
uint8_t midi_data_available(void) {
bool midi_data_available(void) {
if (midi.status == MIDI_PROGRAM_CHANGE) {
return midi.data_received == 1;
}
......@@ -69,22 +69,18 @@ void midi_parse(uint8_t b) {
void midi_init() { midi_status_init(); }
uint8_t midi_load(uint8_t *status, uint8_t *data1, uint8_t *data2) {
if (!midi_data_available()) {
return MIDI_READ_NO_DATA;
}
*status = midi.status;
*data1 = midi.data[0];
*data2 = midi.data[1];
return MIDI_READ_OK;
return midi_data_available();
}
uint8_t midi_read(uint8_t *status, uint8_t *data1, uint8_t *data2) {
bool midi_read(uint8_t *status, uint8_t *data1, uint8_t *data2) {
uint8_t uart_data;
if (uart_read(&uart_data)) {
return MIDI_READ_NO_DATA;
if (!uart_read(&uart_data)) {
return false;
}
midi_parse(uart_data);
......
#ifndef MIDI_H
#define MIDI_H
#include <stdbool.h>
#include <stdint.h>
enum _statuses {
......@@ -24,10 +25,6 @@ enum _cc {
void midi_init(void);
void midi_set_channel(uint8_t channel);
enum { MIDI_READ_OK,
MIDI_READ_NO_DATA,
};
uint8_t midi_read(uint8_t *status, uint8_t *data1, uint8_t *data2);
bool midi_read(uint8_t *status, uint8_t *data1, uint8_t *data2);
#endif
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