3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
33 * Main source file for the MIDI bootloader. This file contains the main tasks of the demo and
34 * is responsible for the initial application hardware configuration.
37 #include "BootloaderMIDI.h"
39 /** Main program entry point. This routine configures the hardware required by the application, then
40 * enters a loop to run the application tasks in sequence.
53 /** Configures the board hardware and chip peripherals for the demo's functionality. */
54 void SetupHardware(void)
56 /* Disable watchdog if enabled by bootloader/fuses */
57 MCUSR
&= ~(1 << WDRF
);
60 /* Disable clock division */
61 clock_prescale_set(clock_div_1
);
63 /* Hardware Initialization */
67 /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
68 * of the USB device after enumeration - the device endpoints are configured and the MIDI management task started.
70 void EVENT_USB_Device_ConfigurationChanged(void)
72 /* Setup MIDI stream endpoints */
73 Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPNUM
, EP_TYPE_BULK
,
74 ENDPOINT_DIR_OUT
, MIDI_STREAM_EPSIZE
,
75 ENDPOINT_BANK_SINGLE
);
77 Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPNUM
, EP_TYPE_BULK
,
78 ENDPOINT_DIR_IN
, MIDI_STREAM_EPSIZE
,
79 ENDPOINT_BANK_SINGLE
);
82 /** Task to handle the generation of MIDI note change events in response to presses of the board joystick, and send them
87 /* Device must be connected and configured for the task to run */
88 if (USB_DeviceState
!= DEVICE_STATE_Configured
)
91 /* Select the MIDI OUT stream */
92 Endpoint_SelectEndpoint(MIDI_STREAM_OUT_EPNUM
);
94 if (Endpoint_IsOUTReceived())
96 USB_MIDI_EventPacket_t InPacket
;
97 Endpoint_Read_Stream_LE(&InPacket
, sizeof(InPacket
));
100 uint8_t Channel
= InPacket
.Data1
;
101 uint8_t Data
= ((InPacket
.Data2
& 0x7F) | ((InPacket
.Data3
== 64) ?
0x80 : 0x00));
103 if ((Channel
== MIDI_CONTROL_CHANNEL
) && (Data
== CONTROL_ENTER_PROG_MODE
))
105 USB_MIDI_EventPacket_t MIDIIn
= (USB_MIDI_EventPacket_t
)
108 .Command
= (MIDI_COMMAND_NOTE_ON
>> 4),
110 .Data1
= MIDI_COMMAND_NOTE_ON
| MIDI_CONTROL_CHANNEL
,
111 .Data2
= CONTROL_DEVICE_READY
,
115 Endpoint_SelectEndpoint(MIDI_STREAM_IN_EPNUM
);
116 Endpoint_Write_Stream_LE(&MIDIIn
, sizeof(MIDIIn
));