Permalink
Browse files

functional, needs some minor debounce work

  • Loading branch information...
1 parent b051162 commit e7c8b176b4b5b640c550abf2d7a33f5ed4ae0783 @tmpvar committed Jun 10, 2012
Showing with 75 additions and 2 deletions.
  1. +74 −1 trunk/Demos/Device/ClassDriver/tbase8/tbase8.c
  2. +1 −1 trunk/Demos/Device/ClassDriver/tbase8/tbase8.h
@@ -22,18 +22,56 @@ USB_ClassInfo_MIDI_Device_t tbase8_MIDI_Interface = {
},
};
+struct {
+ bool pressed;
+ bool on;
+ unsigned long lastOn;
+} inputs[8];
int main(void) {
SetupHardware();
+
+ TCCR1B |= (1 << CS10);
+
+
sei();
+ memset(inputs, 0, sizeof(inputs));
+ unsigned long tick = 0;
for (;;)
{
- MIDI_EventPacket_t ReceivedMIDIEvent;
+
+ if (TCNT1 >= 1000) {
+ tick++;
+ }
+ //MIDI_EventPacket_t ReceivedMIDIEvent;
/*while (MIDI_Device_ReceiveEventPacket(&Keyboard_MIDI_Interface, &ReceivedMIDIEvent)) {
}*/
+ int inputPins[4] = { 0b00000010, 0b00001000, 0b00100000, 0b10000000 };
+ int port;
+ int current;
+ unsigned long currentTime;
+ for (int i=0; i<8; i++) {
+
+ port = (i<4) ? PIND : PINB;
+ current = i%4;
+ if (port & inputPins[current]) {
+ if (!inputs[i].pressed && tick > inputs[i].lastOn) {
+ inputs[i].pressed = true;
+ inputs[i].on = !inputs[i].on;
+ inputs[i].lastOn = tick;
+ // Send midi stuff
+ sendMidiNote(i, inputs[i].on);
+ }
+ } else {
+ inputs[i].pressed = false;
+ //sendMidiNote(i, false);
+ }
+ }
+
+
MIDI_Device_USBTask(&tbase8_MIDI_Interface);
USB_USBTask();
}
@@ -42,16 +80,51 @@ int main(void) {
}
+void sendMidiNote(int button, bool on) {
+ int command = (on) ? MIDI_COMMAND_NOTE_ON : MIDI_COMMAND_NOTE_OFF;
+
+ MIDI_EventPacket_t MIDIEvent = (MIDI_EventPacket_t) {
+ .Event = MIDI_EVENT(0, command),
+ .Data1 = command | MIDI_CHANNEL(1),
+ .Data2 = 60 + button,
+ .Data3 = MIDI_STANDARD_VELOCITY,
+ };
+
+ MIDI_Device_SendEventPacket(&tbase8_MIDI_Interface, &MIDIEvent);
+ MIDI_Device_Flush(&tbase8_MIDI_Interface);
+}
+
/** Configures the board hardware and chip peripherals for the demo's functionality. */
void SetupHardware(void)
{
/* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF);
wdt_disable();
+
/* Disable clock division */
clock_prescale_set(clock_div_1);
+ /* Set the port directions for port b and d */
+ DDRD = 0xFF;
+ DDRB = 0xFF;
+ PORTD = 0b01010101;
+ PORTB = 0b01010101;
+
/* Hardware Initialization */
USB_Init();
}
+
+/** Event handler for the library USB Configuration Changed event. */
+void EVENT_USB_Device_ConfigurationChanged(void)
+{
+ bool ConfigSuccess = true;
+
+ ConfigSuccess &= MIDI_Device_ConfigureEndpoints(&tbase8_MIDI_Interface);
+}
+
+/** Event handler for the library USB Control Request reception event. */
+void EVENT_USB_Device_ControlRequest(void)
+{
+ MIDI_Device_ProcessControlRequest(&tbase8_MIDI_Interface);
+}
@@ -50,7 +50,7 @@
/* Function Prototypes: */
void SetupHardware(void);
-
+ void sendMidiNote(int, bool);
void EVENT_USB_Device_Connect(void);
void EVENT_USB_Device_Disconnect(void);
void EVENT_USB_Device_ConfigurationChanged(void);

0 comments on commit e7c8b17

Please sign in to comment.