-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcy_capsense_sensing_v3.c
6479 lines (5843 loc) · 272 KB
/
cy_capsense_sensing_v3.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_v3.c
* \version 6.10.0
*
* \brief
* This file contains the source of functions common for different scanning
* modes.
*
********************************************************************************
* \copyright
* Copyright 2020-2025, 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 <stddef.h>
#include <string.h>
#include "cy_syslib.h"
#include "cy_sysclk.h"
#include "cy_gpio.h"
#include "cy_device_headers.h"
#include "cycfg_capsense_defines.h"
#include "cy_capsense_sensing.h"
#include "cy_capsense_sensing_v3.h"
#include "cy_capsense_generator_v3.h"
#include "cy_capsense_common.h"
#include "cy_capsense_structure.h"
#include "cy_capsense_processing.h"
#include "cy_capsense_lib.h"
#include "cy_capsense_selftest.h"
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
#include "cy_msc.h"
#include "cy_dmac.h"
#endif
#if (defined(CY_IP_M0S8MSCV3))
/*******************************************************************************
* Local definition
*******************************************************************************/
#define CY_CAPSENSE_CSD_CCOMP_CALC_DIV (4u * CY_CAPSENSE_PERCENTAGE_100)
#define CY_CAPSENSE_CSX_CCOMP_CALC_DIV (8u * CY_CAPSENSE_PERCENTAGE_100)
/* CIC2 Filter Divider */
#define CY_CAPSENSE_CIC2_DIVIDER_1 (1u)
#define CY_CAPSENSE_CIC2_DIVIDER_2 (2u)
#define CY_CAPSENSE_CIC2_DIVIDER_4 (4u)
#define CY_CAPSENSE_CIC2_DIVIDER_8 (8u)
#define CY_CAPSENSE_CIC2_DIVIDER_16 (16u)
/* CIC2 Accumulator parameters */
#define CY_CAPSENSE_CIC2_ACC_BIT_NUM (20u)
#define CY_CAPSENSE_CIC2_ACC_MAX_VAL ((1uL << CY_CAPSENSE_CIC2_ACC_BIT_NUM) - 1u)
/* The minimum allowed value of CDAC compensation divider */
#define CY_CAPSENSE_CDAC_COMP_DIV_MIN_MSCV3 (3u)
/*
* Raw count value equals to appropriate sensor capacitance with dithering configuration.
* Calculated according to the equation:
* rawCount = (snsCap * CY_CAPSENSE_CONVERSION_HECTO) / CY_CAPSENSE_REF_CDAC_LSB_X100;
*/
#define CY_CAPSENSE_DITHERING_SNS_CAP_300_FEMTO_RAW (33u)
#define CY_CAPSENSE_DITHERING_SNS_CAP_500_FEMTO_RAW (56u)
#define CY_CAPSENSE_DITHERING_SNS_CAP_1000_FEMTO_RAW (112u)
#define CY_CAPSENSE_DITHERING_SNS_CAP_3000_FEMTO_RAW (338u)
#define CY_CAPSENSE_DITHERING_SNS_CAP_5000_FEMTO_RAW (564u)
#define CY_CAPSENSE_DITHERING_SNS_CAP_10000_FEMTO_RAW (1128u)
/* CDAC dithering modes */
#define CY_CAPSENSE_CDAC_DITHERING_MODE_DISABLE (0x0u)
#define CY_CAPSENSE_CDAC_DITHERING_MODE_MANUAL (0x1u)
#define CY_CAPSENSE_CDAC_DITHERING_MODE_AUTO (0x2u)
#define CY_CAPSENSE_CDAC_DITHERING_CDAC_REF (100u)
#define CY_CAPSENSE_CDAC_DITHERING_NUM_SUBCONV (100u)
#define CY_CAPSENSE_CDAC_DITHERING_COMP_DIV (256u)
#define CY_CAPSENSE_CDAC_DITHERING_KREF (256u)
#define CY_CAPSENSE_CDAC_DITHERING_CLOCK_REF_RATE (0x1u)
/*
* Watchdog time in mod clocks for CDAC auto-dithering scan is calculated according to the equation:
* WdtTime = (INIT_CMOD + INIT_SHORT + PRO_DUMMY + NUM_SUBCONV * KREF + EPILOGUE) * 3.
* The calculated value is the duration of one sample with the three-time margin.
*/
#define CY_CAPSENSE_CDAC_DITHERING_MOD_CLK_PERIODS (85000u)
/*******************************************************************************
* Constants
*******************************************************************************/
#if (CY_CAPSENSE_DISABLE == CY_CAPSENSE_USE_CAPTURE)
const cy_stc_msc_base_config_t cy_capsense_mscCfg = CY_CAPSENSE_MSC_CONFIG_DEFAULT;
#endif
/******************************************************************************/
/** \cond SECTION_CAPSENSE_INTERNAL */
/** \addtogroup group_capsense_internal *//** \{ */
/******************************************************************************/
uint32_t Cy_CapSense_GetLfsrBitsAuto(
const cy_stc_capsense_widget_config_t * ptrWdConfig,
const cy_stc_capsense_context_t * context);
uint32_t Cy_CapSense_GetClkSrcSSCAuto(
const cy_stc_capsense_widget_config_t * ptrWdConfig,
const cy_stc_capsense_context_t * context);
uint32_t Cy_CapSense_GetClkSrcPRSAuto(
const cy_stc_capsense_widget_context_t * ptrWdContext,
const cy_stc_capsense_context_t * context);
uint32_t Cy_CapSense_GetLfsrBitsNumber(
uint32_t snsClkDivider,
uint32_t snsClkDividerMin,
uint32_t ditherLimitPercents,
uint32_t lfsrScale);
uint32_t Cy_CapSense_RunSSCAuto(
uint32_t autoSelMode,
uint32_t lfsrDitherCycles,
uint32_t ditherLimitCycles,
uint32_t lfsrPolySize,
uint32_t subConvNumber);
uint32_t Cy_CapSense_GetPolySize(uint32_t lfsrPoly);
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_EN)
void Cy_CapSense_SsAutoTuneScanDurationAlignment(
uint64_t widgetMask,
uint32_t clockDivider,
uint32_t subConversion,
cy_stc_capsense_context_t * context);
#endif
#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) ||\
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN))
void Cy_CapSense_SetCompDivider(
uint32_t widgetId,
cy_stc_capsense_context_t * context);
void Cy_CapSense_SetMaxCompCdac(
uint32_t widgetId,
cy_stc_capsense_context_t * context);
#endif
#endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) ||\
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CDAC_COMP_USAGE))
void Cy_CapSense_AmuxUpdateCdacComp(
MSC_Type * base,
const cy_stc_capsense_sensor_context_t * ptrSnsContext);
#endif
void Cy_CapSense_AmuxUpdateScanConfig(
uint32_t chIndex,
uint32_t scanSlot,
uint32_t prevWdIndex,
cy_stc_capsense_context_t * context);
void Cy_CapSense_AmuxStartScan(MSC_Type * base);
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN)
static cy_capsense_status_t Cy_CapSense_CdacDitherScaleCalc(
cy_stc_capsense_context_t * context);
static cy_capsense_status_t Cy_CapSense_ConfigureAutoDitherMode(
cy_stc_capsense_context_t * context);
static cy_capsense_status_t Cy_CapSense_CdacDitherConfigScan(
MSC_Type * ptrHwBase,
uint32_t chId,
uint32_t slotId,
uint32_t snsFrameIdx,
cy_stc_capsense_context_t * context);
#endif
/** \} \endcond */
/*******************************************************************************
* Function Name: Cy_CapSense_ScanSlots_V3
****************************************************************************//**
*
* Initiates the non-blocking scan of specified slots.
*
* This function initiates a scan only for the first specified 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 completion 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 slots are scanned,
* the FRAME interrupt is fired and the interrupt service routine (part of middleware)
* updates the busy status.
* 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 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 only for the fifth-generation CAPSENSE™.
*
* \param startSlotId
* The slot ID scan will be started from.
*
* \param numberSlots
* The number of slots 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_V3(
uint32_t startSlotId,
uint32_t numberSlots,
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
uint32_t curChIndex;
uint32_t startSlotIdLocal = startSlotId;
uint32_t numberSlotsLocal = numberSlots;
uint32_t lastSlot = startSlotIdLocal + numberSlotsLocal - 1u;
const cy_stc_capsense_common_config_t * ptrCommonCfg;
cy_stc_capsense_internal_context_t * ptrIntrCxt;
uint32_t slotValue;
uint32_t curSlotIndex;
#if (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE)
uint32_t wdIndex;
uint32_t snsIndex;
uint32_t scanSlotIndexValid;
#endif
#if ((CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE) || \
(CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD))
uint32_t * ptrSensorFrame;
#endif
#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
uint32_t sensorFrame[CY_MSC_6_SNS_REGS] = {0u, 0u, 0u, 0u, 0u, 0u};
#endif
if ((NULL != context) && (0u != numberSlotsLocal))
{
if (CY_CAPSENSE_SLOT_COUNT > lastSlot)
{
ptrIntrCxt = context->ptrInternalContext;
ptrCommonCfg = context->ptrCommonConfig;
#if (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE)
/* Finds the first enabled slot for scanning */
while (0u < numberSlotsLocal)
{
if (0u != Cy_CapSense_IsSlotEnabled(startSlotIdLocal, context))
{
break;
}
startSlotIdLocal++;
numberSlotsLocal--;
}
/* Finds the last valid slot */
while (0u < numberSlotsLocal)
{
if (0u != Cy_CapSense_IsSlotEnabled(lastSlot, context))
{
break;
}
lastSlot--;
numberSlotsLocal--;
}
#endif
#if (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE)
if (0u == numberSlotsLocal)
{
capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
}
else
#endif
if (CY_CAPSENSE_NOT_BUSY != Cy_CapSense_IsBusy(context))
{
/* Previous widget is being scanned. Return error. */
capStatus = CY_CAPSENSE_STATUS_HW_BUSY;
}
else
{
if ((CY_CAPSENSE_HW_CONFIG_REGULAR_SCANNING == ptrIntrCxt->hwConfigState) &&
(ptrIntrCxt->currentSlotIndex == startSlotIdLocal) && (1u == numberSlotsLocal) &&
(0u == (context->ptrCommonContext->status & CY_CAPSENSE_MW_STATE_CALIBRATION_MASK)) &&
(ptrIntrCxt->scanSingleSlot == CY_CAPSENSE_SCAN_SNGL_SLOT))
{
#if (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE)
/* Initiates the frame start for each channel in interrupt driven scan mode */
for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
{
ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->FRAME_CMD =
MSC_FRAME_CMD_START_FRAME_Msk;
}
#endif /* (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE) */
/* Initialize all enabled MSC channels for scan */
for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
{
Cy_CapSense_SetBusyFlags(curChIndex, context);
if (NULL != ptrIntrCxt->ptrSSCallback)
{
ptrIntrCxt->ptrSSCallback((cy_stc_capsense_active_scan_sns_t *)&context->ptrActiveScanSns[curChIndex]);
}
#if (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE)
ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->SNS_CTL = context->ptrInternalContext->snsCtlReg[curChIndex] |
(MSC_SNS_CTL_START_SCAN_Msk | MSC_SNS_CTL_LAST_Msk);
#endif
#if (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE)
context->ptrSensorFrameContext[((lastSlot + 1u +
((curChIndex + ptrCommonCfg->channelOffset) * CY_CAPSENSE_SLOT_COUNT)) *
CY_MSC_6_SNS_REGS) - 1u] |= MSC_SNS_CTL_LAST_Msk;
#endif
}
#if (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE)
/* Initiates the frame start for each channel in DMA driven scan mode */
for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
{
ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->FRAME_CMD =
MSC_FRAME_CMD_START_FRAME_Msk;
}
#endif
capStatus = CY_CAPSENSE_STATUS_SUCCESS;
}
else
{
#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
{
if (CY_CAPSENSE_SNS_CONNECTED == context->ptrActiveScanSns[curChIndex].connectedSnsState)
{
/* Disconnect the scanned sensor */
Cy_CapSense_DisconnectSensor(curChIndex, context);
}
}
#endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
capStatus = Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_REGULAR_SCANNING, context);
if (CY_CAPSENSE_STATUS_SUCCESS == capStatus)
{
for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
{
context->ptrActiveScanSns[curChIndex].currentChannelSlotIndex = (uint16_t)startSlotIdLocal;
}
#if (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE)
/* Finds number of empty slots requested for scan within DMA raw array */
slotValue = 0u;
for (curSlotIndex = 0u; curSlotIndex < startSlotIdLocal; curSlotIndex++)
{
if (0u == Cy_CapSense_IsSlotEnabled(curSlotIndex, context))
{
slotValue++;
}
}
/* Stores DMA raw array ID */
ptrIntrCxt->firstValidSlot = (uint16_t)(startSlotIdLocal - slotValue);
/* Finds number of valid slots to be scanned */
slotValue = 0u;
for (curSlotIndex = startSlotIdLocal; curSlotIndex < (lastSlot + 1u); curSlotIndex++)
{
if (0u != Cy_CapSense_IsSlotEnabled(curSlotIndex, context))
{
slotValue++;
}
}
if ((ptrIntrCxt->currentSlotIndex != (uint16_t)startSlotIdLocal) ||
(ptrIntrCxt->endSlotIndex != (uint16_t)lastSlot) ||
(ptrIntrCxt->numValidSlots != (uint16_t)slotValue))
{
ptrIntrCxt->numValidSlots = (uint16_t)slotValue;
ptrIntrCxt->currentSlotIndex = (uint16_t)startSlotIdLocal;
ptrIntrCxt->endSlotIndex = (uint16_t)lastSlot;
/* Configure DMA resources for each channel */
for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
{
(void)Cy_CapSense_ConfigureDmaResource(curChIndex, context);
}
}
#else /* (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE) */
ptrIntrCxt->currentSlotIndex = (uint16_t)startSlotIdLocal;
ptrIntrCxt->endSlotIndex = (uint16_t)lastSlot;
/* Initiates the frame start for each channel in interrupt driven scan mode */
for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
{
ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->FRAME_CMD =
MSC_FRAME_CMD_START_FRAME_Msk;
}
#endif /* (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE) */
/* Set the single or multiple slot scan mode */
if ((1u == numberSlotsLocal) &&
(0u == (context->ptrCommonContext->status & CY_CAPSENSE_MW_STATE_CALIBRATION_MASK)))
{
ptrIntrCxt->scanSingleSlot = CY_CAPSENSE_SCAN_SNGL_SLOT;
}
else
{
ptrIntrCxt->scanSingleSlot = CY_CAPSENSE_SCAN_MULTIPLE_SLOT;
}
/* Initialize all enabled MSC channels for scan */
for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
{
Cy_CapSense_SetBusyFlags(curChIndex, context);
#if (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE)
curSlotIndex = startSlotIdLocal + ((curChIndex + ptrCommonCfg->channelOffset) * CY_CAPSENSE_SLOT_COUNT);
slotValue = context->ptrScanSlots[curSlotIndex].wdId;
scanSlotIndexValid = curSlotIndex;
if (CY_CAPSENSE_SLOT_EMPTY == slotValue)
{
#if (CY_CAPSENSE_TOTAL_CH_NUMBER > 1u)
if (curSlotIndex < CY_CAPSENSE_SLOT_COUNT)
{
scanSlotIndexValid += CY_CAPSENSE_SLOT_COUNT;
}
else
{
scanSlotIndexValid -= CY_CAPSENSE_SLOT_COUNT;
}
#endif
}
else if (CY_CAPSENSE_SLOT_SHIELD_ONLY <= slotValue)
{
scanSlotIndexValid = ((uint32_t)context->ptrScanSlots[curSlotIndex].snsId *
CY_CAPSENSE_SLOT_COUNT) + startSlotIdLocal;
}
else
{
/* Do nothing */
}
/* Initializes for each channel the active sensor structure for the current sensor */
wdIndex = context->ptrScanSlots[scanSlotIndexValid].wdId;
snsIndex = context->ptrScanSlots[scanSlotIndexValid].snsId;
#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
(void)Cy_CapSense_ConfigureAnalogMuxResource(curChIndex,
context->ptrWdConfig[wdIndex].senseMethod, context);
#endif
Cy_CapSense_InitActivePtr(curChIndex, wdIndex, snsIndex, context);
#endif /* (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE) */
#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
if ((slotValue != CY_CAPSENSE_SLOT_EMPTY) &&
(slotValue != CY_CAPSENSE_SLOT_SHIELD_ONLY))
{
/* Connect the widget first sensor electrodes */
Cy_CapSense_ConnectSensor(curChIndex, context);
}
/* Getting the sensor frame configuration */
ptrSensorFrame = &sensorFrame[0u];
(void)Cy_CapSense_GenerateSensorConfig(curChIndex, curSlotIndex, ptrSensorFrame, context);
/* Configure the last slot */
if (1u == numberSlotsLocal)
{
sensorFrame[CY_CAPSENSE_SNS_CTL_INDEX] |= MSC_SNS_CTL_LAST_Msk;
}
#else /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
/* Configure the last slot for each channel */
context->ptrSensorFrameContext[((lastSlot + 1u +
((curChIndex + ptrCommonCfg->channelOffset) * CY_CAPSENSE_SLOT_COUNT)) *
CY_MSC_6_SNS_REGS) - 1u] |= MSC_SNS_CTL_LAST_Msk;
#if (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE)
ptrSensorFrame = &context->ptrSensorFrameContext[(startSlotIdLocal +
((curChIndex + ptrCommonCfg->channelOffset) * CY_CAPSENSE_SLOT_COUNT)) *
CY_MSC_6_SNS_REGS];
#endif
#endif
if (NULL != ptrIntrCxt->ptrSSCallback)
{
#if (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE)
ptrIntrCxt->ptrSSCallback((cy_stc_capsense_active_scan_sns_t *)&context->ptrActiveScanSns[0u]);
#else
ptrIntrCxt->ptrSSCallback(NULL);
#endif
}
#if (CY_CAPSENSE_SCAN_MODE_INT_DRIVEN == CY_CAPSENSE_SCAN_MODE)
Cy_MSC_ConfigureScan(ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase,
CY_MSC_6_SNS_REGS, ptrSensorFrame);
#endif
}
#if (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE)
/* Initiates the frame start for each channel in DMA driven scan mode */
for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
{
ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->FRAME_CMD =
MSC_FRAME_CMD_START_FRAME_Msk;
}
#endif
}
}
}
}
}
return capStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ScanAllWidgets_V3
****************************************************************************//**
*
* Initiates the non-blocking scan for all widgets/sensors.
*
* 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 function is the wrapper for the Cy_CapSense_ScanAllSlots() function
* to provide the backward compatibility.
*
* \note
* This function is available only for the fifth-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 - 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_ScanAllWidgets_V3(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_ScanWidget_V3
****************************************************************************//**
*
* Initiates the scanning of all sensors in the widget.
*
* The function uses the Cy_CapSense_ScanSlots() function with the parameters of
* startSlotId and numberSlots retrieved from the firstSlotId and numSlots
* fields of the cy_stc_capsense_widget_config_t structure.
*
* 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 only for the fifth-generation CAPSENSE™.
* This function is available in single-channel solution.
*
* \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:
* - 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_ScanWidget_V3(
uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
if (NULL != context)
{
#if (1u >= CY_CAPSENSE_TOTAL_CH_NUMBER)
if (widgetId < context->ptrCommonConfig->numWd)
{
capStatus = Cy_CapSense_ScanSlots(context->ptrWdConfig[widgetId].firstSlotId,
context->ptrWdConfig[widgetId].numSlots, context);
}
#else
(void)widgetId;
#endif /* (1u >= CY_CAPSENSE_TOTAL_CH_NUMBER) */
}
return capStatus;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ScanSensor_V3
****************************************************************************//**
*
* 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
* This function is available only for the fifth-generation CAPSENSE™.
* This function is available in single-channel solution.
*
* \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:
* - 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_ScanSensor_V3(
uint32_t widgetId,
uint32_t sensorId,
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
if (NULL != context)
{
#if (1u >= CY_CAPSENSE_TOTAL_CH_NUMBER)
if (widgetId < context->ptrCommonConfig->numWd)
{
if (sensorId < context->ptrWdConfig[widgetId].numSns)
{
capStatus = Cy_CapSense_ScanSlots((sensorId + context->ptrWdConfig->firstSlotId), 1u, context);
}
}
#else
(void)widgetId;
(void)sensorId;
#endif /* (1u >= CY_CAPSENSE_TOTAL_CH_NUMBER) */
}
return capStatus;
}
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN))
/*******************************************************************************
* Function Name: Cy_CapSense_CalibrateAllSlots_V3
****************************************************************************//**
*
* Executes CapDAC auto-calibration for all relevant widgets if enabled.
*
* 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 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.
*
* To change calibration targets use the Cy_CapSense_SetCalibrationTarget() function.
*
* \note
* This function is available only for the 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_CHECK_FAIL - The calibration is failed
* because of rawcount is out of the
* defined range.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_CalibrateAllSlots_V3(cy_stc_capsense_context_t * context)
{
cy_capsense_status_t calibStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
const cy_stc_capsense_common_config_t * ptrCommonCfg;
uint32_t curWdIndex;
const cy_stc_capsense_widget_config_t * ptrWdCfg;
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_REF_AUTO_USAGE) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CDAC_REF_AUTO_USAGE) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CDAC_COMP_USAGE))
uint32_t curSlotIndex;
#endif
if (NULL != context)
{
context->ptrCommonContext->status |= CY_CAPSENSE_MW_STATE_CALIBRATION_MASK;
ptrCommonCfg = context->ptrCommonConfig;
calibStatus = CY_CAPSENSE_STATUS_SUCCESS;
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_REF_AUTO_USAGE) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CDAC_REF_AUTO_USAGE))
context->ptrCommonContext->status |= CY_CAPSENSE_MW_STATE_CALIBRATION_SINGLE_MASK;
/* RefCDAC auto-calibration in single CDAC mode */
for (curSlotIndex = 0u; curSlotIndex < CY_CAPSENSE_SLOT_COUNT; curSlotIndex++)
{
calibStatus |= Cy_CapSense_CalibrateSlot(curSlotIndex,
CY_CAPSENSE_CAL_MODE_REF_CDAC_SUC_APPR, context);
}
/* Finds max RefCDAC and normalizes RefCDAC */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_REF_AUTO_USAGE)
for (curWdIndex = 0u; curWdIndex < ptrCommonCfg->numWd; curWdIndex++)
{
if (CY_CAPSENSE_CSD_GROUP == context->ptrWdConfig[curWdIndex].senseMethod)
{
/* Normalize widgets for which CompCDAC */
calibStatus |= Cy_CapSense_NormalizeCdac(curWdIndex, context);
}
}
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CDAC_REF_AUTO_USAGE)
for (curWdIndex = 0u; curWdIndex < ptrCommonCfg->numWd; curWdIndex++)
{
if (CY_CAPSENSE_CSX_GROUP == context->ptrWdConfig[curWdIndex].senseMethod)
{
/* Normalize widgets for which CompCDAC */
calibStatus |= Cy_CapSense_NormalizeCdac(curWdIndex, context);
}
}
#endif
context->ptrCommonContext->status &= (uint32_t)~((uint32_t)CY_CAPSENSE_MW_STATE_CALIBRATION_SINGLE_MASK);
#endif
/* Skip rest of the stages for SmartSense as not needed */
if (0u == (context->ptrCommonContext->status & CY_CAPSENSE_MW_STATE_SMARTSENSE_MASK))
{
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CDAC_COMP_USAGE))
/* Find CompDivider with fixed Ref CDAC and maximum CompCDAC (for case #8 or #4) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_DIV_AUTO_USAGE)
for (curWdIndex = 0u; curWdIndex < ptrCommonCfg->numWd; curWdIndex++)
{
if (CY_CAPSENSE_CSD_GROUP == context->ptrWdConfig[curWdIndex].senseMethod)
{
calibStatus |= Cy_CapSense_CalibrateCompDivider(curWdIndex, context);
}
}
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CDAC_COMP_DIV_AUTO_USAGE)
for (curWdIndex = 0u; curWdIndex < ptrCommonCfg->numWd; curWdIndex++)
{
if (CY_CAPSENSE_CSX_GROUP == context->ptrWdConfig[curWdIndex].senseMethod)
{
calibStatus |= Cy_CapSense_CalibrateCompDivider(curWdIndex, context);
}
}
#endif
/* Calibrate CompCDAC with fixed Ref CDAC and fixed CompDivider (case #3, #4, #7, #8) */
if (CY_CAPSENSE_STATUS_SUCCESS == calibStatus)
{
for (curSlotIndex = 0u; curSlotIndex < CY_CAPSENSE_SLOT_COUNT; curSlotIndex++)
{
/* Calibrate all sensors in slot */
calibStatus |= Cy_CapSense_CalibrateSlot(curSlotIndex,
CY_CAPSENSE_CAL_MODE_COMP_CDAC_SUC_APPR, context);
}
}
#endif
/* Check calibration result */
if (CY_CAPSENSE_STATUS_SUCCESS == calibStatus)
{
for (curWdIndex = 0u; curWdIndex < ptrCommonCfg->numWd; curWdIndex++)
{
ptrWdCfg = &context->ptrWdConfig[curWdIndex];
switch (ptrWdCfg->senseMethod)
{
#if (CY_CAPSENSE_CSD_CDAC_CALIBRATION_USAGE)
case CY_CAPSENSE_CSD_GROUP:
#endif
#if (CY_CAPSENSE_CSX_CDAC_CALIBRATION_USAGE)
case CY_CAPSENSE_CSX_GROUP:
#endif
calibStatus |= Cy_CapSense_VerifyCalibration(curWdIndex, context);
break;
default:
/* Skip widget with disabled auto-calibration */
break;
}
}
}
/* Update CRC if BIST is enabled */
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) &&\
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN))
Cy_CapSense_UpdateAllWidgetCrc(context);
#endif
}
if (CY_CAPSENSE_STATUS_SUCCESS != calibStatus)
{
calibStatus |= CY_CAPSENSE_STATUS_CALIBRATION_FAIL;
}
context->ptrCommonContext->status &= ~(uint32_t)CY_CAPSENSE_MW_STATE_CALIBRATION_MASK;
}
return calibStatus;
}
#endif
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN))
/*******************************************************************************
* Function Name: Cy_CapSense_SetCalibrationTarget_V3
****************************************************************************//**
*
* Sets the CapDAC auto-calibration raw count targets for CSD, CSX and/or ISX
* widgets.
*
* 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™.
*
* \param calibrTarget
* The raw counts target in percentage for the specified sensing method.
* It should be more than 0u and less than 100u. 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_V3(
uint32_t calibrTarget,
uint32_t snsMethod,
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t calibStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
if (NULL != context)
{
if ((CY_CAPSENSE_PERCENTAGE_100 > calibrTarget) && (0u < calibrTarget))
{
switch (snsMethod)
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
case CY_CAPSENSE_CSD_GROUP:
context->ptrInternalContext->intrCsdRawTarget = (uint8_t)calibrTarget;
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
case CY_CAPSENSE_CSX_GROUP:
context->ptrInternalContext->intrCsxRawTarget = (uint8_t)calibrTarget;
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN)
case CY_CAPSENSE_ISX_GROUP:
context->ptrInternalContext->intrIsxRawTarget = (uint8_t)calibrTarget;
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN) */
default:
/* No action */
break;
}
calibStatus = CY_CAPSENSE_STATUS_SUCCESS;
}
}
return calibStatus;
}
#endif
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN))
/*******************************************************************************
* Function Name: Cy_CapSense_CalibrateAllWidgets_V3
****************************************************************************//**
*
* Calibrates CapDACs for all widgets.
*
* The function is the wrapper for the Cy_CapSense_CalibrateAllSlots() function
* to provide the backward compatibility.
*
* \note
* This function is available only for the fifth-generation CAPSENSE™.
* This function is available in single-channel solution.
*
* \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 failed if software
* watchdog timeout occurred
* during any calibration scan,
* the scan was not completed, or
* resulted raw counts
* are outside the limits.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_CalibrateAllWidgets_V3(
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t calibStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
if (NULL != context)
{
#if (1u >= CY_CAPSENSE_TOTAL_CH_NUMBER)
calibStatus = Cy_CapSense_CalibrateAllSlots(context);
#endif /* (1u >= CY_CAPSENSE_TOTAL_CH_NUMBER) */
}