Skip to content

Commit

Permalink
midi
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhumbert committed Aug 20, 2015
1 parent 2d76b5c commit e528087
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 9 deletions.
2 changes: 1 addition & 1 deletion keyboard/planck/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SRC = extended_keymap_common.c \
$(MATRIX) \
led.c \
backlight.c \
beeps.c
beeps.c

ifdef KEYMAP
SRC := extended_keymaps/extended_keymap_$(KEYMAP).c $(SRC)
Expand Down
2 changes: 1 addition & 1 deletion keyboard/planck/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PRODUCT_ID 0x6060
#define DEVICE_VER 0x0001
#define MANUFACTURER Ortholinear Keyboards
#define PRODUCT Planck
#define PRODUCT The Planck Keyboard
#define DESCRIPTION A compact ortholinear keyboard

/* key matrix size */
Expand Down
1 change: 1 addition & 0 deletions keyboard/planck/extended_keymap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef union {
keymap_config_t keymap_config;
#endif


/* translates key to keycode */
uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);

Expand Down
13 changes: 11 additions & 2 deletions keyboard/planck/extended_keymaps/extended_keymap_default.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "extended_keymap_common.h"
#include "backlight.h"
#include "lufa.h"

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = { /* Qwerty */
Expand Down Expand Up @@ -50,10 +51,18 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
switch(id) {
case 0:
if (record->event.pressed) {
register_code(KC_RSFT);
if (!&midi_device) {
register_code(KC_RSFT);
} else {
midi_send_noteon(&midi_device, 1, 64, 127);
}
backlight_step();
} else {
unregister_code(KC_RSFT);
if (!&midi_device) {
unregister_code(KC_RSFT);
} else {
midi_send_noteoff(&midi_device, 1, 64, 127);
}
}
break;
}
Expand Down
1 change: 1 addition & 0 deletions keyboard/planck/matrix_pcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void matrix_init(void)
}
}


uint8_t matrix_scan(void)
{
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
Expand Down
7 changes: 6 additions & 1 deletion protocol/lufa.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ endif

LUFA_SRC = $(LUFA_DIR)/lufa.c \
$(LUFA_DIR)/descriptor.c \
$(LUFA_SRC_USB)
$(LUFA_SRC_USB) \
$(LUFA_DIR)/midi/midi.c \
$(LUFA_DIR)/midi/midi_device.c \
$(LUFA_DIR)/midi/bytequeue/bytequeue.c \
$(LUFA_DIR)/midi/bytequeue/interrupt_setting.c \
$(LUFA_DIR)/LUFA-git/LUFA/Drivers/USB/Class/Device/MIDIClassDevice.c

SRC += $(LUFA_SRC)

Expand Down
158 changes: 158 additions & 0 deletions protocol/lufa/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,164 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.PollingIntervalMS = 0x01
},
#endif

.Audio_ControlInterface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},

.InterfaceNumber = (NKRO_INTERFACE + 1),
.AlternateSetting = 0,

.TotalEndpoints = 0,

.Class = AUDIO_CSCP_AudioClass,
.SubClass = AUDIO_CSCP_ControlSubclass,
.Protocol = AUDIO_CSCP_ControlProtocol,

.InterfaceStrIndex = NO_DESCRIPTOR
},

.Audio_ControlInterface_SPC =
{
.Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface},
.Subtype = AUDIO_DSUBTYPE_CSInterface_Header,

.ACSpecification = VERSION_BCD(1,1,1),
.TotalLength = sizeof(USB_Audio_Descriptor_Interface_AC_t),

.InCollection = 1,
.InterfaceNumber = (NKRO_INTERFACE + 2),
},

.Audio_StreamInterface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},

.InterfaceNumber = (NKRO_INTERFACE + 2),
.AlternateSetting = 0,

.TotalEndpoints = 2,

.Class = AUDIO_CSCP_AudioClass,
.SubClass = AUDIO_CSCP_MIDIStreamingSubclass,
.Protocol = AUDIO_CSCP_StreamingProtocol,

.InterfaceStrIndex = NO_DESCRIPTOR
},

.Audio_StreamInterface_SPC =
{
.Header = {.Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t), .Type = DTYPE_CSInterface},
.Subtype = AUDIO_DSUBTYPE_CSInterface_General,

.AudioSpecification = VERSION_BCD(1,1,1),

.TotalLength = (sizeof(USB_Descriptor_Configuration_t) -
offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC))
},

.MIDI_In_Jack_Emb =
{
.Header = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
.Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,

.JackType = MIDI_JACKTYPE_Embedded,
.JackID = 0x01,

.JackStrIndex = NO_DESCRIPTOR
},

.MIDI_In_Jack_Ext =
{
.Header = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface},
.Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal,

.JackType = MIDI_JACKTYPE_External,
.JackID = 0x02,

.JackStrIndex = NO_DESCRIPTOR
},

.MIDI_Out_Jack_Emb =
{
.Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
.Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,

.JackType = MIDI_JACKTYPE_Embedded,
.JackID = 0x03,

.NumberOfPins = 1,
.SourceJackID = {0x02},
.SourcePinID = {0x01},

.JackStrIndex = NO_DESCRIPTOR
},

.MIDI_Out_Jack_Ext =
{
.Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface},
.Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal,

.JackType = MIDI_JACKTYPE_External,
.JackID = 0x04,

.NumberOfPins = 1,
.SourceJackID = {0x01},
.SourcePinID = {0x01},

.JackStrIndex = NO_DESCRIPTOR
},

.MIDI_In_Jack_Endpoint =
{
.Endpoint =
{
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},

.EndpointAddress = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = MIDI_STREAM_EPSIZE,
.PollingIntervalMS = 0x01
},

.Refresh = 0,
.SyncEndpointNumber = 0
},

.MIDI_In_Jack_Endpoint_SPC =
{
.Header = {.Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t), .Type = DTYPE_CSEndpoint},
.Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,

.TotalEmbeddedJacks = 0x01,
.AssociatedJackID = {0x01}
},

.MIDI_Out_Jack_Endpoint =
{
.Endpoint =
{
.Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint},

.EndpointAddress = (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = MIDI_STREAM_EPSIZE,
.PollingIntervalMS = 0x01
},

.Refresh = 0,
.SyncEndpointNumber = 0
},

.MIDI_Out_Jack_Endpoint_SPC =
{
.Header = {.Size = sizeof(USB_MIDI_Descriptor_Jack_Endpoint_t), .Type = DTYPE_CSEndpoint},
.Subtype = AUDIO_DSUBTYPE_CSEndpoint_General,

.TotalEmbeddedJacks = 0x01,
.AssociatedJackID = {0x03}
}

};


Expand Down
23 changes: 22 additions & 1 deletion protocol/lufa/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ typedef struct
USB_HID_Descriptor_HID_t NKRO_HID;
USB_Descriptor_Endpoint_t NKRO_INEndpoint;
#endif

// MIDI Audio Control Interface
USB_Descriptor_Interface_t Audio_ControlInterface;
USB_Audio_Descriptor_Interface_AC_t Audio_ControlInterface_SPC;

// MIDI Audio Streaming Interface
USB_Descriptor_Interface_t Audio_StreamInterface;
USB_MIDI_Descriptor_AudioInterface_AS_t Audio_StreamInterface_SPC;
USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Emb;
USB_MIDI_Descriptor_InputJack_t MIDI_In_Jack_Ext;
USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Emb;
USB_MIDI_Descriptor_OutputJack_t MIDI_Out_Jack_Ext;
USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_In_Jack_Endpoint;
USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_In_Jack_Endpoint_SPC;
USB_Audio_Descriptor_StreamEndpoint_Std_t MIDI_Out_Jack_Endpoint;
USB_MIDI_Descriptor_Jack_Endpoint_t MIDI_Out_Jack_Endpoint_SPC;

} USB_Descriptor_Configuration_t;


Expand Down Expand Up @@ -117,7 +134,7 @@ typedef struct


/* nubmer of interfaces */
#define TOTAL_INTERFACES (NKRO_INTERFACE + 1)
#define TOTAL_INTERFACES (NKRO_INTERFACE + 3)


// Endopoint number and size
Expand Down Expand Up @@ -150,12 +167,16 @@ typedef struct
# endif
#endif

#define MIDI_STREAM_IN_EPNUM (NKRO_IN_EPNUM + 1)
#define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 1)


#define KEYBOARD_EPSIZE 8
#define MOUSE_EPSIZE 8
#define EXTRAKEY_EPSIZE 8
#define CONSOLE_EPSIZE 32
#define NKRO_EPSIZE 16
#define MIDI_STREAM_EPSIZE 64


uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
Expand Down
Loading

0 comments on commit e528087

Please sign in to comment.