-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupcd_struct.c
More file actions
300 lines (236 loc) · 6.04 KB
/
Copy pathupcd_struct.c
File metadata and controls
300 lines (236 loc) · 6.04 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/usb.h"
#include "usblib/usblib.h"
#include "usblib/usblibpriv.h"
#include "usblib/device/usbdevice.h"
#include "upcd.h"
#define UPCD_VID 0x1cbe
#define UPCD_PID 0x0003
#define DATA_IN_EP USB_EP_1
#define DATA_OUT_EP USB_EP_1
#define DATA_IN_EP_FIFO_SIZE USB_FIFO_SZ_64
#define DATA_OUT_EP_FIFO_SIZE USB_FIFO_SZ_64
#define DATA_IN_EP_MAX_SIZE USBFIFOSizeToBytes(DATA_IN_EP_FIFO_SIZE)
#define DATA_OUT_EP_MAX_SIZE USBFIFOSizeToBytes(DATA_OUT_EP_FIFO_SIZE)
uint8_t g_UPCDDeviceDescriptor[] = {
18,
USB_DTYPE_DEVICE,
USBShort(0x110),
USB_CLASS_VEND_SPECIFIC,
0,
0,
64,
USBShort(0),
USBShort(0),
USBShort(100),
1,
2,
3,
1
};
uint8_t g_UPCDDescriptor[] = {
9,
USB_DTYPE_CONFIGURATION,
USBShort(32),
1,
1,
5,
USB_CONF_ATTR_SELF_PWR,
250,
};
const uint8_t g_UPCDInterface[23] = {
9,
USB_DTYPE_INTERFACE,
0,
0,
2,
USB_CLASS_VEND_SPECIFIC,
0,
0,
4,
//EndPoint Descriptors
7,
USB_DTYPE_ENDPOINT,
USB_EP_DESC_IN | USBEPToIndex(DATA_IN_EP),
USB_EP_ATTR_INT,
USBShort(DATA_IN_EP_MAX_SIZE),
0,
7,
USB_DTYPE_ENDPOINT,
USB_EP_DESC_OUT | USBEPToIndex(DATA_OUT_EP),
USB_EP_ATTR_INT,
USBShort(DATA_OUT_EP_MAX_SIZE),
0,
};
const tConfigSection g_UPCDConfigSection = {
sizeof(g_UPCDDescriptor),
g_UPCDDescriptor,
};
const tConfigSection g_UPCDInterfaceSection = {
sizeof(g_UPCDInterface),
g_UPCDInterface,
};
const tConfigSection *g_UPCDSections[] = {
&g_UPCDConfigSection,
&g_UPCDInterfaceSection,
};
#define NUM_DEV_SECTION sizeof(g_UPCDSections)/sizeof(g_UPCDSections[0])
const tConfigHeader g_UPCDConfigHeader = {
NUM_DEV_SECTION,
g_UPCDSections,
};
const tConfigHeader *const g_UPCDConfigurationDescriptors[] = {
&g_UPCDConfigHeader
};
const uint8_t g_langDescriptor[] =
{
4,
USB_DTYPE_STRING,
USBShort(USB_LANG_EN_US)
};
const uint8_t g_manufacturerString[] =
{
(10 + 1) * 2,
USB_DTYPE_STRING,
'C', 0, '-', 0, 'D', 0, 'A', 0, 'C', 0, ' ', 0, 'A', 0, 'C', 0,
'T', 0, 'S', 0,
};
const uint8_t g_productString[] =
{
(29 + 1) * 2,
USB_DTYPE_STRING,
'U', 0, 'S', 0, 'B', 0, ' ', 0, 'P', 0, 'e', 0, 'r', 0, 'i', 0,
'p', 0, 'h', 0, 'e', 0, 'r', 0, 'a', 0, 'l', 0, ' ', 0, 'C', 0,
'o', 0, 'n', 0, 't', 0, 'r', 0, 'o', 0, 'l', 0, ' ', 0, 'D', 0,
'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0,
};
const uint8_t g_serialNumberString[] =
{
(7 + 1) * 2,
USB_DTYPE_STRING,
'U', 0, 'S', 0, 'B', 0, '-', 0, '0', 0, '0', 0, '1', 0,
};
const uint8_t g_interfaceString[] =
{
(28 + 1) * 2,
USB_DTYPE_STRING,
'D', 0, 'e', 0, 'f', 0, 'a', 0, 'u', 0, 'l', 0, 't', 0, ' ', 0,
'P', 0, 'e', 0, 'r', 0, 'i', 0, 'p', 0, 'h', 0, 'e', 0, 'r', 0,
'a', 0, 'l', 0, ' ', 0, 'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0,
'f', 0, 'a', 0, 'c', 0, 'e', 0,
};
const unsigned char g_configString[] =
{
(32 + 1) * 2,
USB_DTYPE_STRING,
'D', 0, 'e', 0, 'f', 0, 'a', 0, 'u', 0, 'l', 0, 't', 0, ' ', 0,
'P', 0, 'e', 0, 'r', 0, 'i', 0, 'p', 0, 'h', 0, 'e', 0, 'r', 0,
'a', 0, 'l', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, 'f', 0, 'i', 0,
'g', 0, 'u', 0, 'r', 0, 'a', 0, 't', 0, 'i', 0, 'o', 0, 'n', 0,
};
const unsigned char *const g_stringDescriptors[] =
{
g_langDescriptor,
g_manufacturerString,
g_productString,
g_serialNumberString,
g_interfaceString,
g_configString
};
#define NUM_STRING_DESCRIPTORS (sizeof(g_stringDescriptors) / sizeof(uint8_t *))
upcd_device UPCDDev = {
UPCD_VID,
UPCD_PID,
500,
USB_CONF_ATTR_SELF_PWR,
g_stringDescriptors,
NUM_STRING_DESCRIPTORS,
};
static void HandleEndpoints(void *dev, uint32_t status)
{
upcd_devInst *devInst = 0;
upcd_device *device;
uint32_t epStatus, size, compStatus;
static uint8_t data[512];
device = (upcd_device *)dev;
devInst = &device->privInst;
if (status & (0x10000 << USBEPToIndex(devInst->intOutEP))) {
epStatus = USBEndpointStatus(devInst->USBBase,
devInst->intOutEP);
if (epStatus & USB_DEV_RX_PKT_RDY) {
size = USBEndpointDataAvail(devInst->USBBase,
devInst->intOutEP);
compStatus = size;
USBEndpointDataGet(devInst->USBBase,
devInst->intOutEP,
data, &compStatus);
if (size == compStatus) {
USBDevEndpointStatusClear(devInst->
USBBase,
devInst->
intOutEP,
epStatus);
USBDevEndpointDataAck(devInst->USBBase,
devInst->intOutEP,
true);
}
size = CmdHandler(data, size);
USBEndpointDataPut(devInst->USBBase,
devInst->intInEP,
data, size);
USBEndpointDataSend(devInst->USBBase,
devInst->intInEP,
USB_TRANS_IN);
USBEndpointDataSend(devInst->USBBase,
devInst->intInEP,
USB_TRANS_IN_LAST);
}
}
}
const tCustomHandlers g_UPCDHandlers = {
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
HandleEndpoints,
0,
};
void *UPCDInit(uint32_t index, upcd_device *dev)
{
upcd_devInst *privInst;
tConfigDescriptor *priConfigDescp;
tDeviceDescriptor *priDeviceDescp;
privInst = &dev->privInst;
privInst->devInfo.psCallbacks = &g_UPCDHandlers;
privInst->devInfo.pui8DeviceDescriptor = g_UPCDDeviceDescriptor;
privInst->devInfo.ppsConfigDescriptors =
g_UPCDConfigurationDescriptors;
privInst->devInfo.ppui8StringDescriptors = dev->stringDescp;
privInst->devInfo.ui32NumStringDescriptors = dev->numStringDescp;
USBDCDDeviceInfoInit(0, &privInst->devInfo);
privInst->USBBase = USB0_BASE;
privInst->deferredOpFlags = 0;
privInst->connected = false;
privInst->intInEP = DATA_IN_EP;
privInst->intOutEP = DATA_OUT_EP;
privInst->interfaceNo = 0;
InternalUSBTickInit();
InternalUSBRegisterTickHandler(0, (void *)dev);
priDeviceDescp = (tDeviceDescriptor *) g_UPCDDeviceDescriptor;
priDeviceDescp->idVendor = dev->vid;
priDeviceDescp->idProduct = dev->pid;
priConfigDescp = (tConfigDescriptor *) g_UPCDDescriptor;
priConfigDescp->bmAttributes = dev->pwrAttr;
priConfigDescp->bMaxPower = (uint8_t) (dev->maxPwr / 2);
USBDCDInit(index, &privInst->devInfo, (void *)dev);
return dev;
}