From 75b81e47e350d88dcbfa0d60ae482aa2890a3797 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 13 Mar 2014 19:33:09 +0000 Subject: added one button to the simple midi controller git-svn-id: https://svn.spreadspace.org/avr/trunk@252 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- usb-midi/usb-midi.c | 82 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 21 deletions(-) (limited to 'usb-midi/usb-midi.c') diff --git a/usb-midi/usb-midi.c b/usb-midi/usb-midi.c index 47e06fa..c305462 100644 --- a/usb-midi/usb-midi.c +++ b/usb-midi/usb-midi.c @@ -37,6 +37,7 @@ #include #include #include "lufa-descriptor-midi.h" +#include "LUFA/Drivers/Peripheral/Serial.h" /** LUFA MIDI Class driver interface configuration and state information. This structure is * passed to all MIDI Class driver functions, so that multiple instances of the same class @@ -77,6 +78,21 @@ void EVENT_USB_Device_ControlRequest(void) #include "util.h" #include "led.h" +static FILE serial_stream; + +#define KEY_PIN PINF +#define KEY_PORT PORTF +#define KEY_DDR DDRF +#define KEY_BIT 0 + +#define KEY_LP_MAX 255 + +void key_init(void) +{ + KEY_DDR = KEY_DDR & ~(1<> 4), + .Data1 = MIDI_COMMAND_NOTE_ON | 0, + .Data2 = 0, + .Data3 = 0x7F, + }; + MIDI_EventPacket_t MIDIEventOff = (MIDI_EventPacket_t) + { + .CableNumber = 0, + .Command = (MIDI_COMMAND_NOTE_OFF >> 4), + .Data1 = MIDI_COMMAND_NOTE_OFF | 0, + .Data2 = 0, + .Data3 = 0, + }; + + static uint8_t last_state = (1<> 4), - - .Data1 = MIDICommand | 1, - .Data2 = 0, - .Data3 = 0, - }; - MIDI_Device_SendEventPacket(&Keyboard_MIDI_Interface, &MIDIEvent); - MIDI_Device_Flush(&Keyboard_MIDI_Interface); - - led_off(); + while(MIDI_Device_ReceiveEventPacket(&Keyboard_MIDI_Interface, &ReceivedMIDIEvent)) { + led_on(); + printf("%02X %02X %02X\r\n", ReceivedMIDIEvent.Data1, ReceivedMIDIEvent.Data2, ReceivedMIDIEvent.Data3); + led_off(); + } + + uint8_t state = KEY_PIN & (1<= KEY_LP_MAX) { + MIDI_EventPacket_t* MIDIEvent = state ? &MIDIEventOff : &MIDIEventOn; + MIDI_Device_SendEventPacket(&Keyboard_MIDI_Interface, MIDIEvent); + MIDI_Device_Flush(&Keyboard_MIDI_Interface); + + last_state = state; + lp_cnt = 0; + } MIDI_Device_USBTask(&Keyboard_MIDI_Interface); USB_USBTask(); -- cgit v1.2.3