Commit af9dbb4a authored by Jacob Vosmaer's avatar Jacob Vosmaer

Break out uart code to allow midi parser testing

parent acec7613
PRG = crowbx
OBJ = crowbx.o midi.o dac.o voice.o
OBJ = crowbx.o midi.o dac.o voice.o uart.o
MCU_TARGET = atmega328p
#MCU_TARGET = at90s2313
#MCU_TARGET = at90s2333
......
......@@ -7,9 +7,8 @@ UART I/O and MIDI parsing.
*/
#include "midi.h"
#include <avr/io.h>
static uint8_t midi_channel;
uint8_t midi_channel;
void
midi_set_channel(uint8_t channel)
......@@ -19,7 +18,7 @@ midi_set_channel(uint8_t channel)
uint8_t status;
uint16_t data;
static uint8_t parsed_len;
uint8_t parsed_len;
const uint8_t statuses[MIDI_NUM_STATUSES] = {
0b1001, // note on
......@@ -105,37 +104,28 @@ midi_parse(uint8_t midi_byte)
}
void
midi_init()
status_init(void)
{
UBRR0H = 0;
UBRR0L = 31;
UCSR0B = _BV(RXEN0);
// Enable pull-up resistor on RX pin
PORTD |= _BV(PORTD0);
clear_data();
reset_status();
}
void
midi_init()
{
uart_init();
status_init();
}
uint8_t
midi_read(void)
{
uint8_t uart_status = UCSR0A;
if (!(uart_status & _BV(RXC0))) {
// No UART data available
return 0;
}
// Read data to clear all status bits
uint8_t uart_data = UDR0;
if (uart_status & (_BV(FE0) | _BV(DOR0) | _BV(UPE0))) {
// There was a UART error
uint16_t uart_data = uart_read();
if (uart_data >> 8) {
// uart error
return 0;
}
midi_parse(uart_data);
midi_parse(uart_data & 0xff);
return midi_available();
}
#include <avr/io.h>
#include "uart.h"
void
uart_init(void)
{
UBRR0H = 0;
UBRR0L = 31;
UCSR0B = _BV(RXEN0);
// Enable pull-up resistor on RX pin
PORTD |= _BV(PORTD0);
}
#define UART_ERROR (1<<8)
uint16_t
uart_read(void)
{
uint8_t uart_status = UCSR0A;
if (!(uart_status & _BV(RXC0))) {
// No UART data available
return UART_ERROR;
}
// Read data to clear all status bits
uint8_t uart_data = UDR0;
if (uart_status & (_BV(FE0) | _BV(DOR0) | _BV(UPE0))) {
// There was a UART error
return UART_ERROR;
}
return uart_data;
}
\ No newline at end of file
#ifndef uart_h
#define uart_h
uint16_t uart_read(void);
void uart_init(void);
#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