Skip to content
Snippets Groups Projects
Commit 8aec4fce authored by Erik Strand's avatar Erik Strand
Browse files

Modify the MIDI example to work for my board

parent 9c802777
No related branches found
No related tags found
No related merge requests found
......@@ -68,20 +68,54 @@ int main(void)
{
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();
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 (;;)
{
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;
while (MIDI_Device_ReceiveEventPacket(&Keyboard_MIDI_Interface, &ReceivedMIDIEvent))
{
if ((ReceivedMIDIEvent.Event == MIDI_EVENT(0, MIDI_COMMAND_NOTE_ON)) && (ReceivedMIDIEvent.Data3 > 0))
LEDs_SetAllLEDs(ReceivedMIDIEvent.Data2 > 64 ? LEDS_LED1 : LEDS_LED2);
else
LEDs_SetAllLEDs(LEDS_NO_LEDS);
//if ((ReceivedMIDIEvent.Event == MIDI_EVENT(0, MIDI_COMMAND_NOTE_ON)) && (ReceivedMIDIEvent.Data3 > 0))
// LEDs_SetAllLEDs(ReceivedMIDIEvent.Data2 > 64 ? LEDS_LED1 : LEDS_LED2);
//else
// LEDs_SetAllLEDs(LEDS_NO_LEDS);
}
MIDI_Device_USBTask(&Keyboard_MIDI_Interface);
......@@ -109,30 +143,37 @@ void SetupHardware(void)
XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);
PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
#endif
/* Hardware Initialization */
Joystick_Init();
LEDs_Init();
Buttons_Init();
//Joystick_Init();
//LEDs_Init();
//Buttons_Init();
USB_Init();
}
/** 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;
uint8_t MIDICommand = 0;
uint8_t MIDIPitch;
/* Get current joystick mask, XOR with previous to detect joystick changes */
uint8_t JoystickStatus = Joystick_GetStatus();
uint8_t JoystickChanges = (JoystickStatus ^ PrevJoystickStatus);
// Get current joystick mask, XOR with previous to detect joystick changes
//uint8_t JoystickStatus = Joystick_GetStatus();
//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 */
uint8_t Channel = ((Buttons_GetStatus() & BUTTONS_BUTTON1) ? MIDI_CHANNEL(10) : MIDI_CHANNEL(1));
MIDICommand = on ? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF;
//MIDICommand = MIDI_COMMAND_NOTE_ON;
MIDIPitch = 0x3C;
/*
if (JoystickChanges & JOY_LEFT)
{
MIDICommand = ((JoystickStatus & JOY_LEFT)? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF);
......@@ -162,6 +203,7 @@ void CheckJoystickMovement(void)
MIDICommand = ((JoystickStatus & JOY_PRESS)? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF);
MIDIPitch = 0x3B;
}
*/
if (MIDICommand)
{
......@@ -178,19 +220,19 @@ void CheckJoystickMovement(void)
MIDI_Device_Flush(&Keyboard_MIDI_Interface);
}
PrevJoystickStatus = JoystickStatus;
//PrevJoystickStatus = JoystickStatus;
}
/** Event handler for the library USB Connection event. */
void EVENT_USB_Device_Connect(void)
{
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
//LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
}
/** Event handler for the library USB Disconnection event. */
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. */
......@@ -200,7 +242,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
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. */
......
......@@ -46,9 +46,9 @@
#include "Descriptors.h"
#include <LUFA/Drivers/Board/LEDs.h>
#include <LUFA/Drivers/Board/Joystick.h>
#include <LUFA/Drivers/Board/Buttons.h>
//#include <LUFA/Drivers/Board/LEDs.h>
//#include <LUFA/Drivers/Board/Joystick.h>
//#include <LUFA/Drivers/Board/Buttons.h>
#include <LUFA/Drivers/USB/USB.h>
#include <LUFA/Platform/Platform.h>
......@@ -67,7 +67,7 @@
/* Function Prototypes: */
void SetupHardware(void);
void CheckJoystickMovement(void);
void CheckJoystickMovement(bool on);
void EVENT_USB_Device_Connect(void);
void EVENT_USB_Device_Disconnect(void);
......
......@@ -10,11 +10,14 @@
# --------------------------------------
# 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
BOARD = USBKEY
F_CPU = 8000000
MCU = atxmega128a4u
ARCH = XMEGA
BOARD = BOARD_USER
F_CPU = 48000000
F_USB = $(F_CPU)
OPTIMIZATION = s
TARGET = MIDI
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment