-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcy_capsense_sensing_v2.c
3030 lines (2751 loc) · 124 KB
/
cy_capsense_sensing_v2.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_v2.c
* \version 5.0
*
* \brief
* This file contains the source of functions common for different sensing
* methods.
*
********************************************************************************
* \copyright
* Copyright 2018-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 <stdlib.h>
#include <stddef.h>
#include "cy_gpio.h"
#include "cy_sysclk.h"
#include "cycfg_capsense_defines.h"
#include "cy_capsense_common.h"
#include "cy_capsense_structure.h"
#include "cy_capsense_sensing_v2.h"
#include "cy_capsense_sensing.h"
#include "cy_capsense_csx_v2.h"
#include "cy_capsense_csd_v2.h"
#include "cy_capsense_lib.h"
#include "cy_capsense_selftest.h"
#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
#include "cy_csd.h"
#endif
#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
/*******************************************************************************
* Constants
*******************************************************************************/
#define CY_CAPSENSE_AUTOTUNE_CALIBRATION_RESOLUTION (12u)
#define CY_CAPSENSE_AUTOTUNE_CALIBRATION_FREQ_KHZ (1500u)
#define CY_CAPSENSE_CSD_SNS_FREQ_KHZ_MAX (6000u)
#define CY_CAPSENSE_CSD_AUTOTUNE_CAL_UNITS (1000u)
#define CY_CAPSENSE_AUTOTUNE_CP_MAX (69000Lu)
#define CY_CAPSENSE_EXT_CAP_DISCHARGE_TIME (1u)
#define CY_CAPSENSE_VREF_GAIN_MAX (32u)
#define CY_CAPSENSE_VREF_VDDA_MIN_DIFF (600u)
#if (CY_CAPSENSE_PSOC4_FOURTH_GEN)
#define CY_CAPSENSE_VREF_SRSS_MV (1200u)
#else
#define CY_CAPSENSE_VREF_SRSS_MV (800u)
#endif
#define CY_CAPSENSE_VREF_PASS_MV (1200u)
#if (CY_CAPSENSE_PSOC4_FOURTH_GEN)
#define CY_CAPSENSE_VREF_RANGE_0 (4700u)
#define CY_CAPSENSE_VREF_RANGE_1 (3200u)
#define CY_CAPSENSE_VREF_RANGE_2 (2600u)
#define CY_CAPSENSE_VREF_VALUE_0 (2743u)
#define CY_CAPSENSE_VREF_VALUE_1 (2021u)
#define CY_CAPSENSE_VREF_VALUE_2 (1477u)
#define CY_CAPSENSE_VREF_VALUE_MIN (1200u)
#else
#define CY_CAPSENSE_VREF_RANGE_0 (2750u)
#define CY_CAPSENSE_VREF_RANGE_1 (2200u)
#define CY_CAPSENSE_VREF_VALUE_0 (2133u)
#define CY_CAPSENSE_VREF_VALUE_1 (1600u)
#define CY_CAPSENSE_VREF_VALUE_MIN_SRSS (1164u)
#define CY_CAPSENSE_VREF_VALUE_MIN_PASS (1200u)
#endif
#if (CY_CAPSENSE_DISABLE == CY_CAPSENSE_USE_CAPTURE)
const cy_stc_csd_config_t cy_capsense_csdCfg = CY_CAPSENSE_CSD_CONFIG_DEFAULT;
#endif
/*******************************************************************************
* Function Name: Cy_CapSense_SetBusyFlags
****************************************************************************//**
*
* Sets BUSY flags of the cy_capsense_context.status register specified
* by the flags parameter.
*
* This is an internal function. Do not call this function directly from
* the application program.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
*******************************************************************************/
void Cy_CapSense_SetBusyFlags(cy_stc_capsense_context_t * context)
{
context->ptrCommonContext->status |= CY_CAPSENSE_BUSY;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ClrBusyFlags
****************************************************************************//**
*
* Clears BUSY flags of the cy_capsense_context.status register specified
* by the flags parameter.
*
* This is an internal function. Do not call this function directly from
* the application program.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
*******************************************************************************/
void Cy_CapSense_ClrBusyFlags(cy_stc_capsense_context_t * context)
{
/* Clear busy flag */
context->ptrCommonContext->status &= (uint32_t)(~((uint32_t)CY_CAPSENSE_BUSY));
context->ptrActiveScanSns->scanScope = CY_CAPSENSE_SCAN_SCOPE_SNGL_SNS;
/* Mark completion of scan cycle */
context->ptrCommonContext->scanCounter++;
if (NULL != context->ptrInternalContext->ptrEOSCallback)
{
context->ptrInternalContext->ptrEOSCallback(context->ptrActiveScanSns);
}
}
/*******************************************************************************
* Function Name: Cy_CapSense_SetupWidget
****************************************************************************//**
*
* Performs the initialization required to scan the specified widget.
*
* \deprecated This function is deprecated, it will become obsolete in upcoming
* major version of middleware. It is kept for backward compatibility only.
* The Cy_CapSense_ScanWidget() function should be used instead.
*
* This function prepares the middleware to scan all the sensors in the specified
* widget by executing the following tasks:
* 1. Configure the CSD HW block if it is not configured to perform the
* sensing method used by the specified widget. This happens only if the
* CSD and CSX methods are used in a user's project.
* 2. Initialize the CSD HW block with specific sensing configuration (e.g.
* sensor clock, scan resolution) used by the widget.
* 3. Disconnect all previously connected electrodes.
*
* This function does not start sensor scanning. The Cy_CapSense_Scan()
* function must be called to start the scan sensors in the widget. If this
* function is called more than once, it does not break the middleware operation,
* but only the last initialized widget is in effect.
*
* The status of a sensor scan must be checked using the Cy_CapSense_IsBusy()
* function prior to starting a next scan or setting up another widget.
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \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 widget setting up operation:
* - CY_CAPSENSE_STATUS_SUCCESS - The operation is successfully completed.
* - CY_CAPSENSE_STATUS_BAD_PARAM - The widget is invalid or if the specified widget is
* disabled.
* - CY_CAPSENSE_STATUS_INVALID_STATE - The previous scanning is not completed and
* the CSD HW block is busy.
* - CY_CAPSENSE_STATUS_UNKNOWN - An unknown sensing method is used by the widget or
* any other spurious error occurred.
*
**********************************************************************************/
cy_capsense_status_t Cy_CapSense_SetupWidget(
uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t widgetStatus;
if (CY_CAPSENSE_BUSY == Cy_CapSense_IsBusy(context))
{
/* Previous widget is being scanned. Return error. */
widgetStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
}
/*
* Check whether widget id is valid, specified widget is enabled and widget did not
* detect any fault conditions. If all conditions are met,
* set widgetStatus as good, if not, set widgetStatus as bad.
*/
else if ((context->ptrCommonConfig->numWd > widgetId) &&
(0u != Cy_CapSense_IsWidgetEnabled(widgetId, context)))
{
/* Check widget sensing method and call corresponding setup function */
switch (context->ptrWdConfig[widgetId].senseMethod)
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
case CY_CAPSENSE_CSD_GROUP:
Cy_CapSense_CSDSetupWidget(widgetId, context);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
case CY_CAPSENSE_CSX_GROUP:
Cy_CapSense_CSXSetupWidget(widgetId, context);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
default:
/* No other sensing methods */
break;
}
widgetStatus = CY_CAPSENSE_STATUS_SUCCESS;
}
else
{
widgetStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
}
return widgetStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_Scan
****************************************************************************//**
*
* Initiates scanning of all the sensors in the widget initialized by
* Cy_CapSense_SetupWidget(), if no scan is in progress.
*
* \deprecated This function is deprecated, it will become obsolete in upcoming
* major version of middleware. It is kept for backward compatibility only.
* The Cy_CapSense_ScanWidget() function should be used instead without additional
* call of Cy_CapSense_SetupWidget().
*
* Prior to calling this function to scan sensors, the widget required
* to be scanned must be initialized using Cy_CapSense_SetupWidget() function.
*
* This function initiates scan only for the first sensor in the widget and then
* exits the function. The scan for the remaining sensors in the widget is
* initiated in the interrupt service routine (part of middleware) triggered
* at the end of each scan completion. Hence, check the status of the current scan
* using the Cy_CapSense_IsBusy() function and wait until all scans
* in the current widget are finished prior to starting the next scan or
* initializing another widget.
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the scan initiation operation:
* - CY_CAPSENSE_STATUS_SUCCESS - Scanning is successfully started.
* - CY_CAPSENSE_STATUS_INVALID_STATE - The previous scan is not completed and
* the CSD HW block is busy.
* - CY_CAPSENSE_STATUS_UNKNOWN - An unknown sensing method is used by the widget.
*
********************************************************************************/
cy_capsense_status_t Cy_CapSense_Scan(cy_stc_capsense_context_t * context)
{
cy_capsense_status_t scanStatus = CY_CAPSENSE_STATUS_SUCCESS;
if (CY_CAPSENSE_BUSY == Cy_CapSense_IsBusy(context))
{
/* Previous widget is being scanned. Return error. */
scanStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
}
else
{
/* Check widget sensing method and call appropriate functions */
switch (context->ptrActiveScanSns->ptrWdConfig->senseMethod)
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
case CY_CAPSENSE_CSD_GROUP:
Cy_CapSense_CSDScan(context);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
case CY_CAPSENSE_CSX_GROUP:
Cy_CapSense_CSXScan(context);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
default:
scanStatus = CY_CAPSENSE_STATUS_UNKNOWN;
break;
}
}
return scanStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ScanWidget_V2
****************************************************************************//**
*
* Configures the specified widget and initiates scanning of all the sensors
* in the widget if no scan is in progress.
*
* This function initiates scan only for the first sensor in the widget and then
* exits the function. The scan for the remaining sensors in the widget is
* initiated in the interrupt service routine (part of middleware) triggered
* at the end of each scan completion. Hence, status of the current scan
* should be checked using the Cy_CapSense_IsBusy() and wait until all scans
* in the current widget are finished prior to starting the next scan or
* initializing another widget.
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \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 scan initiation operation:
* - CY_CAPSENSE_STATUS_SUCCESS - Scanning is successfully started.
* - CY_CAPSENSE_STATUS_INVALID_STATE - The previous scan is not completed and
* the CSD HW block is busy.
* - CY_CAPSENSE_STATUS_UNKNOWN - An unknown sensing method is used by the widget.
*
********************************************************************************/
cy_capsense_status_t Cy_CapSense_ScanWidget_V2(uint32_t widgetId, cy_stc_capsense_context_t * context)
{
cy_stc_capsense_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
cy_capsense_status_t scanStatus = CY_CAPSENSE_STATUS_SUCCESS;
if (CY_CAPSENSE_BUSY == Cy_CapSense_IsBusy(context))
{
/* Previous widget is being scanned. Return error. */
scanStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
}
else
{
if ((context->ptrActiveScanSns->widgetIndex != (uint8_t)widgetId) ||
(ptrActive->connectedSnsState != CY_CAPSENSE_SNS_DISCONNECTED) ||
(ptrActive->currentSenseMethod != context->ptrWdConfig[widgetId].senseMethod))
{
scanStatus = Cy_CapSense_SetupWidget(widgetId, context);
}
if (CY_CAPSENSE_STATUS_SUCCESS == scanStatus)
{
scanStatus = Cy_CapSense_Scan(context);
}
}
return scanStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_SetupWidgetExt
****************************************************************************//**
*
* Performs extended initialization for the specified widget and also performs
* initialization required for a specific sensor in the widget.
*
* This function requires using the Cy_CapSense_ScanExt() function to
* initiate a scan.
*
* This function does the same as Cy_CapSense_SetupWidget() and also
* does the following tasks:
* 1. Connects the specified sensor of the widget.
* 2. Configures the CSD HW block to perform a scan of the specified sensor.
*
* Once this function is called to initialize a widget and a sensor, the
* Cy_CapSense_ScanExt() function is called to scan the sensor.
*
* This function is called when no scanning is in progress. I.e.
* Cy_CapSense_IsBusy() returns a non-busy status.
*
* Calling this function directly from the application program is not
* recommended. This function is used to implement only the user's specific
* use cases (for faster execution time or pipeline scanning, for example).
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \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 widget setting up operation:
* - CY_CAPSENSE_STATUS_SUCCESS - The operation is successfully completed.
* - CY_CAPSENSE_STATUS_BAD_PARAM - The widget is invalid or if the specified widget is
* disabled.
* - CY_CAPSENSE_STATUS_INVALID_STATE - The previous scanning is not completed and
* the CSD HW block is busy.
*
**********************************************************************************/
cy_capsense_status_t Cy_CapSense_SetupWidgetExt(
uint32_t widgetId,
uint32_t sensorId,
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t widgetStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
if (CY_CAPSENSE_BUSY == Cy_CapSense_IsBusy(context))
{
/* Previous widget is being scanned. Return error. */
widgetStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
}
/*
* Check whether widget id is valid, specified widget is enabled and widget did not
* detect any fault conditions. If all conditions are met,
* set widgetStatus as good, if not, set widgetStatus as bad.
*/
else if ((context->ptrCommonConfig->numWd > widgetId) &&
(0u != Cy_CapSense_IsWidgetEnabled(widgetId, context)))
{
if (context->ptrWdConfig[widgetId].numSns > sensorId)
{
/* Check widget sensing method and call corresponding setup function */
switch (context->ptrWdConfig[widgetId].senseMethod)
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
case CY_CAPSENSE_CSD_GROUP:
Cy_CapSense_CSDSetupWidgetExt(widgetId, sensorId, context);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
case CY_CAPSENSE_CSX_GROUP:
Cy_CapSense_CSXSetupWidgetExt(widgetId, sensorId, context);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
default:
/* No other sensing methods */
break;
}
widgetStatus = CY_CAPSENSE_STATUS_SUCCESS;
}
}
else
{
/* Do nothing */
}
return widgetStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ScanExt
****************************************************************************//**
*
* Starts a conversion on the pre-configured sensor. This function requires
* using the Cy_CapSense_SetupWidgetExt() function to set up the a
* widget.
*
* This function performs single scanning of one sensor in the widget configured
* by the Cy_CapSense_SetupWidgetExt() function.
*
* Calling this function directly from the application program is not
* recommended. This function is used to implement only the user's specific
* use cases (for faster execution time or pipeline scanning, for example).
* This function is called when no scanning is in progress. I.e.
* Cy_CapSense_IsBusy() returns a non-busy status.
*
* The sensor must be pre-configured by using the
* Cy_CapSense_SetupWidgetExt() prior to calling this function.
* The sensor remains ready for the next scan if a previous scan was triggered
* by using the Cy_CapSense_ScanExt() function. In this case, calling
* Cy_CapSense_SetupWidgetExt() is not required every time before the
* Cy_CapSense_ScanExt() function. If a previous scan was triggered in
* any other way - Cy_CapSense_Scan(), Cy_CapSense_ScanAllWidgets(), or
* Cy_CapSense_RunTuner() - (see the Cy_CapSense_RunTuner() function
* description for more details), the sensor must be pre-configured again by
* using the Cy_CapSense_SetupWidgetExt() prior to calling the
* Cy_CapSense_ScanExt() function.
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ScanExt(cy_stc_capsense_context_t * context)
{
cy_capsense_status_t scanStatus = CY_CAPSENSE_STATUS_SUCCESS;
if (CY_CAPSENSE_BUSY == Cy_CapSense_IsBusy(context))
{
/* Previous widget is being scanned. Return error. */
scanStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
}
else
{
/* Check widget sensing method and call appropriate functions */
switch (context->ptrActiveScanSns->ptrWdConfig->senseMethod)
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
case CY_CAPSENSE_CSD_GROUP:
Cy_CapSense_CSDScanExt(context);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
case CY_CAPSENSE_CSX_GROUP:
Cy_CapSense_CSXScanExt(context);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
default:
scanStatus = CY_CAPSENSE_STATUS_UNKNOWN;
break;
}
}
return scanStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ScanSensor_V2
****************************************************************************//**
*
* Starts a conversion on the specified sensor.
*
* Calling this function directly from the application program is not
* recommended. This function is used to implement only the user's specific
* use cases (for faster execution time or pipeline scanning, for example).
* This function is called when no scanning is in progress. I.e.
* Cy_CapSense_IsBusy() returns a non-busy status.
* If the widget is already configured by previous call of this function, the
* widget re-configuration is skipped.
*
* \note
* This function is available only for the fourth-generation CAPSENSE™.
*
* \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.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ScanSensor_V2(
uint32_t widgetId,
uint32_t sensorId,
cy_stc_capsense_context_t * context)
{
cy_stc_capsense_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
cy_capsense_status_t scanStatus = CY_CAPSENSE_STATUS_SUCCESS;
if (CY_CAPSENSE_BUSY == Cy_CapSense_IsBusy(context))
{
/* Previous widget is being scanned. Return error. */
scanStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
}
else
{
if ((ptrActive->widgetIndex != (uint8_t)widgetId) ||
(ptrActive->sensorIndex != (uint8_t)sensorId) ||
(ptrActive->currentSenseMethod != context->ptrWdConfig[widgetId].senseMethod) ||
(ptrActive->connectedSnsState != CY_CAPSENSE_SNS_CONNECTED))
{
scanStatus = Cy_CapSense_SetupWidgetExt(widgetId, sensorId, context);
}
if (CY_CAPSENSE_STATUS_SUCCESS == scanStatus)
{
scanStatus = Cy_CapSense_ScanExt(context);
}
}
return scanStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ScanAllWidgets_V2
****************************************************************************//**
*
* Initiates scanning of all enabled widgets (and sensors) in the project.
*
* The tasks of both Cy_CapSense_SetupWidget() and Cy_CapSense_Scan() functions
* are executed by this function. The status of a sensor scan must be checked
* using the Cy_CapSense_IsBusy() prior to starting the next scan or setting
* up another widget.
*
* This function initiates a scan only for the first sensor in the first widget
* and then exits the function. The scan for the remaining sensors are initiated
* in the interrupt service routine (part of middleware) triggered at the end
* of each scan completion. Hence, the status of the current scan should be
* checked using the Cy_CapSense_IsBusy() and wait until all scans is finished
* prior to starting a next scan or initializing another widget.
*
* \note
* This function is available only for the fourth-generation 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 - Scanning is successfully started.
* - CY_CAPSENSE_STATUS_BAD_PARAM - All the widgets are disabled.
* - CY_CAPSENSE_STATUS_INVALID_STATE - The previous scanning is not completed and the
* CSD HW block is busy.
* - CY_CAPSENSE_STATUS_UNKNOWN - There are unknown errors.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ScanAllWidgets_V2(cy_stc_capsense_context_t * context)
{
uint32_t wdgtIndex;
cy_stc_capsense_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
cy_capsense_status_t scanStatus = CY_CAPSENSE_STATUS_UNKNOWN;
if (CY_CAPSENSE_BUSY == Cy_CapSense_IsBusy(context))
{
/* Previous widget is being scanned. Return error. */
scanStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
}
else
{
/*
* Set up first widget. If widget returned error,
* set up next, continue same until widget does not return error.
*/
for (wdgtIndex = 0u; wdgtIndex < context->ptrCommonConfig->numWd; wdgtIndex++)
{
scanStatus = Cy_CapSense_SetupWidget(wdgtIndex, context);
if (CY_CAPSENSE_STATUS_SUCCESS == scanStatus)
{
ptrActive->scanScope = CY_CAPSENSE_SCAN_SCOPE_ALL_WD_MASK;
/* Initiate scan and quit loop */
scanStatus = Cy_CapSense_Scan(context);
break;
}
}
}
return scanStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_InternalPreCalculation
****************************************************************************//**
*
* Calculate different internal parameters, register values in advance to
* speed up execution time.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return status
* Returns status of operation:
* - Zero - Indicates successful initialization.
* - Non-zero - One or more errors occurred in the initialization process.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context)
{
cy_capsense_status_t initStatus = CY_CAPSENSE_STATUS_SUCCESS;
uint32_t wdgtIndex;
uint32_t temp;
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
if ((context->ptrCommonConfig->portCmodPadNum == context->ptrCommonConfig->portCmodNum) &&
(context->ptrCommonConfig->pinCmodPad == context->ptrCommonConfig->pinCmod))
{
context->ptrInternalContext->csdCmodConnection = (uint8_t)CY_CAPSENSE_CMODPAD_E;
}
else if ((context->ptrCommonConfig->portCshPadNum == context->ptrCommonConfig->portCmodNum) &&
(context->ptrCommonConfig->pinCshPad == context->ptrCommonConfig->pinCmod))
{
context->ptrInternalContext->csdCmodConnection = (uint8_t)CY_CAPSENSE_CTANKPAD_E;
}
else if ((context->ptrCommonConfig->portShieldPadNum == context->ptrCommonConfig->portCmodNum) &&
(context->ptrCommonConfig->pinShieldPad == context->ptrCommonConfig->pinCmod))
{
context->ptrInternalContext->csdCmodConnection = (uint8_t)CY_CAPSENSE_CSHIELDPAD_E;
}
else if ((context->ptrCommonConfig->portVrefExtPadNum == context->ptrCommonConfig->portCmodNum) &&
(context->ptrCommonConfig->pinVrefExtPad == context->ptrCommonConfig->pinCmod))
{
context->ptrInternalContext->csdCmodConnection = (uint8_t)CY_CAPSENSE_VREFEXTPAD_E;
}
else
{
context->ptrInternalContext->csdCmodConnection = (uint8_t)CY_CAPSENSE_CMODPAD_E;
initStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
}
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN)
/* Csh Capacitor Placement */
if ((context->ptrCommonConfig->portCmodPadNum == context->ptrCommonConfig->portCshNum) &&
(context->ptrCommonConfig->pinCmodPad == context->ptrCommonConfig->pinCsh))
{
context->ptrInternalContext->csdCshConnection = (uint8_t)CY_CAPSENSE_CMODPAD_E;
}
else if ((context->ptrCommonConfig->portCshPadNum == context->ptrCommonConfig->portCshNum) &&
(context->ptrCommonConfig->pinCshPad == context->ptrCommonConfig->pinCsh))
{
context->ptrInternalContext->csdCshConnection = (uint8_t)CY_CAPSENSE_CTANKPAD_E;
}
else if ((context->ptrCommonConfig->portShieldPadNum == context->ptrCommonConfig->portCshNum) &&
(context->ptrCommonConfig->pinShieldPad == context->ptrCommonConfig->pinCsh))
{
context->ptrInternalContext->csdCshConnection = (uint8_t)CY_CAPSENSE_CSHIELDPAD_E;
}
else if ((context->ptrCommonConfig->portVrefExtPadNum == context->ptrCommonConfig->portCshNum) &&
(context->ptrCommonConfig->pinVrefExtPad == context->ptrCommonConfig->pinCsh))
{
context->ptrInternalContext->csdCshConnection = (uint8_t)CY_CAPSENSE_VREFEXTPAD_E;
}
else
{
context->ptrInternalContext->csdCshConnection = (uint8_t)CY_CAPSENSE_CTANKPAD_E;
initStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
}
#else
context->ptrInternalContext->csdCshConnection = 0u;
#endif
/* Switch CSD Comparator Selection */
switch (context->ptrInternalContext->csdCmodConnection)
{
case (uint8_t)CY_CAPSENSE_CMODPAD_E:
context->ptrInternalContext->csdRegSwCmpPSel = CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPM_STATIC_CLOSE;
break;
case (uint8_t)CY_CAPSENSE_CSHIELDPAD_E:
context->ptrInternalContext->csdRegSwCmpPSel = CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPS_STATIC_CLOSE;
break;
default:
context->ptrInternalContext->csdRegSwCmpPSel = CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPT_STATIC_CLOSE;
break;
}
context->ptrInternalContext->csdRegSwCmpNSel = CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE;
/* Defines the drive mode of pins depending on the Inactive sensor connection setting */
(void)Cy_CapSense_SetInactiveElectrodeState(context->ptrCommonConfig->csdInactiveSnsConnection,
CY_CAPSENSE_CSD_GROUP, context);
/* Prepares CONFIG register value */
context->ptrInternalContext->csdRegConfig = 0u;
/* Iref Source */
#if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
if (CY_CAPSENSE_IREF_PASS == context->ptrCommonConfig->ssIrefSource)
{
context->ptrInternalContext->csdRegConfig |= CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK;
}
#endif
/* Filter Delay */
temp = context->ptrCommonConfig->periClkHz / context->ptrCommonContext->modCsdClk;
if (temp > CY_CAPSENSE_MOD_CSD_CLK_24000000_HZ)
{
context->ptrInternalContext->csdRegConfig |= CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_48MHZ;
}
else if (temp > CY_CAPSENSE_MOD_CSD_CLK_12000000_HZ)
{
context->ptrInternalContext->csdRegConfig |= CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_24MHZ;
}
else
{
context->ptrInternalContext->csdRegConfig |= CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_12MHZ;
}
/* Shield Delay */
context->ptrInternalContext->csdRegConfig |= (((uint32_t)context->ptrCommonConfig->csdShieldDelay) << CY_CAPSENSE_CSD_CONFIG_SHIELD_DELAY_POS);
/* Sense Enable */
context->ptrInternalContext->csdRegConfig |= CSD_CONFIG_SENSE_EN_Msk;
/* Power On */
context->ptrInternalContext->csdRegConfig |= CSD_CONFIG_ENABLE_Msk;
context->ptrInternalContext->csdRegSwHsPSelCmodInit = 0u;
context->ptrInternalContext->csdRegSwHsPSelCtankInit = 0u;
context->ptrInternalContext->csdRegSwHsPSelScan = 0u;
switch (context->ptrInternalContext->csdCmodConnection)
{
case (uint8_t)CY_CAPSENSE_CMODPAD_E:
context->ptrInternalContext->csdRegSwHsPSelCmodInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
break;
case (uint8_t)CY_CAPSENSE_CSHIELDPAD_E:
context->ptrInternalContext->csdRegSwHsPSelCmodInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
break;
default:
context->ptrInternalContext->csdRegSwHsPSelCmodInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
break;
}
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN)
switch (context->ptrInternalContext->csdCshConnection)
{
case (uint8_t)CY_CAPSENSE_CMODPAD_E:
context->ptrInternalContext->csdRegSwHsPSelCtankInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
context->ptrInternalContext->csdRegSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
break;
case (uint8_t)CY_CAPSENSE_CSHIELDPAD_E:
context->ptrInternalContext->csdRegSwHsPSelCtankInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
context->ptrInternalContext->csdRegSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
break;
default:
context->ptrInternalContext->csdRegSwHsPSelCtankInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
context->ptrInternalContext->csdRegSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
break;
}
#else
context->ptrInternalContext->csdRegSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMB_STATIC_CLOSE;
#endif
/* BYP switch selection */
context->ptrInternalContext->csdRegSwBypSel = CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK | CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYB_MSK;
#else
context->ptrInternalContext->csdRegSwBypSel = CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK;
#endif
/* Switch resistance selection */
context->ptrInternalContext->csdRegSwResInit = ((uint32_t)context->ptrCommonConfig->csdInitSwRes << CSD_SW_RES_RES_HCAV_Pos) |
((uint32_t)context->ptrCommonConfig->csdInitSwRes << CSD_SW_RES_RES_HCBV_Pos);
context->ptrInternalContext->csdRegSwResScan = ((uint32_t)context->ptrCommonConfig->csdShieldSwRes << CSD_SW_RES_RES_HCBV_Pos) |
((uint32_t)context->ptrCommonConfig->csdShieldSwRes << CSD_SW_RES_RES_HCBG_Pos);
/* Switch DSI selection */
context->ptrInternalContext->csdRegSwDsiSel = CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL;
#if (CY_CAPSENSE_PSOC4_FOURTH_GEN)
switch (context->ptrInternalContext->csdCmodConnection)
{
case (uint8_t)CY_CAPSENSE_CMODPAD_E:
context->ptrInternalContext->csdRegSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CMOD_MSK;
break;
case (uint8_t)CY_CAPSENSE_CTANKPAD_E:
context->ptrInternalContext->csdRegSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CSH_TANK_MSK;
break;
default:
/* No action on other connections */
break;
}
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN))
switch (context->ptrInternalContext->csdCshConnection)
{
case (uint8_t)CY_CAPSENSE_CMODPAD_E:
context->ptrInternalContext->csdRegSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CMOD_MSK;
break;
case (uint8_t)CY_CAPSENSE_CTANKPAD_E:
context->ptrInternalContext->csdRegSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CSH_TANK_MSK;
break;
default:
/* No action on other connections */
break;
}
#endif
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
{
context->ptrInternalContext->csdRegAmuxbufInit = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_NORM;
}
else
{
context->ptrInternalContext->csdRegAmuxbufInit = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_HI;
}
#else
context->ptrInternalContext->csdRegAmuxbufInit = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_OFF;
#endif
/* Switch AMUXBUF selection */
context->ptrInternalContext->csdRegSwAmuxbufSel = 0u;
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
if (((CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda) &&
(CY_CAPSENSE_IDAC_SINKING == context->ptrCommonConfig->csdChargeTransfer)) ||
((CY_CAPSENSE_LOW_VOLTAGE_LIMIT <= context->ptrCommonConfig->vdda) &&
(CY_CAPSENSE_IDAC_SOURCING == context->ptrCommonConfig->csdChargeTransfer)))
{
context->ptrInternalContext->csdRegSwAmuxbufSel = CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_IRH_STATIC_CLOSE | CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_ICB_PHI2;
}
#endif
context->ptrInternalContext->csdRegSwShieldSelScan = 0u;
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN)
if (CY_CAPSENSE_IDAC_SINKING == context->ptrCommonConfig->csdChargeTransfer)
{
context->ptrInternalContext->csdRegSwShieldSelScan = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_HSCMP;
}
else
{
context->ptrInternalContext->csdRegSwShieldSelScan = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI1_HSCMP;
}
#else
if (CY_CAPSENSE_IDAC_SINKING == context->ptrCommonConfig->csdChargeTransfer)
{
context->ptrInternalContext->csdRegSwShieldSelScan = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI1 |
CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI2_HSCMP;
}
else
{
context->ptrInternalContext->csdRegSwShieldSelScan = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI1 |
CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI2_HSCMP;
}
#endif
#endif
/* High-Speed Comparator initialization */
context->ptrInternalContext->csdRegHscmpInit = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
context->ptrInternalContext->csdRegHscmpScan = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
if (CY_CAPSENSE_IDAC_SINKING == context->ptrCommonConfig->csdChargeTransfer)
{
context->ptrInternalContext->csdRegHscmpScan = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK | CY_CAPSENSE_CSD_HSCMP_HSCMP_INVERT_MSK;
}
#if (CY_CAPSENSE_DISABLE == CY_CAPSENSE_CSD_SHIELD_EN)
context->ptrInternalContext->csdRegHscmpScan = 0u;
#endif
/* IDACs Config */
context->ptrInternalContext->csdIdacAConfig = context->ptrCommonConfig->idacGainTable[0u].gainReg;
context->ptrInternalContext->csdIdacBConfig = context->ptrCommonConfig->idacGainTable[0u].gainReg;
/* IDACs Polarities */
if (CY_CAPSENSE_IDAC_SINKING == context->ptrCommonConfig->csdChargeTransfer)
{
context->ptrInternalContext->csdIdacAConfig |= (CY_CAPSENSE_CSD_IDACA_POLARITY_VDDA_SNK << CY_CAPSENSE_CSD_IDACA_POLARITY_POS);
context->ptrInternalContext->csdIdacBConfig |= (CY_CAPSENSE_CSD_IDACB_POLARITY_VDDA_SNK << CY_CAPSENSE_CSD_IDACB_POLARITY_POS);
}
else
{
context->ptrInternalContext->csdIdacAConfig |= (CY_CAPSENSE_CSD_IDACA_POLARITY_VSSA_SRC << CY_CAPSENSE_CSD_IDACA_POLARITY_POS);
context->ptrInternalContext->csdIdacBConfig |= (CY_CAPSENSE_CSD_IDACB_POLARITY_VSSA_SRC << CY_CAPSENSE_CSD_IDACB_POLARITY_POS);
}
/* IDACs Balancing Mode */
context->ptrInternalContext->csdIdacAConfig |= (CY_CAPSENSE_CSD_IDACA_BALL_MODE_FULL << CY_CAPSENSE_CSD_IDACA_BALL_MODE_POS);
context->ptrInternalContext->csdIdacBConfig |= (CY_CAPSENSE_CSD_IDACB_BALL_MODE_FULL << CY_CAPSENSE_CSD_IDACB_BALL_MODE_POS);
/* Legs Config */
context->ptrInternalContext->csdIdacAConfig |= (CY_CAPSENSE_CSD_IDACA_LEG1_MODE_CSD << CY_CAPSENSE_CSD_IDACA_LEG1_MODE_POS);
context->ptrInternalContext->csdIdacAConfig |= (CY_CAPSENSE_CSD_IDACA_LEG2_MODE_CSD << CY_CAPSENSE_CSD_IDACA_LEG2_MODE_POS);
context->ptrInternalContext->csdIdacAConfig |= (CY_CAPSENSE_CSD_IDACA_LEG1_EN_MSK);
context->ptrInternalContext->csdIdacBConfig |= (CY_CAPSENSE_CSD_IDACB_LEG1_MODE_CSD_STATIC << CY_CAPSENSE_CSD_IDACB_LEG1_MODE_POS);
context->ptrInternalContext->csdIdacBConfig |= (CY_CAPSENSE_CSD_IDACB_LEG2_MODE_CSD_STATIC << CY_CAPSENSE_CSD_IDACB_LEG2_MODE_POS);
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN)
context->ptrInternalContext->csdIdacBConfig |= (CY_CAPSENSE_CSD_IDACB_LEG1_EN_MSK);
#endif
/* IO Control Selection */
if (CY_CAPSENSE_IDAC_SINKING == context->ptrCommonConfig->csdChargeTransfer)
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 |
CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY |
CY_CAPSENSE_CSD_TX_AMUXB_EN_PHI2_DELAY |
CY_CAPSENSE_CSD_TX_OUT_MSK |
CY_CAPSENSE_CSD_TX_N_OUT_STATIC_CLOSE);
#else
context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 |
CY_CAPSENSE_CSD_TX_N_OUT_STATIC_CLOSE);
#endif
}
else
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 |
CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY |
CY_CAPSENSE_CSD_TX_AMUXB_EN_PHI2_DELAY);
#else
context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2);
#endif