Commit 8aec4fce authored by Erik Strand's avatar Erik Strand
Browse files

Modify the MIDI example to work for my board

parent 9c802777
...@@ -68,20 +68,54 @@ int main(void) ...@@ -68,20 +68,54 @@ int main(void)
{ {
SetupHardware(); SetupHardware();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); //LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
PORTC.DIRSET = (1 << 5) | (1u << 6) | (1u << 7);
PORTC.OUTSET = (1 << 5) | (1u << 6) | (1u << 7);
GlobalInterruptEnable(); GlobalInterruptEnable();
uint32_t count = 0;
bool on = false;
uint8_t channel = MIDI_CHANNEL(1);
uint8_t command = 0;
uint8_t pitch = 60;
uint8_t velocity = 100;
for (;;) for (;;)
{ {
CheckJoystickMovement(); if (++count == 50000) {
count = 0;
PORTC.OUTTGL = (1 << 5);
if (on) {
command = MIDI_COMMAND_NOTE_OFF;
} else {
command = MIDI_COMMAND_NOTE_ON;
}
on = !on;
MIDI_EventPacket_t MIDIEvent = (MIDI_EventPacket_t)
{
.Event = MIDI_EVENT(0, command),
.Data1 = command | channel,
.Data2 = pitch,
.Data3 = velocity,
};
MIDI_Device_SendEventPacket(&Keyboard_MIDI_Interface, &MIDIEvent);
MIDI_Device_Flush(&Keyboard_MIDI_Interface);
}
MIDI_EventPacket_t ReceivedMIDIEvent; MIDI_EventPacket_t ReceivedMIDIEvent;
while (MIDI_Device_ReceiveEventPacket(&Keyboard_MIDI_Interface, &ReceivedMIDIEvent)) while (MIDI_Device_ReceiveEventPacket(&Keyboard_MIDI_Interface, &ReceivedMIDIEvent))
{ {
if ((ReceivedMIDIEvent.Event == MIDI_EVENT(0, MIDI_COMMAND_NOTE_ON)) && (ReceivedMIDIEvent.Data3 > 0)) //if ((ReceivedMIDIEvent.Event == MIDI_EVENT(0, MIDI_COMMAND_NOTE_ON)) && (ReceivedMIDIEvent.Data3 > 0))
LEDs_SetAllLEDs(ReceivedMIDIEvent.Data2 > 64 ? LEDS_LED1 : LEDS_LED2); // LEDs_SetAllLEDs(ReceivedMIDIEvent.Data2 > 64 ? LEDS_LED1 : LEDS_LED2);
else //else
LEDs_SetAllLEDs(LEDS_NO_LEDS); // LEDs_SetAllLEDs(LEDS_NO_LEDS);
} }
MIDI_Device_USBTask(&Keyboard_MIDI_Interface); MIDI_Device_USBTask(&Keyboard_MIDI_Interface);
...@@ -109,30 +143,37 @@ void SetupHardware(void) ...@@ -109,30 +143,37 @@ void SetupHardware(void)
XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB); XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);
PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
#endif #endif
/* Hardware Initialization */ /* Hardware Initialization */
Joystick_Init(); //Joystick_Init();
LEDs_Init(); //LEDs_Init();
Buttons_Init(); //Buttons_Init();
USB_Init(); USB_Init();
} }
/** Checks for changes in the position of the board joystick, sending MIDI events to the host upon each change. */ /** Checks for changes in the position of the board joystick, sending MIDI events to the host upon each change. */
void CheckJoystickMovement(void) void CheckJoystickMovement(bool on)
{ {
static uint8_t PrevJoystickStatus; static uint8_t PrevJoystickStatus;
uint8_t MIDICommand = 0; uint8_t MIDICommand = 0;
uint8_t MIDIPitch; uint8_t MIDIPitch;
/* Get current joystick mask, XOR with previous to detect joystick changes */ // Get current joystick mask, XOR with previous to detect joystick changes
uint8_t JoystickStatus = Joystick_GetStatus(); //uint8_t JoystickStatus = Joystick_GetStatus();
uint8_t JoystickChanges = (JoystickStatus ^ PrevJoystickStatus); //uint8_t JoystickChanges = (JoystickStatus ^ PrevJoystickStatus);
// Get board button status - if pressed use channel 10 (percussion), otherwise use channel 1
//uint8_t Channel = ((Buttons_GetStatus() & BUTTONS_BUTTON1) ? MIDI_CHANNEL(10) : MIDI_CHANNEL(1));
uint8_t Channel = MIDI_CHANNEL(1);
/* Get board button status - if pressed use channel 10 (percussion), otherwise use channel 1 */ MIDICommand = on ? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF;
uint8_t Channel = ((Buttons_GetStatus() & BUTTONS_BUTTON1) ? MIDI_CHANNEL(10) : MIDI_CHANNEL(1)); //MIDICommand = MIDI_COMMAND_NOTE_ON;
MIDIPitch = 0x3C;
/*
if (JoystickChanges & JOY_LEFT) if (JoystickChanges & JOY_LEFT)
{ {
MIDICommand = ((JoystickStatus & JOY_LEFT)? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF); MIDICommand = ((JoystickStatus & JOY_LEFT)? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF);
...@@ -162,6 +203,7 @@ void CheckJoystickMovement(void) ...@@ -162,6 +203,7 @@ void CheckJoystickMovement(void)
MIDICommand = ((JoystickStatus & JOY_PRESS)? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF); MIDICommand = ((JoystickStatus & JOY_PRESS)? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF);
MIDIPitch = 0x3B; MIDIPitch = 0x3B;
} }
*/
if (MIDICommand) if (MIDICommand)
{ {
...@@ -178,19 +220,19 @@ void CheckJoystickMovement(void) ...@@ -178,19 +220,19 @@ void CheckJoystickMovement(void)
MIDI_Device_Flush(&Keyboard_MIDI_Interface); MIDI_Device_Flush(&Keyboard_MIDI_Interface);
} }
PrevJoystickStatus = JoystickStatus; //PrevJoystickStatus = JoystickStatus;
} }
/** Event handler for the library USB Connection event. */ /** Event handler for the library USB Connection event. */
void EVENT_USB_Device_Connect(void) void EVENT_USB_Device_Connect(void)
{ {
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); //LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
} }
/** Event handler for the library USB Disconnection event. */ /** Event handler for the library USB Disconnection event. */
void EVENT_USB_Device_Disconnect(void) void EVENT_USB_Device_Disconnect(void)
{ {
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); //LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
} }
/** Event handler for the library USB Configuration Changed event. */ /** Event handler for the library USB Configuration Changed event. */
...@@ -200,7 +242,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) ...@@ -200,7 +242,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
ConfigSuccess &= MIDI_Device_ConfigureEndpoints(&Keyboard_MIDI_Interface); ConfigSuccess &= MIDI_Device_ConfigureEndpoints(&Keyboard_MIDI_Interface);
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR); //LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
} }
/** Event handler for the library USB Control Request reception event. */ /** Event handler for the library USB Control Request reception event. */
......
...@@ -46,9 +46,9 @@ ...@@ -46,9 +46,9 @@
#include "Descriptors.h" #include "Descriptors.h"
#include <LUFA/Drivers/Board/LEDs.h> //#include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Joystick.h> //#include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/Buttons.h> //#include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Drivers/USB/USB.h> #include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Platform/Platform.h> #include <LUFA/Platform/Platform.h>
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
/* Function Prototypes: */ /* Function Prototypes: */
void SetupHardware(void); void SetupHardware(void);
void CheckJoystickMovement(void); void CheckJoystickMovement(bool on);
void EVENT_USB_Device_Connect(void); void EVENT_USB_Device_Connect(void);
void EVENT_USB_Device_Disconnect(void); void EVENT_USB_Device_Disconnect(void);
......
...@@ -10,11 +10,14 @@ ...@@ -10,11 +10,14 @@
# -------------------------------------- # --------------------------------------
# Run "make help" for target help. # Run "make help" for target help.
# Can program XMEGA boards with
# avrdude -p x128a4u -P usb -c atmelice_pdi -U flash:w:MIDI.hex
MCU = at90usb1287
ARCH = AVR8 MCU = atxmega128a4u
BOARD = USBKEY ARCH = XMEGA
F_CPU = 8000000 BOARD = BOARD_USER
F_CPU = 48000000
F_USB = $(F_CPU) F_USB = $(F_CPU)
OPTIMIZATION = s OPTIMIZATION = s
TARGET = MIDI TARGET = MIDI
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment