baee8dd6e7a810ad357ef76a0295e875f6733a96
[fw/altos] / src / kernel / ao_product.c
1 /*
2  * Copyright © 2009 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #include "ao.h"
19 #include "ao_product.h"
20
21 /* Defines which mark this particular AltOS product */
22
23 const char ao_version[AO_MAX_VERSION] = AO_iVersion_STRING;
24 const char ao_manufacturer[] = AO_iManufacturer_STRING;
25 const char ao_product[] = AO_iProduct_STRING;
26
27 #define LE_WORD(x)    ((x)&0xFF),((uint8_t) (((uint16_t) (x))>>8))
28
29 #if HAS_USB
30
31 /* Maximum power in mA */
32 #ifndef AO_USB_MAX_POWER
33 #define AO_USB_MAX_POWER        100
34 #endif
35
36 #ifndef AO_USB_INTERFACE_CLASS
37 #define AO_USB_INTERFACE_CLASS  0x02
38 #endif
39
40 #include "ao_usb.h"
41 /* USB descriptors in one giant block of bytes */
42 AO_ROMCONFIG_SYMBOL(0x00aa) uint8_t ao_usb_descriptors [] =
43 {
44         /* Device descriptor */
45         0x12,
46         AO_USB_DESC_DEVICE,
47         LE_WORD(0x0110),        /*  bcdUSB */
48         0x02,                   /*  bDeviceClass */
49         0x00,                   /*  bDeviceSubClass */
50         0x00,                   /*  bDeviceProtocol */
51         AO_USB_CONTROL_SIZE,    /*  bMaxPacketSize */
52         LE_WORD(0xFFFE),        /*  idVendor */
53         LE_WORD(AO_idProduct_NUMBER),   /*  idProduct */
54         LE_WORD(0x0100),        /*  bcdDevice */
55         0x01,                   /*  iManufacturer */
56         0x02,                   /*  iProduct */
57         0x03,                   /*  iSerialNumber */
58         0x01,                   /*  bNumConfigurations */
59
60         /* Configuration descriptor */
61         0x09,
62         AO_USB_DESC_CONFIGURATION,
63         LE_WORD(67),            /*  wTotalLength */
64         0x02,                   /*  bNumInterfaces */
65         0x01,                   /*  bConfigurationValue */
66         0x00,                   /*  iConfiguration */
67         0xC0,                   /*  bmAttributes */
68         AO_USB_MAX_POWER >> 1,  /*  bMaxPower, 2mA units */
69
70         /* Control class interface */
71         0x09,
72         AO_USB_DESC_INTERFACE,
73         0x00,                   /*  bInterfaceNumber */
74         0x00,                   /*  bAlternateSetting */
75         0x01,                   /*  bNumEndPoints */
76         AO_USB_INTERFACE_CLASS, /*  bInterfaceClass */
77         0x02,                   /*  bInterfaceSubClass */
78         0x01,                   /*  bInterfaceProtocol, linux requires value of 1 for the cdc_acm module */
79         0x00,                   /*  iInterface */
80
81         /* Header functional descriptor */
82         0x05,
83         AO_USB_CS_INTERFACE,
84         0x00,                   /*  bDescriptor SubType Header */
85         LE_WORD(0x0110),        /*  CDC version 1.1 */
86
87         /* Call management functional descriptor */
88         0x05,
89         AO_USB_CS_INTERFACE,
90         0x01,                   /* bDescriptor SubType Call Management */
91         0x01,                   /* bmCapabilities = device handles call management */
92         0x01,                   /* bDataInterface call management interface number */
93
94         /* ACM functional descriptor */
95         0x04,
96         AO_USB_CS_INTERFACE,
97         0x02,                   /* bDescriptor SubType Abstract Control Management */
98         0x02,                   /* bmCapabilities = D1 (Set_line_Coding, Set_Control_Line_State, Get_Line_Coding and Serial_State) */
99
100         /* Union functional descriptor */
101         0x05,
102         AO_USB_CS_INTERFACE,
103         0x06,                   /* bDescriptor SubType Union Functional descriptor */
104         0x00,                   /* bMasterInterface */
105         0x01,                   /* bSlaveInterface0 */
106
107         /* Notification EP */
108         0x07,
109         AO_USB_DESC_ENDPOINT,
110         AO_USB_INT_EP|0x80,     /* bEndpointAddress */
111         0x03,                   /* bmAttributes = intr */
112         LE_WORD(8),             /* wMaxPacketSize */
113         0xff,                   /* bInterval */
114
115         /* Data class interface descriptor */
116         0x09,
117         AO_USB_DESC_INTERFACE,
118         0x01,                   /* bInterfaceNumber */
119         0x00,                   /* bAlternateSetting */
120         0x02,                   /* bNumEndPoints */
121         0x0A,                   /* bInterfaceClass = data */
122         0x00,                   /* bInterfaceSubClass */
123         0x00,                   /* bInterfaceProtocol */
124         0x00,                   /* iInterface */
125
126         /* Data EP OUT */
127         0x07,
128         AO_USB_DESC_ENDPOINT,
129         AO_USB_OUT_EP,          /* bEndpointAddress */
130         0x02,                   /* bmAttributes = bulk */
131         LE_WORD(AO_USB_OUT_SIZE),/* wMaxPacketSize */
132         0x00,                   /* bInterval */
133
134         /* Data EP in */
135         0x07,
136         AO_USB_DESC_ENDPOINT,
137         AO_USB_IN_EP|0x80,      /* bEndpointAddress */
138         0x02,                   /* bmAttributes = bulk */
139         LE_WORD(AO_USB_IN_SIZE),/* wMaxPacketSize */
140         0x00,                   /* bInterval */
141
142         /* String descriptors */
143         0x04,
144         AO_USB_DESC_STRING,
145         LE_WORD(0x0409),
146
147         /* iManufacturer */
148         AO_iManufacturer_LEN,
149         AO_USB_DESC_STRING,
150         AO_iManufacturer_UCS2,
151
152         /* iProduct */
153         AO_iProduct_LEN,
154         AO_USB_DESC_STRING,
155         AO_iProduct_UCS2,
156
157         /* iSerial */
158         AO_iSerial_LEN,
159         AO_USB_DESC_STRING,
160         AO_iSerial_UCS2,
161
162         /* Terminating zero */
163         0
164 };
165 #endif