summaryrefslogtreecommitdiffhomepage
path: root/digital/dev2/src/usb_twi/descriptors.c
blob: 728184f6404f9c6ed46f4193fafc6ff4dacccd8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* descriptors.c */
/* dev2 - Multi-purpose development board using USB and Ethernet. {{{
 *
 * 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 "common.h"

#include "modules/usb/usb.h"

#include <avr/pgmspace.h>

#include "descriptors.h"

/* Configuration structure. */
typedef struct
{
    USB_Descriptor_Configuration_Header_t Config;
    USB_Descriptor_Interface_t TS1_Interface;
    USB_Descriptor_Endpoint_t TS1_DataOutEndpoint;
    USB_Descriptor_Endpoint_t TS1_DataInEndpoint;
} USB_Descriptor_Configuration_t;

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: 1,
	    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 | TWI_RX_EPNUM),
	    Attributes: EP_TYPE_BULK,
	    EndpointSize: TWI_RX_EPSIZE,
	    PollingIntervalMS: 0x00
	},

    TS1_DataInEndpoint:
	{
	    Header: { Size: sizeof (USB_Descriptor_Endpoint_t),
			Type: DTYPE_Endpoint },
	    EndpointAddress: (ENDPOINT_DESCRIPTOR_DIR_IN | TWI_TX_EPNUM),
	    Attributes: EP_TYPE_BULK,
	    EndpointSize: TWI_TX_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 (8), Type: DTYPE_String },
	UnicodeString: L"dev2 twi"
};

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;
}