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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
|
//****************************************************************************
//
// usbdcomp.c - USB composite device class driver.
//
// Copyright (c) 2010-2014 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.0.12573 of the Tiva USB Library.
//
//****************************************************************************
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/usb.h"
#include "usblib/usblib.h"
#include "usblib/usblibpriv.h"
#include "usblib/usb-ids.h"
#include "usblib/usbcdc.h"
#include "usblib/device/usbdevice.h"
#include "usblib/device/usbdcdc.h"
#include "usblib/device/usbdcomp.h"
//****************************************************************************
//
//! \addtogroup composite_device_class_api
//! @{
//
//****************************************************************************
//****************************************************************************
//
// Device Descriptor. This is stored in RAM to allow several fields to be
// changed at runtime based on the client's requirements.
//
//****************************************************************************
static uint8_t g_pui8CompDeviceDescriptor[] =
{
18, // Size of this structure.
USB_DTYPE_DEVICE, // Type of this structure.
USBShort(0x110), // USB version 1.1 (if we say 2.0, hosts assume
// high-speed - see USB 2.0 spec 9.2.6.6)
USB_CLASS_MISC, // USB Device Class (spec 5.1.1)
USB_MISC_SUBCLASS_COMMON, // USB Device Sub-class (spec 5.1.1)
USB_MISC_PROTOCOL_IAD, // USB Device protocol (spec 5.1.1)
64, // Maximum packet size for default pipe.
USBShort(0), // Vendor ID (filled in during USBDCompositeInit).
USBShort(0), // Product ID (filled in during USBDCompositeInit).
USBShort(0x100), // Device Version BCD.
1, // Manufacturer string identifier.
2, // Product string identifier.
3, // Product serial number.
1 // Number of configurations.
};
//****************************************************************************
//
// Composite class device configuration descriptor.
//
// It is vital that the configuration descriptor bConfigurationValue field
// (byte 6) is 1 for the first configuration and increments by 1 for each
// additional configuration defined here. This relationship is assumed in the
// device stack for simplicity even though the USB 2.0 specification imposes
// no such restriction on the bConfigurationValue values.
//
// Note that this structure is deliberately located in RAM since we need to
// be able to patch some values in it based on client requirements.
//
//****************************************************************************
static const uint8_t g_pui8CompConfigDescriptor[] =
{
//
// Configuration descriptor header.
//
9, // Size of the configuration descriptor.
USB_DTYPE_CONFIGURATION, // Type of this descriptor.
USBShort(0), // The total size of this full structure.
0, // The number of interfaces in this
// configuration, this will be filled by
// the class as it discovers all classes
// supported.
1, // The unique value for this configuration.
0, // The string identifier that describes this
// configuration.
USB_CONF_ATTR_BUS_PWR, // .
250, // The maximum power in 2mA increments.
};
//****************************************************************************
//
// Byte offsets used to access various fields in our index/interface/endpoint
// lookup table (tUSBDCompositeDevice.pui32DeviceWorkspace). This workspace
// contains one 4 byte entry per device. The LSB is the device index, next byte
// is the number of the first interface not within this device, next byte is
// the number of the first IN endpoint not within this device and the final
// byte is the number of the first OUT endpoint not within this device. Using
// this simple table we can reasonably quickly cross-reference index with
// interface and endpoint numbers.
//
//****************************************************************************
#define LOOKUP_INDEX_BYTE 0
#define LOOKUP_INTERFACE_BYTE 1
#define LOOKUP_IN_END_BYTE 2
#define LOOKUP_OUT_END_BYTE 3
//****************************************************************************
//
// A marker used to indicate an invalid index into the device table.
//
//****************************************************************************
#define INVALID_DEVICE_INDEX 0xFFFFFFFF
//****************************************************************************
//
// Various internal handlers needed by this class.
//
//****************************************************************************
static void HandleDisconnect(void *pvCompositeInstance);
static void InterfaceChange(void *pvCompositeInstance, uint8_t ui8InterfaceNum,
uint8_t ui8AlternateSetting);
static void ConfigChangeHandler(void *pvCompositeInstance, uint32_t ui32Value);
static void DataSent(void *pvCompositeInstance, uint32_t ui32Info);
static void DataReceived(void *pvCompositeInstance, uint32_t ui32Info);
static void HandleEndpoints(void *pvCompositeInstance, uint32_t ui32Status);
static void HandleRequests(void *pvCompositeInstance, tUSBRequest *psUSBRequest);
static void SuspendHandler(void *pvCompositeInstance);
static void ResumeHandler(void *pvCompositeInstance);
static void ResetHandler(void *pvCompositeInstance);
static void HandleDevice(void *pvCompositeInstance, uint32_t ui32Request,
void *pvRequestData);
static void GetDescriptor(void *pvCompositeInstance, tUSBRequest *psUSBRequest);
//****************************************************************************
//
// Configuration Descriptor.
//
//****************************************************************************
tConfigHeader *g_ppCompConfigDescriptors[1];
//****************************************************************************
//
// The device information structure for the USB Composite device.
//
//****************************************************************************
const tCustomHandlers g_sCompHandlers =
{
//
// GetDescriptor
//
GetDescriptor,
//
// RequestHandler
//
HandleRequests,
//
// InterfaceChange
//
InterfaceChange,
//
// ConfigChange
//
ConfigChangeHandler,
//
// DataReceived
//
DataReceived,
//
// DataSentCallback
//
DataSent,
//
// ResetHandler
//
ResetHandler,
//
// SuspendHandler
//
SuspendHandler,
//
// ResumeHandler
//
ResumeHandler,
//
// DisconnectHandler
//
HandleDisconnect,
//
// EndpointHandler
//
HandleEndpoints,
//
// DeviceHandler
//
HandleDevice,
};
//****************************************************************************
//
// Use the lookup table from the field pui32DeviceWorkspace in the
// tUSBDCompositeDevice structure to determine which device to call given a
// particular composite device interface number.
//
// The returned value is the index into psDevice->tCompositeEntry indicating
// the device which contains this interface or INVALID_DEVICE_INDEX if no
// device contains the passed interface number.
//
//****************************************************************************
static uint32_t
InterfaceToIndex(tUSBDCompositeDevice *psDevice, uint32_t ui32Interface)
{
uint32_t ui32Loop;
uint32_t ui32Lookup;
//
// Check each lookup entry in turn.
//
for(ui32Loop = 0; ui32Loop < psDevice->ui32NumDevices; ui32Loop++)
{
//
// Get the look up value from the device.
//
ui32Lookup = psDevice->psDevices[ui32Loop].ui32DeviceWorkspace;
ui32Lookup = (ui32Lookup >> (8 * LOOKUP_INTERFACE_BYTE)) & 0xff;
//
// If the desired interface number is lower than the value in the
// current lookup table entry, we have found the desired device so
// return its index.
//
if(ui32Interface < ui32Lookup)
{
return(ui32Loop);
}
}
//
// If we get here, an invalid interface number was passed so return a
// marker to indicate this.
//
return(INVALID_DEVICE_INDEX);
}
//****************************************************************************
//
// Use the lookup table from the field pui32DeviceWorkspace in the
// tUSBDCompositeDevice structure to determine which device to call given a
// particular composite device endpoint number.
//
// The returned value is the index into psDevice->tCompositeEntry indicating
// the device which contains this endpoint or INVALID_DEVICE_INDEX if no
// device contains the passed endpoint number.
//
//****************************************************************************
static uint32_t
EndpointToIndex(tUSBDCompositeDevice *psDevice, uint32_t ui32Endpoint,
bool bInEndpoint)
{
uint32_t ui32Loop, ui32EndpointByte, ui32Lookup;
//
// Are we considering an IN or OUT endpoint?
//
ui32EndpointByte = bInEndpoint ? LOOKUP_IN_END_BYTE : LOOKUP_OUT_END_BYTE;
//
// Check each lookup entry in turn.
//
for(ui32Loop = 0; ui32Loop < psDevice->ui32NumDevices; ui32Loop++)
{
//
// Get the look up byte from the device.
//
ui32Lookup = psDevice->psDevices[ui32Loop].ui32DeviceWorkspace;
ui32Lookup = (ui32Lookup >> (ui32EndpointByte * 8)) & 0xff;
//
// If the desired endpoint number is lower than the value in the
// current lookup table entry, we have found the desired device so
// return its index.
//
if(ui32Endpoint < ui32Lookup)
{
return(ui32Loop);
}
}
//
// If we get here, an invalid endpoint number was passed so return a
// marker to indicate this.
//
return(INVALID_DEVICE_INDEX);
}
//****************************************************************************
//
// This function will check if any device classes need a get descriptor
// handler called.
//
//****************************************************************************
static void
GetDescriptor(void *pvCompositeInstance, tUSBRequest *psUSBRequest)
{
uint32_t ui32Idx;
const tDeviceInfo *psDeviceInfo;
tUSBDCompositeDevice *psCompDevice;
//
// Create the composite device pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
//
// Determine which device this request is intended for. We have to be
// careful here to send this to the callback for the correct device
// depending upon whether it is a request sent to the device, the interface
// or the endpoint.
//
switch(psUSBRequest->bmRequestType & USB_RTYPE_RECIPIENT_M)
{
case USB_RTYPE_INTERFACE:
{
ui32Idx = InterfaceToIndex(psCompDevice,
(psUSBRequest->wIndex & 0xFF));
break;
}
case USB_RTYPE_ENDPOINT:
{
ui32Idx = EndpointToIndex(psCompDevice,
(psUSBRequest->wIndex & 0x0F),
(psUSBRequest->wIndex & 0x80) ? true : false);
break;
}
//
// Requests sent to the device or any other recipient can't be
// handled here since we have no way of telling where they are
// supposed to be handled. As a result, we just stall them.
//
// If your composite device has some device-specific descriptors,
// you should add code here to handle them.
//
case USB_RTYPE_DEVICE:
case USB_RTYPE_OTHER:
default:
{
ui32Idx = INVALID_DEVICE_INDEX;
break;
}
}
//
// Did we find a device class to pass the request to?
//
if(ui32Idx != INVALID_DEVICE_INDEX)
{
//
// Get a pointer to the individual device instance.
//
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
//
// Does this device have a GetDescriptor callback?
//
if(psDeviceInfo->psCallbacks->pfnGetDescriptor)
{
//
// Remember this device index so that we can correctly route any
// data notification callbacks to it.
//
psCompDevice->sPrivateData.ui32EP0Owner = ui32Idx;
//
// Call the device to retrieve the descriptor.
//
psDeviceInfo->psCallbacks->pfnGetDescriptor(
psCompDevice->psDevices[ui32Idx].pvInstance, psUSBRequest);
}
else
{
//
// Oops - we can't satisfy the request so stall EP0 to indicate
// an error.
//
USBDCDStallEP0(USBBaseToIndex(
psCompDevice->sPrivateData.ui32USBBase));
}
}
else
{
//
// We are unable to satisfy the descriptor request so stall EP0 to
// indicate an error.
//
USBDCDStallEP0(USBBaseToIndex(
psCompDevice->sPrivateData.ui32USBBase));
}
}
//****************************************************************************
//
// This function will check if any device classes need an suspend handler
// called.
//
//****************************************************************************
static void
SuspendHandler(void *pvCompositeInstance)
{
uint32_t ui32Idx;
tUSBDCompositeDevice *psCompDevice;
const tDeviceInfo *psDeviceInfo;
void *pvDeviceInst;
ASSERT(pvCompositeInstance != 0);
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
//
// Inform the application that the device has resumed.
//
if(psCompDevice->pfnCallback)
{
psCompDevice->pfnCallback(pvCompositeInstance, USB_EVENT_SUSPEND,
0, 0);
}
for(ui32Idx = 0; ui32Idx < psCompDevice->ui32NumDevices; ui32Idx++)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
pvDeviceInst = psCompDevice->psDevices[ui32Idx].pvInstance;
if(psDeviceInfo->psCallbacks->pfnSuspendHandler)
{
psDeviceInfo->psCallbacks->pfnSuspendHandler(pvDeviceInst);
}
}
}
//****************************************************************************
//
// This function will check if any device classes need an resume handler
// called.
//
//****************************************************************************
static void
ResumeHandler(void *pvCompositeInstance)
{
uint32_t ui32Idx;
tUSBDCompositeDevice *psCompDevice;
const tDeviceInfo *psDeviceInfo;
void *pvDeviceInst;
ASSERT(pvCompositeInstance != 0);
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
//
// Inform the application that the device has resumed.
//
if(psCompDevice->pfnCallback)
{
psCompDevice->pfnCallback(pvCompositeInstance, USB_EVENT_RESUME,
0, 0);
}
for(ui32Idx = 0; ui32Idx < psCompDevice->ui32NumDevices; ui32Idx++)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
pvDeviceInst = psCompDevice->psDevices[ui32Idx].pvInstance;
if(psDeviceInfo->psCallbacks->pfnResumeHandler)
{
psDeviceInfo->psCallbacks->pfnResumeHandler(pvDeviceInst);
}
}
}
//****************************************************************************
//
// This function will check if any device classes need an reset handler
// called.
//
//****************************************************************************
static void
ResetHandler(void *pvCompositeInstance)
{
uint32_t ui32Idx;
tUSBDCompositeDevice *psCompDevice;
const tDeviceInfo *psDeviceInfo;
void *pvDeviceInst;
ASSERT(pvCompositeInstance != 0);
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
//
// Inform the application that the device has been connected.
//
if(psCompDevice->pfnCallback)
{
psCompDevice->pfnCallback(pvCompositeInstance,
USB_EVENT_CONNECTED, 0, 0);
}
for(ui32Idx = 0; ui32Idx < psCompDevice->ui32NumDevices; ui32Idx++)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
pvDeviceInst = psCompDevice->psDevices[ui32Idx].pvInstance;
if(psDeviceInfo->psCallbacks->pfnResetHandler)
{
psDeviceInfo->psCallbacks->pfnResetHandler(pvDeviceInst);
}
}
}
//****************************************************************************
//
// This function is called to handle data being set to the host so that the
// application callback can be called when the data has been transferred.
//
//****************************************************************************
static void
DataSent(void *pvCompositeInstance, uint32_t ui32Info)
{
uint32_t ui32Idx;
const tDeviceInfo *psDeviceInfo;
tUSBDCompositeDevice *psCompDevice;
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
//
// Pass this notification on to the device which last handled a
// transaction on endpoint 0 (assuming we know who that was).
//
ui32Idx = psCompDevice->sPrivateData.ui32EP0Owner;
if(ui32Idx != INVALID_DEVICE_INDEX)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
if(psDeviceInfo->psCallbacks->pfnDataSent)
{
psDeviceInfo->psCallbacks->pfnDataSent(
psCompDevice->psDevices[ui32Idx].pvInstance, ui32Info);
}
}
}
//****************************************************************************
//
// This function is called to handle data being received back from the host so
// that the application callback can be called when the new data is ready.
//
//****************************************************************************
static void
DataReceived(void *pvCompositeInstance, uint32_t ui32Info)
{
uint32_t ui32Idx;
const tDeviceInfo *psDeviceInfo;
tUSBDCompositeDevice *psCompDevice;
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
//
// Pass this notification on to the device which last handled a
// transaction on endpoint 0 (assuming we know who that was).
//
ui32Idx = psCompDevice->sPrivateData.ui32EP0Owner;
if(ui32Idx != INVALID_DEVICE_INDEX)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
if(psDeviceInfo->psCallbacks->pfnDataReceived)
{
psDeviceInfo->psCallbacks->pfnDataReceived(
psCompDevice->psDevices[ui32Idx].pvInstance, ui32Info);
}
}
}
//****************************************************************************
//
// This function will check if any device classes need an endpoint handler
// called.
//
//****************************************************************************
static void
HandleEndpoints(void *pvCompositeInstance, uint32_t ui32Status)
{
uint32_t ui32Idx;
const tDeviceInfo *psDeviceInfo;
tUSBDCompositeDevice *psCompDevice;
ASSERT(pvCompositeInstance != 0);
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
//
// Call each of the endpoint handlers. This may seem odd since we should
// only call the handler whose endpoint needs service. Unfortunately, if
// the device class driver is using uDMA, we have no way of knowing which
// handler to call (since ui32Status will be 0). Since the handlers are
// set up to ignore any callback that is not for them, this is safe.
//
for(ui32Idx = 0; ui32Idx < psCompDevice->ui32NumDevices; ui32Idx++)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
if(psDeviceInfo->psCallbacks->pfnEndpointHandler)
{
psDeviceInfo->psCallbacks->pfnEndpointHandler(
psCompDevice->psDevices[ui32Idx].pvInstance, ui32Status);
}
}
}
//*****************************************************************************
//
// Device instance specific handler.
//
//*****************************************************************************
static void
HandleDevice(void *pvCompositeInstance, uint32_t ui32Request,
void *pvRequestData)
{
uint32_t ui32Idx;
tUSBDCompositeDevice *psCompDevice;
const tDeviceInfo *psDeviceInfo;
ASSERT(pvCompositeInstance != 0);
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
for(ui32Idx = 0; ui32Idx < psCompDevice->ui32NumDevices; ui32Idx++)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
if(psDeviceInfo->psCallbacks->pfnDeviceHandler)
{
psDeviceInfo->psCallbacks->pfnDeviceHandler(
psCompDevice->psDevices[ui32Idx].pvInstance, ui32Request,
pvRequestData);
}
}
if(psCompDevice->pfnCallback)
{
switch(ui32Request)
{
case USB_EVENT_LPM_RESUME:
{
//
// Pass the LPM resume event to the client.
//
psCompDevice->pfnCallback(0, USB_EVENT_LPM_RESUME, 0,
(void *)0);
break;
}
case USB_EVENT_LPM_SLEEP:
{
//
// Pass the LPM sleep event to the client.
//
psCompDevice->pfnCallback(0, USB_EVENT_LPM_SLEEP, 0,
(void *)0);
break;
}
case USB_EVENT_LPM_ERROR:
{
//
// Pass the LPM error event to the client.
//
psCompDevice->pfnCallback(0, USB_EVENT_LPM_ERROR, 0,
(void *)0);
break;
}
default:
{
break;
}
}
}
}
//****************************************************************************
//
// This function is called by the USB device stack whenever the device is
// disconnected from the host.
//
//****************************************************************************
static void
HandleDisconnect(void *pvCompositeInstance)
{
uint32_t ui32Idx;
const tDeviceInfo *psDeviceInfo;
tUSBDCompositeDevice *psCompDevice;
ASSERT(pvCompositeInstance != 0);
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
//
// Inform the application that the device has been disconnected.
//
if(psCompDevice->pfnCallback)
{
psCompDevice->pfnCallback(pvCompositeInstance,
USB_EVENT_DISCONNECTED, 0, 0);
}
for(ui32Idx = 0; ui32Idx < psCompDevice->ui32NumDevices; ui32Idx++)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
if(psDeviceInfo->psCallbacks->pfnDisconnectHandler)
{
psDeviceInfo->psCallbacks->pfnDisconnectHandler(
psCompDevice->psDevices[ui32Idx].pvInstance);
}
}
}
//****************************************************************************
//
// This function is called by the USB device stack whenever the device
// interface changes. It will be passed on to the device classes if they have
// a handler for this function.
//
//****************************************************************************
static void
InterfaceChange(void *pvCompositeInstance, uint8_t ui8InterfaceNum,
uint8_t ui8AlternateSetting)
{
uint32_t ui32Idx;
const tDeviceInfo *psDeviceInfo;
tUSBDCompositeDevice *psCompDevice;
ASSERT(pvCompositeInstance != 0);
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
for(ui32Idx = 0; ui32Idx < psCompDevice->ui32NumDevices; ui32Idx++)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
if(psDeviceInfo->psCallbacks->pfnInterfaceChange)
{
psDeviceInfo->psCallbacks->pfnInterfaceChange(
psCompDevice->psDevices[ui32Idx].pvInstance,
ui8InterfaceNum, ui8AlternateSetting);
}
}
}
//****************************************************************************
//
// This function is called by the USB device stack whenever the device
// configuration changes. It will be passed on to the device classes if they
// have a handler for this function.
//
//****************************************************************************
static void
ConfigChangeHandler(void *pvCompositeInstance, uint32_t ui32Value)
{
uint32_t ui32Idx;
const tDeviceInfo *psDeviceInfo;
tUSBDCompositeDevice *psCompDevice;
ASSERT(pvCompositeInstance != 0);
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
for(ui32Idx = 0; ui32Idx < psCompDevice->ui32NumDevices; ui32Idx++)
{
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
if(psDeviceInfo->psCallbacks->pfnConfigChange)
{
psDeviceInfo->psCallbacks->pfnConfigChange(
psCompDevice->psDevices[ui32Idx].pvInstance, ui32Value);
}
}
}
//****************************************************************************
//
// This function is called by the USB device stack whenever a non-standard
// request is received.
//
// \param pvCompositeInstance
// \param psUSBRequest points to the request received.
//
// This call will be passed on to the device classes if they have a handler
// for this function.
//
// \return None.
//
//****************************************************************************
static void
HandleRequests(void *pvCompositeInstance, tUSBRequest *psUSBRequest)
{
uint32_t ui32Idx;
const tDeviceInfo *psDeviceInfo;
tUSBDCompositeDevice *psCompDevice;
//
// Create the device instance pointer.
//
psCompDevice = (tUSBDCompositeDevice *)pvCompositeInstance;
//
// Determine which device this request is intended for. We have to be
// careful here to send this to the callback for the correct device
// depending upon whether it is a request sent to the device, the interface
// or the endpoint.
//
switch(psUSBRequest->bmRequestType & USB_RTYPE_RECIPIENT_M)
{
case USB_RTYPE_INTERFACE:
{
ui32Idx = InterfaceToIndex(psCompDevice,
(psUSBRequest->wIndex & 0xFF));
break;
}
case USB_RTYPE_ENDPOINT:
{
ui32Idx = EndpointToIndex(psCompDevice,
(psUSBRequest->wIndex & 0x0F),
(psUSBRequest->wIndex & 0x80) ? true : false);
break;
}
//
// Requests sent to the device or any other recipient can't be
// handled here since we have no way of telling where they are
// supposed to be handled. As a result, we just stall them.
//
// If your composite device has some device-specific requests that need
// to be handled at the device (rather than interface or endpoint)
// level, you should add code here to handle them.
//
case USB_RTYPE_DEVICE:
case USB_RTYPE_OTHER:
default:
{
ui32Idx = INVALID_DEVICE_INDEX;
break;
}
}
//
// Did we find a device class to pass the request to?
//
if(ui32Idx != INVALID_DEVICE_INDEX)
{
//
// Get a pointer to the individual device instance.
//
psDeviceInfo = psCompDevice->psDevices[ui32Idx].psDevInfo;
//
// Does this device have a RequestHandler callback?
//
if(psDeviceInfo->psCallbacks->pfnRequestHandler)
{
//
// Remember this device index so that we can correctly route any
// data notification callbacks to it.
//
psCompDevice->sPrivateData.ui32EP0Owner = ui32Idx;
//
// Yes - call the device to retrieve the descriptor.
//
psDeviceInfo->psCallbacks->pfnRequestHandler(
psCompDevice->psDevices[ui32Idx].pvInstance,
psUSBRequest);
}
else
{
//
// Oops - we can't satisfy the request so stall EP0 to indicate
// an error.
//
USBDCDStallEP0(USBBaseToIndex(
psCompDevice->sPrivateData.ui32USBBase));
}
}
else
{
//
// We are unable to satisfy the descriptor request so stall EP0 to
// indicate an error.
//
USBDCDStallEP0(USBBaseToIndex(
psCompDevice->sPrivateData.ui32USBBase));
}
}
//****************************************************************************
//
// This function handles sending interface number changes to device instances.
//
//****************************************************************************
static void
CompositeIfaceChange(tCompositeEntry *psCompDevice, uint8_t ui8Old,
uint8_t ui8New)
{
uint8_t pui8Interfaces[2];
if(psCompDevice->psDevInfo->psCallbacks->pfnDeviceHandler)
{
//
// Create the data to pass to the device handler.
//
pui8Interfaces[0] = ui8Old;
pui8Interfaces[1] = ui8New;
//
// Call the device handler to inform the class of the interface number
// change.
//
psCompDevice->psDevInfo->psCallbacks->pfnDeviceHandler(
psCompDevice->pvInstance, USB_EVENT_COMP_IFACE_CHANGE,
(void *)pui8Interfaces);
}
}
//****************************************************************************
//
// This function handles sending endpoint number changes to device instances.
//
//****************************************************************************
static void
CompositeEPChange(tCompositeEntry *psCompDevice, uint8_t ui8Old,
uint8_t ui8New)
{
uint8_t pui8Interfaces[2];
if(psCompDevice->psDevInfo->psCallbacks->pfnDeviceHandler)
{
//
// Create the data to pass to the device handler.
//
pui8Interfaces[0] = ui8Old;
pui8Interfaces[1] = ui8New;
ui8New--;
//
// Call the device handler to inform the class of the interface number
// change.
//
psCompDevice->psDevInfo->psCallbacks->pfnDeviceHandler(
psCompDevice->pvInstance, USB_EVENT_COMP_EP_CHANGE,
(void *)pui8Interfaces);
}
}
//****************************************************************************
//
// This function merges the configuration descriptors into a single multiple
// instance device.
//
//****************************************************************************
uint32_t
BuildCompositeDescriptor(tUSBDCompositeDevice *psCompDevice)
{
uint32_t ui32Idx, ui32Offset, ui32CPIdx, ui32FixINT, ui32Dev;
uint16_t ui16TotalLength, ui16Bytes;
uint8_t ui8Interface, ui8INEndpoint, ui8OUTEndpoint;
uint8_t *pui8Data, *pui8Config;
const tConfigHeader *psConfigHeader;
tDescriptorHeader *psHeader;
const uint8_t *pui8Descriptor;
tInterfaceDescriptor *psInterface;
tEndpointDescriptor *psEndpoint;
const tDeviceInfo *psDevice;
//
// Save the number of devices to look through.
//
ui32Dev = 0;
ui32Idx = 0;
ui8Interface = 0;
ui8INEndpoint = 1;
ui8OUTEndpoint = 1;
ui32Offset = 0;
ui32FixINT = 0;
//
// This puts the first section pointer in the first entry in the list
// of sections.
//
psCompDevice->sPrivateData.ppsCompSections[0] =
&psCompDevice->sPrivateData.psCompSections[0];
//
// Put the pointer to this instances configuration descriptor into the
// front of the list.
//
psCompDevice->sPrivateData.ppsCompSections[0]->pui8Data =
(uint8_t *)&psCompDevice->sPrivateData.sConfigDescriptor;
psCompDevice->sPrivateData.ppsCompSections[0]->ui16Size =
psCompDevice->sPrivateData.sConfigDescriptor.bLength;
//
// The configuration descriptor is 9 bytes so initialize the total length
// to 9 bytes.
//
ui16TotalLength = 9;
//
// Copy the section pointer into the section array for the composite
// device. This is awkward but is required given the definition
// of the structures.
//
psCompDevice->sPrivateData.ppsCompSections[1] =
&psCompDevice->sPrivateData.psCompSections[1];
//
// Copy the pointer to the application supplied space into the section
// list.
//
psCompDevice->sPrivateData.ppsCompSections[1]->ui16Size = 0;
psCompDevice->sPrivateData.ppsCompSections[1]->pui8Data =
psCompDevice->sPrivateData.pui8Data;
//
// Create a local pointer to the data that is used to copy data from
// the other devices into the composite descriptor.
//
pui8Data = psCompDevice->sPrivateData.pui8Data;
//
// Consider each device in turn.
//
while(ui32Dev < psCompDevice->ui32NumDevices)
{
//
// Save the current starting address of this descriptor.
//
pui8Config = pui8Data + ui32Offset;
//
// Create a local pointer to the configuration header.
//
psDevice = psCompDevice->psDevices[ui32Dev].psDevInfo;
psConfigHeader = psDevice->ppsConfigDescriptors[0];
//
// Loop through each of the sections in this device's configuration
// descriptor.
//
for(ui32Idx = 0; ui32Idx < psConfigHeader->ui8NumSections; ui32Idx++)
{
//
// Initialize the local offset in this descriptor. We include
// a special case here to ignore the initial 9 byte configuration
// descriptor since this has already been handled.
//
if(ui32Idx)
{
//
// This is not the first section so we handle everything in
// it.
//
ui16Bytes = 0;
}
else
{
//
// This is the first section for this device so skip the 9
// byte configuration descriptor since we've already handled
// this.
//
ui16Bytes = 9;
//
// If this section includes only the configuration descriptor,
// skip it entirely.
//
if(psConfigHeader->psSections[ui32Idx]->ui16Size <= ui16Bytes)
{
continue;
}
}
//
// Get a pointer to the configuration descriptor.
//
pui8Descriptor = psConfigHeader->psSections[ui32Idx]->pui8Data;
//
// Bounds check the allocated space and return if there is not
// enough space.
//
if(ui32Offset > psCompDevice->sPrivateData.ui32DataSize)
{
return(1);
}
//
// Copy the descriptor from the device into the descriptor list.
//
for(ui32CPIdx = 0;
ui32CPIdx < psConfigHeader->psSections[ui32Idx]->ui16Size;
ui32CPIdx++)
{
pui8Data[ui32CPIdx + ui32Offset] = pui8Descriptor[ui32CPIdx];
}
//
// Read out the descriptors in this section.
//
while(ui16Bytes < psConfigHeader->psSections[ui32Idx]->ui16Size)
{
//
// Create a descriptor header pointer.
//
psHeader = (tDescriptorHeader *)&pui8Data[ui32Offset +
ui16Bytes];
//
// Check for interface descriptors and modify the numbering to
// match the composite device.
//
if(psHeader->bDescriptorType == USB_DTYPE_INTERFACE)
{
psInterface = (tInterfaceDescriptor *)psHeader;
//
// See if this is an alternate setting or the initial
// setting.
//
if(psInterface->bAlternateSetting != 0)
{
//
// If this is an alternate setting then use the
// previous interface number because the current one
// has already been incremented.
//
psInterface->bInterfaceNumber = ui8Interface - 1;
}
else
{
//
// Notify the class that it's interface number has
// changed.
//
CompositeIfaceChange(
&psCompDevice->psDevices[ui32Dev],
psInterface->bInterfaceNumber,
ui8Interface);
//
// This was the non-alternate setting so save the
// value and move to the next interface number.
//
psInterface->bInterfaceNumber = ui8Interface;
//
// No strings allowed on interface descriptors for
// composite devices.
//
psInterface->iInterface = 0;
ui8Interface++;
}
}
//
// Check for endpoint descriptors and modify the numbering to
// match the composite device.
//
else if(psHeader->bDescriptorType == USB_DTYPE_ENDPOINT)
{
psEndpoint = (tEndpointDescriptor *)psHeader;
//
// Check if this is an IN or OUT endpoint.
//
if(psEndpoint->bEndpointAddress & USB_RTYPE_DIR_IN)
{
//
// Check if this is the special Fixed Interrupt class
// and this is the interrupt endpoint.
//
if(((psEndpoint->bmAttributes & USB_EP_ATTR_TYPE_M) ==
USB_EP_ATTR_INT) &&
(psCompDevice->ui16PID == USB_PID_COMP_SERIAL))
{
//
// Check if the Fixed Interrupt endpoint has been
// set yet.
//
if(ui32FixINT == 0)
{
//
// Allocate the fixed interrupt endpoint and
// save its number.
//
ui32FixINT = ui8INEndpoint++;
}
CompositeEPChange(
&psCompDevice->psDevices[ui32Dev],
psEndpoint->bEndpointAddress,
ui32FixINT);
psEndpoint->bEndpointAddress = ui32FixINT |
USB_RTYPE_DIR_IN;
}
else
{
//
// Notify the class that it's interface number has
// changed.
//
CompositeEPChange(
&psCompDevice->psDevices[ui32Dev],
psEndpoint->bEndpointAddress,
ui8INEndpoint);
psEndpoint->bEndpointAddress = ui8INEndpoint++ |
USB_RTYPE_DIR_IN;
}
}
else
{
//
// Notify the class that it's interface number has
// changed.
//
CompositeEPChange(&psCompDevice->psDevices[ui32Dev],
psEndpoint->bEndpointAddress,
ui8OUTEndpoint);
psEndpoint->bEndpointAddress = ui8OUTEndpoint++;
}
}
//
// Move on to the next descriptor.
//
ui16Bytes += psHeader->bLength;
}
ui32Offset += psConfigHeader->psSections[ui32Idx]->ui16Size;
ui16TotalLength += ui16Bytes;
}
//
// Allow the device class to make adjustments to the configuration
// descriptor.
//
psCompDevice->psDevices[ui32Dev].psDevInfo->psCallbacks->pfnDeviceHandler(
psCompDevice->psDevices[ui32Dev].pvInstance,
USB_EVENT_COMP_CONFIG, (void *)pui8Config);
//
// Add an entry into the device workspace array to allow us to quickly
// map interface and endpoint numbers to device instances later.
//
psCompDevice->psDevices[ui32Dev].ui32DeviceWorkspace =
(ui32Dev << (LOOKUP_INDEX_BYTE * 8)) |
(ui8Interface << (LOOKUP_INTERFACE_BYTE * 8)) |
(ui8OUTEndpoint << (LOOKUP_OUT_END_BYTE * 8)) |
(ui8INEndpoint << (LOOKUP_IN_END_BYTE * 8));
//
// Move on to the next device.
//
ui32Dev++;
}
//
// Modify the configuration descriptor to match the number of interfaces
// and the new total size.
//
psCompDevice->sPrivateData.sCompConfigHeader.ui8NumSections = 2;
psCompDevice->sPrivateData.ppsCompSections[1]->ui16Size = ui32Offset;
psCompDevice->sPrivateData.sConfigDescriptor.bNumInterfaces =
ui8Interface;
psCompDevice->sPrivateData.sConfigDescriptor.wTotalLength =
ui16TotalLength;
return(0);
}
//****************************************************************************
//
//! This function should be called once for the composite class device to
//! initialize basic operation and prepare for enumeration.
//!
//! \param ui32Index is the index of the USB controller to initialize for
//! composite device operation.
//! \param psDevice points to a structure containing parameters customizing
//! the operation of the composite device.
//! \param ui32Size is the size in bytes of the data pointed to by the
//! \e pui8Data parameter.
//! \param pui8Data is the data area that the composite class can use to build
//! up descriptors.
//!
//! In order for an application to initialize the USB composite device class,
//! it must first call this function with the a valid composite device class
//! structure in the \e psDevice parameter. This allows this function to
//! initialize the USB controller and device code to be prepared to enumerate
//! and function as a USB composite device. The \e ui32Size and \e pui8Data
//! parameters should be large enough to hold all of the class instances
//! passed in via the \e psDevice structure. This is typically the full size
//! of the configuration descriptor for a device minus its configuration
//! header(9 bytes).
//!
//! This function returns a void pointer that must be passed in to all other
//! APIs used by the composite class.
//!
//! See the documentation on the tUSBDCompositeDevice structure for more
//! information on how to properly fill the structure members.
//!
//! \return This function returns 0 on failure or a non-zero void pointer on
//! success.
//
//****************************************************************************
void *
USBDCompositeInit(uint32_t ui32Index, tUSBDCompositeDevice *psDevice,
uint32_t ui32Size, uint8_t *pui8Data)
{
tCompositeInstance *psInst;
int32_t i32Idx;
uint8_t *pui8Temp;
//
// Check parameter validity.
//
ASSERT(ui32Index == 0);
ASSERT(psDevice);
ASSERT(psDevice->ppui8StringDescriptors);
//
// Initialize the work space in the passed instance structure.
//
psInst = &psDevice->sPrivateData;
psInst->ui32DataSize = ui32Size;
psInst->pui8Data = pui8Data;
//
// Save the base address of the USB controller.
//
psInst->ui32USBBase = USBIndexToBase(ui32Index);
//
// No device is currently transferring data on EP0.
//
psInst->ui32EP0Owner = INVALID_DEVICE_INDEX;
//
// Initialize the device information structure.
//
psInst->sDevInfo.psCallbacks = &g_sCompHandlers;
psInst->sDevInfo.pui8DeviceDescriptor = g_pui8CompDeviceDescriptor;
psInst->sDevInfo.ppsConfigDescriptors =
(const tConfigHeader * const *)g_ppCompConfigDescriptors;
psInst->sDevInfo.ppui8StringDescriptors = 0;
psInst->sDevInfo.ui32NumStringDescriptors = 0;
//
// Initialize the device info structure for the composite device.
//
USBDCDDeviceInfoInit(0, &psInst->sDevInfo);
g_ppCompConfigDescriptors[0] = &psInst->sCompConfigHeader;
g_ppCompConfigDescriptors[0]->ui8NumSections = 0;
g_ppCompConfigDescriptors[0]->psSections =
(const tConfigSection * const *)psDevice->sPrivateData.ppsCompSections;
//
// Create a byte pointer to use with the copy.
//
pui8Temp = (uint8_t *)&psInst->sConfigDescriptor;
//
// Copy the default configuration descriptor into the instance data.
//
for(i32Idx = 0; i32Idx < g_pui8CompConfigDescriptor[0]; i32Idx++)
{
pui8Temp[i32Idx] = g_pui8CompConfigDescriptor[i32Idx];
}
//
// Create a byte pointer to use with the copy.
//
pui8Temp = (uint8_t *)&psInst->sDeviceDescriptor;
//
// Copy the default configuration descriptor into the instance data.
//
for(i32Idx = 0; i32Idx < g_pui8CompDeviceDescriptor[0]; i32Idx++)
{
pui8Temp[i32Idx] = g_pui8CompDeviceDescriptor[i32Idx];
}
//
// Fix up the device descriptor with the client-supplied values.
//
psInst->sDeviceDescriptor.idVendor = psDevice->ui16VID;
psInst->sDeviceDescriptor.idProduct = psDevice->ui16PID;
//
// Fix up the configuration descriptor with client-supplied values.
//
psInst->sConfigDescriptor.bmAttributes = psDevice->ui8PwrAttributes;
psInst->sConfigDescriptor.bMaxPower =
(uint8_t)(psDevice->ui16MaxPowermA>>1);
psInst->sDevInfo.pui8DeviceDescriptor =
(const uint8_t *)&psInst->sDeviceDescriptor;
//
// Plug in the client's string table to the device information
// structure.
//
psInst->sDevInfo.ppui8StringDescriptors =
psDevice->ppui8StringDescriptors;
psInst->sDevInfo.ui32NumStringDescriptors =
psDevice->ui32NumStringDescriptors;
//
// Enable Clocking to the USB controller so that changes to the USB
// controller can be made in the BuildCompositeDescriptor() function.
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);
//
// Create the combined descriptors.
//
if(BuildCompositeDescriptor(psDevice))
{
return(0);
}
//
// All is well so now pass the descriptors to the lower layer and put
// the bulk device on the bus.
//
USBDCDInit(ui32Index, &psInst->sDevInfo, (void *)psDevice);
//
// Return the pointer to the instance indicating that everything went
// well.
//
return((void *)psDevice);
}
//****************************************************************************
//
//! Shuts down the composite device.
//!
//! \param pvCompositeInstance is the pointer to the device instance structure
//! as returned by USBDCompositeInit().
//!
//! This function terminates composite device interface for the instance
//! not me supplied. Following this call, the \e pvCompositeInstance instance
//! should not be used in any other calls.
//!
//! \return None.
//
//****************************************************************************
void
USBDCompositeTerm(void *pvCompositeInstance)
{
ASSERT(pvCompositeInstance != 0);
}
//****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//****************************************************************************
|