Added new RESET_TOGGLES_LIBUSB_COMPAT compile time option to the AVRISP-MKII clone...
[pub/USBasp.git] / Demos / Host / LowLevel / MIDIHost / MIDIHost.c
index e89b261..f6b607a 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2011.
+     Copyright (C) Dean Camera, 2012.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -165,8 +165,9 @@ void MIDIHost_Task(void)
 {
        if (USB_HostState != HOST_STATE_Configured)
          return;
 {
        if (USB_HostState != HOST_STATE_Configured)
          return;
-         
+
        Pipe_SelectPipe(MIDI_DATA_IN_PIPE);
        Pipe_SelectPipe(MIDI_DATA_IN_PIPE);
+       Pipe_Unfreeze();
 
        if (Pipe_IsINReceived())
        {
 
        if (Pipe_IsINReceived())
        {
@@ -177,18 +178,21 @@ void MIDIHost_Task(void)
                if (!(Pipe_BytesInPipe()))
                  Pipe_ClearIN();
 
                if (!(Pipe_BytesInPipe()))
                  Pipe_ClearIN();
 
-               bool NoteOnEvent  = ((MIDIEvent.Command & 0x0F) == (MIDI_COMMAND_NOTE_ON  >> 4));
-               bool NoteOffEvent = ((MIDIEvent.Command & 0x0F) == (MIDI_COMMAND_NOTE_OFF >> 4));
+               bool NoteOnEvent  = (MIDIEvent.Event == MIDI_EVENT(0, MIDI_COMMAND_NOTE_ON));
+               bool NoteOffEvent = (MIDIEvent.Event == MIDI_EVENT(0, MIDI_COMMAND_NOTE_OFF));
 
                if (NoteOnEvent || NoteOffEvent)
                {
                        printf_P(PSTR("MIDI Note %s - Channel %d, Pitch %d, Velocity %d\r\n"), NoteOnEvent ? "On" : "Off",
                                                                                                                                                                   ((MIDIEvent.Data1 & 0x0F) + 1),
                                                                                                                                                                   MIDIEvent.Data2, MIDIEvent.Data3);
 
                if (NoteOnEvent || NoteOffEvent)
                {
                        printf_P(PSTR("MIDI Note %s - Channel %d, Pitch %d, Velocity %d\r\n"), NoteOnEvent ? "On" : "Off",
                                                                                                                                                                   ((MIDIEvent.Data1 & 0x0F) + 1),
                                                                                                                                                                   MIDIEvent.Data2, MIDIEvent.Data3);
-               }                               
+               }
        }
        }
+       
+       Pipe_Freeze();
 
        Pipe_SelectPipe(MIDI_DATA_OUT_PIPE);
 
        Pipe_SelectPipe(MIDI_DATA_OUT_PIPE);
+       Pipe_Unfreeze();
 
        if (Pipe_IsOUTReady())
        {
 
        if (Pipe_IsOUTReady())
        {
@@ -237,8 +241,7 @@ void MIDIHost_Task(void)
                {
                        MIDI_EventPacket_t MIDIEvent = (MIDI_EventPacket_t)
                                {
                {
                        MIDI_EventPacket_t MIDIEvent = (MIDI_EventPacket_t)
                                {
-                                       .CableNumber = 0,
-                                       .Command     = (MIDICommand >> 4),
+                                       .Event       = MIDI_EVENT(0, MIDICommand),
 
                                        .Data1       = MIDICommand | Channel,
                                        .Data2       = MIDIPitch,
 
                                        .Data1       = MIDICommand | Channel,
                                        .Data2       = MIDIPitch,
@@ -252,6 +255,8 @@ void MIDIHost_Task(void)
                        Pipe_ClearOUT();
                }
 
                        Pipe_ClearOUT();
                }
 
+               Pipe_Freeze();
+
                /* Save previous joystick value for next joystick change detection */
                PrevJoystickStatus = JoystickStatus;
        }
                /* Save previous joystick value for next joystick change detection */
                PrevJoystickStatus = JoystickStatus;
        }