Root/atusb/fw2/descr.c

Source at commit ec21e4ba4756379934fc24635438040f66d2ab7c created 9 years 5 months ago.
By Werner Almesberger, atusb/fw2: support device -> host side of the ATUSB EP0 protocol
1/*
2 * atspi/descr.c - USB descriptors
3 *
4 * Written 2008-2011 by Werner Almesberger
5 * Copyright 2008-2011 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include "freakusb.h"
15#include <avr/pgmspace.h>
16
17
18#if 0
19/* f32xbase/fw/common/usb.h */
20
21#define USB_DT_DEVICE 1
22#define USB_DT_CONFIG 2
23#define USB_DT_STRING 3
24#define USB_DT_INTERFACE 4
25#define USB_DT_ENDPOINT 5
26
27#endif
28
29#define USB_CLASS_VENDOR_SPEC 0xff
30
31#define USB_ATTR_BUS_POWERED 0x80
32
33#define USB_DT_DEVICE DEV_DESCR
34#define USB_DT_CONFIG CFG_DESCR
35#define USB_DT_INTERFACE INTF_DESCR
36#define USB_DT_ENDPOINT EP_DESCR
37
38#define EP0_SIZE MAX_BUF_SZ
39#define EP1_SIZE MAX_BUF_SZ
40#define USB_VENDOR 0x20b7 /* Qi Hardware */
41#define USB_PRODUCT 0x1540 /* ben-wpan atusb */
42
43#define LE(x) ((uint16_t) (x) & 0xff), ((uint16_t) (x) >> 8)
44
45/*
46 * Device descriptor
47 */
48
49uint8_t device_descriptor[18] PROGMEM = {
50    18, /* bLength */
51    USB_DT_DEVICE, /* bDescriptorType */
52    LE(0x200), /* bcdUSB */
53    USB_CLASS_VENDOR_SPEC, /* bDeviceClass */
54    0x00, /* bDeviceSubClass */
55    0x00, /* bDeviceProtocol */
56    EP0_SIZE, /* bMaxPacketSize */
57    LE(USB_VENDOR), /* idVendor */
58    LE(USB_PRODUCT), /* idProduct */
59    LE(0x0001), /* bcdDevice */
60    0, /* iManufacturer */
61    0, /* iProduct */
62    0, /* iSerialNumber */
63    1 /* bNumConfigurations */
64};
65
66
67/*
68 * Our configuration
69 *
70 * We're always bus-powered.
71 */
72
73uint8_t config_descriptor[] PROGMEM = {
74    9, /* bLength */
75    USB_DT_CONFIG, /* bDescriptorType */
76#if 0
77    LE(9+9+7+7), /* wTotalLength */
78#else
79    LE(9+9), /* wTotalLength */
80#endif
81    1, /* bNumInterfaces */
82    1, /* bConfigurationValue (> 0 !) */
83    0, /* iConfiguration */
84    USB_ATTR_BUS_POWERED, /* bmAttributes */
85    50/2, /* bMaxPower (50 mA) */
86
87    /* Interface #0 */
88
89    9, /* bLength */
90    USB_DT_INTERFACE, /* bDescriptorType */
91    0, /* bInterfaceNumber */
92    0, /* bAlternateSetting */
93#if 0
94    2, /* bNumEndpoints */
95#else
96    0,
97#endif
98    USB_CLASS_VENDOR_SPEC, /* bInterfaceClass */
99    0, /* bInterfaceSubClass */
100    0, /* bInterfaceProtocol */
101    0, /* iInterface */
102
103#if 0
104    /* EP OUT */
105
106    7, /* bLength */
107    USB_DT_ENDPOINT, /* bDescriptorType */
108    0x01, /* bEndPointAddress */
109    0x02, /* bmAttributes (bulk) */
110    LE(EP1_SIZE), /* wMaxPacketSize */
111    0, /* bInterval */
112
113    /* EP IN */
114
115    7, /* bLength */
116    USB_DT_ENDPOINT, /* bDescriptorType */
117    0x81, /* bEndPointAddress */
118    0x02, /* bmAttributes (bulk) */
119    LE(EP1_SIZE), /* wMaxPacketSize */
120    0, /* bInterval */
121#endif
122};
123
124
125#define dev_desc device_descriptor
126#define cfg_desc config_descriptor
127
128U8 *desc_dev_get()
129{
130    return dev_desc;
131}
132U8 desc_dev_get_len()
133{
134    return pgm_read_byte(dev_desc);
135}
136U8 *desc_cfg_get()
137{
138    return cfg_desc;
139}
140U8 desc_cfg_get_len()
141{
142    return pgm_read_byte(cfg_desc + 2);
143}
144U8 *desc_dev_qual_get()
145{
146    return NULL;
147}
148U8 desc_dev_qual_get_len()
149{
150    return 0;
151}
152U8 *desc_str_get(U8 index)
153{
154    return NULL;
155}
156U8 desc_str_get_len(U8 index)
157{
158    return 0;
159}
160

Archive Download this file



interactive