From 23cee4f9ac0e293f6e32c0215879aedb4c151718 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 10 Apr 2009 01:16:16 +0200 Subject: * digital/avr/modules/usb: - added usb module. --- digital/avr/modules/usb/test/descriptors.c | 184 +++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 digital/avr/modules/usb/test/descriptors.c (limited to 'digital/avr/modules/usb/test/descriptors.c') diff --git a/digital/avr/modules/usb/test/descriptors.c b/digital/avr/modules/usb/test/descriptors.c new file mode 100644 index 00000000..4ccc7b49 --- /dev/null +++ b/digital/avr/modules/usb/test/descriptors.c @@ -0,0 +1,184 @@ +/* descriptors.c */ +/* usb - USB device module using LUFA. {{{ + * + * Copyright (C) 2009 Nicolas Schodet + * + * APBTeam: + * Web: http://apbteam.org/ + * Email: team AT apbteam DOT org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * }}} */ +#include "descriptors.h" + +USB_Descriptor_Device_t PROGMEM DeviceDescriptor = +{ + Header: { Size: sizeof (USB_Descriptor_Device_t), Type: DTYPE_Device }, + USBSpecification: VERSION_BCD (01.10), + Class: 0xFF, + SubClass: 0x00, + Protocol: 0x00, + Endpoint0Size: 8, + /* Taken from LUFA IDs. */ + VendorID: 0x03EB, + ProductID: 0x204E, + ReleaseNumber: 0x0000, + ManufacturerStrIndex: 0x01, + ProductStrIndex: 0x02, + SerialNumStrIndex: NO_DESCRIPTOR, + NumberOfConfigurations: 1 +}; + +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: 2, + ConfigurationNumber: 1, + ConfigurationStrIndex: NO_DESCRIPTOR, + ConfigAttributes: (USB_CONFIG_ATTR_BUSPOWERED | + USB_CONFIG_ATTR_SELFPOWERED), + MaxPowerConsumption: USB_CONFIG_POWER_MA (100) + }, + + TS1_Interface: + { + Header: { Size: sizeof (USB_Descriptor_Interface_t), + Type: DTYPE_Interface }, + InterfaceNumber: 0, + AlternateSetting: 0, + TotalEndpoints: 2, + Class: 0xFF, + SubClass: 0x00, + Protocol: 0x00, + InterfaceStrIndex: NO_DESCRIPTOR + }, + + TS1_DataOutEndpoint: + { + Header: { Size: sizeof (USB_Descriptor_Endpoint_t), + Type: DTYPE_Endpoint }, + EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_OUT | TS1_RX_EPNUM), + Attributes: EP_TYPE_BULK, + EndpointSize: TS_TXRX_EPSIZE, + PollingIntervalMS: 0x00 + }, + + TS1_DataInEndpoint: + { + Header: { Size: sizeof (USB_Descriptor_Endpoint_t), + Type: DTYPE_Endpoint }, + EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_IN | TS1_TX_EPNUM), + Attributes: EP_TYPE_BULK, + EndpointSize: TS_TXRX_EPSIZE, + PollingIntervalMS: 0x00 + }, + + TS2_Interface: + { + Header: { Size: sizeof (USB_Descriptor_Interface_t), + Type: DTYPE_Interface }, + InterfaceNumber: 1, + AlternateSetting: 0, + TotalEndpoints: 2, + Class: 0xFF, + SubClass: 0x00, + Protocol: 0x00, + InterfaceStrIndex: NO_DESCRIPTOR + }, + + TS2_DataOutEndpoint: + { + Header: { Size: sizeof (USB_Descriptor_Endpoint_t), + Type: DTYPE_Endpoint }, + EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_OUT | TS2_RX_EPNUM), + Attributes: EP_TYPE_BULK, + EndpointSize: TS_TXRX_EPSIZE, + PollingIntervalMS: 0x00 + }, + + TS2_DataInEndpoint: + { + Header: { Size: sizeof (USB_Descriptor_Endpoint_t), + Type: DTYPE_Endpoint }, + EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_IN | TS2_TX_EPNUM), + Attributes: EP_TYPE_BULK, + EndpointSize: TS_TXRX_EPSIZE, + PollingIntervalMS: 0x00 + } +}; + +USB_Descriptor_String_t PROGMEM LanguageString = +{ + Header: { Size: USB_STRING_LEN (1), Type: DTYPE_String }, + UnicodeString: {LANGUAGE_ID_ENG} +}; + +USB_Descriptor_String_t PROGMEM ManufacturerString = +{ + Header: { Size: USB_STRING_LEN (7), Type: DTYPE_String }, + UnicodeString: L"APBTeam" +}; + +USB_Descriptor_String_t PROGMEM ProductString = +{ + Header: { Size: USB_STRING_LEN (16), Type: DTYPE_String }, + UnicodeString: L"Dual Serial Echo" +}; + +uint16_t +USB_GetDescriptor (const uint16_t wValue, const uint8_t wIndex, + void** const DescriptorAddress) +{ + const uint8_t DescriptorType = wValue >> 8; + const uint8_t DescriptorNumber = wValue & 0xFF; + void * Address = NULL; + uint16_t Size = NO_DESCRIPTOR; + switch (DescriptorType) + { + case DTYPE_Device: + Address = DESCRIPTOR_ADDRESS (DeviceDescriptor); + Size = sizeof (USB_Descriptor_Device_t); + break; + case DTYPE_Configuration: + Address = DESCRIPTOR_ADDRESS (ConfigurationDescriptor); + Size = sizeof (USB_Descriptor_Configuration_t); + break; + case DTYPE_String: + switch (DescriptorNumber) + { + case 0x00: + Address = DESCRIPTOR_ADDRESS (LanguageString); + Size = pgm_read_byte (&LanguageString.Header.Size); + break; + case 0x01: + Address = DESCRIPTOR_ADDRESS (ManufacturerString); + Size = pgm_read_byte (&ManufacturerString.Header.Size); + break; + case 0x02: + Address = DESCRIPTOR_ADDRESS (ProductString); + Size = pgm_read_byte (&ProductString.Header.Size); + break; + } + break; + } + *DescriptorAddress = Address; + return Size; +} + -- cgit v1.2.3