summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-06-30 01:56:20 +0200
committerChristian Pointner <equinox@spreadspace.org>2015-06-30 01:56:20 +0200
commit6136d891b10c01af0e0108c14a3c4031ea44e826 (patch)
treebac70d78361e0eef6d6a45d7456ba249ca5c3883
parentported usb-midi to new lufa (diff)
ported usb-dua-serial to new lufa
-rw-r--r--lib/lufa-descriptor-usbdualserial.c468
-rw-r--r--lib/lufa-descriptor-usbdualserial.h171
-rw-r--r--usb-dual-serial/Makefile6
-rw-r--r--usb-dual-serial/usb-dual-serial.c111
4 files changed, 388 insertions, 368 deletions
diff --git a/lib/lufa-descriptor-usbdualserial.c b/lib/lufa-descriptor-usbdualserial.c
index f270b5f..e26b5f9 100644
--- a/lib/lufa-descriptor-usbdualserial.c
+++ b/lib/lufa-descriptor-usbdualserial.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
@@ -37,17 +37,6 @@
#include "lufa-descriptor-usbdualserial.h"
-/* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
- * the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
- * This allows the host to track a device across insertions on different ports, allowing them to retain allocated
- * resources like COM port numbers and drivers. On demos using this feature, give a warning on unsupported devices
- * so that the user can supply their own serial number descriptor instead or remove the USE_INTERNAL_SERIAL value
- * from the Device Descriptor (forcing the host to generate a serial number for each device from the VID, PID and
- * port location).
- */
-#if (USE_INTERNAL_SERIAL == NO_DESCRIPTOR)
- #warning USE_INTERNAL_SERIAL is not available on this AVR - please manually construct a device serial descriptor.
-#endif
/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
* device characteristics, including the supported USB version, control endpoint size and the
@@ -56,24 +45,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_IADDeviceClass,
- .SubClass = USB_CSCP_IADDeviceSubclass,
- .Protocol = USB_CSCP_IADDeviceProtocol,
+ .USBSpecification = VERSION_BCD(1,1,0),
+ .Class = USB_CSCP_IADDeviceClass,
+ .SubClass = USB_CSCP_IADDeviceSubclass,
+ .Protocol = USB_CSCP_IADDeviceProtocol,
- .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
+ .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
- .VendorID = 0x03EB,
- .ProductID = 0x204E,
- .ReleaseNumber = VERSION_BCD(00.01),
+ .VendorID = 0x03EB,
+ .ProductID = 0x204E,
+ .ReleaseNumber = VERSION_BCD(0,0,1),
- .ManufacturerStrIndex = 0x01,
- .ProductStrIndex = 0x02,
- .SerialNumStrIndex = USE_INTERNAL_SERIAL,
+ .ManufacturerStrIndex = STRING_ID_Manufacturer,
+ .ProductStrIndex = STRING_ID_Product,
+ .SerialNumStrIndex = USE_INTERNAL_SERIAL,
- .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
+ .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};
/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
@@ -83,264 +72,249 @@ 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 = 4,
+ .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
+ .TotalInterfaces = 4,
- .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)
+ },
- .CDC1_IAD =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
+ .CDC1_IAD =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
- .FirstInterfaceIndex = 0,
- .TotalInterfaces = 2,
+ .FirstInterfaceIndex = INTERFACE_ID_CDC1_CCI,
+ .TotalInterfaces = 2,
- .Class = CDC_CSCP_CDCClass,
- .SubClass = CDC_CSCP_ACMSubclass,
- .Protocol = CDC_CSCP_ATCommandProtocol,
+ .Class = CDC_CSCP_CDCClass,
+ .SubClass = CDC_CSCP_ACMSubclass,
+ .Protocol = CDC_CSCP_ATCommandProtocol,
- .IADStrIndex = NO_DESCRIPTOR
- },
+ .IADStrIndex = NO_DESCRIPTOR
+ },
- .CDC1_CCI_Interface =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+ .CDC1_CCI_Interface =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
- .InterfaceNumber = 0,
- .AlternateSetting = 0,
+ .InterfaceNumber = INTERFACE_ID_CDC1_CCI,
+ .AlternateSetting = 0,
- .TotalEndpoints = 1,
+ .TotalEndpoints = 1,
- .Class = CDC_CSCP_CDCClass,
- .SubClass = CDC_CSCP_ACMSubclass,
- .Protocol = CDC_CSCP_ATCommandProtocol,
+ .Class = CDC_CSCP_CDCClass,
+ .SubClass = CDC_CSCP_ACMSubclass,
+ .Protocol = CDC_CSCP_ATCommandProtocol,
- .InterfaceStrIndex = NO_DESCRIPTOR
- },
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
- .CDC1_Functional_Header =
- {
- .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
- .Subtype = CDC_DSUBTYPE_CSInterface_Header,
+ .CDC1_Functional_Header =
+ {
+ .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
+ .Subtype = CDC_DSUBTYPE_CSInterface_Header,
- .CDCSpecification = VERSION_BCD(01.10),
- },
+ .CDCSpecification = VERSION_BCD(1,1,0),
+ },
- .CDC1_Functional_ACM =
- {
- .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
- .Subtype = CDC_DSUBTYPE_CSInterface_ACM,
+ .CDC1_Functional_ACM =
+ {
+ .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
+ .Subtype = CDC_DSUBTYPE_CSInterface_ACM,
- .Capabilities = 0x06,
- },
+ .Capabilities = 0x06,
+ },
- .CDC1_Functional_Union =
- {
- .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
- .Subtype = CDC_DSUBTYPE_CSInterface_Union,
+ .CDC1_Functional_Union =
+ {
+ .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
+ .Subtype = CDC_DSUBTYPE_CSInterface_Union,
- .MasterInterfaceNumber = 0,
- .SlaveInterfaceNumber = 1,
- },
+ .MasterInterfaceNumber = INTERFACE_ID_CDC1_CCI,
+ .SlaveInterfaceNumber = INTERFACE_ID_CDC1_DCI,
+ },
- .CDC1_ManagementEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+ .CDC1_ManagementEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | CDC1_NOTIFICATION_EPNUM),
- .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = CDC_NOTIFICATION_EPSIZE,
- .PollingIntervalMS = 0xFF
- },
+ .EndpointAddress = CDC1_NOTIFICATION_EPADDR,
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = CDC_NOTIFICATION_EPSIZE,
+ .PollingIntervalMS = 0xFF
+ },
- .CDC1_DCI_Interface =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+ .CDC1_DCI_Interface =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
- .InterfaceNumber = 1,
- .AlternateSetting = 0,
+ .InterfaceNumber = INTERFACE_ID_CDC1_DCI,
+ .AlternateSetting = 0,
- .TotalEndpoints = 2,
+ .TotalEndpoints = 2,
- .Class = CDC_CSCP_CDCDataClass,
- .SubClass = CDC_CSCP_NoDataSubclass,
- .Protocol = CDC_CSCP_NoDataProtocol,
+ .Class = CDC_CSCP_CDCDataClass,
+ .SubClass = CDC_CSCP_NoDataSubclass,
+ .Protocol = CDC_CSCP_NoDataProtocol,
- .InterfaceStrIndex = NO_DESCRIPTOR
- },
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
- .CDC1_DataOutEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+ .CDC1_DataOutEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_OUT | CDC1_RX_EPNUM),
- .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = CDC_TXRX_EPSIZE,
- .PollingIntervalMS = 0x01
- },
+ .EndpointAddress = CDC1_RX_EPADDR,
+ .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = CDC_TXRX_EPSIZE,
+ .PollingIntervalMS = 0x05
+ },
- .CDC1_DataInEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+ .CDC1_DataInEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | CDC1_TX_EPNUM),
- .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = CDC_TXRX_EPSIZE,
- .PollingIntervalMS = 0x01
- },
+ .EndpointAddress = CDC1_TX_EPADDR,
+ .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = CDC_TXRX_EPSIZE,
+ .PollingIntervalMS = 0x05
+ },
- .CDC2_IAD =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
+ .CDC2_IAD =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
- .FirstInterfaceIndex = 2,
- .TotalInterfaces = 2,
+ .FirstInterfaceIndex = INTERFACE_ID_CDC2_CCI,
+ .TotalInterfaces = 2,
- .Class = CDC_CSCP_CDCClass,
- .SubClass = CDC_CSCP_ACMSubclass,
- .Protocol = CDC_CSCP_ATCommandProtocol,
+ .Class = CDC_CSCP_CDCClass,
+ .SubClass = CDC_CSCP_ACMSubclass,
+ .Protocol = CDC_CSCP_ATCommandProtocol,
- .IADStrIndex = NO_DESCRIPTOR
- },
+ .IADStrIndex = NO_DESCRIPTOR
+ },
- .CDC2_CCI_Interface =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+ .CDC2_CCI_Interface =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
- .InterfaceNumber = 2,
- .AlternateSetting = 0,
+ .InterfaceNumber = INTERFACE_ID_CDC2_CCI,
+ .AlternateSetting = 0,
- .TotalEndpoints = 1,
+ .TotalEndpoints = 1,
- .Class = CDC_CSCP_CDCClass,
- .SubClass = CDC_CSCP_ACMSubclass,
- .Protocol = CDC_CSCP_ATCommandProtocol,
+ .Class = CDC_CSCP_CDCClass,
+ .SubClass = CDC_CSCP_ACMSubclass,
+ .Protocol = CDC_CSCP_ATCommandProtocol,
- .InterfaceStrIndex = NO_DESCRIPTOR
- },
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
- .CDC2_Functional_Header =
- {
- .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
- .Subtype = CDC_DSUBTYPE_CSInterface_Header,
+ .CDC2_Functional_Header =
+ {
+ .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
+ .Subtype = CDC_DSUBTYPE_CSInterface_Header,
- .CDCSpecification = VERSION_BCD(01.10),
- },
+ .CDCSpecification = VERSION_BCD(1,1,0),
+ },
- .CDC2_Functional_ACM =
- {
- .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
- .Subtype = CDC_DSUBTYPE_CSInterface_ACM,
+ .CDC2_Functional_ACM =
+ {
+ .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
+ .Subtype = CDC_DSUBTYPE_CSInterface_ACM,
- .Capabilities = 0x06,
- },
+ .Capabilities = 0x06,
+ },
- .CDC2_Functional_Union =
- {
- .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
- .Subtype = CDC_DSUBTYPE_CSInterface_Union,
+ .CDC2_Functional_Union =
+ {
+ .Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
+ .Subtype = CDC_DSUBTYPE_CSInterface_Union,
- .MasterInterfaceNumber = 2,
- .SlaveInterfaceNumber = 3,
- },
+ .MasterInterfaceNumber = INTERFACE_ID_CDC2_CCI,
+ .SlaveInterfaceNumber = INTERFACE_ID_CDC2_DCI,
+ },
- .CDC2_ManagementEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+ .CDC2_ManagementEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | CDC2_NOTIFICATION_EPNUM),
- .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = CDC_NOTIFICATION_EPSIZE,
- .PollingIntervalMS = 0xFF
- },
+ .EndpointAddress = CDC2_NOTIFICATION_EPADDR,
+ .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = CDC_NOTIFICATION_EPSIZE,
+ .PollingIntervalMS = 0xFF
+ },
- .CDC2_DCI_Interface =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
+ .CDC2_DCI_Interface =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
- .InterfaceNumber = 3,
- .AlternateSetting = 0,
+ .InterfaceNumber = INTERFACE_ID_CDC2_DCI,
+ .AlternateSetting = 0,
- .TotalEndpoints = 2,
+ .TotalEndpoints = 2,
- .Class = CDC_CSCP_CDCDataClass,
- .SubClass = CDC_CSCP_NoDataSubclass,
- .Protocol = CDC_CSCP_NoDataProtocol,
+ .Class = CDC_CSCP_CDCDataClass,
+ .SubClass = CDC_CSCP_NoDataSubclass,
+ .Protocol = CDC_CSCP_NoDataProtocol,
- .InterfaceStrIndex = NO_DESCRIPTOR
- },
-
- .CDC2_DataOutEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
-
- .EndpointAddress = (ENDPOINT_DIR_OUT | CDC2_RX_EPNUM),
- .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = CDC_TXRX_EPSIZE,
- .PollingIntervalMS = 0x01
- },
+ .InterfaceStrIndex = NO_DESCRIPTOR
+ },
+
+ .CDC2_DataOutEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+
+ .EndpointAddress = CDC2_RX_EPADDR,
+ .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = CDC_TXRX_EPSIZE,
+ .PollingIntervalMS = 0x05
+ },
- .CDC2_DataInEndpoint =
- {
- .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
+ .CDC2_DataInEndpoint =
+ {
+ .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | CDC2_TX_EPNUM),
- .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
- .EndpointSize = CDC_TXRX_EPSIZE,
- .PollingIntervalMS = 0x01
- }
+ .EndpointAddress = CDC2_TX_EPADDR,
+ .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
+ .EndpointSize = CDC_TXRX_EPSIZE,
+ .PollingIntervalMS = 0x05
+ }
};
/** 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(13), .Type = DTYPE_String},
- .UnicodeString = L"LUFA Dual CDC Demo"
+const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA Dual CDC 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
@@ -352,43 +326,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;
}
diff --git a/lib/lufa-descriptor-usbdualserial.h b/lib/lufa-descriptor-usbdualserial.h
index 01d10f2..195c644 100644
--- a/lib/lufa-descriptor-usbdualserial.h
+++ b/lib/lufa-descriptor-usbdualserial.h
@@ -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
@@ -36,77 +36,100 @@
#ifndef _DESCRIPTORS_H_
#define _DESCRIPTORS_H_
- /* Includes: */
- #include <avr/pgmspace.h>
-
- #include <LUFA/Drivers/USB/USB.h>
-
- /* Macros: */
- /** Endpoint number of the first CDC interface's device-to-host data IN endpoint. */
- #define CDC1_TX_EPNUM 1
-
- /** Endpoint number of the first CDC interface's host-to-device data OUT endpoint. */
- #define CDC1_RX_EPNUM 2
-
- /** Endpoint number of the first CDC interface's device-to-host notification IN endpoint. */
- #define CDC1_NOTIFICATION_EPNUM 3
-
- /** Endpoint number of the second CDC interface's device-to-host data IN endpoint. */
- #define CDC2_TX_EPNUM 4
-
- /** Endpoint number of the second CDC interface's host-to-device data OUT endpoint. */
- #define CDC2_RX_EPNUM 5
-
- /** Endpoint number of the second CDC interface's device-to-host notification IN endpoint. */
- #define CDC2_NOTIFICATION_EPNUM 6
-
- /** Size in bytes of the CDC device-to-host notification IN endpoints. */
- #define CDC_NOTIFICATION_EPSIZE 8
-
- /** Size in bytes of the CDC data IN and OUT endpoints. */
- #define CDC_TXRX_EPSIZE 16
-
- /* Type Defines: */
- /** Type define for the device configuration descriptor structure. This must be defined in the
- * application code, as the configuration descriptor contains several sub-descriptors which
- * vary between devices, and which describe the device's usage to the host.
- */
- typedef struct
- {
- USB_Descriptor_Configuration_Header_t Config;
-
- // First CDC Control Interface
- USB_Descriptor_Interface_Association_t CDC1_IAD;
- USB_Descriptor_Interface_t CDC1_CCI_Interface;
- USB_CDC_Descriptor_FunctionalHeader_t CDC1_Functional_Header;
- USB_CDC_Descriptor_FunctionalACM_t CDC1_Functional_ACM;
- USB_CDC_Descriptor_FunctionalUnion_t CDC1_Functional_Union;
- USB_Descriptor_Endpoint_t CDC1_ManagementEndpoint;
-
- // First CDC Data Interface
- USB_Descriptor_Interface_t CDC1_DCI_Interface;
- USB_Descriptor_Endpoint_t CDC1_DataOutEndpoint;
- USB_Descriptor_Endpoint_t CDC1_DataInEndpoint;
-
- // Second CDC Control Interface
- USB_Descriptor_Interface_Association_t CDC2_IAD;
- USB_Descriptor_Interface_t CDC2_CCI_Interface;
- USB_CDC_Descriptor_FunctionalHeader_t CDC2_Functional_Header;
- USB_CDC_Descriptor_FunctionalACM_t CDC2_Functional_ACM;
- USB_CDC_Descriptor_FunctionalUnion_t CDC2_Functional_Union;
- USB_Descriptor_Endpoint_t CDC2_ManagementEndpoint;
-
- // Second CDC Data Interface
- USB_Descriptor_Interface_t CDC2_DCI_Interface;
- USB_Descriptor_Endpoint_t CDC2_DataOutEndpoint;
- USB_Descriptor_Endpoint_t CDC2_DataInEndpoint;
- } USB_Descriptor_Configuration_t;
-
- /* Function Prototypes: */
- uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
- const uint8_t wIndex,
- const void** const DescriptorAddress)
- ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
+ /* Includes: */
+ #include <avr/pgmspace.h>
+
+ #include <LUFA/Drivers/USB/USB.h>
+
+ /* Macros: */
+ /** Endpoint address of the first CDC interface's device-to-host data IN endpoint. */
+ #define CDC1_TX_EPADDR (ENDPOINT_DIR_IN | 1)
+
+ /** Endpoint address of the first CDC interface's host-to-device data OUT endpoint. */
+ #define CDC1_RX_EPADDR (ENDPOINT_DIR_OUT | 2)
+
+ /** Endpoint address of the first CDC interface's device-to-host notification IN endpoint. */
+ #define CDC1_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 3)
+
+ /** Endpoint address of the second CDC interface's device-to-host data IN endpoint. */
+ #define CDC2_TX_EPADDR (ENDPOINT_DIR_IN | 4)
+
+ /** Endpoint address of the second CDC interface's host-to-device data OUT endpoint. */
+ #define CDC2_RX_EPADDR (ENDPOINT_DIR_OUT | 5)
+
+ /** Endpoint address of the second CDC interface's device-to-host notification IN endpoint. */
+ #define CDC2_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 6)
+
+ /** Size in bytes of the CDC device-to-host notification IN endpoints. */
+ #define CDC_NOTIFICATION_EPSIZE 8
+
+ /** Size in bytes of the CDC data IN and OUT endpoints. */
+ #define CDC_TXRX_EPSIZE 16
+
+ /* Type Defines: */
+ /** Type define for the device configuration descriptor structure. This must be defined in the
+ * application code, as the configuration descriptor contains several sub-descriptors which
+ * vary between devices, and which describe the device's usage to the host.
+ */
+ typedef struct
+ {
+ USB_Descriptor_Configuration_Header_t Config;
+
+ // First CDC Control Interface
+ USB_Descriptor_Interface_Association_t CDC1_IAD;
+ USB_Descriptor_Interface_t CDC1_CCI_Interface;
+ USB_CDC_Descriptor_FunctionalHeader_t CDC1_Functional_Header;
+ USB_CDC_Descriptor_FunctionalACM_t CDC1_Functional_ACM;
+ USB_CDC_Descriptor_FunctionalUnion_t CDC1_Functional_Union;
+ USB_Descriptor_Endpoint_t CDC1_ManagementEndpoint;
+
+ // First CDC Data Interface
+ USB_Descriptor_Interface_t CDC1_DCI_Interface;
+ USB_Descriptor_Endpoint_t CDC1_DataOutEndpoint;
+ USB_Descriptor_Endpoint_t CDC1_DataInEndpoint;
+
+ // Second CDC Control Interface
+ USB_Descriptor_Interface_Association_t CDC2_IAD;
+ USB_Descriptor_Interface_t CDC2_CCI_Interface;
+ USB_CDC_Descriptor_FunctionalHeader_t CDC2_Functional_Header;
+ USB_CDC_Descriptor_FunctionalACM_t CDC2_Functional_ACM;
+ USB_CDC_Descriptor_FunctionalUnion_t CDC2_Functional_Union;
+ USB_Descriptor_Endpoint_t CDC2_ManagementEndpoint;
+
+ // Second CDC Data Interface
+ USB_Descriptor_Interface_t CDC2_DCI_Interface;
+ USB_Descriptor_Endpoint_t CDC2_DataOutEndpoint;
+ USB_Descriptor_Endpoint_t CDC2_DataInEndpoint;
+ } USB_Descriptor_Configuration_t;
+
+ /** Enum for the device interface descriptor IDs within the device. Each interface descriptor
+ * should have a unique ID index associated with it, which can be used to refer to the
+ * interface from other descriptors.
+ */
+ enum InterfaceDescriptors_t
+ {
+ INTERFACE_ID_CDC1_CCI = 0, /**< CDC1 CCI interface descriptor ID */
+ INTERFACE_ID_CDC1_DCI = 1, /**< CDC1 DCI interface descriptor ID */
+ INTERFACE_ID_CDC2_CCI = 2, /**< CDC2 CCI interface descriptor ID */
+ INTERFACE_ID_CDC2_DCI = 3, /**< CDC2 DCI interface descriptor ID */
+ };
+
+ /** Enum for the device string descriptor IDs within the device. Each string descriptor should
+ * have a unique ID index associated with it, which can be used to refer to the string from
+ * other descriptors.
+ */
+ enum StringDescriptors_t
+ {
+ STRING_ID_Language = 0, /**< Supported Languages string descriptor ID (must be zero) */
+ STRING_ID_Manufacturer = 1, /**< Manufacturer string ID */
+ STRING_ID_Product = 2, /**< Product string ID */
+ };
+
+ /* Function Prototypes: */
+ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
+ const uint8_t wIndex,
+ const void** const DescriptorAddress)
+ ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif
diff --git a/usb-dual-serial/Makefile b/usb-dual-serial/Makefile
index a2ea03c..8dc0e29 100644
--- a/usb-dual-serial/Makefile
+++ b/usb-dual-serial/Makefile
@@ -29,15 +29,15 @@ SPREADAVR_PATH := ..
RESET_FUNC := $(SPREADAVR_PATH)/tools/reset_lufa_cdc
RESET_PARAM := 'r'
-LUFA_PATH := $(SPREADAVR_PATH)/contrib/LUFA-120219
+LUFA_PATH := $(SPREADAVR_PATH)/contrib/lufa-LUFA-140928
LUFA_OPTS = -D USB_DEVICE_ONLY
LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
-LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\"" -D USB_MANUFACTURER_LEN=7
-LUFA_OPTS += -D USB_PRODUCT="L\"spreadspace usb-dual-serial example\"" -D USB_PRODUCT_LEN=35
+LUFA_OPTS += -D USB_MANUFACTURER="L\"equinox\""
+LUFA_OPTS += -D USB_PRODUCT="L\"spreadspace usb-dual-serial example\""
LUFA_COMPONENTS := USB USBCLASS SERIAL
diff --git a/usb-dual-serial/usb-dual-serial.c b/usb-dual-serial/usb-dual-serial.c
index 02b50be..d70095a 100644
--- a/usb-dual-serial/usb-dual-serial.c
+++ b/usb-dual-serial/usb-dual-serial.c
@@ -2,7 +2,7 @@
* spreadspace avr utils
*
*
- * Copyright (C) 2013-2014 Christian Pointner <equinox@spreadspace.org>
+ * Copyright (C) 2013-2015 Christian Pointner <equinox@spreadspace.org>
*
* This file is part of spreadspace avr utils.
*
@@ -31,7 +31,7 @@
/*
LUFA Library
- Copyright (C) Dean Camera, 2012.
+ Copyright (C) Dean Camera, 2014.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
@@ -50,19 +50,25 @@ USB_ClassInfo_CDC_Device_t VirtualSerial1_CDC_Interface =
{
.Config =
{
- .ControlInterfaceNumber = 0,
-
- .DataINEndpointNumber = CDC1_TX_EPNUM,
- .DataINEndpointSize = CDC_TXRX_EPSIZE,
- .DataINEndpointDoubleBank = false,
-
- .DataOUTEndpointNumber = CDC1_RX_EPNUM,
- .DataOUTEndpointSize = CDC_TXRX_EPSIZE,
- .DataOUTEndpointDoubleBank = false,
-
- .NotificationEndpointNumber = CDC1_NOTIFICATION_EPNUM,
- .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
- .NotificationEndpointDoubleBank = false,
+ .ControlInterfaceNumber = INTERFACE_ID_CDC1_CCI,
+ .DataINEndpoint =
+ {
+ .Address = CDC1_TX_EPADDR,
+ .Size = CDC_TXRX_EPSIZE,
+ .Banks = 1,
+ },
+ .DataOUTEndpoint =
+ {
+ .Address = CDC1_RX_EPADDR,
+ .Size = CDC_TXRX_EPSIZE,
+ .Banks = 1,
+ },
+ .NotificationEndpoint =
+ {
+ .Address = CDC1_NOTIFICATION_EPADDR,
+ .Size = CDC_NOTIFICATION_EPSIZE,
+ .Banks = 1,
+ },
},
};
@@ -70,19 +76,25 @@ USB_ClassInfo_CDC_Device_t VirtualSerial2_CDC_Interface =
{
.Config =
{
- .ControlInterfaceNumber = 2,
-
- .DataINEndpointNumber = CDC2_TX_EPNUM,
- .DataINEndpointSize = CDC_TXRX_EPSIZE,
- .DataINEndpointDoubleBank = false,
-
- .DataOUTEndpointNumber = CDC2_RX_EPNUM,
- .DataOUTEndpointSize = CDC_TXRX_EPSIZE,
- .DataOUTEndpointDoubleBank = false,
-
- .NotificationEndpointNumber = CDC2_NOTIFICATION_EPNUM,
- .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
- .NotificationEndpointDoubleBank = false,
+ .ControlInterfaceNumber = INTERFACE_ID_CDC2_CCI,
+ .DataINEndpoint =
+ {
+ .Address = CDC2_TX_EPADDR,
+ .Size = CDC_TXRX_EPSIZE,
+ .Banks = 1,
+ },
+ .DataOUTEndpoint =
+ {
+ .Address = CDC2_RX_EPADDR,
+ .Size = CDC_TXRX_EPSIZE,
+ .Banks = 1,
+ },
+ .NotificationEndpoint =
+ {
+ .Address = CDC2_NOTIFICATION_EPADDR,
+ .Size = CDC_NOTIFICATION_EPSIZE,
+ .Banks = 1,
+ },
},
};
@@ -131,6 +143,9 @@ void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCI
break;
}
+ /* Keep the TX line held high (idle) while the USART is reconfigured */
+ PORTD |= (1 << 3);
+
/* Must turn off USART before reconfiguring it, otherwise incorrect operation may occur */
UCSR1B = 0;
UCSR1A = 0;
@@ -143,13 +158,16 @@ void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCI
UCSR1C = ConfigMask;
UCSR1A = (1 << U2X1);
UCSR1B = ((1 << RXCIE1) | (1 << TXEN1) | (1 << RXEN1));
+
+ /* Release the TX line after the USART has been reconfigured */
+ PORTD &= ~(1 << 3);
}
ISR(USART1_RX_vect, ISR_BLOCK)
{
uint8_t ReceivedByte = UDR1;
- if (USB_DeviceState == DEVICE_STATE_Configured)
+ if ((USB_DeviceState == DEVICE_STATE_Configured) && !(RingBuffer_IsFull(&USARTtoUSB_Buffer)))
RingBuffer_Insert(&USARTtoUSB_Buffer, ReceivedByte);
}
@@ -157,30 +175,36 @@ void usbserial_init(void)
{
RingBuffer_InitBuffer(&USBtoUSART_Buffer, USBtoUSART_Buffer_Data, sizeof(USBtoUSART_Buffer_Data));
RingBuffer_InitBuffer(&USARTtoUSB_Buffer, USARTtoUSB_Buffer_Data, sizeof(USARTtoUSB_Buffer_Data));
- TCCR0B = (1 << CS02);
}
void usbserial_task(void)
{
- if (!(RingBuffer_IsFull(&USBtoUSART_Buffer))) {
- int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
- if (!(ReceivedByte < 0))
- RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
- }
+ if (!(RingBuffer_IsFull(&USBtoUSART_Buffer))) {
+ int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
+ if (!(ReceivedByte < 0))
+ RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
+ }
- uint16_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
- if ((TIFR0 & (1 << TOV0)) || (BufferCount > (uint8_t)(sizeof(USARTtoUSB_Buffer_Data) * .75))) {
- TIFR0 |= (1 << TOV0);
- while (BufferCount--) {
- if (CDC_Device_SendByte(&VirtualSerial1_CDC_Interface, RingBuffer_Peek(&USARTtoUSB_Buffer)) != ENDPOINT_READYWAIT_NoError)
- break;
+ uint16_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
+ if (BufferCount) {
+ Endpoint_SelectEndpoint(VirtualSerial1_CDC_Interface.Config.DataINEndpoint.Address);
+ if (Endpoint_IsINReady()) {
+ uint8_t BytesToSend = MIN(BufferCount, (CDC_TXRX_EPSIZE - 1));
+ while (BytesToSend--) {
+ if (CDC_Device_SendByte(&VirtualSerial1_CDC_Interface,
+ RingBuffer_Peek(&USARTtoUSB_Buffer)) != ENDPOINT_READYWAIT_NoError) {
+ break;
+ }
RingBuffer_Remove(&USARTtoUSB_Buffer);
}
}
+ }
+
+ if (Serial_IsSendReady() && !(RingBuffer_IsEmpty(&USBtoUSART_Buffer)))
+ Serial_SendByte(RingBuffer_Remove(&USBtoUSART_Buffer));
- if (!(RingBuffer_IsEmpty(&USBtoUSART_Buffer)))
- Serial_SendByte(RingBuffer_Remove(&USBtoUSART_Buffer));
+ CDC_Device_USBTask(&VirtualSerial1_CDC_Interface);
}
/* end LUFA CDC-ACM specific definitions*/
@@ -231,7 +255,6 @@ int main(void)
}
usbserial_task();
- CDC_Device_USBTask(&VirtualSerial1_CDC_Interface);
CDC_Device_USBTask(&VirtualSerial2_CDC_Interface);
USB_USBTask();
}