Commit 500293a5 authored by Snorre Nilssen Vestli's avatar Snorre Nilssen Vestli

add midi UART driver

parent 27f79e96
......@@ -85,7 +85,7 @@ void parse_midi(char input)
midi_buffer[midi_current_byte++] = input;
//find free channel & update
midi_add_note(midi_buffer[0],midi_buffer[1]);
midi_state == FREE;
midi_state = FREE;
} else {
tesla_panic();
}
......@@ -105,7 +105,7 @@ void parse_midi(char input)
midi_buffer[midi_current_byte++] = input;
midi_clear_note(midi_buffer[0],midi_buffer[1]);
midi_state == FREE;
midi_state = FREE;
} else {
tesla_panic();
......
......@@ -12,6 +12,7 @@
#include "panel_io.h"
#include "watchdog.h"
#include "clock.h"
#include "uart.h"
#include "tesla_io.h"
#include "tesladefs.h"
......@@ -19,7 +20,7 @@
int main(void)
{
uint8_t error;
char usartchar;
char uartchar;
note_t notes[TESLA_MAX_CHANNELS];
midi_channel_t midi_channel;
......@@ -33,6 +34,9 @@ int main(void)
//PANEL IO INIT
panel_init();
//midi UART init
uart_init();
//WATCHDOG INIT
error = watchdog_init();
if (error){
......@@ -57,30 +61,33 @@ int main(void)
while(1)
{
//POLL MIDI USART
parse_midi(usartchar);
//READ PANEL IO
//PANEL STATE
panel_update();
if (uart_read(&uartchar)){
//POLL MIDI USART
parse_midi(uartchar);
//HANDLE WAVE IO
for (uint8_t i = 0; i < TESLA_MAX_CHANNELS; i++){
if (notes[i].change){
notes[i].change = 0;
if (notes[i].on){
// turn on relevant channel
tesla_channel_play(notes[i].tesla_channel, notes[i].note, panel_get_level());
} else {
//turn off relevant channel
tesla_channel_stop(notes[i].tesla_channel);
}
//HANDLE WAVE IO
for (uint8_t i = 0; i < TESLA_MAX_CHANNELS; i++){
if (notes[i].change){
notes[i].change = 0;
if (notes[i].on){
// turn on relevant channel
tesla_channel_play(notes[i].tesla_channel, notes[i].note, panel_get_level());
} else {
//turn off relevant channel
tesla_channel_stop(notes[i].tesla_channel);
}
} /*else if (notes[i].update){
//Handle renewed velocity
} /*else if (notes[i].update){
//TODO: Handle renewed velocity
}*/
}*/
}
}
// TODO: handle updated level pot
watchdog_pet();
}
}
\ No newline at end of file
/*
* uart.c
*
* Created: 26.08.2014 23:00:09
* Author: Snorre
*/
#include <avr/io.h>
#include "uart.h"
void uart_init(){
//enable uart
MIDI_UART.CTRLB |= USART_RXEN_bm;
//set baud
MIDI_UART.BAUDCTRLA = 63; // = (32MHz/(2^0 * 16 * 31250)) - 1
}
uint8_t uart_read(char* output){
if (MIDI_UART.STATUS & USART_RXCIF_bm){ // is data ready?
MIDI_UART.STATUS = USART_RXCIF_bm; // write flag to clear flag
*output = MIDI_UART.DATA;
return 1;
} else {
return 0;
}
}
\ No newline at end of file
/*
* uart.h
*
* Created: 26.08.2014 22:43:05
* Author: Snorre
*/
#ifndef UART_H_
#define UART_H_
void uart_init();
uint8_t uart_read(char* output);
#define MIDI_UART USARTC1
#endif /* UART_H_ */
\ No newline at end of file
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