From d7c4299cd4aaaabcce3c5d6eab3a4f693dd784cc Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Sat, 22 Jul 2017 12:22:52 +0200 Subject: midi input handling redone --- floppyMusic/main.c | 5 ++- floppyMusic/midi.c | 107 +++++++++++++++++++++++++++++++++-------------------- floppyMusic/midi.h | 23 ++++++++++-- 3 files changed, 88 insertions(+), 47 deletions(-) (limited to 'floppyMusic') diff --git a/floppyMusic/main.c b/floppyMusic/main.c index 8719312..56df5b2 100644 --- a/floppyMusic/main.c +++ b/floppyMusic/main.c @@ -8,6 +8,7 @@ //#define _TEST_MODE #include +#include #include "floppy.h" @@ -37,8 +38,8 @@ int main(void) for(;;) { - while (!(UCSRA & (1<>8) & 0xff; + UBRRL = (unsigned char) ubrr & 0xff; - for(int i = 0; i < 20; i++) { //Wait 100µs for next datapackage - _delay_us(1); - if((UCSRA & (1<> 4) & 0x0f; // Shift command into first 4 bits; note = data[1]; - /*velocity = data2;*/ - - //PORTA = ~command; - - switch(command) + velocity = data[2]; + + midi_command(command, note, velocity); + +} + +void midi_command(char _cmd, char _note, char _vel) +{ + switch(_cmd) { case 0x08: //Note off PORTA = 1; - midi_update_note(note, 0); + midi_update_note(_note, 0); break; case 0x09: //Note on PORTA = 2; - midi_update_note(note, 1); + midi_update_note(_note, 1); break; /* case 0x0A:break; //Note Fade Out @@ -68,23 +80,25 @@ ISR(USART_RXC_vect) } } -void midi_setup() +uint8_t midi_recv_avail() { - midi_active_channels = 0x00; - DDRA = 0xff; - PORTA = 0xff; - //UART init - unsigned int ubrr = (F_CPU / (16 * _MIDI_LINK_SPEED)) - 1; + return midi_recv_ptr; +} - UBRRH = (unsigned char) (ubrr>>8) & 0xff; - UBRRL = (unsigned char) ubrr & 0xff; +char midi_get_recv_buf() +{ + if(midi_recv_ptr > 0) + midi_recv_ptr--; + else + return 0x00; - UCSRB = (1<0=ON */ +static void midi_uart_out(unsigned char _c); + #endif /* MIDI_H_ */ \ No newline at end of file -- cgit v1.2.3