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

add midi UART driver

parent 27f79e96
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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();
+27 −20
Original line number Diff line number Diff line
@@ -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,11 +61,13 @@ int main(void)
	
    while(1)
    {
		//READ PANEL IO
		panel_update();
		
		if (uart_read(&uartchar)){
			//POLL MIDI USART 
		parse_midi(usartchar);
			parse_midi(uartchar);
		
		//READ PANEL IO
			//PANEL STATE
		
			//HANDLE WAVE IO
			for (uint8_t i = 0; i < TESLA_MAX_CHANNELS; i++){
@@ -76,11 +82,12 @@ int main(void)
					}
				
				} /*else if (notes[i].update){
				//Handle renewed velocity
					//TODO: Handle renewed velocity
				
				}*/
			}
		
		}
		// TODO: handle updated level pot
		watchdog_pet();
    }
}
 No newline at end of file

TeslaMidi/uart.c

0 → 100644
+34 −0
Original line number Diff line number Diff line
/*
 * 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

TeslaMidi/uart.h

0 → 100644
+19 −0
Original line number Diff line number Diff line
/*
 * 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