diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-06-30 01:29:31 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-06-30 01:29:31 +0200 |
commit | 3a39803b4d66096899573f5203f3191c9db93697 (patch) | |
tree | 8b14339ae55144f00d8cb6d383f1eb4627c0173a /lib/lufa-descriptor-midi.c | |
parent | ported usb-keyboardmouse to new lufa (diff) |
ported usb-midi to new lufa
Diffstat (limited to 'lib/lufa-descriptor-midi.c')
-rw-r--r-- | lib/lufa-descriptor-midi.c | 395 |
1 files changed, 190 insertions, 205 deletions
diff --git a/lib/lufa-descriptor-midi.c b/lib/lufa-descriptor-midi.c index b804386..d88198f 100644 --- a/lib/lufa-descriptor-midi.c +++ b/lib/lufa-descriptor-midi.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2012. + Copyright (C) Dean Camera, 2014. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -18,7 +18,7 @@ advertising or publicity pertaining to distribution of the software without specific, written prior permission. - The author disclaim all warranties with regard to this + The author disclaims all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the author be liable for any special, indirect or consequential damages or any damages @@ -44,24 +44,24 @@ */ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = { - .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, + .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, - .USBSpecification = VERSION_BCD(01.10), - .Class = USB_CSCP_NoDeviceClass, - .SubClass = USB_CSCP_NoDeviceSubclass, - .Protocol = USB_CSCP_NoDeviceProtocol, + .USBSpecification = VERSION_BCD(1,1,0), + .Class = USB_CSCP_NoDeviceClass, + .SubClass = USB_CSCP_NoDeviceSubclass, + .Protocol = USB_CSCP_NoDeviceProtocol, - .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, + .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, - .VendorID = 0x03EB, - .ProductID = 0x2048, - .ReleaseNumber = VERSION_BCD(00.01), + .VendorID = 0x03EB, + .ProductID = 0x2048, + .ReleaseNumber = VERSION_BCD(0,0,1), - .ManufacturerStrIndex = 0x01, - .ProductStrIndex = 0x02, - .SerialNumStrIndex = NO_DESCRIPTOR, + .ManufacturerStrIndex = STRING_ID_Manufacturer, + .ProductStrIndex = STRING_ID_Product, + .SerialNumStrIndex = NO_DESCRIPTOR, - .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS + .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS }; /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage @@ -71,219 +71,204 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = */ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = { - .Config = - { - .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, + .Config = + { + .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, - .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), - .TotalInterfaces = 2, + .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), + .TotalInterfaces = 2, - .ConfigurationNumber = 1, - .ConfigurationStrIndex = NO_DESCRIPTOR, + .ConfigurationNumber = 1, + .ConfigurationStrIndex = NO_DESCRIPTOR, - .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), + .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), - .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) - }, + .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) + }, - .Audio_ControlInterface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, + .Audio_ControlInterface = + { + .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - .InterfaceNumber = 0, - .AlternateSetting = 0, + .InterfaceNumber = INTERFACE_ID_AudioControl, + .AlternateSetting = 0, - .TotalEndpoints = 0, + .TotalEndpoints = 0, - .Class = AUDIO_CSCP_AudioClass, - .SubClass = AUDIO_CSCP_ControlSubclass, - .Protocol = AUDIO_CSCP_ControlProtocol, + .Class = AUDIO_CSCP_AudioClass, + .SubClass = AUDIO_CSCP_ControlSubclass, + .Protocol = AUDIO_CSCP_ControlProtocol, - .InterfaceStrIndex = NO_DESCRIPTOR - }, + .InterfaceStrIndex = NO_DESCRIPTOR + }, - .Audio_ControlInterface_SPC = - { - .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface}, - .Subtype = AUDIO_DSUBTYPE_CSInterface_Header, + .Audio_ControlInterface_SPC = + { + .Header = {.Size = sizeof(USB_Audio_Descriptor_Interface_AC_t), .Type = DTYPE_CSInterface}, + .Subtype = AUDIO_DSUBTYPE_CSInterface_Header, - .ACSpecification = VERSION_BCD(01.00), - .TotalLength = sizeof(USB_Audio_Descriptor_Interface_AC_t), + .ACSpecification = VERSION_BCD(1,0,0), + .TotalLength = sizeof(USB_Audio_Descriptor_Interface_AC_t), - .InCollection = 1, - .InterfaceNumber = 1, - }, + .InCollection = 1, + .InterfaceNumber = INTERFACE_ID_AudioStream, + }, - .Audio_StreamInterface = - { - .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, + .Audio_StreamInterface = + { + .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, - .InterfaceNumber = 1, - .AlternateSetting = 0, + .InterfaceNumber = INTERFACE_ID_AudioStream, + .AlternateSetting = 0, - .TotalEndpoints = 2, + .TotalEndpoints = 2, - .Class = AUDIO_CSCP_AudioClass, - .SubClass = AUDIO_CSCP_MIDIStreamingSubclass, - .Protocol = AUDIO_CSCP_StreamingProtocol, + .Class = AUDIO_CSCP_AudioClass, + .SubClass = AUDIO_CSCP_MIDIStreamingSubclass, + .Protocol = AUDIO_CSCP_StreamingProtocol, - .InterfaceStrIndex = NO_DESCRIPTOR - }, + .InterfaceStrIndex = NO_DESCRIPTOR + }, - .Audio_StreamInterface_SPC = - { - .Header = {.Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t), .Type = DTYPE_CSInterface}, - .Subtype = AUDIO_DSUBTYPE_CSInterface_General, + .Audio_StreamInterface_SPC = + { + .Header = {.Size = sizeof(USB_MIDI_Descriptor_AudioInterface_AS_t), .Type = DTYPE_CSInterface}, + .Subtype = AUDIO_DSUBTYPE_CSInterface_General, - .AudioSpecification = VERSION_BCD(01.00), + .AudioSpecification = VERSION_BCD(1,0,0), - .TotalLength = (sizeof(USB_Descriptor_Configuration_t) - - offsetof(USB_Descriptor_Configuration_t, Audio_StreamInterface_SPC)) - }, + .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, + .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, + .JackType = MIDI_JACKTYPE_Embedded, + .JackID = 0x01, - .JackStrIndex = NO_DESCRIPTOR - }, + .JackStrIndex = NO_DESCRIPTOR + }, - .MIDI_In_Jack_Ext = - { - .Header = {.Size = sizeof(USB_MIDI_Descriptor_InputJack_t), .Type = DTYPE_CSInterface}, - .Subtype = AUDIO_DSUBTYPE_CSInterface_InputTerminal, + .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, + .JackType = MIDI_JACKTYPE_External, + .JackID = 0x02, - .JackStrIndex = NO_DESCRIPTOR - }, + .JackStrIndex = NO_DESCRIPTOR + }, - .MIDI_Out_Jack_Emb = - { - .Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface}, - .Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal, + .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, + .JackType = MIDI_JACKTYPE_Embedded, + .JackID = 0x03, - .NumberOfPins = 1, - .SourceJackID = {0x02}, - .SourcePinID = {0x01}, + .NumberOfPins = 1, + .SourceJackID = {0x02}, + .SourcePinID = {0x01}, - .JackStrIndex = NO_DESCRIPTOR - }, + .JackStrIndex = NO_DESCRIPTOR + }, - .MIDI_Out_Jack_Ext = - { - .Header = {.Size = sizeof(USB_MIDI_Descriptor_OutputJack_t), .Type = DTYPE_CSInterface}, - .Subtype = AUDIO_DSUBTYPE_CSInterface_OutputTerminal, + .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, + .JackType = MIDI_JACKTYPE_External, + .JackID = 0x04, - .NumberOfPins = 1, - .SourceJackID = {0x01}, - .SourcePinID = {0x01}, + .NumberOfPins = 1, + .SourceJackID = {0x01}, + .SourcePinID = {0x01}, - .JackStrIndex = NO_DESCRIPTOR - }, + .JackStrIndex = NO_DESCRIPTOR + }, - .MIDI_In_Jack_Endpoint = - { - .Endpoint = - { - .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint}, + .MIDI_In_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 - }, + .EndpointAddress = MIDI_STREAM_OUT_EPADDR, + .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = MIDI_STREAM_EPSIZE, + .PollingIntervalMS = 0x05 + }, - .Refresh = 0, - .SyncEndpointNumber = 0 - }, + .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, + .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} - }, + .TotalEmbeddedJacks = 0x01, + .AssociatedJackID = {0x01} + }, - .MIDI_Out_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_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} - } + .MIDI_Out_Jack_Endpoint = + { + .Endpoint = + { + .Header = {.Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), .Type = DTYPE_Endpoint}, + + .EndpointAddress = MIDI_STREAM_IN_EPADDR, + .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), + .EndpointSize = MIDI_STREAM_EPSIZE, + .PollingIntervalMS = 0x05 + }, + + .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} + } }; /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate * via the language ID table available at USB.org what languages the device supports for its string descriptors. */ -const USB_Descriptor_String_t PROGMEM LanguageString = -{ - .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, - - .UnicodeString = {LANGUAGE_ID_ENG} -}; +const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG); /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * Descriptor. */ -const USB_Descriptor_String_t PROGMEM ManufacturerString = -{ #ifndef USB_MANUFACTURER - .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, - .UnicodeString = L"Dean Camera" +const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"Dean Camera"); #else - .Header = {.Size = USB_STRING_LEN(USB_MANUFACTURER_LEN), .Type = DTYPE_String}, - .UnicodeString = USB_MANUFACTURER +const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(USB_MANUFACTURER); #endif -}; /** Product descriptor string. This is a Unicode string containing the product's details in human readable form, * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * Descriptor. */ -const USB_Descriptor_String_t PROGMEM ProductString = -{ #ifndef USB_PRODUCT - .Header = {.Size = USB_STRING_LEN(14), .Type = DTYPE_String}, - .UnicodeString = L"LUFA MIDI Demo" +const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA MIDI Demo"); #else - .Header = {.Size = USB_STRING_LEN(USB_PRODUCT_LEN), .Type = DTYPE_String}, - .UnicodeString = USB_PRODUCT +const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(USB_PRODUCT); #endif -}; /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" * documentation) by the application code so that the address and size of a requested descriptor can be given @@ -295,43 +280,43 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, const void** const DescriptorAddress) { - const uint8_t DescriptorType = (wValue >> 8); - const uint8_t DescriptorNumber = (wValue & 0xFF); - - const void* Address = NULL; - uint16_t Size = NO_DESCRIPTOR; - - switch (DescriptorType) - { - case DTYPE_Device: - Address = &DeviceDescriptor; - Size = sizeof(USB_Descriptor_Device_t); - break; - case DTYPE_Configuration: - Address = &ConfigurationDescriptor; - Size = sizeof(USB_Descriptor_Configuration_t); - break; - case DTYPE_String: - switch (DescriptorNumber) - { - case 0x00: - Address = &LanguageString; - Size = pgm_read_byte(&LanguageString.Header.Size); - break; - case 0x01: - Address = &ManufacturerString; - Size = pgm_read_byte(&ManufacturerString.Header.Size); - break; - case 0x02: - Address = &ProductString; - Size = pgm_read_byte(&ProductString.Header.Size); - break; - } - - break; - } - - *DescriptorAddress = Address; - return Size; + const uint8_t DescriptorType = (wValue >> 8); + const uint8_t DescriptorNumber = (wValue & 0xFF); + + const void* Address = NULL; + uint16_t Size = NO_DESCRIPTOR; + + switch (DescriptorType) + { + case DTYPE_Device: + Address = &DeviceDescriptor; + Size = sizeof(USB_Descriptor_Device_t); + break; + case DTYPE_Configuration: + Address = &ConfigurationDescriptor; + Size = sizeof(USB_Descriptor_Configuration_t); + break; + case DTYPE_String: + switch (DescriptorNumber) + { + case STRING_ID_Language: + Address = &LanguageString; + Size = pgm_read_byte(&LanguageString.Header.Size); + break; + case STRING_ID_Manufacturer: + Address = &ManufacturerString; + Size = pgm_read_byte(&ManufacturerString.Header.Size); + break; + case STRING_ID_Product: + Address = &ProductString; + Size = pgm_read_byte(&ProductString.Header.Size); + break; + } + + break; + } + + *DescriptorAddress = Address; + return Size; } |