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
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
|
//*****************************************************************************
//
// usblib.h - Main header file for the USB Library.
//
// Copyright (c) 2008-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.
//
//*****************************************************************************
#ifndef __USBLIB_H__
#define __USBLIB_H__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
//*****************************************************************************
//
// This is the maximum number of devices we can support when in host mode and
// using a hub. By default, we support up to 4 devices (plus 1 internally for
// the hub itself).
//
//*****************************************************************************
#ifndef MAX_USB_DEVICES
#define MAX_USB_DEVICES 5
#endif
//*****************************************************************************
//
// This is the maximum number of endpoints supported by the usblib.
//
//*****************************************************************************
#ifndef USBLIB_NUM_EP
#define USBLIB_NUM_EP 8 // Number of supported endpoints.
#endif
//*****************************************************************************
//
// The following macro allows compiler-independent syntax to be used to
// define packed structures. A typical structure definition using these
// macros will look similar to the following example:
//
// #ifdef ewarm
// #pragma pack(1)
// #endif
//
// typedef struct _PackedStructName
// {
// uint32_t ui32FirstField;
// int8_t i8CharMember;
// uint16_t ui16Short;
// }
// PACKED tPackedStructName;
//
// #ifdef ewarm
// #pragma pack()
// #endif
//
// The conditional blocks related to ewarm include the #pragma pack() lines
// only if the IAR Embedded Workbench compiler is being used. Unfortunately,
// it is not possible to emit a #pragma from within a macro definition so this
// must be done explicitly.
//
//*****************************************************************************
#if defined(ccs) || \
defined(codered) || \
defined(gcc) || \
defined(rvmdk) || \
defined(__ARMCC_VERSION) || \
defined(sourcerygxx)
#define PACKED __attribute__ ((packed))
#elif defined(ewarm)
#define PACKED
#else
#error Unrecognized COMPILER!
#endif
//*****************************************************************************
//
// Assorted language IDs from the document "USB_LANGIDs.pdf" provided by the
// USB Implementers' Forum (Version 1.0).
//
//*****************************************************************************
#define USB_LANG_CHINESE_PRC 0x0804 // Chinese (PRC)
#define USB_LANG_CHINESE_TAIWAN 0x0404 // Chinese (Taiwan)
#define USB_LANG_EN_US 0x0409 // English (United States)
#define USB_LANG_EN_UK 0x0809 // English (United Kingdom)
#define USB_LANG_EN_AUS 0x0C09 // English (Australia)
#define USB_LANG_EN_CA 0x1009 // English (Canada)
#define USB_LANG_EN_NZ 0x1409 // English (New Zealand)
#define USB_LANG_FRENCH 0x040C // French (Standard)
#define USB_LANG_GERMAN 0x0407 // German (Standard)
#define USB_LANG_HINDI 0x0439 // Hindi
#define USB_LANG_ITALIAN 0x0410 // Italian (Standard)
#define USB_LANG_JAPANESE 0x0411 // Japanese
#define USB_LANG_KOREAN 0x0412 // Korean
#define USB_LANG_ES_TRAD 0x040A // Spanish (Traditional)
#define USB_LANG_ES_MODERN 0x0C0A // Spanish (Modern)
#define USB_LANG_SWAHILI 0x0441 // Swahili (Kenya)
#define USB_LANG_URDU_IN 0x0820 // Urdu (India)
#define USB_LANG_URDU_PK 0x0420 // Urdu (Pakistan)
//*****************************************************************************
//
//! \addtogroup usbchap9_src
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
// Note:
//
// Structure definitions which are derived directly from the USB specification
// use field names from the specification. Since a somewhat different version
// of Hungarian prefix notation is used from the standard, beware of making
// assumptions about field sizes based on the field prefix when using
// these structures. Of particular note is the difference in the meaning of
// the 'i' prefix. In USB structures, this indicates a single byte index
// whereas in other code, this is an integer or enumeration variable.
//
//*****************************************************************************
//*****************************************************************************
//
// All structures defined in this section of the header require byte packing of
// fields. This is usually accomplished using the PACKED macro but, for IAR
// Embedded Workbench, this requires a pragma.
//
//*****************************************************************************
#ifdef ewarm
#pragma pack(1)
#endif
//*****************************************************************************
//
// Definitions related to standard USB device requests (sections 9.3 & 9.4)
//
//*****************************************************************************
//*****************************************************************************
//
//! The standard USB request header as defined in section 9.3 of the USB 2.0
//! specification.
//
//*****************************************************************************
typedef struct
{
//
//! Determines the type and direction of the request.
//
uint8_t bmRequestType;
//
//! Identifies the specific request being made.
//
uint8_t bRequest;
//
//! Word-sized field that varies according to the request.
//
uint16_t wValue;
//
//! Word-sized field that varies according to the request; typically used
//! to pass an index or offset.
//
uint16_t wIndex;
//
//! The number of bytes to transfer if there is a data stage to the
//! request.
//
uint16_t wLength;
}
PACKED tUSBRequest;
//*****************************************************************************
//
// The following defines are used with the bmRequestType member of tUSBRequest.
//
// Request types have 3 bit fields:
// 4:0 - Is the recipient type.
// 6:5 - Is the request type.
// 7 - Is the direction of the request.
//
//*****************************************************************************
#define USB_RTYPE_DIR_IN 0x80
#define USB_RTYPE_DIR_OUT 0x00
#define USB_RTYPE_TYPE_M 0x60
#define USB_RTYPE_VENDOR 0x40
#define USB_RTYPE_CLASS 0x20
#define USB_RTYPE_STANDARD 0x00
#define USB_RTYPE_RECIPIENT_M 0x1f
#define USB_RTYPE_OTHER 0x03
#define USB_RTYPE_ENDPOINT 0x02
#define USB_RTYPE_INTERFACE 0x01
#define USB_RTYPE_DEVICE 0x00
//*****************************************************************************
//
// Standard USB requests IDs used in the bRequest field of tUSBRequest.
//
//*****************************************************************************
#define USBREQ_GET_STATUS 0x00
#define USBREQ_CLEAR_FEATURE 0x01
#define USBREQ_SET_FEATURE 0x03
#define USBREQ_SET_ADDRESS 0x05
#define USBREQ_GET_DESCRIPTOR 0x06
#define USBREQ_SET_DESCRIPTOR 0x07
#define USBREQ_GET_CONFIG 0x08
#define USBREQ_SET_CONFIG 0x09
#define USBREQ_GET_INTERFACE 0x0a
#define USBREQ_SET_INTERFACE 0x0b
#define USBREQ_SYNC_FRAME 0x0c
//*****************************************************************************
//
// Data returned from a USBREQ_GET_STATUS request to a device.
//
//*****************************************************************************
#define USB_STATUS_SELF_PWR 0x0001 // Currently self powered.
#define USB_STATUS_BUS_PWR 0x0000 // Currently bus-powered.
#define USB_STATUS_PWR_M 0x0001 // Mask for power mode.
#define USB_STATUS_REMOTE_WAKE 0x0002 // Remote wake-up is currently enabled.
//*****************************************************************************
//
// Feature Selectors (tUSBRequest.wValue) passed on USBREQ_CLEAR_FEATURE and
// USBREQ_SET_FEATURE.
//
//*****************************************************************************
#define USB_FEATURE_EP_HALT 0x0000 // Endpoint halt feature.
#define USB_FEATURE_REMOTE_WAKE 0x0001 // Remote wake feature, device only.
#define USB_FEATURE_TEST_MODE 0x0002 // Test mode
//*****************************************************************************
//
// Endpoint Selectors (tUSBRequest.wIndex) passed on USBREQ_CLEAR_FEATURE,
// USBREQ_SET_FEATURE and USBREQ_GET_STATUS.
//
//*****************************************************************************
#define USB_REQ_EP_NUM_M 0x007F
#define USB_REQ_EP_DIR_M 0x0080
#define USB_REQ_EP_DIR_IN 0x0080
#define USB_REQ_EP_DIR_OUT 0x0000
//*****************************************************************************
//
// Standard USB descriptor types. These values are passed in the upper bytes
// of tUSBRequest.wValue on USBREQ_GET_DESCRIPTOR and also appear in the
// bDescriptorType field of standard USB descriptors.
//
//*****************************************************************************
#define USB_DTYPE_DEVICE 1
#define USB_DTYPE_CONFIGURATION 2
#define USB_DTYPE_STRING 3
#define USB_DTYPE_INTERFACE 4
#define USB_DTYPE_ENDPOINT 5
#define USB_DTYPE_DEVICE_QUAL 6
#define USB_DTYPE_OSPEED_CONF 7
#define USB_DTYPE_INTERFACE_PWR 8
#define USB_DTYPE_OTG 9
#define USB_DTYPE_INTERFACE_ASC 11
#define USB_DTYPE_CS_INTERFACE 36
#define USB_DTYPE_HUB 41
//*****************************************************************************
//
// Definitions related to USB descriptors (sections 9.5 & 9.6)
//
//*****************************************************************************
//*****************************************************************************
//
//! This structure describes a generic descriptor header. These fields are to
//! be found at the beginning of all valid USB descriptors.
//
//*****************************************************************************
typedef struct
{
//
//! The length of this descriptor (including this length byte) expressed
//! in bytes.
//
uint8_t bLength;
//
//! The type identifier of the descriptor whose information follows. For
//! standard descriptors, this field could contain, for example,
//! USB_DTYPE_DEVICE to identify a device descriptor or USB_DTYPE_ENDPOINT
//! to identify an endpoint descriptor.
//
uint8_t bDescriptorType;
}
PACKED tDescriptorHeader;
//*****************************************************************************
//
//! This structure describes the USB device descriptor as defined in USB
//! 2.0 specification section 9.6.1.
//
//*****************************************************************************
typedef struct
{
//
//! The length of this descriptor in bytes. All device descriptors are
//! 18 bytes long.
//
uint8_t bLength;
//
//! The type of the descriptor. For a device descriptor, this will be
//! USB_DTYPE_DEVICE (1).
//
uint8_t bDescriptorType;
//
//! The USB Specification Release Number in BCD format. For USB 2.0, this
//! will be 0x0200.
//
uint16_t bcdUSB;
//
//! The device class code.
//
uint8_t bDeviceClass;
//
//! The device subclass code. This value qualifies the value found in the
//! bDeviceClass field.
//
uint8_t bDeviceSubClass;
//
//! The device protocol code. This value is qualified by the values of
//! bDeviceClass and bDeviceSubClass.
//
uint8_t bDeviceProtocol;
//
//! The maximum packet size for endpoint zero. Valid values are 8, 16, 32
//! and 64.
//
uint8_t bMaxPacketSize0;
//
//! The device Vendor ID (VID) as assigned by the USB-IF.
//
uint16_t idVendor;
//
//! The device Product ID (PID) as assigned by the manufacturer.
//
uint16_t idProduct;
//
//! The device release number in BCD format.
//
uint16_t bcdDevice;
//
//! The index of a string descriptor describing the manufacturer.
//
uint8_t iManufacturer;
//
//! The index of a string descriptor describing the product.
//
uint8_t iProduct;
//
//! The index of a string descriptor describing the device's serial
//! number.
//
uint8_t iSerialNumber;
//
//! The number of possible configurations offered by the device. This
//! field indicates the number of distinct configuration descriptors that
//! the device offers.
//
uint8_t bNumConfigurations;
}
PACKED tDeviceDescriptor;
//*****************************************************************************
//
// USB Device Class codes used in the tDeviceDescriptor.bDeviceClass field.
// Definitions for the bDeviceSubClass and bDeviceProtocol fields are device
// specific and can be found in the appropriate device class header files.
//
//*****************************************************************************
#define USB_CLASS_DEVICE 0x00
#define USB_CLASS_AUDIO 0x01
#define USB_CLASS_CDC 0x02
#define USB_CLASS_HID 0x03
#define USB_CLASS_PHYSICAL 0x05
#define USB_CLASS_IMAGE 0x06
#define USB_CLASS_PRINTER 0x07
#define USB_CLASS_MASS_STORAGE 0x08
#define USB_CLASS_HUB 0x09
#define USB_CLASS_CDC_DATA 0x0a
#define USB_CLASS_SMART_CARD 0x0b
#define USB_CLASS_SECURITY 0x0d
#define USB_CLASS_VIDEO 0x0e
#define USB_CLASS_HEALTHCARE 0x0f
#define USB_CLASS_DIAG_DEVICE 0xdc
#define USB_CLASS_WIRELESS 0xe0
#define USB_CLASS_MISC 0xef
#define USB_CLASS_APP_SPECIFIC 0xfe
#define USB_CLASS_VEND_SPECIFIC 0xff
#define USB_CLASS_EVENTS 0xffffffff
//*****************************************************************************
//
// Generic values for undefined subclass and protocol.
//
//*****************************************************************************
#define USB_SUBCLASS_UNDEFINED 0x00
#define USB_PROTOCOL_UNDEFINED 0x00
//*****************************************************************************
//
// The following are the miscellaneous subclass values.
//
//*****************************************************************************
#define USB_MISC_SUBCLASS_SYNC 0x01
#define USB_MISC_SUBCLASS_COMMON \
0x02
//*****************************************************************************
//
// These following are miscellaneous protocol values.
//
//*****************************************************************************
#define USB_MISC_PROTOCOL_IAD 0x01
//*****************************************************************************
//
// These following are hub protocol values.
//
//*****************************************************************************
#define USB_HUB_PROTOCOL_FS 0x00
#define USB_HUB_PROTOCOL_SINGLE 0x01
#define USB_HUB_PROTOCOL_MULTI 0x02
//*****************************************************************************
//
//! This structure describes the USB device qualifier descriptor as defined in
//! the USB 2.0 specification, section 9.6.2.
//
//*****************************************************************************
typedef struct
{
//
//! The length of this descriptor in bytes. All device qualifier
//! descriptors are 10 bytes long.
//
uint8_t bLength;
//
//! The type of the descriptor. For a device descriptor, this will be
//! USB_DTYPE_DEVICE_QUAL (6).
//
uint8_t bDescriptorType;
//
//! The USB Specification Release Number in BCD format. For USB 2.0, this
//! will be 0x0200.
//
uint16_t bcdUSB;
//
//! The device class code.
//
uint8_t bDeviceClass;
//
//! The device subclass code. This value qualifies the value found in the
//! bDeviceClass field.
//
uint8_t bDeviceSubClass;
//
//! The device protocol code. This value is qualified by the values of
//! bDeviceClass and bDeviceSubClass.
//
uint8_t bDeviceProtocol;
//
//! The maximum packet size for endpoint zero when operating at a speed
//! other than high speed.
//
uint8_t bMaxPacketSize0;
//
//! The number of other-speed configurations supported.
//
uint8_t bNumConfigurations;
//
//! Reserved for future use. Must be set to zero.
//
uint8_t bReserved;
}
PACKED tDeviceQualifierDescriptor;
//*****************************************************************************
//
//! This structure describes the USB configuration descriptor as defined in
//! USB 2.0 specification section 9.6.3. This structure also applies to the
//! USB other speed configuration descriptor defined in section 9.6.4.
//
//*****************************************************************************
typedef struct
{
//
//! The length of this descriptor in bytes. All configuration descriptors
//! are 9 bytes long.
//
uint8_t bLength;
//
//! The type of the descriptor. For a configuration descriptor, this will
//! be USB_DTYPE_CONFIGURATION (2).
//
uint8_t bDescriptorType;
//
//! The total length of data returned for this configuration. This
//! includes the combined length of all descriptors (configuration,
//! interface, endpoint and class- or vendor-specific) returned for this
//! configuration.
//
uint16_t wTotalLength;
//
//! The number of interface supported by this configuration.
//
uint8_t bNumInterfaces;
//
//! The value used as an argument to the SetConfiguration standard request
//! to select this configuration.
//
uint8_t bConfigurationValue;
//
//! The index of a string descriptor describing this configuration.
//
uint8_t iConfiguration;
//
//! Attributes of this configuration.
//
uint8_t bmAttributes;
//
//! The maximum power consumption of the USB device from the bus in this
//! configuration when the device is fully operational. This is expressed
//! in units of 2mA so, for example, 100 represents 200mA.
//
uint8_t bMaxPower;
}
PACKED tConfigDescriptor;
//*****************************************************************************
//
// Flags used in constructing the value assigned to the field
// tConfigDescriptor.bmAttributes. Note that bit 7 is reserved and must be set
// to 1.
//
//*****************************************************************************
#define USB_CONF_ATTR_PWR_M 0xC0
#define USB_CONF_ATTR_SELF_PWR 0xC0
#define USB_CONF_ATTR_BUS_PWR 0x80
#define USB_CONF_ATTR_RWAKE 0xA0
//*****************************************************************************
//
//! This structure describes the USB interface descriptor as defined in USB
//! 2.0 specification section 9.6.5.
//
//*****************************************************************************
typedef struct
{
//
//! The length of this descriptor in bytes. All interface descriptors
//! are 9 bytes long.
//
uint8_t bLength;
//
//! The type of the descriptor. For an interface descriptor, this will
//! be USB_DTYPE_INTERFACE (4).
//
uint8_t bDescriptorType;
//
//! The number of this interface. This is a zero based index into the
//! array of concurrent interfaces supported by this configuration.
//
uint8_t bInterfaceNumber;
//
//! The value used to select this alternate setting for the interface
//! defined in bInterfaceNumber.
//
uint8_t bAlternateSetting;
//
//! The number of endpoints used by this interface (excluding endpoint
//! zero).
//
uint8_t bNumEndpoints;
//
//! The interface class code as assigned by the USB-IF.
//
uint8_t bInterfaceClass;
//
//! The interface subclass code as assigned by the USB-IF.
//
uint8_t bInterfaceSubClass;
//
//! The interface protocol code as assigned by the USB-IF.
//
uint8_t bInterfaceProtocol;
//
//! The index of a string descriptor describing this interface.
//
uint8_t iInterface;
}
PACKED tInterfaceDescriptor;
//*****************************************************************************
//
//! This structure describes the USB endpoint descriptor as defined in USB
//! 2.0 specification section 9.6.6.
//
//*****************************************************************************
typedef struct
{
//
//! The length of this descriptor in bytes. All endpoint descriptors
//! are 7 bytes long.
//
uint8_t bLength;
//
//! The type of the descriptor. For an endpoint descriptor, this will
//! be USB_DTYPE_ENDPOINT (5).
//
uint8_t bDescriptorType;
//
//! The address of the endpoint. This field contains the endpoint number
//! ORed with flag USB_EP_DESC_OUT or USB_EP_DESC_IN to indicate the
//! endpoint direction.
//
uint8_t bEndpointAddress;
//
//! The endpoint transfer type, USB_EP_ATTR_CONTROL, USB_EP_ATTR_ISOC,
//! USB_EP_ATTR_BULK or USB_EP_ATTR_INT and, if isochronous, additional
//! flags indicating usage type and synchronization method.
//
uint8_t bmAttributes;
//
//! The maximum packet size this endpoint is capable of sending or
//! receiving when this configuration is selected. For high speed
//! isochronous or interrupt endpoints, bits 11 and 12 are used to
//! pass additional information.
//
uint16_t wMaxPacketSize;
//
//! The polling interval for data transfers expressed in frames or
//! micro frames depending upon the operating speed.
//
uint8_t bInterval;
}
PACKED tEndpointDescriptor;
//*****************************************************************************
//
// Flags used in constructing the value assigned to the field
// tEndpointDescriptor.bEndpointAddress.
//
//*****************************************************************************
#define USB_EP_DESC_OUT 0x00
#define USB_EP_DESC_IN 0x80
#define USB_EP_DESC_NUM_M 0x0f
//*****************************************************************************
//
// Mask used to extract the maximum packet size (in bytes) from the
// wMaxPacketSize field of the endpoint descriptor.
//
//*****************************************************************************
#define USB_EP_MAX_PACKET_COUNT_M \
0x07FF
//*****************************************************************************
//
// Endpoint attributes used in tEndpointDescriptor.bmAttributes.
//
//*****************************************************************************
#define USB_EP_ATTR_CONTROL 0x00
#define USB_EP_ATTR_ISOC 0x01
#define USB_EP_ATTR_BULK 0x02
#define USB_EP_ATTR_INT 0x03
#define USB_EP_ATTR_TYPE_M 0x03
#define USB_EP_ATTR_ISOC_M 0x0c
#define USB_EP_ATTR_ISOC_NOSYNC 0x00
#define USB_EP_ATTR_ISOC_ASYNC 0x04
#define USB_EP_ATTR_ISOC_ADAPT 0x08
#define USB_EP_ATTR_ISOC_SYNC 0x0c
#define USB_EP_ATTR_USAGE_M 0x30
#define USB_EP_ATTR_USAGE_DATA 0x00
#define USB_EP_ATTR_USAGE_FEEDBACK \
0x10
#define USB_EP_ATTR_USAGE_IMPFEEDBACK \
0x20
//*****************************************************************************
//
//! This structure describes the USB string descriptor for index 0 as defined
//! in USB 2.0 specification section 9.6.7. Note that the number of language
//! IDs is variable and can be determined by examining bLength. The number of
//! language IDs present in the descriptor is given by ((bLength - 2) / 2).
//
//*****************************************************************************
typedef struct
{
//
//! The length of this descriptor in bytes. This value will vary
//! depending upon the number of language codes provided in the descriptor.
//
uint8_t bLength;
//
//! The type of the descriptor. For a string descriptor, this will be
//! USB_DTYPE_STRING (3).
//
uint8_t bDescriptorType;
//
//! The language code (LANGID) for the first supported language. Note that
//! this descriptor may support multiple languages, in which case, the
//! number of elements in the wLANGID array will increase and bLength will
//! be updated accordingly.
//
uint16_t wLANGID[1];
}
PACKED tString0Descriptor;
//*****************************************************************************
//
//! This structure describes the USB string descriptor for all string indexes
//! other than 0 as defined in USB 2.0 specification section 9.6.7.
//
//*****************************************************************************
typedef struct
{
//
//! The length of this descriptor in bytes. This value will be 2 greater
//! than the number of bytes comprising the UNICODE string that the
//! descriptor contains.
//
uint8_t bLength;
//
//! The type of the descriptor. For a string descriptor, this will be
//! USB_DTYPE_STRING (3).
//
uint8_t bDescriptorType;
//
//! The first byte of the UNICODE string. This string is not NULL
//! terminated. Its length (in bytes) can be computed by subtracting 2
//! from the value in the bLength field.
//
uint8_t bString;
}
PACKED tStringDescriptor;
//*****************************************************************************
//
//! Write a 16-bit value to a USB descriptor block.
//!
//! \param ui16Value is the 16-bit value to write to the descriptor.
//!
//! This helper macro is used in descriptor definitions to write two-byte
//! values. Since the configuration descriptor contains all interface and
//! endpoint descriptors in a contiguous block of memory, these descriptors are
//! typically defined using an array of bytes rather than as packed structures.
//!
//! \return Not a function.
//
//*****************************************************************************
#define USBShort(ui16Value) (ui16Value & 0xff), (ui16Value >> 8)
//*****************************************************************************
//
//! Write a 24-bit value to a USB descriptor block.
//!
//! \param ui32Value is the 24-bit value that to write to the descriptor.
//!
//! This helper macro is used in descriptor definitions to write three-byte
//! values. Since the configuration descriptor contains all interface and
//! endpoint descriptors in a contiguous block of memory, these descriptors are
//! typically defined using an array of bytes rather than as packed structures.
//!
//! \return Not a function.
//
//*****************************************************************************
#define USB3Byte(ui32Value) (ui32Value & 0xff), \
((ui32Value >> 8) & 0xff), \
((ui32Value >> 16) & 0xff)
//*****************************************************************************
//
//! Write a 32-bit value to a USB descriptor block.
//!
//! \param ui32Value is the 32-bit value that to write to the descriptor.
//!
//! This helper macro is used in descriptor definitions to write four-byte
//! values. Since the configuration descriptor contains all interface and
//! endpoint descriptors in a contiguous block of memory, these descriptors are
//! typically defined using an array of bytes rather than as packed structures.
//!
//! \return Not a function.
//
//*****************************************************************************
#define USBLong(ui32Value) (ui32Value & 0xff), \
((ui32Value >> 8) & 0xff), \
((ui32Value >> 16) & 0xff), \
((ui32Value >> 24) & 0xff)
//*****************************************************************************
//
//! Traverse to the next USB descriptor in a block.
//!
//! \param ptr points to the first byte of a descriptor in a block of
//! USB descriptors.
//!
//! This macro aids in traversing lists of descriptors by returning a pointer
//! to the next descriptor in the list given a pointer to the current one.
//!
//! \return Returns a pointer to the next descriptor in the block following
//! \e ptr.
//!
//*****************************************************************************
#define NEXT_USB_DESCRIPTOR(ptr) \
(tDescriptorHeader *)(((uint8_t *)(ptr)) + \
*((uint8_t *)(ptr)))
//*****************************************************************************
//
// Return to default packing when using the IAR Embedded Workbench compiler.
//
//*****************************************************************************
#ifdef ewarm
#pragma pack()
#endif
//*****************************************************************************
//
// Close the usbchap9_src Doxygen group.
//! @}
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup device_api
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
// Function prototype for any standard USB request.
//
//*****************************************************************************
typedef void (* tStdRequest)(void *pvInstance, tUSBRequest *pUSBRequest);
//*****************************************************************************
//
// Data callback for receiving data from an endpoint.
//
//*****************************************************************************
typedef void (* tInfoCallback)(void *pvInstance, uint32_t ui32Info);
//*****************************************************************************
//
// Callback made to indicate that an interface alternate setting change has
// occurred.
//
//*****************************************************************************
typedef void (* tInterfaceCallback)(void *pvInstance, uint8_t ui8InterfaceNum,
uint8_t ui8AlternateSetting);
//*****************************************************************************
//
// Generic interrupt handler callbacks.
//
//*****************************************************************************
typedef void (* tUSBIntHandler)(void *pvInstance);
//*****************************************************************************
//
// Interrupt handler callbacks that have status information.
//
//*****************************************************************************
typedef void (* tUSBEPIntHandler)(void *pvInstance, uint32_t ui32Status);
//*****************************************************************************
//
//! Generic handler callbacks that are used when the callers needs to call into
//! an instance of class.
//
//*****************************************************************************
typedef void (* tUSBDeviceHandler)(void *pvInstance, uint32_t ui32Request,
void *pvRequestData);
//*****************************************************************************
//
//! USB event handler functions used during enumeration and operation of the
//! device stack.
//
//*****************************************************************************
typedef struct
{
//
//! This callback is made whenever the USB host requests a non-standard
//! descriptor from the device.
//
tStdRequest pfnGetDescriptor;
//
//! This callback is made whenever the USB host makes a non-standard
//! request.
//
tStdRequest pfnRequestHandler;
//
//! This callback is made in response to a SetInterface request from the
//! host.
//
tInterfaceCallback pfnInterfaceChange;
//
//! This callback is made in response to a SetConfiguration request from
//! the host.
//
tInfoCallback pfnConfigChange;
//
//! This callback is made when data has been received following to a call
//! to USBDCDRequestDataEP0.
//
tInfoCallback pfnDataReceived;
//
//! This callback is made when data has been transmitted following a call
//! to USBDCDSendDataEP0.
//
tInfoCallback pfnDataSent;
//
//! This callback is made when a USB reset is detected.
//
tUSBIntHandler pfnResetHandler;
//
//! This callback is made when the bus has been inactive long enough to
//! trigger a suspend condition.
//
tUSBIntHandler pfnSuspendHandler;
//
//! This is called when resume signaling is detected.
//
tUSBIntHandler pfnResumeHandler;
//
//! This callback is made when the device is disconnected from the USB bus.
//
tUSBIntHandler pfnDisconnectHandler;
//
//! This callback is made to inform the device of activity on all endpoints
//! other than endpoint zero.
//
tUSBEPIntHandler pfnEndpointHandler;
//
//! This generic handler is provided to allow requests based on
//! a given instance to be passed into a device. This is commonly used
//! by a top level composite device that is using multiple instances of
//! a class.
//
tUSBDeviceHandler pfnDeviceHandler;
}
tCustomHandlers;
//*****************************************************************************
//
//! This structure defines a contiguous block of data which contains a group
//! of descriptors that form part of a configuration descriptor for a device.
//! It is assumed that a config section contains only whole descriptors. It is
//! not valid to split a single descriptor across multiple sections.
//!
//*****************************************************************************
typedef struct
{
//
//! The number of bytes of descriptor data pointed to by pui8Data.
//
uint16_t ui16Size;
//
//! A pointer to a block of data containing an integral number of
//! USB descriptors which form part of a larger configuration descriptor.
//
const uint8_t *pui8Data;
}
tConfigSection;
//*****************************************************************************
//
//! This is the top level structure defining a USB device configuration
//! descriptor. A configuration descriptor contains a collection of device-
//! specific descriptors in addition to the basic config, interface and
//! endpoint descriptors. To allow flexibility in constructing the
//! configuration, the descriptor is described in terms of a list of data
//! blocks. The first block must contain the configuration descriptor itself
//! and the following blocks are appended to this in order to produce the
//! full descriptor sent to the host in response to a GetDescriptor request
//! for the configuration descriptor.
//!
//*****************************************************************************
typedef struct
{
//
//! The number of sections comprising the full descriptor for this
//! configuration.
//
uint8_t ui8NumSections;
//
//! A pointer to an array of ui8NumSections section pointers which must
//! be concatenated to form the configuration descriptor.
//
const tConfigSection * const *psSections;
}
tConfigHeader;
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup general_usblib_api
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
// Predeclare of the DMA instance structure.
//
//*****************************************************************************
typedef struct tUSBDMAInstance tUSBDMAInstance;
//*****************************************************************************
//
// USB descriptor parsing functions found in usbdesc.c
//
//*****************************************************************************
//*****************************************************************************
//
//! The USB_DESC_ANY label is used as a wild card in several of the descriptor
//! parsing APIs to determine whether or not particular search criteria should
//! be ignored.
//
//*****************************************************************************
#define USB_DESC_ANY 0xFFFFFFFF
extern uint32_t USBDescGetNum(tDescriptorHeader *psDesc, uint32_t ui32Size,
uint32_t ui32Type);
extern tDescriptorHeader *USBDescGet(tDescriptorHeader *psDesc,
uint32_t ui32Size, uint32_t ui32Type,
uint32_t ui32Index);
extern uint32_t
USBDescGetNumAlternateInterfaces(tConfigDescriptor *psConfig,
uint8_t ui8InterfaceNumber);
extern tInterfaceDescriptor *USBDescGetInterface(tConfigDescriptor *psConfig,
uint32_t ui32Index,
uint32_t ui32AltCfg);
extern tEndpointDescriptor *
USBDescGetInterfaceEndpoint(tInterfaceDescriptor *psInterface,
uint32_t ui32Index, uint32_t ui32Size);
//*****************************************************************************
//
//! The operating mode required by the USB library client. This type is used
//! by applications which wish to be able to switch between host and device
//! modes by calling the USBStackModeSet() API.
//
//*****************************************************************************
typedef enum
{
//
//! Operate in USB device mode with active monitoring of VBUS and the
//! ID pin must be pulled to a logic high value.
//
eUSBModeDevice = 0,
//
//! Operate in USB host mode with active monitoring of VBUS and the ID pin
//! must be pulled to a logic low value.
//
eUSBModeHost,
//
//! Operate as an On-The-Go device which requires both VBUS and ID to be
//! connected directly to the USB controller from the USB connector.
//
eUSBModeOTG,
//
//! A marker indicating that no USB mode has yet been set by the
//! application.
//
eUSBModeNone,
//
//! Force host mode so that the VBUS and ID pins are not used or monitored
//! by the USB controller.
//
eUSBModeForceHost,
//
//! Forcing device mode so that the VBUS and ID pins are not used or
//! monitored by the USB controller.
//
eUSBModeForceDevice,
}
tUSBMode;
//*****************************************************************************
//
// A pointer to a USB mode callback function. This function is called by the
// USB library to indicate to the application which operating mode it should
// use, host or device.
//
//*****************************************************************************
typedef void (*tUSBModeCallback)(uint32_t ui32Index, tUSBMode iMode);
//*****************************************************************************
//
//! USB callback function.
//!
//! \param pvCBData is the callback pointer associated with the instance
//! generating the callback. This is a value provided by the client during
//! initialization of the instance making the callback.
//! \param ui32Event is the identifier of the asynchronous event which is being
//! notified to the client.
//! \param ui32MsgParam is an event-specific parameter.
//! \param pvMsgData is an event-specific data pointer.
//!
//! A function pointer provided to the USB layer by the application
//! which will be called to notify it of all asynchronous events relating to
//! data transmission or reception. This callback is used by device class
//! drivers and host pipe functions.
//!
//! \return Returns an event-dependent value.
//
//*****************************************************************************
typedef uint32_t (* tUSBCallback)(void *pvCBData, uint32_t ui32Event,
uint32_t ui32MsgParam, void *pvMsgData);
//*****************************************************************************
//
// Error sources reported via USB_EVENT_ERROR.
//
//*****************************************************************************
//
//! The host received an invalid PID in a transaction.
//
#define USBERR_HOST_IN_PID_ERROR \
0x01000000
//
//! The host did not receive a response from a device.
//
#define USBERR_HOST_IN_NOT_COMP 0x00100000
//
//! The host received a stall on an IN endpoint.
//
#define USBERR_HOST_IN_STALL 0x00400000
//
//! The host detected a CRC or bit-stuffing error (isochronous mode).
//
#define USBERR_HOST_IN_DATA_ERROR \
0x00080000
//
//! The host received NAK on an IN endpoint for longer than the specified
//! timeout period (interrupt, bulk and control modes).
//
#define USBERR_HOST_IN_NAK_TO 0x00080000
//
//! The host failed to communicate with a device via an IN endpoint.
//
#define USBERR_HOST_IN_ERROR 0x00040000
//
//! The host receive FIFO is full.
//
#define USBERR_HOST_IN_FIFO_FULL \
0x00020000
//
//! The host received NAK on an OUT endpoint for longer than the specified
//! timeout period (bulk, interrupt and control modes).
//
#define USBERR_HOST_OUT_NAK_TO 0x00000080
//
//! The host did not receive a response from a device (isochronous mode).
//
#define USBERR_HOST_OUT_NOT_COMP \
0x00000080
//
//! The host received a stall on an OUT endpoint.
//
#define USBERR_HOST_OUT_STALL 0x00000020
//
//! The host failed to communicate with a device via an OUT endpoint.
//
#define USBERR_HOST_OUT_ERROR 0x00000004
//
//! The host received NAK on endpoint 0 for longer than the configured
//! timeout.
//
#define USBERR_HOST_EP0_NAK_TO 0x00000080
//
//! The host failed to communicate with a device via an endpoint zero.
//
#define USBERR_HOST_EP0_ERROR 0x00000010
//
//! The device detected a CRC error in received data.
//
#define USBERR_DEV_RX_DATA_ERROR \
0x00080000
//
//! The device was unable to receive a packet from the host since the receive
//! FIFO is full.
//
#define USBERR_DEV_RX_OVERRUN 0x00040000
//
//! The device receive FIFO is full.
//
#define USBERR_DEV_RX_FIFO_FULL 0x00020000
//*****************************************************************************
//
// Close the general_usblib_api Doxygen group.
//! @}
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup usblib_events
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! This structure is used to return generic event based information to an
//! application. The following events are currently supported:
//! USB_EVENT_CONNECTED, USB_EVENT_DISCONNECTED, USB_EVENT_POWER_FAULT,
//! USB_EVENT_POWER_FAULT, USB_EVENT_POWER_ENABLE,
//! USB_EVENT_POWER_DISABLE and USB_EVENT_SOF.
//
//*****************************************************************************
typedef struct
{
//
//! One of the USB_EVENT_ values.
//
uint32_t ui32Event;
//
//! The caller supplied instance value that is passed to event handlers.
//
uint32_t ui32Instance;
}
tEventInfo;
//*****************************************************************************
//
// Base identifiers for groups of USB events. These are used by both the
// device class drivers and host layer.
//
// USB_CLASS_EVENT_BASE is the lowest identifier that should be used for
// a class-specific event. Individual event bases are defined for each
// of the supported device class drivers. Events with IDs between
// USB_EVENT_BASE and USB_CLASS_EVENT_BASE are reserved for stack use.
//
//*****************************************************************************
#define USB_EVENT_BASE 0x0000
#define USB_CLASS_EVENT_BASE 0x8000
//*****************************************************************************
//
// Event base identifiers for the various device classes supported in host
// and device modes.
// The first 0x800 values of a range are reserved for the device specific
// messages and the second 0x800 values of a range are used for the host
// specific messages for a given class.
//
//*****************************************************************************
#define USBD_CDC_EVENT_BASE (USB_CLASS_EVENT_BASE + 0)
#define USBD_HID_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x1000)
#define USBD_HID_KEYB_EVENT_BASE \
(USBD_HID_EVENT_BASE + 0x100)
#define USBD_BULK_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x2000)
#define USBD_MSC_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x3000)
#define USBD_AUDIO_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x4000)
#define USBD_DFU_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x5000)
#define USBH_CDC_EVENT_BASE (USBD_CDC_EVENT_BASE + 0x800)
#define USBH_HID_EVENT_BASE (USBD_HID_EVENT_BASE + 0x800)
#define USBH_BULK_EVENT_BASE (USBD_BULK_EVENT_BASE + 0x800)
#define USBH_MSC_EVENT_BASE (USBD_MSC_EVENT_BASE + 0x800)
#define USBH_AUDIO_EVENT_BASE (USBD_AUDIO_EVENT_BASE + 0x800)
//*****************************************************************************
//
// General events supported by device classes and host pipes.
//
//*****************************************************************************
//
//! The device is now attached to a USB host and ready to begin sending
//! and receiving data (used by device classes only).
//
#define USB_EVENT_CONNECTED (USB_EVENT_BASE + 0)
//
//! The device has been disconnected from the USB host (used by device classes
//! only).
//!
//! \note In device mode, the USB_EVENT_DISCONNECTED will not be reported if
//! the MCU's PB1/USB0VBUS pin is connected to a fixed +5 Volts rather than
//! directly to the VBUS pin on the USB connector.
//
#define USB_EVENT_DISCONNECTED (USB_EVENT_BASE + 1)
//
//! Data has been received and is in the buffer provided or is ready to be
//! read from the FIFO. If the \e pvMsgData value is 0 then the
//! \e ui32MsgParam value contains the amount of data in bytes ready to be read
//! from the device. If the \e pvMsgData value is not 0 then \e pvMsgData is
//! a pointer to the data that was read and \e ui32MsgParam is the number of
//! valid bytes in the array pointed to by \e pvMsgData.
//
#define USB_EVENT_RX_AVAILABLE (USB_EVENT_BASE + 2)
//
//! This event is sent by a lower layer to inquire about the amount of
//! unprocessed data buffered in the layers above. It is used in cases
//! where a low level driver needs to ensure that all preceding data has
//! been processed prior to performing some action or making some notification.
//! Clients receiving this event should return the number of bytes of data
//! that are unprocessed or 0 if no outstanding data remains.
//
#define USB_EVENT_DATA_REMAINING \
(USB_EVENT_BASE + 3)
//
//! This event is sent by a lower layer supporting DMA to request a buffer in
//! which the next received packet may be stored. The \e ui32MsgValue
//! parameter indicates the maximum size of packet that can be received in this
//! channel and \e pvMsgData points to storage which should be written with the
//! returned buffer pointer. The return value from the callback should be the
//! size of the buffer allocated (which may be less than the maximum size
//! passed in \e ui32MsgValue if the client knows that fewer bytes are expected
//! to be received) or 0 if no buffer is being returned.
//
#define USB_EVENT_REQUEST_BUFFER \
(USB_EVENT_BASE + 4)
//
//! Data has been sent and acknowledged. If this event is received via the
//! USB buffer callback, the \e ui32MsgValue parameter indicates the number of
//! bytes from the transmit buffer that have been successfully transmitted
//! and acknowledged.
//
#define USB_EVENT_TX_COMPLETE (USB_EVENT_BASE + 5)
//
//! An error has been reported on the channel or pipe. The \e ui32MsgValue
//! parameter indicates the source(s) of the error and is the logical OR
//! combination of "USBERR_" flags defined below.
//
#define USB_EVENT_ERROR (USB_EVENT_BASE + 6)
//
//! The bus has entered suspend state.
//
#define USB_EVENT_SUSPEND (USB_EVENT_BASE + 7)
//
//! The bus has left suspend state.
//
#define USB_EVENT_RESUME (USB_EVENT_BASE + 8)
//
//! A scheduler event has occurred.
//
#define USB_EVENT_SCHEDULER (USB_EVENT_BASE + 9)
//
//! A device or host has detected a stall condition.
//
#define USB_EVENT_STALL (USB_EVENT_BASE + 10)
//
//! The host detected a power fault condition.
//
#define USB_EVENT_POWER_FAULT (USB_EVENT_BASE + 11)
//
//! The controller has detected a A-Side cable and needs power applied This is
//! only generated on OTG parts if automatic power control is disabled.
//
#define USB_EVENT_POWER_ENABLE (USB_EVENT_BASE + 12)
//
//! The controller needs power removed, This is only generated on OTG parts
//! if automatic power control is disabled.
//
#define USB_EVENT_POWER_DISABLE (USB_EVENT_BASE + 13)
//
//! This define is used with a device class's pfnDeviceHandler handler function
//! to indicate that the USB library has changed the interface number. This
//! event is typically due to the class being included in a composite device.
//!
//! The \e pvInstance is a pointer to an instance of the device being accessed.
//!
//! The \e ui32Request is USB_EVENT_COMP_IFACE_CHANGE.
//!
//! The \e pvRequestData is a pointer to a two byte array where the first value
//! is the old interface number and the second is the new interface number.
//
#define USB_EVENT_COMP_IFACE_CHANGE \
(USB_EVENT_BASE + 14)
//
//! This define is used with a device class's pfnDeviceHandler handler function
//! to indicate that the USB library has changed the endpoint number. This
//! event is typically due to the class being included in a composite device.
//!
//! The \e pvInstance is a pointer to an instance of the device being accessed.
//!
//! The \e ui32Request is USB_EVENT_COMP_EP_CHANGE.
//!
//! The \e pvRequestData is a pointer to a two byte array where the first value
//! is the old endpoint number and the second is the new endpoint number. The
//! endpoint numbers should be exactly as USB specification defines them and
//! bit 7 set indicates an IN endpoint and bit 7 clear indicates an OUT
//! endpoint.
//
#define USB_EVENT_COMP_EP_CHANGE \
(USB_EVENT_BASE + 15)
//
//! This define is used with a device class's pfnDeviceHandler handler function
//! to indicate that the USB library has changed the string index number for a
//! string. This event is typically due to the class being included in a
//! composite device.
//!
//! The \e pvInstance is a pointer to an instance of the device being accessed.
//!
//! The \e ui32Request is USB_EVENT_COMP_STR_CHANGE.
//!
//! The \e pvRequestData is a pointer to a two byte array where the first value
//! is the old string index and the second is the new string index.
//
#define USB_EVENT_COMP_STR_CHANGE \
(USB_EVENT_BASE + 16)
//
//! This define is used with a device class's pfnDeviceHandler handler function
//! to indicate that the USB library has changed the configuration descriptor.
//! This allows the class to make final adjustments to the configuration
//! descriptor. This event is typically due to the class being included in a
//! composite device.
//!
//! The \e pvInstance is a pointer to an instance of the device being accessed.
//!
//! The \e ui32Request is USB_EVENT_COMP_CONFIG.
//!
//! The \e pvRequestData is a pointer to the beginning of the configuration
//! descriptor for the device instance.
//
#define USB_EVENT_COMP_CONFIG (USB_EVENT_BASE + 17)
//
//! An unknown device is now attached to a USB host. This value is only valid
//! for the generic event handler and not other device handlers. It is
//! useful for applications that want to know when an unknown device is
//! connected and what the class is of the unknown device.
//!
//! The \e ui32Instance is the device instance for the unknown device.
//
#define USB_EVENT_UNKNOWN_CONNECTED \
(USB_EVENT_BASE + 18)
//
//! A start of frame event has occurred. This event is disabled by default
//! and must be enabled via a call from the application to USBHCDEventEnable().
//
#define USB_EVENT_SOF (USB_EVENT_BASE + 19)
//
//! This event occurs when a device enters LPM sleep mode.
//
#define USB_EVENT_LPM_SLEEP (USB_EVENT_BASE + 20)
//
//! This event occurs when a device is resumed from LPM sleep mode.
//
#define USB_EVENT_LPM_RESUME (USB_EVENT_BASE + 21)
//
//! This event occurs when a device has responded with a NYET to an LPM request
//! because LPM responses were disabled.
//
#define USB_EVENT_LPM_ERROR (USB_EVENT_BASE + 22)
//*****************************************************************************
//
// Close the usblib_events Doxygen group.
//! @}
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup usblib_buffer_api
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! A function pointer type which describes either a class driver packet read
//! or packet write function (both have the same prototype) to the USB
//! buffer object.
//
//*****************************************************************************
typedef uint32_t (* tUSBPacketTransfer)(void *pvHandle, uint8_t *pi8Data,
uint32_t ui32Length, bool bLast);
//*****************************************************************************
//
//! A function pointer type which describes either a class driver transmit
//! or receive packet available function (both have the same prototype) to the
//! USB buffer object.
//!
//! \param pvHandle is the handle of the device.
//!
//! \return None.
//
//*****************************************************************************
typedef uint32_t (* tUSBPacketAvailable)(void *pvHandle);
//*****************************************************************************
//
//! The number of bytes of workspace that each USB buffer object requires.
//! This workspace memory is provided to the buffer on USBBufferInit() in
//! the \e pvWorkspace field of the \e tUSBBuffer structure.
//
//*****************************************************************************
#define USB_BUFFER_WORKSPACE_SIZE \
24
//*****************************************************************************
//
// The defines used with the USBDCDFeatureSet() or USBHCDFeatureSet() calls.
//
//*****************************************************************************
//*****************************************************************************
//
//! This feature setting enables or disables LPM support in the USB library in
//! either host or device mode depending on if the USBHCDFeatureSet() or
//! USBDCDFeatureSet() is called. If no action is taken the default behavior of
//! USB library is to not support LPM transactions. The \e pvFeature value
//! is a pointer to a 32-bit value containing the a logical OR of the following
//! values:
//!
//! - \b USBLIB_FEATURE_LPM_EN is used to enable LPM support in host or device
//! mode.
//! - \b USBLIB_FEATURE_LPM_DIS(default) is used to disable LPM support in host
//! or device mode.
//! - \b USBLIB_FEATURE_LPM_RMT_WAKE is used to enable remote wake from an
//! LPM suspended state.
//!
//
//*****************************************************************************
#define USBLIB_FEATURE_LPM 0x00000001
//*****************************************************************************
//
// The defines used with the USBDCDFeatureSet() or USBHCDFeatureSet() calls
// for \b USBLIB_FEATURE_LPM feature requests.
//
//*****************************************************************************
#define USBLIB_FEATURE_LPM_RMT_WAKE \
0x00000002
#define USBLIB_FEATURE_LPM_EN 0x00000001
#define USBLIB_FEATURE_LPM_DIS 0x00000000
//*****************************************************************************
//
//! This feature setting allows an application to inform the USB library of the
//! current processor speed that is can use for internal timing when the frame
//! counter is not yet running. The \e pvFeature is a pointer to a 32-bit
//! value that holds the processor frequency in Hz.
//
//*****************************************************************************
#define USBLIB_FEATURE_CPUCLK 0x00000002
//*****************************************************************************
//
//! This feature setting allows an application to inform the USB library of the
//! current USB PLL rate in cases where the USB library needs this information
//! for internal configuration. If this feature is not set, then default rate
//! for the USB PLL is 480MHz. The \e pvFeature is a pointer to an 32-bit
//! value that holds the USB PLL speed in Hz. If the application needs to use
//! an external USB clock the PLL value should be set to zero. This is used
//! when connecting to an external USB phy which is providing the 60-MHz clock.
//!
//
//*****************************************************************************
#define USBLIB_FEATURE_USBPLL 0x00000003
//*****************************************************************************
//!
//! This feature setting allows an application to disable or configure and
//! enable the ULPI features in the USB library. If this feature is not set,
//! the default behavior is to not support ULPI operation. The \e pvFeature is
//! a pointer to an 32-bit value that holds the USB ULPI configuration. The
//! following are the valid settings for this feature:
//!
//! - USBLIB_FEATURE_ULPI_NONE disables all ULPI support.
//! - USBLIB_FEATURE_ULPI_HS enable ULPI with high speed support.
//! - USBLIB_FEATURE_ULPI_FS enable ULPI with full speed support.
//
//*****************************************************************************
#define USBLIB_FEATURE_USBULPI 0x00000004
//*****************************************************************************
//
// The defines used with the USBDCDFeatureSet() or USBHCDFeatureSet() calls
// for \b USBLIB_FEATURE_USBULPI feature requests.
//
//*****************************************************************************
#define USBLIB_FEATURE_ULPI_NONE \
0x00000000
#define USBLIB_FEATURE_ULPI_HS 0x00000010
#define USBLIB_FEATURE_ULPI_FS 0x00000020
//*****************************************************************************
//
//! This feature setting enables or disables various power settings in the USB
//! library in either host or device mode depending on if the
//! USBHCDFeatureSet() or USBDCDFeatureSet() is called. The \e pvFeature value
//! is a pointer to a 32-bit value containing the a logical OR of the following
//! values:
//!
//! - \b USBLIB_FEATURE_POWER_BUS - USB device mode is bus powered(default).
//! - \b USBLIB_FEATURE_POWER_SELF - USB device mode is self powered.
//! - \b USBLIB_FEATURE_REMOTE_WAKE - Enable USB remote wake feature.
//
//*****************************************************************************
#define USBLIB_FEATURE_POWER 0x00000005
//*****************************************************************************
//
// The defines used with the USBDCDFeatureSet() or USBHCDFeatureSet() calls
// for \b USBLIB_FEATURE_POWER feature requests.
//
//*****************************************************************************
#define USBLIB_FEATURE_POWER_SELF \
0x00000001
#define USBLIB_FEATURE_POWER_BUS \
0x00000000
#define USBLIB_FEATURE_REMOTE_WAKE \
0x00000002
//*****************************************************************************
//
// The structure used with the USBDCDFeatureSet() or USBHCDFeatureSet() calls
// to set feature enables and resume timing parameter.
//
//*****************************************************************************
typedef struct
{
uint32_t ui32HIRD;
uint32_t ui32Features;
}
tLPMFeature;
//*****************************************************************************
//
//! The structure used by the application to initialize a buffer object that
//! will provide buffered access to either a transmit or receive channel.
//
//*****************************************************************************
typedef struct
{
//
//! This field sets the mode of the buffer. If true, the buffer
//! operates as a transmit buffer and supports calls to USBBufferWrite
//! by the client. If false, the buffer operates as a receive buffer
//! and supports calls to USBBufferRead.
//
bool bTransmitBuffer;
//
//! A pointer to the callback function which will be called to notify
//! the application of all asynchronous events related to the operation
//! of the buffer.
//
tUSBCallback pfnCallback;
//
//! A pointer that the buffer will pass back to the client in the
//! first parameter of all callbacks related to this instance.
//
void *pvCBData;
//
//! The function which should be called to transmit a packet of data
//! in transmit mode or receive a packet in receive mode.
//
tUSBPacketTransfer pfnTransfer;
//
//! The function which should be called to determine if the endpoint is
//! ready to accept a new packet for transmission in transmit mode or
//! to determine the size of the buffer required to read a packet in
//! receive mode.
//
tUSBPacketAvailable pfnAvailable;
//
//! The handle to pass to the low level function pointers
//! provided in the pfnTransfer and pfnAvailable members. For USB device
//! use, this is the psDevice parameter required by the relevant device
//! class driver APIs. For USB host use, this is the pipe identifier
//! returned by USBHCDPipeAlloc.
//
void *pvHandle;
//
//! A pointer to memory to be used as the ring buffer for this
//! instance.
//
uint8_t *pui8Buffer;
//
//! The size, in bytes, of the buffer pointed to by pi8Buffer.
//
uint32_t ui32BufferSize;
//
//! A pointer to USB_BUFFER_WORKSPACE_SIZE bytes of RAM that the buffer
//! object can use for workspace.
//
void *pvWorkspace;
}
tUSBBuffer;
//*****************************************************************************
//
//! The structure used for encapsulating all the items associated with a
//! ring buffer.
//
//*****************************************************************************
typedef struct
{
//
//! The ring buffer size.
//
uint32_t ui32Size;
//
//! The ring buffer write index.
//
volatile uint32_t ui32WriteIndex;
//
//! The ring buffer read index.
//
volatile uint32_t ui32ReadIndex;
//
//! The ring buffer.
//
uint8_t *pui8Buf;
}
tUSBRingBufObject;
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
//*****************************************************************************
//
// USB buffer API function prototypes.
//
//*****************************************************************************
extern const tUSBBuffer *USBBufferInit(const tUSBBuffer *psBuffer);
extern void USBBufferZeroLengthPacketInsert(const tUSBBuffer *psBuffer,
bool bSendZLP);
extern void USBBufferInfoGet(const tUSBBuffer *psBuffer,
tUSBRingBufObject *psRingBuf);
extern void *USBBufferCallbackDataSet(tUSBBuffer *psBuffer, void *pvCBData);
extern uint32_t USBBufferWrite(const tUSBBuffer *psBuffer,
const uint8_t *pui8Data, uint32_t ui32Length);
extern void USBBufferDataWritten(const tUSBBuffer *psBuffer,
uint32_t ui32Length);
extern void USBBufferDataRemoved(const tUSBBuffer *psBuffer,
uint32_t ui32Length);
extern void USBBufferFlush(const tUSBBuffer *psBuffer);
extern uint32_t USBBufferRead(const tUSBBuffer *psBuffer, uint8_t *pui8Data,
uint32_t ui32Length);
extern uint32_t USBBufferDataAvailable(const tUSBBuffer *psBuffer);
extern uint32_t USBBufferSpaceAvailable(const tUSBBuffer *psBuffer);
extern uint32_t USBBufferEventCallback(void *pvCBData, uint32_t ui32Event,
uint32_t ui32MsgValue, void *pvMsgData);
extern bool USBRingBufFull(tUSBRingBufObject *psUSBRingBuf);
extern bool USBRingBufEmpty(tUSBRingBufObject *psUSBRingBuf);
extern void USBRingBufFlush(tUSBRingBufObject *psUSBRingBuf);
extern uint32_t USBRingBufUsed(tUSBRingBufObject *psUSBRingBuf);
extern uint32_t USBRingBufFree(tUSBRingBufObject *psUSBRingBuf);
extern uint32_t USBRingBufContigUsed(tUSBRingBufObject *psUSBRingBuf);
extern uint32_t USBRingBufContigFree(tUSBRingBufObject *psUSBRingBuf);
extern uint32_t USBRingBufSize(tUSBRingBufObject *psUSBRingBuf);
extern uint8_t USBRingBufReadOne(tUSBRingBufObject *psUSBRingBuf);
extern void USBRingBufRead(tUSBRingBufObject *psUSBRingBuf,
uint8_t *pui8Data, uint32_t ui32Length);
extern void USBRingBufWriteOne(tUSBRingBufObject *psUSBRingBuf,
uint8_t ui8Data);
extern void USBRingBufWrite(tUSBRingBufObject *psUSBRingBuf,
const uint8_t *pui8Data, uint32_t ui32Length);
extern void USBRingBufAdvanceWrite(tUSBRingBufObject *psUSBRingBuf,
uint32_t ui32NumBytes);
extern void USBRingBufAdvanceRead(tUSBRingBufObject *psUSBRingBuf,
uint32_t ui32NumBytes);
extern void USBRingBufInit(tUSBRingBufObject *psUSBRingBuf,
uint8_t *pui8Buf, uint32_t ui32Size);
//*****************************************************************************
//
// Mode selection and dual mode interrupt steering functions.
//
//*****************************************************************************
extern void USBStackModeSet(uint32_t ui32Index, tUSBMode iUSBMode,
tUSBModeCallback pfnCallback);
extern void USBDualModeInit(uint32_t ui32Index);
extern void USBDualModeTerm(uint32_t ui32Index);
extern void USBOTGMain(uint32_t ui32MsTicks);
extern void USBOTGPollRate(uint32_t ui32Index, uint32_t ui32PollRate);
extern void USBOTGModeInit(uint32_t ui32Index, uint32_t ui32PollRate,
void *pHostData, uint32_t ui32HostDataSize);
extern void USBOTGModeTerm(uint32_t ui32Index);
extern void USB0OTGModeIntHandler(void);
extern bool USBOTGFeatureSet(uint32_t ui32Index, uint32_t ui32Feature,
void *pvFeature);
extern void USB0DualModeIntHandler(void);
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif // __USBLIB_H__
|