IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Usage du mot-clef "static"


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre chevronné Avatar de electroremy
    Homme Profil pro
    Ingénieur sécurité
    Inscrit en
    Juin 2007
    Messages
    999
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur sécurité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 999
    Par défaut Usage du mot-clef "static"
    Bonjour,

    En c++, dans une classe, le mot clef "static" permet de déclarer des variables et des fonctions comme "globales" à l'ensemble des instances de la classe.

    C'est une fonction particulière, on ne devrait donc pas trouver ça souvent.

    J'ai des fichiers, issus de librairies permettant de gérer du hardware (écran TFT, shield Ethernet), où presque toutes voire toutes les fonctions et les variables sont déclarées "static"

    Pour le Shield Ethernet ça me semble logique car on peut avoir plusieurs instances d'une classe (typiquement des clients et un serveur, qui dérivent d'une classe plus générale) qui "partagent" des variables liées à un unique hardware qui n'ont donc aucune raison de ne pas être identiques. Pour ce cas de figure, "static" semble non seulement logique mais aussi indispensable.

    En revanche pour l'écran TFT, par principe la classe n'est instanciée qu'à un seul exemplaire pour piloter un écran.
    Et si on arrivait à gérer deux écrans TFT dans le même projet, il faudrait que les deux instances soient totalement indépendantes pour piloter correctement chaque écran.
    Aussi, dans ce cas de figure je ne comprend pas l'usage de "static".

    D'ailleurs, dans ma classe qui gère la dalle tactile, je n'ai rien de déclaré en "static".

    J'imagine que dans l'embarqué, il y a des particularité qui fait qu'on utilise "static" beaucoup plus souvent que sur un PC.

    J'ai aussi des variables déclarées en "volatile" et là c'est beaucoup plus évident par rapport aux usages du c++ : tout ce qui est déclaré en "volatile" correspond à des broches ou à des ports.
    Il faut donc absolument éviter que le compilateur simplifie le code en regroupant ou en supprimant des lectures ou écritures de variables "volatile" car le compilateur ne peut pas savoir que le hardware va lire ou modifier ces broches.

    Au total, dans l'ensemble de mon projet, j'ai beaucoup moins de déclarations "volatile" (29) que de "static" (277)

    Merci

    A bientôt

  2. #2
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 908
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 908
    Par défaut
    bonjour

    vous avez un lien vers cette bibliothèque pour l'écran TFT?

  3. #3
    Membre chevronné Avatar de electroremy
    Homme Profil pro
    Ingénieur sécurité
    Inscrit en
    Juin 2007
    Messages
    999
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur sécurité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 999
    Par défaut
    Oui, avec le code c'est mieux

    C'est une 'fork' que je suis en train de terminer...
    Il me reste à finaliser quelques fonctions, et à nettoyer mon code, d'où ma question.

    - A l'origine, il y a la bibliothèque Adafruit GFX et ILI9341
    - Puis, un fork "PDQ" de Hackaday
    - Et enfin, ma propre version

    Ma version est plus rapide, elle a plus de fonctions et occupe moins de ROM.
    En contrepartie, elle ne convient que pour un Arduino UNO et un ILI9341, alors que les bibliothèques originales s'adaptait à plusieurs cartes et plusieurs afficheurs.
    C'est normal, on ne peut pas tout avoir dans la vie, mon code est optimisé mais au détriment de la portabilité.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    1271
    1272
    1273
    1274
    1275
    1276
    1277
    1278
    1279
    1280
    1281
    1282
    1283
    1284
    1285
    1286
    1287
    1288
    1289
    1290
    1291
    1292
    1293
    1294
    1295
    1296
    1297
    1298
    1299
    1300
    1301
    1302
    1303
    1304
    1305
    1306
    1307
    1308
    1309
    1310
    1311
    1312
    1313
    1314
    1315
    1316
    1317
    1318
    1319
    1320
    1321
    1322
    1323
    1324
    1325
    1326
    1327
    1328
    1329
    1330
    1331
    1332
    1333
    1334
    1335
    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    1354
    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    1369
    1370
    1371
    1372
    1373
    1374
    1375
    1376
    1377
    1378
    1379
    1380
    1381
    1382
    1383
    1384
    1385
    1386
    1387
    1388
    1389
    1390
    1391
    1392
    1393
    1394
    1395
    1396
    1397
    1398
    1399
    1400
    1401
    1402
    1403
    1404
    1405
    1406
    1407
    1408
    1409
    1410
    1411
    1412
    1413
    1414
    1415
    1416
    1417
    1418
    1419
    1420
    1421
    1422
    1423
    1424
    1425
    1426
    1427
    1428
    1429
    1430
    1431
    1432
    1433
    1434
    1435
    1436
    1437
    1438
    1439
    1440
    1441
    1442
    1443
    1444
    1445
    1446
    1447
    1448
    1449
    1450
    1451
    1452
    1453
    1454
    1455
    1456
    1457
    1458
    1459
    1460
    1461
    1462
    1463
    1464
    1465
    1466
    1467
    1468
    1469
    1470
    1471
    1472
    1473
    1474
    1475
    1476
    1477
    1478
    1479
    1480
    1481
    1482
    1483
    1484
    1485
    1486
    1487
    1488
    1489
    1490
    1491
    1492
    1493
    1494
    1495
    1496
    1497
    1498
    1499
    1500
    1501
    1502
    1503
    1504
    1505
    1506
    1507
    1508
    1509
    1510
    1511
    1512
    1513
    1514
    1515
    1516
    1517
    1518
    1519
    1520
    1521
    1522
    1523
    1524
    1525
    1526
    1527
    1528
    1529
    1530
    1531
    1532
    1533
    1534
    1535
    1536
    1537
    1538
    1539
    1540
    1541
    1542
    1543
    1544
    1545
    1546
    1547
    1548
    1549
    1550
    1551
    1552
    1553
    1554
    1555
    1556
    1557
    1558
    1559
    1560
    1561
    1562
    1563
    1564
    1565
    1566
    1567
    1568
    1569
    1570
    1571
    1572
    1573
    1574
    1575
    1576
    1577
    1578
    1579
    1580
    1581
    1582
    1583
    1584
    1585
    1586
    1587
    1588
    1589
    1590
    1591
    1592
    1593
    1594
    1595
    1596
    1597
    1598
    1599
    1600
    1601
    1602
    1603
    1604
    1605
    1606
    1607
    1608
    1609
    1610
    1611
    1612
    1613
    1614
    1615
    1616
    1617
    1618
    1619
    1620
    1621
    1622
    1623
    1624
    1625
    1626
    1627
    1628
    1629
    1630
    1631
    1632
    1633
    1634
    1635
    1636
    1637
    1638
    1639
    1640
    1641
    1642
    1643
    1644
    1645
    1646
    1647
    1648
    1649
    1650
    1651
    1652
    1653
    1654
    1655
    1656
    1657
    1658
    1659
    1660
    1661
    1662
    1663
    1664
    1665
    1666
    1667
    1668
    1669
    1670
    1671
    1672
    1673
    1674
    1675
    1676
    1677
    1678
    1679
    1680
    1681
    1682
    1683
    1684
    1685
    1686
    1687
    1688
    1689
    1690
    1691
    1692
    1693
    1694
    1695
    1696
    1697
    1698
    1699
    1700
    1701
    1702
    1703
    1704
    1705
    1706
    1707
    1708
    1709
    1710
    1711
    1712
    1713
    1714
    1715
    1716
    1717
    1718
    1719
    1720
    1721
    1722
    1723
    1724
    1725
    /*
     *                          ****** FORK FOR THE ******
     *
     * -------------- ETHERNET CLIENT TOUCH SCREEN INTERFACE PROJET -------------- * 
     * Arduino UNO + ILI9341 TFT screen + XPT2046 touch panel + Shield Ethernet II *
     *                               V53 - 31/01/2021                              *
     *                          Compile with Arduino 1.8.12                        *
     *                       PLEASE READ PDF MANUAL BEFORE USE                     * 
     *                               www.remylucas.fr                              *
     * --------------------------------------------------------------------------- *
     */
     
     /*
    This is a replacement "re-mix" of the Adafruit GFX library and associated hardware LCD drivers.
     
    https://hackaday.io/project/6038-pdqgfx-optimzed-avr-lcd-graphics
     
    It is between 2.5 and 12 times faster than the Adafruit libraries for SPI LCDs
     
    Remy LUCAS Fork is a little bit faster, have more functions and alors takes less ROM usage.
     
    NOTE: This file is from the Adafruit_ILI9341 library (which PDQ_IL9341 was based on).  Thanks Adafruit!
     
     This is a library for the Adafruit 2.2" SPI display.
    This library works with the Adafruit 2.2" TFT Breakout w/SD card
      ----> http://www.adafruit.com/products/1480
     
    Check out the links above for our tutorials and wiring diagrams.
    These displays use SPI to communicate, 4 or 5 pins are required
    to interface (RST is optional).
    Adafruit invests time and resources providing this open source code,
    please support Adafruit and open-source hardware by purchasing
    products from Adafruit!
     
    Written by Limor Fried/Ladyada for Adafruit Industries.
    MIT license, all text above must be included in any redistribution
    */
     
    #if !defined(TFT_SIZE_WIDTH) 
    #define TFT_SIZE_WIDTH 240
    #endif
    #if !defined(TFT_SIZE_HEIGHT) 
    #define TFT_SIZE_HEIGHT 320 
    #endif 
     
    // DEFINE HERE THE PIN USED -------------------
    #define	ILI9341_CS_PIN	0 // <= /CS pin (chip-select, LOW to get attention of ILI9341, HIGH and it ignores SPI bus)
    #define	ILI9341_DC_PIN	9 // <= DC pin (1=data or 0=command indicator line) also called RS
    #define	ILI9341_RST_PIN	8 // <= RST pin (optional)
    // other pins (MISO, MOSI, CK) used are dictated by HARDWARE SPI
    // --------------------------------------------
     
    // other PDQ library options
    #define	ILI9341_SAVE_SPCR	0	 
     
    #include "Arduino.h"
    #include "Print.h"
    #include <avr/pgmspace.h>
     
    #include "RLucas_TFT_FastPin.h"
     
    #if !defined(__AVR_ATtiny85__) && !defined(__AVR_ATtiny45__)
    #define INLINE		inline
    #define INLINE_OPT	__attribute__((always_inline))
    #else
    #define INLINE
    #define INLINE_OPT
    #endif
    #ifndef pgm_read_byte
    	#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
    #endif
    #ifndef pgm_read_word
    	#define pgm_read_word(addr) (*(const unsigned short *)(addr))
    #endif
    #ifndef pgm_read_dword
    	#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
    #endif
    #if !defined(__INT_MAX__) || (__INT_MAX__ > 0xFFFFL)
    	#define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
    #else
    	#define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
    #endif
     
    int GLOBAL_X1; // X or X1
    int GLOBAL_Y1; // Y or Y1
    int GLOBAL_X2; // X2 or W
    int GLOBAL_Y2; // Y2 or H
    int GLOBAL_X3; // X3 or L or R
    int GLOBAL_Y3; // Y3
    unsigned int GLOBAL_Colour; // Draw Colour
    unsigned int GLOBAL_ColourBG; // Background colour (usefull for bitmaps, texts)
    uint8_t GLOBAL_Button_Offset;
     
    bool RainbowFunc_UseBG; // used to swith from Rainbow_BG_Colour to Rainbow_Colour
    bool RainbowFunc_Mode; // used to swith from Rainbow_BG_Colour to Rainbow_Colour
    bool RainbowFunc_X_Direction; // used to swith from Rainbow_BG_Colour to Rainbow_Colour
     
    uint8_t Rainbow_R; // R value when X or Y = Rainbow_XY_min
    uint8_t Rainbow_G;
    uint8_t Rainbow_B;
    int Rainbow_DR; // R value when X or Y = Rainbow_XY_min + Rainbow_XY_delta is Rainbow_R + Rainbow_DR 
    int Rainbow_DG;
    int Rainbow_DB;
    bool Rainbow_Mode;
    bool Rainbow_X_Direction;
    int Rainbow_XY_min;
    int Rainbow_XY_delta;
    bool Rainbow_Swap;
    int Rainbow_WH;
     
    uint8_t Rainbow_BG_R;
    uint8_t Rainbow_BG_G;
    uint8_t Rainbow_BG_B;
    int Rainbow_BG_DR;
    int Rainbow_BG_DG;
    int Rainbow_BG_DB;
    bool Rainbow_BG_Mode;
    bool Rainbow_BG_X_Direction;
    int Rainbow_BG_XY_min;
    int Rainbow_BG_XY_delta;
    bool Rainbow_BG_Swap;
    int Rainbow_BG_WH;
     
    byte BG_Coul_Index;
     
    unsigned int Colour[14] = {0,63488,2016,31,63519,65504,65535,33808,64512,1024,32768,65535,16904,33808}; // couleurs par défaut
    #define Index_Colour_Black 0 //             0
    #define Index_Colour_Red 1 //            63488
    #define Index_Colour_Green 2 //             2016
    #define Index_Colour_Blue 3 //             31
    #define Index_Colour_Purple 4 //           63519
    #define Index_Colour_Yellow 5 //            65504
    #define Index_Colour_White 6 //            65535
    #define Index_Colour_Gray 7 //             33808
    #define Index_Colour_Orange 8 //           64512
    #define Index_Colour_DarkGreen 9 //        1024
    #define Index_Colour_Brown 10 //      		32768
    #define Index_Colour_ButtonTopLeft 11 //   65535
    #define Index_Colour_ButtonBottomRightInt 12 // 16904
    #define Index_Colour_ButtonBottomRightExt 13 // 33808
     
    // swap any type
    template<typename T>
    static inline void swapValue(T& x, T& y) {
    	T tmp = x;
    	x = y;
    	y = tmp;
    }
    typedef int			coord_t;
     
    class PDQ_ILI9341 : public Print {
     public:
    	// ILI9341 commands - For datasheet see https://www.adafruit.com/products/1480
     	enum {
    		ILI9341_NOP			= 0x00,
    		ILI9341_SWRESET		= 0x01,
    		ILI9341_RDDID		= 0x04,
    		ILI9341_RDDST		= 0x09,
     
    		ILI9341_SLPIN		= 0x10,
    		ILI9341_SLPOUT		= 0x11,
    		ILI9341_PTLON		= 0x12,
    		ILI9341_NORON		= 0x13,
     
    		ILI9341_RDMODE		= 0x0A,
    		ILI9341_RDMADCTL	= 0x0B,
    		ILI9341_RDPIXFMT	= 0x0C,
    		ILI9341_RDIMGFMT	= 0x0A,
    		ILI9341_RDSELFDIAG	= 0x0F,
     
    		ILI9341_INVOFF		= 0x20,
    		ILI9341_INVON		= 0x21,
    		ILI9341_GAMMASET	= 0x26,
    		ILI9341_DISPOFF		= 0x28,
    		ILI9341_DISPON		= 0x29,
     
    		ILI9341_CASET		= 0x2A,
    		ILI9341_PASET		= 0x2B,
    		ILI9341_RAMWR		= 0x2C,
    		ILI9341_RAMRD		= 0x2E,
     
    		ILI9341_PTLAR		= 0x30,
    		ILI9341_MADCTL		= 0x36,
    		ILI9341_PIXFMT		= 0x3A,
     
    		ILI9341_FRMCTR1		= 0xB1,
    		ILI9341_FRMCTR2		= 0xB2,
    		ILI9341_FRMCTR3		= 0xB3,
    		ILI9341_INVCTR		= 0xB4,
    		ILI9341_DFUNCTR		= 0xB6,
     
    		ILI9341_PWCTR1		= 0xC0,
    		ILI9341_PWCTR2		= 0xC1,
    		ILI9341_PWCTR3		= 0xC2,
    		ILI9341_PWCTR4		= 0xC3,
    		ILI9341_PWCTR5		= 0xC4,
    		ILI9341_VMCTR1		= 0xC5,
    		ILI9341_VMCTR2		= 0xC7,
     
    		ILI9341_RDID1		= 0xDA,
    		ILI9341_RDID2		= 0xDB,
    		ILI9341_RDID3		= 0xDC,
    		ILI9341_RDID4		= 0xDD,
     
    		ILI9341_GMCTRP1		= 0xE0,
    		ILI9341_GMCTRN1		= 0xE1,
     
    		// ILI9341_PWCTR6	= 0xFC,
    	};
     
    	// some other misc. constants
    	enum {
    		// screen dimensions
    		//ILI9341_TFTWIDTH	= 240,
    		//ILI9341_TFTHEIGHT	= 320,
    		// MADCTL bits
    		ILI9341_MADCTL_MH	= 0x04,	// bit 2 = 0 for refresh left -> right, 1 for refresh right -> left
    		ILI9341_MADCTL_RGB	= 0x00,	// bit 3 = 0 for RGB color order
    		ILI9341_MADCTL_BGR	= 0x08,	// bit 3 = 1 for BGR color order
    		ILI9341_MADCTL_ML	= 0x10,	// bit 4 = 0 for refresh top -> bottom, 1 for bottom -> top
    		ILI9341_MADCTL_MV	= 0x20,	// bit 5 = 0 for column, row order (portrait), 1 for row, column order (landscape)
    		ILI9341_MADCTL_MX	= 0x40,	// bit 6 = 0 for left -> right, 1 for right -> left order
    		ILI9341_MADCTL_MY	= 0x80,	// bit 7 = 0 for top -> bottom, 1 for bottom -> top
    		// delay indicator bit for commandList()
    		DELAY				= 0x80
    	};
     
    	// === lower-level internal routines =========
    	static void commandList(const uint8_t *addr);
     
    	// NOTE: Make sure each spi_begin() is matched with a single spi_end() (and don't call either twice)
    	// set CS back to low (LCD selected)
    	static inline void spi_begin() __attribute__((always_inline)) {
    #if ILI9341_SAVE_SPCR && defined(AVR_HARDWARE_SPI)
    		swapValue(save_SPCR, SPCR);	// swap initial/current SPCR settings
    #endif
    		FastPin<ILI9341_CS_PIN>::lo();		// CS <= LOW (selected)
    	}
    	// NOTE: Make sure each spi_begin() is matched with a single spi_end() (and don't call either twice)
    	// reset CS back to high (LCD unselected)
    	static inline void spi_end() __attribute__((always_inline))	{
    		FastPin<ILI9341_CS_PIN>::hi();		// CS <= HIGH (deselected)
    #if ILI9341_SAVE_SPCR && defined(AVR_HARDWARE_SPI)
    		swapValue(SPCR, save_SPCR);	// swap current/initial SPCR settings
    #endif
    	}
    #if defined(AVR_HARDWARE_SPI)
    	// 10 cycle delay (including "call")
    	static void delay10() __attribute__((noinline)) __attribute__((naked)) 	{
    		__asm__ __volatile__
    		(
    									// +4 (call to get here)
    #if !defined(__AVR_HAVE_RAMPD__)	
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    #else
    			"	nop\n"				// +1 (1-cycle NOP)
    #endif
    			"	ret\n"				// +4 (or +5 on >64KB AVR with RAMPD reg)
    									// = 10 cycles
    			: : : 
    		);
    	}
    	// 13 cycle delay (including "call")
    	static void delay13() __attribute__((noinline)) __attribute__((naked))	{
    		__asm__ __volatile__
    		(
    									// +4 (call to get here)
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    #if !defined(__AVR_HAVE_RAMPD__)	
    			"	nop\n"				// +1 (1-cycle NOP)
    #endif
    			"	ret\n"				// +4 (or +5 on >64KB AVR with RAMPD reg)
    									// = 13 cycles
    			: : : 
    		);
    	}
    	// 15 cycle delay (including "call")
    	static void delay15() __attribute__((noinline)) __attribute__((naked))	{
    		__asm__ __volatile__
    		(
    									// +4 (call to get here)
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    #if !defined(__AVR_HAVE_RAMPD__)	
    			"	nop\n"				// +1 (1-cycle NOP)
    #endif
    			"	ret\n"				// +4 (or +5 on >64KB AVR with RAMPD reg)
    									// = 15 cycles
    			: : : 
    		);
    	}
    	// 17 cycle delay (including "call")
    	static void delay17() __attribute__((noinline)) __attribute__((naked))	{
    		__asm__ __volatile__
    		(
    									// +4 (call to get here)
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    			"	adiw	r24,0\n"	// +2 (2-cycle NOP)
    #if !defined(__AVR_HAVE_RAMPD__)	
    			"	nop\n"				// +1 (2-cycle NOP)
    #endif
    			"	ret\n"				// +4 (or +5 on >64KB AVR with RAMPD reg)
    									// = 17 cycles
    			: : : 
    		);
    	}
    	// normal SPI write with minimal hand-tuned delay (assuming max DIV2 SPI rate)
    	static INLINE void spiWrite(uint8_t data) INLINE_OPT	{
    		SPDR = data;
    		__asm__ __volatile__
    		(
    			"	call	_ZN11PDQ_ILI93417delay17Ev\n"	// call mangled delay17 (compiler would needlessly save/restore regs)
    			: : : 
    		);
    	}
    	// special SPI write with minimal hand-tuned delay (assuming max DIV2 SPI rate) - minus 2 cycles for RS (etc.) change
    	static INLINE void spiWrite_preCmd(uint8_t data) INLINE_OPT	{
    		SPDR = data;
     
    		__asm__ __volatile__
    		(
    			"	call	_ZN11PDQ_ILI93417delay15Ev\n"	// call mangled delay15 (compiler would needlessly save/restore regs)
    			: : : 
    		);
    	}
    	// SPI 16-bit write with minimal hand-tuned delay (assuming max DIV2 SPI rate)
    	static INLINE void spiWrite16(uint16_t data) INLINE_OPT	{
    		uint8_t temp;
    		__asm__ __volatile__
    		(
    			"	out	%[spi],%[hi]\n"				// write SPI data (18 cycles until next write)
    			"	call	_ZN11PDQ_ILI93417delay17Ev\n"	// call mangled delay17 (compiler would needlessly save/restore regs)
    			"	out	%[spi],%[lo]\n"				// write SPI data (18 cycles until next write)
    			"	call	_ZN11PDQ_ILI93417delay17Ev\n"	// call mangled delay17 (compiler would needlessly save/restore regs)
     
    			: [temp] "=d" (temp)
    			: [spi] "i" (_SFR_IO_ADDR(SPDR)), [lo] "r" ((uint8_t)data), [hi] "r" ((uint8_t)(data>>8))
    			: 
    		);
    	}
    	// SPI 16-bit write with minimal hand-tuned delay (assuming max DIV2 SPI rate) minus 2 cycles
    	static INLINE void spiWrite16_preCmd(uint16_t data) INLINE_OPT	{
    		uint8_t temp;
    		__asm__ __volatile__
    		(
    			"	out	%[spi],%[hi]\n"				// write SPI data (18 cycles until next write)
    			"	call	_ZN11PDQ_ILI93417delay17Ev\n"	// call mangled delay17 (compiler would needlessly save/restore regs)
    			"	out	%[spi],%[lo]\n"				// write SPI data (18 cycles until next write)
    			"	call	_ZN11PDQ_ILI93417delay15Ev\n"	// call mangled delay15 (compiler would needlessly save/restore regs)
     
    			: [temp] "=d" (temp)
    			: [spi] "i" (_SFR_IO_ADDR(SPDR)), [lo] "r" ((uint8_t)data), [hi] "r" ((uint8_t)(data>>8))
    			: 
    		);
    	}
    	// SPI 16-bit write with minimal hand-tuned delay (assuming max DIV2 SPI rate) minus 4 cycles
    	static INLINE void spiWrite16_lineDraw(uint16_t data) INLINE_OPT	{
    		uint8_t temp;
    		__asm__ __volatile__
    		(
    			"	out	%[spi],%[hi]\n"				// write SPI data (18 cycles until next write)
    			"	call	_ZN11PDQ_ILI93417delay17Ev\n"	// call mangled delay17 (compiler would needlessly save/restore regs)
    			"	out	%[spi],%[lo]\n"				// write SPI data (18 cycles until next write)
     
    			: [temp] "=d" (temp)
    			: [spi] "i" (_SFR_IO_ADDR(SPDR)), [lo] "r" ((uint8_t)data), [hi] "r" ((uint8_t)(data>>8))
    			: 
    		);
    	}
    	// normal SPI write with minimal hand-tuned delay (assuming max DIV2 SPI rate)
    	static INLINE void spiWrite16(uint16_t data, int count) INLINE_OPT	{
    		uint8_t temp;
    		__asm__ __volatile__
    		(
    			"	sbiw	%[count],0\n"				// test count
    			"	brmi	4f\n"					// if < 0 then done
    			"	breq	4f\n"					// if == 0 then done
    			"1:	out	%[spi],%[hi]\n"				// write SPI data (18 cycles until next write)
    			"	call	_ZN11PDQ_ILI93417delay17Ev\n"	// call mangled delay17 (compiler would needlessly save/restore regs)
    			"	out	%[spi],%[lo]\n"				// write SPI data (18 cycles until next write)
    			"	call	_ZN11PDQ_ILI93417delay13Ev\n"	// call mangled delay13 (compiler would needlessly save/restore regs)
    			"	sbiw	%[count],1\n"				// +2	decrement count
    			"	brne	1b\n"					// +2/1	if != 0 then loop
    										// = 13 + 2 + 2 (17 cycles)			
    			"4:\n"
     
    			: [temp] "=d" (temp), [count] "+w" (count)
    			: [spi] "i" (_SFR_IO_ADDR(SPDR)), [lo] "r" ((uint8_t)data), [hi] "r" ((uint8_t)(data>>8))
    			: 
    		);
    	}
    #else	// bit-bang
    #if defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny45__)
    	// USI hardware assisted
    	static void spiWrite(uint8_t data) __attribute__((noinline))	{
    		USIDR = data;
    		__asm__ __volatile__
    		(
    			"	out %[spi],%[clkp0]\n"	// MSB
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"	// LSB
    			"	out %[spi],%[clkp1]\n"
    			: 
    			: [spi] "i" (_SFR_IO_ADDR(USICR)), [clkp0] "a" ((uint8_t)((1<<USIWM0)|(0<<USICS0)|(1<<USITC))), [clkp1] "a" ((uint8_t)((1<<USIWM0)|(0<<USICS0)|(1<<USITC)|(1<<USICLK)))
    			:
    		);
    	}
    	static void spiWrite16(uint16_t data) __attribute__((noinline))	{
    		USIDR = data>>8;
    		__asm__ __volatile__
    		(
    			"	out %[spi],%[clkp0]\n"	// MSB
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"	// LSB
    			"	out %[spi],%[clkp1]\n"
    			: 
    			: [spi] "i" (_SFR_IO_ADDR(USICR)), [clkp0] "a" ((uint8_t)((1<<USIWM0)|(0<<USICS0)|(1<<USITC))), [clkp1] "a" ((uint8_t)((1<<USIWM0)|(0<<USICS0)|(1<<USITC)|(1<<USICLK)))
    			:
    		);
     
    		USIDR = data&0xff;
    		__asm__ __volatile__
    		(
    			"	out %[spi],%[clkp0]\n"	// MSB
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"
    			"	out %[spi],%[clkp1]\n"
    			"	out %[spi],%[clkp0]\n"	// LSB
    			"	out %[spi],%[clkp1]\n"
    			: 
    			: [spi] "i" (_SFR_IO_ADDR(USICR)), [clkp0] "a" ((uint8_t)((1<<USIWM0)|(0<<USICS0)|(1<<USITC))), [clkp1] "a" ((uint8_t)((1<<USIWM0)|(0<<USICS0)|(1<<USITC)|(1<<USICLK)))
    			:
    		);
    	}
    #else
    	static void spiWrite(uint8_t data) __attribute__((noinline))	{
    		// Fast SPI bitbang swiped from LPD8806 library
    		for(uint8_t bit = 0x80; bit; bit >>= 1)	{
    			if (data & bit)
    				FastPin<ILI9341_MOSI_PIN>::hi();
    			else
    				FastPin<ILI9341_MOSI_PIN>::lo();
     
    			FastPin<ILI9341_SCLK_PIN>::hi();
    			FastPin<ILI9341_SCLK_PIN>::lo();
    		}
    	}
    	static void spiWrite16(uint16_t data) __attribute__((noinline))	{
    		spiWrite(data >> 8);
    		spiWrite(data & 0xff);
    	}
    #endif
    	static INLINE void spiWrite_preCmd(uint8_t data) INLINE_OPT	{
    		spiWrite(data);
    	}
    	static INLINE void spiWrite16_preCmd(uint16_t data) INLINE_OPT	{
    		spiWrite16(data);
    	}
    	static INLINE void spiWrite16_lineDraw(uint16_t data) INLINE_OPT	{
    		spiWrite16(data);
    	}
    	static INLINE void spiWrite16(uint16_t data, int count) INLINE_OPT	{
    		while (count-- > 0)
    			spiWrite16(data);
    	}
    	static inline void delay10()	{ }
    	static inline void delay13()	{ }
    	static inline void delay15()	{ }
    	static inline void delay17()	{ }
    #endif
    	// write SPI byte with RS (aka D/C) pin set low to indicate a command byte (and then reset back to high when done)
    	static INLINE void writeCommand(uint8_t data) INLINE_OPT	{
    		FastPin<ILI9341_DC_PIN>::lo();		// RS <= LOW indicate command byte
    		spiWrite_preCmd(data);
    		FastPin<ILI9341_DC_PIN>::hi();		// RS <= HIGH indicate data byte (always assumed left in data mode)
    	}
    	// write SPI byte with RS assumed low indicating a data byte
    	static inline void writeData(uint8_t data) __attribute__((always_inline))	{
    		spiWrite(data);
    	} 
    	// internal version that does not spi_begin()/spi_end()
    	static INLINE void setAddrWindow_(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) INLINE_OPT	{
    		writeCommand(ILI9341_CASET); 		// column address set
    		spiWrite16(x0);				// XSTART
    		spiWrite16_preCmd(x1);			// XEND
    		writeCommand(ILI9341_PASET); 		// row address set
    		spiWrite16(y0);				// YSTART
    		spiWrite16_preCmd(y1);		 	// YEND
    		writeCommand(ILI9341_RAMWR); 		// write to RAM
    	}
    #if ILI9341_SAVE_SPCR && defined(AVR_HARDWARE_SPI)
    	static volatile uint8_t	save_SPCR;	// initial SPCR value/saved SPCR value (swapped in spi_begin/spi_end)
    #endif
     
    	PDQ_ILI9341();
    	static void inline begin(void);
     
    	static void drawPixel(int x, int y);
    	static void drawFastVLine(int x, int y, int h);
    	static void drawFastHLine(int x, int y, int w);
    	static void setRotation(uint8_t r);
    	static void drawFastBitmap(uint8_t *bitmap, uint8_t angleFM);
    	static void drawFastChar(coord_t x, coord_t y, unsigned char c);
    	static void fillScreen();
    	static void drawLine(int x0, int y0, int x1, int y1);
    	static void fillRect(int x, int y, int w, int h);
    	static void DrawButtonFrame(byte mode);
    	static void setFont(byte params, byte textSize);
     
    	static void drawRect();
     
    	static int getButtonCornerX();
    	static int getButtonCornerY();
    	static void drawCircle();
    	static void drawCircleHelper(coord_t x0, coord_t y0, coord_t r, uint8_t cornername);
    	static void fillCircle();
    	static void fillCircleHelper(coord_t x0, coord_t y0, coord_t r, uint8_t cornername, coord_t delta);
    	static void drawTriangle();
    	static void fillTriangle();
    	static void drawRoundRect();
    	static void fillRoundRect();
     
    	virtual size_t write(uint8_t); // Called by Arduino "Print.h"
     
     	static coord_t	cursor_x, cursor_y;
    	static boolean	wrap;				// If set, 'wrap' text at right edge of display
    	static uint8_t	rotation;
     
    protected:	
     	static coord_t	WIDTH, HEIGHT;		// This is the 'raw' display w/h - never changes
    	static coord_t	_width, _height;	// Display w/h as modified by current rotation
     
    	static uint8_t	GLOBAL_FontSizeX; // Taille de la police
    	static uint8_t	GLOBAL_FontSizeY; // Taille de la police
    	static int16_t	GLOBAL_FontBits; // Nombre de bits par caractère
    	static uint8_t	GLOBAL_CarSpace; // Nombre de pixels entre chaque caractère 
    	static uint8_t	GLOBAL_LineSpace; // Nombre de pixels entre chaque ligne
    	static uint8_t	GLOBAL_MinAscii; // Code ASCII le plus petit affichable
    	static uint8_t	GLOBAL_MaxAscii; // Code ASCII le plus grand affichable
    	static char* GLOBAL_FontAdrr; // Adresse de la police
     
    	static uint8_t	GLOBAL_TextSize;
     
    	static uint8_t carWidth;
    	static uint8_t carHeight;	
     
    	static uint8_t flagTabXY;	
    };
     
    #if ILI9341_SAVE_SPCR && defined(AVR_HARDWARE_SPI)
    // static data needed by base class
    volatile uint8_t PDQ_ILI9341::save_SPCR;
    #endif
     
    int16_t		PDQ_ILI9341::WIDTH;			// This is the 'raw' display w/h - never changes
    int16_t		PDQ_ILI9341::HEIGHT;
    int16_t		PDQ_ILI9341::_width;		// Display w/h as modified by current rotation
    int16_t		PDQ_ILI9341::_height;
    int16_t		PDQ_ILI9341::cursor_x;
    int16_t		PDQ_ILI9341::cursor_y;
    uint8_t		PDQ_ILI9341::rotation;
    boolean		PDQ_ILI9341::wrap;			// If set, 'wrap' text at right edge of display
    uint8_t		PDQ_ILI9341::GLOBAL_FontSizeX;
    uint8_t		PDQ_ILI9341::GLOBAL_FontSizeY;
    int16_t		PDQ_ILI9341::GLOBAL_FontBits;
    uint8_t		PDQ_ILI9341::GLOBAL_CarSpace;
    uint8_t		PDQ_ILI9341::GLOBAL_LineSpace;
    uint8_t		PDQ_ILI9341::GLOBAL_MinAscii;
    uint8_t		PDQ_ILI9341::GLOBAL_MaxAscii;
    char*		PDQ_ILI9341::GLOBAL_FontAdrr;
    uint8_t		PDQ_ILI9341::GLOBAL_TextSize;
    uint8_t		PDQ_ILI9341::carWidth;
    uint8_t		PDQ_ILI9341::carHeight;
    uint8_t		PDQ_ILI9341::flagTabXY;
     
    PDQ_ILI9341::PDQ_ILI9341()  {
    	WIDTH		= (int16_t)TFT_SIZE_WIDTH;
    	HEIGHT		= (int16_t)TFT_SIZE_HEIGHT;
    	_width		= (int16_t)TFT_SIZE_WIDTH;
    	_height		= (int16_t)TFT_SIZE_HEIGHT;
    	rotation	= 1; // Needed to force SetRotation() to send data to TFT screen in Begin()
    	wrap		= true;
    	flagTabXY = 0;
    #if defined(AVR_HARDWARE_SPI)
    	// must reference these functions from C++ or they will be stripped by linker (called from inline asm)
    	delay10();
    	delay13();
    	delay15();
    	delay17();
    #endif
    }
     
    // Companion code to the above tables.  Reads and issues a series of LCD commands stored in PROGMEM byte array.
    void PDQ_ILI9341::commandList(const uint8_t *addr) {
    	uint8_t	numCommands, numArgs;
    	uint16_t ms;
    	numCommands = pgm_read_byte(addr++);		// Number of commands to follow
    	while (numCommands--) {				// For each command...
    		writeCommand(pgm_read_byte(addr++));	// Read, issue command
    		numArgs	= pgm_read_byte(addr++);	// Number of args to follow
    		ms = numArgs & DELAY;			// If hibit set, delay follows args
    		numArgs &= ~DELAY;			// Mask out delay bit
    		while (numArgs--) {			// For each argument...
    			writeData(pgm_read_byte(addr++)); // Read, issue argument
    		}
    		if (ms)	{
    			ms = pgm_read_byte(addr++);	// Read post-command delay time (ms)
    			if(ms == 255)
    				ms = 500;		// If 255, delay for 500 ms
    			delay(ms);
    		}
    	}
    }
     
    void PDQ_ILI9341::begin(void) {
    	// set CS and RS pin directions to output
    	FastPin<ILI9341_CS_PIN>::setOutput();
    	FastPin<ILI9341_DC_PIN>::setOutput();
    #if !defined(AVR_HARDWARE_SPI)
    	#if defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
    		USICR = (0<<USISIE)|(0<<USIOIE)|(0<<USIWM1)|(1<<USIWM0)|(0<<USICS1)|(1<<USICS0)|(1<<USICLK)|(0<<USITC);
    	#endif
    	#if defined (ILI9341_MISO_PIN)
    		FastPin<ILI9341_MISO_PIN>::setInput();
    	#endif
    	FastPin<ILI9341_MOSI_PIN>::setOutput();
    	FastPin<ILI9341_SCLK_PIN>::setOutput();
    	FastPin<ILI9341_MOSI_PIN>::lo();
    	FastPin<ILI9341_SCLK_PIN>::lo();
    #endif
    	FastPin<ILI9341_CS_PIN>::hi();		// CS <= HIGH (deselected, so no spurious data)
    	FastPin<ILI9341_DC_PIN>::hi();		// RS <= HIGH (default data byte)
    #if defined(AVR_HARDWARE_SPI)
    	#if ILI9341_SAVE_SPCR
    		uint8_t oldSPCR = SPCR;	// save initial SPCR settings
    	#endif	
    	SPI.begin();
    	SPI.setBitOrder(MSBFIRST);
    	SPI.setDataMode(SPI_MODE0);
    	SPI.setClockDivider(SPI_CLOCK_DIV2);	// 8 MHz (full! speed!) [1 byte every 18 cycles]
    #endif
    #if ILI9341_SAVE_SPCR && defined(AVR_HARDWARE_SPI)
    	save_SPCR = SPCR;	// save SPCR settings
    	SPCR = oldSPCR;		// restore previous SPCR settings (spi_begin/spi_end will switch between the two)
    #endif	
    	spi_begin();
    	// Initialization commands for ILI9341 screens
    	static const uint8_t ILI9341_cmds[] PROGMEM = {
    		22,
    		ILI9341_SWRESET, DELAY,		// 1
    		5,
    		0xEF, 3,			// 2
    		0x03, 0x80, 0x02,
    		0xCF, 3,			// 3
    		0x00, 0xC1, 0x30,
    		0xED, 4,			// 4
    		0x64, 0x03, 0x12, 0x81,
    		0xE8, 3,			// 5
    		0x85, 0x00, 0x78,
    		0xCB, 5,			// 6
    		0x39, 0x2C, 0x00, 0x34, 0x02,
    		0xF7, 1,			// 7
    		0x20,
    		0xEA, 2,			// 8
    		0x00, 0x00,
    		ILI9341_PWCTR1, 1,		// 9 power control 
    		0x23,				// VRH[5:0] 
    		ILI9341_PWCTR2, 1,		// 10 power control 
    		0x10,				// SAP[2:0];BT[3:0]  
    		ILI9341_VMCTR1, 2,		// 11 VCM control 
    		0x3e, 0x28,
    		ILI9341_VMCTR2, 1,		// 12 VCM control2 
    		0x86,				// --
    		ILI9341_MADCTL, 1,		// 13
    		(ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR),
    		ILI9341_PIXFMT, 1,		// 14
    		0x55,
    		ILI9341_FRMCTR1, 2,		// 15
    		0x00, 0x18,
    		ILI9341_DFUNCTR, 3,		// 16
    		0x08, 0x82, 0x27,
    		0xF2, 1,			// 17 3Gamma Function Disable 
    		0x00,
    		ILI9341_GAMMASET, 1,		// 18 Gamma curve selected 
    		0x01,
    		ILI9341_GMCTRP1, 15,		// 19 Set Gamma 
    		0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
    		ILI9341_GMCTRN1, 15,		// 20
    		0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
    		ILI9341_SLPOUT, DELAY,		// 21
    		120,
    		ILI9341_DISPON, 0,		// 22
    	};
    	commandList(ILI9341_cmds);
    	spi_end();
    	setRotation(0);
    }
     
    // === FONT MANAGEMENT ==========================================================================================
    //
    // You can change, remove or add fonts here
    //
    // WARNING ! RLucas_glcdfont_compact2.h IS USED BY SETUP MENU - PLEASE READ COMMENTS IN .INO FILE AT LINE 348
    //
    #include "RLucas_glcdfont_compact.h"    // Include here the .h file for font n°0
    #include "RLucas_glcdfont_compact2.h"   // Include here the .h file for font n°1
    #include "RLucas_glcdfont_compact3.h"   // Include here the .h file for font n°2
    //#include "RLucas_glcdfont_compact4.h" // Include here the .h file for font n°3
    void PDQ_ILI9341::setFont(byte params, byte textSize) {
      // params = LineSpace * 32 + CarSpace * 4 + FontIndex
      GLOBAL_TextSize = textSize;
      GLOBAL_LineSpace = (params & 0b11100000) >> 5;
      GLOBAL_CarSpace = (params & 0b00011100) >> 2;
      switch (params & 0b00000011) {
      case 0:
    	GLOBAL_FontAdrr = RLucas_glcdfont_compact;  // Type here PROGMEM name of font n°0
    	break;
      case 1:
    	GLOBAL_FontAdrr = RLucas_glcdfont_compact2;  // Type here PROGMEM name of font n°1
    	break;
      case 2:
    	GLOBAL_FontAdrr = RLucas_glcdfont_compact3;  // Type here PROGMEM name of font n°2
    	break;
      case 3:
    	//GLOBAL_FontAdrr = RLucas_glcdfont_compact4;  // Type here PROGMEM name of font n°3
    	break;
      }
      GLOBAL_FontSizeX = pgm_read_byte(GLOBAL_FontAdrr);
      GLOBAL_FontSizeY = pgm_read_byte(GLOBAL_FontAdrr+1);
      GLOBAL_MinAscii = pgm_read_byte(GLOBAL_FontAdrr+2);
      GLOBAL_MaxAscii = pgm_read_byte(GLOBAL_FontAdrr+3);
      GLOBAL_FontAdrr +=4 ;
      GLOBAL_FontBits = GLOBAL_FontSizeX * GLOBAL_FontSizeY;
      carWidth = GLOBAL_FontSizeX  * GLOBAL_TextSize + GLOBAL_CarSpace; 
      carHeight = GLOBAL_FontSizeY  * GLOBAL_TextSize + GLOBAL_LineSpace;
    }
    // ==============================================================================================================
     
    void Rainbow_Colour(int xy) {
    	byte R;
    	byte G;
    	byte B;
    	if (RainbowFunc_UseBG) {
    		R = Rainbow_BG_R;
    		G = Rainbow_BG_G;
    		B = Rainbow_BG_B;
    		if (Rainbow_BG_Swap) {
    			//xy = Rainbow_BG_WH - 1 - xy - Rainbow_BG_XY_min;
    			xy = Rainbow_BG_WH - xy;
    		} else {
    			xy -= Rainbow_BG_XY_min;
    		}
    		if (xy >= Rainbow_BG_XY_delta) {
    			R += Rainbow_BG_DR;
    			G += Rainbow_BG_DG;
    			B += Rainbow_BG_DB;
    		} else if (xy > 0) {
    			if (Rainbow_BG_DR !=0) R += Rainbow_BG_DR * xy / Rainbow_BG_XY_delta;
    			if (Rainbow_BG_DG !=0) G += Rainbow_BG_DG * xy / Rainbow_BG_XY_delta;
    			if (Rainbow_BG_DB !=0) B += Rainbow_BG_DB * xy / Rainbow_BG_XY_delta;
    		}
    	} else {
    		R = Rainbow_R;
    		G = Rainbow_G;
    		B = Rainbow_B;
    		if (Rainbow_Swap) {
    			//xy = Rainbow_WH - 1 - xy - Rainbow_XY_min;
    			xy = Rainbow_WH - xy;
    		} else {
    			xy -= Rainbow_XY_min;
    		}
    		if (xy >= Rainbow_XY_delta) {
    			R += Rainbow_DR;
    			G += Rainbow_DG;
    			B += Rainbow_DB;
    		} else if (xy > 0) {
    			if (Rainbow_DR !=0) R += Rainbow_DR * xy / Rainbow_XY_delta;
    			if (Rainbow_DG !=0) G += Rainbow_DG * xy / Rainbow_XY_delta;
    			if (Rainbow_DB !=0) B += Rainbow_DB * xy / Rainbow_XY_delta;
    		}
    	}
    	GLOBAL_Colour = (R << 11) | (G << 5) | B;
    }
     
    void Rainbow_BG_Colour(int xy) {
    	byte R;
    	byte G;
    	byte B;
    	R = Rainbow_BG_R;
    	G = Rainbow_BG_G;
    	B = Rainbow_BG_B;
    	if (Rainbow_BG_Swap) {
    		//xy = Rainbow_BG_WH - 1 - xy - Rainbow_BG_XY_min;
    		xy = Rainbow_BG_WH  - xy;
    	} else {
    		xy -= Rainbow_BG_XY_min;
    	}
    	if (xy >= Rainbow_BG_XY_delta) {
    		R += Rainbow_BG_DR;
    		G += Rainbow_BG_DG;
    		B += Rainbow_BG_DB;
    	} else if (xy > 0) {
    		if (Rainbow_BG_DR !=0) R += Rainbow_BG_DR * xy / Rainbow_BG_XY_delta;
    		if (Rainbow_BG_DG !=0) G += Rainbow_BG_DG * xy / Rainbow_BG_XY_delta;
    		if (Rainbow_BG_DB !=0) B += Rainbow_BG_DB * xy / Rainbow_BG_XY_delta;
    	}
    	GLOBAL_ColourBG = (R << 11) | (G << 5) | B;
    }
     
    void RainbowSelect(byte colour_index) {
    	// This function allows Rainbow_Colour to use Rainbow_BG_Colour parameters
    	if (BG_Coul_Index == colour_index) {
    		RainbowFunc_UseBG = true;
    		RainbowFunc_Mode = Rainbow_BG_Mode;
    		RainbowFunc_X_Direction = Rainbow_BG_X_Direction;
    	} else {
    		RainbowFunc_UseBG = false;
    		RainbowFunc_Mode = Rainbow_Mode;
    		RainbowFunc_X_Direction = Rainbow_X_Direction;
    	}
    }
     
    void Rainbow_Swap_XY(int WH) {
    	Rainbow_Swap = !Rainbow_Swap;
    	Rainbow_WH = WH - 1 - Rainbow_XY_min;
    }
     
    void Rainbow_BG_Swap_XY(int WH) {
    	Rainbow_BG_Swap = !Rainbow_BG_Swap;
    	Rainbow_BG_WH = WH - 1 - Rainbow_BG_XY_min;
    }
     
    void PDQ_ILI9341::setRotation(uint8_t m) {
    	byte rot;
    	rot =  (4 + m - rotation) & 3 ; // 'rot' is the rotation made by the 'rotation' to 'm' orientation change
    	if (rot == 0) return;
    	rotation = m; 
     
    	spi_begin();
    	writeCommand(ILI9341_MADCTL);
    	switch (m) {
    	case 0:
    		writeData(ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR);
    		_width	= TFT_SIZE_WIDTH;
    		_height = TFT_SIZE_HEIGHT;
    		break;
    	case 1:
    		writeData(ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR);
    		_width	= TFT_SIZE_HEIGHT;
    		_height = TFT_SIZE_WIDTH;
    		break;
    	case 2:
    		writeData(ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR);
    		_width	= TFT_SIZE_WIDTH;
    		_height = TFT_SIZE_HEIGHT;
    		break;
    	case 3:
    		writeData(ILI9341_MADCTL_MV | ILI9341_MADCTL_MY | ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR);
    		_width	= TFT_SIZE_HEIGHT;
    		_height = TFT_SIZE_WIDTH;
    		break;
    	}
    	spi_end();	
     
    	// WARNING ! We have to turn also RAINBOW PARAMETERS !
    	// => It's user friendly for Rainbows
    	// => It's NECESSARY for bitmaps Rainbows (bitmaps use TFT screen rotation feature)
    	if (rot==2) { // +180° -180°
    		if (Rainbow_X_Direction) {
    			Rainbow_Swap_XY(_width);
    		} else {
    			Rainbow_Swap_XY(_height);
    		}
    		if (Rainbow_BG_X_Direction) {
    			Rainbow_BG_Swap_XY(_width);
    		} else {
    			Rainbow_BG_Swap_XY(_height);
    		}
    	} else { // +90° -270° or +270° -90°
    		Rainbow_X_Direction = !Rainbow_X_Direction;
    		Rainbow_BG_X_Direction = !Rainbow_BG_X_Direction;		
    		RainbowFunc_X_Direction = !RainbowFunc_X_Direction; // Also important !
    		if (rot == 1) { // +90° -270°
    			if (!Rainbow_X_Direction) {
    				Rainbow_Swap_XY(_height);
    			}
    			if (!Rainbow_BG_X_Direction) {
    				Rainbow_BG_Swap_XY(_height);
    			}
    		} else { //+270° -90°
    			if (Rainbow_X_Direction) {
    				Rainbow_Swap_XY(_width);
    			}
    			if (Rainbow_BG_X_Direction) {
    				Rainbow_BG_Swap_XY(_width);
    			}
    		}
    	}
    }
     
    void PDQ_ILI9341::DrawButtonFrame(byte mode=0) { // 0 = after Print ; 1 = after Bitmap ; 2 = direct DrawBouton() call
    	if ((GLOBAL_Button_Offset == 0) && (mode!=2)) return;
    	// - mode 0 : SetTextCursor previously defined GLOBAL_X1, GLOBAL_Y1
    	// - mode 1 : DrawBitmap previously defined GLOBAL_X1, GLOBAL_Y1 as top left corner and GLOBAL_X2, GLOBAL_Y2 as bottom right corner
    	// - mode 2 : GLOBAL_X1, GLOBAL_Y1, GLOBAL_X2, GLOBAL_Y2 are set up for direct use
    	int X,Y,W,H; // Allow compiler to use registers
    	X = GLOBAL_X1;
    	Y = GLOBAL_Y1;
    	if (mode==0) {
    		W = getButtonCornerX();
    		H = getButtonCornerY();
    	} else {
    		W = GLOBAL_X2;
    		H = GLOBAL_Y2;
    	}
    	if (mode!=2) {
    		W += 2 * GLOBAL_Button_Offset - GLOBAL_X1;
    		H += 2 * GLOBAL_Button_Offset - GLOBAL_Y1;
    		X -= GLOBAL_Button_Offset;
    		Y -= GLOBAL_Button_Offset;
    	}
    	GLOBAL_Colour = Colour[Index_Colour_ButtonTopLeft]; // 11 : Top left border
    	drawFastHLine(X, Y, W + 1); 
    	drawFastVLine(X, Y, H);
    	GLOBAL_Colour = Colour[Index_Colour_ButtonBottomRightExt]; // 13 : Bottom right ext border
    	drawFastHLine(X + 1, Y + H - 1, W); 
    	drawFastVLine(X + W, Y + 1, H - 1);
    	GLOBAL_Colour = Colour[Index_Colour_ButtonBottomRightInt]; // 12 : Bottom right int border
    	drawFastHLine(X, Y + H, W + 2); 
    	drawFastVLine(X + W + 1, Y, H + 1);
    }
     
    int PDQ_ILI9341::getButtonCornerX() {
    	//return cursor_x + carWidth - GLOBAL_CarSpace;
    	return cursor_x - GLOBAL_CarSpace; // '+carWidth' already done by write()
    }
     
    int PDQ_ILI9341::getButtonCornerY() {
    	return cursor_y + carHeight - GLOBAL_LineSpace; 
    }
     
    void PDQ_ILI9341::drawPixel(int x, int y) {
    	// WARNING : It's very stupid to call this function a lot of time to draw something
    	// ILI9341 screen is designed to :
    	//   - define a rectangular window
    	//   - "fill" this window with 'pushcolor' instructions
    	spi_begin();
    	setAddrWindow_(x, y, x, y); 
    	if (RainbowFunc_Mode) {
    		if (RainbowFunc_X_Direction) {
    			Rainbow_Colour(x);
    		} else {
    			Rainbow_Colour(y);
    		}		
    	}
    	spiWrite16_preCmd(GLOBAL_Colour);
    	spi_end();
    }
     
    void PDQ_ILI9341::drawFastVLine(int x, int y, int h) {
    	spi_begin();
    	setAddrWindow_(x, y, x, _height);
    	if (RainbowFunc_Mode) {
    		if (RainbowFunc_X_Direction) {
    			Rainbow_Colour(x);
    			spiWrite16(GLOBAL_Colour, h);
    		} else {
    			for (; h > 0; h--) {
    				Rainbow_Colour(y);
    				spiWrite16(GLOBAL_Colour);
    				y++;
    			}
    		}
    	} else {
    		spiWrite16(GLOBAL_Colour, h);
    	}
    	spi_end();
    }
     
    void PDQ_ILI9341::drawFastHLine(int x, int y, int w) {
    	spi_begin();
    	setAddrWindow_(x, y, _width, y);
    	if (RainbowFunc_Mode) {
    		if (RainbowFunc_X_Direction) {
    			for (; w > 0; w--) {
    				Rainbow_Colour(x);
    				spiWrite16(GLOBAL_Colour);
    				x++;
    			}
    		} else {
    			Rainbow_Colour(y);
    			spiWrite16(GLOBAL_Colour, w);
    		}
    	} else {
    		spiWrite16(GLOBAL_Colour, w);
    	}
    	spi_end();
    }
     
    void PDQ_ILI9341::fillScreen() {
    	fillRect(0, 0, _width, _height);
    }
     
    void PDQ_ILI9341::fillRect(int x, int y, int w, int h) {
    	spi_begin();
    	if (RainbowFunc_Mode) {
    		if (RainbowFunc_X_Direction) {
    			for (; w > 0; w--) { // w vertical lines
    				setAddrWindow_(x, y, x, _height);
    				Rainbow_Colour(x);
    				spiWrite16(GLOBAL_Colour, h);
    				x++;
    			}
    		} else {
    			for (; h > 0; h--) { // h horizontal lines
    				setAddrWindow_(x, y, _width, y);
    				Rainbow_Colour(y);
    				spiWrite16(GLOBAL_Colour, w);
    				y++;
    			}
    		}
    	} else { // We can't use spiWrite16(GLOBAL_Colour, h*w) because h*w can be > 65535
    		setAddrWindow_(x, y, x+w-1, _height);
    		if (w > h) {
    			x = w;
    			w = h;
    			h = x;
    		}
    		for (; w > 0; w--) {
    			spiWrite16(GLOBAL_Colour, h);
    		}	
    	}
    	spi_end();	
    }
     
    void PDQ_ILI9341::drawFastBitmap(uint8_t *bitmap, uint8_t angleFM) {
    	coord_t x, x2, y2, x1, y1;
    	coord_t w, h;
    	byte compression;
    	byte tmp;
    	byte rotation_backup;
    	int nbPixToPrint;
    	int i;
    	bool colorToPrint;
    	bool mirror;
     
    	// Reading bitmap header :
    	compression = bitmap[0];
    	w = bitmap[1];
    	h = bitmap[2];
    	if (compression & 0b10000000) w +=256;
    	if (compression & 0b01000000) h +=256;
    	compression = compression & 0b00111111; // 0 = No compression / 1 = Compression / 2 = Compression for large bitmaps
    	bitmap+=3; // Bitmap data start @ bitmap[3]
     
    	// Use TFT screen rotation for bitmap rotation :
    	mirror = angleFM > 3;
    	angleFM &= 3;
    	switch (angleFM) {
    	case 0:
    		x1 = GLOBAL_X1;
    		y1 = GLOBAL_Y1;
    		break;
    	case 1:
    		x1 = GLOBAL_Y1;
    		y1 = _width - GLOBAL_X1 - h;
    		break;
    	case 2:
    		x1 = _width - GLOBAL_X1 - w;
    		y1 = _height - GLOBAL_Y1 - h;
    		break;
    	case 3:
    		x1 = _height - GLOBAL_Y1 - w;
    		y1 = GLOBAL_X1;
    		break;
    	}
    	if (angleFM>0) {
    		rotation_backup = rotation;
    		setRotation((rotation + angleFM) & 3);
    	}
     
    	// Drawing :
    	spi_begin();
    	if (GLOBAL_Button_Offset!=0) {
    		if (angleFM & 1) {
    			GLOBAL_X2 = GLOBAL_X1 + h - 1;
    			GLOBAL_Y2 = GLOBAL_Y1 + w;
    		} else {
    			GLOBAL_X2 = GLOBAL_X1 + w - 1;
    			GLOBAL_Y2 = GLOBAL_Y1 + h;
    		}
    	}
    	x = x1;
    	x2 = x + w - 1;
    	if (mirror) {
    		y2 = y1 + h;
    	} else {
    		setAddrWindow_(x1, y1, x2, _height);	
    		y2 = y1 - 1;
    	}
    	i = 0;
    	nbPixToPrint = 0;
    	do {
    		if (x == x1) {
    			// Begin new line :
    			if (mirror) {
    				y2--;
    				setAddrWindow_(x1, y2, x2, _height);	
    			} else {
    				y2++; 
    			}
    			if (RainbowFunc_Mode && !RainbowFunc_X_Direction) Rainbow_Colour(y2);
    			if (Rainbow_BG_Mode && !Rainbow_BG_X_Direction) Rainbow_BG_Colour(y2);
    		}
     
    		// Find color and number of pixels to print:
    		if (compression == 0) { 
    			// No compression - Each bit of bitmap[] is the pixel number 'i'
    			colorToPrint = bitmap[i >> 3] & (0b10000000 >> (i & 0b111));
    			i++; // For very large bitmaps, 'i' should be a LONG value... but without compression it will never appends
    		} else {
    			// Compression : bitmap[] bytes define a color and the number of pixel that use this color
    			if (nbPixToPrint == 0) {
    				// 'i' is used as bitmap[] byte index
    				tmp = bitmap[i];
    				i++;
    				colorToPrint = tmp & 0b10000000;
    				if (compression == 1) {
    					nbPixToPrint = tmp & 0b01111111;
    				} else {
    					nbPixToPrint = tmp & 0b00111111;
    					if (tmp & 0b01000000) {
    						nbPixToPrint = bitmap[i] + (nbPixToPrint << 8);
    						i++;    
    					}
    				}
    			}
    			nbPixToPrint--;
    		}
    		if (colorToPrint) {
    			if (RainbowFunc_Mode && RainbowFunc_X_Direction) Rainbow_Colour(x);
    			spiWrite16(GLOBAL_Colour);
    		} else {
    			if (Rainbow_BG_Mode && Rainbow_BG_X_Direction) Rainbow_BG_Colour(x);
    			spiWrite16(GLOBAL_ColourBG);
    		}
    		// Update coordinates:
    		x++;
    		if (x > x2) {
    			x = x1;
    			h--;
    		}
    	} while (h>0);
    	spi_end();
     
    	if (angleFM>0) setRotation(rotation_backup);
    }
     
    // Very fast text writing, that use custom fonts stored without dummy bits 
    // Space and tabs are printed faster, and fonts don't have to include space or tabs chars (it saves memory)
    // Moreover, this function allows 'in-text' instructions with non printable ASCII codes
    // It's a very goog feature that save memory usage and allows easier display update with texts stored in Buffer_RAM[]
    // This function is called by .print()... and .print() use \0 char for end of text... so 'c' can't be equal to zero !
    // So we have to deal with this for 'in-text' instructions parameters :
    // - if X param has to be between 0 and 254, then c = X + 1
    // - if X param has to be between 255 and 509, then c = X - 254
    size_t PDQ_ILI9341::write(uint8_t c) {
    	int8_t i;
    	int8_t j;
    	int8_t k;
    	int8_t u;
    	unsigned int numPix;
    	if (flagTabXY!=0) {
    		// Here, 'c' is values used to change text cursor :
    		// flagTabXY = 1 Set Text Cursor  X < 254
    		// flagTabXY = 2 Set Text Cursor  X < 254  Y < 254
    		// flagTabXY = 3 Set Text Cursor  X < 254  Y > 254
    		// flagTabXY = 4 Set Text Cursor  X > 254
    		// flagTabXY = 5 Set Text Cursor  X > 254  Y < 254
    		// flagTabXY = 6 Set Text Cursor  X > 254  Y > 254
    		// flagTabXY = 7 Set Text Cursor  Y < 254
    		// flagTabXY = 8 Set Text Cursor  Y > 254
    		i = 0;
    		j = flagTabXY;
    		c--; // needed because c can be equal to zero
     
    		if (j>6) { //  7 8
    			cursor_y = c;
    			if (j==8) {
    				cursor_y += 254 ;
    			}
    		} else { // 1 2 3 4 5 6
    			cursor_x = c; 
    			if (j>3) { // 4 5 6
    				cursor_x += 254 ;
    				j -= 3; // 4->1 5->2 6->3 
    			}
    			if (j>1) {   // 2 3 5 6
    				i = j+5; // 7 8 7 8 
    			}
    		}
    		flagTabXY = i;
    		if (i==0)  {
    			// Here, 'Set Text Cursor' in-text instruction is ended.
    			// We have to store Text Cursor value, needed if we have to draw buttons
    			GLOBAL_X1 = cursor_x;
    			GLOBAL_Y1 = cursor_y;
    		}
    		return 1;
    	}
    	if (c == '\n') {
    		// Line feed :
    		cursor_x = 0;
    		cursor_y += carHeight;
    	} else if (c <GLOBAL_MinAscii) {
    		// ASCII codes < 33 are 'in-text' instructions :	
    		if ((c>17)&&(c<32)) {
    			// Color change
    			c -= 18;
    			// c is the new color index :
    			RainbowSelect(c);
    			GLOBAL_Colour = Colour[c]; 
    		} else if (c!=13) {
    			if (c<9) {
    				// Set Text Cursor, followed by X and/or Y cursor values
    				flagTabXY = c; 
    				if (GLOBAL_Button_Offset != 0) {
    					// Here, we have finished to print a text, so we have to draw a button frame arround :
    					// WARNING ! There is a problem if a text begin by a "Set cursor" in-text instruction
    					// so when GLOBAL_Button_Offset>0 a text CANNOT begin by a "Set cursor" in-text instruction
    					unsigned int colourBackup;
    					colourBackup = GLOBAL_Colour;
    					DrawButtonFrame();
    					GLOBAL_Colour = colourBackup;
    				}
    			} else {
    				// Tabs in text
    				// c value:       9, 11, 12, 14, 15, 16, 17, ou 32 
    				// tabs (spaces): 2,  3,  4,  5,  6,  7,  8,     1
    				if (c<14) c++;
    				if (c==10) c++;
    				if (c==32) c=10;
    				c -= 9;
    				spi_begin();
    				if (Rainbow_BG_Mode) {
    					if (Rainbow_BG_X_Direction) {
    						// Write tab as several vertical lines
    						for (i=0;i<carWidth*c;i++) {
    							setAddrWindow_(cursor_x+i, cursor_y, cursor_x+i, _height); 
    							Rainbow_BG_Colour(cursor_x + i);
    							spiWrite16(GLOBAL_ColourBG, carHeight);
    						}
    					} else {
    						setAddrWindow_(cursor_x, cursor_y, cursor_x + carWidth * c  - 1, _height); 
    						// Write tab as several horizontal lines
    						for (j=0;j<carHeight;j++) {
    							Rainbow_BG_Colour(cursor_y + j);
    							spiWrite16(GLOBAL_ColourBG, carWidth * c);
    						}
    					}
    				} else {
    					// Write tab as fill rectangle
    					setAddrWindow_(cursor_x, cursor_y, cursor_x + carWidth * c  - 1, _height); 
    					spiWrite16(GLOBAL_ColourBG, carWidth * carHeight * c);
    				}
    				spi_end();
    				cursor_x += carWidth * c ; 
    			}
    		}
    	} else {
    		if (cursor_x > (_width - carWidth)) { // X : Clipping or wrapping
    			if (wrap) {
    				cursor_x = 0;
    				cursor_y += carHeight; 
    			} else {
    				return 1;
    			}
    		}
    		if (cursor_y >= _height) return 1; // Y : Clipping
    		if (c <= GLOBAL_MaxAscii) {
    			numPix = (c - GLOBAL_MinAscii) * GLOBAL_FontBits;
    			spi_begin();
    			setAddrWindow_(cursor_x, cursor_y, cursor_x + carWidth - 1, _height); 
    			// If GLOBAL_TextSize = 3 then each pixel of each char is a SQUARE of 3 x 3 pixels
    			// Keep in mind that: in computer graphics, a pixel is a SQUARE, not a DOT
    			for (j=0; j<GLOBAL_FontSizeY; j++) { 
    				for (k = 0; k<GLOBAL_TextSize ; k++) {
    					if (k!=0) numPix -= GLOBAL_FontSizeX; 
    					if (RainbowFunc_Mode && !RainbowFunc_X_Direction) {
    						Rainbow_Colour(cursor_y + j * GLOBAL_TextSize + k);
    					}
    					if (Rainbow_BG_Mode && !Rainbow_BG_X_Direction) {
    						Rainbow_BG_Colour(cursor_y + j * GLOBAL_TextSize + k);
    					}
    					for (i=0; i<GLOBAL_FontSizeX; i++) { 
    						if (pgm_read_byte(GLOBAL_FontAdrr+(numPix>>3)) & (0b00000001 << (numPix & 0b111))) { 
    							// Pixel de coordonnées
    							// X = i + cursor_x
    							// Y = j * GLOBAL_TextSize + k + cursor_y
    							if (RainbowFunc_Mode && RainbowFunc_X_Direction) {
    								for (u=0; u<GLOBAL_TextSize; u++) {
    									Rainbow_Colour(cursor_x + i * GLOBAL_TextSize + u);
    									spiWrite16(GLOBAL_Colour);
    								}
    							} else {
    								spiWrite16(GLOBAL_Colour, GLOBAL_TextSize);
    							}
    						} else {
    							if (Rainbow_BG_Mode && Rainbow_BG_X_Direction) {
    								for (u=0; u<GLOBAL_TextSize; u++) {
    									Rainbow_BG_Colour(cursor_x + i * GLOBAL_TextSize + u);
    									spiWrite16(GLOBAL_ColourBG);
    								}
    							} else {
    								spiWrite16(GLOBAL_ColourBG, GLOBAL_TextSize);
    							}
    						}
    						numPix++; 
    					}
    					if (Rainbow_BG_Mode && Rainbow_BG_X_Direction) {
    						for (u=0; u<GLOBAL_CarSpace; u++) {
    							Rainbow_BG_Colour(cursor_x + GLOBAL_FontSizeX * GLOBAL_TextSize + u);
    							spiWrite16(GLOBAL_ColourBG); // Space between chars
    						}
    					} else {
    						spiWrite16(GLOBAL_ColourBG, GLOBAL_CarSpace); // Space between chars
    					}
    				}
    			}
    			if (Rainbow_BG_Mode) {
    				// Rectangle : GLOBAL_LineSpace *  carWidth
    				if (Rainbow_BG_X_Direction) {
    					for (j=0; j<GLOBAL_LineSpace; j++) {
    						for (i=0; i<carWidth; i++) {
    							Rainbow_BG_Colour(cursor_x + i);
    							spiWrite16(GLOBAL_ColourBG); // Space between lines
    						}
    					}
    				} else {
    					for (j=0; j<GLOBAL_LineSpace; j++) {
    						Rainbow_BG_Colour(cursor_y + GLOBAL_FontSizeY * GLOBAL_TextSize + j);
    						spiWrite16(GLOBAL_ColourBG, carWidth); // Space between lines
    					}
    				}
    			} else {
    				spiWrite16(GLOBAL_ColourBG, GLOBAL_LineSpace *  carWidth  ); // Space between lines
    			}
    			spi_end();
    		}
    		// Even if chars with ASCII code > GLOBAL_MaxAscii are not printed, we print a space. It's better.
    		cursor_x += carWidth; 
    	}
    	return 1;
    }
     
    // Bresenham's algorithm - thx Wikipedia
    void PDQ_ILI9341::drawLine(int x0, int y0, int x1, int y1) {
    	int8_t steep = abs(y1 - y0) > abs(x1 - x0);
    	if (steep)	{
    		swapValue(x0, y0);
    		swapValue(x1, y1);
    	}
    	if (x0 > x1)	{
    		swapValue(x0, x1);
    		swapValue(y0, y1);
    	}
    	if (x1 < 0)
    		return;
    	int dx, dy;
    	dx = x1 - x0;
    	dy = abs(y1 - y0);
    	int err = dx / 2;
    	int8_t ystep;
    	if (y0 < y1)	{
    		ystep = 1;
    	}	else	{
    		ystep = -1;
    	}
    	uint8_t setaddr = 1;
    	if (steep)	{ // y increments every iteration (y0 is x-axis, and x0 is y-axis)
    		if (x1 >= _height)
    			x1 = _height - 1;
    		for (; x0 <= x1; x0++)	{
    			if ((x0 >= 0) && (y0 >= 0) && (y0 < _width))
    				break;
    			err -= dy;
    			if (err < 0)	{
    				err += dx;
    				y0 += ystep;
    			}
    		}
    		if (x0 > x1)
    			return;
    		spi_begin();
    		for (; x0 <= x1; x0++)	{
    			if (setaddr)	{
    				setAddrWindow_(y0, x0, y0, _height);
    				setaddr = 0;
    			}
    			if (RainbowFunc_Mode) {
    				if (RainbowFunc_X_Direction) {
    					Rainbow_Colour(y0);
    				} else {
    					Rainbow_Colour(x0);
    				}
    			}
    			spiWrite16_lineDraw(GLOBAL_Colour);
    			err -= dy;
    			if (err < 0)	{
    				y0 += ystep;
    				if ((y0 < 0) || (y0 >= _width))
    					break;
    				err += dx;
    				setaddr = 1;
    			}
    #if defined(AVR_HARDWARE_SPI)
    			else{
    				__asm__ __volatile__
    				(
    					"	call	_ZN11PDQ_ILI93417delay10Ev\n"
    					: : :
    				);
    			}
    #endif
    		}
    	}	else {	// x increments every iteration (x0 is x-axis, and y0 is y-axis)
    		if (x1 >= _width)
    			x1 = _width - 1;
     
    		for (; x0 <= x1; x0++)	{
    			if ((x0 >= 0) && (y0 >= 0) && (y0 < _height))
    				break;
    			err -= dy;
    			if (err < 0){
    				err += dx;
    				y0 += ystep;
    			}
    		}
    		if (x0 > x1)
    			return;
    		spi_begin();
    		for (; x0 <= x1; x0++)	{
    			if (setaddr){
    				setAddrWindow_(x0, y0, _width, y0);
    				setaddr = 0;
    			}
    			if (RainbowFunc_Mode) {
    				if (RainbowFunc_X_Direction) {
    					Rainbow_Colour(x0);
    				} else {
    					Rainbow_Colour(y0);
    				}
    			}
    			spiWrite16_lineDraw(GLOBAL_Colour);
    			err -= dy;
    			if (err < 0){
    				y0 += ystep;
    				if ((y0 < 0) || (y0 >= _height))
    					break;
    				err += dx;
    				setaddr = 1;
    			}
    #if defined(AVR_HARDWARE_SPI)
    			else{
    				__asm__ __volatile__
    				(
    					"	call	_ZN11PDQ_ILI93417delay10Ev\n"
    					: : :
    				);
    			}
    #endif
    		}
    	}
    	spi_end();
    }
     
    void PDQ_ILI9341::drawRect() {
    	drawFastHLine(GLOBAL_X1	,  GLOBAL_Y1	, GLOBAL_X2);
    	drawFastHLine(GLOBAL_X1	,  GLOBAL_Y1+GLOBAL_Y2-1, GLOBAL_X2);
    	drawFastVLine(GLOBAL_X1	,  GLOBAL_Y1	, GLOBAL_Y2);
    	drawFastVLine(GLOBAL_X1+GLOBAL_X2-1,  GLOBAL_Y1	, GLOBAL_Y2);
    }
     
    void PDQ_ILI9341::drawCircle() {
    	coord_t f		= 1 - GLOBAL_X3;
    	coord_t ddF_x	= 1;
    	coord_t ddF_y	= -2 * GLOBAL_X3;
    	coord_t x		= 0;
    	coord_t y		= GLOBAL_X3;
    	drawPixel(GLOBAL_X1  , GLOBAL_Y1+GLOBAL_X3);
    	drawPixel(GLOBAL_X1  , GLOBAL_Y1-GLOBAL_X3);
    	drawPixel(GLOBAL_X1+GLOBAL_X3, GLOBAL_Y1	);
    	drawPixel(GLOBAL_X1-GLOBAL_X3, GLOBAL_Y1	);
    	while (x < y) {
    		if (f >= 0) {
    			y--;
    			ddF_y += 2;
    			f += ddF_y;
    		}
    		x++;
    		ddF_x += 2;
    		f += ddF_x;
    		drawPixel(GLOBAL_X1 + x, GLOBAL_Y1 + y);
    		drawPixel(GLOBAL_X1 - x, GLOBAL_Y1 + y);
    		drawPixel(GLOBAL_X1 + x, GLOBAL_Y1 - y);
    		drawPixel(GLOBAL_X1 - x, GLOBAL_Y1 - y);
    		drawPixel(GLOBAL_X1 + y, GLOBAL_Y1 + x);
    		drawPixel(GLOBAL_X1 - y, GLOBAL_Y1 + x);
    		drawPixel(GLOBAL_X1 + y, GLOBAL_Y1 - x);
    		drawPixel(GLOBAL_X1 - y, GLOBAL_Y1 - x);
    	}
    }
     
    void PDQ_ILI9341::drawCircleHelper( coord_t x0, coord_t y0, coord_t r, uint8_t cornername) {
    	coord_t f	= 1 - r;
    	coord_t ddF_x	= 1;
    	coord_t ddF_y	= -2 * r;
    	coord_t x	= 0;
    	coord_t y	= r;
    	while (x < y){
    		if (f >= 0) {
    			y--;
    			ddF_y += 2;
    			f += ddF_y;
    		}
    		x++;
    		ddF_x += 2;
    		f += ddF_x;
    		if (cornername & 0x4) {
    			drawPixel(x0 + x, y0 + y);
    			drawPixel(x0 + y, y0 + x);
    		}
    		if (cornername & 0x2) {
    			drawPixel(x0 + x, y0 - y);
    			drawPixel(x0 + y, y0 - x);
    		}
    		if (cornername & 0x8) {
    			drawPixel(x0 - y, y0 + x);
    			drawPixel(x0 - x, y0 + y);
    		}
    		if (cornername & 0x1) {
    			drawPixel(x0 - y, y0 - x);
    			drawPixel(x0 - x, y0 - y);
    		}
    	}
    }
     
    void PDQ_ILI9341::fillCircle() {
    	drawFastVLine(GLOBAL_X1, GLOBAL_Y1-GLOBAL_X3, 2*GLOBAL_X3+1);
    	fillCircleHelper(GLOBAL_X1, GLOBAL_Y1, GLOBAL_X3, 3, 0);
    }
     
    // Used to do circles and roundrects
    void PDQ_ILI9341::fillCircleHelper(coord_t x0, coord_t y0, coord_t r, uint8_t cornername, coord_t delta) {
    	coord_t f	= 1 - r;
    	coord_t ddF_x	= 1;
    	coord_t ddF_y	= -2 * r;
    	coord_t x	= 0;
    	coord_t y	= r;
    	while (x < y) {
    		if (f >= 0) {
    			y--;
    			ddF_y += 2;
    			f += ddF_y;
    		}
    		x++;
    		ddF_x += 2;
    		f += ddF_x;
    		if (cornername & 0x1) {
    			drawFastVLine(x0+x, y0-y, 2*y+1+delta);
    			drawFastVLine(x0+y, y0-x, 2*x+1+delta);
    		}
    		if (cornername & 0x2) {
    			drawFastVLine(x0-x, y0-y, 2*y+1+delta);
    			drawFastVLine(x0-y, y0-x, 2*x+1+delta);
    		}
    	}
    }
     
    void PDQ_ILI9341::drawRoundRect() {
    	// smarter version
    	drawFastHLine(GLOBAL_X1+GLOBAL_X3  , GLOBAL_Y1	, GLOBAL_X2-2*GLOBAL_X3); // Top
    	drawFastHLine(GLOBAL_X1+GLOBAL_X3  , GLOBAL_Y1+GLOBAL_Y2-1, GLOBAL_X2-2*GLOBAL_X3); // Bottom
    	drawFastVLine(GLOBAL_X1	, GLOBAL_Y1+GLOBAL_X3  , GLOBAL_Y2-2*GLOBAL_X3); // Left
    	drawFastVLine(GLOBAL_X1+GLOBAL_X2-1, GLOBAL_Y1+GLOBAL_X3  , GLOBAL_Y2-2*GLOBAL_X3); // Right
    	// draw four corners
    	drawCircleHelper(GLOBAL_X1+GLOBAL_X3	, GLOBAL_Y1+GLOBAL_X3	, GLOBAL_X3, 1);
    	drawCircleHelper(GLOBAL_X1+GLOBAL_X2-GLOBAL_X3-1, GLOBAL_Y1+GLOBAL_X3	, GLOBAL_X3, 2);
    	drawCircleHelper(GLOBAL_X1+GLOBAL_X2-GLOBAL_X3-1, GLOBAL_Y1+GLOBAL_Y2-GLOBAL_X3-1, GLOBAL_X3, 4);
    	drawCircleHelper(GLOBAL_X1+GLOBAL_X3	, GLOBAL_Y1+GLOBAL_Y2-GLOBAL_X3-1, GLOBAL_X3, 8);
    }
     
    void PDQ_ILI9341::fillRoundRect() {
    	// smarter version
    	fillRect(GLOBAL_X1+GLOBAL_X3, GLOBAL_Y1, GLOBAL_X2-2*GLOBAL_X3, GLOBAL_Y2);
    	// draw four corners
    	fillCircleHelper(GLOBAL_X1+GLOBAL_X2-GLOBAL_X3-1, GLOBAL_Y1+GLOBAL_X3, GLOBAL_X3, 1, GLOBAL_Y2-2*GLOBAL_X3-1);
    	fillCircleHelper(GLOBAL_X1+GLOBAL_X3	, GLOBAL_Y1+GLOBAL_X3, GLOBAL_X3, 2, GLOBAL_Y2-2*GLOBAL_X3-1);
    }
     
    void PDQ_ILI9341::drawTriangle() {
    	drawLine(GLOBAL_X1, GLOBAL_Y1, GLOBAL_X2, GLOBAL_Y2);
    	drawLine(GLOBAL_X2, GLOBAL_Y2, GLOBAL_X3, GLOBAL_Y3);
    	drawLine(GLOBAL_X3, GLOBAL_Y3, GLOBAL_X1, GLOBAL_Y1);
    }
     
    void PDQ_ILI9341::fillTriangle() {
    	coord_t a, b, y, last;
    	int X1,Y1,X2,Y2,X3,Y3; // Economie de 50 octets de code - Ca vaut le coup de passer par des Var locales (compilées en registres) car il y a beaucoup de calculs
    	X1=GLOBAL_X1;
    	Y1=GLOBAL_Y1;
    	X2=GLOBAL_X2;
    	Y2=GLOBAL_Y2;
    	X3=GLOBAL_X3;
    	Y3=GLOBAL_Y3;
    	// Sort coordinates by Y order (Y3 >= Y2 >= Y1)
    	if (Y1 > Y2) {
    		swapValue(Y1, Y2);
    		swapValue(X1, X2);
    	}
    	if (Y2 > Y3) {
    		swapValue(Y3, Y2);
    		swapValue(X3, X2);
    	}
    	if (Y1 > Y2) {
    		swapValue(Y1, Y2);
    		swapValue(X1, X2);
    	}
    	// Handle awkward all-on-same-line case as its own thing
    	if (Y1 == Y3) {
    		a = b = X1;
    		if (X2 < a)
    			a = X2;
    		else if (X2 > b)
    			b = X2;
    		if (X3 < a)
    			a = X3;
    		else if (X3 > b)
    			b = X3;
    		drawFastHLine(a, Y1, b-a+1);
    		return;
    	}
    	coord_t	dx01 = X2 - X1;
    	coord_t	dy01 = Y2 - Y1;
    	coord_t	dx02 = X3 - X1;
    	coord_t	dy02 = Y3 - Y1;
    	coord_t	dx12 = X3 - X2;
    	coord_t	dy12 = Y3 - Y2;
    	int32_t	sa = 0;
    	int32_t	sb = 0;
    	// For upper part of triangle, find scanline crossings for segments 0-1 and 0-2. If Y2=Y3 (flat-bottomed triangle), the scanline Y2
    	// is included here (and second loop will be skipped, avoiding a /0 error there), otherwise scanline Y2 is skipped here and handled
    	// in the second loop...which also avoids a /0 error here if Y1=Y2 (flat-topped triangle).
    	if (Y2 == Y3)
    		last = Y2;	// Include Y2 scanline
    	else
    		last = Y2-1;	// Skip it
     
    	for (y = Y1; y <= last; y++) {
    		a = X1 + sa / dy01;
    		b = X1 + sb / dy02;
    		sa += dx01;
    		sb += dx02;
    		// longhand:
    		//a = X1 + (X2 - X1) * (y - Y1) / (Y2 - Y1);
    		//b = X1 + (X3 - X1) * (y - Y1) / (Y3 - Y1);
    		if (a > b)
    			swapValue(a, b);
    		drawFastHLine(a, y, b-a+1);
    	}
     
    	// For lower part of triangle, find scanline crossings for segments 0-2 and 1-2. This loop is skipped if Y2=Y3.
    	sa = dx12 * (y - Y2);
    	sb = dx02 * (y - Y1);
    	for (; y <= Y3; y++) {
    		a = X2 + sa / dy12;
    		b = X1 + sb / dy02;
    		sa += dx12;
    		sb += dx02;
    		// longhand:
    		//a = X2 + (X3 - X2) * (y - Y2) / (Y3 - Y2);
    		//b = X1 + (X3 - X1) * (y - Y1) / (Y3 - Y1);
    		if (a > b)
    			swapValue(a, b);
    		drawFastHLine(a, y, b-a+1);
    	}
    }

  4. #4
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 908
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 908
    Par défaut
    Aussi, dans ce cas de figure je ne comprend pas l'usage de "static".
    dans la bibliothèque d'origine il n'y a pas de static et c'est vous qui les avez rajoutés?

    je ne suis pas sûr de comprendre la question (s'il y en a une)

  5. #5
    Membre chevronné Avatar de electroremy
    Homme Profil pro
    Ingénieur sécurité
    Inscrit en
    Juin 2007
    Messages
    999
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur sécurité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 999
    Par défaut
    La bibliothèque d'origine contenait des 'static' à la pelle, ce n'est pas moi qui les ai ajouté, je les ai conservés.

    Bien que pas mal modifié, le code actuel contient des choses venant du code ancien qui ne sont peut être plus nécessaires.

    La complexité du c++ auxquelles s'ajoute les optimisations du compilateur et les contraintes du hardware Arduino rendent les choses plus difficiles à comprendre et à modifier.

    Souvent, quelque chose qui à priori ne sert à rien est indispensable

    C'est pour ça que je pose la question.

  6. #6
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 908
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 908
    Par défaut
    J’ai regardé la bibliothèque bibliothèque Adafruit ILI9341 et j’en n’ai pas vu à part des tableaux

  7. #7
    Membre chevronné Avatar de electroremy
    Homme Profil pro
    Ingénieur sécurité
    Inscrit en
    Juin 2007
    Messages
    999
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur sécurité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 999
    Par défaut
    Citation Envoyé par Jay M Voir le message
    J’ai regardé la bibliothèque bibliothèque Adafruit ILI9341 et j’en n’ai pas vu à part des tableaux
    Les "static" se trouvent dans la première fork que j'ai prise, celle d'hackaday

    Ma version est la "deuxième" fork, une fork de la fork

  8. #8
    Membre chevronné Avatar de electroremy
    Homme Profil pro
    Ingénieur sécurité
    Inscrit en
    Juin 2007
    Messages
    999
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur sécurité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 999
    Par défaut
    Du coup, une idée sur l'utilité (ou pas) de ces statics à la pelle ?

    Il reste la méthode bourrin : supprimer pour voir si ça fonctionne toujours avec le risque d'avoir un code avec des bugs aléatoires d'autant plus difficiles à mettre en évidence qu'il risquent de survenir une fois sur 10 ou sur 100

    Une réponse argumentée sur le plan théorique serait préférable

    A bientôt

  9. #9
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 908
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 908
    Par défaut
    La théorie dit cela
    Static Function Members
    By declaring a function member as static, you make it independent of any particular object of the class. A static member function can be called even if no objects of the class exist and the static functions are accessed using only the class name and the scope resolution operator ::.

    A static member function can only access static data member, other static member functions and any other functions from outside the class.

    Static member functions have a class scope and they do not have access to the this pointer of the class. You could use a static member function to determine whether some objects of the class have been created or not.
    Donc en enlevant static tout ce que vous pouvez casser c’est si les appels se faisaient sur la classe et pas sur une instance. Il y a un tout petit gain de performance car this n’est pas rajouté en paramètre lors de l’appel.

  10. #10
    Membre chevronné Avatar de electroremy
    Homme Profil pro
    Ingénieur sécurité
    Inscrit en
    Juin 2007
    Messages
    999
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur sécurité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 999
    Par défaut
    Citation Envoyé par Jay M Voir le message
    Il y a un tout petit gain de performance car this n’est pas rajouté en paramètre lors de l’appel.
    Je pense que voilà l'explication.

    Les gens de hackaday ont utilisé Static pour gagner un peu en performance, même si ce n'était pas nécessaire

    Merci

  11. #11
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 908
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 908
    Par défaut
    C’est quand même infime...

  12. #12
    Membre chevronné Avatar de electroremy
    Homme Profil pro
    Ingénieur sécurité
    Inscrit en
    Juin 2007
    Messages
    999
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Doubs (Franche Comté)

    Informations professionnelles :
    Activité : Ingénieur sécurité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 999
    Par défaut
    Oui certes, mais c'est dans l'esprit "hacker"

    Et le plus important pour moi : cet usage "abusif" de static ne pénalise pas mon programme (je n'ai pas donc besoin de les retirer pour optimiser mon code)

    A bientôt

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. le mot clef "static"
    Par Kyle128 dans le forum Débuter
    Réponses: 10
    Dernier message: 17/06/2009, 13h38
  2. Usage du mot clef base et du modifier override
    Par olibara dans le forum C#
    Réponses: 9
    Dernier message: 05/09/2008, 14h33
  3. Utilisation du mot-clef "static"
    Par sir_gcc dans le forum Langage
    Réponses: 3
    Dernier message: 16/04/2007, 11h18
  4. mot-clef static
    Par keil dans le forum C++
    Réponses: 8
    Dernier message: 25/01/2006, 17h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo