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
208
209
213
214
215
216
217
218
219
220
221
222
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
248
249
250
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
293
294
295
296
300
301
302
303
304
305
306
307
308
309
310
311
312
321
322
324
325
326
327
328
329
330
331
332
333
334
335
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
367
368
369
370
374
375
376
377
378
379
380
381
382
383
384
385
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
412
421
422
428
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
471
472
473
474
475
476
480
484
488
492
496
500
504
508
512
516
523
524
525
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
590
594
598
602
606
610
614
618
622
626
633
634
635
656
657
658
659
660
661
662
663
664
665
666
667
668
669
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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
797
798
799
803
807
808
816
817
818
822
823
824
825
826
827
828
829
830
831
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
913
914
915
916
917
918
919
920
921
922
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1012
1017
1018
1019
1020
1021
1022
1023
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
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
1086
1087
1088
1089
1090
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
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
1156
1157
1158
1159
1160
1162
1163
1164
1165
1166
1170
1171
1172
1178
1179
1180
1181
1182
1183
1184
1185
1186
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1215
1216
1217
1218
1219
1220
1225
1226
1227
1228
1229
1230
1231
1232
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1254
1255
1256
1257
1262
1263
1264
1265
1266
1267
1268
1269
1270
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
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
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
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
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
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
1467
1468
1481
1482
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1507
1508
1509
1513
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1530
1531
1532
1537
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1562
1563
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
1600
1601
1602
1603
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1621
1622
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1639
1640
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
1678
1679
1680
1681
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1699
1700
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1717
1718
1720
1721
1722
1723
1724
1725
1726
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1751
1752
1753
1754
1755
1761
1767
1773
1779
1780
1781
1782
1786
1787
1789
1790
1791
1792
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1807
1808
1809
1810
1815
1816
1817
1818
1819
1821
1822
1824
1825
1826
1827
1828
1829
1830
1832
1833
1835
1836
1837
1838
1839
1840
1842
1843
1845
1846
1848
1849
1850
1851
1852
1853
1854
1855
1856
1863
1864
1869
1870
1871
1877
1878
1879
1880
1881
1882
1885
1886
1887
1893
1894
1895
1896
1897
1898
1901
1902
1903
1909
1910
1911
1912
1913
1914
1917
1918
1919
1925
1926
1927
1928
1929
1930
1933
1934
1935
1941
1942
1943
1944
1945
1946
1949
1950
1951
1957
1958
1959
1960
1961
1962
1965
1966
1967
1973
1974
1975
1976
1977
1978
1981
1982
1983
1989
1990
1991
1992
1993
1994
1997
1998
1999
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2041
2045
2046
2049
2050
2053
2054
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2085
2086
2087
2088
2089
2090
2091
2092
2093
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2106
2107
2109
2110
2111
2112
2113
2119
2120
2121
2122
2123
2124
2126
2127
2129
2130
2131
2132
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2153
2154
2155
2156
2157
2158
2159
2160
2162
2163
2165
2166
2167
2168
2174
2175
2176
2177
2178
2179
2181
2182
2184
2185
2186
2187
2193
2194
2195
2196
2197
2198
2199
2200
2205
2206
2207
2208
2213
2214
2215
2216
2217
2219
2220
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2298
2299
2300
2301
2302
2303
2304
2305
2307
2308
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2351
2352
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2395
2396
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2422
2423
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2449
2450
2452
2453
2454
2455
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2476
2480
2481
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2501
2502
2503
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2523
2524
2526
2527
2528
2529
2530
2531
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2560
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2589
2590
2592
2593
2594
2595
2596
2597
2598
2602
2603
2604
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2626
2627
2628
2629
2630
2634
2635
2636
2637
2641
2642
2643
2649
2655
2661
2666
2667
2668
2671
2672
2673
2676
2677
2680
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
/* ... */
#ifdef HAL_IRDA_MODULE_ENABLED
/* ... */
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
void IRDA_InitCallbacksToDefault(IRDA_HandleTypeDef *hirda);
#endif
static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda);
static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda);
static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma);
static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda);
static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda);
/* ... */
Private function prototypes
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
{
if (hirda == NULL)
{
return HAL_ERROR;
}if (hirda == NULL) { ... }
assert_param(IS_IRDA_INSTANCE(hirda->Instance));
assert_param(IS_IRDA_POWERMODE(hirda->Init.IrDAMode));
if (hirda->gState == HAL_IRDA_STATE_RESET)
{
hirda->Lock = HAL_UNLOCKED;
#if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
IRDA_InitCallbacksToDefault(hirda);
if (hirda->MspInitCallback == NULL)
{
hirda->MspInitCallback = HAL_IRDA_MspInit;
}if (hirda->MspInitCallback == NULL) { ... }
hirda->MspInitCallback(hirda);/* ... */
#else
HAL_IRDA_MspInit(hirda);/* ... */
#endif
}if (hirda->gState == HAL_IRDA_STATE_RESET) { ... }
hirda->gState = HAL_IRDA_STATE_BUSY;
__HAL_IRDA_DISABLE(hirda);
IRDA_SetConfig(hirda);
/* ... */
CLEAR_BIT(hirda->Instance->CR2, (USART_CR2_LINEN | USART_CR2_STOP | USART_CR2_CLKEN));
CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
__HAL_IRDA_ENABLE(hirda);
MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.IrDAMode);
SET_BIT(hirda->Instance->CR3, USART_CR3_IREN);
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_READY;
hirda->RxState = HAL_IRDA_STATE_READY;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
{
if (hirda == NULL)
{
return HAL_ERROR;
}if (hirda == NULL) { ... }
assert_param(IS_IRDA_INSTANCE(hirda->Instance));
hirda->gState = HAL_IRDA_STATE_BUSY;
__HAL_IRDA_DISABLE(hirda);
#if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
if (hirda->MspDeInitCallback == NULL)
{
hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;
}if (hirda->MspDeInitCallback == NULL) { ... }
hirda->MspDeInitCallback(hirda);/* ... */
#else
HAL_IRDA_MspDeInit(hirda);
#endif
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_RESET;
hirda->RxState = HAL_IRDA_STATE_RESET;
__HAL_UNLOCK(hirda);
return HAL_OK;
}{ ... }
/* ... */
__weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
/* ... */
__weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* ... */
HAL_StatusTypeDef HAL_IRDA_RegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID, pIRDA_CallbackTypeDef pCallback)
{
HAL_StatusTypeDef status = HAL_OK;
if (pCallback == NULL)
{
hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
return HAL_ERROR;
}if (pCallback == NULL) { ... }
if (hirda->gState == HAL_IRDA_STATE_READY)
{
switch (CallbackID)
{
case HAL_IRDA_TX_HALFCOMPLETE_CB_ID :
hirda->TxHalfCpltCallback = pCallback;
break;
case HAL_IRDA_TX_HALFCOMPLETE_CB_ID :
case HAL_IRDA_TX_COMPLETE_CB_ID :
hirda->TxCpltCallback = pCallback;
break;
case HAL_IRDA_TX_COMPLETE_CB_ID :
case HAL_IRDA_RX_HALFCOMPLETE_CB_ID :
hirda->RxHalfCpltCallback = pCallback;
break;
case HAL_IRDA_RX_HALFCOMPLETE_CB_ID :
case HAL_IRDA_RX_COMPLETE_CB_ID :
hirda->RxCpltCallback = pCallback;
break;
case HAL_IRDA_RX_COMPLETE_CB_ID :
case HAL_IRDA_ERROR_CB_ID :
hirda->ErrorCallback = pCallback;
break;
case HAL_IRDA_ERROR_CB_ID :
case HAL_IRDA_ABORT_COMPLETE_CB_ID :
hirda->AbortCpltCallback = pCallback;
break;
case HAL_IRDA_ABORT_COMPLETE_CB_ID :
case HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID :
hirda->AbortTransmitCpltCallback = pCallback;
break;
case HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID :
case HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID :
hirda->AbortReceiveCpltCallback = pCallback;
break;
case HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID :
case HAL_IRDA_MSPINIT_CB_ID :
hirda->MspInitCallback = pCallback;
break;
case HAL_IRDA_MSPINIT_CB_ID :
case HAL_IRDA_MSPDEINIT_CB_ID :
hirda->MspDeInitCallback = pCallback;
break;
case HAL_IRDA_MSPDEINIT_CB_ID :
default :
hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (hirda->gState == HAL_IRDA_STATE_READY) { ... }
else if (hirda->gState == HAL_IRDA_STATE_RESET)
{
switch (CallbackID)
{
case HAL_IRDA_MSPINIT_CB_ID :
hirda->MspInitCallback = pCallback;
break;
case HAL_IRDA_MSPINIT_CB_ID :
case HAL_IRDA_MSPDEINIT_CB_ID :
hirda->MspDeInitCallback = pCallback;
break;
case HAL_IRDA_MSPDEINIT_CB_ID :
default :
hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (hirda->gState == HAL_IRDA_STATE_RESET) { ... }
else
{
hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
return status;
}HAL_IRDA_RegisterCallback (IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID, pIRDA_CallbackTypeDef pCallback) { ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_UnRegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID)
{
HAL_StatusTypeDef status = HAL_OK;
if (HAL_IRDA_STATE_READY == hirda->gState)
{
switch (CallbackID)
{
case HAL_IRDA_TX_HALFCOMPLETE_CB_ID :
hirda->TxHalfCpltCallback = HAL_IRDA_TxHalfCpltCallback;
break;
case HAL_IRDA_TX_HALFCOMPLETE_CB_ID :
case HAL_IRDA_TX_COMPLETE_CB_ID :
hirda->TxCpltCallback = HAL_IRDA_TxCpltCallback;
break;
case HAL_IRDA_TX_COMPLETE_CB_ID :
case HAL_IRDA_RX_HALFCOMPLETE_CB_ID :
hirda->RxHalfCpltCallback = HAL_IRDA_RxHalfCpltCallback;
break;
case HAL_IRDA_RX_HALFCOMPLETE_CB_ID :
case HAL_IRDA_RX_COMPLETE_CB_ID :
hirda->RxCpltCallback = HAL_IRDA_RxCpltCallback;
break;
case HAL_IRDA_RX_COMPLETE_CB_ID :
case HAL_IRDA_ERROR_CB_ID :
hirda->ErrorCallback = HAL_IRDA_ErrorCallback;
break;
case HAL_IRDA_ERROR_CB_ID :
case HAL_IRDA_ABORT_COMPLETE_CB_ID :
hirda->AbortCpltCallback = HAL_IRDA_AbortCpltCallback;
break;
case HAL_IRDA_ABORT_COMPLETE_CB_ID :
case HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID :
hirda->AbortTransmitCpltCallback = HAL_IRDA_AbortTransmitCpltCallback;
break;
case HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID :
case HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID :
hirda->AbortReceiveCpltCallback = HAL_IRDA_AbortReceiveCpltCallback;
break;
case HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID :
case HAL_IRDA_MSPINIT_CB_ID :
hirda->MspInitCallback = HAL_IRDA_MspInit;
break;
case HAL_IRDA_MSPINIT_CB_ID :
case HAL_IRDA_MSPDEINIT_CB_ID :
hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;
break;
case HAL_IRDA_MSPDEINIT_CB_ID :
default :
hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}if (HAL_IRDA_STATE_READY == hirda->gState) { ... }
else if (HAL_IRDA_STATE_RESET == hirda->gState)
{
switch (CallbackID)
{
case HAL_IRDA_MSPINIT_CB_ID :
hirda->MspInitCallback = HAL_IRDA_MspInit;
break;
case HAL_IRDA_MSPINIT_CB_ID :
case HAL_IRDA_MSPDEINIT_CB_ID :
hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;
break;
case HAL_IRDA_MSPDEINIT_CB_ID :
default :
hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
break;default
}switch (CallbackID) { ... }
}else if (HAL_IRDA_STATE_RESET == hirda->gState) { ... }
else
{
hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
status = HAL_ERROR;
}else { ... }
return status;
}HAL_IRDA_UnRegisterCallback (IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size, uint32_t Timeout)
{
const uint16_t *tmp;
uint32_t tickstart = 0U;
if (hirda->gState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
__HAL_LOCK(hirda);
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_BUSY_TX;
tickstart = HAL_GetTick();
hirda->TxXferSize = Size;
hirda->TxXferCount = Size;
while (hirda->TxXferCount > 0U)
{
hirda->TxXferCount--;
if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
{
if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) { ... }
tmp = (const uint16_t *) pData;
hirda->Instance->DR = (*tmp & (uint16_t)0x01FF);
if (hirda->Init.Parity == IRDA_PARITY_NONE)
{
pData += 2U;
}if (hirda->Init.Parity == IRDA_PARITY_NONE) { ... }
else
{
pData += 1U;
}else { ... }
}if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B) { ... }
else
{
if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK) { ... }
hirda->Instance->DR = (*pData++ & (uint8_t)0xFF);
}else { ... }
}while (hirda->TxXferCount > 0U) { ... }
if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK) { ... }
hirda->gState = HAL_IRDA_STATE_READY;
__HAL_UNLOCK(hirda);
return HAL_OK;
}if (hirda->gState == HAL_IRDA_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
{
uint16_t *tmp;
uint32_t tickstart = 0U;
if (hirda->RxState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
__HAL_LOCK(hirda);
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
tickstart = HAL_GetTick();
hirda->RxXferSize = Size;
hirda->RxXferCount = Size;
while (hirda->RxXferCount > 0U)
{
hirda->RxXferCount--;
if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
{
if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) { ... }
tmp = (uint16_t *) pData ;
if (hirda->Init.Parity == IRDA_PARITY_NONE)
{
*tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
pData += 2U;
}if (hirda->Init.Parity == IRDA_PARITY_NONE) { ... }
else
{
*tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
pData += 1U;
}else { ... }
}if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B) { ... }
else
{
if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
{
return HAL_TIMEOUT;
}if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK) { ... }
if (hirda->Init.Parity == IRDA_PARITY_NONE)
{
*pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
}if (hirda->Init.Parity == IRDA_PARITY_NONE) { ... }
else
{
*pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
}else { ... }
}else { ... }
}while (hirda->RxXferCount > 0U) { ... }
hirda->RxState = HAL_IRDA_STATE_READY;
__HAL_UNLOCK(hirda);
return HAL_OK;
}if (hirda->RxState == HAL_IRDA_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
{
if (hirda->gState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
__HAL_LOCK(hirda);
hirda->pTxBuffPtr = pData;
hirda->TxXferSize = Size;
hirda->TxXferCount = Size;
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_BUSY_TX;
__HAL_UNLOCK(hirda);
SET_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
return HAL_OK;
}if (hirda->gState == HAL_IRDA_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
{
if (hirda->RxState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
__HAL_LOCK(hirda);
hirda->pRxBuffPtr = pData;
hirda->RxXferSize = Size;
hirda->RxXferCount = Size;
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
__HAL_UNLOCK(hirda);
if (hirda->Init.Parity != IRDA_PARITY_NONE)
{
SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
}if (hirda->Init.Parity != IRDA_PARITY_NONE) { ... }
else
{
SET_BIT(hirda->Instance->CR1, USART_CR1_RXNEIE);
}else { ... }
SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
return HAL_OK;
}if (hirda->RxState == HAL_IRDA_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
{
const uint32_t *tmp;
if (hirda->gState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
__HAL_LOCK(hirda);
hirda->pTxBuffPtr = pData;
hirda->TxXferSize = Size;
hirda->TxXferCount = Size;
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_BUSY_TX;
hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
hirda->hdmatx->XferAbortCallback = NULL;
tmp = (const uint32_t *)&pData;
HAL_DMA_Start_IT(hirda->hdmatx, *(const uint32_t *)tmp, (uint32_t)&hirda->Instance->DR, Size);
__HAL_IRDA_CLEAR_FLAG(hirda, IRDA_FLAG_TC);
__HAL_UNLOCK(hirda);
/* ... */
SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
return HAL_OK;
}if (hirda->gState == HAL_IRDA_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
{
uint32_t *tmp;
if (hirda->RxState == HAL_IRDA_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}if ((pData == NULL) || (Size == 0U)) { ... }
__HAL_LOCK(hirda);
hirda->pRxBuffPtr = pData;
hirda->RxXferSize = Size;
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
hirda->hdmarx->XferAbortCallback = NULL;
tmp = (uint32_t *)&pData;
HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->DR, *(uint32_t *)tmp, Size);
__HAL_IRDA_CLEAR_OREFLAG(hirda);
__HAL_UNLOCK(hirda);
if (hirda->Init.Parity != IRDA_PARITY_NONE)
{
SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
}if (hirda->Init.Parity != IRDA_PARITY_NONE) { ... }
SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
/* ... */
SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
return HAL_OK;
}if (hirda->RxState == HAL_IRDA_STATE_READY) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
{
uint32_t dmarequest = 0x00U;
__HAL_LOCK(hirda);
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
}if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest) { ... }
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
{
CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
}if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest) { ... }
__HAL_UNLOCK(hirda);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
{
__HAL_LOCK(hirda);
if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
{
SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
}if (hirda->gState == HAL_IRDA_STATE_BUSY_TX) { ... }
if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
{
__HAL_IRDA_CLEAR_OREFLAG(hirda);
if (hirda->Init.Parity != IRDA_PARITY_NONE)
{
SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
}if (hirda->Init.Parity != IRDA_PARITY_NONE) { ... }
SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
}if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX) { ... }
__HAL_UNLOCK(hirda);
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
{
uint32_t dmarequest = 0x00U;
/* ... */
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
if (hirda->hdmatx != NULL)
{
HAL_DMA_Abort(hirda->hdmatx);
}if (hirda->hdmatx != NULL) { ... }
IRDA_EndTxTransfer(hirda);
}if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest) { ... }
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
if (hirda->hdmarx != NULL)
{
HAL_DMA_Abort(hirda->hdmarx);
}if (hirda->hdmarx != NULL) { ... }
IRDA_EndRxTransfer(hirda);
}if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest) { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef *hirda)
{
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
if (hirda->hdmatx != NULL)
{
/* ... */
hirda->hdmatx->XferAbortCallback = NULL;
HAL_DMA_Abort(hirda->hdmatx);
}if (hirda->hdmatx != NULL) { ... }
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT)) { ... }
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
if (hirda->hdmarx != NULL)
{
/* ... */
hirda->hdmarx->XferAbortCallback = NULL;
HAL_DMA_Abort(hirda->hdmarx);
}if (hirda->hdmarx != NULL) { ... }
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR)) { ... }
hirda->TxXferCount = 0x00U;
hirda->RxXferCount = 0x00U;
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->RxState = HAL_IRDA_STATE_READY;
hirda->gState = HAL_IRDA_STATE_READY;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef *hirda)
{
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
if (hirda->hdmatx != NULL)
{
/* ... */
hirda->hdmatx->XferAbortCallback = NULL;
HAL_DMA_Abort(hirda->hdmatx);
}if (hirda->hdmatx != NULL) { ... }
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT)) { ... }
hirda->TxXferCount = 0x00U;
hirda->gState = HAL_IRDA_STATE_READY;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef *hirda)
{
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
if (hirda->hdmarx != NULL)
{
/* ... */
hirda->hdmarx->XferAbortCallback = NULL;
HAL_DMA_Abort(hirda->hdmarx);
}if (hirda->hdmarx != NULL) { ... }
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR)) { ... }
hirda->RxXferCount = 0x00U;
hirda->RxState = HAL_IRDA_STATE_READY;
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda)
{
uint32_t AbortCplt = 0x01U;
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
/* ... */
if (hirda->hdmatx != NULL)
{
/* ... */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
hirda->hdmatx->XferAbortCallback = IRDA_DMATxAbortCallback;
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT)) { ... }
else
{
hirda->hdmatx->XferAbortCallback = NULL;
}else { ... }
}if (hirda->hdmatx != NULL) { ... }
if (hirda->hdmarx != NULL)
{
/* ... */
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
hirda->hdmarx->XferAbortCallback = IRDA_DMARxAbortCallback;
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR)) { ... }
else
{
hirda->hdmarx->XferAbortCallback = NULL;
}else { ... }
}if (hirda->hdmarx != NULL) { ... }
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
if (hirda->hdmatx != NULL)
{
/* ... */
if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
{
hirda->hdmatx->XferAbortCallback = NULL;
}if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK) { ... }
else
{
AbortCplt = 0x00U;
}else { ... }
}if (hirda->hdmatx != NULL) { ... }
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT)) { ... }
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
if (hirda->hdmarx != NULL)
{
/* ... */
if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
{
hirda->hdmarx->XferAbortCallback = NULL;
AbortCplt = 0x01U;
}if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK) { ... }
else
{
AbortCplt = 0x00U;
}else { ... }
}if (hirda->hdmarx != NULL) { ... }
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR)) { ... }
if (AbortCplt == 0x01U)
{
hirda->TxXferCount = 0x00U;
hirda->RxXferCount = 0x00U;
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_READY;
hirda->RxState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->AbortCpltCallback(hirda);/* ... */
#else
HAL_IRDA_AbortCpltCallback(hirda);/* ... */
#endif
}if (AbortCplt == 0x01U) { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef *hirda)
{
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
if (hirda->hdmatx != NULL)
{
/* ... */
hirda->hdmatx->XferAbortCallback = IRDA_DMATxOnlyAbortCallback;
if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
{
hirda->hdmatx->XferAbortCallback(hirda->hdmatx);
}if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK) { ... }
}if (hirda->hdmatx != NULL) { ... }
else
{
hirda->TxXferCount = 0x00U;
hirda->gState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->AbortTransmitCpltCallback(hirda);/* ... */
#else
HAL_IRDA_AbortTransmitCpltCallback(hirda);/* ... */
#endif
}else { ... }
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT)) { ... }
else
{
hirda->TxXferCount = 0x00U;
hirda->gState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->AbortTransmitCpltCallback(hirda);/* ... */
#else
HAL_IRDA_AbortTransmitCpltCallback(hirda);/* ... */
#endif
}else { ... }
return HAL_OK;
}{ ... }
/* ... */
HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef *hirda)
{
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
if (hirda->hdmarx != NULL)
{
/* ... */
hirda->hdmarx->XferAbortCallback = IRDA_DMARxOnlyAbortCallback;
if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
{
hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
}if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK) { ... }
}if (hirda->hdmarx != NULL) { ... }
else
{
hirda->RxXferCount = 0x00U;
hirda->RxState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->AbortReceiveCpltCallback(hirda);/* ... */
#else
HAL_IRDA_AbortReceiveCpltCallback(hirda);/* ... */
#endif
}else { ... }
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR)) { ... }
else
{
hirda->RxXferCount = 0x00U;
hirda->RxState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->AbortReceiveCpltCallback(hirda);/* ... */
#else
HAL_IRDA_AbortReceiveCpltCallback(hirda);/* ... */
#endif
}else { ... }
return HAL_OK;
}{ ... }
/* ... */
void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
{
uint32_t isrflags = READ_REG(hirda->Instance->SR);
uint32_t cr1its = READ_REG(hirda->Instance->CR1);
uint32_t cr3its = READ_REG(hirda->Instance->CR3);
uint32_t errorflags = 0x00U;
uint32_t dmarequest = 0x00U;
errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
if (errorflags == RESET)
{
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
{
IRDA_Receive_IT(hirda);
return;
}if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) { ... }
}if (errorflags == RESET) { ... }
if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
{
if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
{
hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
}if (((isrflags & USART_SR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET)) { ... }
IRDA parity error interrupt occurred
if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
{
hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
}if (((isrflags & USART_SR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) { ... }
IRDA noise error interrupt occurred
if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
{
hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
}if (((isrflags & USART_SR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) { ... }
IRDA frame error interrupt occurred
if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET)))
{
hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
}if (((isrflags & USART_SR_ORE) != RESET) && (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET))) { ... }
IRDA Over-Run interrupt occurred
if (hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
{
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
{
IRDA_Receive_IT(hirda);
}if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) { ... }
/* ... */
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
if (((hirda->ErrorCode & HAL_IRDA_ERROR_ORE) != RESET) || dmarequest)
{
/* ... */
IRDA_EndRxTransfer(hirda);
if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
{
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
if (hirda->hdmarx != NULL)
{
/* ... */
hirda->hdmarx->XferAbortCallback = IRDA_DMAAbortOnError;
if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
{
hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
}if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK) { ... }
}if (hirda->hdmarx != NULL) { ... }
else
{
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->ErrorCallback(hirda);/* ... */
#else
HAL_IRDA_ErrorCallback(hirda);/* ... */
#endif
}else { ... }
}if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR)) { ... }
else
{
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->ErrorCallback(hirda);/* ... */
#else
HAL_IRDA_ErrorCallback(hirda);/* ... */
#endif
}else { ... }
}if (((hirda->ErrorCode & HAL_IRDA_ERROR_ORE) != RESET) || dmarequest) { ... }
else
{
/* ... */
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->ErrorCallback(hirda);/* ... */
#else
HAL_IRDA_ErrorCallback(hirda);/* ... */
#endif
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
}else { ... }
}if (hirda->ErrorCode != HAL_IRDA_ERROR_NONE) { ... }
return;
}if ((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET))) { ... }
if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
{
IRDA_Transmit_IT(hirda);
return;
}if (((isrflags & USART_SR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) { ... }
IRDA in mode Transmitter
if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
{
IRDA_EndTransmit_IT(hirda);
return;
}if (((isrflags & USART_SR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET)) { ... }
}{ ... }
/* ... */
__weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
/* ... */
__weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
/* ... */
__weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
/* ... */
__weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
/* ... */
__weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
/* ... */
__weak void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
/* ... */
__weak void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
/* ... */
__weak void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef *hirda)
{
UNUSED(hirda);
/* ... */
}{ ... }
/* ... */
/* ... */
/* ... */
HAL_IRDA_StateTypeDef HAL_IRDA_GetState(const IRDA_HandleTypeDef *hirda)
{
uint32_t temp1 = 0x00U, temp2 = 0x00U;
temp1 = hirda->gState;
temp2 = hirda->RxState;
return (HAL_IRDA_StateTypeDef)(temp1 | temp2);
}{ ... }
/* ... */
uint32_t HAL_IRDA_GetError(const IRDA_HandleTypeDef *hirda)
{
return hirda->ErrorCode;
}{ ... }
/* ... */
/* ... */
/* ... */
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
/* ... */
void IRDA_InitCallbacksToDefault(IRDA_HandleTypeDef *hirda)
{
hirda->TxHalfCpltCallback = HAL_IRDA_TxHalfCpltCallback;
hirda->TxCpltCallback = HAL_IRDA_TxCpltCallback;
hirda->RxHalfCpltCallback = HAL_IRDA_RxHalfCpltCallback;
hirda->RxCpltCallback = HAL_IRDA_RxCpltCallback;
hirda->ErrorCallback = HAL_IRDA_ErrorCallback;
hirda->AbortCpltCallback = HAL_IRDA_AbortCpltCallback;
hirda->AbortTransmitCpltCallback = HAL_IRDA_AbortTransmitCpltCallback;
hirda->AbortReceiveCpltCallback = HAL_IRDA_AbortReceiveCpltCallback;
}IRDA_InitCallbacksToDefault (IRDA_HandleTypeDef *hirda) { ... }
/* ... */#endif
/* ... */
static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
{
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
{
hirda->TxXferCount = 0U;
/* ... */
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
}if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U) { ... }
else
{
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->TxCpltCallback(hirda);/* ... */
#else
HAL_IRDA_TxCpltCallback(hirda);/* ... */
#endif
}else { ... }
}{ ... }
/* ... */
static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
{
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->TxHalfCpltCallback(hirda);/* ... */
#else
HAL_IRDA_TxHalfCpltCallback(hirda);/* ... */
#endif
}{ ... }
/* ... */
static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
{
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
{
hirda->RxXferCount = 0U;
CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
/* ... */
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
hirda->RxState = HAL_IRDA_STATE_READY;
}if ((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U) { ... }
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->RxCpltCallback(hirda);/* ... */
#else
HAL_IRDA_RxCpltCallback(hirda);/* ... */
#endif
}{ ... }
/* ... */
static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
{
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->RxHalfCpltCallback(hirda);/* ... */
#else
HAL_IRDA_RxHalfCpltCallback(hirda);/* ... */
#endif
}{ ... }
/* ... */
static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
{
uint32_t dmarequest = 0x00U;
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT);
if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest)
{
hirda->TxXferCount = 0U;
IRDA_EndTxTransfer(hirda);
}if ((hirda->gState == HAL_IRDA_STATE_BUSY_TX) && dmarequest) { ... }
dmarequest = HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR);
if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest)
{
hirda->RxXferCount = 0U;
IRDA_EndRxTransfer(hirda);
}if ((hirda->RxState == HAL_IRDA_STATE_BUSY_RX) && dmarequest) { ... }
hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->ErrorCallback(hirda);/* ... */
#else
HAL_IRDA_ErrorCallback(hirda);/* ... */
#endif
}{ ... }
/* ... */
static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
{
while ((__HAL_IRDA_GET_FLAG(hirda, Flag) ? SET : RESET) == Status)
{
if (Timeout != HAL_MAX_DELAY)
{
if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout))
{
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
hirda->gState = HAL_IRDA_STATE_READY;
hirda->RxState = HAL_IRDA_STATE_READY;
__HAL_UNLOCK(hirda);
return HAL_TIMEOUT;
}if ((Timeout == 0U) || ((HAL_GetTick() - Tickstart) > Timeout)) { ... }
}if (Timeout != HAL_MAX_DELAY) { ... }
}while ((__HAL_IRDA_GET_FLAG(hirda, Flag) ? SET : RESET) == Status) { ... }
return HAL_OK;
}{ ... }
/* ... */
static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda)
{
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
hirda->gState = HAL_IRDA_STATE_READY;
}{ ... }
/* ... */
static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda)
{
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
hirda->RxState = HAL_IRDA_STATE_READY;
}{ ... }
/* ... */
static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma)
{
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
hirda->RxXferCount = 0x00U;
hirda->TxXferCount = 0x00U;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->ErrorCallback(hirda);/* ... */
#else
HAL_IRDA_ErrorCallback(hirda);/* ... */
#endif
}{ ... }
/* ... */
static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
{
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
hirda->hdmatx->XferAbortCallback = NULL;
if (hirda->hdmarx != NULL)
{
if (hirda->hdmarx->XferAbortCallback != NULL)
{
return;
}if (hirda->hdmarx->XferAbortCallback != NULL) { ... }
}if (hirda->hdmarx != NULL) { ... }
hirda->TxXferCount = 0x00U;
hirda->RxXferCount = 0x00U;
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_READY;
hirda->RxState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->AbortCpltCallback(hirda);/* ... */
#else
HAL_IRDA_AbortCpltCallback(hirda);/* ... */
#endif
}{ ... }
/* ... */
static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
{
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
hirda->hdmarx->XferAbortCallback = NULL;
if (hirda->hdmatx != NULL)
{
if (hirda->hdmatx->XferAbortCallback != NULL)
{
return;
}if (hirda->hdmatx->XferAbortCallback != NULL) { ... }
}if (hirda->hdmatx != NULL) { ... }
hirda->TxXferCount = 0x00U;
hirda->RxXferCount = 0x00U;
hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
hirda->gState = HAL_IRDA_STATE_READY;
hirda->RxState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->AbortCpltCallback(hirda);/* ... */
#else
HAL_IRDA_AbortCpltCallback(hirda);/* ... */
#endif
}{ ... }
/* ... */
static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
{
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
hirda->TxXferCount = 0x00U;
hirda->gState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->AbortTransmitCpltCallback(hirda);/* ... */
#else
HAL_IRDA_AbortTransmitCpltCallback(hirda);/* ... */
#endif
}{ ... }
/* ... */
static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
{
IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
hirda->RxXferCount = 0x00U;
hirda->RxState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->AbortReceiveCpltCallback(hirda);/* ... */
#else
HAL_IRDA_AbortReceiveCpltCallback(hirda);/* ... */
#endif
}{ ... }
/* ... */
static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
{
const uint16_t *tmp;
if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
{
if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
{
tmp = (const uint16_t *) hirda->pTxBuffPtr;
hirda->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
if (hirda->Init.Parity == IRDA_PARITY_NONE)
{
hirda->pTxBuffPtr += 2U;
}if (hirda->Init.Parity == IRDA_PARITY_NONE) { ... }
else
{
hirda->pTxBuffPtr += 1U;
}else { ... }
}if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B) { ... }
else
{
hirda->Instance->DR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0x00FF);
}else { ... }
if (--hirda->TxXferCount == 0U)
{
CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TXEIE);
SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
}if (--hirda->TxXferCount == 0U) { ... }
return HAL_OK;
}if (hirda->gState == HAL_IRDA_STATE_BUSY_TX) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda)
{
CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
hirda->gState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->TxCpltCallback(hirda);/* ... */
#else
HAL_IRDA_TxCpltCallback(hirda);/* ... */
#endif
return HAL_OK;
}{ ... }
/* ... */
static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
{
uint16_t *tmp;
uint16_t uhdata;
if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
{
uhdata = (uint16_t) READ_REG(hirda->Instance->DR);
if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
{
tmp = (uint16_t *) hirda->pRxBuffPtr;
if (hirda->Init.Parity == IRDA_PARITY_NONE)
{
*tmp = (uint16_t)(uhdata & (uint16_t)0x01FF);
hirda->pRxBuffPtr += 2U;
}if (hirda->Init.Parity == IRDA_PARITY_NONE) { ... }
else
{
*tmp = (uint16_t)(uhdata & (uint16_t)0x00FF);
hirda->pRxBuffPtr += 1U;
}else { ... }
}if (hirda->Init.WordLength == IRDA_WORDLENGTH_9B) { ... }
else
{
if (hirda->Init.Parity == IRDA_PARITY_NONE)
{
*hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x00FF);
}if (hirda->Init.Parity == IRDA_PARITY_NONE) { ... }
else
{
*hirda->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)0x007F);
}else { ... }
}else { ... }
if (--hirda->RxXferCount == 0U)
{
CLEAR_BIT(hirda->Instance->CR1, USART_CR1_RXNEIE);
CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
hirda->RxState = HAL_IRDA_STATE_READY;
#if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
hirda->RxCpltCallback(hirda);/* ... */
#else
HAL_IRDA_RxCpltCallback(hirda);/* ... */
#endif
return HAL_OK;
}if (--hirda->RxXferCount == 0U) { ... }
return HAL_OK;
}if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX) { ... }
else
{
return HAL_BUSY;
}else { ... }
}{ ... }
/* ... */
static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
{
uint32_t pclk;
assert_param(IS_IRDA_INSTANCE(hirda->Instance));
assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
assert_param(IS_IRDA_MODE(hirda->Init.Mode));
assert_param(IS_IRDA_POWERMODE(hirda->Init.IrDAMode));
CLEAR_BIT(hirda->Instance->CR2, USART_CR2_STOP);
-------------------------- USART CR2 Configuration
CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE));
/* ... */
SET_BIT(hirda->Instance->CR1, (hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode));
-------------------------- USART CR1 Configuration
CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE));
-------------------------- USART CR3 Configuration
#if defined(USART6) && defined(UART9) && defined(UART10)
if ((hirda->Instance == USART1) || (hirda->Instance == USART6) || (hirda->Instance == UART9) || (hirda->Instance == UART10))
{
pclk = HAL_RCC_GetPCLK2Freq();
SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
}if ((hirda->Instance == USART1) || (hirda->Instance == USART6) || (hirda->Instance == UART9) || (hirda->Instance == UART10)) { ... }
/* ... */#elif defined(USART6)
if((hirda->Instance == USART1) || (hirda->Instance == USART6))
{
pclk = HAL_RCC_GetPCLK2Freq();
SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
}if ((hirda->Instance == USART1) || (hirda->Instance == USART6)) { ... }
/* ... */#else
if(hirda->Instance == USART1)
{
pclk = HAL_RCC_GetPCLK2Freq();
SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
}if (hirda->Instance == USART1) { ... }
/* ... */#endif
else
{
pclk = HAL_RCC_GetPCLK1Freq();
SET_BIT(hirda->Instance->BRR, IRDA_BRR(pclk, hirda->Init.BaudRate));
}else { ... }
}{ ... }
/* ... */
/* ... */
#endif
/* ... */
/* ... */