Select one of the symbols to view example projects that use it.
 
Outline
#include "stmpe811.h"
#define STMPE811_MAX_INSTANCE
stmpe811_ts_drv
stmpe811_io_drv
stmpe811
stmpe811_Init(uint16_t)
stmpe811_Reset(uint16_t)
stmpe811_ReadID(uint16_t)
stmpe811_EnableGlobalIT(uint16_t)
stmpe811_DisableGlobalIT(uint16_t)
stmpe811_EnableITSource(uint16_t, uint8_t)
stmpe811_DisableITSource(uint16_t, uint8_t)
stmpe811_SetITPolarity(uint16_t, uint8_t)
stmpe811_SetITType(uint16_t, uint8_t)
stmpe811_GlobalITStatus(uint16_t, uint8_t)
stmpe811_ReadGITStatus(uint16_t, uint8_t)
stmpe811_ClearGlobalIT(uint16_t, uint8_t)
stmpe811_IO_Start(uint16_t, uint32_t)
stmpe811_IO_Config(uint16_t, uint32_t, IO_ModeTypedef)
stmpe811_IO_InitPin(uint16_t, uint32_t, uint8_t)
stmpe811_IO_DisableAF(uint16_t, uint32_t)
stmpe811_IO_EnableAF(uint16_t, uint32_t)
stmpe811_IO_SetEdgeMode(uint16_t, uint32_t, uint8_t)
stmpe811_IO_WritePin(uint16_t, uint32_t, uint8_t)
stmpe811_IO_ReadPin(uint16_t, uint32_t)
stmpe811_IO_EnableIT(uint16_t)
stmpe811_IO_DisableIT(uint16_t)
stmpe811_IO_EnablePinIT(uint16_t, uint32_t)
stmpe811_IO_DisablePinIT(uint16_t, uint32_t)
stmpe811_IO_ITStatus(uint16_t, uint32_t)
stmpe811_IO_ClearIT(uint16_t, uint32_t)
stmpe811_TS_Start(uint16_t)
stmpe811_TS_DetectTouch(uint16_t)
stmpe811_TS_GetXY(uint16_t, uint16_t *, uint16_t *)
stmpe811_TS_EnableIT(uint16_t)
stmpe811_TS_DisableIT(uint16_t)
stmpe811_TS_ITStatus(uint16_t)
stmpe811_TS_ClearIT(uint16_t)
stmpe811_GetInstance(uint16_t)
Files
loading...
SourceVuSTM32 Libraries and Samplesstmpe811stmpe811.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file stmpe811.c * @author MCD Application Team * @brief This file provides a set of functions needed to manage the STMPE811 * IO Expander devices. ****************************************************************************** * @attention * * Copyright (c) 2014 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 "stmpe811.h" /** @addtogroup BSP * @{ *//* ... */ /** @addtogroup Components * @{ *//* ... */ /** @defgroup STMPE811 * @{ *//* ... */ /** @defgroup STMPE811_Private_Types_Definitions * @{ *//* ... */ /** @defgroup STMPE811_Private_Defines * @{ *//* ... */ #define STMPE811_MAX_INSTANCE 2 /** * @} *//* ... */ /** @defgroup STMPE811_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup STMPE811_Private_Variables * @{ *//* ... */ /* Touch screen driver structure initialization */ TS_DrvTypeDef stmpe811_ts_drv = { stmpe811_Init, stmpe811_ReadID, stmpe811_Reset, stmpe811_TS_Start, stmpe811_TS_DetectTouch, stmpe811_TS_GetXY, stmpe811_TS_EnableIT, stmpe811_TS_ClearIT, stmpe811_TS_ITStatus, stmpe811_TS_DisableIT, ...}; /* IO driver structure initialization */ IO_DrvTypeDef stmpe811_io_drv = { stmpe811_Init, stmpe811_ReadID, stmpe811_Reset, stmpe811_IO_Start, stmpe811_IO_Config, stmpe811_IO_WritePin, stmpe811_IO_ReadPin, stmpe811_IO_EnableIT, stmpe811_IO_DisableIT, stmpe811_IO_ITStatus, stmpe811_IO_ClearIT, ...}; /* stmpe811 instances by address */ uint8_t stmpe811[STMPE811_MAX_INSTANCE] = {0}; /** * @} *//* ... */ /** @defgroup STMPE811_Private_Function_Prototypes * @{ *//* ... */ static uint8_t stmpe811_GetInstance(uint16_t DeviceAddr); /** * @} *//* ... */ /** @defgroup STMPE811_Private_Functions * @{ *//* ... */ /** * @brief Initialize the stmpe811 and configure the needed hardware resources * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void stmpe811_Init(uint16_t DeviceAddr) { uint8_t instance; uint8_t empty; /* Check if device instance already exists */ instance = stmpe811_GetInstance(DeviceAddr); /* To prevent double initialization */ if(instance == 0xFF) { /* Look for empty instance */ empty = stmpe811_GetInstance(0); if(empty < STMPE811_MAX_INSTANCE) { /* Register the current device instance */ stmpe811[empty] = DeviceAddr; /* Initialize IO BUS layer */ IOE_Init(); /* Generate stmpe811 Software reset */ stmpe811_Reset(DeviceAddr); }if (empty < STMPE811_MAX_INSTANCE) { ... } }if (instance == 0xFF) { ... } }{ ... } /** * @brief Reset the stmpe811 by Software. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void stmpe811_Reset(uint16_t DeviceAddr) { /* Power Down the stmpe811 */ IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL1, 2); /* Wait for a delay to ensure registers erasing */ IOE_Delay(10); /* Power On the Codec after the power off => all registers are reinitialized */ IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL1, 0); /* Wait for a delay to ensure registers erasing */ IOE_Delay(2); }{ ... } /** * @brief Read the stmpe811 IO Expander device ID. * @param DeviceAddr: Device address on communication Bus. * @retval The Device ID (two bytes). *//* ... */ uint16_t stmpe811_ReadID(uint16_t DeviceAddr) { /* Initialize IO BUS layer */ IOE_Init(); /* Return the device ID value */ return ((IOE_Read(DeviceAddr, STMPE811_REG_CHP_ID_LSB) << 8) |\ (IOE_Read(DeviceAddr, STMPE811_REG_CHP_ID_MSB))); }{ ... } /** * @brief Enable the Global interrupt. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void stmpe811_EnableGlobalIT(uint16_t DeviceAddr) { uint8_t tmp = 0; /* Read the Interrupt Control register */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL); /* Set the global interrupts to be Enabled */ tmp |= (uint8_t)STMPE811_GIT_EN; /* Write Back the Interrupt Control register */ IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp); }{ ... } /** * @brief Disable the Global interrupt. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void stmpe811_DisableGlobalIT(uint16_t DeviceAddr) { uint8_t tmp = 0; /* Read the Interrupt Control register */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL); /* Set the global interrupts to be Disabled */ tmp &= ~(uint8_t)STMPE811_GIT_EN; /* Write Back the Interrupt Control register */ IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp); }{ ... } /** * @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 STMPE811_GIT_IO: IO interrupt * @arg STMPE811_GIT_ADC : ADC interrupt * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt * @retval None *//* ... */ void stmpe811_EnableITSource(uint16_t DeviceAddr, uint8_t Source) { uint8_t tmp = 0; /* Get the current value of the INT_EN register */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_EN); /* Set the interrupts to be Enabled */ tmp |= Source; /* Set the register */ IOE_Write(DeviceAddr, STMPE811_REG_INT_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 STMPE811_GIT_IO: IO interrupt * @arg STMPE811_GIT_ADC : ADC interrupt * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt * @retval None *//* ... */ void stmpe811_DisableITSource(uint16_t DeviceAddr, uint8_t Source) { uint8_t tmp = 0; /* Get the current value of the INT_EN register */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_EN); /* Set the interrupts to be Enabled */ tmp &= ~Source; /* Set the register */ IOE_Write(DeviceAddr, STMPE811_REG_INT_EN, tmp); }{ ... } /** * @brief Set the global interrupt Polarity. * @param DeviceAddr: Device address on communication Bus. * @param Polarity: the IT mode polarity, could be one of the following values: * @arg STMPE811_POLARITY_LOW: Interrupt line is active Low/Falling edge * @arg STMPE811_POLARITY_HIGH: Interrupt line is active High/Rising edge * @retval None *//* ... */ void stmpe811_SetITPolarity(uint16_t DeviceAddr, uint8_t Polarity) { uint8_t tmp = 0; /* Get the current register value */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL); /* Mask the polarity bits */ tmp &= ~(uint8_t)0x04; /* Modify the Interrupt Output line configuration */ tmp |= Polarity; /* Set the new register value */ IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp); }{ ... } /** * @brief Set the global interrupt Type. * @param DeviceAddr: Device address on communication Bus. * @param Type: Interrupt line activity type, could be one of the following values: * @arg STMPE811_TYPE_LEVEL: Interrupt line is active in level model * @arg STMPE811_TYPE_EDGE: Interrupt line is active in edge model * @retval None *//* ... */ void stmpe811_SetITType(uint16_t DeviceAddr, uint8_t Type) { uint8_t tmp = 0; /* Get the current register value */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_INT_CTRL); /* Mask the type bits */ tmp &= ~(uint8_t)0x02; /* Modify the Interrupt Output line configuration */ tmp |= Type; /* Set the new register value */ IOE_Write(DeviceAddr, STMPE811_REG_INT_CTRL, tmp); }{ ... } /** * @brief Check the selected Global interrupt source pending bit * @param DeviceAddr: Device address on communication Bus. * @param Source: the Global interrupt source to be checked, could be: * @arg STMPE811_GIT_IO: IO interrupt * @arg STMPE811_GIT_ADC : ADC interrupt * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt * @retval The checked Global interrupt source status. *//* ... */ uint8_t stmpe811_GlobalITStatus(uint16_t DeviceAddr, uint8_t Source) { /* Return the global IT source status */ return((IOE_Read(DeviceAddr, STMPE811_REG_INT_STA) & Source) == Source); }{ ... } /** * @brief Return the Global interrupts status * @param DeviceAddr: Device address on communication Bus. * @param Source: the Global interrupt source to be checked, could be: * @arg STMPE811_GIT_IO: IO interrupt * @arg STMPE811_GIT_ADC : ADC interrupt * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt * @retval The checked Global interrupt source status. *//* ... */ uint8_t stmpe811_ReadGITStatus(uint16_t DeviceAddr, uint8_t Source) { /* Return the global IT source status */ return((IOE_Read(DeviceAddr, STMPE811_REG_INT_STA) & 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 following values: * @arg STMPE811_GIT_IO: IO interrupt * @arg STMPE811_GIT_ADC : ADC interrupt * @arg STMPE811_GIT_FE : Touch Screen Controller FIFO Error interrupt * @arg STMPE811_GIT_FF : Touch Screen Controller FIFO Full interrupt * @arg STMPE811_GIT_FOV : Touch Screen Controller FIFO Overrun interrupt * @arg STMPE811_GIT_FTH : Touch Screen Controller FIFO Threshold interrupt * @arg STMPE811_GIT_TOUCH : Touch Screen Controller Touch Detected interrupt * @retval None *//* ... */ void stmpe811_ClearGlobalIT(uint16_t DeviceAddr, uint8_t Source) { /* Write 1 to the bits that have to be cleared */ IOE_Write(DeviceAddr, STMPE811_REG_INT_STA, Source); }{ ... } /** * @brief Start the IO functionality use and disable the AF for selected IO pin(s). * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: The IO pin(s) to put in AF. This parameter can be one * of the following values: * @arg STMPE811_PIN_x: where x can be from 0 to 7. * @retval None *//* ... */ void stmpe811_IO_Start(uint16_t DeviceAddr, uint32_t IO_Pin) { uint8_t mode; /* Get the current register value */ mode = IOE_Read(DeviceAddr, STMPE811_REG_SYS_CTRL2); /* Set the Functionalities to be Disabled */ mode &= ~(STMPE811_IO_FCT | STMPE811_ADC_FCT); /* Write the new register value */ IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL2, mode); /* Disable AF for the selected IO pin(s) */ stmpe811_IO_DisableAF(DeviceAddr, (uint8_t)IO_Pin); }{ ... } /** * @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 STMPE811_PIN_x: where x can be from 0 to 7. * @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 * @retval 0 if no error, IO_Mode if error *//* ... */ uint8_t stmpe811_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_INPUT: /* Input mode */ stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN); break; case IO_MODE_INPUT: case IO_MODE_OUTPUT: /* Output mode */ stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_OUT); break; case IO_MODE_OUTPUT: case IO_MODE_IT_RISING_EDGE: /* Interrupt rising edge mode */ stmpe811_IO_EnableIT(DeviceAddr); stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin); stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN); stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_EDGE); stmpe811_IO_SetEdgeMode(DeviceAddr, IO_Pin, STMPE811_EDGE_RISING); break; case IO_MODE_IT_RISING_EDGE: case IO_MODE_IT_FALLING_EDGE: /* Interrupt falling edge mode */ stmpe811_IO_EnableIT(DeviceAddr); stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin); stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN); stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_EDGE); stmpe811_IO_SetEdgeMode(DeviceAddr, IO_Pin, STMPE811_EDGE_FALLING); break; case IO_MODE_IT_FALLING_EDGE: case IO_MODE_IT_LOW_LEVEL: /* Low level interrupt mode */ stmpe811_IO_EnableIT(DeviceAddr); stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin); stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN); stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_LEVEL); stmpe811_SetITPolarity(DeviceAddr, STMPE811_POLARITY_LOW); break; case IO_MODE_IT_LOW_LEVEL: case IO_MODE_IT_HIGH_LEVEL: /* High level interrupt mode */ stmpe811_IO_EnableIT(DeviceAddr); stmpe811_IO_EnablePinIT(DeviceAddr, IO_Pin); stmpe811_IO_InitPin(DeviceAddr, IO_Pin, STMPE811_DIRECTION_IN); stmpe811_SetITType(DeviceAddr, STMPE811_TYPE_LEVEL); stmpe811_SetITPolarity(DeviceAddr, STMPE811_POLARITY_HIGH); break; case IO_MODE_IT_HIGH_LEVEL: 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 STMPE811_PIN_x: Where x can be from 0 to 7. * @param Direction: could be STMPE811_DIRECTION_IN or STMPE811_DIRECTION_OUT. * @retval None *//* ... */ void stmpe811_IO_InitPin(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Direction) { uint8_t tmp = 0; /* Get all the Pins direction */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_DIR); /* Set the selected pin direction */ if (Direction != STMPE811_DIRECTION_IN) { tmp |= (uint8_t)IO_Pin; }if (Direction != STMPE811_DIRECTION_IN) { ... } else { tmp &= ~(uint8_t)IO_Pin; }else { ... } /* Write the register new value */ IOE_Write(DeviceAddr, STMPE811_REG_IO_DIR, tmp); }{ ... } /** * @brief Disable the AF for the selected IO pin(s). * @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 STMPE811_PIN_x: Where x can be from 0 to 7. * @retval None *//* ... */ void stmpe811_IO_DisableAF(uint16_t DeviceAddr, uint32_t IO_Pin) { uint8_t tmp = 0; /* Get the current state of the IO_AF register */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_AF); /* Enable the selected pins alternate function */ tmp |= (uint8_t)IO_Pin; /* Write back the new value in IO AF register */ IOE_Write(DeviceAddr, STMPE811_REG_IO_AF, tmp); }{ ... } /** * @brief Enable the AF for the selected IO pin(s). * @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 STMPE811_PIN_x: Where x can be from 0 to 7. * @retval None *//* ... */ void stmpe811_IO_EnableAF(uint16_t DeviceAddr, uint32_t IO_Pin) { uint8_t tmp = 0; /* Get the current register value */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_AF); /* Enable the selected pins alternate function */ tmp &= ~(uint8_t)IO_Pin; /* Write back the new register value */ IOE_Write(DeviceAddr, STMPE811_REG_IO_AF, tmp); }{ ... } /** * @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 STMPE811_PIN_x: Where x can be from 0 to 7. * @param Edge: The edge which will be detected. This parameter can be one or * a combination of following values: STMPE811_EDGE_FALLING and STMPE811_EDGE_RISING . * @retval None *//* ... */ void stmpe811_IO_SetEdgeMode(uint16_t DeviceAddr, uint32_t IO_Pin, uint8_t Edge) { uint8_t tmp1 = 0, tmp2 = 0; /* Get the current registers values */ tmp1 = IOE_Read(DeviceAddr, STMPE811_REG_IO_FE); tmp2 = IOE_Read(DeviceAddr, STMPE811_REG_IO_RE); /* Disable the Falling Edge */ tmp1 &= ~(uint8_t)IO_Pin; /* Disable the Falling Edge */ tmp2 &= ~(uint8_t)IO_Pin; /* Enable the Falling edge if selected */ if (Edge & STMPE811_EDGE_FALLING) { tmp1 |= (uint8_t)IO_Pin; }if (Edge & STMPE811_EDGE_FALLING) { ... } /* Enable the Rising edge if selected */ if (Edge & STMPE811_EDGE_RISING) { tmp2 |= (uint8_t)IO_Pin; }if (Edge & STMPE811_EDGE_RISING) { ... } /* Write back the new registers values */ IOE_Write(DeviceAddr, STMPE811_REG_IO_FE, tmp1); IOE_Write(DeviceAddr, STMPE811_REG_IO_RE, tmp2); }{ ... } /** * @brief Write a new IO pin state. * @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 STMPE811_PIN_x: where x can be from 0 to 7. * @param PinState: The new IO pin state. * @retval None *//* ... */ void stmpe811_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 register */ IOE_Write(DeviceAddr, STMPE811_REG_IO_SET_PIN, (uint8_t)IO_Pin); }if (PinState != 0) { ... } else { /* Set the register */ IOE_Write(DeviceAddr, STMPE811_REG_IO_CLR_PIN, (uint8_t)IO_Pin); }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 STMPE811_PIN_x: where x can be from 0 to 7. * @retval IO pin(s) state. *//* ... */ uint32_t stmpe811_IO_ReadPin(uint16_t DeviceAddr, uint32_t IO_Pin) { return((uint32_t)(IOE_Read(DeviceAddr, STMPE811_REG_IO_MP_STA) & (uint8_t)IO_Pin)); }{ ... } /** * @brief Enable the global IO interrupt source. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void stmpe811_IO_EnableIT(uint16_t DeviceAddr) { IOE_ITConfig(); /* Enable global IO IT source */ stmpe811_EnableITSource(DeviceAddr, STMPE811_GIT_IO); /* Enable global interrupt */ stmpe811_EnableGlobalIT(DeviceAddr); }{ ... } /** * @brief Disable the global IO interrupt source. * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void stmpe811_IO_DisableIT(uint16_t DeviceAddr) { /* Disable the global interrupt */ stmpe811_DisableGlobalIT(DeviceAddr); /* Disable global IO IT source */ stmpe811_DisableITSource(DeviceAddr, STMPE811_GIT_IO); }{ ... } /** * @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 STMPE811_PIN_x: where x can be from 0 to 7. * @retval None *//* ... */ void stmpe811_IO_EnablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin) { uint8_t tmp = 0; /* Get the IO interrupt state */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_INT_EN); /* Set the interrupts to be enabled */ tmp |= (uint8_t)IO_Pin; /* Write the register new value */ IOE_Write(DeviceAddr, STMPE811_REG_IO_INT_EN, tmp); }{ ... } /** * @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 STMPE811_PIN_x: where x can be from 0 to 7. * @retval None *//* ... */ void stmpe811_IO_DisablePinIT(uint16_t DeviceAddr, uint32_t IO_Pin) { uint8_t tmp = 0; /* Get the IO interrupt state */ tmp = IOE_Read(DeviceAddr, STMPE811_REG_IO_INT_EN); /* Set the interrupts to be Disabled */ tmp &= ~(uint8_t)IO_Pin; /* Write the register new value */ IOE_Write(DeviceAddr, STMPE811_REG_IO_INT_EN, tmp); }{ ... } /** * @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 STMPE811_PIN_x Where x can be from 0 to 7. * @retval Status of the checked IO pin(s). *//* ... */ uint32_t stmpe811_IO_ITStatus(uint16_t DeviceAddr, uint32_t IO_Pin) { /* Get the Interrupt status */ return(IOE_Read(DeviceAddr, STMPE811_REG_IO_INT_STA) & (uint8_t)IO_Pin); }{ ... } /** * @brief Clear the selected IO interrupt pending bit(s). * @param DeviceAddr: Device address on communication Bus. * @param IO_Pin: the IO interrupt to be cleared, could be: * @arg STMPE811_PIN_x: Where x can be from 0 to 7. * @retval None *//* ... */ void stmpe811_IO_ClearIT(uint16_t DeviceAddr, uint32_t IO_Pin) { /* Clear the global IO IT pending bit */ stmpe811_ClearGlobalIT(DeviceAddr, STMPE811_GIT_IO); /* Clear the IO IT pending bit(s) */ IOE_Write(DeviceAddr, STMPE811_REG_IO_INT_STA, (uint8_t)IO_Pin); /* Clear the Edge detection pending bit*/ IOE_Write(DeviceAddr, STMPE811_REG_IO_ED, (uint8_t)IO_Pin); /* Clear the Rising edge pending bit */ IOE_Write(DeviceAddr, STMPE811_REG_IO_RE, (uint8_t)IO_Pin); /* Clear the Falling edge pending bit */ IOE_Write(DeviceAddr, STMPE811_REG_IO_FE, (uint8_t)IO_Pin); }{ ... } /** * @brief Configures the touch Screen Controller (Single point detection) * @param DeviceAddr: Device address on communication Bus. * @retval None. *//* ... */ void stmpe811_TS_Start(uint16_t DeviceAddr) { uint8_t mode; /* Get the current register value */ mode = IOE_Read(DeviceAddr, STMPE811_REG_SYS_CTRL2); /* Set the Functionalities to be Enabled */ mode &= ~(STMPE811_IO_FCT); /* Write the new register value */ IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL2, mode); /* Select TSC pins in TSC alternate mode */ stmpe811_IO_EnableAF(DeviceAddr, STMPE811_TOUCH_IO_ALL); /* Set the Functionalities to be Enabled */ mode &= ~(STMPE811_TS_FCT | STMPE811_ADC_FCT); /* Set the new register value */ IOE_Write(DeviceAddr, STMPE811_REG_SYS_CTRL2, mode); /* Select Sample Time, bit number and ADC Reference */ IOE_Write(DeviceAddr, STMPE811_REG_ADC_CTRL1, 0x49); /* Wait for 2 ms */ IOE_Delay(2); /* Select the ADC clock speed: 3.25 MHz */ IOE_Write(DeviceAddr, STMPE811_REG_ADC_CTRL2, 0x01); /* Select 2 nF filter capacitor */ /* Configuration: - Touch average control : 4 samples - Touch delay time : 500 uS - Panel driver setting time: 500 uS *//* ... */ IOE_Write(DeviceAddr, STMPE811_REG_TSC_CFG, 0x9A); /* Configure the Touch FIFO threshold: single point reading */ IOE_Write(DeviceAddr, STMPE811_REG_FIFO_TH, 0x01); /* Clear the FIFO memory content. */ IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x01); /* Put the FIFO back into operation mode */ IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x00); /* Set the range and accuracy pf the pressure measurement (Z) : - Fractional part :7 - Whole part :1 *//* ... */ IOE_Write(DeviceAddr, STMPE811_REG_TSC_FRACT_XYZ, 0x01); /* Set the driving capability (limit) of the device for TSC pins: 50mA */ IOE_Write(DeviceAddr, STMPE811_REG_TSC_I_DRIVE, 0x01); /* Touch screen control configuration (enable TSC): - No window tracking index - XYZ acquisition mode *//* ... */ IOE_Write(DeviceAddr, STMPE811_REG_TSC_CTRL, 0x01); /* Clear all the status pending bits if any */ IOE_Write(DeviceAddr, STMPE811_REG_INT_STA, 0xFF); /* Wait for 2 ms delay */ IOE_Delay(2); }{ ... } /** * @brief Return if there is touch detected or not. * @param DeviceAddr: Device address on communication Bus. * @retval Touch detected state. *//* ... */ uint8_t stmpe811_TS_DetectTouch(uint16_t DeviceAddr) { uint8_t state; uint8_t ret = 0; state = ((IOE_Read(DeviceAddr, STMPE811_REG_TSC_CTRL) & (uint8_t)STMPE811_TS_CTRL_STATUS) == (uint8_t)STMPE811_TS_CTRL_STATUS); if(state > 0) { if(IOE_Read(DeviceAddr, STMPE811_REG_FIFO_SIZE) > 0) { ret = 1; }if (IOE_Read(DeviceAddr, STMPE811_REG_FIFO_SIZE) > 0) { ... } }if (state > 0) { ... } else { /* Reset FIFO */ IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x01); /* Enable the FIFO again */ IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x00); }else { ... } 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 stmpe811_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y) { uint8_t dataXYZ[4]; uint32_t uldataXYZ; IOE_ReadMultiple(DeviceAddr, STMPE811_REG_TSC_DATA_NON_INC, dataXYZ, sizeof(dataXYZ)) ; /* Calculate positions values */ uldataXYZ = (dataXYZ[0] << 24)|(dataXYZ[1] << 16)|(dataXYZ[2] << 8)|(dataXYZ[3] << 0); *X = (uldataXYZ >> 20) & 0x00000FFF; *Y = (uldataXYZ >> 8) & 0x00000FFF; /* Reset FIFO */ IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x01); /* Enable the FIFO again */ IOE_Write(DeviceAddr, STMPE811_REG_FIFO_STA, 0x00); }{ ... } /** * @brief Configure the selected source to generate a global interrupt or not * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void stmpe811_TS_EnableIT(uint16_t DeviceAddr) { IOE_ITConfig(); /* Enable global TS IT source */ stmpe811_EnableITSource(DeviceAddr, STMPE811_TS_IT); /* Enable global interrupt */ stmpe811_EnableGlobalIT(DeviceAddr); }{ ... } /** * @brief Configure the selected source to generate a global interrupt or not * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void stmpe811_TS_DisableIT(uint16_t DeviceAddr) { /* Disable global interrupt */ stmpe811_DisableGlobalIT(DeviceAddr); /* Disable global TS IT source */ stmpe811_DisableITSource(DeviceAddr, STMPE811_TS_IT); }{ ... } /** * @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 stmpe811_TS_ITStatus(uint16_t DeviceAddr) { /* Return TS interrupts status */ return(stmpe811_ReadGITStatus(DeviceAddr, STMPE811_TS_IT)); }{ ... } /** * @brief Configure the selected source to generate a global interrupt or not * @param DeviceAddr: Device address on communication Bus. * @retval None *//* ... */ void stmpe811_TS_ClearIT(uint16_t DeviceAddr) { /* Clear the global TS IT source */ stmpe811_ClearGlobalIT(DeviceAddr, STMPE811_TS_IT); }{ ... } /** * @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 stmpe811_GetInstance(uint16_t DeviceAddr) { uint8_t idx = 0; /* Check all the registered instances */ for(idx = 0; idx < STMPE811_MAX_INSTANCE ; idx ++) { if(stmpe811[idx] == DeviceAddr) { return idx; }if (stmpe811[idx] == DeviceAddr) { ... } }for (idx = 0; idx < STMPE811_MAX_INSTANCE ; idx ++) { ... } return 0xFF; }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.