-
Notifications
You must be signed in to change notification settings - Fork 4
/
cy_capsense_sensing.c
1873 lines (1770 loc) · 88.9 KB
/
cy_capsense_sensing.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************//**
* \file cy_capsense_sensing.c
* \version 5.0
*
* \brief
* This file consists of common parts for different supported platforms
* like fourth and fifth generation platforms.
*
********************************************************************************
* \copyright
* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company)
* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
*******************************************************************************/
#include "cy_capsense_common.h"
#include "cycfg_capsense_defines.h"
#include "cy_capsense_structure.h"
#include "cy_capsense_sensing.h"
#include "cy_gpio.h"
#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
#include "cy_capsense_sensing_v2.h"
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
#include "cy_capsense_sensing_lp.h"
#include "cy_capsense_generator_lp.h"
#else /* (CY_CAPSENSE_PSOC4_FIFTH_GEN) */
#include "cy_capsense_sensing_v3.h"
#include "cy_capsense_generator_v3.h"
#endif
#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3) || defined(CY_IP_M0S8MSCV3LP))
/*******************************************************************************
* Function Name: Cy_CapSense_ScanWidget
****************************************************************************//**
*
* Performs the initialization required to scan the specified widget and triggers
* the scanning of all sensors in the widget.
*
* If the middleware is busy, do not initiate a new scan or set up widgets.
* Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment.
* Use the Cy_CapSense_MwState() function to verify if MW executes any firmware
* tasks related to initialization, scanning, and processing at a particular moment.
*
* For fifth-generation low power CAPSENSE™ the function initiates only
* Active widget scans. To initiate Low Power widget scan use
* the Cy_CapSense_ScanLpWidget() function.
*
* \note
* For the fourth-generation this function is also available and it should be used
* instead of Cy_CapSense_SetupWidget() and Cy_CapSense_Scan() functions.
* The specified widget will remain set up after scanning completes.
* If this function is called multiple times on the same widget, the set up
* is only done the first time but a scan will be done each time the function
* is called.
* For the fifth-generation CAPSENSE™ this function is available in
* single-channel solution only. It is recommended to use
* the Cy_CapSense_ScanSlots() function instead for compatibility with
* further CAPSENSE™ middleware versions.
*
* \param widgetId
* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the operation \ref cy_capsense_status_t.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ScanWidget(
uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
return Cy_CapSense_ScanWidget_V3(widgetId, context);
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
return Cy_CapSense_ScanWidget_V3Lp(widgetId, context);
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
return Cy_CapSense_ScanWidget_V2(widgetId, context);
#endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
}
/*******************************************************************************
* Function Name: Cy_CapSense_ScanSensor
****************************************************************************//**
*
* Initiates the scanning of the selected sensor in the widget.
*
* If the middleware is busy, do not initiate a new scan or set up widgets.
* Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment.
* Use the Cy_CapSense_MwState() function to verify if MW executes any firmware
* tasks related to initialization, scanning, and processing at a particular moment.
*
* \note
* For the fifth-generation CAPSENSE™ this function is available in
* single-channel solution. It is recommended to use
* the Cy_CapSense_ScanSlots() function instead for compatibility with
* further CAPSENSE™ middleware versions.
*
* \param widgetId
* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
*
* \param sensorId
* Specifies the ID number of the sensor within the widget. A macro for the
* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE_<WIDGET_NAME>_SNS<SENSOR_NUMBER>_ID.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the operation \ref cy_capsense_status_t.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ScanSensor(
uint32_t widgetId,
uint32_t sensorId,
cy_stc_capsense_context_t * context)
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
return Cy_CapSense_ScanSensor_V3(widgetId, sensorId, context);
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
return Cy_CapSense_ScanSensor_V3Lp(widgetId, sensorId, context);
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
return Cy_CapSense_ScanSensor_V2(widgetId, sensorId, context);
#endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
}
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)|| (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
/*******************************************************************************
* Function Name: Cy_CapSense_ScanAllSlots
****************************************************************************//**
*
* Initiates the non-blocking scan of all Active slots and then exits. Scanning
* is initiated only if no scan is in progress. To initiate all Low Power slot
* scan use the Cy_CapSense_ScanAllLpSlots() function.
*
* \par
* * For fifth-generation low power CAPSENSE™
* This function loads slots configurations into the internal buffer of the
* CAPSENSE™ hardware block and triggers scanning.
* If the scan frame doesn`t fit into the internal buffer it will be processed as
* the sequence of sub-frames. Next sub-frame will be loaded by the interrupt
* service routine(part of middleware) once scan of previous sub-frame is complete.
* The scanning process duration consists of a some
* pre-configured interval and a frame scan duration. The first slot scan starts
* after the pre-configured interval. The default duration of the interval is
* 1 ILO cycle. The interval duration can be changed
* by the Cy_CapSense_ConfigureMsclpTimer() function.
* If the "Enable external frame start" option is disabled in the CAPSENSE™
* Configurator, the scanning process will be triggered immediately.
* If the "Enable external frame start" option is enabled in the CAPSENSE™
* Configurator, the scanning process will be triggered by the first external
* synchronization signal after a function call.
* The number of slots in frame in this case should not exceed the maximum
* possible slot number to fit into the internal buffer of the CAPSENSE™
* hardware block.
* The External synchronization signal parameters should meet the following
* constraints:
* * - the interval between the return of the function and the rising edge
* of an external synchronization signal must not be less than 2 ILO cycles;
* * - the pulse duration of an external synchronization signal
* (if the signal is in High level) must not be less than 2 ILO cycles and more
* than the full scanning process duration. The full scanning process
* duration is the time between the rising edge of the external
* synchronization pulse and clearing of BUSY flag. The Cy_CapSense_IsBusy()
* function can be used to check BUSY flag;
* * - the interval between sub-sequent pulses should not be less than full
* scanning process duration.
* Disregarding the "Enable external frame start" option, the transition into
* system DEEP SLEEP mode is allowed after the scan process is started
* by the function.
* To decrease the start scan time when it is intended to scan the same frame,
* i.e. startSlotId and numberSlots parameters are the same, then the scan
* is performed without the MSC HW block reconfiguration.
* In this case, the number of slots in the frame shall not exceed the maximum
* possible slot number to fit into the internal buffer of the CAPSENSE™
* hardware block.
*
* \par
* * For fifth-generation CAPSENSE™ this function initiates a scan for
* the first slot for all channels and then exits. Scans for the remaining slots
* in the Interrupt-driven scan mode are initiated in the interrupt service
* routine (part of middleware) triggered at the end
* of each scan completed for each channel. If the syncMode field in the
* cy_stc_capsense_common_config_t structure is set to CY_CAPSENSE_SYNC_MODE_OFF,
* then the next slot scan for the channel with the fired interrupt,
* will start regardless of the another channel readiness for the next scan.
* If the syncMode field is set to CY_CAPSENSE_SYNC_INTERNAL (for single-chip projects)
* or to CY_CAPSENSE_SYNC_EXTERNAL (for multi-chip projects),
* then the next slot scan for the channel with the fired interrupt,
* will start in lockstep with another channels after they all are ready
* for the next scan (the next scan configuration is loaded into the channel MSC HW block).
* Scans for the remaining slots in CS-DMA scan mode are initiated
* by DMAC triggered at the end
* of each scan completed for each channel. The channel scan synchronization is
* performed as in Interrupt-driven scan mode. After all slots are scanned,
* the FRAME interrupt is fired and the interrupt service routine (part of middleware)
* updates the busy status. The transition into system DEEP SLEEP mode is allowed
* only when all scans are finished.
*
* If the middleware is busy, do not initiate a new scan or set up widgets.
* Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment.
* Use the Cy_CapSense_MwState() function to verify if MW executes any firmware
* tasks related to initialization, scanning, and processing at a particular moment.
*
* \note
* This function is available for the fifth-generation and fifth-generation low power CAPSENSE™.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the operation:
* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed successfully.
* - CY_CAPSENSE_STATUS_BAD_PARAM - The input parameter is invalid.
* - CY_CAPSENSE_STATUS_HW_BUSY - The HW is busy with the previous scan.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ScanAllSlots(
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
if (NULL != context)
{
capStatus = Cy_CapSense_ScanSlots(0u, CY_CAPSENSE_SLOT_COUNT, context);
}
return capStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ScanSlots
****************************************************************************//**
*
* Initiates the non-blocking scan of a specified regular slots set named "frame"
* and then exits.
* Scanning is initiated only if no scan is in progress.
* Check the status of the current scan using the Cy_CapSense_IsBusy()
* function. The application program should wait until the current frame scan is
* finished prior to start a next scan by using the function.
*
* \par
* * For fifth-generation low power CAPSENSE™
* The function loads the frame configuration into the internal buffer of the
* CAPSENSE™ hardware block and triggers the scanning process.
* If the frame configuration does not fit into the internal buffer its scan will
* be processed as a sequence of sub-frame scans. A next sub-frame will be loaded
* by the interrupt service routine (part of the middleware)
* after the previous sub-frame scan is complete.
* The scanning process duration consists of a some
* pre-configured interval and a frame scan duration. The first slot scan starts
* after the pre-configured interval. The default duration of the interval is
* 1 ILO cycle. The interval duration can be changed
* by the Cy_CapSense_ConfigureMsclpTimer() function.
* If the "Enable external frame start" option is disabled in the CAPSENSE™
* Configurator, the scanning process will be triggered immediately.
* If the "Enable external frame start" option is enabled in the CAPSENSE™
* Configurator, the scanning process will be triggered by the first external
* synchronization signal after a function call.
* In this case, the number of slots in the frame shall not exceed the maximum
* possible slot number to fit into the internal buffer of the CAPSENSE™
* hardware block.
* The External synchronization signal parameters should meet the following
* constraints:
* * - the interval between the return of the function and the rising edge
* of an external synchronization signal must not be less than 2 ILO cycles;
* * - the pulse duration of an external synchronization signal
* (if the signal is in High level) must not be less than 2 ILO cycles and more
* than the full scanning process duration. The full scanning process
* duration is the time between the rising edge of the external
* synchronization pulse and clearing of BUSY flag. The Cy_CapSense_IsBusy()
* function can be used to check BUSY flag;
* * - the interval between sub-sequent pulses should not be less than full
* scanning process duration.
* Disregarding the "Enable external frame start" option, the transition into
* a system DEEP SLEEP mode is allowed after the scan process is started
* by the function.
* To decrease the start scan time when it is intended to scan the same frame,
* i.e. startSlotId and numberSlots parameters are the same, then the scan
* is performed without the MSC HW block reconfiguration.
* In this case, the number of slots in the frame shall not exceed the maximum
* possible slot number to fit into the internal buffer of the CAPSENSE™
* hardware block.
*
* \par
* * For fifth-generation CAPSENSE™ this function initiates a scan for
* the first slot for all channels and then exits. Scans for the remaining slots
* in the Interrupt-driven scan mode are initiated in the interrupt service
* routine (part of middleware) triggered at the end
* of each scan completed for each channel. If the syncMode field in the
* cy_stc_capsense_common_config_t structure is set to CY_CAPSENSE_SYNC_MODE_OFF,
* then the next slot scan for the channel with the fired interrupt,
* will start regardless of the another channel readiness for the next scan.
* If the syncMode field is set to CY_CAPSENSE_SYNC_INTERNAL (for single-chip
* projects) or to CY_CAPSENSE_SYNC_EXTERNAL (for multi-chip projects),
* then the next slot scan for the channel with the fired interrupt,
* will start in lockstep with another channels after they all are ready
* for the next scan.
* The scan for the remaining slots in CS-DMA scan mode are initiated
* by DMAC triggered at the end
* of each scan completion for each channel. The channel scan synchronization is
* performed as in Interrupt-driven scan mode. After all specified slots are
* scanned, the FRAME interrupt is fired and the interrupt service routine
* (part of middleware) updates the busy status. The transition into a system
* DEEP SLEEP mode is allowed only when all specified scans are finished.
* To decrease the start scan time when it is intended to scan the same slot,
* i.e. the startSlotId parameter is the same and numberSlots = 1u, then the scan
* is performed without the MSC HW block reconfiguration. Also, in the legacy
* AMUX mode sensors are not disconnected.
*
* If the middleware is busy, do not initiate a new scan or set up widgets.
* Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment.
* Use the Cy_CapSense_MwState() function to verify if MW executes any firmware
* tasks related to initialization, scanning, and processing at a particular moment.
*
* \note
* This function is available for the fifth-generation and fifth-generation
* low power CAPSENSE™.
*
* \param startSlotId
* The slot ID the scan of the specified frame will be started from.
*
* \param numberSlots
* The number of slots in the specified frame will be scanned.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the operation:
* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed successfully.
* - CY_CAPSENSE_STATUS_BAD_PARAM - The input parameter is invalid.
* - CY_CAPSENSE_STATUS_HW_BUSY - The HW is busy with the previous scan.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ScanSlots(
uint32_t startSlotId,
uint32_t numberSlots,
cy_stc_capsense_context_t * context)
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
return Cy_CapSense_ScanSlots_V3(startSlotId, numberSlots, context);
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)*/
return Cy_CapSense_ScanSlots_V3Lp(startSlotId, numberSlots, context);
#endif
}
#endif
/*******************************************************************************
* Function Name: Cy_CapSense_ScanAllWidgets
****************************************************************************//**
*
* Initiates scanning of all enabled widgets (and sensors) in the project.
* For fifth-generation low power CAPSENSE™ the function initiates only
* Active widget scans. The initiation of a Low Power widget scan uses
* the Cy_CapSense_ScanAllLpWidgets() function.
*
* This function initiates a scan only for the first sensor in the first widget
* for the fourth-generation CAPSENSE™ or a scan for the first slot
* for the fifth-generation CAPSENSE™ and fifth-generation low power
* CAPSENSE™ and then exits the function. The scan
* for the remaining sensors(slots) are initiated in the interrupt-driven mode
* in the interrupt service routine (part of middleware) triggered at the end
* of each scan completion or by DMA controllers in the DMA mode for
* the fifth-generation CAPSENSE™. For the fifth-generation low power
* CAPSENSE™ the remaining sensor scans depend on the ACTIVE sensor
* quantity, for details see the Cy_CapSense_ScanAllSlots() function description.
*
* If the middleware is busy, do not initiate a new scan or set up widgets.
* Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment.
* Use the Cy_CapSense_MwState() function to verify if MW executes any firmware
* tasks related to initialization, scanning, and processing at a particular moment.
* The application program should wait until the current frame scan is finished prior
* to start a next scan by using the function.
*
* To get widget enable/working status the Cy_CapSense_IsWidgetEnabled() and
* Cy_CapSense_IsSlotEnabled() functions should be used. This status can be configured
* with Cy_CapSense_SetWidgetStatus() function.
*
* \note
* For the fifth-generation CAPSENSE™ and fifth-generation low power
* CAPSENSE™ it is recommended to use the Cy_CapSense_ScanAllSlots()
* function instead for compatibility with further CAPSENSE™
* middleware versions.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the operation \ref cy_capsense_status_t.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ScanAllWidgets(
cy_stc_capsense_context_t * context)
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
return Cy_CapSense_ScanAllWidgets_V3(context);
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
return Cy_CapSense_ScanAllWidgets_V3Lp(context);
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
return Cy_CapSense_ScanAllWidgets_V2(context);
#endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
}
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)|| (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
/*******************************************************************************
* Function Name: Cy_CapSense_MwState
****************************************************************************//**
*
* Returns a detailed state of the CAPSENSE™ middleware and MSC and
* MSCLP HW blocks in Single- or Multi-channel mode. This feature is useful in
* multi-thread applications or in ISR.
* Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment.
* Use the Cy_CapSense_MwState() function to verify if MW executes any firmware
* tasks related to initialization, scanning, and processing at a particular moment.
* If the middleware is busy, a new scan, setup widgets, any kind of reconfiguration,
* or parameter change should not be initiated.
*
* \note
* This function is available for the fifth-generation and fifth-generation
* low power CAPSENSE™.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the state of the middleware as a sum of the state and status masks:
*
* - CY_CAPSENSE_BUSY_CH_MASK - The set [x] bit of the result
* means that the previously initiated
* scan for the [x] channel is in progress.
* The next scan frame cannot be started.
* - CY_CAPSENSE_MW_STATE_ACTIVE_WD_SCAN_MASK - The last or currently scanned widget
* type is Active widget.
* \note This field is available only
* for the fifth-generation low power
* CAPSENSE™.
* - CY_CAPSENSE_MW_STATE_LP_WD_SCAN_MASK - The last or currently scanned widget
* type is Low Power widget.
* \note This field is available only
* for the fifth-generation low power
* CAPSENSE™.
* - CY_CAPSENSE_BUSY - The previously initiated scan is
* in progress.
* - CY_CAPSENSE_MW_STATE_BIST_MASK - The BIST is in progress.
* The next scan frame cannot be started.
* - CY_CAPSENSE_MW_STATE_CALIBRATION_MASK - The auto-calibration is in progress.
* The next scan frame cannot be started.
* - CY_CAPSENSE_MW_STATE_SMARTSENSE_MASK - The smart sensing algorithm is
* in progress.
* The next scan frame cannot be started.
* - CY_CAPSENSE_MW_STATE_INITIALIZATION_MASK - Middleware initialization is
* in progress and the next scan frame
* cannot be initiated.
* - CY_CAPSENSE_MW_STATE_SCAN_SLOT_MASK[x] - The set [x] number of the result
* means that the previously initiated
* scan for the [x] slot is completed
* or in progress. In CS-DMA mode, this
* field is set only for the first
* scanned slot.
*
*******************************************************************************/
cy_capsense_mw_state_t Cy_CapSense_MwState(const cy_stc_capsense_context_t * context)
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
return Cy_CapSense_MwState_V3(context);
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
return Cy_CapSense_MwState_V3Lp(context);
#endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
}
#endif /* ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)|| (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)) */
/*******************************************************************************
* Function Name: Cy_CapSense_IsBusy
****************************************************************************//**
*
* This function returns a status whether MW executes HW scanning at a particular moment.
*
* If the middleware is busy, do not initiate a new scan or set up widgets.
* Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment.
* Use the Cy_CapSense_MwState() function to verify if MW executes any firmware
* tasks related to initialization, scanning, and processing at a particular moment.
* If the middleware is busy, a new scan, setup widgets, any kind of reconfiguration,
* or parameter change should not be initiated.
*
* \param context
* The pointer to the CAPSENSE™ context
* structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the middleware as a sum of the masks.
* - CY_CAPSENSE_NOT_BUSY - No scan is in progress and
* a next scan can be initiated.
* - CY_CAPSENSE_BUSY - The previously initiated scan is
* in progress.
*
*******************************************************************************/
uint32_t Cy_CapSense_IsBusy(
const cy_stc_capsense_context_t * context)
{
return (context->ptrCommonContext->status & CY_CAPSENSE_BUSY);
}
/*******************************************************************************
* Function Name: Cy_CapSense_InterruptHandler
****************************************************************************//**
*
* Implements interrupt service routine for CAPSENSE™ middleware.
*
* The CAPSENSE™ middleware uses this interrupt to implement a
* non-blocking sensor scan method, in which only the first sensor scan is
* initiated by the application program. Subsequent sensor scans are
* initiated in the interrupt service routine as soon as the current scan
* or current sub-frame is completed.
*
* The CAPSENSE™ middleware does not initialize or modify the priority
* of interrupts. For the proper middleware operation, the application program
* must configure CAPSENSE™ block interrupt and assign the interrupt
* vector to the Cy_CapSense_InterruptHandler() function. Refer to function
* usage example for details.
*
* The calls of the Start Sample and End Of Scan callbacks
* (see the \ref group_capsense_callbacks section for details) are the part
* of the Cy_CapSense_InterruptHandler() routine and they lengthen its execution.
* These callbacks should not lengthen the ISR execution too much to prevent
* different interrupt overlaps.
*
* \param base
* The pointer to the base register address of the CAPSENSE™ HW block.
* This argument is kept for uniformity and backward compatibility
* and is not used. The function can be called with value NULL.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \funcusage
*
* An example of the ISR initialization:
*
* The CapSense_ISR_cfg variable should be declared by the application
* program according to the examples below:<br>
* For Core CM0+:
* \snippet capsense/snippet/main.c snippet_m0p_capsense_interrupt_source_declaration
* \note MSCLP HW contains two interrupt sources.
* The CAPSENSE™ Middleware supports only the msclp_interrupt_<b>lp</b>_IRQn
* vector and therefore it should be used.
*
* For Core CM4:
* \snippet capsense/snippet/main.c snippet_m4_capsense_interrupt_source_declaration
*
* The CAPSENSE™ interrupt handler should be defined by the application program
* according to the example below:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_IntHandler
*
* Then, the application program should configure and enable the CSD block interrupt
* between calls of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Initialization
*
* The CapSense_HW is the pointer to the base register address of
* the CAPSENSE™ HW block. A macro for the pointer is in the cycfg_peripherals.h
* file defined as \<Personality_Name\>_HW. If no name is specified,
* the following default names are used:
* * csd_\<Block_Number\>_csd_\<Block_Number\>_HW - for forth-generation CAPSENSE™ HW.
* * msc_\<Block_Number\>_msc_\<Block_Number\>_HW - for fifth-generation CAPSENSE™ HW.
* * msclp_\<Block_Number\>_msclp_\<Block_Number\>_HW - for fifth-generation low power CAPSENSE™ HW.
*
* An example of sharing the CSD HW block (fourth-generation CAPSENSE™) by the CAPSENSE™
* middleware and CSDADC middleware.<br>
* Declares the CapSense_ISR_cfg variable:
* \snippet capsense/snippet/main.c snippet_m4_capsense_interrupt_source_declaration
*
* Declares the CSDADC_ISR_cfg variable:
* \snippet capsense/snippet/main.c snippet_m4_adc_interrupt_source_declaration
*
* Defines the CAPSENSE™ interrupt handler:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_IntHandler
*
* Defines the CSDADC interrupt handler:
* \snippet capsense/snippet/main.c snippet_CSDADC_Interrupt
*
* The part of the main.c FW flow:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_TimeMultiplex
*
*******************************************************************************/
void Cy_CapSense_InterruptHandler(
void * base,
cy_stc_capsense_context_t * context)
{
(void)base;
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
Cy_CapSense_InterruptHandler_V3(NULL, context);
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
Cy_CapSense_InterruptHandler_V3Lp(NULL, context);
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
Cy_CapSense_InterruptHandler_V2(NULL, context);
#endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
}
/*******************************************************************************
* Function Name: Cy_CapSense_CalibrateAllWidgets
****************************************************************************//**
*
* Executes CapDAC/IDAC auto-calibration for all the sensors in all widgets
* of some sensing groups (CSD, CSX, or ISX) if calibration is enabled
* for such group of widgets. The auto-calibration finds CapDAC/IDAC values
* to have raw counts close to configured target values. Use sensing and
* processing functions after auto-calibration to update all baselines and
* configured filters.
*
* Having enabled the CDAC auto-calibration algorithm is the most common use
* case. It helps to tune your system considering board-to-board variation,
* temperature drift, etc. CDAC auto-calibration is enabled by default.
*
* The default auto-calibration target values are defined as:
* * 85% of the maximum raw count for CSD widgets
* * 40% of the maximum raw count for CSX widgets.
* * 40% of the maximum raw count for ISX widgets.
* Use the Cy_CapSense_SetCalibrationTarget() function to change calibration targets .
*
* For fifth-generation low power CAPSENSE™ the function calibrates only
* Active widgets. For Low Power widgets use
* the Cy_CapSense_CalibrateAllLpWidgets() function.
*
* This function detects the sensing method used by each widget and performs
* a successive approximation search algorithm to find the appropriate Reference
* and Compensation CapDAC (if enabled) values for all sensors for
* the fifth-generation CAPSENSE™ and for all Active sensors for
* the fifth-generation low power CAPSENSE™. For the fifth-generation
* low power CAPSENSE™ if during the calibration process it is reached
* the Reference CapDAC value lower than /ref CY_CAPSENSE_CAL_REF_CDAC_MIN_CODE
* and Fine CapDAC usage is enabled in CAPSENSE™ Configurator then
* the FineCDAC calibration is performed with the reference CDAC value set to 0.
*
* For the the forth-generation
* CAPSENSE™ the function finds appropriate modulator and compensation
* IDAC (if enabled) values for all sensors in CSD widgets
* and/or IDAC values for all sensors in CSX widgets to make sensor raw count
* to the default value level.
*
* This function could be used only if Enable auto-calibration parameter
* is enabled for CSD and/or CSX (and/or ISX for fifth-generation low power
* CAPSENSE™) widgets.
*
* \note
* For the fifth-generation CAPSENSE™ this function is available in
* single-channel solution. It is recommended to use
* the Cy_CapSense_CalibrateAllSlots() function instead for compatibility with
* further CAPSENSE™ middleware versions.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the operation \ref cy_capsense_status_t.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_CalibrateAllWidgets(
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t retVal = CY_CAPSENSE_STATUS_BAD_CONFIG;
(void)context;
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_CALIBRATION_EN))
retVal = Cy_CapSense_CalibrateAllWidgets_V3(context);
#endif
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_CALIBRATION_EN))
retVal = Cy_CapSense_CalibrateAllWidgets_V3Lp(context);
#endif
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN))
retVal = Cy_CapSense_CalibrateAllWidgets_V2(context);
#endif
#endif
return retVal;
}
#if (((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)) && \
((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_CALIBRATION_EN)))
/*******************************************************************************
* Function Name: Cy_CapSense_CalibrateAllSlots
****************************************************************************//**
*
* Executes CapDAC/IDAC auto-calibration for all the sensors in all widgets
* of some sensing groups (CSD, CSX, or ISX) if calibration is enabled
* for such group of widgets. The auto-calibration finds CapDAC/IDAC values
* to have raw counts close to configured target values. Use sensing and
* processing functions after auto-calibration to update all baselines and
* configured filters.
*
* Having enabled the CDAC auto-calibration algorithm is the most common use
* case. It helps to tune your system considering board-to-board variation,
* temperature drift, etc. CDAC auto-calibration is enabled by default.
*
* For fifth-generation low power CAPSENSE™ the function calibrates only
* Active widgets. For Low Power widgets use
* the Cy_CapSense_CalibrateAllLpWidgets() function.
*
* The function performs searching of Reference CDAC code, Compensation CDAC
* code Compensation Divider (whichever is enabled) by using a successive
* approximation method to make the sensor's raw count closest to the
* defined targets. The auto-calibration target values are defined
* (by default) as:
* * 85% of the maximum raw count for CSD widgets
* * 40% of the maximum raw count for CSX widgets.
* * 40% of the maximum raw count for ISX widgets.
* Use the Cy_CapSense_SetCalibrationTarget() function to change calibration targets .
*
* For the fifth-generation
* low power CAPSENSE™ if during the calibration process it is reached
* the Reference CapDAC value lower than /ref CY_CAPSENSE_CAL_REF_CDAC_MIN_CODE
* and Fine CapDAC usage is enabled in CAPSENSE™ Configurator then
* the FineCDAC calibration is performed with the reference CDAC value set to 0.
*
* \note
* This function is available for the fifth-generation CAPSENSE™ and
* fifth-generation low power CAPSENSE™.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the operation:
* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed successfully.
* - CY_CAPSENSE_STATUS_BAD_PARAM - The input parameter is invalid.
* - CY_CAPSENSE_STATUS_CALIBRATION_FAIL - The calibration is failed due to
* the issues with scanning (either
* watchdog timer, interrupt breaking, etc.).
* - CY_CAPSENSE_STATUS_CALIBRATION_REF_CHECK_FAIL - The reference/fine CapDAC
* calibration stage is failed as the raw count
* minimum across widget is out of range.
* - CY_CAPSENSE_STATUS_CALIBRATION_CHECK_FAIL - The resulting rawcounts across
* all sensors in widget are out of defined range.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_CalibrateAllSlots(cy_stc_capsense_context_t * context)
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
return Cy_CapSense_CalibrateAllSlots_V3(context);
#else
return Cy_CapSense_CalibrateAllSlots_V3Lp(context);
#endif
}
/*******************************************************************************
* Function Name: Cy_CapSense_SetCalibrationTarget
****************************************************************************//**
*
* Sets the CapDAC auto-calibration raw count target for CSD, CSX or ISX
* widgets. The function only updates the target value, use
* Cy_CapSense_CalibrateWidget() / Cy_CapSense_CalibrateAllWidgets() /
* Cy_CapSense_CalibrateAllLpWidgets() / Cy_CapSense_CalibrateAllSlots() to change
* raw counts according to the updated target.
*
* The function sets the specified raw count targets if CSD, CSX and/or ISX
* widgets are in the project and the auto-calibration is enabled for them. These
* targets will be used instead the configured ones by
* Cy_CapSense_CalibrateAllSlots(), Cy_CapSense_CalibrateAllWidgets() and
* Cy_CapSense_CalibrateWidget() functions.
*
* \note
* This function is available only for the fifth-generation CAPSENSE™ and
* fifth-generation low power CAPSENSE™.
*
* \param calibrTarget
* The raw counts target in percentage for the specified sensing method.
* It should be in range [1..99]. If the specified target is
* outside the range, then it will not be updated and the
* CY_CAPSENSE_STATUS_BAD_PARAM status will be returned.
*
* \param snsMethod
* Desired sensing method the calibration target should be updated for:
* * CY_CAPSENSE_CSD_GROUP - CSD sensing method
* * CY_CAPSENSE_CSX_GROUP - CSX sensing method
* * CY_CAPSENSE_ISX_GROUP - ISX sensing method
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the operation:
* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed successfully.
* - CY_CAPSENSE_STATUS_BAD_PARAM - At least one of the input parameter is
* invalid.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_SetCalibrationTarget(
uint32_t calibrTarget,
uint32_t snsMethod,
cy_stc_capsense_context_t * context)
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
return Cy_CapSense_SetCalibrationTarget_V3(calibrTarget, snsMethod, context);
#else
return Cy_CapSense_SetCalibrationTarget_V3Lp(calibrTarget, snsMethod, context);
#endif
}
#endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN || CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP) */
#if (((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) && (1u == CY_CAPSENSE_TOTAL_CH_NUMBER)) ||\
(CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
/*******************************************************************************
* Function Name: Cy_CapSense_CalibrateWidget
****************************************************************************//**
*
* Executes the CapDAC/IDAC calibration for all the sensors in the specified
* widget to the default target value.
*
* This function performs exactly the same tasks as
* Cy_CapSense_CalibrateAllWidgets(), but only for a specified widget. Use
* sensing and processing functions after auto-calibration to update all
* baselines and configured filters.
*
* \note
* For the fifth-generation CAPSENSE™ this function is available in
* single-channel solution. It is recommended to use
* the Cy_CapSense_CalibrateAllSlots() function instead for compatibility with
* further CAPSENSE™ middleware versions.
*
* \param widgetId
* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the operation \ref cy_capsense_status_t.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_CalibrateWidget(
uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t retVal = CY_CAPSENSE_STATUS_BAD_CONFIG;
(void)widgetId;
(void)context;
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN) ||\
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_CALIBRATION_EN))
retVal = Cy_CapSense_CalibrateWidget_V3(widgetId, context);
#endif
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN) ||\
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_CALIBRATION_EN))
retVal = Cy_CapSense_CalibrateWidget_V3Lp(widgetId, context);
#endif
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN))
retVal = Cy_CapSense_CalibrateWidget_V2(widgetId, context);
#endif
#endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
return retVal;
}
#endif /* #if (((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) && (1u == CY_CAPSENSE_TOTAL_CH_NUMBER)) ||\
(CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)) */
#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN || \
((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) && \
(CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)))
/*******************************************************************************
* Function Name: Cy_CapSense_SetPinState
****************************************************************************//**
*
* Sets the state (drive mode and HSIOM state) of the GPIO used by a sensor.
*
* The possible states are GND, Shield, High-Z, Tx, Negative Tx, Rx, and Sensor.
* If the sensor specified in the input parameter is a ganged sensor, then
* the state of all GPIOs associated with the ganged sensor is updated.
*
* To access a sensor of CSD of button or slider widgets, use the sensor ID.
* To access a sensor of CSD matrix button or touchpad widgets,
* use either row ID or column ID as appropriate.
* To access sensor CSX widgets, use either Rx ID or Tx ID as appropriate.
*
* This function accepts the CY_CAPSENSE_SHIELD and CY_CAPSENSE_SENSOR states
* as an input only if there is at least one CSD widget in the project.
* Similarly, this function accepts the CY_CAPSENSE_TX_PIN and
* CY_CAPSENSE_RX_PIN states as an input only if there is at least one
* CSX widget in the project.
*
* This function must not be called while the middleware is in the busy state.
* Calling this function directly from the application program is not
* recommended. This function is used to implement only the custom-specific
* use cases.
*
* Functions that perform a setup and scan of a sensor/widget automatically
* set the required pin states for a sensor as required and overwrite changes
* made by this function to a sensor that are going to be scanned. Therefore
* the Cy_CapSense_SetPinState() function should be called in StartSample
* callback (see the \ref group_capsense_callbacks section for details)
* or with low-level functions that perform a single-sensor scanning.
*
* The function is available for the fourth-generation and fifth-generation (only
* for CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) CAPSENSE™. For fifth-generation
* CAPSENSE&trade with CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD and for fifth-
* generation low power CAPSENSE&trade use Cy_CapSense_SlotPinState().
*
* \param widgetId
* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
*
* \param sensorElement
* Specifies the ID of the sensor element within the widget to change
* its pin state.
* * For the CSD widgets use the sensor ID. A macro for the
* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE_<WIDGET_NAME>_SNS<SENSOR_NUMBER>_ID.
* * For the CSX widgets use either Rx ID or Tx ID.
* The first Rx in a widget corresponds to sensorElement = 0; the second
* Rx in a widget corresponds to sensorElement = 1, and so on.
* The last Tx in a widget corresponds to sensorElement = (RxNum + TxNum - 1).
* A macro for the Rx ID or Tx ID can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE_<WIDGET_NAME>_<TX/RX><TX/RX_NUMBER>_ID.
*
* \param state
* Specifies the state of the sensor to be set:
* 1. CY_CAPSENSE_GROUND - The pin is connected to the ground.
* 2. CY_CAPSENSE_HIGHZ - The drive mode of the pin is set to High-Z
* Analog.
* 3. CY_CAPSENSE_SHIELD - The shield signal is routed to the pin
* (available only if CSD sensing method with
* shield electrode is enabled).
* 4. CY_CAPSENSE_SENSOR - The pin is connected to the scanning bus
* (available only if CSD sensing method
* is enabled).
* 5. CY_CAPSENSE_TX_PIN - The Tx signal is routed to the sensor
* (available only if CSX sensing method
* is enabled).
* 6. CY_CAPSENSE_RX_PIN - The pin is connected to the scanning bus
* (available only if CSX sensing method
* is enabled).
* 7. CY_CAPSENSE_NEGATIVE_TX_PIN - The Negative Tx signal is routed to the sensor
* (available only if CSD sensing method
* is enabled).
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return status
* Returns the operation status:
* - CY_CAPSENSE_STATUS_SUCCESS - Indicates the successful electrode setting.
* - CY_CAPSENSE_STATUS_BAD_PARAM - 1) widgetID, sensorElement or state
* are not valid;
* 2) the CSD sensing method is disabled for desired
* CY_CAPSENSE_SHIELD or CY_CAPSENSE_SENSOR states;
* 3) the CSX sensing method is disabled for desired
* CY_CAPSENSE_TX_PIN, CY_CAPSENSE_NEGATIVE_TX_PIN or
* CY_CAPSENSE_RX_PIN states.
*
* \funcusage
* An example of using the Cy_CapSense_SetPinState() function to perform
* sensor state re-configuration:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_SetPinState
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_SetPinState(
uint32_t widgetId,
uint32_t sensorElement,
uint32_t state,
const cy_stc_capsense_context_t * context)
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
return Cy_CapSense_SetPinState_V3(widgetId, sensorElement, state, context);
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */