X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/99a9e415efd1e27d902427ccd1aa6e4a9f9d4d05..b35f93a372d8c872aebab4e3626bfc58d85b84d7:/Demos/Host/LowLevel/MIDIHost/MIDIHost.c?ds=inline diff --git a/Demos/Host/LowLevel/MIDIHost/MIDIHost.c b/Demos/Host/LowLevel/MIDIHost/MIDIHost.c index 5ff3baa39..6924fd448 100644 --- a/Demos/Host/LowLevel/MIDIHost/MIDIHost.c +++ b/Demos/Host/LowLevel/MIDIHost/MIDIHost.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2010. + Copyright (C) Dean Camera, 2011. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2011 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 @@ -66,11 +66,14 @@ void SetupHardware(void) clock_prescale_set(clock_div_1); /* Hardware Initialization */ - SerialStream_Init(9600, false); + Serial_Init(9600, false); LEDs_Init(); Buttons_Init(); Joystick_Init(); USB_Init(); + + /* Create a stdio stream for the serial port for stdin and stdout */ + Serial_CreateStream(NULL); } /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and @@ -102,7 +105,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void) /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */ void EVENT_USB_Host_HostError(const uint8_t ErrorCode) { - USB_ShutDown(); + USB_Disable(); printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n" " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); @@ -181,7 +184,10 @@ void MIDI_Host_Task(void) { MIDI_EventPacket_t MIDIEvent; - Pipe_Read_Stream_LE(&MIDIEvent, sizeof(MIDIEvent)); + Pipe_Read_Stream_LE(&MIDIEvent, sizeof(MIDIEvent), NULL); + + 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)); @@ -191,10 +197,7 @@ void MIDI_Host_Task(void) 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 (!(Pipe_BytesInPipe())) - Pipe_ClearIN(); + } } Pipe_SelectPipe(MIDI_DATA_OUT_PIPE); @@ -255,7 +258,7 @@ void MIDI_Host_Task(void) }; /* Write the MIDI event packet to the pipe */ - Pipe_Write_Stream_LE(&MIDIEvent, sizeof(MIDIEvent)); + Pipe_Write_Stream_LE(&MIDIEvent, sizeof(MIDIEvent), NULL); /* Send the data in the pipe to the device */ Pipe_ClearOUT();