Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "mfxstm32l152.h"
Private typedef
Private define
#define MFXSTM32L152_MAX_INSTANCE
Private macro
Private variables
mfxstm32l152_ts_drv
mfxstm32l152_io_drv
mfxstm32l152_idd_drv
mfxstm32l152
Private function prototypes
Private functions
mfxstm32l152_Init(uint16_t)
mfxstm32l152_DeInit(uint16_t)
mfxstm32l152_Reset(uint16_t)
mfxstm32l152_LowPower(uint16_t)
mfxstm32l152_WakeUp(uint16_t)
mfxstm32l152_ReadID(uint16_t)
mfxstm32l152_ReadFwVersion(uint16_t)
mfxstm32l152_EnableITSource(uint16_t, uint8_t)
mfxstm32l152_DisableITSource(uint16_t, uint8_t)
mfxstm32l152_GlobalITStatus(uint16_t, uint8_t)
mfxstm32l152_ClearGlobalIT(uint16_t, uint8_t)
mfxstm32l152_SetIrqOutPinPolarity(uint16_t, uint8_t)
mfxstm32l152_SetIrqOutPinType(uint16_t, uint8_t)
----------------------- GPIO
mfxstm32l152_IO_Start(uint16_t, uint32_t)
mfxstm32l152_IO_Config(uint16_t, uint32_t, IO_ModeTypedef)
mfxstm32l152_IO_InitPin(uint16_t, uint32_t, uint8_t)
mfxstm32l152_IO_SetIrqEvtMode(uint16_t, uint32_t, uint8_t)
mfxstm32l152_IO_SetIrqTypeMode(uint16_t, uint32_t, uint8_t)
mfxstm32l152_IO_WritePin(uint16_t, uint32_t, uint8_t)
mfxstm32l152_IO_ReadPin(uint16_t, uint32_t)
mfxstm32l152_IO_EnableIT(uint16_t)
mfxstm32l152_IO_DisableIT(uint16_t)
mfxstm32l152_IO_EnablePinIT(uint16_t, uint32_t)
mfxstm32l152_IO_DisablePinIT(uint16_t, uint32_t)
mfxstm32l152_IO_ITStatus(uint16_t, uint32_t)
mfxstm32l152_IO_ClearIT(uint16_t, uint32_t)
mfxstm32l152_IO_EnableAF(uint16_t)
mfxstm32l152_IO_DisableAF(uint16_t)
--------------------- TOUCH SCREEN
mfxstm32l152_TS_Start(uint16_t)
mfxstm32l152_TS_DetectTouch(uint16_t)
mfxstm32l152_TS_GetXY(uint16_t, uint16_t *, uint16_t *)
mfxstm32l152_TS_EnableIT(uint16_t)
mfxstm32l152_TS_DisableIT(uint16_t)
mfxstm32l152_TS_ITStatus(uint16_t)
mfxstm32l152_TS_ClearIT(uint16_t)
--------------------- IDD MEASUREMENT
mfxstm32l152_IDD_Start(uint16_t)
mfxstm32l152_IDD_Config(uint16_t, IDD_ConfigTypeDef)
mfxstm32l152_IDD_ConfigShuntNbLimit(uint16_t, uint8_t)
mfxstm32l152_IDD_GetValue(uint16_t, uint32_t *)
mfxstm32l152_IDD_GetShuntUsed(uint16_t)
mfxstm32l152_IDD_EnableIT(uint16_t)
mfxstm32l152_IDD_ClearIT(uint16_t)
mfxstm32l152_IDD_GetITStatus(uint16_t)
mfxstm32l152_IDD_DisableIT(uint16_t)
--------------------- ERROR MANAGEMENT
mfxstm32l152_Error_ReadSrc(uint16_t)
mfxstm32l152_Error_ReadMsg(uint16_t)
mfxstm32l152_Error_EnableIT(uint16_t)
mfxstm32l152_Error_ClearIT(uint16_t)
mfxstm32l152_Error_GetITStatus(uint16_t)
mfxstm32l152_Error_DisableIT(uint16_t)
mfxstm32l152_ReadReg(uint16_t, uint8_t)
mfxstm32l152_WriteReg(uint16_t, uint8_t, uint8_t)
mfxstm32l152_GetInstance(uint16_t)
mfxstm32l152_ReleaseInstance(uint16_t)
mfxstm32l152_reg24_setPinValue(uint16_t, uint8_t, uint32_t, uint8_t)
Files
loading...
SourceVuSTM32 Libraries and Samplesmfxstm32l152mfxstm32l152.c
 
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file mfxstm32l152.c * @author MCD Application Team * @brief This file provides a set of functions needed to manage the MFXSTM32L152 * IO Expander devices. ****************************************************************************** * @attention * * Copyright (c) 2015 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "mfxstm32l152.h" /** @addtogroup BSP * @{ *//* ... */ /** @addtogroup Component * @{ *//* ... */ /** @defgroup MFXSTM32L152 * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /** @defgroup MFXSTM32L152_Private_Types_Definitions * @{ *//* ... */ Private typedef /* Private define ------------------------------------------------------------*/ /** @defgroup MFXSTM32L152_Private_Defines * @{ *//* ... */ #define MFXSTM32L152_MAX_INSTANCE 3 Private define /* Private macro -------------------------------------------------------------*/ /** @defgroup MFXSTM32L152_Private_Macros * @{ *//* ... */ Private macro /* Private variables ---------------------------------------------------------*/ /** @defgroup MFXSTM32L152_Private_Variables * @{ *//* ... */ /* Touch screen driver structure initialization */ TS_DrvTypeDef mfxstm32l152_ts_drv = { mfxstm32l152_Init, mfxstm32l152_ReadID, mfxstm32l152_Reset, mfxstm32l152_TS_Start, mfxstm32l152_TS_DetectTouch, mfxstm32l152_TS_GetXY, mfxstm32l152_TS_EnableIT, mfxstm32l152_TS_ClearIT, mfxstm32l152_TS_ITStatus, mfxstm32l152_TS_DisableIT, ...}; /* IO driver structure initialization */ IO_DrvTypeDef mfxstm32l152_io_drv = { mfxstm32l152_Init, mfxstm32l152_ReadID, mfxstm32l152_Reset, mfxstm32l152_IO_Start, mfxstm32l152_IO_Config, mfxstm32l152_IO_WritePin, mfxstm32l152_IO_ReadPin, mfxstm32l152_IO_EnableIT, mfxstm32l152_IO_DisableIT, mfxstm32l152_IO_ITStatus, mfxstm32l152_IO_ClearIT, ...}; /* IDD driver structure initialization */ IDD_DrvTypeDef mfxstm32l152_idd_drv = { mfxstm32l152_Init, mfxstm32l152_DeInit, mfxstm32l152_ReadID, mfxstm32l152_Reset, mfxstm32l152_LowPower, mfxstm32l152_WakeUp, mfxstm32l152_IDD_Start, mfxstm32l152_IDD_Config, mfxstm32l152_IDD_GetValue, mfxstm32l152_IDD_EnableIT, mfxstm32l152_IDD_ClearIT, mfxstm32l152_IDD_GetITStatus, mfxstm32l152_IDD_DisableIT, mfxstm32l152_Error_EnableIT, mfxstm32l152_Error_ClearIT, mfxstm32l152_Error_GetITStatus, mfxstm32l152_Error_DisableIT, mfxstm32l152_Error_ReadSrc, mfxstm32l152_Error_ReadMsg ...}; /* mfxstm32l152 instances by address */ uint8_t mfxstm32l152[MFXSTM32L152_MAX_INSTANCE] = {0}; /** * @} *//* ... */ Private variables /* Private function prototypes -----------------------------------------------*/ /** @defgroup MFXSTM32L152_Private_Function_Prototypes * @{ *//* ... */ static uint8_t mfxstm32l152_GetInstance(uint16_t DeviceAddr); static uint8_t mfxstm32l152_ReleaseInstance(uint16_t DeviceAddr); static void mfxstm32l152_reg24_setPinValue(uint16_t DeviceAddr, uint8_t RegisterAddr, uint32_t PinPosition, uint8_t PinValue ); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** @defgroup MFXSTM32L152_Private_Functions * @{ *//* ... */ /** * @brief Initialize the mfxstm32l152 and configure the needed hardware resources * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_Init(uint16_t DeviceAddr) { uint8_t instance; uint8_t empty; /* Check if device instance already exists */ instance = mfxstm32l152_GetInstance(DeviceAddr); /* To prevent double initialization */ if(instance == 0xFF) { /* Look for empty instance */ empty = mfxstm32l152_GetInstance(0); if(empty < MFXSTM32L152_MAX_INSTANCE) { /* Register the current device instance */ mfxstm32l152[empty] = DeviceAddr; /* Initialize IO BUS layer */ MFX_IO_Init(); }if (empty < MFXSTM32L152_MAX_INSTANCE) { ... } }if (instance == 0xFF) { ... } mfxstm32l152_SetIrqOutPinPolarity(DeviceAddr, MFXSTM32L152_OUT_PIN_POLARITY_HIGH); mfxstm32l152_SetIrqOutPinType(DeviceAddr, MFXSTM32L152_OUT_PIN_TYPE_PUSHPULL); }{ ... } /** * @brief DeInitialize the mfxstm32l152 and unconfigure the needed hardware resources * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_DeInit(uint16_t DeviceAddr) { uint8_t instance; /* release existing instance */ instance = mfxstm32l152_ReleaseInstance(DeviceAddr); /* De-Init only if instance was previously registered */ if(instance != 0xFF) { /* De-Initialize IO BUS layer */ MFX_IO_DeInit(); }if (instance != 0xFF) { ... } }{ ... } /** * @brief Reset the mfxstm32l152 by Software. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_Reset(uint16_t DeviceAddr) { /* Soft Reset */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL, MFXSTM32L152_SWRST); /* Wait for a delay to ensure registers erasing */ MFX_IO_Delay(10); }{ ... } /** * @brief Put mfxstm32l152 Device in Low Power standby mode * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_LowPower(uint16_t DeviceAddr) { /* Enter standby mode */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL, MFXSTM32L152_STANDBY); /* enable wakeup pin */ MFX_IO_EnableWakeupPin(); }{ ... } /** * @brief WakeUp mfxstm32l152 from standby mode * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_WakeUp(uint16_t DeviceAddr) { uint8_t instance; /* Check if device instance already exists */ instance = mfxstm32l152_GetInstance(DeviceAddr); /* if instance does not exist, first initialize pins*/ if(instance == 0xFF) { /* enable wakeup pin */ MFX_IO_EnableWakeupPin(); }if (instance == 0xFF) { ... } /* toggle wakeup pin */ MFX_IO_Wakeup(); }{ ... } /** * @brief Read the MFXSTM32L152 IO Expander device ID. * @param DeviceAddr: Device address on communication Bus. * @retval The Device ID (two bytes). *//* ... */ uint16_t mfxstm32l152_ReadID(uint16_t DeviceAddr) { uint8_t id; /* Wait for a delay to ensure the state of registers */ MFX_IO_Delay(1); /* Initialize IO BUS layer */ MFX_IO_Init(); id = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_ID); /* Return the device ID value */ return (id); }{ ... } /** * @brief Read the MFXSTM32L152 device firmware version. * @param DeviceAddr: Device address on communication Bus. * @retval The Device FW version (two bytes). *//* ... */ uint16_t mfxstm32l152_ReadFwVersion(uint16_t DeviceAddr) { uint8_t data[2]; MFX_IO_ReadMultiple((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_FW_VERSION_MSB, data, sizeof(data)) ; /* Recompose MFX firmware value */ return ((data[0] << 8) | data[1]); }{ ... } /** * @brief Enable the interrupt mode for the selected IT source * @param DeviceAddr: Device address on communication Bus. * @param Source: The interrupt source to be configured, could be: * @arg MFXSTM32L152_IRQ_GPIO: IO interrupt * @arg MFXSTM32L152_IRQ_IDD : IDD interrupt * @arg MFXSTM32L152_IRQ_ERROR : Error interrupt * @arg MFXSTM32L152_IRQ_TS_DET : Touch Screen Controller Touch Detected interrupt * @arg MFXSTM32L152_IRQ_TS_NE : Touch Screen FIFO Not Empty * @arg MFXSTM32L152_IRQ_TS_TH : Touch Screen FIFO threshold triggered * @arg MFXSTM32L152_IRQ_TS_FULL : Touch Screen FIFO Full * @arg MFXSTM32L152_IRQ_TS_OVF : Touch Screen FIFO Overflow * @retval None *//* ... */ void mfxstm32l152_EnableITSource(uint16_t DeviceAddr, uint8_t Source) { uint8_t tmp = 0; /* Get the current value of the INT_EN register */ tmp = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_SRC_EN); /* Set the interrupts to be Enabled */ tmp |= Source; /* Set the register */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_SRC_EN, tmp); }{ ... } /** * @brief Disable the interrupt mode for the selected IT source * @param DeviceAddr: Device address on communication Bus. * @param Source: The interrupt source to be configured, could be: * @arg MFXSTM32L152_IRQ_GPIO: IO interrupt * @arg MFXSTM32L152_IRQ_IDD : IDD interrupt * @arg MFXSTM32L152_IRQ_ERROR : Error interrupt * @arg MFXSTM32L152_IRQ_TS_DET : Touch Screen Controller Touch Detected interrupt * @arg MFXSTM32L152_IRQ_TS_NE : Touch Screen FIFO Not Empty * @arg MFXSTM32L152_IRQ_TS_TH : Touch Screen FIFO threshold triggered * @arg MFXSTM32L152_IRQ_TS_FULL : Touch Screen FIFO Full * @arg MFXSTM32L152_IRQ_TS_OVF : Touch Screen FIFO Overflow * @retval None *//* ... */ void mfxstm32l152_DisableITSource(uint16_t DeviceAddr, uint8_t Source) { uint8_t tmp = 0; /* Get the current value of the INT_EN register */ tmp = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_SRC_EN); /* Set the interrupts to be Enabled */ tmp &= ~Source; /* Set the register */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_SRC_EN, tmp); }{ ... } /** * @brief Returns the selected Global interrupt source pending bit value * @param DeviceAddr: Device address on communication Bus. * @param Source: the Global interrupt source to be checked, could be: * @arg MFXSTM32L152_IRQ_GPIO: IO interrupt * @arg MFXSTM32L152_IRQ_IDD : IDD interrupt * @arg MFXSTM32L152_IRQ_ERROR : Error interrupt * @arg MFXSTM32L152_IRQ_TS_DET : Touch Screen Controller Touch Detected interrupt * @arg MFXSTM32L152_IRQ_TS_NE : Touch Screen FIFO Not Empty * @arg MFXSTM32L152_IRQ_TS_TH : Touch Screen FIFO threshold triggered * @arg MFXSTM32L152_IRQ_TS_FULL : Touch Screen FIFO Full * @arg MFXSTM32L152_IRQ_TS_OVF : Touch Screen FIFO Overflow * @retval The value of the checked Global interrupt source status. *//* ... */ uint8_t mfxstm32l152_GlobalITStatus(uint16_t DeviceAddr, uint8_t Source) { /* Return the global IT source status (pending or not)*/ return((MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_PENDING) & Source)); }{ ... } /** * @brief Clear the selected Global interrupt pending bit(s) * @param DeviceAddr: Device address on communication Bus. * @param Source: the Global interrupt source to be cleared, could be any combination * of the below values. The acknowledge signal for MFXSTM32L152_GPIOs configured in input * with interrupt is not on this register but in IRQ_GPI_ACK1, IRQ_GPI_ACK2 registers. * @arg MFXSTM32L152_IRQ_IDD : IDD interrupt * @arg MFXSTM32L152_IRQ_ERROR : Error interrupt * @arg MFXSTM32L152_IRQ_TS_DET : Touch Screen Controller Touch Detected interrupt * @arg MFXSTM32L152_IRQ_TS_NE : Touch Screen FIFO Not Empty * @arg MFXSTM32L152_IRQ_TS_TH : Touch Screen FIFO threshold triggered * @arg MFXSTM32L152_IRQ_TS_FULL : Touch Screen FIFO Full * @arg MFXSTM32L152_IRQ_TS_OVF : Touch Screen FIFO Overflow * /\/\ IMPORTANT NOTE /\/\ must not use MFXSTM32L152_IRQ_GPIO as argument, see IRQ_GPI_ACK1 and IRQ_GPI_ACK2 registers * @retval None *//* ... */ void mfxstm32l152_ClearGlobalIT(uint16_t DeviceAddr, uint8_t Source) { /* Write 1 to the bits that have to be cleared */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_ACK, Source); }{ ... } /** * @brief Set the global interrupt Polarity of IRQ_OUT_PIN. * @param DeviceAddr: Device address on communication Bus. * @param Polarity: the IT mode polarity, could be one of the following values: * @arg MFXSTM32L152_OUT_PIN_POLARITY_LOW: Interrupt output line is active Low edge * @arg MFXSTM32L152_OUT_PIN_POLARITY_HIGH: Interrupt line output is active High edge * @retval None *//* ... */ void mfxstm32l152_SetIrqOutPinPolarity(uint16_t DeviceAddr, uint8_t Polarity) { uint8_t tmp = 0; /* Get the current register value */ tmp = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_MFX_IRQ_OUT); /* Mask the polarity bits */ tmp &= ~(uint8_t)0x02; /* Modify the Interrupt Output line configuration */ tmp |= Polarity; /* Set the new register value */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_MFX_IRQ_OUT, tmp); /* Wait for 1 ms for MFX to change IRQ_out pin config, before activate it */ MFX_IO_Delay(1); }{ ... } /** * @brief Set the global interrupt Type of IRQ_OUT_PIN. * @param DeviceAddr: Device address on communication Bus. * @param Type: Interrupt line activity type, could be one of the following values: * @arg MFXSTM32L152_OUT_PIN_TYPE_OPENDRAIN: Open Drain output Interrupt line * @arg MFXSTM32L152_OUT_PIN_TYPE_PUSHPULL: Push Pull output Interrupt line * @retval None *//* ... */ void mfxstm32l152_SetIrqOutPinType(uint16_t DeviceAddr, uint8_t Type) { uint8_t tmp = 0; /* Get the current register value */ tmp = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_MFX_IRQ_OUT); /* Mask the type bits */ tmp &= ~(uint8_t)0x01; /* Modify the Interrupt Output line configuration */ tmp |= Type; /* Set the new register value */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_MFX_IRQ_OUT, tmp); /* Wait for 1 ms for MFX to change IRQ_out pin config, before activate it */ MFX_IO_Delay(1); }{ ... } /* ------------------------------------------------------------------ */Private functions /* ----------------------- GPIO ------------------------------------- */ /* ------------------------------------------------------------------ */ /** * @brief Start the IO functionality used and enable the AF for selected IO pin(s). * @param DeviceAddr: Device address on communication Bus. * @param AF_en: 0 to disable, else enabled. * @retval None *//* ... */ void mfxstm32l152_IO_Start(uint16_t DeviceAddr, uint32_t IO_Pin) { uint8_t mode; /* Get the current register value */ mode = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL); /* Set the IO Functionalities to be Enabled */ mode |= MFXSTM32L152_GPIO_EN; /* Enable ALTERNATE functions */ /* AGPIO[0..3] can be either IDD or GPIO */ /* AGPIO[4..7] can be either TS or GPIO */ /* if IDD or TS are enabled no matter the value this bit GPIO are not available for those pins */ /* however the MFX will waste some cycles to to handle these potential GPIO (pooling, etc) */ /* so if IDD and TS are both active it is better to let ALTERNATE off (0) */ /* if however IDD or TS are not connected then set it on gives more GPIOs availability */ /* remind that AGPIO are less efficient then normal GPIO (They use pooling rather then EXTI */ if (IO_Pin > 0xFFFF) { mode |= MFXSTM32L152_ALTERNATE_GPIO_EN; }if (IO_Pin > 0xFFFF) { ... } else { mode &= ~MFXSTM32L152_ALTERNATE_GPIO_EN; }else { ... } /* Write the new register value */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL, mode); /* Wait for 1 ms for MFX to change IRQ_out pin config, before activate it */ MFX_IO_Delay(1); }{ ... } /** * @brief Configures the IO pin(s) according to IO mode structure value. * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The output pin to be set or reset. This parameter can be one * of the following values: * @arg MFXSTM32L152_GPIO_PIN_x: where x can be from 0 to 23. * @param IO_Mode: The IO pin mode to configure, could be one of the following values: * @arg IO_MODE_INPUT * @arg IO_MODE_OUTPUT * @arg IO_MODE_IT_RISING_EDGE * @arg IO_MODE_IT_FALLING_EDGE * @arg IO_MODE_IT_LOW_LEVEL * @arg IO_MODE_IT_HIGH_LEVEL * @arg IO_MODE_INPUT_PU, * @arg IO_MODE_INPUT_PD, * @arg IO_MODE_OUTPUT_OD_PU, * @arg IO_MODE_OUTPUT_OD_PD, * @arg IO_MODE_OUTPUT_PP_PU, * @arg IO_MODE_OUTPUT_PP_PD, * @arg IO_MODE_IT_RISING_EDGE_PU * @arg IO_MODE_IT_FALLING_EDGE_PU * @arg IO_MODE_IT_LOW_LEVEL_PU * @arg IO_MODE_IT_HIGH_LEVEL_PU * @arg IO_MODE_IT_RISING_EDGE_PD * @arg IO_MODE_IT_FALLING_EDGE_PD * @arg IO_MODE_IT_LOW_LEVEL_PD * @arg IO_MODE_IT_HIGH_LEVEL_PD * @retval None *//* ... */ uint8_t mfxstm32l152_IO_Config(uint16_t DeviceAddr, uint32_t IO_Pin, IO_ModeTypedef IO_Mode) { uint8_t error_code = 0; /* Configure IO pin according to selected IO mode */ switch(IO_Mode) { case IO_MODE_OFF: /* Off or analog mode */ case IO_MODE_ANALOG: /* Off or analog mode */ mfxstm32l152_IO_DisablePinIT(DeviceAddr, IO_Pin); /* first disable IT */ mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITHOUT_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_DOWN); break; case IO_MODE_ANALOG: case IO_MODE_INPUT: /* Input mode */ mfxstm32l152_IO_DisablePinIT(DeviceAddr, IO_Pin); /* first disable IT */ mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITHOUT_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); break; case IO_MODE_INPUT: case IO_MODE_INPUT_PU: /* Input mode */ mfxstm32l152_IO_DisablePinIT(DeviceAddr, IO_Pin); /* first disable IT */ mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); break; case IO_MODE_INPUT_PU: case IO_MODE_INPUT_PD: /* Input mode */ mfxstm32l152_IO_DisablePinIT(DeviceAddr, IO_Pin); /* first disable IT */ mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_DOWN); break; case IO_MODE_INPUT_PD: case IO_MODE_OUTPUT: /* Output mode */ case IO_MODE_OUTPUT_PP_PD: /* Output mode */ mfxstm32l152_IO_DisablePinIT(DeviceAddr, IO_Pin); /* first disable IT */ mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_OUT); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPO_PUSH_PULL); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_DOWN); break; case IO_MODE_OUTPUT_PP_PD: case IO_MODE_OUTPUT_PP_PU: /* Output mode */ mfxstm32l152_IO_DisablePinIT(DeviceAddr, IO_Pin); /* first disable IT */ mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_OUT); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPO_PUSH_PULL); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); break; case IO_MODE_OUTPUT_PP_PU: case IO_MODE_OUTPUT_OD_PD: /* Output mode */ mfxstm32l152_IO_DisablePinIT(DeviceAddr, IO_Pin); /* first disable IT */ mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_OUT); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPO_OPEN_DRAIN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_DOWN); break; case IO_MODE_OUTPUT_OD_PD: case IO_MODE_OUTPUT_OD_PU: /* Output mode */ mfxstm32l152_IO_DisablePinIT(DeviceAddr, IO_Pin); /* first disable IT */ mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_OUT); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPO_OPEN_DRAIN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); break; case IO_MODE_OUTPUT_OD_PU: case IO_MODE_IT_RISING_EDGE: /* Interrupt rising edge mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITHOUT_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_EDGE); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_HLRE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_RISING_EDGE: case IO_MODE_IT_RISING_EDGE_PU: /* Interrupt rising edge mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_EDGE); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_HLRE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_RISING_EDGE_PU: case IO_MODE_IT_RISING_EDGE_PD: /* Interrupt rising edge mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_DOWN); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_EDGE); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_HLRE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_RISING_EDGE_PD: case IO_MODE_IT_FALLING_EDGE: /* Interrupt falling edge mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITHOUT_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_EDGE); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_LLFE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_FALLING_EDGE: case IO_MODE_IT_FALLING_EDGE_PU: /* Interrupt falling edge mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_EDGE); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_LLFE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_FALLING_EDGE_PU: case IO_MODE_IT_FALLING_EDGE_PD: /* Interrupt falling edge mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_DOWN); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_EDGE); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_LLFE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_FALLING_EDGE_PD: case IO_MODE_IT_LOW_LEVEL: /* Low level interrupt mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITHOUT_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_LEVEL); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_LLFE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_LOW_LEVEL: case IO_MODE_IT_LOW_LEVEL_PU: /* Low level interrupt mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_LEVEL); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_LLFE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_LOW_LEVEL_PU: case IO_MODE_IT_LOW_LEVEL_PD: /* Low level interrupt mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_DOWN); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_LEVEL); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_LLFE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_LOW_LEVEL_PD: case IO_MODE_IT_HIGH_LEVEL: /* High level interrupt mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITHOUT_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_LEVEL); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_HLRE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_HIGH_LEVEL: case IO_MODE_IT_HIGH_LEVEL_PU: /* High level interrupt mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_UP); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_LEVEL); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_HLRE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_HIGH_LEVEL_PU: case IO_MODE_IT_HIGH_LEVEL_PD: /* High level interrupt mode */ mfxstm32l152_IO_EnableIT(DeviceAddr); mfxstm32l152_IO_InitPin(DeviceAddr, IO_Pin, MFXSTM32L152_GPIO_DIR_IN); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_TYPE1, IO_Pin, MFXSTM32L152_GPI_WITH_PULL_RESISTOR); mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_PUPD1, IO_Pin, MFXSTM32L152_GPIO_PULL_DOWN); mfxstm32l152_IO_SetIrqEvtMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_EVT_LEVEL); mfxstm32l152_IO_SetIrqTypeMode(DeviceAddr, IO_Pin, MFXSTM32L152_IRQ_GPI_TYPE_HLRE); mfxstm32l152_IO_EnablePinIT(DeviceAddr, IO_Pin); /* last to do: enable IT */ break; case IO_MODE_IT_HIGH_LEVEL_PD: default: error_code = (uint8_t) IO_Mode; break;default }switch (IO_Mode) { ... } return error_code; }{ ... } /** * @brief Initialize the selected IO pin direction. * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The IO pin to be configured. This parameter could be any * combination of the following values: * @arg MFXSTM32L152_GPIO_PIN_x: Where x can be from 0 to 23. * @param Direction: could be MFXSTM32L152_GPIO_DIR_IN or MFXSTM32L152_GPIO_DIR_OUT. * @retval None *//* ... */ void mfxstm32l152_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction) { mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_DIR1, IO_Pin, Direction); }{ ... } /** * @brief Set the global interrupt Type. * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The IO pin to be configured. This parameter could be any * combination of the following values: * @arg MFXSTM32L152_GPIO_PIN_x: Where x can be from 0 to 23. * @param Evt: Interrupt line activity type, could be one of the following values: * @arg MFXSTM32L152_IRQ_GPI_EVT_LEVEL: Interrupt line is active in level model * @arg MFXSTM32L152_IRQ_GPI_EVT_EDGE: Interrupt line is active in edge model * @retval None *//* ... */ void mfxstm32l152_IO_SetIrqEvtMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Evt) { mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_EVT1, IO_Pin, Evt); MFX_IO_Delay(1); }{ ... } /** * @brief Configure the Edge for which a transition is detectable for the * selected pin. * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The IO pin to be configured. This parameter could be any * combination of the following values: * @arg MFXSTM32L152_GPIO_PIN_x: Where x can be from 0 to 23. * @param Evt: Interrupt line activity type, could be one of the following values: * @arg MFXSTM32L152_IRQ_GPI_TYPE_LLFE: Interrupt line is active in Low Level or Falling Edge * @arg MFXSTM32L152_IRQ_GPI_TYPE_HLRE: Interrupt line is active in High Level or Rising Edge * @retval None *//* ... */ void mfxstm32l152_IO_SetIrqTypeMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Type) { mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_TYPE1, IO_Pin, Type); MFX_IO_Delay(1); }{ ... } /** * @brief When GPIO is in output mode, puts the corresponding GPO in High (1) or Low (0) level. * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The output pin to be set or reset. This parameter can be one * of the following values: * @arg MFXSTM32L152_GPIO_PIN_x: where x can be from 0 to 23. * @param PinState: The new IO pin state. * @retval None *//* ... */ void mfxstm32l152_IO_WritePin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t PinState) { /* Apply the bit value to the selected pin */ if (PinState != 0) { /* Set the SET register */ mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPO_SET1, IO_Pin, 1); }if (PinState != 0) { ... } else { /* Set the CLEAR register */ mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_GPO_CLR1, IO_Pin, 1); }else { ... } }{ ... } /** * @brief Return the state of the selected IO pin(s). * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The output pin to be set or reset. This parameter can be one * of the following values: * @arg MFXSTM32L152_GPIO_PIN_x: where x can be from 0 to 23. * @retval IO pin(s) state. *//* ... */ uint32_t mfxstm32l152_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin) { uint32_t tmp1 = 0; uint32_t tmp2 = 0; uint32_t tmp3 = 0; if(IO_Pin & 0x000000FF) { tmp1 = (uint32_t) MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_STATE1); }if (IO_Pin & 0x000000FF) { ... } if(IO_Pin & 0x0000FF00) { tmp2 = (uint32_t) MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_STATE2); }if (IO_Pin & 0x0000FF00) { ... } if(IO_Pin & 0x00FF0000) { tmp3 = (uint32_t) MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_GPIO_STATE3); }if (IO_Pin & 0x00FF0000) { ... } tmp3 = tmp1 + (tmp2 << 8) + (tmp3 << 16); return(tmp3 & IO_Pin); }{ ... } /** * @brief Enable the global IO interrupt source. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_IO_EnableIT(uint16_t DeviceAddr) { MFX_IO_ITConfig(); /* Enable global IO IT source */ mfxstm32l152_EnableITSource(DeviceAddr, MFXSTM32L152_IRQ_GPIO); }{ ... } /** * @brief Disable the global IO interrupt source. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_IO_DisableIT(uint16_t DeviceAddr) { /* Disable global IO IT source */ mfxstm32l152_DisableITSource(DeviceAddr, MFXSTM32L152_IRQ_GPIO); }{ ... } /** * @brief Enable interrupt mode for the selected IO pin(s). * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The IO interrupt to be enabled. This parameter could be any * combination of the following values: * @arg MFXSTM32L152_GPIO_PIN_x: where x can be from 0 to 23. * @retval None *//* ... */ void mfxstm32l152_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin) { mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_SRC1, IO_Pin, 1); }{ ... } /** * @brief Disable interrupt mode for the selected IO pin(s). * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The IO interrupt to be disabled. This parameter could be any * combination of the following values: * @arg MFXSTM32L152_GPIO_PIN_x: where x can be from 0 to 23. * @retval None *//* ... */ void mfxstm32l152_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin) { mfxstm32l152_reg24_setPinValue(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_SRC1, IO_Pin, 0); }{ ... } /** * @brief Check the status of the selected IO interrupt pending bit * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The IO interrupt to be checked could be: * @arg MFXSTM32L152_GPIO_PIN_x Where x can be from 0 to 23. * @retval Status of the checked IO pin(s). *//* ... */ uint32_t mfxstm32l152_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin) { /* Get the Interrupt status */ uint8_t tmp1 = 0; uint16_t tmp2 = 0; uint32_t tmp3 = 0; if(IO_Pin & 0xFF) { tmp1 = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_PENDING1); }if (IO_Pin & 0xFF) { ... } if(IO_Pin & 0xFFFF00) { tmp2 = (uint16_t) MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_PENDING2); }if (IO_Pin & 0xFFFF00) { ... } if(IO_Pin & 0xFFFF0000) { tmp3 = (uint32_t) MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_PENDING3); }if (IO_Pin & 0xFFFF0000) { ... } tmp3 = tmp1 + (tmp2 << 8) + (tmp3 << 16); return(tmp3 & IO_Pin); }{ ... } /** * @brief Clear the selected IO interrupt pending bit(s). It clear automatically also the general MFXSTM32L152_REG_ADR_IRQ_PENDING * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: the IO interrupt to be cleared, could be: * @arg MFXSTM32L152_GPIO_PIN_x: Where x can be from 0 to 23. * @retval None *//* ... */ void mfxstm32l152_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin) { /* Clear the IO IT pending bit(s) by acknowledging */ /* it cleans automatically also the Global IRQ_GPIO */ /* normally this function is called under interrupt */ uint8_t pin_0_7, pin_8_15, pin_16_23; pin_0_7 = IO_Pin & 0x0000ff; pin_8_15 = IO_Pin >> 8; pin_8_15 = pin_8_15 & 0x00ff; pin_16_23 = IO_Pin >> 16; if (pin_0_7) { MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_ACK1, pin_0_7); }if (pin_0_7) { ... } if (pin_8_15) { MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_ACK2, pin_8_15); }if (pin_8_15) { ... } if (pin_16_23) { MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_IRQ_GPI_ACK3, pin_16_23); }if (pin_16_23) { ... } }{ ... } /** * @brief Enable the AF for aGPIO. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_IO_EnableAF(uint16_t DeviceAddr) { uint8_t mode; /* Get the current register value */ mode = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL); /* Enable ALTERNATE functions */ /* AGPIO[0..3] can be either IDD or GPIO */ /* AGPIO[4..7] can be either TS or GPIO */ /* if IDD or TS are enabled no matter the value this bit GPIO are not available for those pins */ /* however the MFX will waste some cycles to to handle these potential GPIO (pooling, etc) */ /* so if IDD and TS are both active it is better to let ALTERNATE disabled (0) */ /* if however IDD or TS are not connected then set it on gives more GPIOs availability */ /* remind that AGPIO are less efficient then normal GPIO (they use pooling rather then EXTI) */ mode |= MFXSTM32L152_ALTERNATE_GPIO_EN; /* Write the new register value */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL, mode); }{ ... } /** * @brief Disable the AF for aGPIO. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_IO_DisableAF(uint16_t DeviceAddr) { uint8_t mode; /* Get the current register value */ mode = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL); /* Enable ALTERNATE functions */ /* AGPIO[0..3] can be either IDD or GPIO */ /* AGPIO[4..7] can be either TS or GPIO */ /* if IDD or TS are enabled no matter the value this bit GPIO are not available for those pins */ /* however the MFX will waste some cycles to to handle these potential GPIO (pooling, etc) */ /* so if IDD and TS are both active it is better to let ALTERNATE disabled (0) */ /* if however IDD or TS are not connected then set it on gives more GPIOs availability */ /* remind that AGPIO are less efficient then normal GPIO (they use pooling rather then EXTI) */ mode &= ~MFXSTM32L152_ALTERNATE_GPIO_EN; /* Write the new register value */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL, mode); }{ ... } /* ------------------------------------------------------------------ */----------------------- GPIO /* --------------------- TOUCH SCREEN ------------------------------- */ /* ------------------------------------------------------------------ */ /** * @brief Configures the touch Screen Controller (Single point detection) * @param DeviceAddr: Device address on communication Bus. * @retval None. *//* ... */ void mfxstm32l152_TS_Start(uint16_t DeviceAddr) { uint8_t mode; /* Get the current register value */ mode = MFX_IO_Read(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL); /* Set the Functionalities to be Enabled */ mode |= MFXSTM32L152_TS_EN; /* Set the new register value */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL, mode); /* Wait for 2 ms */ MFX_IO_Delay(2); /* Select 2 nF filter capacitor */ /* Configuration: - Touch average control : 4 samples - Touch delay time : 500 uS - Panel driver setting time: 500 uS *//* ... */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_TS_SETTLING, 0x32); MFX_IO_Write(DeviceAddr, MFXSTM32L152_TS_TOUCH_DET_DELAY, 0x5); MFX_IO_Write(DeviceAddr, MFXSTM32L152_TS_AVE, 0x04); /* Configure the Touch FIFO threshold: single point reading */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_TS_FIFO_TH, 0x01); /* Clear the FIFO memory content. */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_TS_FIFO_TH, MFXSTM32L152_TS_CLEAR_FIFO); /* Touch screen control configuration : - No window tracking index *//* ... */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_TS_TRACK, 0x00); /* Clear all the IT status pending bits if any */ mfxstm32l152_IO_ClearIT(DeviceAddr, 0xFFFFFF); /* Wait for 1 ms delay */ MFX_IO_Delay(1); }{ ... } /** * @brief Return if there is touch detected or not. * @param DeviceAddr: Device address on communication Bus. * @retval Touch detected state. *//* ... */ uint8_t mfxstm32l152_TS_DetectTouch(uint16_t DeviceAddr) { uint8_t state; uint8_t ret = 0; state = MFX_IO_Read(DeviceAddr, MFXSTM32L152_TS_FIFO_STA); state = ((state & (uint8_t)MFXSTM32L152_TS_CTRL_STATUS) == (uint8_t)MFXSTM32L152_TS_CTRL_STATUS); if(state > 0) { if(MFX_IO_Read(DeviceAddr, MFXSTM32L152_TS_FIFO_LEVEL) > 0) { ret = 1; }if (MFX_IO_Read(DeviceAddr, MFXSTM32L152_TS_FIFO_LEVEL) > 0) { ... } }if (state > 0) { ... } return ret; }{ ... } /** * @brief Get the touch screen X and Y positions values * @param DeviceAddr: Device address on communication Bus. * @param X: Pointer to X position value * @param Y: Pointer to Y position value * @retval None. *//* ... */ void mfxstm32l152_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y) { uint8_t data_xy[3]; MFX_IO_ReadMultiple(DeviceAddr, MFXSTM32L152_TS_XY_DATA, data_xy, sizeof(data_xy)) ; /* Calculate positions values */ *X = (data_xy[1]<<4) + (data_xy[0]>>4); *Y = (data_xy[2]<<4) + (data_xy[0]&4); /* Reset the FIFO memory content. */ MFX_IO_Write(DeviceAddr, MFXSTM32L152_TS_FIFO_TH, MFXSTM32L152_TS_CLEAR_FIFO); }{ ... } /** * @brief Configure the selected source to generate a global interrupt or not * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_TS_EnableIT(uint16_t DeviceAddr) { MFX_IO_ITConfig(); /* Enable global TS IT source */ mfxstm32l152_EnableITSource(DeviceAddr, MFXSTM32L152_IRQ_TS_DET); }{ ... } /** * @brief Configure the selected source to generate a global interrupt or not * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_TS_DisableIT(uint16_t DeviceAddr) { /* Disable global TS IT source */ mfxstm32l152_DisableITSource(DeviceAddr, MFXSTM32L152_IRQ_TS_DET); }{ ... } /** * @brief Configure the selected source to generate a global interrupt or not * @param DeviceAddr: Device address on communication Bus. * @retval TS interrupts status *//* ... */ uint8_t mfxstm32l152_TS_ITStatus(uint16_t DeviceAddr) { /* Return TS interrupts status */ return(mfxstm32l152_GlobalITStatus(DeviceAddr, MFXSTM32L152_IRQ_TS)); }{ ... } /** * @brief Configure the selected source to generate a global interrupt or not * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_TS_ClearIT(uint16_t DeviceAddr) { /* Clear the global TS IT source */ mfxstm32l152_ClearGlobalIT(DeviceAddr, MFXSTM32L152_IRQ_TS); }{ ... } /* ------------------------------------------------------------------ */--------------------- TOUCH SCREEN /* --------------------- IDD MEASUREMENT ---------------------------- */ /* ------------------------------------------------------------------ */ /** * @brief Launch IDD current measurement * @param DeviceAddr: Device address on communication Bus * @retval None. *//* ... */ void mfxstm32l152_IDD_Start(uint16_t DeviceAddr) { uint8_t mode = 0; /* Get the current register value */ mode = MFX_IO_Read((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_CTRL); /* Set the Functionalities to be enabled */ mode |= MFXSTM32L152_IDD_CTRL_REQ; /* Start measurement campaign */ MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_CTRL, mode); }{ ... } /** * @brief Configures the IDD current measurement * @param DeviceAddr: Device address on communication Bus. * @param MfxIddConfig: Parameters depending on hardware config. * @retval None *//* ... */ void mfxstm32l152_IDD_Config(uint16_t DeviceAddr, IDD_ConfigTypeDef MfxIddConfig) { uint8_t value = 0; uint8_t mode = 0; /* Get the current register value */ mode = MFX_IO_Read((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL); if((mode & MFXSTM32L152_IDD_EN) != MFXSTM32L152_IDD_EN) { /* Set the Functionalities to be enabled */ mode |= MFXSTM32L152_IDD_EN; /* Set the new register value */ MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_SYS_CTRL, mode); }if ((mode & MFXSTM32L152_IDD_EN) != MFXSTM32L152_IDD_EN) { ... } /* Control register setting: number of shunts */ value = ((MfxIddConfig.ShuntNbUsed << 1) & MFXSTM32L152_IDD_CTRL_SHUNT_NB); value |= (MfxIddConfig.VrefMeasurement & MFXSTM32L152_IDD_CTRL_VREF_DIS); value |= (MfxIddConfig.Calibration & MFXSTM32L152_IDD_CTRL_CAL_DIS); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_CTRL, value); /* Idd pre delay configuration: unit and value*/ value = (MfxIddConfig.PreDelayUnit & MFXSTM32L152_IDD_PREDELAY_UNIT) | (MfxIddConfig.PreDelayValue & MFXSTM32L152_IDD_PREDELAY_VALUE); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_PRE_DELAY, value); /* Shunt 0 register value: MSB then LSB */ value = (uint8_t) (MfxIddConfig.Shunt0Value >> 8); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT0_MSB, value); value = (uint8_t) (MfxIddConfig.Shunt0Value); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT0_LSB, value); /* Shunt 1 register value: MSB then LSB */ value = (uint8_t) (MfxIddConfig.Shunt1Value >> 8); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT1_MSB, value); value = (uint8_t) (MfxIddConfig.Shunt1Value); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT1_LSB, value); /* Shunt 2 register value: MSB then LSB */ value = (uint8_t) (MfxIddConfig.Shunt2Value >> 8); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT2_MSB, value); value = (uint8_t) (MfxIddConfig.Shunt2Value); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT2_LSB, value); /* Shunt 3 register value: MSB then LSB */ value = (uint8_t) (MfxIddConfig.Shunt3Value >> 8); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT3_MSB, value); value = (uint8_t) (MfxIddConfig.Shunt3Value); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT3_LSB, value); /* Shunt 4 register value: MSB then LSB */ value = (uint8_t) (MfxIddConfig.Shunt4Value >> 8); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT4_MSB, value); value = (uint8_t) (MfxIddConfig.Shunt4Value); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT4_LSB, value); /* Shunt 0 stabilization delay */ value = MfxIddConfig.Shunt0StabDelay; MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SH0_STABILIZATION, value); /* Shunt 1 stabilization delay */ value = MfxIddConfig.Shunt1StabDelay; MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SH1_STABILIZATION, value); /* Shunt 2 stabilization delay */ value = MfxIddConfig.Shunt2StabDelay; MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SH2_STABILIZATION, value); /* Shunt 3 stabilization delay */ value = MfxIddConfig.Shunt3StabDelay; MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SH3_STABILIZATION, value); /* Shunt 4 stabilization delay */ value = MfxIddConfig.Shunt4StabDelay; MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SH4_STABILIZATION, value); /* Idd ampli gain value: MSB then LSB */ value = (uint8_t) (MfxIddConfig.AmpliGain >> 8); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_GAIN_MSB, value); value = (uint8_t) (MfxIddConfig.AmpliGain); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_GAIN_LSB, value); /* Idd VDD min value: MSB then LSB */ value = (uint8_t) (MfxIddConfig.VddMin >> 8); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_VDD_MIN_MSB, value); value = (uint8_t) (MfxIddConfig.VddMin); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_VDD_MIN_LSB, value); /* Idd number of measurements */ value = MfxIddConfig.MeasureNb; MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_NBR_OF_MEAS, value); /* Idd delta delay configuration: unit and value */ value = (MfxIddConfig.DeltaDelayUnit & MFXSTM32L152_IDD_DELTADELAY_UNIT) | (MfxIddConfig.DeltaDelayValue & MFXSTM32L152_IDD_DELTADELAY_VALUE); MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_MEAS_DELTA_DELAY, value); /* Idd number of shut on board */ value = MfxIddConfig.ShuntNbOnBoard; MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNTS_ON_BOARD, value); }{ ... } /** * @brief This function allows to modify number of shunt used for a measurement * @param DeviceAddr: Device address on communication Bus * @retval None. *//* ... */ void mfxstm32l152_IDD_ConfigShuntNbLimit(uint16_t DeviceAddr, uint8_t ShuntNbLimit) { uint8_t mode = 0; /* Get the current register value */ mode = MFX_IO_Read((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_CTRL); /* Clear number of shunt limit */ mode &= ~(MFXSTM32L152_IDD_CTRL_SHUNT_NB); /* Clear number of shunt limit */ mode |= ((ShuntNbLimit << 1) & MFXSTM32L152_IDD_CTRL_SHUNT_NB); /* Write noewx desired limit */ MFX_IO_Write((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_CTRL, mode); }{ ... } /** * @brief Get Idd current value * @param DeviceAddr: Device address on communication Bus * @param ReadValue: Pointer on value to be read * @retval Idd value in 10 nA. *//* ... */ void mfxstm32l152_IDD_GetValue(uint16_t DeviceAddr, uint32_t *ReadValue) { uint8_t data[3]; MFX_IO_ReadMultiple((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_VALUE_MSB, data, sizeof(data)) ; /* Recompose Idd current value */ *ReadValue = (data[0] << 16) | (data[1] << 8) | data[2]; }{ ... } /** * @brief Get Last shunt used for measurement * @param DeviceAddr: Device address on communication Bus * @retval Last shunt used *//* ... */ uint8_t mfxstm32l152_IDD_GetShuntUsed(uint16_t DeviceAddr) { return(MFX_IO_Read((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_IDD_SHUNT_USED)); }{ ... } /** * @brief Configure mfx to enable Idd interrupt * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_IDD_EnableIT(uint16_t DeviceAddr) { MFX_IO_ITConfig(); /* Enable global IDD interrupt source */ mfxstm32l152_EnableITSource(DeviceAddr, MFXSTM32L152_IRQ_IDD); }{ ... } /** * @brief Clear Idd global interrupt * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_IDD_ClearIT(uint16_t DeviceAddr) { /* Clear the global IDD interrupt source */ mfxstm32l152_ClearGlobalIT(DeviceAddr, MFXSTM32L152_IRQ_IDD); }{ ... } /** * @brief get Idd interrupt status * @param DeviceAddr: Device address on communication Bus. * @retval IDD interrupts status *//* ... */ uint8_t mfxstm32l152_IDD_GetITStatus(uint16_t DeviceAddr) { /* Return IDD interrupt status */ return(mfxstm32l152_GlobalITStatus(DeviceAddr, MFXSTM32L152_IRQ_IDD)); }{ ... } /** * @brief disable Idd interrupt * @param DeviceAddr: Device address on communication Bus. * @retval None. *//* ... */ void mfxstm32l152_IDD_DisableIT(uint16_t DeviceAddr) { /* Disable global IDD interrupt source */ mfxstm32l152_DisableITSource(DeviceAddr, MFXSTM32L152_IRQ_IDD); }{ ... } /* ------------------------------------------------------------------ */--------------------- IDD MEASUREMENT /* --------------------- ERROR MANAGEMENT --------------------------- */ /* ------------------------------------------------------------------ */ /** * @brief Read Error Source. * @param DeviceAddr: Device address on communication Bus. * @retval Error message code with error source *//* ... */ uint8_t mfxstm32l152_Error_ReadSrc(uint16_t DeviceAddr) { /* Get the current source register value */ return(MFX_IO_Read((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_ERROR_SRC)); }{ ... } /** * @brief Read Error Message * @param DeviceAddr: Device address on communication Bus. * @retval Error message code with error source *//* ... */ uint8_t mfxstm32l152_Error_ReadMsg(uint16_t DeviceAddr) { /* Get the current message register value */ return(MFX_IO_Read((uint8_t) DeviceAddr, MFXSTM32L152_REG_ADR_ERROR_MSG)); }{ ... } /** * @brief Enable Error global interrupt * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_Error_EnableIT(uint16_t DeviceAddr) { MFX_IO_ITConfig(); /* Enable global Error interrupt source */ mfxstm32l152_EnableITSource(DeviceAddr, MFXSTM32L152_IRQ_ERROR); }{ ... } /** * @brief Clear Error global interrupt * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void mfxstm32l152_Error_ClearIT(uint16_t DeviceAddr) { /* Clear the global Error interrupt source */ mfxstm32l152_ClearGlobalIT(DeviceAddr, MFXSTM32L152_IRQ_ERROR); }{ ... } /** * @brief get Error interrupt status * @param DeviceAddr: Device address on communication Bus. * @retval Error interrupts status *//* ... */ uint8_t mfxstm32l152_Error_GetITStatus(uint16_t DeviceAddr) { /* Return Error interrupt status */ return(mfxstm32l152_GlobalITStatus(DeviceAddr, MFXSTM32L152_IRQ_ERROR)); }{ ... } /** * @brief disable Error interrupt * @param DeviceAddr: Device address on communication Bus. * @retval None. *//* ... */ void mfxstm32l152_Error_DisableIT(uint16_t DeviceAddr) { /* Disable global Error interrupt source */ mfxstm32l152_DisableITSource(DeviceAddr, MFXSTM32L152_IRQ_ERROR); }{ ... } /** * @brief FOR DEBUG ONLY *//* ... */ uint8_t mfxstm32l152_ReadReg(uint16_t DeviceAddr, uint8_t RegAddr) { /* Get the current register value */ return(MFX_IO_Read((uint8_t) DeviceAddr, RegAddr)); }{ ... } void mfxstm32l152_WriteReg(uint16_t DeviceAddr, uint8_t RegAddr, uint8_t Value) { /* set the current register value */ MFX_IO_Write((uint8_t) DeviceAddr, RegAddr, Value); }{ ... } /* ------------------------------------------------------------------ */--------------------- ERROR MANAGEMENT /* ----------------------- Private functions ------------------------ */ /* ------------------------------------------------------------------ */ /** * @brief Check if the device instance of the selected address is already registered * and return its index * @param DeviceAddr: Device address on communication Bus. * @retval Index of the device instance if registered, 0xFF if not. *//* ... */ static uint8_t mfxstm32l152_GetInstance(uint16_t DeviceAddr) { uint8_t idx; /* Check all the registered instances */ for(idx = 0; idx < MFXSTM32L152_MAX_INSTANCE ; idx ++) { if(mfxstm32l152[idx] == DeviceAddr) { return idx; }if (mfxstm32l152[idx] == DeviceAddr) { ... } }for (idx = 0; idx < MFXSTM32L152_MAX_INSTANCE ; idx ++) { ... } return 0xFF; }{ ... } /** * @brief Release registered device instance * @param DeviceAddr: Device address on communication Bus. * @retval Index of released device instance, 0xFF if not. *//* ... */ static uint8_t mfxstm32l152_ReleaseInstance(uint16_t DeviceAddr) { uint8_t idx; /* Check for all the registered instances */ for(idx = 0; idx < MFXSTM32L152_MAX_INSTANCE ; idx ++) { if(mfxstm32l152[idx] == DeviceAddr) { mfxstm32l152[idx] = 0; return idx; }if (mfxstm32l152[idx] == DeviceAddr) { ... } }for (idx = 0; idx < MFXSTM32L152_MAX_INSTANCE ; idx ++) { ... } return 0xFF; }{ ... } /** * @brief Internal routine * @param DeviceAddr: Device address on communication Bus. * @param RegisterAddr: Register Address * @param PinPosition: Pin [0:23] * @param PinValue: 0/1 * @retval None *//* ... */ void mfxstm32l152_reg24_setPinValue(uint16_t DeviceAddr, uint8_t RegisterAddr, uint32_t PinPosition, uint8_t PinValue ) { uint8_t tmp = 0; uint8_t pin_0_7, pin_8_15, pin_16_23; pin_0_7 = PinPosition & 0x0000ff; pin_8_15 = PinPosition >> 8; pin_8_15 = pin_8_15 & 0x00ff; pin_16_23 = PinPosition >> 16; if (pin_0_7) { /* Get the current register value */ tmp = MFX_IO_Read(DeviceAddr, RegisterAddr); /* Set the selected pin direction */ if (PinValue != 0) { tmp |= (uint8_t)pin_0_7; }if (PinValue != 0) { ... } else { tmp &= ~(uint8_t)pin_0_7; }else { ... } /* Set the new register value */ MFX_IO_Write(DeviceAddr, RegisterAddr, tmp); }if (pin_0_7) { ... } if (pin_8_15) { /* Get the current register value */ tmp = MFX_IO_Read(DeviceAddr, RegisterAddr+1); /* Set the selected pin direction */ if (PinValue != 0) { tmp |= (uint8_t)pin_8_15; }if (PinValue != 0) { ... } else { tmp &= ~(uint8_t)pin_8_15; }else { ... } /* Set the new register value */ MFX_IO_Write(DeviceAddr, RegisterAddr+1, tmp); }if (pin_8_15) { ... } if (pin_16_23) { /* Get the current register value */ tmp = MFX_IO_Read(DeviceAddr, RegisterAddr+2); /* Set the selected pin direction */ if (PinValue != 0) { tmp |= (uint8_t)pin_16_23; }if (PinValue != 0) { ... } else { tmp &= ~(uint8_t)pin_16_23; }else { ... } /* Set the new register value */ MFX_IO_Write(DeviceAddr, RegisterAddr+2, tmp); }if (pin_16_23) { ... } }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.