3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 USB_ClassInfo_MIDI_t Keyboard_MIDI_Interface
=
37 .DataINEndpointNumber
= MIDI_STREAM_IN_EPNUM
,
38 .DataINEndpointSize
= MIDI_STREAM_EPSIZE
,
40 .DataOUTEndpointNumber
= MIDI_STREAM_OUT_EPNUM
,
41 .DataOUTEndpointSize
= MIDI_STREAM_EPSIZE
,
48 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
52 CheckJoystickMovement();
58 void SetupHardware(void)
60 /* Disable watchdog if enabled by bootloader/fuses */
61 MCUSR
&= ~(1 << WDRF
);
64 /* Disable clock division */
65 clock_prescale_set(clock_div_1
);
67 /* Hardware Initialization */
74 void CheckJoystickMovement(void)
76 static uint8_t PrevJoystickStatus
;
78 uint8_t MIDICommand
= 0;
81 /* Get current joystick mask, XOR with previous to detect joystick changes */
82 uint8_t JoystickStatus
= Joystick_GetStatus();
83 uint8_t JoystickChanges
= (JoystickStatus
^ PrevJoystickStatus
);
85 /* Get board button status - if pressed use channel 10 (percussion), otherwise use channel 1 */
86 uint8_t Channel
= ((Buttons_GetStatus() & BUTTONS_BUTTON1
) ?
MIDI_CHANNEL(10) : MIDI_CHANNEL(1));
88 if (JoystickChanges
& JOY_LEFT
)
90 MIDICommand
= ((JoystickStatus
& JOY_LEFT
)? MIDI_COMMAND_NOTE_ON
: MIDI_COMMAND_NOTE_OFF
);
94 if (JoystickChanges
& JOY_UP
)
96 MIDICommand
= ((JoystickStatus
& JOY_UP
)? MIDI_COMMAND_NOTE_ON
: MIDI_COMMAND_NOTE_OFF
);
100 if (JoystickChanges
& JOY_RIGHT
)
102 MIDICommand
= ((JoystickStatus
& JOY_RIGHT
)? MIDI_COMMAND_NOTE_ON
: MIDI_COMMAND_NOTE_OFF
);
106 if (JoystickChanges
& JOY_DOWN
)
108 MIDICommand
= ((JoystickStatus
& JOY_DOWN
)? MIDI_COMMAND_NOTE_ON
: MIDI_COMMAND_NOTE_OFF
);
112 if (JoystickChanges
& JOY_PRESS
)
114 MIDICommand
= ((JoystickStatus
& JOY_PRESS
)? MIDI_COMMAND_NOTE_ON
: MIDI_COMMAND_NOTE_OFF
);
120 USB_MIDI_EventPacket_t MIDIEvent
= (USB_MIDI_EventPacket_t
)
123 .Command
= MIDICommand
,
125 .Data1
= (MIDICommand
<< 4) | Channel
,
127 .Data3
= MIDI_STANDARD_VELOCITY
,
130 USB_MIDI_SendEventPacket(&Keyboard_MIDI_Interface
, &MIDIEvent
);
133 PrevJoystickStatus
= JoystickStatus
;
136 void EVENT_USB_Connect(void)
138 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
141 void EVENT_USB_Disconnect(void)
143 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
146 void EVENT_USB_ConfigurationChanged(void)
148 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
150 if (!(USB_MIDI_ConfigureEndpoints(&Keyboard_MIDI_Interface
)))
151 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);