LUFA Dual virtual serial demo added with some modifications. Also removed useless joypad and led code. Prepared to implement the required functionality.
This commit is contained in:
parent
e610ebe2f4
commit
8cd47bd802
10 changed files with 3669 additions and 0 deletions
126
src/Config/LUFAConfig.h
Normal file
126
src/Config/LUFAConfig.h
Normal file
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2015.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2015 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
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
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
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
* \brief LUFA Library Configuration Header File
|
||||
*
|
||||
* This header file is used to configure LUFA's compile time options,
|
||||
* as an alternative to the compile time constants supplied through
|
||||
* a makefile.
|
||||
*
|
||||
* For information on what each token does, refer to the LUFA
|
||||
* manual section "Summary of Compile Tokens".
|
||||
*/
|
||||
|
||||
#ifndef _LUFA_CONFIG_H_
|
||||
#define _LUFA_CONFIG_H_
|
||||
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
|
||||
/* Non-USB Related Configuration Tokens: */
|
||||
// #define DISABLE_TERMINAL_CODES
|
||||
|
||||
/* USB Class Driver Related Tokens: */
|
||||
// #define HID_HOST_BOOT_PROTOCOL_ONLY
|
||||
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
|
||||
// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
|
||||
// #define HID_MAX_COLLECTIONS {Insert Value Here}
|
||||
// #define HID_MAX_REPORTITEMS {Insert Value Here}
|
||||
// #define HID_MAX_REPORT_IDS {Insert Value Here}
|
||||
// #define NO_CLASS_DRIVER_AUTOFLUSH
|
||||
|
||||
/* General USB Driver Related Tokens: */
|
||||
// #define ORDERED_EP_CONFIG
|
||||
#define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
|
||||
#define USB_DEVICE_ONLY
|
||||
// #define USB_HOST_ONLY
|
||||
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
|
||||
// #define NO_LIMITED_CONTROLLER_CONNECT
|
||||
// #define NO_SOF_EVENTS
|
||||
|
||||
/* USB Device Mode Driver Related Tokens: */
|
||||
// #define USE_RAM_DESCRIPTORS
|
||||
#define USE_FLASH_DESCRIPTORS
|
||||
// #define USE_EEPROM_DESCRIPTORS
|
||||
// #define NO_INTERNAL_SERIAL
|
||||
#define FIXED_CONTROL_ENDPOINT_SIZE 8
|
||||
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
|
||||
#define FIXED_NUM_CONFIGURATIONS 1
|
||||
// #define CONTROL_ONLY_DEVICE
|
||||
#define INTERRUPT_CONTROL_ENDPOINT
|
||||
// #define NO_DEVICE_REMOTE_WAKEUP
|
||||
// #define NO_DEVICE_SELF_POWER
|
||||
|
||||
/* USB Host Mode Driver Related Tokens: */
|
||||
// #define HOST_STATE_AS_GPIOR {Insert Value Here}
|
||||
// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
|
||||
// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
|
||||
// #define NO_AUTO_VBUS_MANAGEMENT
|
||||
// #define INVERTED_VBUS_ENABLE_LINE
|
||||
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
|
||||
/* Non-USB Related Configuration Tokens: */
|
||||
// #define DISABLE_TERMINAL_CODES
|
||||
|
||||
/* USB Class Driver Related Tokens: */
|
||||
// #define HID_HOST_BOOT_PROTOCOL_ONLY
|
||||
// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
|
||||
// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
|
||||
// #define HID_MAX_COLLECTIONS {Insert Value Here}
|
||||
// #define HID_MAX_REPORTITEMS {Insert Value Here}
|
||||
// #define HID_MAX_REPORT_IDS {Insert Value Here}
|
||||
// #define NO_CLASS_DRIVER_AUTOFLUSH
|
||||
|
||||
/* General USB Driver Related Tokens: */
|
||||
#define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_RC32MCLKSRC | USB_OPT_BUSEVENT_PRIHIGH)
|
||||
// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
|
||||
// #define NO_LIMITED_CONTROLLER_CONNECT
|
||||
// #define NO_SOF_EVENTS
|
||||
|
||||
/* USB Device Mode Driver Related Tokens: */
|
||||
// #define USE_RAM_DESCRIPTORS
|
||||
#define USE_FLASH_DESCRIPTORS
|
||||
// #define USE_EEPROM_DESCRIPTORS
|
||||
// #define NO_INTERNAL_SERIAL
|
||||
#define FIXED_CONTROL_ENDPOINT_SIZE 8
|
||||
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
|
||||
#define FIXED_NUM_CONFIGURATIONS 1
|
||||
// #define CONTROL_ONLY_DEVICE
|
||||
#define MAX_ENDPOINT_INDEX 6
|
||||
// #define NO_DEVICE_REMOTE_WAKEUP
|
||||
// #define NO_DEVICE_SELF_POWER
|
||||
|
||||
#else
|
||||
|
||||
#error Unsupported architecture for this LUFA configuration file.
|
||||
|
||||
#endif
|
||||
#endif
|
360
src/Descriptors.c
Normal file
360
src/Descriptors.c
Normal file
|
@ -0,0 +1,360 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2015.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2015 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
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
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
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
|
||||
* computer-readable structures which the host requests upon device enumeration, to determine
|
||||
* the device's capabilities and functions.
|
||||
*/
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
|
||||
/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
|
||||
* device characteristics, including the supported USB version, control endpoint size and the
|
||||
* number of device configurations. The descriptor is read out by the USB host when the enumeration
|
||||
* process begins.
|
||||
*/
|
||||
const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
|
||||
|
||||
.USBSpecification = VERSION_BCD(1,1,0),
|
||||
.Class = USB_CSCP_IADDeviceClass,
|
||||
.SubClass = USB_CSCP_IADDeviceSubclass,
|
||||
.Protocol = USB_CSCP_IADDeviceProtocol,
|
||||
|
||||
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
|
||||
|
||||
.VendorID = 0x03EB,
|
||||
.ProductID = 0x204E,
|
||||
.ReleaseNumber = VERSION_BCD(0,0,1),
|
||||
|
||||
.ManufacturerStrIndex = STRING_ID_Manufacturer,
|
||||
.ProductStrIndex = STRING_ID_Product,
|
||||
.SerialNumStrIndex = USE_INTERNAL_SERIAL,
|
||||
|
||||
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
|
||||
};
|
||||
|
||||
/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
|
||||
* of the device in one of its supported configurations, including information about any device interfaces
|
||||
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
|
||||
* a configuration so that the host may correctly communicate with the USB device.
|
||||
*/
|
||||
const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
|
||||
|
||||
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
|
||||
.TotalInterfaces = 4,
|
||||
|
||||
.ConfigurationNumber = 1,
|
||||
.ConfigurationStrIndex = NO_DESCRIPTOR,
|
||||
|
||||
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
|
||||
|
||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
||||
},
|
||||
|
||||
.CDC1_IAD =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_Association_t), .Type = DTYPE_InterfaceAssociation},
|
||||
|
||||
.FirstInterfaceIndex = INTERFACE_ID_CDC1_CCI,
|
||||
.TotalInterfaces = 2,
|
||||
|
||||
.Class = CDC_CSCP_CDCClass,
|
||||
.SubClass = CDC_CSCP_ACMSubclass,
|
||||
.Protocol = CDC_CSCP_ATCommandProtocol,
|
||||
|
||||
.IADStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC1_CCI_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = INTERFACE_ID_CDC1_CCI,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 1,
|
||||
|
||||
.Class = CDC_CSCP_CDCClass,
|
||||
.SubClass = CDC_CSCP_ACMSubclass,
|
||||
.Protocol = CDC_CSCP_ATCommandProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC1_Functional_Header =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Header,
|
||||
|
||||
.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,
|
||||
|
||||
.Capabilities = 0x06,
|
||||
},
|
||||
|
||||
.CDC1_Functional_Union =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Union,
|
||||
|
||||
.MasterInterfaceNumber = INTERFACE_ID_CDC1_CCI,
|
||||
.SlaveInterfaceNumber = INTERFACE_ID_CDC1_DCI,
|
||||
},
|
||||
|
||||
.CDC1_ManagementEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.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},
|
||||
|
||||
.InterfaceNumber = INTERFACE_ID_CDC1_DCI,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 2,
|
||||
|
||||
.Class = CDC_CSCP_CDCDataClass,
|
||||
.SubClass = CDC_CSCP_NoDataSubclass,
|
||||
.Protocol = CDC_CSCP_NoDataProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC1_DataOutEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.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},
|
||||
|
||||
.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},
|
||||
|
||||
.FirstInterfaceIndex = INTERFACE_ID_CDC2_CCI,
|
||||
.TotalInterfaces = 2,
|
||||
|
||||
.Class = CDC_CSCP_CDCClass,
|
||||
.SubClass = CDC_CSCP_ACMSubclass,
|
||||
.Protocol = CDC_CSCP_ATCommandProtocol,
|
||||
|
||||
.IADStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC2_CCI_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
|
||||
.InterfaceNumber = INTERFACE_ID_CDC2_CCI,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 1,
|
||||
|
||||
.Class = CDC_CSCP_CDCClass,
|
||||
.SubClass = CDC_CSCP_ACMSubclass,
|
||||
.Protocol = CDC_CSCP_ATCommandProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
|
||||
.CDC2_Functional_Header =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Header,
|
||||
|
||||
.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,
|
||||
|
||||
.Capabilities = 0x06,
|
||||
},
|
||||
|
||||
.CDC2_Functional_Union =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Union,
|
||||
|
||||
.MasterInterfaceNumber = INTERFACE_ID_CDC2_CCI,
|
||||
.SlaveInterfaceNumber = INTERFACE_ID_CDC2_DCI,
|
||||
},
|
||||
|
||||
.CDC2_ManagementEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
|
||||
.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},
|
||||
|
||||
.InterfaceNumber = INTERFACE_ID_CDC2_DCI,
|
||||
.AlternateSetting = 0,
|
||||
|
||||
.TotalEndpoints = 2,
|
||||
|
||||
.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 = 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},
|
||||
|
||||
.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 = 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 = USB_STRING_DESCRIPTOR(L"Dean Camera");
|
||||
|
||||
/** 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 = USB_STRING_DESCRIPTOR(L"LUFA CDC USB2SerialMux");
|
||||
|
||||
/** 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
|
||||
* to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
|
||||
* is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
|
||||
* USB host.
|
||||
*/
|
||||
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 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;
|
||||
}
|
||||
|
135
src/Descriptors.h
Normal file
135
src/Descriptors.h
Normal file
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2015.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2015 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
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
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
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for Descriptors.c.
|
||||
*/
|
||||
|
||||
#ifndef _DESCRIPTORS_H_
|
||||
#define _DESCRIPTORS_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
|
||||
#include <avr/pgmspace.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
|
||||
|
66
src/LUFA_USB2SerialMux.inf
Normal file
66
src/LUFA_USB2SerialMux.inf
Normal file
|
@ -0,0 +1,66 @@
|
|||
;************************************************************
|
||||
; Windows USB CDC ACM Setup File
|
||||
; Copyright (c) 2000 Microsoft Corporation
|
||||
;************************************************************
|
||||
|
||||
[DefaultInstall]
|
||||
CopyINF="LUFA_USB2SerialMux.inf"
|
||||
|
||||
[Version]
|
||||
Signature="$Windows NT$"
|
||||
Class=Ports
|
||||
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
|
||||
Provider=%MFGNAME%
|
||||
DriverVer=7/1/2012,10.0.0.0
|
||||
|
||||
[Manufacturer]
|
||||
%MFGNAME%=DeviceList, NTx86, NTamd64, NTia64
|
||||
|
||||
[SourceDisksNames]
|
||||
|
||||
[SourceDisksFiles]
|
||||
|
||||
[DestinationDirs]
|
||||
DefaultDestDir=12
|
||||
|
||||
[DriverInstall]
|
||||
Include=mdmcpq.inf
|
||||
CopyFiles=FakeModemCopyFileSection
|
||||
AddReg=DriverInstall.AddReg
|
||||
|
||||
[DriverInstall.Services]
|
||||
Include=mdmcpq.inf
|
||||
AddService=usbser, 0x00000002, LowerFilter_Service_Inst
|
||||
|
||||
[DriverInstall.AddReg]
|
||||
HKR,,EnumPropPages32,,"msports.dll,SerialPortPropPageProvider"
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Vendor and Product ID Definitions
|
||||
;------------------------------------------------------------------------------
|
||||
; When developing your USB device, the VID and PID used in the PC side
|
||||
; application program and the firmware on the microcontroller must match.
|
||||
; Modify the below line to use your VID and PID. Use the format as shown below.
|
||||
; Note: One INF file can be used for multiple devices with different VID and PIDs.
|
||||
; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line.
|
||||
;------------------------------------------------------------------------------
|
||||
[DeviceList]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02
|
||||
|
||||
[DeviceList.NTx86]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02
|
||||
|
||||
[DeviceList.NTamd64]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02
|
||||
|
||||
[DeviceList.NTia64]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; String Definitions
|
||||
;------------------------------------------------------------------------------
|
||||
;Modify these strings to customize your device
|
||||
;------------------------------------------------------------------------------
|
||||
[Strings]
|
||||
MFGNAME="http://www.lufa-lib.org"
|
||||
DESCRIPTION="LUFA CDC-ACM Virtual Serial Port"
|
320
src/USB2SerialMux.c
Normal file
320
src/USB2SerialMux.c
Normal file
|
@ -0,0 +1,320 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2015.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2015 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
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
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
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Main source file for the iUSB2SerialMux demo. This file contains the main tasks of the demo and
|
||||
* is responsible for the initial application hardware configuration.
|
||||
*/
|
||||
|
||||
#include "USB2SerialMux.h"
|
||||
|
||||
/** Contains the current baud rate and other settings of the first virtual serial port. While this demo does not use
|
||||
* the physical USART and thus does not use these settings, they must still be retained and returned to the host
|
||||
* upon request or the host will assume the device is non-functional.
|
||||
*
|
||||
* These values are set by the host via a class-specific request, however they are not required to be used accurately.
|
||||
* It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
|
||||
* serial link characteristics and instead sends and receives data in endpoint streams.
|
||||
*/
|
||||
static CDC_LineEncoding_t LineEncoding1 = { .BaudRateBPS = 0,
|
||||
.CharFormat = CDC_LINEENCODING_OneStopBit,
|
||||
.ParityType = CDC_PARITY_None,
|
||||
.DataBits = 8 };
|
||||
|
||||
/** Contains the current baud rate and other settings of the second virtual serial port. While this demo does not use
|
||||
* the physical USART and thus does not use these settings, they must still be retained and returned to the host
|
||||
* upon request or the host will assume the device is non-functional.
|
||||
*
|
||||
* These values are set by the host via a class-specific request, however they are not required to be used accurately.
|
||||
* It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
|
||||
* serial link characteristics and instead sends and receives data in endpoint streams.
|
||||
*/
|
||||
static CDC_LineEncoding_t LineEncoding2 = { .BaudRateBPS = 0,
|
||||
.CharFormat = CDC_LINEENCODING_OneStopBit,
|
||||
.ParityType = CDC_PARITY_None,
|
||||
.DataBits = 8 };
|
||||
|
||||
|
||||
/** Main program entry point. This routine configures the hardware required by the application, then
|
||||
* enters a loop to run the application tasks in sequence.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
SetupHardware();
|
||||
|
||||
SET_ERR_MASK(ERRMASK_USB_NOTREADY);
|
||||
GlobalInterruptEnable();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
CDC1_Task();
|
||||
CDC2_Task();
|
||||
USB_USBTask();
|
||||
}
|
||||
}
|
||||
|
||||
/** Configures the board hardware and chip peripherals for the demo's functionality. */
|
||||
void SetupHardware(void)
|
||||
{
|
||||
#if (ARCH == ARCH_AVR8)
|
||||
/* Disable watchdog if enabled by bootloader/fuses */
|
||||
MCUSR &= ~(1 << WDRF);
|
||||
wdt_disable();
|
||||
|
||||
/* Disable clock division */
|
||||
clock_prescale_set(clock_div_1);
|
||||
|
||||
#elif (ARCH == ARCH_XMEGA)
|
||||
/* Start the PLL to multiply the 2MHz RC oscillator to 32MHz and switch the CPU core to run from it */
|
||||
XMEGACLK_StartPLL(CLOCK_SRC_INT_RC2MHZ, 2000000, F_CPU);
|
||||
XMEGACLK_SetCPUClockSource(CLOCK_SRC_PLL);
|
||||
|
||||
/* Start the 32MHz internal RC oscillator and start the DFLL to increase it to 48MHz using the USB SOF as a reference */
|
||||
XMEGACLK_StartInternalOscillator(CLOCK_SRC_INT_RC32MHZ);
|
||||
XMEGACLK_StartDFLL(CLOCK_SRC_INT_RC32MHZ, DFLL_REF_INT_USBSOF, F_USB);
|
||||
|
||||
PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
|
||||
#endif
|
||||
|
||||
/* Hardware Initialization */
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and
|
||||
* starts the library USB task to begin the enumeration and USB management process.
|
||||
*/
|
||||
void EVENT_USB_Device_Connect(void)
|
||||
{
|
||||
/* Indicate USB enumerating */
|
||||
SET_ERR_MASK(ERRMASK_USB_ENUMERATING);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via
|
||||
* the status LEDs and stops the USB management and CDC management tasks.
|
||||
*/
|
||||
void EVENT_USB_Device_Disconnect(void)
|
||||
{
|
||||
/* Indicate USB not ready */
|
||||
SET_ERR_MASK(ERRMASK_USB_NOTREADY);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration
|
||||
* of the USB device after enumeration - the device endpoints are configured and the CDC management tasks are started.
|
||||
*/
|
||||
void EVENT_USB_Device_ConfigurationChanged(void)
|
||||
{
|
||||
bool ConfigSuccess = true;
|
||||
|
||||
/* Setup first CDC Interface's Endpoints */
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_TX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_RX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1);
|
||||
|
||||
/* Setup second CDC Interface's Endpoints */
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_TX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_RX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
|
||||
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1);
|
||||
|
||||
/* Reset line encoding baud rates so that the host knows to send new values */
|
||||
LineEncoding1.BaudRateBPS = 0;
|
||||
LineEncoding2.BaudRateBPS = 0;
|
||||
|
||||
/* Indicate endpoint configuration success or failure */
|
||||
SET_ERR_MASK(ConfigSuccess ? ERRMASK_USB_READY : ERRMASK_USB_ERROR);
|
||||
}
|
||||
|
||||
/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
|
||||
* the device from the USB host before passing along unhandled control requests to the library for processing
|
||||
* internally.
|
||||
*/
|
||||
void EVENT_USB_Device_ControlRequest(void)
|
||||
{
|
||||
/* Determine which interface's Line Coding data is being set from the wIndex parameter */
|
||||
void* LineEncodingData = (USB_ControlRequest.wIndex == 0) ? &LineEncoding1 : &LineEncoding2;
|
||||
|
||||
/* Process CDC specific control requests */
|
||||
switch (USB_ControlRequest.bRequest)
|
||||
{
|
||||
case CDC_REQ_GetLineEncoding:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the line coding data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(LineEncodingData, sizeof(CDC_LineEncoding_t));
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
break;
|
||||
case CDC_REQ_SetLineEncoding:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Read the line coding data in from the host into the global struct */
|
||||
Endpoint_Read_Control_Stream_LE(LineEncodingData, sizeof(CDC_LineEncoding_t));
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
|
||||
break;
|
||||
case CDC_REQ_SetControlLineState:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Function to manage CDC data transmission and reception to and from the host for the first CDC interface,
|
||||
* which sends answers or response data to the host.
|
||||
*/
|
||||
void CDC1_Task(void)
|
||||
{
|
||||
char* ReportString = NULL;
|
||||
static bool ActionSent = false;
|
||||
|
||||
/* Device must be connected and configured for the task to run */
|
||||
if (USB_DeviceState != DEVICE_STATE_Configured)
|
||||
return;
|
||||
|
||||
//===========================================================================
|
||||
/* Select the Serial Rx Endpoint */
|
||||
Endpoint_SelectEndpoint(CDC1_RX_EPADDR);
|
||||
|
||||
if (Endpoint_IsOUTReceived())
|
||||
{
|
||||
// TODO disable this line if data should be received
|
||||
Endpoint_ClearOUT(); // Throw away any received data from the host at this point
|
||||
|
||||
// TODO Read the data from the host
|
||||
|
||||
/* Create a temp buffer big enough to hold the incoming endpoint packet */
|
||||
uint8_t Buffer[Endpoint_BytesInEndpoint()];
|
||||
|
||||
/* Remember how large the incoming packet is */
|
||||
uint16_t DataLength = Endpoint_BytesInEndpoint();
|
||||
|
||||
/* Read in the incoming packet into the buffer */
|
||||
Endpoint_Read_Stream_LE(&Buffer, DataLength, NULL);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
// TODO process the received data and descide to do an action
|
||||
// uint8_t cmd = processReceivedControlData(&Buffer, DataLength);
|
||||
// if (cmd != NULL)
|
||||
// {
|
||||
// call(cmd)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
/* Determine if data/answeres should be sent to the host
|
||||
* the previous RX section should be clarify that behaviour.
|
||||
*/
|
||||
|
||||
/* Flag management - Only allow one string to be sent per action */
|
||||
if ((ReportString != NULL) && (ActionSent == false) && LineEncoding1.BaudRateBPS)
|
||||
{
|
||||
ActionSent = true;
|
||||
|
||||
/* Select the Serial Tx Endpoint */
|
||||
Endpoint_SelectEndpoint(CDC1_TX_EPADDR);
|
||||
|
||||
/* Write the String to the Endpoint */
|
||||
Endpoint_Write_Stream_LE(ReportString, strlen(ReportString), NULL);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Wait until the endpoint is ready for another packet */
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
/* Send an empty packet to ensure that the host does not buffer data sent to it */
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Function to manage CDC data transmission and reception to and from the host for the second CDC interface,
|
||||
* which sends all data received from a node (mux) during USART to the host.
|
||||
*/
|
||||
void CDC2_Task(void)
|
||||
{
|
||||
/* Device must be connected and configured for the task to run */
|
||||
if (USB_DeviceState != DEVICE_STATE_Configured)
|
||||
return;
|
||||
|
||||
//===========================================================================
|
||||
/* Select the Serial Rx Endpoint */
|
||||
Endpoint_SelectEndpoint(CDC2_RX_EPADDR);
|
||||
|
||||
/* Check to see if any data has been received */
|
||||
if (Endpoint_IsOUTReceived())
|
||||
{
|
||||
/* Create a temp buffer big enough to hold the incoming endpoint packet */
|
||||
uint8_t Buffer[Endpoint_BytesInEndpoint()];
|
||||
|
||||
/* Remember how large the incoming packet is */
|
||||
uint16_t DataLength = Endpoint_BytesInEndpoint();
|
||||
|
||||
/* Read in the incoming packet into the buffer */
|
||||
Endpoint_Read_Stream_LE(&Buffer, DataLength, NULL);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
// TODO at this point send the data to the USART
|
||||
// Send USART &Buffer
|
||||
|
||||
// TODO read the USART data and send them to the host
|
||||
// Fill &Buffer with USART data or send the USART input buffer direct
|
||||
|
||||
/* Select the Serial Tx Endpoint */
|
||||
Endpoint_SelectEndpoint(CDC2_TX_EPADDR);
|
||||
|
||||
/* Write the received data to the endpoint */
|
||||
Endpoint_Write_Stream_LE(&Buffer, DataLength, NULL);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Wait until the endpoint is ready for the next packet */
|
||||
Endpoint_WaitUntilReady();
|
||||
|
||||
/* Send an empty packet to prevent host buffering */
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
}
|
80
src/USB2SerialMux.h
Normal file
80
src/USB2SerialMux.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
LUFA Library
|
||||
Copyright (C) Dean Camera, 2015.
|
||||
|
||||
dean [at] fourwalledcubicle [dot] com
|
||||
www.lufa-lib.org
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright 2015 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
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that the copyright notice and this
|
||||
permission notice and warranty disclaimer appear in supporting
|
||||
documentation, and that the name of the author not be used in
|
||||
advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
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
|
||||
whatsoever resulting from loss of use, data or profits, whether
|
||||
in an action of contract, negligence or other tortious action,
|
||||
arising out of or in connection with the use or performance of
|
||||
this software.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
*
|
||||
* Header file for USB2SerialMux.c.
|
||||
*/
|
||||
|
||||
#ifndef _DUAL_VIRTUALSERIAL_H_
|
||||
#define _DUAL_VIRTUALSERIAL_H_
|
||||
|
||||
/* Includes: */
|
||||
#include <avr/io.h>
|
||||
#include <avr/wdt.h>
|
||||
#include <avr/power.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Descriptors.h"
|
||||
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include <LUFA/Platform/Platform.h>
|
||||
|
||||
uint8_t error_mask = 0x00;
|
||||
|
||||
/* Macros: */
|
||||
|
||||
#define SET_ERR_MASK(m) error_mask = m
|
||||
|
||||
/** Error mask, to indicate that the USB interface is not ready. */
|
||||
#define ERRMASK_USB_NOTREADY (1 << 0)
|
||||
|
||||
/** Error mask, to indicate that the USB interface is enumerating. */
|
||||
#define ERRMASK_USB_ENUMERATING ((1 << 1) | (1 << 2))
|
||||
|
||||
/** Error mask, to indicate that the USB interface is ready. */
|
||||
#define ERRMASK_USB_READY ((1 << 1) | (1 << 3))
|
||||
|
||||
/** Error mask, to indicate that an error has occurred in the USB interface. */
|
||||
#define ERRMASK_USB_ERROR ((1 << 0) | (1 << 2))
|
||||
|
||||
/* Function Prototypes: */
|
||||
void CDC1_Task(void);
|
||||
void CDC2_Task(void);
|
||||
void SetupHardware(void);
|
||||
|
||||
void EVENT_USB_Device_Connect(void);
|
||||
void EVENT_USB_Device_Disconnect(void);
|
||||
void EVENT_USB_Device_ConfigurationChanged(void);
|
||||
void EVENT_USB_Device_ControlRequest(void);
|
||||
|
||||
#endif
|
||||
|
89
src/USB2SerialMux.txt
Normal file
89
src/USB2SerialMux.txt
Normal file
|
@ -0,0 +1,89 @@
|
|||
/** \file
|
||||
*
|
||||
* This file contains special DoxyGen information for the generation of the main page and other special
|
||||
* documentation pages. It is not a project source file.
|
||||
*/
|
||||
|
||||
/** \mainpage Dual Communications Device Class (Dual Virtual Serial Port) Device
|
||||
*
|
||||
* \section Sec_Compat Demo Compatibility:
|
||||
*
|
||||
* The following list indicates what microcontrollers are compatible with this demo.
|
||||
*
|
||||
* \li Series 7 USB AVRs (AT90USBxxx7)
|
||||
* \li Series 6 USB AVRs (AT90USBxxx6)
|
||||
* \li Series 4 USB AVRs (ATMEGAxxU4)
|
||||
* \li Series AU XMEGA AVRs (ATXMEGAxxxAxU)
|
||||
* \li Series B XMEGA AVRs (ATXMEGAxxxBx)
|
||||
* \li Series C XMEGA AVRs (ATXMEGAxxxCx)
|
||||
*
|
||||
* \section Sec_Info USB Information:
|
||||
*
|
||||
* The following table gives a rundown of the USB utilization of this demo.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td><b>USB Mode:</b></td>
|
||||
* <td>Device</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>USB Class:</b></td>
|
||||
* <td>Communications Device Class (CDC)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>USB Subclass:</b></td>
|
||||
* <td>Abstract Control Model (ACM)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Relevant Standards:</b></td>
|
||||
* <td>USBIF CDC Class Standard</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Relevant Standards:</b></td>
|
||||
* <td>USBIF Interface Association Descriptor ECN \n
|
||||
* USBIF CDC Class Standard</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td><b>Supported USB Speeds:</b></td>
|
||||
* <td>Full Speed Mode</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* \section Sec_Description Project Description:
|
||||
*
|
||||
* Dual Communications Device Class demonstration application.
|
||||
* This gives a simple reference application for implementing
|
||||
* a compound device with dual CDC functions acting as a pair
|
||||
* of virtual serial ports. This demo uses Interface Association
|
||||
* Descriptors to link together the pair of related CDC
|
||||
* descriptors for each virtual serial port, which may not be
|
||||
* supported in all OSes - Windows Vista is supported, as is
|
||||
* XP (although the latter may need a hotfix to function).
|
||||
*
|
||||
* Joystick actions are transmitted to the host as strings
|
||||
* through the first serial port. The device does not respond to
|
||||
* serial data sent from the host in the first serial port.
|
||||
*
|
||||
* The second serial port echoes back data sent from the host.
|
||||
*
|
||||
* After running this demo for the first time on a new computer,
|
||||
* you will need to supply the .INF file located in this demo
|
||||
* project's directory as the device's driver when running under
|
||||
* Windows. This will enable Windows to use its inbuilt CDC drivers,
|
||||
* negating the need for custom drivers for the device. Other
|
||||
* Operating Systems should automatically use their own inbuilt
|
||||
* CDC-ACM drivers.
|
||||
*
|
||||
* \section Sec_Options Project Options
|
||||
*
|
||||
* The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.
|
||||
*
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>
|
||||
* None
|
||||
* </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
|
60
src/asf.xml
Normal file
60
src/asf.xml
Normal file
|
@ -0,0 +1,60 @@
|
|||
<asf xmlversion="1.0">
|
||||
<project caption="Dual Virtual Serial Device Demo (Low Level APIs)" id="lufa.demos.device.lowlevel.dual_cdc.example.avr8">
|
||||
<require idref="lufa.demos.device.lowlevel.dual_cdc"/>
|
||||
<require idref="lufa.boards.dummy.avr8"/>
|
||||
<generator value="as5_8"/>
|
||||
|
||||
<device-support value="at90usb1287"/>
|
||||
<config name="lufa.drivers.board.name" value="none"/>
|
||||
|
||||
<build type="define" name="F_CPU" value="16000000UL"/>
|
||||
<build type="define" name="F_USB" value="16000000UL"/>
|
||||
</project>
|
||||
|
||||
<project caption="Dual Virtual Serial Device Demo (Low Level APIs)" id="lufa.demos.device.lowlevel.dual_cdc.example.xmega">
|
||||
<require idref="lufa.demos.device.lowlevel.dual_cdc"/>
|
||||
<require idref="lufa.boards.dummy.xmega"/>
|
||||
<generator value="as5_8"/>
|
||||
|
||||
<device-support value="atxmega128a1u"/>
|
||||
<config name="lufa.drivers.board.name" value="none"/>
|
||||
|
||||
<build type="define" name="F_CPU" value="32000000UL"/>
|
||||
<build type="define" name="F_USB" value="48000000UL"/>
|
||||
</project>
|
||||
|
||||
<module type="application" id="lufa.demos.device.lowlevel.dual_cdc" caption="Dual Virtual Serial Device Demo (Low Level APIs)">
|
||||
<info type="description" value="summary">
|
||||
Dual Virtual Serial (CDC) demo, implementing a pair of virtual serial port interfaces. This demo uses the Low Level LUFA APIs to manually implement a USB Class for demonstration purposes without using the simpler in-built LUFA Class Driver APIs.
|
||||
</info>
|
||||
|
||||
<info type="gui-flag" value="move-to-root"/>
|
||||
|
||||
<info type="keyword" value="Technology">
|
||||
<keyword value="Low Level APIs"/>
|
||||
<keyword value="USB Device"/>
|
||||
<keyword value="CDC Class"/>
|
||||
</info>
|
||||
|
||||
<device-support-alias value="lufa_avr8"/>
|
||||
<device-support-alias value="lufa_xmega"/>
|
||||
<device-support-alias value="lufa_uc3"/>
|
||||
|
||||
<build type="distribute" subtype="user-file" value="doxyfile"/>
|
||||
<build type="distribute" subtype="user-file" value="USB2SerialMux.txt"/>
|
||||
<build type="distribute" subtype="user-file" value="LUFA_USB2SerialMux.inf"/>
|
||||
|
||||
<build type="c-source" value="USB2SerialMux.c"/>
|
||||
<build type="c-source" value="Descriptors.c"/>
|
||||
<build type="header-file" value="USB2SerialMux.h"/>
|
||||
<build type="header-file" value="Descriptors.h"/>
|
||||
|
||||
<build type="module-config" subtype="path" value="Config"/>
|
||||
<build type="header-file" value="Config/LUFAConfig.h"/>
|
||||
|
||||
<require idref="lufa.common"/>
|
||||
<require idref="lufa.platform"/>
|
||||
<require idref="lufa.drivers.usb"/>
|
||||
<require idref="lufa.drivers.board"/>
|
||||
</module>
|
||||
</asf>
|
2395
src/doxyfile
Normal file
2395
src/doxyfile
Normal file
File diff suppressed because it is too large
Load diff
38
src/makefile
Normal file
38
src/makefile
Normal file
|
@ -0,0 +1,38 @@
|
|||
#
|
||||
# LUFA Library
|
||||
# Copyright (C) Dean Camera, 2015.
|
||||
#
|
||||
# dean [at] fourwalledcubicle [dot] com
|
||||
# www.lufa-lib.org
|
||||
#
|
||||
# --------------------------------------
|
||||
# LUFA Project Makefile.
|
||||
# --------------------------------------
|
||||
|
||||
# Run "make help" for target help.
|
||||
|
||||
MCU = atmega32u4
|
||||
ARCH = AVR8
|
||||
BOARD = USBKEY
|
||||
F_CPU = 16000000UL
|
||||
F_USB = $(F_CPU)
|
||||
OPTIMIZATION = s
|
||||
TARGET = USB2SerialMux
|
||||
SRC = $(TARGET).c Descriptors.c $(LUFA_SRC_USB)
|
||||
LUFA_PATH = ../LUFA
|
||||
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/
|
||||
LD_FLAGS =
|
||||
|
||||
# Default target
|
||||
all:
|
||||
|
||||
# Include LUFA build script makefiles
|
||||
include $(LUFA_PATH)/Build/lufa_core.mk
|
||||
include $(LUFA_PATH)/Build/lufa_sources.mk
|
||||
include $(LUFA_PATH)/Build/lufa_build.mk
|
||||
include $(LUFA_PATH)/Build/lufa_cppcheck.mk
|
||||
include $(LUFA_PATH)/Build/lufa_doxygen.mk
|
||||
include $(LUFA_PATH)/Build/lufa_dfu.mk
|
||||
include $(LUFA_PATH)/Build/lufa_hid.mk
|
||||
include $(LUFA_PATH)/Build/lufa_avrdude.mk
|
||||
include $(LUFA_PATH)/Build/lufa_atprogram.mk
|
Loading…
Reference in a new issue