-
Notifications
You must be signed in to change notification settings - Fork 4
/
cy_capsense_control.c
2059 lines (1913 loc) · 89.5 KB
/
cy_capsense_control.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_control.c
* \version 5.0
*
* \brief
* This file provides the source code to the Control module functions.
*
********************************************************************************
* \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 <stddef.h>
#include "cy_syslib.h"
#include "cy_syspm.h"
#include "cycfg_capsense_defines.h"
#include "cy_capsense_common.h"
#include "cy_capsense_structure.h"
#include "cy_capsense_control.h"
#include "cy_capsense_processing.h"
#include "cy_capsense_filter.h"
#include "cy_capsense_tuner.h"
#include "cy_capsense_sensing.h"
#include "cy_capsense_selftest.h"
#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
#include "cy_capsense_sensing_v2.h"
#include "cy_csd.h"
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
#include "cy_capsense_sensing_lp.h"
#include "cy_msclp.h"
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
#include "cy_capsense_sensing_v3.h"
#include "cy_msc.h"
#endif
#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3) || defined(CY_IP_M0S8MSCV3LP))
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
#if !defined(CY_CAPSENSE_SMARTSENSE_LP_HW_EN)
#define CY_CAPSENSE_SMARTSENSE_LP_HW_EN (0u)
#endif
#endif
/*******************************************************************************
* Function Name: Cy_CapSense_Init
****************************************************************************//**
*
* Captures HW blocks (one or more) for CAPSENSE™ operations and configures them
* to the default state. Call this function with the application program
* prior to calling any other function of the middleware.
*
* The following tasks are executed:
* 1. Capturing not used HW blocks. If any
* of HW blocks are
* already in use, then the function returns the fail status, and
* the application program should perform corresponding actions. For example, releasing
* the HW block captured by another middleware.
* 2. If the HW block has been captured successfully, this function configures it
* to the default state.
*
* After the middleware is configured using the Cy_CapSense_Init() function,
* the application program configures and enables the HW block interrupt(s),
* and then call of the Cy_CapSense_Enable() function to complete the
* middleware initialization process.
* See the function usage example below for more details.
*
* When the middleware operation is stopped by the Cy_CapSense_DeInit()
* function, subsequent call of the Cy_CapSense_Init() function repeats
* initialization process and it is not needed to call the Cy_CapSense_Enable()
* function second time. However, to implement time-multiplexed mode
* (sharing the HW block(s) between multiple middleware)
* the Cy_CapSense_Save() and Cy_CapSense_Restore() functions should be used
* instead of the Cy_CapSense_DeInit() and Cy_CapSense_Init() functions for
* further compatibility.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t
* generated by the CAPSENSE™ Configurator tool. The structure contains both, CAPSENSE™
* configuration and internal data and it is used during whole CAPSENSE™ operation.
*
* \return
* Returns the status of the initialization process. If CY_CAPSENSE_STATUS_SUCCESS is not
* received, some of the initialization fails, the middleware may not operate
* as expected, and repeating of initialization is required.
*
* \funcusage
*
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Initialization
* The 'cy_capsense_context' variable that is used as the parameter of the
* Cy_CapSense_Init() and Cy_CapSense_Enable() functions is declared in the
* cycfg_capsense.h file.
*
* The CapSense_ISR_cfg variable should be declared by the application
* program according to the examples below:<br>
* For PSoC™ 4 CPU or for PSoC™ 6 CM0+ core:
* \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 CM4 core:
* \snippet capsense/snippet/main.c snippet_m4_capsense_interrupt_source_declaration
*
* The CAPSENSE™ interrupt handler should be declared by the application program
* according to the example below:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_IntHandler
*
* 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.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_Init(cy_stc_capsense_context_t * context)
{
cy_capsense_status_t result = CY_CAPSENSE_STATUS_BAD_PARAM;
cy_stc_capsense_internal_context_t * ptrInternalCxt;
uint32_t wdIndex;
cy_stc_capsense_widget_context_t * ptrWdCxt;
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
const cy_stc_capsense_common_config_t * ptrCommonCfg;
#endif
if (NULL != context)
{
ptrInternalCxt = context->ptrInternalContext;
ptrInternalCxt->intrCsdInactSnsConn = CY_CAPSENSE_SNS_CONNECTION_UNDEFINED;
ptrInternalCxt->intrCsxInactSnsConn = CY_CAPSENSE_SNS_CONNECTION_UNDEFINED;
ptrInternalCxt->ptrSSCallback = NULL;
ptrInternalCxt->ptrEOSCallback = NULL;
ptrInternalCxt->ptrTunerReceiveCallback = NULL;
ptrInternalCxt->ptrTunerSendCallback = NULL;
ptrWdCxt = context->ptrWdConfig->ptrWdContext;
for (wdIndex = 0u; wdIndex < CY_CAPSENSE_TOTAL_WIDGET_COUNT; wdIndex++)
{
ptrWdCxt->status |= (CY_CAPSENSE_WD_ENABLE_MASK | CY_CAPSENSE_WD_WORKING_MASK);
ptrWdCxt++;
}
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
/* Set the maximum refresh rate (default value) for ACTIVE scan mode */
ptrInternalCxt->activeWakeupTimer = 0u;
/* Set default compensation factor for nominal ILO frequency (40KHz) */
ptrInternalCxt->iloCompensationFactor = CY_CAPSENSE_DEFAULT_ILO_FACTOR;
#endif
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
ptrCommonCfg = context->ptrCommonConfig;
ptrInternalCxt->ptrEODsInitCallback = NULL;
ptrInternalCxt->intrIsxInactSnsConn = CY_CAPSENSE_SNS_CONNECTION_UNDEFINED;
ptrInternalCxt->intrCsdRawTarget = ptrCommonCfg->csdRawTarget;
ptrInternalCxt->intrCsxRawTarget = ptrCommonCfg->csxRawTarget;
ptrInternalCxt->intrIsxRawTarget = ptrCommonCfg->isxRawTarget;
ptrInternalCxt->numCoarseInitChargeCycles = ptrCommonCfg->numCoarseInitChargeCycles;
ptrInternalCxt->numCoarseInitSettleCycles = ptrCommonCfg->numCoarseInitSettleCycles;
ptrInternalCxt->numProOffsetCycles = ptrCommonCfg->numProOffsetCycles;
ptrInternalCxt->proOffsetCdacComp = ptrCommonCfg->proOffsetCdacComp;
ptrInternalCxt->lfsrPoly = CY_CAPSENSE_LFSR_POLY;
ptrInternalCxt->lfsrScale = CY_CAPSENSE_LFSR_SCALE;
ptrInternalCxt->cdacDitherSeed = CY_CAPSENSE_CDAC_DITHER_SEED;
ptrInternalCxt->cdacDitherPoly = CY_CAPSENSE_CDAC_DITHER_POLY;
ptrInternalCxt->modClk = CY_CAPSENSE_MODCLK_DIV;
ptrWdCxt = context->ptrWdConfig->ptrWdContext;
for (wdIndex = 0u; wdIndex < CY_CAPSENSE_TOTAL_WIDGET_COUNT; wdIndex++)
{
if (0u == ptrWdCxt->maxRawCount)
{
ptrWdCxt->status |= CY_CAPSENSE_WD_MAXCOUNT_CALC_MASK;
}
if (0u == ptrWdCxt->maxRawCountRow)
{
ptrWdCxt->status |= CY_CAPSENSE_WD_MAXCOUNT_ROW_CALC_MASK;
}
ptrWdCxt++;
}
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
ptrInternalCxt->numEpiCycles = ptrCommonCfg->numEpiCycles;
ptrInternalCxt->numFineInitWaitCycles = CY_CAPSENSE_NUM_FINE_INIT_WAIT_CYCLES;
ptrInternalCxt->numFineInitCycles = CY_CAPSENSE_NUM_FINE_INIT_CYCLES;
#if (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE)
/* Set undefined value to initiate DMA configuration in Cy_CapSense_ScanSlots() function */
ptrInternalCxt->currentSlotIndex = CY_CAPSENSE_SLOT_COUNT_MAX_VALUE;
(void)Cy_CapSense_InitializeDmaArrays(context);
#endif
#endif
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
ptrInternalCxt->numProWaitKrefDelay = ptrCommonCfg->numProWaitKrefDelay;
ptrInternalCxt->numProWaitKrefDelayPrs = ptrCommonCfg->numProWaitKrefDelayPrs;
ptrInternalCxt->numEpiKrefDelay = ptrCommonCfg->numEpiKrefDelay;
ptrInternalCxt->numEpiKrefDelayPrs = ptrCommonCfg->numEpiKrefDelayPrs;
ptrInternalCxt->mrssStateAfterScan = CY_CAPSENSE_MRSS_TURN_OFF;
ptrInternalCxt->numFineInitCycles = CY_CAPSENSE_NUM_FINE_INIT_CYCLES;
ptrInternalCxt->csdCdacDitherEn = CY_CAPSENSE_CSD_CDAC_DITHER_EN;
ptrInternalCxt->csxCdacDitherEn = CY_CAPSENSE_CSX_CDAC_DITHER_EN;
ptrInternalCxt->isxCdacDitherEn = CY_CAPSENSE_ISX_CDAC_DITHER_EN;
ptrInternalCxt->bslnCoefSlow = CY_CAPSENSE_BSLN_COEFF_SLOW;
ptrInternalCxt->bslnCoefFast = CY_CAPSENSE_BSLN_COEFF_FAST;
ptrInternalCxt->bslnUpdateDelay = CY_CAPSENSE_BSLN_UPDATE_DELAY;
ptrInternalCxt->iirCoeffLp = CY_CAPSENSE_IIR_COEFF_LP;
ptrInternalCxt->wotScanInterval = CY_CAPSENSE_WOT_SCAN_INTERVAL;
ptrInternalCxt->wotTimeout = CY_CAPSENSE_WOT_TIMEOUT;
#endif
result = Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_UNDEFINED, context);
if (CY_CAPSENSE_STATUS_SUCCESS == result)
{
result = Cy_CapSense_Restore(context);
}
#endif
#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
result = Cy_CapSense_Restore(context);
#endif
}
return result;
}
/*******************************************************************************
* Function Name: Cy_CapSense_Enable
****************************************************************************//**
*
* Initializes the CAPSENSE™ firmware modules.
*
* Call the Cy_CapSense_Init() function and configure CAPSENSE™ HW block interrupts
* prior to calling this function.
* See the function usage example below for details on usage.
*
* The following are executed as part of the function:
* 1. Check CAPSENSE™ configuration integrity.
* 2. Pre-calculate of internal register values to speed up operation.
* 3. Configure the CAPSENSE™ HW block to perform capacitive sensing operation.
* 4. If the smart sensing algorithm is selected for the CSD Tuning mode in the
* Basic tab, the auto-tuning functionality is executed to set the optimal
* values for the CAPSENSE™ HW block parameters of the widgets/sensors.
* 5. Calibrate the sensors and find the optimal values for DACs of each widget/sensor,
* if the auto-calibration is enabled in the CSD Settings, CSX Settings or ISX Settings tabs.
* 6. Perform scanning for all the sensors and initialize the baseline history.
* 7. If the firmware filters are enabled in the Advanced General tab, the
* filter histories are also initialized.
*
* Any subsequent call of this function repeats the initialization process.
* Therefore, it is possible to change the middleware configuration
* from the application program by writing registers to the data structure
* and calling this function again.
*
* The repeated call of this function is also done inside the
* Cy_CapSense_RunTuner() function when a restart command is received.
*
* The function calls the Cy_CapSense_ScanAllWidgets() function to proper
* baseline setup.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the initialization process. If CY_CAPSENSE_STATUS_SUCCESS is not
* received, some of the initialization fails.
*
* \funcusage
*
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Initialization
* The 'cy_capsense_context' variable that is used as the parameter of the
* Cy_CapSense_Init() and Cy_CapSense_Enable() functions is declared in the
* cycfg_capsense.h file.
*
* The CapSense_ISR_cfg variable should be declared by the application
* program according to the examples below:<br>
* For CM0+ core:
* \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 CM4 core:
* \snippet capsense/snippet/main.c snippet_m4_capsense_interrupt_source_declaration
*
* The CAPSENSE™ interrupt handler should be declared by the application program
* according to the example below:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_IntHandler
*
* 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.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_Enable(cy_stc_capsense_context_t * context)
{
cy_capsense_status_t result;
uint32_t cpuFreqMHz;
uint32_t watchdogCounter;
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
context->ptrCommonContext->status |= CY_CAPSENSE_MW_STATE_INITIALIZATION_MASK;
uint32_t widgetId;
#endif
/* Approximate duration of Wait For Init loop */
const uint32_t isBusyLoopDuration = 5uL;
/* Wait For Init watchdog timeout in microseconds */
const uint32_t isBusyWatchdogTimeUs = 1000000uL;
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_RC_HW_IIR_FILTER_EN)
context->ptrInternalContext->hwIirInit = 0u;
(void)Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_CAPTURED_DEFAULT, context);
#endif
/* Initialize CAPSENSE™ modules */
result = Cy_CapSense_Initialize(context);
if (CY_CAPSENSE_STATUS_SUCCESS == result)
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_HW_EN))
result |= Cy_CapSense_SsAutoTune(context);
#elif (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN)
result |= Cy_CapSense_CalibrateAllCsdWidgets(context);
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN)
result |= Cy_CapSense_CalibrateAllCsxWidgets(context);
#endif
#elif (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_HW_EN))
result |= Cy_CapSense_SsAutoTune(context);
#endif
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN))
result |= Cy_CapSense_CalibrateAllSlots(context);
#endif
#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP) */
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_HW_EN) || \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_LP_HW_EN))
result |= Cy_CapSense_SsAutoTune(context);
#endif
#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))
{
result |= Cy_CapSense_CalibrateAllSlots(context);
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN)
result |= Cy_CapSense_CalibrateAllLpSlots(context);
#endif /* CY_CAPSENSE_LP_EN */
}
#endif
#endif
/* Scan each widget separately if the MPSC is enabled */
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED)
for (widgetId = 0u; widgetId < CY_CAPSENSE_TOTAL_WIDGET_COUNT; widgetId++)
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN)
if ((uint8_t)CY_CAPSENSE_WD_LOW_POWER_E != context->ptrWdConfig[widgetId].wdType)
{
result |= Cy_CapSense_ScanSlots(context->ptrWdConfig[widgetId].firstSlotId,
context->ptrWdConfig[widgetId].numSlots, context);
}
#else
result |= Cy_CapSense_ScanSlots(context->ptrWdConfig[widgetId].firstSlotId,
context->ptrWdConfig[widgetId].numSlots, context);
#endif
result |= Cy_CapSense_WaitEndScan(1000000uL, context); /* 1sec timeout */
}
#else
result |= Cy_CapSense_ScanAllSlots(context);
#endif /* CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED */
#else
result |= Cy_CapSense_ScanAllWidgets(context);
#endif /* CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP */
/* Init Watchdog Counter to prevent a hang */
cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
watchdogCounter = Cy_CapSense_WatchdogCyclesNum(isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
while (CY_CAPSENSE_NOT_BUSY != Cy_CapSense_IsBusy(context))
{
if (0uL == watchdogCounter)
{
result = CY_CAPSENSE_STATUS_TIMEOUT;
break;
}
watchdogCounter--;
}
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_RC_HW_IIR_FILTER_EN)
context->ptrInternalContext->hwIirInit = (uint8_t)MSCLP_CE_CTL_RCF_EN_Msk;
(void)Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_CAPTURED_DEFAULT, context);
#endif
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
for (widgetId = 0u; widgetId < CY_CAPSENSE_TOTAL_WIDGET_COUNT; widgetId++)
{
Cy_CapSense_PreProcessWidget(widgetId, context);
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED)
if (((CY_CAPSENSE_MPSC_MIN_ORDER <= context->ptrWdConfig[widgetId].mpOrder) ||
(CY_CAPSENSE_MPSC_MIN_ORDER <= context->ptrWdConfig[widgetId].mpOrderRows)) &&
(CY_CAPSENSE_CSD_GROUP == context->ptrWdConfig[widgetId].senseMethod))
{
result |= Cy_CapSense_ProcessWidgetMpDeconvolution(widgetId, context);
}
#endif
#endif
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_TX_ENABLED)
if ((CY_CAPSENSE_MPTX_MIN_ORDER <= context->ptrWdConfig[widgetId].mpOrder) &&
(CY_CAPSENSE_CSX_GROUP == context->ptrWdConfig[widgetId].senseMethod))
{
result |= Cy_CapSense_ProcessWidgetMpDeconvolution(widgetId, context);
}
#endif
#endif
}
#endif
}
#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
Cy_CapSense_InitializeAllFilters(context);
#endif
Cy_CapSense_InitializeAllBaselines(context);
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
context->ptrCommonContext->status &= ~(uint32_t)CY_CAPSENSE_MW_STATE_INITIALIZATION_MASK;
#endif
return result;
}
/*******************************************************************************
* Function Name: Cy_CapSense_Initialize
****************************************************************************//**
*
* Initializes all sub-modules of the CAPSENSE™ middleware.
*
* The initialization includes:
* - Data Structure - set the default middleware parameters based
* on configuration.
* - Data Processing - resets the status all widgets.
* - Tuner - resets the tuner communication state.
* - Sensing - prepares the CAPSENSE™ HW blocks for operation.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Return CY_CAPSENSE_STATUS_SUCCESS if the initialization was successful.
* If CY_CAPSENSE_STATUS_SUCCESS is not received, some of the initialization
* fails.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_Initialize(cy_stc_capsense_context_t * context)
{
cy_capsense_status_t result;
result = Cy_CapSense_CheckConfigIntegrity(context);
if (CY_CAPSENSE_STATUS_SUCCESS == result)
{
Cy_CapSense_InitializeAllStatuses(context);
result |= Cy_CapSense_SsInitialize(context);
/* The Tuner and the BIST are initialized only once */
if (CY_CAPSENSE_INIT_NEEDED == context->ptrCommonContext->initDone)
{
Cy_CapSense_TuInitialize(context);
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN)
Cy_CapSense_BistDsInitialize(context);
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) */
context->ptrCommonContext->initDone = CY_CAPSENSE_INIT_DONE;
}
}
return result;
}
/*******************************************************************************
* Function Name: Cy_CapSense_DeInit
****************************************************************************//**
*
* Stops the middleware operation and releases the CAPSENSE™ captured HW blocks.
*
* No sensor scanning can be executed when the middleware is stopped.
* This function should be called only when no scanning is in progress.
* I.e. Cy_CapSense_IsBusy() returns a non-busy status.
*
* After the middleware stops, the CAPSENSE™ HW block(s) may be reconfigured with the
* application program or other middleware for any other usage.
*
* When the middleware operation is stopped by the Cy_CapSense_DeInit()
* function, subsequent call of the Cy_CapSense_Init() function repeats
* the initialization process, so a subsequent call of the Cy_CapSense_Enable()
* function is not required. However, to implement Time-multiplexed mode
* (sharing the CAPSENSE™ HW block(s) between multiple middleware)
* the Cy_CapSense_Save() and Cy_CapSense_Restore() functions should be used
* instead of the Cy_CapSense_DeInit() and Cy_CapSense_Init() functions for
* further compatibility.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the stop process. If CY_CAPSENSE_STATUS_SUCCESS is not received,
* the stop process fails and retries may be required.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_DeInit(cy_stc_capsense_context_t * context)
{
cy_capsense_status_t result;
result = Cy_CapSense_Save(context);
if (CY_CAPSENSE_STATUS_SUCCESS != result)
{
result = CY_CAPSENSE_STATUS_BAD_DATA;
}
else
{
context->ptrCommonContext->initDone = CY_CAPSENSE_INIT_NEEDED;
}
return result;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ProcessAllWidgets
****************************************************************************//**
*
* Performs full data processing of all enabled widgets.
*
* This function performs all data processes for all enabled widgets and
* sensors in the middleware to produce meaningful status output from widgets
* and sensors. The following tasks are executed as part of processing all the
* widgets:
* 1. Apply raw count filters to the raw counts, if they are enabled.
* 2. Update the thresholds if the smart sensing algorithm Full Auto-Tuning
* is enabled.
* 3. Update the baselines and difference counts for all the sensors.
* 4. Update the sensor and widget output status. Updates on/off status for
* buttons and proximity widgets, centroid/position for
* the sliders and the X/Y position for the touchpads.
*
* This function is called by the application program only after all the enabled
* widgets (and sensors) in the middleware are scanned. Calling this function
* multiple times without sensor scanning causes unexpected behavior.
*
* Disabled and/or non-working widgets are not processed by this function.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the processing operation. If CY_CAPSENSE_STATUS_SUCCESS
* is not received, the processing fails and retries may be required.
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ProcessAllWidgets(cy_stc_capsense_context_t * context)
{
uint32_t wdIndex;
cy_capsense_status_t result = CY_CAPSENSE_STATUS_SUCCESS;
for (wdIndex = CY_CAPSENSE_TOTAL_WIDGET_COUNT; wdIndex-- > 0u;)
{
if (0u != Cy_CapSense_IsWidgetEnabled(wdIndex, context))
{
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP && (CY_CAPSENSE_DISABLE != CY_CAPSENSE_LP_EN))
if ((uint8_t)CY_CAPSENSE_WD_LOW_POWER_E != context->ptrWdConfig[wdIndex].wdType)
#endif /* CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP & CY_CAPSENSE_LP_EN */
{
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) && (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN))
if (0u == ((&context->ptrWdConfig[wdIndex])->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_ALL_CH_MASK))
{
/* Processes all widgets with disabled MFS and all widgets with the original (main) frequency */
result |= Cy_CapSense_ProcessWidget(wdIndex, context);
}
#else
result |= Cy_CapSense_ProcessWidget(wdIndex, context);
#endif
}
}
}
return result;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ProcessWidget
****************************************************************************//**
*
* Performs full data processing of the specified widget if it is enabled.
*
* This function performs exactly the same tasks as
* Cy_CapSense_ProcessAllWidgets(), but only for a specified widget. This
* function can be used along with the Cy_CapSense_ScanWidget() function
* (4th Generation) to scan and process data for a specific widget or with
* the Cy_CapSense_ScanSlots() function (5th Generation).
* This function is called only after all the sensors in the widgets are scanned.
*
* The disabled and/or non-working widgets are not processed by this function.
*
* The pipeline scan method, which during scanning a current widget (N),
* performs the processing of the previously scanned widget (N-1)) can be
* implemented using this function and it may reduce the total execution time,
* increase the refresh rate, and decrease the average power consumption.
* See the function usage example below for details on usage.
*
* For the Fifth generation CAPSENSE™ if the specified widget has the enabled
* multi-frequency scan feature then the function does the following:
* - If the specified widget ID refers to main (base) frequency then the function
* processes raw count processing of all three widgets (main and two sub-widgets)
* and then status processing of the main widget only.
* - If the specified widget ID refers to sub-widgets (1st or 2nd frequency channels)
* then the function returns CY_CAPSENSE_STATUS_BAD_PARAM. To perform customized
* processing use the Cy_CapSense_ProcessWidgetExt() function.
*
* \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.
*
* \note For the fifth-generation low power CAPSENSE™ widgets
* of the \ref CY_CAPSENSE_WD_LOW_POWER_E type are not processed and
* \ref CY_CAPSENSE_STATUS_BAD_PARAM is returned
* if a widget of this type is passed.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the widget processing:
* - CY_CAPSENSE_STATUS_SUCCESS - The operation is successfully completed
* - CY_CAPSENSE_STATUS_BAD_PARAM - The input parameter is invalid
* - CY_CAPSENSE_STATUS_INVALID_STATE - The specified widget is disabled
* - CY_CAPSENSE_STATUS_BAD_DATA - The processing is failed
*
* \funcusage
*
* An example of pipeline implementation:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_ProcessWidget
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ProcessWidget(
uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
cy_capsense_status_t result = CY_CAPSENSE_STATUS_SUCCESS;
const cy_stc_capsense_widget_config_t * ptrWdCfg;
/* Check parameter validity */
if (widgetId >= CY_CAPSENSE_TOTAL_WIDGET_COUNT)
{
result = CY_CAPSENSE_STATUS_BAD_PARAM;
}
else
{
ptrWdCfg = &context->ptrWdConfig[widgetId];
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
if ((uint8_t)CY_CAPSENSE_WD_LOW_POWER_E == ptrWdCfg->wdType)
{
result = CY_CAPSENSE_STATUS_BAD_PARAM;
}
else
#endif /* CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP */
{
/* Check widget enable status */
if (0u == Cy_CapSense_IsWidgetEnabled(widgetId, context))
{
result = CY_CAPSENSE_STATUS_INVALID_STATE;
}
#if (((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)) &&\
(CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN))
/* Check for sub-widget */
if ((0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK)) &&
(0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_ALL_CH_MASK)))
{
result |= CY_CAPSENSE_STATUS_BAD_PARAM;
}
#endif
}
}
if (CY_CAPSENSE_STATUS_SUCCESS == result)
{
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP))
#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK))
{
Cy_CapSense_PreProcessWidget(widgetId + CY_CAPSENSE_MFS_CH2_INDEX, context);
Cy_CapSense_PreProcessWidget(widgetId + CY_CAPSENSE_MFS_CH1_INDEX, context);
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED)
if (((CY_CAPSENSE_MPSC_MIN_ORDER <= ptrWdCfg->mpOrder) ||
(CY_CAPSENSE_MPSC_MIN_ORDER <= ptrWdCfg->mpOrderRows)) &&
(CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod))
{
result |= Cy_CapSense_ProcessWidgetMpDeconvolution(widgetId + CY_CAPSENSE_MFS_CH2_INDEX, context);
result |= Cy_CapSense_ProcessWidgetMpDeconvolution(widgetId + CY_CAPSENSE_MFS_CH1_INDEX, context);
}
#endif
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_TX_ENABLED)
if ((CY_CAPSENSE_MPTX_MIN_ORDER <= ptrWdCfg->mpOrder) &&
(CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod))
{
result |= Cy_CapSense_ProcessWidgetMpDeconvolution(widgetId + CY_CAPSENSE_MFS_CH2_INDEX, context);
result |= Cy_CapSense_ProcessWidgetMpDeconvolution(widgetId + CY_CAPSENSE_MFS_CH1_INDEX, context);
}
#endif
}
#endif
Cy_CapSense_PreProcessWidget(widgetId, context);
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED)
if (((CY_CAPSENSE_MPSC_MIN_ORDER <= ptrWdCfg->mpOrder) ||
(CY_CAPSENSE_MPSC_MIN_ORDER <= ptrWdCfg->mpOrderRows)) &&
(CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod))
{
result |= Cy_CapSense_ProcessWidgetMpDeconvolution(widgetId, context);
}
#endif
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_TX_ENABLED)
if ((CY_CAPSENSE_MPTX_MIN_ORDER <= ptrWdCfg->mpOrder) &&
(CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod))
{
result |= Cy_CapSense_ProcessWidgetMpDeconvolution(widgetId, context);
}
#endif
#endif
#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK))
{
result |= Cy_CapSense_DpProcessWidgetRawCounts(widgetId + CY_CAPSENSE_MFS_CH2_INDEX, context);
result |= Cy_CapSense_DpProcessWidgetRawCounts(widgetId + CY_CAPSENSE_MFS_CH1_INDEX, context);
}
#endif
result |= Cy_CapSense_DpProcessWidgetRawCounts(widgetId, context);
switch (ptrWdCfg->senseMethod)
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
case CY_CAPSENSE_CSD_GROUP:
Cy_CapSense_DpProcessCsdWidgetStatus(ptrWdCfg, 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_DpProcessCsxWidgetStatus(ptrWdCfg);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN)
case CY_CAPSENSE_ISX_GROUP:
Cy_CapSense_DpProcessIsxWidgetStatus(ptrWdCfg);
break;
#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN) */
default:
result |= CY_CAPSENSE_STATUS_BAD_PARAM;
break;
}
}
return result;
}
/*******************************************************************************
* Function Name: Cy_CapSense_ProcessWidgetExt
****************************************************************************//**
*
* Performs customized data processing on the selected widget.
*
* This function performs customized data processing specified by the mode
* parameter on a widget. This function can be used with any of the
* available scan functions. This function should be called only after all
* the sensors in the specified widget are scanned. Calling this function
* multiple times with the same mode without new sensor scan causes
* unexpected behavior. This function ignores the widget statuses like
* disabled and/or non-working and performs processing in any case.
*
* The CY_CAPSENSE_PROCESS_CALC_NOISE and CY_CAPSENSE_PROCESS_THRESHOLDS masks
* for mode parameter are supported only when smart sensing algorithm is enabled
* for CSD widgets.
*
* The execution order of processing tasks starts from LSB to MSB of the
* mode parameter. To implement a different order of execution, call this
* function multiple times with the required mode parameter.
*
* For more details, refer to function usage example below.
*
* \note
* For the fifth-generation CAPSENSE™ and fifth-generation low power
* CAPSENSE™ extra processing should be performed prior a call of
* this function:
* * A raw count pre-processing calling either the Cy_CapSense_PreProcessWidget()
* or Cy_CapSense_PreProcessSensor() functions.
* * A deconvolution for widgets with multi-phase Tx or Self calling the
* Cy_CapSense_ProcessWidgetMpDeconvolution() function
* (multi-phase Self is available only for the fifth-generation low power CAPSENSE™)
* In this case a full processing flow consists of the following:
* * Cy_CapSense_PreProcessWidget()
* * Cy_CapSense_ProcessWidgetMpDeconvolution()
* * Cy_CapSense_ProcessWidgetExt()
*
* \note
* For the fifth generation and fifth-generation low power CAPSENSE™
* if the specified widget has the enabled multi-frequency scan feature
* then the processing must follow the following order:
* * Sub-widget channel 2
* * Sub-widget channel 1
* * Main widget channel 0
* The CY_CAPSENSE_PROCESS_MFS_FILTER option is skipped for sub-widgets,
* however CY_CAPSENSE_PROCESS_STATUS option is available.
*
* \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.
*
* \note For the fifth-generation low power CAPSENSE™ widgets
* of the \ref CY_CAPSENSE_WD_LOW_POWER_E type are not processed and
* \ref CY_CAPSENSE_STATUS_BAD_PARAM is returned
* if a widget of this type is passed.
*
* \param mode
* Specifies the type of widget processing to be executed for the
* specified widget:
* 1. Bits [31..7] - Reserved.
* 2. Bits [6..0] - CY_CAPSENSE_PROCESS_ALL - Execute all of the below tasks.
* 3. Bit [6] - CY_CAPSENSE_PROCESS_STATUS - Update the status
* (on/off, centroid position).
* 4. Bit [5] - CY_CAPSENSE_PROCESS_MFS_FILTER - Run the firmware filters
* for MFS on sensor rawcounts
* (applicable only for fifth-generation CAPSENSE™
* and fifth-generation low power CAPSENSE™).
* 5. Bit [4] - CY_CAPSENSE_PROCESS_THRESHOLDS - Update the thresholds
* (only in CSD auto-tuning mode).
* 6. Bit [3] - CY_CAPSENSE_PROCESS_CALC_NOISE - Calculate the noise
* (only in CSD auto-tuning mode).
* 7. Bit [2] - CY_CAPSENSE_PROCESS_DIFFCOUNTS - Update the difference
* counts of each sensor.
* 8. Bit [1] - CY_CAPSENSE_PROCESS_BASELINE - Update the baselines
* for all sensor.
* 9. Bit [0] - CY_CAPSENSE_PROCESS_FILTER - Run the firmware filters
* on sensor rawcounts.
*
* \param context
* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the widget processing operation:
* - CY_CAPSENSE_STATUS_SUCCESS - The processing is successfully performed.
* - CY_CAPSENSE_STATUS_BAD_PARAM - The input parameter is invalid.
* - CY_CAPSENSE_STATUS_BAD_DATA - The processing failed.
*
* \funcusage
*
* An example of customized data processing, changed processing order:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_ProcessWidgetExt
*
*******************************************************************************/
cy_capsense_status_t Cy_CapSense_ProcessWidgetExt(
uint32_t widgetId,
uint32_t mode,
cy_stc_capsense_context_t * context)
{
uint32_t snsIndex;
cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
uint32_t snsHistorySize;
uint32_t freqChIndex;
uint16_t * ptrHistorySns;
uint16_t * ptrBslnInvSns;
uint8_t * ptrHistoryLowSns = NULL;
cy_stc_capsense_sensor_context_t * ptrSnsCxtSns;
const cy_stc_capsense_widget_config_t * ptrWdCfg;
/* Check parameter validity */
if (widgetId < CY_CAPSENSE_TOTAL_WIDGET_COUNT)
{
ptrWdCfg = &context->ptrWdConfig[widgetId];
#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)
if ((uint8_t)CY_CAPSENSE_WD_LOW_POWER_E != ptrWdCfg->wdType)
#endif /* CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP */
{
capStatus = CY_CAPSENSE_STATUS_SUCCESS;
snsHistorySize = (uint32_t)ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_MASK;
/* Run the desired processing for the all CSD widget sensors */
for (freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
{
ptrSnsCxtSns = &ptrWdCfg->ptrSnsContext[freqChIndex * context->ptrCommonConfig->numSns];
ptrBslnInvSns = &ptrWdCfg->ptrBslnInv[freqChIndex * context->ptrCommonConfig->numSns];
ptrHistorySns = &ptrWdCfg->ptrRawFilterHistory[freqChIndex * (CY_CAPSENSE_RAW_HISTORY_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)];
if (CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
{
ptrHistoryLowSns = &ptrWdCfg->ptrRawFilterHistoryLow[freqChIndex *
(CY_CAPSENSE_IIR_HISTORY_LOW_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)];
}
for (snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
{
capStatus |= Cy_CapSense_DpProcessSensorRawCountsExt(ptrWdCfg, ptrSnsCxtSns, ptrHistorySns,
ptrHistoryLowSns, mode, ptrBslnInvSns, context);
ptrSnsCxtSns++;
ptrBslnInvSns++;
ptrHistorySns += snsHistorySize;
if (NULL != ptrHistoryLowSns)
{
ptrHistoryLowSns++;
}
}
}
#if ((CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) && \
(CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN))
ptrSnsCxtSns = ptrWdCfg->ptrSnsContext;
for (snsIndex = ptrWdCfg->numSns; snsIndex-- > 0u;)
{
Cy_CapSense_RunMfsFiltering(ptrSnsCxtSns, context);
ptrSnsCxtSns++;
}
#endif
#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN) && \
((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)))
if ((0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK)) &&
(0u == (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_ALL_CH_MASK)))
{
if (0u != (mode & CY_CAPSENSE_PROCESS_MFS_FILTER))
{
(void)Cy_CapSense_RunMfsMedian(widgetId, context);
}
}
#endif
if (0u != (mode & CY_CAPSENSE_PROCESS_STATUS))
{
switch (ptrWdCfg->senseMethod)
{
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
case CY_CAPSENSE_CSX_GROUP:
Cy_CapSense_DpProcessCsxWidgetStatus(ptrWdCfg);
break;
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
case CY_CAPSENSE_CSD_GROUP:
Cy_CapSense_DpProcessCsdWidgetStatus(ptrWdCfg, context);
break;
#endif
#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN)
case CY_CAPSENSE_ISX_GROUP:
Cy_CapSense_DpProcessIsxWidgetStatus(ptrWdCfg);
break;
#endif
default:
capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
/* No action */
break;
}