summaryrefslogtreecommitdiff
path: root/protocol/lufa
diff options
context:
space:
mode:
Diffstat (limited to 'protocol/lufa')
-rw-r--r--protocol/lufa/descriptor.c10
-rw-r--r--protocol/lufa/descriptor.h27
-rw-r--r--protocol/lufa/lufa.c103
-rw-r--r--protocol/lufa/lufa.h11
4 files changed, 112 insertions, 39 deletions
diff --git a/protocol/lufa/descriptor.c b/protocol/lufa/descriptor.c
index 8a14c5e09f..5454926b18 100644
--- a/protocol/lufa/descriptor.c
+++ b/protocol/lufa/descriptor.c
@@ -492,7 +492,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
- .InterfaceNumber = MIDI_INTERFACE,
+ .InterfaceNumber = AC_INTERFACE,
.AlternateSetting = 0,
.TotalEndpoints = 0,
@@ -513,14 +513,14 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.TotalLength = sizeof(USB_Audio_Descriptor_Interface_AC_t),
.InCollection = 1,
- .InterfaceNumber = MIDI2_INTERFACE,
+ .InterfaceNumber = AS_INTERFACE,
},
.Audio_StreamInterface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
- .InterfaceNumber = MIDI2_INTERFACE,
+ .InterfaceNumber = AS_INTERFACE,
.AlternateSetting = 0,
.TotalEndpoints = 2,
@@ -601,7 +601,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
{
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM),
+ .EndpointAddress = MIDI_STREAM_OUT_EPADDR,
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = MIDI_STREAM_EPSIZE,
.PollingIntervalMS = 0x05
@@ -626,7 +626,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
{
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM),
+ .EndpointAddress = MIDI_STREAM_IN_EPADDR,
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = MIDI_STREAM_EPSIZE,
.PollingIntervalMS = 0x05
diff --git a/protocol/lufa/descriptor.h b/protocol/lufa/descriptor.h
index 0471ef31de..4fd81a0e87 100644
--- a/protocol/lufa/descriptor.h
+++ b/protocol/lufa/descriptor.h
@@ -135,14 +135,14 @@ typedef struct
#endif
#ifdef MIDI_ENABLE
-# define MIDI_INTERFACE (NKRO_INTERFACE + 1)
-# define MIDI2_INTERFACE (NKRO_INTERFACE + 2)
+# define AC_INTERFACE (NKRO_INTERFACE + 1)
+# define AS_INTERFACE (NKRO_INTERFACE + 2)
#else
-# define MIDI2_INTERFACE NKRO_INTERFACE
+# define AS_INTERFACE NKRO_INTERFACE
#endif
/* nubmer of interfaces */
-#define TOTAL_INTERFACES MIDI2_INTERFACE + 1
+#define TOTAL_INTERFACES AS_INTERFACE + 1
// Endopoint number and size
@@ -170,20 +170,23 @@ typedef struct
#ifdef NKRO_ENABLE
# define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1)
-# if defined(__AVR_ATmega32U2__) && NKRO_IN_EPNUM > 4
-# error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO)"
-# endif
+#else
+# define NKRO_IN_EPNUM CONSOLE_OUT_EPNUM
#endif
#ifdef MIDI_ENABLE
-# define MIDI_STREAM_IN_EPNUM (NKRO_IN_EPNUM + 1)
-# define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 1)
-#else
-# define MIDI_STREAM_IN_EPNUM NKRO_IN_EPNUM
-# define MIDI_STREAM_OUT_EPNUM NKRO_IN_EPNUM
+# define MIDI_STREAM_IN_EPNUM (NKRO_IN_EPNUM + 1)
+// # define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 1)
+# define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 2)
+# define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
+# define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
#endif
+#if defined(__AVR_ATmega32U2__) && MIDI_STREAM_OUT_EPADDR > 4
+# error "Endpoints are not available enough to support all functions. Remove some in Makefile.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI)"
+#endif
+
#define KEYBOARD_EPSIZE 8
#define MOUSE_EPSIZE 8
#define EXTRAKEY_EPSIZE 8
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index 78ed6cfe20..e9f335a632 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -92,20 +92,21 @@ host_driver_t lufa_driver = {
void SetupHardware(void);
+#ifdef MIDI_ENABLE
USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface =
{
.Config =
{
- .StreamingInterfaceNumber = MIDI2_INTERFACE,
+ .StreamingInterfaceNumber = AS_INTERFACE,
.DataINEndpoint =
{
- .Address = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM),
+ .Address = MIDI_STREAM_IN_EPADDR,
.Size = MIDI_STREAM_EPSIZE,
.Banks = 1,
},
.DataOUTEndpoint =
{
- .Address = (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM),
+ .Address = MIDI_STREAM_OUT_EPADDR,
.Size = MIDI_STREAM_EPSIZE,
.Banks = 1,
},
@@ -120,7 +121,7 @@ USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface =
#define SYS_COMMON_1 0x50
#define SYS_COMMON_2 0x20
#define SYS_COMMON_3 0x30
-
+#endif
/*******************************************************************************
@@ -291,12 +292,10 @@ void EVENT_USB_Device_ConfigurationChanged(void)
#endif
#ifdef MIDI_ENABLE
- ConfigSuccess &= MIDI_Device_ConfigureEndpoints(&USB_MIDI_Interface);
-
- // ConfigSuccess &= ENDPOINT_CONFIG(MIDI_STREAM_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
- // MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
- // ConfigSuccess &= ENDPOINT_CONFIG(MIDI_STREAM_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
- // MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
+ ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
+ // ConfigSuccess &= MIDI_Device_ConfigureEndpoints(&USB_MIDI_Interface);
+
#endif
}
@@ -324,7 +323,7 @@ void EVENT_USB_Device_ControlRequest(void)
uint8_t* ReportData = NULL;
uint8_t ReportSize = 0;
- MIDI_Device_ProcessControlRequest(&USB_MIDI_Interface);
+ // MIDI_Device_ProcessControlRequest(&USB_MIDI_Interface);
/* Handle HID Class specific requests */
switch (USB_ControlRequest.bRequest)
@@ -706,6 +705,74 @@ void midi_usb_init(MidiDevice * device){
SetupHardware();
sei();
}
+
+void MIDI_Task(void)
+{
+
+ /* Device must be connected and configured for the task to run */
+ dprint("in MIDI_TASK\n");
+ if (USB_DeviceState != DEVICE_STATE_Configured)
+ return;
+ dprint("continuing in MIDI_TASK\n");
+
+ Endpoint_SelectEndpoint(MIDI_STREAM_IN_EPADDR);
+
+ if (Endpoint_IsINReady())
+ {
+
+ dprint("Endpoint is ready\n");
+
+ uint8_t MIDICommand = 0;
+ uint8_t MIDIPitch;
+
+ /* Get board button status - if pressed use channel 10 (percussion), otherwise use channel 1 */
+ uint8_t Channel = MIDI_CHANNEL(1);
+
+ MIDICommand = MIDI_COMMAND_NOTE_ON;
+ MIDIPitch = 0x3E;
+
+ /* Check if a MIDI command is to be sent */
+ if (MIDICommand)
+ {
+ dprint("Command exists\n");
+ MIDI_EventPacket_t MIDIEvent = (MIDI_EventPacket_t)
+ {
+ .Event = MIDI_EVENT(0, MIDICommand),
+
+ .Data1 = MIDICommand | Channel,
+ .Data2 = MIDIPitch,
+ .Data3 = MIDI_STANDARD_VELOCITY,
+ };
+
+ /* Write the MIDI event packet to the endpoint */
+ Endpoint_Write_Stream_LE(&MIDIEvent, sizeof(MIDIEvent), NULL);
+
+ /* Send the data in the endpoint to the host */
+ Endpoint_ClearIN();
+ }
+ }
+
+
+ /* Select the MIDI OUT stream */
+ Endpoint_SelectEndpoint(MIDI_STREAM_OUT_EPADDR);
+
+ /* Check if a MIDI command has been received */
+ if (Endpoint_IsOUTReceived())
+ {
+ MIDI_EventPacket_t MIDIEvent;
+
+ /* Read the MIDI event packet from the endpoint */
+ Endpoint_Read_Stream_LE(&MIDIEvent, sizeof(MIDIEvent), NULL);
+
+ /* If the endpoint is now empty, clear the bank */
+ if (!(Endpoint_BytesInEndpoint()))
+ {
+ /* Clear the endpoint ready for new packet */
+ Endpoint_ClearOUT();
+ }
+ }
+}
+
#endif
@@ -761,10 +828,10 @@ int main(void)
midi_register_cc_callback(&midi_device, cc_callback);
midi_register_sysex_callback(&midi_device, sysex_callback);
- midi_send_cc(&midi_device, 0, 1, 2);
- midi_send_cc(&midi_device, 15, 1, 0);
- midi_send_noteon(&midi_device, 0, 64, 127);
- midi_send_noteoff(&midi_device, 0, 64, 127);
+ // midi_send_cc(&midi_device, 0, 1, 2);
+ // midi_send_cc(&midi_device, 15, 1, 0);
+ // midi_send_noteon(&midi_device, 0, 64, 127);
+ // midi_send_noteoff(&midi_device, 0, 64, 127);
#endif
@@ -795,12 +862,14 @@ int main(void)
}
}
- keyboard_task();
-
#ifdef MIDI_ENABLE
midi_device_process(&midi_device);
+ // MIDI_Task();
#endif
+ keyboard_task();
+
+
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
USB_USBTask();
#endif
diff --git a/protocol/lufa/lufa.h b/protocol/lufa/lufa.h
index 554d82ae5f..8bcd8503a6 100644
--- a/protocol/lufa/lufa.h
+++ b/protocol/lufa/lufa.h
@@ -68,17 +68,18 @@ typedef struct {
} __attribute__ ((packed)) report_extra_t;
#ifdef MIDI_ENABLE
+void MIDI_Task(void);
MidiDevice midi_device;
#endif
-#if LUFA_VERSION_INTEGER < 0x120730
- /* old API 120219 */
- #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint(epnum, eptype, epdir, epsize, epbank)
-#else
+// #if LUFA_VERSION_INTEGER < 0x120730
+// /* old API 120219 */
+// #define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint(epnum, eptype, epdir, epsize, epbank)
+// #else
/* new API >= 120730 */
#define ENDPOINT_BANK_SINGLE 1
#define ENDPOINT_BANK_DOUBLE 2
#define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum) , eptype, epsize, epbank)
-#endif
+// #endif
#endif