From a4aa9306f7e4323994902f0baf5b1570ffbbfe59 Mon Sep 17 00:00:00 2001 From: gitlab-runner Date: Thu, 7 Mar 2024 06:38:50 -0600 Subject: [PATCH] Upload capsense 5.0.0.6806 [2234] --- README.md | 10 +- RELEASE.md | 20 +- cy_capsense.h | 159 +- cy_capsense_centroid.c | 4 +- cy_capsense_centroid.h | 4 +- cy_capsense_common.h | 72 +- cy_capsense_control.c | 40 +- cy_capsense_control.h | 4 +- cy_capsense_csd_v2.c | 6 +- cy_capsense_csd_v2.h | 4 +- cy_capsense_csx_v2.c | 12 +- cy_capsense_csx_v2.h | 4 +- cy_capsense_filter.c | 4 +- cy_capsense_filter.h | 4 +- cy_capsense_generator_lp.c | 8 +- cy_capsense_generator_lp.h | 199 +- cy_capsense_generator_v3.c | 5 +- cy_capsense_generator_v3.h | 4 +- cy_capsense_gesture_lib.h | 4 +- cy_capsense_lib.h | 87 +- cy_capsense_processing.c | 4 +- cy_capsense_processing.h | 4 +- cy_capsense_selftest.c | 23 +- cy_capsense_selftest.h | 4 +- cy_capsense_selftest_lp.c | 48 +- cy_capsense_selftest_lp.h | 22 +- cy_capsense_selftest_v2.c | 14 +- cy_capsense_selftest_v2.h | 24 +- cy_capsense_selftest_v3.c | 27 +- cy_capsense_selftest_v3.h | 4 +- cy_capsense_sensing.c | 89 +- cy_capsense_sensing.h | 4 +- cy_capsense_sensing_lp.c | 2940 ++++++++++++----- cy_capsense_sensing_lp.h | 80 +- cy_capsense_sensing_v2.c | 17 +- cy_capsense_sensing_v2.h | 4 +- cy_capsense_sensing_v3.c | 700 +++- cy_capsense_sensing_v3.h | 8 +- cy_capsense_sm_base_full_wave_lp.h | 233 +- cy_capsense_sm_base_full_wave_v3.h | 4 +- cy_capsense_structure.c | 10 +- cy_capsense_structure.h | 82 +- cy_capsense_tuner.c | 4 +- cy_capsense_tuner.h | 4 +- .../html/annotated.html | 6 +- .../html/classes.html | 6 +- .../html/functions.html | 6 +- .../html/functions_b.html | 6 +- .../html/functions_c.html | 21 +- .../html/functions_d.html | 6 +- .../html/functions_e.html | 6 +- .../html/functions_f.html | 6 +- .../html/functions_g.html | 6 +- .../html/functions_h.html | 9 +- .../html/functions_i.html | 6 +- .../html/functions_k.html | 6 +- .../html/functions_l.html | 6 +- .../html/functions_m.html | 6 +- .../html/functions_n.html | 6 +- .../html/functions_o.html | 6 +- .../html/functions_p.html | 6 +- .../html/functions_r.html | 12 +- .../html/functions_s.html | 6 +- .../html/functions_t.html | 6 +- .../html/functions_v.html | 6 +- .../html/functions_vars.html | 6 +- .../html/functions_vars_b.html | 6 +- .../html/functions_vars_c.html | 21 +- .../html/functions_vars_d.html | 6 +- .../html/functions_vars_e.html | 6 +- .../html/functions_vars_f.html | 6 +- .../html/functions_vars_g.html | 6 +- .../html/functions_vars_h.html | 9 +- .../html/functions_vars_i.html | 6 +- .../html/functions_vars_k.html | 6 +- .../html/functions_vars_l.html | 6 +- .../html/functions_vars_m.html | 6 +- .../html/functions_vars_n.html | 6 +- .../html/functions_vars_o.html | 6 +- .../html/functions_vars_p.html | 6 +- .../html/functions_vars_r.html | 12 +- .../html/functions_vars_s.html | 6 +- .../html/functions_vars_t.html | 6 +- .../html/functions_vars_v.html | 6 +- .../html/functions_vars_w.html | 6 +- .../html/functions_vars_x.html | 6 +- .../html/functions_vars_y.html | 6 +- .../html/functions_vars_z.html | 6 +- .../html/functions_w.html | 6 +- .../html/functions_x.html | 6 +- .../html/functions_y.html | 6 +- .../html/functions_z.html | 6 +- .../group__group__capsense__callbacks.html | 6 +- ...oup__group__capsense__data__structure.html | 6 +- .../html/group__group__capsense__enums.html | 150 +- .../html/group__group__capsense__enums.js | 24 +- ..._group__capsense__gesture__structures.html | 6 +- .../group__group__capsense__high__level.html | 95 +- .../group__group__capsense__low__level.html | 221 +- .../group__group__capsense__low__level.js | 6 +- .../html/group__group__capsense__macros.html | 6 +- .../group__group__capsense__macros__bist.html | 8 +- ...oup__group__capsense__macros__general.html | 12 +- ...oup__group__capsense__macros__gesture.html | 6 +- ...roup__capsense__macros__miscellaneous.html | 14 +- ..._group__capsense__macros__miscellaneous.js | 2 +- ...p__group__capsense__macros__mw__state.html | 6 +- .../group__group__capsense__macros__pin.html | 10 +- ...oup__group__capsense__macros__process.html | 8 +- ...up__group__capsense__macros__settings.html | 32 +- ...roup__group__capsense__macros__settings.js | 6 + ...roup__group__capsense__macros__status.html | 16 +- .../group__group__capsense__macros__status.js | 2 +- ...group__group__capsense__macros__touch.html | 6 +- .../group__group__capsense__structures.html | 6 +- .../group__group__capsense__structures.js | 12 +- .../html/index.html | 56 +- .../html/modules.html | 6 +- .../html/navtreedata.js | 11 +- .../html/navtreeindex0.js | 184 +- .../html/navtreeindex1.js | 310 +- .../html/navtreeindex2.js | 8 +- .../html/navtreeindex3.js | 8 +- .../html/navtreeindex4.js | 47 +- .../html/navtreeindex5.js | 5 + .../html/search/all_2.js | 33 +- .../html/search/all_7.js | 1 + .../html/search/all_f.js | 2 - .../html/search/enums_0.js | 2 +- .../html/search/enumvalues_0.js | 12 +- .../html/search/functions_0.js | 4 + .../html/search/variables_2.js | 5 +- .../html/search/variables_7.js | 1 + .../html/search/variables_f.js | 2 - ...__stc__capsense__active__scan__sns__t.html | 6 +- ...capsense__adaptive__filter__config__t.html | 6 +- ...psense__advanced__centroid__config__t.html | 6 +- ...psense__advanced__touchpad__config__t.html | 6 +- ..._stc__capsense__alp__fltr__channel__t.html | 6 +- ...__stc__capsense__alp__fltr__config__t.html | 6 +- ..._stc__capsense__auto__tune__config__t.html | 6 +- ...__stc__capsense__ballistic__config__t.html | 6 +- ..._stc__capsense__ballistic__context__t.html | 6 +- ...y__stc__capsense__ballistic__delta__t.html | 6 +- ...ctcy__stc__capsense__bist__context__t.html | 6 +- ...capsense__bist__custom__parameters__t.html | 6 +- ...cy__stc__capsense__channel__config__t.html | 6 +- ...tcy__stc__capsense__common__config__t.html | 6 +- ...cy__stc__capsense__common__context__t.html | 6 +- .../structcy__stc__capsense__context__t.html | 6 +- ..._stc__capsense__csx__touch__buffer__t.html | 6 +- ...stc__capsense__csx__touch__history__t.html | 6 +- ...__stc__capsense__electrode__config__t.html | 6 +- ...cy__stc__capsense__gesture__config__t.html | 6 +- ...y__stc__capsense__gesture__context__t.html | 6 +- ...__stc__capsense__gesture__position__t.html | 6 +- ...__capsense__hw__smartsense__config__t.html | 6 +- ...__stc__capsense__idac__gain__table__t.html | 6 +- ...__stc__capsense__internal__context__t.html | 25 +- ...structcy__stc__capsense__mp__table__t.html | 6 +- ...ctcy__stc__capsense__ofcd__context__t.html | 6 +- ...ctcy__stc__capsense__ofdc__context__t.html | 6 +- ...ctcy__stc__capsense__ofes__context__t.html | 6 +- ...ctcy__stc__capsense__offl__context__t.html | 6 +- ...ctcy__stc__capsense__oflp__context__t.html | 6 +- ...ctcy__stc__capsense__ofrt__context__t.html | 6 +- ...ctcy__stc__capsense__ofsc__context__t.html | 6 +- ...ctcy__stc__capsense__ofsl__context__t.html | 6 +- ...ructcy__stc__capsense__pin__config__t.html | 6 +- .../structcy__stc__capsense__position__t.html | 8 +- ...tructcy__stc__capsense__scan__slot__t.html | 6 +- ...cy__stc__capsense__sensor__context__t.html | 6 +- ...__smartsense__csd__noise__envelope__t.html | 6 +- ...se__smartsense__update__thresholds__t.html | 6 +- ...ctcy__stc__capsense__tfsc__context__t.html | 6 +- ...ctcy__stc__capsense__tfsl__context__t.html | 6 +- ...ctcy__stc__capsense__tfzm__context__t.html | 6 +- .../structcy__stc__capsense__touch__t.html | 48 +- ...tcy__stc__capsense__widget__config__t.html | 114 +- ...cy__stc__capsense__widget__context__t.html | 50 +- ...__stc__capsense__widget__crc__data__t.html | 14 +- version.xml | 2 +- 182 files changed, 5007 insertions(+), 2206 deletions(-) create mode 100644 docs/capsense_api_reference_manual/html/navtreeindex5.js diff --git a/README.md b/README.md index f4dfdcd..ec9ef11 100644 --- a/README.md +++ b/README.md @@ -39,15 +39,15 @@ For more information, refer to: * CAPSENSE™ overview: * [CAPSENSE™ Middleware RELEASE.md](./RELEASE.md) * [CAPSENSE™ Middleware API Reference Guide](https://infineon.github.io/capsense/capsense_api_reference_manual/html/index.html) - * [ModusToolbox™ CAPSENSE™ Configurator Tool Guide](www.cypress.com/ModusToolboxCapSenseConfig) - * [ModusToolbox™ CAPSENSE™ Tuner Tool Guide](www.cypress.com/ModusToolboxCapSenseTuner) + * [ModusToolbox™ CAPSENSE™ Configurator Tool Guide](www.infineon.com/ModusToolboxCapSenseConfig) + * [ModusToolbox™ CAPSENSE™ Tuner Tool Guide](www.infineon.com/ModusToolboxCapSenseTuner) * [CAPSENSE™ Design Guide](https://www.infineon.com/dgdl/Infineon-AN85951_PSoC_4_and_PSoC_6_MCU_CapSense_Design_Guide-ApplicationNotes-v27_00-EN.pdf?fileId=8ac78c8c7cdc391c017d0723535d4661) * [CSDADC Middleware API Reference Guide](https://infineon.github.io/csdadc/csdadc_api_reference_manual/html/index.html) * [CSDIDAC Middleware API Reference Guide](https://infineon.github.io/csdidac/csdidac_api_reference_manual/html/index.html) * ModusToolbox™ Overview: * [ModusToolbox™ Software Environment, Quick Start Guide, Documentation, and Videos](https://www.infineon.com/cms/en/design-support/tools/sdk/modustoolbox-software) - * [ModusToolbox™ Device Configurator Tool Guide](https://www.cypress.com/ModusToolboxDeviceConfig) + * [ModusToolbox™ Device Configurator Tool Guide](https://www.infineon.com/ModusToolboxDeviceConfig) * Infineon Technologies AG Kits and Code Examples: * [CAPSENSE™ Middleware Code Example for MBED OS](https://github.com/Infineon/mbed-os-example-capsense) @@ -56,9 +56,11 @@ For more information, refer to: * [CY8CKIT-149 PSoC™ 4100S Plus Prototyping Kit](https://www.infineon.com/cms/en/product/evaluation-boards/cy8ckit-149/) * [CY8CKIT-041-40XX PSoC™ 4 S-Series Pioneer Kit](https://www.infineon.com/dgdl/Infineon-CY8CKIT-041-40XX_PSoC_4_S-Series_Pioneer_Kit_Quick_Start_Guide-UserManual-v01_00-EN.pdf?fileId=8ac78c8c7d0d8da4017d0efc44781263) * [CY8CKIT-041-41XX PSoC™ 4100S CAPSENSE™ Pioneer Kit](https://www.infineon.com/cms/en/product/evaluation-boards/cy8ckit-041-41xx/) + * [CY8CKIT-040T PSoC™ 4000T CAPSENSE™ Evaluation Kit](https://www.infineon.com/cms/en/product/evaluation-boards/cy8ckit-040t/) * General Information: * [AN210781 Getting Started with PSoC™ 6 MCU with Bluetooth Low Energy (BLE) Connectivity](https://www.infineon.com/dgdl/Infineon-AN210781_Getting_Started_with_PSoC_6_MCU_with_Bluetooth_Low_Energy_(BLE)_Connectivity_on_PSoC_Creator-ApplicationNotes-v05_00-EN.pdf?fileId=8ac78c8c7cdc391c017d0d311f536528) + * [AN215671 PSoC™ 6 MCU firmware design for BLE applications](https://www.infineon.com/cms/en/search.html#!term=AN215671&view=downloads) * [PSoC™ 6 Technical Reference Manual](https://www.infineon.com/dgdl/Infineon-PSoC_6_MCU_PSoC_63_with_BLE_Architecture_Technical_Reference_Manual-AdditionalTechnicalInformation-v11_00-EN.pdf?fileId=8ac78c8c7d0d8da4017d0f946fea01ca) * [PSoC™ 63 with BLE Datasheet Programmable System-on-Chip datasheet](https://www.infineon.com/dgdl/Infineon-PSoC_6_MCU_PSoC_63_with_BLE_Datasheet_Programmable_System-on-Chip_(PSoC)-DataSheet-v16_00-EN.pdf?fileId=8ac78c8c7d0d8da4017d0ee4efe46c37) * [CAT1 PDL API Reference](https://infineon.github.io/mtb-pdl-cat1/pdl_api_reference_manual/html/index.html) @@ -69,4 +71,4 @@ For more information, refer to: * [Infineon Technologies](http://www.infineon.com) --- -CYPRESS™ Semiconductor Corporation, 2019-2023. +CYPRESS™ Semiconductor Corporation, 2019-2024. diff --git a/RELEASE.md b/RELEASE.md index 0035cd9..8beb55d 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,4 +1,4 @@ -# CAPSENSE™ Middleware Library 4.0 +# CAPSENSE™ Middleware Library 5.0 ### What is Included? For a complete description of the CAPSENSE™ middleware, refer to [README.md](./README.md) and [API Reference Guide](https://infineon.github.io/capsense/capsense_api_reference_manual/html/index.html). @@ -18,14 +18,14 @@ This version of the CAPSENSE™ middleware was validated for compatibility with | Software and tools | Version | | :--- | :----: | -| ModusToolbox™ Software Environment | 3.1 | -| - ModusToolbox™ Device Configurator | 4.10 | +| ModusToolbox™ Software Environment | 3.2 | +| - ModusToolbox™ Device Configurator | 4.20 | | - ModusToolbox™ MSC Superblock Personality for PSoC™ 4 devices in the Device Configurator | 1.0 | | - ModusToolbox™ MSCLP Personality for PSoC™ 4 devices in the Device Configurator | 3.0 | | - ModusToolbox™ MSC Personality for PSoC™ 4 devices in the Device Configurator | 1.1 | | - ModusToolbox™ CSD Personality for PSoC™ 4 devices in the Device Configurator | 2.0 | -| - ModusToolbox™ CSD Personality for PSoC™ 6 devices in the Device Configurator | 2.0 | -| - ModusToolbox™ CAPSENSE™ Configurator / Tuner | 6.10 | +| - ModusToolbox™ CSD Personality for PSoC™ 6 devices in the Device Configurator | 3.0 | +| - ModusToolbox™ CAPSENSE™ Configurator / Tuner | 6.20 | | CAT1 Peripheral Driver Library (PDL) | 3.3.1 | | CAT2 Peripheral Driver Library (PDL) | 2.5.0 | | GCC Compiler | 11.3.1 | @@ -39,15 +39,15 @@ For more information, refer to: * CAPSENSE™ overview: * [CAPSENSE™ Middleware RELEASE.md](./RELEASE.md) * [CAPSENSE™ Middleware API Reference Guide](https://infineon.github.io/capsense/capsense_api_reference_manual/html/index.html) - * [ModusToolbox™ CAPSENSE™ Configurator Tool Guide](www.cypress.com/ModusToolboxCapSenseConfig) - * [ModusToolbox™ CAPSENSE™ Tuner Tool Guide](www.cypress.com/ModusToolboxCapSenseTuner) + * [ModusToolbox™ CAPSENSE™ Configurator Tool Guide](www.infineon.com/ModusToolboxCapSenseConfig) + * [ModusToolbox™ CAPSENSE™ Tuner Tool Guide](www.infineon.com/ModusToolboxCapSenseTuner) * [CAPSENSE™ Design Guide](https://www.infineon.com/dgdl/Infineon-AN85951_PSoC_4_and_PSoC_6_MCU_CapSense_Design_Guide-ApplicationNotes-v27_00-EN.pdf?fileId=8ac78c8c7cdc391c017d0723535d4661) * [CSDADC Middleware API Reference Guide](https://infineon.github.io/csdadc/csdadc_api_reference_manual/html/index.html) * [CSDIDAC Middleware API Reference Guide](https://infineon.github.io/csdidac/csdidac_api_reference_manual/html/index.html) * ModusToolbox™ Overview: * [ModusToolbox™ Software Environment, Quick Start Guide, Documentation, and Videos](https://www.infineon.com/cms/en/design-support/tools/sdk/modustoolbox-software) - * [ModusToolbox™ Device Configurator Tool Guide](https://www.cypress.com/ModusToolboxDeviceConfig) + * [ModusToolbox™ Device Configurator Tool Guide](https://www.infineon.com/ModusToolboxDeviceConfig) * Infineon Technologies AG Kits and Code Examples * [CAPSENSE™ Middleware Code Example for MBED OS](https://github.com/Infineon/mbed-os-example-capsense) @@ -56,9 +56,11 @@ For more information, refer to: * [CY8CKIT-149 PSoC™ 4100S Plus Prototyping Kit](https://www.infineon.com/cms/en/product/evaluation-boards/cy8ckit-149) * [CY8CKIT-041-40XX PSoC™ 4 S-Series Pioneer Kit](https://www.infineon.com/dgdl/Infineon-CY8CKIT-041-40XX_PSoC_4_S-Series_Pioneer_Kit_Quick_Start_Guide-UserManual-v01_00-EN.pdf?fileId=8ac78c8c7d0d8da4017d0efc44781263) * [CY8CKIT-041-41XX PSoC™ 4100S CAPSENSE™ Pioneer Kit](https://www.infineon.com/cms/en/product/evaluation-boards/cy8ckit-041-41xx/) + * [CY8CKIT-040T PSoC™ 4000T CAPSENSE™ Evaluation Kit](https://www.infineon.com/cms/en/product/evaluation-boards/cy8ckit-040t/) * General information: * [AN210781 Getting Started with PSoC™ 6 MCU with Bluetooth Low Energy (BLE) Connectivity](https://www.infineon.com/dgdl/Infineon-AN210781_Getting_Started_with_PSoC_6_MCU_with_Bluetooth_Low_Energy_(BLE)_Connectivity_on_PSoC_Creator-ApplicationNotes-v05_00-EN.pdf?fileId=8ac78c8c7cdc391c017d0d311f536528) + * [AN215671 PSoC™ 6 MCU firmware design for BLE applications](https://www.infineon.com/cms/en/search.html#!term=AN215671&view=downloads) * [PSoC™ 6 Technical Reference Manual](https://www.infineon.com/dgdl/Infineon-PSoC_6_MCU_PSoC_63_with_BLE_Architecture_Technical_Reference_Manual-AdditionalTechnicalInformation-v11_00-EN.pdf?fileId=8ac78c8c7d0d8da4017d0f946fea01ca) * [PSoC™ 63 with BLE Datasheet Programmable System-on-Chip datasheet](https://www.infineon.com/dgdl/Infineon-PSoC_6_MCU_PSoC_63_with_BLE_Datasheet_Programmable_System-on-Chip_(PSoC)-DataSheet-v16_00-EN.pdf?fileId=8ac78c8c7d0d8da4017d0ee4efe46c37) * [CAT1 PDL API Reference](https://infineon.github.io/mtb-pdl-cat1/pdl_api_reference_manual/html/index.html) @@ -69,4 +71,4 @@ For more information, refer to: * [Infineon Technologies](http://www.infineon.com) --- -CYPRESS™ Semiconductor Corporation, 2019-2023. +CYPRESS™ Semiconductor Corporation, 2019-2024. diff --git a/cy_capsense.h b/cy_capsense.h index 94bf7fe..fee225f 100644 --- a/cy_capsense.h +++ b/cy_capsense.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense.h -* \version 4.0 +* \version 5.0 * * \brief * This file includes all the header files of the CAPSENSE™ middleware. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 @@ -185,11 +185,11 @@ * * The * CAT2 Peripheral Driver Library (PDL) is included in the project * in case if the PSoC™ 4 device is used. -* * +* * * ModusToolbox™ Device Configurator Tool, -* +* * ModusToolbox™ CAPSENSE™ Configurator Tool, and -* +* * ModusToolbox™ CAPSENSE™ Tuner Tool * are installed on the machine. * @@ -250,11 +250,11 @@ * * * ModusToolbox™ Software Environment -* 3.1 +* 3.2 * * * - ModusToolbox™ Device Configurator tool -* 4.10 +* 4.20 * * * - ModusToolbox™ MSC Superblock Personality for PSoC™ 4 devices in the Device Configurator tool @@ -274,11 +274,11 @@ * * * - ModusToolbox™ CSD Personality for PSoC™ 6 devices in the Device Configurator tool -* 2.0 +* 3.0 * * * - ModusToolbox™ CAPSENSE™ Configurator tool -* 6.10 +* 6.20 * * * - ModusToolbox™ CAPSENSE™ Tuner tool @@ -661,6 +661,9 @@ * * * +* \note Refer to the "Errata" section of the device datasheet to get information +* about the known problems related to the CAPSENSE™ HW IP block. +* ******************************************************************************** * \section section_capsense_changelog Changelog ******************************************************************************** @@ -668,7 +671,126 @@ * * * -* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* +* * * * +* +* +* +* * * * * +* that form 3x3 matrix with a local maximum in the center). It is not used by Middleware, however can be +* re-used by users to define a touch shape or a finger size. * * * @@ -138,6 +139,86 @@ typedef struct * * 3 - three touches are detected * * CY_CAPSENSE_POSITION_MULTIPLE - multiple touches are detected * and information in position structure should be ignored. + * + * The below table specifies a number of touches could be reported for a specific widget. + *
VersionChangesReason for Change
4.05.0 +* This version is not backward compatible with the +* previous version due to re-designed CDAC Auto-calibration. +* We tried to keep the established API, but your design may need to be +* updated to operate with CAPSENSE™ middleware v5.0. +* Also, if you use the CAPSENSE&trade middleware v5.0, you must use +* the CAPSENSE&trade Configurator v6.20 tool or later. This MW version is not +* compatible with the previous Configurator tool versions. +* +*
+* Re-designed CDAC Auto-calibration algorithm for the fifth-generation +* LP devices +* +* Feature enhancement +*
+* Added auto selection mode of CIC2 decimation rate for the +* fifth-generation LP devices +* +* Feature enhancement +*
+* Added Auto-selection mode of CDAC Dither scale value for the +* fifth-generation and fifth-generation LP devices +* +* Feature enhancement +*
+* Added the HW IIR Filter initialization function +* Cy_CapSense_ScanInitializeHwIirAllSlots() and +* Cy_CapSense_ScanInitializeHwIirSlots() for fifth-generation LP devices +* +* Feature enhancement +*
+* Corrected the low power widget scanning flow by excluding waking up at a +* signal detection - only the end of the frame interrupt is kept. +* Condition: multiple low power sensors. This will avoid multiple interrupt +* generation and in some cases prevent the device from hanging. +* +* Defect fixing +*
+* Corrected description of the cy_stc_capsense_position_t structure +* +* Defect fixing +*
+* Removed Epilogue cycles from the maximum Raw Counts definition +* +* Defect fixing +*
+* Hidden a Multi-phase Self feature for fifth-generation LP devices +* +* Defect fixing +*
+* Disabled the External Frame Start in the Cy_CapSense_InitializeMaxRaw() +* function for the fifth-generation devices +* +* Defect fixing +*
+* Corrected description of the BIST measurement function +* +* Defect fixing +*
+* Corrected description of the cy_stc_capsense_touch_t structure +* +* Defect fixing +*
+* Updated description of the software watchdog time calculation for +* the fifth-generation devices +* +* Defect fixing +*
4.0 * This version is not backward compatible with the * previous version due to fifth-generation LP devices support @@ -810,6 +932,14 @@ *
+* Added Long Press gesture +* +* Feature enhancement +*
3.0 * This version is not backward compatible with the @@ -1043,10 +1173,10 @@ * * * CAPSENSE™ Overview: * -* * ModusToolbox™ +* * ModusToolbox™ * CAPSENSE™ Configurator Tool Guide * -* * ModusToolbox™ +* * ModusToolbox™ * CAPSENSE™ Tuner Tool Guide * * * @@ -1058,7 +1188,7 @@ * ModusToolbox™ Software Environment, Quick Start Guide, Documentation, * and Videos * -* * ModusToolbox™ +* * ModusToolbox™ * Device Configurator Tool Guide * * * Infineon Technologies Kits and Code Examples: @@ -1086,6 +1216,9 @@ * * AN210781 Getting Started with * PSoC™ 6 MCU with Bluetooth Low Energy (BLE) Connectivity * +* * AN215671 PSoC™ 6 MCU +* firmware design for BLE applications +* * * * PSoC™ 6 Technical Reference Manual * diff --git a/cy_capsense_centroid.c b/cy_capsense_centroid.c index 4b4f622..bcc0be2 100644 --- a/cy_capsense_centroid.c +++ b/cy_capsense_centroid.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_centroid.c -* \version 4.0 +* \version 5.0 * * \brief * This file provides the source code for the centroid calculation methods @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_centroid.h b/cy_capsense_centroid.h index 2711b9c..178ee07 100644 --- a/cy_capsense_centroid.h +++ b/cy_capsense_centroid.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_centroid.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes for the centroid calculation @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_common.h b/cy_capsense_common.h index 21ebff9..9ccd623 100644 --- a/cy_capsense_common.h +++ b/cy_capsense_common.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_common.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the common CAPSENSE™ middleware definitions. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 @@ -106,11 +106,11 @@ extern "C" { /** \addtogroup group_capsense_macros_general *//** \{ */ /******************************************************************************/ /** Middleware major version */ -#define CY_CAPSENSE_MW_VERSION_MAJOR (4) +#define CY_CAPSENSE_MW_VERSION_MAJOR (5) /** Middleware minor version */ #define CY_CAPSENSE_MW_VERSION_MINOR (0) /** Middleware version */ -#define CY_CAPSENSE_MW_VERSION (400) +#define CY_CAPSENSE_MW_VERSION (500) #if (CY_CAPSENSE_PSOC6_FOURTH_GEN) /** Defined supported CSD driver version */ @@ -202,7 +202,7 @@ extern "C" { /** Widget active status mask */ #define CY_CAPSENSE_WD_ACTIVE_MASK (0x01u) -/** Widget disable status mask */ +/** Widget enable status mask */ #define CY_CAPSENSE_WD_ENABLE_MASK (0x02u) /** Widget working status mask */ #define CY_CAPSENSE_WD_WORKING_MASK (0x04u) @@ -281,6 +281,12 @@ extern "C" { #define CY_CAPSENSE_CIC_FILTER (0u) /** CIC2 filter mode */ #define CY_CAPSENSE_CIC2_FILTER (1u) +/** Maximum CIC2 Decimation Rate */ +#define CY_CAPSENSE_MAX_DECIMATION_RATE (255u) +/** CIC2 filter minimum valid sample number */ +#define CY_CAPSENSE_CIC2_MIN_VALID_SAMPLES (2u) +/** CIC2 filter maximum valid sample number */ +#define CY_CAPSENSE_CIC2_MAX_VALID_SAMPLES (515u) /** Raw count counter mode saturate */ #define CY_CAPSENSE_COUNTER_MODE_SATURATE (0u) @@ -526,6 +532,14 @@ extern "C" { /** LFSR range for LFSR_BITS=3 */ #define CY_CAPSENSE_LFSR_BITS_RANGE_3 (0x03u) +/* CIC2 Decimation Rate Mode selection options */ +/** The cicRate value set by users */ +#define CY_CAPSENSE_CIC_RATE_MODE_MANUAL (0u) +/** The cicRate value configured by middleware */ +#define CY_CAPSENSE_CIC_RATE_MODE_AUTO (1u) +/** The cicRate value configured by SMARTSENSE™ algorithm */ +#define CY_CAPSENSE_CIC_RATE_MODE_SMARTSENSE (2u) + /* Sense clock auto-selection modes for MSCv3 */ /** This mode implements checking the following rules: * - An LFSR value should be selected so that the max clock dither is limited with the value, @@ -806,7 +820,7 @@ extern "C" { * CAPSENSE™ */ #define CY_CAPSENSE_ISX_RX_PIN (8u) - /** Configuring of pin as an ISX Rx + /** Configuring of pin as an VDDA/2 * \note This macro is available only for the fifth-generation CAPSENSE™ and the fifth-generation low power * CAPSENSE™ */ @@ -882,9 +896,9 @@ extern "C" { #define CY_CAPSENSE_HW_CONFIG_CHANNEL_SATURATION (5u) /** CAPSENSE™ related HW is configured to the smart sense */ #define CY_CAPSENSE_HW_CONFIG_SMARTSENSE (6u) +/** CAPSENSE™ related HW is configured to execute a scan to define CDAC dither parameters */ +#define CY_CAPSENSE_HW_CONFIG_AUTO_DITHERING (7u) -/** Maximum Decimation Rate */ -#define CY_CAPSENSE_MAX_DECIMATION_RATE (255u) /** \} */ @@ -1005,9 +1019,9 @@ extern "C" { #define CY_CAPSENSE_STATUS_HW_LOCKED (0x80u) /** Return status \ref cy_capsense_status_t of CAPSENSE™ operation: Unable to perform calibration */ #define CY_CAPSENSE_STATUS_CALIBRATION_FAIL (0x100u) -/** Return status \ref cy_capsense_status_t of CAPSENSE™ operation: Calibration scan with the maximum CDAC code is saturated */ -#define CY_CAPSENSE_STATUS_CALIBRATION_OVERFLOW (0x200u) -/** Return status \ref cy_capsense_status_t of CAPSENSE™ operation: Unable to perform calibration */ +/** Return status \ref cy_capsense_status_t of CAPSENSE™ operation: CapDac calibration fail - The reference/fine CapDAC calibration stage is failed as the raw count minimum across widget is out of range */ +#define CY_CAPSENSE_STATUS_CALIBRATION_REF_CHECK_FAIL (0x200u) +/** Return status \ref cy_capsense_status_t of CAPSENSE™ operation: CapDac calibration fail - The resulting rawcounts across all sensors in widget are out of defined range */ #define CY_CAPSENSE_STATUS_CALIBRATION_CHECK_FAIL (0x400u) /** Return status \ref cy_capsense_status_t of CAPSENSE™ operation: Sense Clock Divider * is out of the valid range for the specified Clock source configuration @@ -1059,25 +1073,6 @@ extern "C" { #define CY_CAPSENSE_MODE_AS_MS (0x2u) /* The Autonomous-Scan Multi-Sensor Mode */ #define CY_CAPSENSE_MODE_LP_AOS (0x3u) /* The Low Power Always-On-Scanning Mode */ -/* These definitions on CDAC_ FINE below should be removed once Configurator support achieved */ -#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) - #if !defined(CY_CAPSENSE_CSD_CDAC_FINE_EN) - #define CY_CAPSENSE_CSD_CDAC_FINE_EN (CY_CAPSENSE_ENABLE) - #endif -#endif - -#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) - #if !defined(CY_CAPSENSE_CSX_CDAC_FINE_EN) - #define CY_CAPSENSE_CSX_CDAC_FINE_EN (CY_CAPSENSE_ENABLE) - #endif -#endif - -#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN) - #if !defined(CY_CAPSENSE_ISX_CDAC_FINE_EN) - #define CY_CAPSENSE_ISX_CDAC_FINE_EN (CY_CAPSENSE_DISABLE) - #endif -#endif - #endif /* CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP */ #define CY_CAPSENSE_BYTES_IN_16_BITS (2uL) @@ -1087,6 +1082,8 @@ extern "C" { #define CY_CAPSENSE_CONVERSION_HECTO (100u) #define CY_CAPSENSE_CONVERSION_DEKA (10u) #define CY_CAPSENSE_DIVIDER_TWO (2u) +#define CY_CAPSENSE_32_BIT_MASK (0xFFFFFFFFu) +#define CY_CAPSENSE_25_BIT_MASK (0x01FFFFFFu) #define CY_CAPSENSE_16_BIT_MASK (0xFFFFu) #define CY_CAPSENSE_14_BIT_MASK (0x3FFFu) @@ -1099,6 +1096,21 @@ extern "C" { #define CY_CAPSENSE_MDW_ID (CY_CAPSENSE_ID) #define CY_CAPSENSE_SW_STS_BUSY (CY_CAPSENSE_BUSY) +/* CAPSENSE IMO clock values in MHz */ +#define CY_CAPSENSE_IMO_CLK_25_MHZ (25u) +#define CY_CAPSENSE_IMO_CLK_38_MHZ (38u) +#define CY_CAPSENSE_IMO_CLK_46_MHZ (46u) + +#if defined(CY_IP_M0S8MSCV3LP) + /* CAPSENSE MRSS IMO frequency value */ + #if (CY_CAPSENSE_IMO_FREQUENCY == CY_CAPSENSE_IMO_25_MHZ) + #define CY_CAPSENSE_MOD_CLOCK_MHZ CY_CAPSENSE_IMO_CLK_25_MHZ + #elif (CY_CAPSENSE_IMO_FREQUENCY == CY_CAPSENSE_IMO_38_MHZ) + #define CY_CAPSENSE_MOD_CLOCK_MHZ CY_CAPSENSE_IMO_CLK_38_MHZ + #else /* (CY_CAPSENSE_IMO_FREQUENCY == CY_CAPSENSE_IMO_46_MHZ) */ + #define CY_CAPSENSE_MOD_CLOCK_MHZ CY_CAPSENSE_IMO_CLK_46_MHZ + #endif +#endif /* CY_IP_M0S8MSCV3LP */ #if defined(__cplusplus) } diff --git a/cy_capsense_control.c b/cy_capsense_control.c index 89b5571..4c533f0 100644 --- a/cy_capsense_control.c +++ b/cy_capsense_control.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_control.c -* \version 4.0 +* \version 5.0 * * \brief * This file provides the source code to the Control module functions. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 @@ -56,7 +56,7 @@ * * The following tasks are executed: * 1. Capturing not used HW blocks. If any -* of HW block is +* 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. @@ -126,7 +126,7 @@ cy_capsense_status_t Cy_CapSense_Init(cy_stc_capsense_context_t * context) uint32_t wdIndex; cy_stc_capsense_widget_context_t * ptrWdCxt; - #if((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)) + #if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)) const cy_stc_capsense_common_config_t * ptrCommonCfg; #endif @@ -176,11 +176,11 @@ cy_capsense_status_t Cy_CapSense_Init(cy_stc_capsense_context_t * context) ptrWdCxt = context->ptrWdConfig->ptrWdContext; for (wdIndex = 0u; wdIndex < CY_CAPSENSE_TOTAL_WIDGET_COUNT; wdIndex++) { - if(0u == ptrWdCxt->maxRawCount) + if (0u == ptrWdCxt->maxRawCount) { ptrWdCxt->status |= CY_CAPSENSE_WD_MAXCOUNT_CALC_MASK; } - if(0u == ptrWdCxt->maxRawCountRow) + if (0u == ptrWdCxt->maxRawCountRow) { ptrWdCxt->status |= CY_CAPSENSE_WD_MAXCOUNT_ROW_CALC_MASK; } @@ -258,7 +258,7 @@ cy_capsense_status_t Cy_CapSense_Init(cy_stc_capsense_context_t * context) * 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 initialization process. +* 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. @@ -521,8 +521,8 @@ cy_capsense_status_t Cy_CapSense_Initialize(cy_stc_capsense_context_t * context) * * 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 +* 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 @@ -623,16 +623,15 @@ cy_capsense_status_t Cy_CapSense_ProcessAllWidgets(cy_stc_capsense_context_t * c * * 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_SetupWidget() and -* Cy_CapSense_Scan() functions (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. +* 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. * -* A pipeline scan method (i.e. during scanning of a current widget (N), -* perform processing of the previously scanned widget (N-1)) can be +* 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. @@ -1311,8 +1310,8 @@ cy_en_syspm_status_t Cy_CapSense_DeepSleepCallback( * * Increments the timestamp register for the predefined timestamp interval. * -* A timestamp is required for operation of the Gesture and Ballistic multiplier -* feature. Hence this function and timestamp is required only if the Gesture +* A timestamp is required for the operation of the Gesture and Ballistic multiplier +* feature. Hence, this function and timestamp are required only if the Gesture * detection or Ballistic multiplier feature is enabled. * * This function increments the timestamp by the interval specified @@ -1338,7 +1337,7 @@ cy_en_syspm_status_t Cy_CapSense_DeepSleepCallback( * The interval at which this function is called should match with interval * defined in context->ptrCommonContext->timestampInterval register. Either the * register value can be updated to match the callback interval or the callback -* can be made at interval set in the register. +* can be made to be set in the register at an interval. * * If a timestamp is available from another source, the application program * may choose to periodically update the timestamp by using the @@ -1491,6 +1490,7 @@ cy_capsense_status_t Cy_CapSense_Restore_V2(cy_stc_capsense_context_t * context) { /* Reset CSD HW block sequencer state always to handle a corner case when the sequencer is not in the idle state */ context->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK; + (void)context->ptrCommonConfig->ptrCsdBase->INTR_MASK; context->ptrCommonConfig->ptrCsdBase->SEQ_START = CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK; watchdogCounter = Cy_CapSense_WatchdogCyclesNum(watchdogTimeoutUs, context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA, cyclesPerLoop); @@ -1501,7 +1501,7 @@ cy_capsense_status_t Cy_CapSense_Restore_V2(cy_stc_capsense_context_t * context) } while((CY_CSD_BUSY == csdHwStatus) && (0u != watchdogCounter)); - if(CY_CSD_SUCCESS == csdHwStatus) + if (CY_CSD_SUCCESS == csdHwStatus) { #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_USE_CAPTURE) csdHwStatus = Cy_CSD_Capture(ptrCsdBaseAdd, CY_CSD_CAPSENSE_KEY, ptrCsdCxt); diff --git a/cy_capsense_control.h b/cy_capsense_control.h index 809d8f0..194f9e3 100644 --- a/cy_capsense_control.h +++ b/cy_capsense_control.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_control.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes of the Control module. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_csd_v2.c b/cy_capsense_csd_v2.c index 3a851da..2053901 100644 --- a/cy_capsense_csd_v2.c +++ b/cy_capsense_csd_v2.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_csd_v2.c -* \version 4.0 +* \version 5.0 * * \brief * This file defines the data structure global variables and provides @@ -10,7 +10,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 @@ -232,6 +232,7 @@ void Cy_CapSense_CSDInitialize(cy_stc_capsense_context_t * context) context->ptrCommonConfig->ptrCsdBase->IO_SEL = context->ptrInternalContext->csdRegIoSel; #endif context->ptrCommonConfig->ptrCsdBase->INTR_SET = CY_CAPSENSE_DEFAULT_CSD_INTR_SET; + (void)context->ptrCommonConfig->ptrCsdBase->INTR_SET; context->ptrCommonConfig->ptrCsdBase->SW_DSI_SEL = context->ptrInternalContext->csdRegSwDsiSel; context->ptrCommonConfig->ptrCsdBase->ADC_CTL = CY_CAPSENSE_DEFAULT_CSD_ADC_CTL; @@ -1877,6 +1878,7 @@ static void Cy_CapSense_CSDTriggerScan(cy_stc_capsense_context_t * context) /* Enable SAMPLE interrupt */ context->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK; + (void)context->ptrCommonConfig->ptrCsdBase->INTR_MASK; context->ptrCommonConfig->ptrCsdBase->SW_HS_P_SEL = context->ptrInternalContext->csdRegSwHsPSelScan; /* Set scanning configuration for switches */ diff --git a/cy_capsense_csd_v2.h b/cy_capsense_csd_v2.h index 251caa5..3ed771e 100644 --- a/cy_capsense_csd_v2.h +++ b/cy_capsense_csd_v2.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_csd_v2.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes specific to the CSD sensing @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_csx_v2.c b/cy_capsense_csx_v2.c index 9feb596..5b81f35 100644 --- a/cy_capsense_csx_v2.c +++ b/cy_capsense_csx_v2.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_csx_v2.c -* \version 4.0 +* \version 5.0 * * \brief * This file defines the data structure global variables and provides @@ -10,7 +10,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 @@ -104,10 +104,13 @@ void Cy_CapSense_CSXInitialize(cy_stc_capsense_context_t * context) /* Clear all pending interrupts of the CSD HW block */ context->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK; + (void)context->ptrCommonConfig->ptrCsdBase->INTR; /* Enable the End Of Scan interrupt */ context->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_DEFAULT_CSD_INTR_MASK_CFG; + (void)context->ptrCommonConfig->ptrCsdBase->INTR_MASK; context->ptrCommonConfig->ptrCsdBase->INTR_SET = 0u; + (void)context->ptrCommonConfig->ptrCsdBase->INTR_SET; context->ptrCommonConfig->ptrCsdBase->HSCMP = CY_CAPSENSE_DEFAULT_CSD_HSCMP_CFG; context->ptrCommonConfig->ptrCsdBase->AMBUF = context->ptrInternalContext->csxRegAMuxBuf; context->ptrCommonConfig->ptrCsdBase->REFGEN = context->ptrInternalContext->csxRegRefgen; @@ -717,7 +720,7 @@ static void Cy_CapSense_CSXStartSample(cy_stc_capsense_context_t * context) /* Enable interrupt */ context->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK; - + (void)context->ptrCommonConfig->ptrCsdBase->INTR_MASK; if (NULL != context->ptrInternalContext->ptrSSCallback) { context->ptrInternalContext->ptrSSCallback(context->ptrActiveScanSns); @@ -1078,12 +1081,11 @@ void Cy_CapSense_CSXScanISR(void * capsenseContext) uint32_t maxCount = (uint32_t) ptrActive->ptrWdContext->maxRawCount; cxt->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK; - + (void)cxt->ptrCommonConfig->ptrCsdBase->INTR_MASK; /* Clear all pending interrupts of the CSD HW block */ cxt->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK; (void)cxt->ptrCommonConfig->ptrCsdBase->INTR; - tmpRawCount = (uint16_t)(cxt->ptrCommonConfig->ptrCsdBase->RESULT_VAL1 & CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK); diff --git a/cy_capsense_csx_v2.h b/cy_capsense_csx_v2.h index 48e27ae..2d41e97 100644 --- a/cy_capsense_csx_v2.h +++ b/cy_capsense_csx_v2.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_csx_v2.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes specific to the CSX sensing @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_filter.c b/cy_capsense_filter.c index 569e75f..8cdda4b 100644 --- a/cy_capsense_filter.c +++ b/cy_capsense_filter.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_filter.c -* \version 4.0 +* \version 5.0 * * \brief * This file contains the source code of all filters implementation. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_filter.h b/cy_capsense_filter.h index 51247d8..4edd99b 100644 --- a/cy_capsense_filter.h +++ b/cy_capsense_filter.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_filter.h -* \version 4.0 +* \version 5.0 * * \brief * This file contains the definitions for all the filters implementation. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_generator_lp.c b/cy_capsense_generator_lp.c index 62279d8..ce00787 100644 --- a/cy_capsense_generator_lp.c +++ b/cy_capsense_generator_lp.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_generator_lp.c -* \version 4.0 +* \version 5.0 * * \brief * This file contains the source of functions common for register map @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 @@ -428,7 +428,7 @@ cy_capsense_status_t Cy_CapSense_GenerateSensorConfig( ptrSensorCfgLocal[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= (uint32_t)(tempValue & (uint32_t)~(uint32_t)CY_CAPSENSE_CIC_AUTO_MASK) << CY_CAPSENSE_CIC_FIELD_POSITION; #endif - if((CY_CAPSENSE_ENABLE == ptrWdCxt->coarseInitBypassEn) && + if ((CY_CAPSENSE_ENABLE == ptrWdCxt->coarseInitBypassEn) && (scanSlot != ptrWdCfg->firstSlotId)) { ptrSensorCfgLocal[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= MSCLP_SNS_SNS_SCAN_CTL_INIT_BYPASS_Msk; @@ -796,7 +796,7 @@ void Cy_CapSense_GenerateAllSensorConfig( ptrWdCfg = &context->ptrWdConfig[wdIndex]; snsMethod = ptrWdCfg->senseMethod; - if(CY_CAPSENSE_ISX_GROUP == snsMethod) + if (CY_CAPSENSE_ISX_GROUP == snsMethod) { numEltd = (uint32_t)ptrWdCfg->numRows + ptrWdCfg->numCols; eltdPinCfg = ptrWdCfg->ptrEltdConfig; diff --git a/cy_capsense_generator_lp.h b/cy_capsense_generator_lp.h index a6ad1bc..65d031f 100644 --- a/cy_capsense_generator_lp.h +++ b/cy_capsense_generator_lp.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_generator_lp.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes specific to the register @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 @@ -237,6 +237,33 @@ uint32_t Cy_CapSense_AdjustSnsClkDivider( (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC13_FLD_REF_MODE << MSCLP_SW_SEL_CSW_FUNC_REF_MODE_Pos) | \ (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC13_FLD_DDRV_EN << MSCLP_SW_SEL_CSW_FUNC_DDRV_EN_Pos)) +/* CSW14 = ISX RX (two-pin cfg, internal VDDA/2) */ +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW14_CSZ_VALUE \ +((CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_SW_AMUXA << MSCLP_SW_SEL_CSW_FUNC_SW_AMUXA_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_SW_AMUXB << MSCLP_SW_SEL_CSW_FUNC_SW_AMUXB_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_SW_PU << MSCLP_SW_SEL_CSW_FUNC_SW_PU_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_SW_PD << MSCLP_SW_SEL_CSW_FUNC_SW_PD_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_REF_MODE << MSCLP_SW_SEL_CSW_FUNC_REF_MODE_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_DDRV_EN << MSCLP_SW_SEL_CSW_FUNC_DDRV_EN_Pos)) + +/* CSW15 = ISX RX (one-pin cfg, external VDDA/2) */ +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW15_CSZ_VALUE \ +((CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_SW_AMUXA << MSCLP_SW_SEL_CSW_FUNC_SW_AMUXA_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_SW_AMUXB << MSCLP_SW_SEL_CSW_FUNC_SW_AMUXB_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_SW_PU << MSCLP_SW_SEL_CSW_FUNC_SW_PU_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_SW_PD << MSCLP_SW_SEL_CSW_FUNC_SW_PD_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_REF_MODE << MSCLP_SW_SEL_CSW_FUNC_REF_MODE_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_DDRV_EN << MSCLP_SW_SEL_CSW_FUNC_DDRV_EN_Pos)) + +/* CSW16 = ISX RX (one-pin cfg, internal VDDA/2) */ +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW16_CSZ_VALUE \ +((CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_SW_AMUXA << MSCLP_SW_SEL_CSW_FUNC_SW_AMUXA_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_SW_AMUXB << MSCLP_SW_SEL_CSW_FUNC_SW_AMUXB_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_SW_PU << MSCLP_SW_SEL_CSW_FUNC_SW_PU_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_SW_PD << MSCLP_SW_SEL_CSW_FUNC_SW_PD_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_REF_MODE << MSCLP_SW_SEL_CSW_FUNC_REF_MODE_Pos) | \ + (CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_DDRV_EN << MSCLP_SW_SEL_CSW_FUNC_DDRV_EN_Pos)) + /* Indexes of this values must correspond to the CY_CAPSENSE_CTRLMUX_PIN_STATE_... definitions in the common.h */ #define CY_CAPSENSE_PIN_STATES_ARR \ @@ -466,7 +493,7 @@ uint32_t Cy_CapSense_AdjustSnsClkDivider( (CY_CAPSENSE_SM_REG_MODE1_SW_SEL_CMOD2_FLD_REF_MODE << MSCLP_MODE_SW_SEL_CMOD2_REF_MODE_Pos) | \ (CY_CAPSENSE_SM_REG_MODE1_SW_SEL_CMOD2_FLD_DDRV_EN << MSCLP_MODE_SW_SEL_CMOD2_DDRV_EN_Pos)) -/************************* ISX RM register values *****************************/ +/************************* ISX RM register values (external VDDA/2) ***********/ #define CY_CAPSENSE_ISX_RM_SENSE_DUTY_CTL \ ((CY_CAPSENSE_SM_REG_MODE2_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos) | \ @@ -758,7 +785,7 @@ uint32_t Cy_CapSense_AdjustSnsClkDivider( (CY_CAPSENSE_SM_REG_MODE4_SW_SEL_CMOD2_FLD_REF_MODE << MSCLP_MODE_SW_SEL_CMOD2_REF_MODE_Pos) | \ (CY_CAPSENSE_SM_REG_MODE4_SW_SEL_CMOD2_FLD_DDRV_EN << MSCLP_MODE_SW_SEL_CMOD2_DDRV_EN_Pos)) -/****************** ISX RM with CapDAC dithering register values *********************/ +/****************** ISX RM with CapDAC dithering register values (external VDDA/2) */ #define CY_CAPSENSE_ISX_RM_DITHER_SENSE_DUTY_CTL \ ((CY_CAPSENSE_SM_REG_MODE5_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos) | \ @@ -1004,6 +1031,170 @@ uint32_t Cy_CapSense_AdjustSnsClkDivider( (CY_CAPSENSE_SM_REG_MODE11_SW_SEL_CMOD2_FLD_REF_MODE << MSCLP_MODE_SW_SEL_CMOD2_REF_MODE_Pos) | \ (CY_CAPSENSE_SM_REG_MODE11_SW_SEL_CMOD2_FLD_DDRV_EN << MSCLP_MODE_SW_SEL_CMOD2_DDRV_EN_Pos)) +/****************** ISX RM register values (internal VDDA/2) ******************/ + +#define CY_CAPSENSE_ISX_RM_INTERNAL_SENSE_DUTY_CTL \ +((CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH2_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH3_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN << MSCLP_MODE_SENSE_DUTY_CTL_PH_GAP_2CYCLE_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0X_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1X_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHX_GAP_2CYCLE_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_SHIFT_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_MODE_SEL_Pos)) + +#define CY_CAPSENSE_ISX_RM_INTERNAL_SW_SEL_CDAC_FL \ +((CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLTCA << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLTCA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLCB << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLCB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLTV << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLTV_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLTG << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLTG_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLBV << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLBV_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLBG << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLBG_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_ACTIVATION_MODE << MSCLP_MODE_SW_SEL_CDAC_FL_ACTIVATION_MODE_Pos)) + +#define CY_CAPSENSE_ISX_RM_INTERNAL_SW_SEL_TOP \ +((CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_CACB << MSCLP_MODE_SW_SEL_TOP_CACB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_CACC << MSCLP_MODE_SW_SEL_TOP_CACC_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_CBCD << MSCLP_MODE_SW_SEL_TOP_CBCD_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_AYA_CTL << MSCLP_MODE_SW_SEL_TOP_AYA_CTL_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_AYA_EN << MSCLP_MODE_SW_SEL_TOP_AYA_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_AYB_CTL << MSCLP_MODE_SW_SEL_TOP_AYB_CTL_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_AYB_EN << MSCLP_MODE_SW_SEL_TOP_AYB_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_BYB << MSCLP_MODE_SW_SEL_TOP_BYB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_BGRF << MSCLP_MODE_SW_SEL_TOP_BGRF_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_RMF << MSCLP_MODE_SW_SEL_TOP_RMF_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_MBF << MSCLP_MODE_SW_SEL_TOP_MBF_Pos)) + +#define CY_CAPSENSE_ISX_RM_INTERNAL_SW_SEL_COMP \ +((CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPCS1 << MSCLP_MODE_SW_SEL_COMP_CPCS1_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPCS3 << MSCLP_MODE_SW_SEL_COMP_CPCS3_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPMA << MSCLP_MODE_SW_SEL_COMP_CPMA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPCA << MSCLP_MODE_SW_SEL_COMP_CPCA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPCB << MSCLP_MODE_SW_SEL_COMP_CPCB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMCB << MSCLP_MODE_SW_SEL_COMP_CMCB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPF << MSCLP_MODE_SW_SEL_COMP_CPF_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMCS2 << MSCLP_MODE_SW_SEL_COMP_CMCS2_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMCS4 << MSCLP_MODE_SW_SEL_COMP_CMCS4_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMV << MSCLP_MODE_SW_SEL_COMP_CMV_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMG << MSCLP_MODE_SW_SEL_COMP_CMG_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMF << MSCLP_MODE_SW_SEL_COMP_CMF_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_HALF_WAVE_EN << MSCLP_MODE_SW_SEL_COMP_HALF_WAVE_EN_Pos)) + +#define CY_CAPSENSE_ISX_RM_INTERNAL_SW_SEL_SH \ +((CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_SOMB << MSCLP_MODE_SW_SEL_SH_SOMB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_CBSO << MSCLP_MODE_SW_SEL_SH_CBSO_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_SPCS1 << MSCLP_MODE_SW_SEL_SH_SPCS1_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_SPCS3 << MSCLP_MODE_SW_SEL_SH_SPCS3_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_FSP << MSCLP_MODE_SW_SEL_SH_FSP_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_BUF_SEL << MSCLP_MODE_SW_SEL_SH_BUF_SEL_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_BUF_EN << MSCLP_MODE_SW_SEL_SH_BUF_EN_Pos)) + +#define CY_CAPSENSE_ISX_RM_INTERNAL_SW_SEL_CMOD1 \ +((CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_AMUXA << MSCLP_MODE_SW_SEL_CMOD1_SW_AMUXA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_C1CA << MSCLP_MODE_SW_SEL_CMOD1_SW_C1CA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_C1CC << MSCLP_MODE_SW_SEL_CMOD1_SW_C1CC_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_AMUXB << MSCLP_MODE_SW_SEL_CMOD1_SW_AMUXB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_PU << MSCLP_MODE_SW_SEL_CMOD1_SW_PU_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_PD << MSCLP_MODE_SW_SEL_CMOD1_SW_PD_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_REF_MODE << MSCLP_MODE_SW_SEL_CMOD1_REF_MODE_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_DDRV_EN << MSCLP_MODE_SW_SEL_CMOD1_DDRV_EN_Pos)) + +#define CY_CAPSENSE_ISX_RM_INTERNAL_SW_SEL_CMOD2 \ +((CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_AMUXA << MSCLP_MODE_SW_SEL_CMOD2_SW_AMUXA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_AMUXB << MSCLP_MODE_SW_SEL_CMOD2_SW_AMUXB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_C2CB << MSCLP_MODE_SW_SEL_CMOD2_SW_C2CB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_C2CD << MSCLP_MODE_SW_SEL_CMOD2_SW_C2CD_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_PU << MSCLP_MODE_SW_SEL_CMOD2_SW_PU_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_PD << MSCLP_MODE_SW_SEL_CMOD2_SW_PD_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_REF_MODE << MSCLP_MODE_SW_SEL_CMOD2_REF_MODE_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_DDRV_EN << MSCLP_MODE_SW_SEL_CMOD2_DDRV_EN_Pos)) + +/****************** ISX RM with CapDAC dithering register values (internal VDDA/2) */ + +#define CY_CAPSENSE_ISX_RM_DITHER_INTERNAL_SENSE_DUTY_CTL \ +((CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH2_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH3_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN << MSCLP_MODE_SENSE_DUTY_CTL_PH_GAP_2CYCLE_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0X_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1X_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHX_GAP_2CYCLE_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_SHIFT_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL << MSCLP_MODE_SENSE_DUTY_CTL_PHASE_MODE_SEL_Pos)) + +#define CY_CAPSENSE_ISX_RM_DITHER_INTERNAL_SW_SEL_CDAC_FL \ +((CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLTCA << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLTCA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLCB << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLCB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLTV << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLTV_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLTG << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLTG_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLBV << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLBV_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLBG << MSCLP_MODE_SW_SEL_CDAC_FL_SW_FLBG_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_ACTIVATION_MODE << MSCLP_MODE_SW_SEL_CDAC_FL_ACTIVATION_MODE_Pos)) + +#define CY_CAPSENSE_ISX_RM_DITHER_INTERNAL_SW_SEL_TOP \ +((CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_CACB << MSCLP_MODE_SW_SEL_TOP_CACB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_CACC << MSCLP_MODE_SW_SEL_TOP_CACC_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_CBCD << MSCLP_MODE_SW_SEL_TOP_CBCD_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_AYA_CTL << MSCLP_MODE_SW_SEL_TOP_AYA_CTL_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_AYA_EN << MSCLP_MODE_SW_SEL_TOP_AYA_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_AYB_CTL << MSCLP_MODE_SW_SEL_TOP_AYB_CTL_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_AYB_EN << MSCLP_MODE_SW_SEL_TOP_AYB_EN_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_BYB << MSCLP_MODE_SW_SEL_TOP_BYB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_BGRF << MSCLP_MODE_SW_SEL_TOP_BGRF_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_RMF << MSCLP_MODE_SW_SEL_TOP_RMF_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_MBF << MSCLP_MODE_SW_SEL_TOP_MBF_Pos)) + +#define CY_CAPSENSE_ISX_RM_DITHER_INTERNAL_SW_SEL_COMP \ +((CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPCS1 << MSCLP_MODE_SW_SEL_COMP_CPCS1_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPCS3 << MSCLP_MODE_SW_SEL_COMP_CPCS3_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPMA << MSCLP_MODE_SW_SEL_COMP_CPMA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPCA << MSCLP_MODE_SW_SEL_COMP_CPCA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPCB << MSCLP_MODE_SW_SEL_COMP_CPCB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMCB << MSCLP_MODE_SW_SEL_COMP_CMCB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPF << MSCLP_MODE_SW_SEL_COMP_CPF_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMCS2 << MSCLP_MODE_SW_SEL_COMP_CMCS2_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMCS4 << MSCLP_MODE_SW_SEL_COMP_CMCS4_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMV << MSCLP_MODE_SW_SEL_COMP_CMV_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMG << MSCLP_MODE_SW_SEL_COMP_CMG_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMF << MSCLP_MODE_SW_SEL_COMP_CMF_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_HALF_WAVE_EN << MSCLP_MODE_SW_SEL_COMP_HALF_WAVE_EN_Pos)) + +#define CY_CAPSENSE_ISX_RM_DITHER_INTERNAL_SW_SEL_SH \ +((CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_SOMB << MSCLP_MODE_SW_SEL_SH_SOMB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_CBSO << MSCLP_MODE_SW_SEL_SH_CBSO_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_SPCS1 << MSCLP_MODE_SW_SEL_SH_SPCS1_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_SPCS3 << MSCLP_MODE_SW_SEL_SH_SPCS3_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_FSP << MSCLP_MODE_SW_SEL_SH_FSP_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_BUF_SEL << MSCLP_MODE_SW_SEL_SH_BUF_SEL_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_BUF_EN << MSCLP_MODE_SW_SEL_SH_BUF_EN_Pos)) + +#define CY_CAPSENSE_ISX_RM_DITHER_INTERNAL_SW_SEL_CMOD1 \ +((CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_AMUXA << MSCLP_MODE_SW_SEL_CMOD1_SW_AMUXA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_C1CA << MSCLP_MODE_SW_SEL_CMOD1_SW_C1CA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_C1CC << MSCLP_MODE_SW_SEL_CMOD1_SW_C1CC_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_AMUXB << MSCLP_MODE_SW_SEL_CMOD1_SW_AMUXB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_PU << MSCLP_MODE_SW_SEL_CMOD1_SW_PU_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_PD << MSCLP_MODE_SW_SEL_CMOD1_SW_PD_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_REF_MODE << MSCLP_MODE_SW_SEL_CMOD1_REF_MODE_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_DDRV_EN << MSCLP_MODE_SW_SEL_CMOD1_DDRV_EN_Pos)) + +#define CY_CAPSENSE_ISX_RM_DITHER_INTERNAL_SW_SEL_CMOD2 \ +((CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_AMUXA << MSCLP_MODE_SW_SEL_CMOD2_SW_AMUXA_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_AMUXB << MSCLP_MODE_SW_SEL_CMOD2_SW_AMUXB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_C2CB << MSCLP_MODE_SW_SEL_CMOD2_SW_C2CB_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_C2CD << MSCLP_MODE_SW_SEL_CMOD2_SW_C2CD_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_PU << MSCLP_MODE_SW_SEL_CMOD2_SW_PU_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_PD << MSCLP_MODE_SW_SEL_CMOD2_SW_PD_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_REF_MODE << MSCLP_MODE_SW_SEL_CMOD2_REF_MODE_Pos) | \ + (CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_DDRV_EN << MSCLP_MODE_SW_SEL_CMOD2_DDRV_EN_Pos)) + #define CY_CAPSENSE_CSD_RM_MODE \ { \ diff --git a/cy_capsense_generator_v3.c b/cy_capsense_generator_v3.c index 7238d7b..45026b9 100644 --- a/cy_capsense_generator_v3.c +++ b/cy_capsense_generator_v3.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_generator_v3.c -* \version 4.0 +* \version 5.0 * * \brief * This file contains the source of functions common for register map @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 @@ -314,6 +314,7 @@ cy_capsense_status_t Cy_CapSense_GenerateBaseConfig( #else ptrBaseCfg->intrMask |= MSC_INTR_MASK_SCAN_Msk; #endif /* (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE) */ + (void)ptrBaseCfg->intrMask; /* Shielding is available in CSD only */ #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) &&\ diff --git a/cy_capsense_generator_v3.h b/cy_capsense_generator_v3.h index 5ab90a6..f18c83d 100644 --- a/cy_capsense_generator_v3.h +++ b/cy_capsense_generator_v3.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_generator_v3.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes specific to the register @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 diff --git a/cy_capsense_gesture_lib.h b/cy_capsense_gesture_lib.h index 625fe21..08aa1e0 100644 --- a/cy_capsense_gesture_lib.h +++ b/cy_capsense_gesture_lib.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_gesture_lib.h -* \version 4.0 +* \version 5.0 * * \brief * Provides the gesture interface. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_lib.h b/cy_capsense_lib.h index da1e9d2..e531474 100644 --- a/cy_capsense_lib.h +++ b/cy_capsense_lib.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_lib.h -* \version 4.0 +* \version 5.0 * * \brief * The file contains application programming interface to the CAPSENSE™ library. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 @@ -107,7 +107,8 @@ typedef struct * ReservedReservedMSB = Age of touch; LSB = Z-value represents a touch strength (summ of sensor diff counts divided by 16 -* that form 3x3 matrix with a local maximum in the center)
id
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
CAPSENSENumber of positions
Sensing methodWidget type012  3  Multiple
CSDButton No touch 
 detected 
Number of active sensors
(up to number of sensors)
N/A
Matrix buttonSingle touch
detected
N/AN/AMultiple touches
detected
Linear sliderSingle touch
detected
N/AN/AN/A
Radial sliderSingle touch
detected
N/AN/AN/A
TouchpadSingle touch
detected
Two touches
detected
N/AMultiple touches
detected
ProximityNumber of active sensors
(up to number of sensors)
N/A
CSXButtonNumber of active sensors
(up to number of sensors)
N/A
Matrix buttonNumber of active sensors
(up to number of sensors)
N/A
Linear sliderSingle touch
detected
N/AN/AN/A
TouchpadNumber of touches
(up to 3)
N/A
*/ } cy_stc_capsense_touch_t; diff --git a/cy_capsense_processing.c b/cy_capsense_processing.c index aa017ad..4f6c477 100644 --- a/cy_capsense_processing.c +++ b/cy_capsense_processing.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_processing.c -* \version 4.0 +* \version 5.0 * * \brief * This file provides the source code for the Data Processing module functions. @@ -11,7 +11,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_processing.h b/cy_capsense_processing.h index 99617bd..97f4c7e 100644 --- a/cy_capsense_processing.h +++ b/cy_capsense_processing.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_processing.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes for the Data Processing module. @@ -11,7 +11,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_selftest.c b/cy_capsense_selftest.c index db17830..ef87d49 100644 --- a/cy_capsense_selftest.c +++ b/cy_capsense_selftest.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_selftest.c -* \version 4.0 +* \version 5.0 * * \brief * This file provides the source code to the Built-in Self-test (BIST) @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2021-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying @@ -89,7 +89,7 @@ * possible to launch the function with any combination of the available tests. * - CY_CAPSENSE_BIST_CRC_WDGT_MASK - Verifies the RAM widget structure CRC * for all the widgets. -* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK - Checks all the sensors for a short +* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK - Checks all the sensor pins for a short * to GND / VDD / other sensors. * - CY_CAPSENSE_BIST_SNS_CAP_MASK - Measures all the sensors capacitance. * - CY_CAPSENSE_BIST_ELTD_CAP_MASK - Measures all the electrodes capacitance @@ -830,9 +830,9 @@ cy_en_capsense_bist_status_t Cy_CapSense_MeasureVdda( * is defined by the RefCDAC tolerance. * * By default, all CAPSENSE™ sensors (electrodes) that are not being -* measured are set to the GND state for CSD measured electrodes (sensors) and -* to the HIGH-Z state for CSX measured electrodes (Rx and Tx). -* Shield electrodes are also configured to the GND state. +* are set to a corresponding Inactive sensor connection parameter matching +* configuration used for a specified sensing method. Shield electrodes are +* also matching the CSD Inactive sensor connection parameter. * The inactive state can be changed in run-time by using * the Cy_CapSense_SetInactiveElectrodeState() function. * @@ -959,17 +959,18 @@ cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSensorElectrode( * external series resistance). The measurement accuracy is about 30%. * * By default, all CAPSENSE™ sensors (electrodes) that are not being -* measured are set to the GND state for CSD measured electrodes (sensors) and -* to the HIGH-Z state for CSX measured electrodes (Rx and Tx). -* Shield electrodes are also configured to the GND state. +* are set to a corresponding Inactive sensor connection parameter matching +* configuration used for a specified sensing method. Shield electrodes are +* also matching the CSD Inactive sensor connection parameter. * The inactive state can be changed in run-time by using * the Cy_CapSense_SetInactiveElectrodeState() function. * * By default, the both Cmod1 and Cmod2 capacitors are used for the measurement. * * Measured capacitance values (Cp for CSD widgets and Cm for CSX widgets) -* are stored in the .snsCap field of the \ref cy_stc_capsense_sensor_context_t -* structure. +* are stored in the ptrSnsCapacitance sensor capacitance array field +* and in the ptrEltdCapacitance electrode capacitance array +* of the \ref cy_stc_capsense_widget_config_t structure. * * The all sensor measurement can be done on all the sensors using * the Cy_CapSense_RunSelfTest() function along with diff --git a/cy_capsense_selftest.h b/cy_capsense_selftest.h index ef16b0e..e96d0a8 100644 --- a/cy_capsense_selftest.h +++ b/cy_capsense_selftest.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_selftest.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes of the BIST module. * ******************************************************************************** * \copyright -* Copyright 2021-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying diff --git a/cy_capsense_selftest_lp.c b/cy_capsense_selftest_lp.c index c866e2a..f2ec0d5 100644 --- a/cy_capsense_selftest_lp.c +++ b/cy_capsense_selftest_lp.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_selftest_lp.c -* \version 4.0 +* \version 5.0 * * \brief * This file provides the source code to the Built-in Self-test (BIST) @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2021-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying @@ -67,6 +67,7 @@ #define CY_CAPSENSE_BIST_CP_MAX_VALUE (200000u) #define CY_CAPSENSE_BIST_CSH_MAX_VALUE (1600000u) #define CY_CAPSENSE_BIST_PROMILLE_FACTOR (1000u) +#define CY_CAPSENSE_BIST_ELTD_CAP_NUM_EPI_CYCLES (2u) /******************************************************************************* * Macros for the external capacitor capacitance measurement test @@ -300,7 +301,7 @@ * possible to launch the function with any combination of the available tests. * - CY_CAPSENSE_BIST_CRC_WDGT_MASK - Verifies the RAM widget structure CRC * for all the widgets. -* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK - Checks all the sensors for a short +* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK - Checks all the sensor pins for a short * to GND / VDD / other sensors. * - CY_CAPSENSE_BIST_SNS_CAP_MASK - Measures all the sensors capacitance. * - CY_CAPSENSE_BIST_ELTD_CAP_MASK - Measures all the electrodes capacitance. @@ -1691,9 +1692,9 @@ void Cy_CapSense_BistSetAllCmodPinsState( * is defined by the RefCDAC tolerance. * * By default, all CAPSENSE™ sensors (electrodes) that are not being -* measured are set to the GND state for CSD measured electrodes (sensors) and -* to the HIGH-Z state for CSX measured electrodes (Rx and Tx). -* Shield electrodes are also configured to the GND state. +* are set to a corresponding Inactive sensor connection parameter matching +* configuration used for a specified sensing method. Shield electrodes are +* also matching the CSD Inactive sensor connection parameter. * The inactive state can be changed in run-time by using * the Cy_CapSense_SetInactiveElectrodeState() function. * @@ -2036,17 +2037,18 @@ static cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceAllElectrodes( * external series resistance). The measurement accuracy is about 30%. * * By default, all CAPSENSE™ sensors (electrodes) that are not being -* measured are set to the GND state for CSD measured electrodes (sensors) and -* to the HIGH-Z state for CSX measured electrodes (Rx and Tx). -* Shield electrodes are also configured to the GND state. +* are set to a corresponding Inactive sensor connection parameter matching +* configuration used for a specified sensing method. Shield electrodes are +* also matching the CSD Inactive sensor connection parameter. * The inactive state can be changed in run-time by using * the Cy_CapSense_SetInactiveElectrodeState() function. * * By default, the both Cmod1 and Cmod2 capacitors are used for the measurement. * * Measured capacitance values (Cp for CSD widgets and Cm for CSX widgets) -* are stored in the .snsCap field of the \ref cy_stc_capsense_sensor_context_t -* structure. +* are stored in the ptrSnsCapacitance sensor capacitance array field +* and in the ptrEltdCapacitance electrode capacitance array +* of the \ref cy_stc_capsense_widget_config_t structure. * * The all sensor measurement can be done on all the sensors using * the Cy_CapSense_RunSelfTest() function along with @@ -2146,17 +2148,18 @@ cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSlotSensors_V3Lp( * external series resistance). The measurement accuracy is about 30%. * * By default, all CAPSENSE™ sensors (electrodes) that are not being -* measured are set to the GND state for CSD measured electrodes (sensors) and -* to the HIGH-Z state for CSX measured electrodes (Rx and Tx). -* Shield electrodes are also configured to the GND state. +* are set to a corresponding Inactive sensor connection parameter matching +* configuration used for a specified sensing method. Shield electrodes are +* also matching the CSD Inactive sensor connection parameter. * The inactive state can be changed in run-time by using * the Cy_CapSense_SetInactiveElectrodeState() function. * * By default, the both Cmod1 and Cmod2 capacitors are used for the measurement. * * Measured capacitance values (Cp for CSD widgets and Cm for CSX widgets) -* are stored in the .snsCap field of the \ref cy_stc_capsense_sensor_context_t -* structure. +* are stored in the ptrSnsCapacitance sensor capacitance array field +* and in the ptrEltdCapacitance electrode capacitance array +* of the \ref cy_stc_capsense_widget_config_t structure. * * The all sensor measurement can be done on all the sensors using * the Cy_CapSense_RunSelfTest() function along with @@ -2166,8 +2169,8 @@ cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSlotSensors_V3Lp( * by another scan. * * \note -* This function is available for the fifth-generation and fifth-generation -* low power CAPSENSE™. +* This function is available only for the fifth-generation low power +* CAPSENSE™. * * \param slotId * Specifies the ID number of the slot to measure sensor capacitance. @@ -2393,7 +2396,7 @@ static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensor( watchdog = Cy_CapSense_WaitEndOfCpuScan(watchdog, context); /* Check if the watchdog timeout happened */ - if(0u == watchdog) + if (0u == watchdog) { result = CY_CAPSENSE_BIST_TIMEOUT_E; } @@ -2544,7 +2547,7 @@ static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSlot( watchdog = Cy_CapSense_WaitEndOfCpuScan(watchdog, context); /* Check if the watchdog timeout happened */ - if(0u == watchdog) + if (0u == watchdog) { result = CY_CAPSENSE_BIST_TIMEOUT_E; } @@ -2721,8 +2724,6 @@ static void Cy_CapSense_BistGenerateBaseConfig( context->ptrCommonConfig->ptrChConfig->ptrHwContext); Cy_CapSense_SetupCpuOperatingMode(context); - - Cy_SysLib_DelayUs(CY_CAPSENSE_ANALOG_SETTLING_TIME_US); } #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) || (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN) || \ ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))) */ @@ -4075,8 +4076,7 @@ void Cy_CapSense_BistMeasureCapacitanceSensorInit( } /* NumSubConv */ ptrBistCxt->eltdCapSubConvNum = (uint16_t)CY_CAPSENSE_BIST_ELTD_CAP_SUBCONV_NUM_DEFAULT; - /* NumEpiCycles and NumProWaitCycles depends on SnsClk divider */ - ptrBistCxt->eltdCapNumEpiCycles = ptrBistCxt->eltdCapSnsClk / CY_CAPSENSE_DIVIDER_TWO; + ptrBistCxt->eltdCapNumEpiCycles = CY_CAPSENSE_BIST_ELTD_CAP_NUM_EPI_CYCLES; ptrBistCxt->eltdCapNumFineInitWaitCycles = ptrBistCxt->eltdCapNumEpiCycles; } #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN) */ diff --git a/cy_capsense_selftest_lp.h b/cy_capsense_selftest_lp.h index a963d91..b445255 100644 --- a/cy_capsense_selftest_lp.h +++ b/cy_capsense_selftest_lp.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_selftest_lp.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes of the BIST module. * ******************************************************************************** * \copyright -* Copyright 2021-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying @@ -32,24 +32,6 @@ extern "C" { #endif -/******************************************************************************* -* CAPSENSE™ BIST Enumerated Types -*******************************************************************************/ - -/******************************************************************************/ -/** \addtogroup group_capsense_enums *//** \{ */ -/******************************************************************************/ - -/** Defines IDs of the external capacitors */ -typedef enum -{ - CY_CAPSENSE_BIST_CMOD01_ID_E = 0x00u, /**< ID for the MSC0 Cmod1 external capacitor */ - CY_CAPSENSE_BIST_CMOD02_ID_E = 0x01u, /**< ID for the MSC0 Cmod2 external capacitor */ -} cy_en_capsense_bist_external_cap_id_t; - -/** \} */ - - /******************************************************************************* * Function Prototypes *******************************************************************************/ diff --git a/cy_capsense_selftest_v2.c b/cy_capsense_selftest_v2.c index 6e6fb19..1415662 100644 --- a/cy_capsense_selftest_v2.c +++ b/cy_capsense_selftest_v2.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_selftest_v2.c -* \version 4.0 +* \version 5.0 * * \brief * This file provides the source code to the Built-in Self-test (BIST) @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2019-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2019-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 @@ -368,7 +368,7 @@ * possible to launch the function with any combination of the available tests. * - CY_CAPSENSE_BIST_CRC_WDGT_MASK - Verifies the RAM widget structure CRC * for all the widgets. -* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK - Checks all the sensors for a short +* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK - Checks all the sensor pins for a short * to GND / VDD / other sensors. * - CY_CAPSENSE_BIST_SNS_CAP_MASK - Measures all the sensors capacitance. * - CY_CAPSENSE_BIST_SHIELD_CAP_MASK - Measures the shield capacitance. @@ -1551,9 +1551,9 @@ static void Cy_CapSense_SetPinPc( * external series resistance). The measurement accuracy is about 15%. * * By default, all CAPSENSE™ sensors (electrodes) that are not being -* measured are set to the GND state for CSD measured electrodes (sensors) and -* to the HIGH-Z state for CSX measured electrodes (Rx and Tx). -* Shield electrodes are also configured to the GND state. +* are set to a corresponding Inactive sensor connection parameter matching +* configuration used for a specified sensing method. Shield electrodes are +* also matching the CSD Inactive sensor connection parameter. * The inactive state can be changed in run-time by using * the Cy_CapSense_SetInactiveElectrodeState() function. * @@ -2477,6 +2477,7 @@ static void Cy_CapSense_BistMeasureCapacitanceSensorEnable( } #endif ptrCsdHwBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK; + (void)ptrCsdHwBase->INTR_MASK; ptrCsdHwBase->AMBUF = context->ptrBistContext->regAmbuf; ptrCsdHwBase->ADC_CTL = 0u; ptrCsdHwBase->SEQ_TIME = 0u; @@ -2553,6 +2554,7 @@ static void Cy_CapSense_BistMeasureCapacitanceSensorShieldEnable( } #endif ptrCsdHwBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK; + (void)ptrCsdHwBase->INTR_MASK; ptrCsdHwBase->AMBUF = context->ptrBistContext->regAmbufShield; ptrCsdHwBase->ADC_CTL = 0u; ptrCsdHwBase->SEQ_TIME = 0u; diff --git a/cy_capsense_selftest_v2.h b/cy_capsense_selftest_v2.h index 02b8814..1486f6b 100644 --- a/cy_capsense_selftest_v2.h +++ b/cy_capsense_selftest_v2.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_selftest_v2.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes of the BIST module. * ******************************************************************************** * \copyright -* Copyright 2019-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2019-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 @@ -37,26 +37,6 @@ extern "C" { #define CY_CAPSENSE_BIST_CAP_SETTLING_TIME_DEFAULT (2u) -/******************************************************************************* -* CAPSENSE™ BIST Enumerated Types -*******************************************************************************/ - -/******************************************************************************/ -/** \addtogroup group_capsense_enums *//** \{ */ -/******************************************************************************/ - -/** Defines IDs of the external capacitors */ -typedef enum -{ - CY_CAPSENSE_BIST_CMOD_ID_E = 0x00u, /**< ID for Cmod external capacitor */ - CY_CAPSENSE_BIST_CINTA_ID_E = 0x01u, /**< ID for CintA external capacitor */ - CY_CAPSENSE_BIST_CINTB_ID_E = 0x02u, /**< ID for CintB external capacitor */ - CY_CAPSENSE_BIST_CSH_ID_E = 0x03u, /**< ID for Csh external capacitor */ -} cy_en_capsense_bist_external_cap_id_t; - -/** \} */ - - /******************************************************************************* * Function Prototypes *******************************************************************************/ diff --git a/cy_capsense_selftest_v3.c b/cy_capsense_selftest_v3.c index 22c907a..2a7fa3d 100644 --- a/cy_capsense_selftest_v3.c +++ b/cy_capsense_selftest_v3.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_selftest_v3.c -* \version 4.0 +* \version 5.0 * * \brief * This file provides the source code to the Built-in Self-test (BIST) @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2021-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying @@ -498,7 +498,7 @@ * possible to launch the function with any combination of the available tests. * - CY_CAPSENSE_BIST_CRC_WDGT_MASK - Verifies the RAM widget structure CRC * for all the widgets. -* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK - Checks all the sensors for a short +* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK - Checks all the sensor pins for a short * to GND / VDD / other sensors. * - CY_CAPSENSE_BIST_SNS_CAP_MASK - Measures all the sensors capacitance. * - CY_CAPSENSE_BIST_ELTD_CAP_MASK - Measures all the electrodes capacitance. @@ -1852,9 +1852,9 @@ void Cy_CapSense_BistSetAllCmodPinsState( * is defined by the RefCDAC tolerance. * * By default, all CAPSENSE™ sensors (electrodes) that are not being -* measured are set to the GND state for CSD measured electrodes (sensors) and -* to the HIGH-Z state for CSX measured electrodes (Rx and Tx). -* Shield electrodes are also configured to the GND state. +* are set to a corresponding Inactive sensor connection parameter matching +* configuration used for a specified sensing method. Shield electrodes are +* also matching the CSD Inactive sensor connection parameter. * The inactive state can be changed in run-time by using * the Cy_CapSense_SetInactiveElectrodeState() function. * @@ -2148,17 +2148,18 @@ static cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceAllElectrodes( * external series resistance). The measurement accuracy is about 30%. * * By default, all CAPSENSE™ sensors (electrodes) that are not being -* measured are set to the GND state for CSD measured electrodes (sensors) and -* to the HIGH-Z state for CSX measured electrodes (Rx and Tx). -* Shield electrodes are also configured to the GND state. +* are set to a corresponding Inactive sensor connection parameter matching +* configuration used for a specified sensing method. Shield electrodes are +* also matching the CSD Inactive sensor connection parameter. * The inactive state can be changed in run-time by using * the Cy_CapSense_SetInactiveElectrodeState() function. * * By default, the both Cmod1 and Cmod2 capacitors are used for the measurement. * * Measured capacitance values (Cp for CSD widgets and Cm for CSX widgets) -* are stored in the .snsCap field of the \ref cy_stc_capsense_sensor_context_t -* structure. +* are stored in the ptrSnsCapacitance sensor capacitance array field +* and in the ptrEltdCapacitance electrode capacitance array +* of the \ref cy_stc_capsense_widget_config_t structure. * * The all sensor measurement can be done on all the sensors using * the Cy_CapSense_RunSelfTest() function along with @@ -2408,9 +2409,7 @@ static cy_capsense_status_t Cy_CapSense_BistMeasureCapacitanceSensorEnable( { capStatus = CY_CAPSENSE_STATUS_HW_BUSY; break; - } - /* The time interval is required for settling analog part of the HW block. */ - Cy_SysLib_DelayUs(CY_CAPSENSE_ANALOG_SETTLING_TIME_US); + } Cy_CapSense_BistGenerateBaseConfig(curChIndex, context); } /* Check if all MSC channel is not busy and clear all pending interrupts */ diff --git a/cy_capsense_selftest_v3.h b/cy_capsense_selftest_v3.h index 45d8ba8..3da1a35 100644 --- a/cy_capsense_selftest_v3.h +++ b/cy_capsense_selftest_v3.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_selftest_v3.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes of the BIST module. * ******************************************************************************** * \copyright -* Copyright 2021-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying diff --git a/cy_capsense_sensing.c b/cy_capsense_sensing.c index e40807b..596b334 100644 --- a/cy_capsense_sensing.c +++ b/cy_capsense_sensing.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_sensing.c -* \version 4.0 +* \version 5.0 * * \brief * This file consists of common parts for different supported platforms @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2021-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying @@ -37,8 +37,9 @@ * Function Name: Cy_CapSense_ScanWidget ****************************************************************************//** * -* Initiates the scanning of all sensors in the widget. - +* Performs the initialization required to scan the specified widget and triggers +* the scanning of all sensors in the widget. +* * If the middleware is busy, do not initiate a new scan or set up widgets. * Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. * Use the Cy_CapSense_MwState() function to verify if MW executes any firmware @@ -49,6 +50,12 @@ * the Cy_CapSense_ScanLpWidget() function. * * \note +* For the fourth-generation this function is also available and it should be used +* instead of Cy_CapSense_SetupWidget() and Cy_CapSense_Scan() functions. +* The specified widget will remain set up after scanning completes. +* If this function is called multiple times on the same widget, the set up +* is only done the first time but a scan will be done each time the function +* is called. * For the fifth-generation CAPSENSE™ this function is available in * single-channel solution only. It is recommended to use * the Cy_CapSense_ScanSlots() function instead for compatibility with @@ -151,7 +158,7 @@ cy_capsense_status_t Cy_CapSense_ScanSensor( * Configurator, the scanning process will be triggered immediately. * If the "Enable external frame start" option is enabled in the CAPSENSE™ * Configurator, the scanning process will be triggered by the first external -* synchronization signal after call of the function. +* synchronization signal after a function call. * The number of slots in frame in this case should not exceed the maximum * possible slot number to fit into the internal buffer of the CAPSENSE™ * hardware block. @@ -160,7 +167,7 @@ cy_capsense_status_t Cy_CapSense_ScanSensor( * * - the interval between the return of the function and the rising edge * of an external synchronization signal must not be less than 2 ILO cycles; * * - the pulse duration of an external synchronization signal -* (i.e. signal is in High level) must not be less than 2 ILO cycles and more +* (if the signal is in High level) must not be less than 2 ILO cycles and more * than the full scanning process duration. The full scanning process * duration is the time between the rising edge of the external * synchronization pulse and clearing of BUSY flag. The Cy_CapSense_IsBusy() @@ -173,7 +180,7 @@ cy_capsense_status_t Cy_CapSense_ScanSensor( * To decrease the start scan time when it is intended to scan the same frame, * i.e. startSlotId and numberSlots parameters are the same, then the scan * is performed without the MSC HW block reconfiguration. -* The number of slots in frame in this case should not exceed the maximum +* In this case, the number of slots in the frame shall not exceed the maximum * possible slot number to fit into the internal buffer of the CAPSENSE™ * hardware block. * @@ -182,7 +189,7 @@ cy_capsense_status_t Cy_CapSense_ScanSensor( * the first slot for all channels and then exits. Scans for the remaining slots * in the Interrupt-driven scan mode are initiated in the interrupt service * routine (part of middleware) triggered at the end -* of each scan completion for each channel. If the syncMode field in the +* of each scan completed for each channel. If the syncMode field in the * cy_stc_capsense_common_config_t structure is set to CY_CAPSENSE_SYNC_MODE_OFF, * then the next slot scan for the channel with the fired interrupt, * will start regardless of the another channel readiness for the next scan. @@ -193,7 +200,7 @@ cy_capsense_status_t Cy_CapSense_ScanSensor( * for the next scan (the next scan configuration is loaded into the channel MSC HW block). * Scans for the remaining slots in CS-DMA scan mode are initiated * by DMAC triggered at the end -* of each scan completion for each channel. The channel scan synchronization is +* of each scan completed for each channel. The channel scan synchronization is * performed as in Interrupt-driven scan mode. After all slots are scanned, * the FRAME interrupt is fired and the interrupt service routine (part of middleware) * updates the busy status. The transition into system DEEP SLEEP mode is allowed @@ -259,8 +266,8 @@ cy_capsense_status_t Cy_CapSense_ScanAllSlots( * Configurator, the scanning process will be triggered immediately. * If the "Enable external frame start" option is enabled in the CAPSENSE™ * Configurator, the scanning process will be triggered by the first external -* synchronization signal after call of the function. -* The number of slots in frame in this case should not exceed the maximum +* synchronization signal after a function call. +* In this case, the number of slots in the frame shall not exceed the maximum * possible slot number to fit into the internal buffer of the CAPSENSE™ * hardware block. * The External synchronization signal parameters should meet the following @@ -268,7 +275,7 @@ cy_capsense_status_t Cy_CapSense_ScanAllSlots( * * - the interval between the return of the function and the rising edge * of an external synchronization signal must not be less than 2 ILO cycles; * * - the pulse duration of an external synchronization signal -* (i.e. signal is in High level) must not be less than 2 ILO cycles and more +* (if the signal is in High level) must not be less than 2 ILO cycles and more * than the full scanning process duration. The full scanning process * duration is the time between the rising edge of the external * synchronization pulse and clearing of BUSY flag. The Cy_CapSense_IsBusy() @@ -276,12 +283,12 @@ cy_capsense_status_t Cy_CapSense_ScanAllSlots( * * - the interval between sub-sequent pulses should not be less than full * scanning process duration. * Disregarding the "Enable external frame start" option, the transition into -* system DEEP SLEEP mode is allowed after the scan process is started +* a system DEEP SLEEP mode is allowed after the scan process is started * by the function. * To decrease the start scan time when it is intended to scan the same frame, * i.e. startSlotId and numberSlots parameters are the same, then the scan * is performed without the MSC HW block reconfiguration. -* The number of slots in frame in this case should not exceed the maximum +* In this case, the number of slots in the frame shall not exceed the maximum * possible slot number to fit into the internal buffer of the CAPSENSE™ * hardware block. * @@ -290,7 +297,7 @@ cy_capsense_status_t Cy_CapSense_ScanAllSlots( * the first slot for all channels and then exits. Scans for the remaining slots * in the Interrupt-driven scan mode are initiated in the interrupt service * routine (part of middleware) triggered at the end -* of each scan completion for each channel. If the syncMode field in the +* of each scan completed for each channel. If the syncMode field in the * cy_stc_capsense_common_config_t structure is set to CY_CAPSENSE_SYNC_MODE_OFF, * then the next slot scan for the channel with the fired interrupt, * will start regardless of the another channel readiness for the next scan. @@ -304,7 +311,7 @@ cy_capsense_status_t Cy_CapSense_ScanAllSlots( * of each scan completion for each channel. The channel scan synchronization is * performed as in Interrupt-driven scan mode. After all specified slots are * scanned, the FRAME interrupt is fired and the interrupt service routine -* (part of middleware) updates the busy status. The transition into system +* (part of middleware) updates the busy status. The transition into a system * DEEP SLEEP mode is allowed only when all specified scans are finished. * To decrease the start scan time when it is intended to scan the same slot, * i.e. the startSlotId parameter is the same and numberSlots = 1u, then the scan @@ -356,7 +363,7 @@ cy_capsense_status_t Cy_CapSense_ScanSlots( * * Initiates scanning of all enabled widgets (and sensors) in the project. * For fifth-generation low power CAPSENSE™ the function initiates only -* Active widget scans. To initiate Low Power widget scan use +* Active widget scans. The initiation of a Low Power widget scan uses * the Cy_CapSense_ScanAllLpWidgets() function. * * This function initiates a scan only for the first sensor in the first widget @@ -377,6 +384,10 @@ cy_capsense_status_t Cy_CapSense_ScanSlots( * The application program should wait until the current frame scan is finished prior * to start a next scan by using the function. * +* To get widget enable/working status the Cy_CapSense_IsWidgetEnabled() and +* Cy_CapSense_IsSlotEnabled() functions should be used. This status can be configured +* with Cy_CapSense_SetWidgetStatus() function. +* * \note * For the fifth-generation CAPSENSE™ and fifth-generation low power * CAPSENSE™ it is recommended to use the Cy_CapSense_ScanAllSlots() @@ -740,9 +751,11 @@ cy_capsense_status_t Cy_CapSense_CalibrateAllWidgets( * - 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_CALIBRATION_REF_CHECK_FAIL - The reference/fine CapDAC +* calibration stage is failed as the raw count +* minimum across widget is out of range. +* - CY_CAPSENSE_STATUS_CALIBRATION_CHECK_FAIL - The resulting rawcounts across +* all sensors in widget are out of defined range. * *******************************************************************************/ cy_capsense_status_t Cy_CapSense_CalibrateAllSlots(cy_stc_capsense_context_t * context) @@ -1585,56 +1598,68 @@ cy_capsense_status_t Cy_CapSense_InitializeMaxRaw( uint32_t tmpVal; cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_SUCCESS; const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId]; - #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) uint32_t scanSlotId; const cy_stc_capsense_scan_slot_t * ptrScanSlots; #endif + uint32_t tempRaw = 0u; - if(0u != (CY_CAPSENSE_WD_MAXCOUNT_CALC_MASK & ptrWdCfg->ptrWdContext->status)) + if (0u != (CY_CAPSENSE_WD_MAXCOUNT_CALC_MASK & ptrWdCfg->ptrWdContext->status)) { /* Prepare and execute the measurement to obtain the MAX raw count for the one-dimension widgets * or columns for two-dimension widgets. */ tmpVal = ptrWdCfg->firstSlotId; #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP) - capStatus |= Cy_CapSense_ExecuteSaturatedScan(&ptrWdCfg->ptrWdContext->maxRawCount, widgetId, + capStatus |= Cy_CapSense_ExecuteSaturatedScan(&tempRaw, widgetId, tmpVal, CY_CAPSENSE_SATURATED_MAX_COUNT, context); #else - capStatus |= Cy_CapSense_ExecuteSaturatedScan(&ptrWdCfg->ptrWdContext->maxRawCount, + capStatus |= Cy_CapSense_ExecuteSaturatedScan(&tempRaw, tmpVal, CY_CAPSENSE_SATURATED_MAX_COUNT, context); #endif + if (CY_CAPSENSE_16_BIT_MASK < tempRaw) + { + tempRaw = CY_CAPSENSE_16_BIT_MASK; + } + ptrWdCfg->ptrWdContext->maxRawCount = (uint16_t)tempRaw; } - #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) - if(CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + if (CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) { - if(((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType) || ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType)) + if (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType) || ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType)) { - if(0u != (CY_CAPSENSE_WD_MAXCOUNT_ROW_CALC_MASK & ptrWdCfg->ptrWdContext->status)) + if (0u != (CY_CAPSENSE_WD_MAXCOUNT_ROW_CALC_MASK & ptrWdCfg->ptrWdContext->status)) { /* Prepare and execute the measurement to obtain the MAX raw count for rows for two-dimension widgets. */ scanSlotId = (uint32_t)ptrWdCfg->firstSlotId + ptrWdCfg->numSlots - 1u; #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP) - capStatus |= Cy_CapSense_ExecuteSaturatedScan(&ptrWdCfg->ptrWdContext->maxRawCountRow, widgetId, + capStatus |= Cy_CapSense_ExecuteSaturatedScan(&tempRaw, widgetId, scanSlotId, CY_CAPSENSE_SATURATED_MAX_COUNT, context); + ptrWdCfg->ptrWdContext->maxRawCountRow = (uint16_t)tempRaw; #else - capStatus |= Cy_CapSense_ExecuteSaturatedScan(&ptrWdCfg->ptrWdContext->maxRawCountRow, + capStatus |= Cy_CapSense_ExecuteSaturatedScan(&tempRaw, scanSlotId, CY_CAPSENSE_SATURATED_MAX_COUNT, context); #endif + if (CY_CAPSENSE_16_BIT_MASK < tempRaw) + { + tempRaw = CY_CAPSENSE_16_BIT_MASK; + } + ptrWdCfg->ptrWdContext->maxRawCountRow = (uint16_t)tempRaw; /* For the multi-channel mode, iterate through enabled channels and find the sensing channel that * drives the sensor (not Shield only, Tx only, or Empty). */ for (tmpVal = 0u; tmpVal < CY_CAPSENSE_TOTAL_CH_NUMBER; tmpVal++) { ptrScanSlots = &context->ptrScanSlots[scanSlotId + (CY_CAPSENSE_SLOT_COUNT * tmpVal)]; - if(CY_CAPSENSE_SLOT_SHIELD_ONLY > ptrScanSlots->wdId) + if (CY_CAPSENSE_SLOT_SHIELD_ONLY > ptrScanSlots->wdId) { break; } } - if(tmpVal >= CY_CAPSENSE_TOTAL_CH_NUMBER) + if (tmpVal >= CY_CAPSENSE_TOTAL_CH_NUMBER) { capStatus |= CY_CAPSENSE_STATUS_BAD_CONFIG; } diff --git a/cy_capsense_sensing.h b/cy_capsense_sensing.h index b0f53c9..7b00c19 100644 --- a/cy_capsense_sensing.h +++ b/cy_capsense_sensing.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_sensing.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the common function prototypes for different supported @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2021-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying diff --git a/cy_capsense_sensing_lp.c b/cy_capsense_sensing_lp.c index be68e86..95000b7 100644 --- a/cy_capsense_sensing_lp.c +++ b/cy_capsense_sensing_lp.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_sensing_lp.c -* \version 4.0 +* \version 5.0 * * \brief * This file contains the source of functions common for different scanning @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 @@ -84,6 +84,43 @@ /* The minimum allowed value of CDAC compensation divider */ #define CY_CAPSENSE_CDAC_COMP_DIV_MIN_MSCLP (3u) +#define CY_CAPSENSE_ROW_SNS_CALIBRATION (0u) +#define CY_CAPSENSE_COL_SNS_CALIBRATION (1u) + +/* +* 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 us for CDAC auto-dithering scan is calculated according to the equation: +* WdtTime = (fineInit + Nsub + KrefDelay) * Kref * 3 / modClockFreqMhz. +* The calculated value is the duration of one sample with the three-time margin. +*/ +#define CY_CAPSENSE_CDAC_DITHERING_WATCHDOG_TIME (((CY_CAPSENSE_NUM_FINE_INIT_CYCLES + \ + CY_CAPSENSE_CDAC_DITHERING_NUM_SUBCONV + \ + CY_CAPSENSE_NUM_EPI_KREF_DELAY) * \ + CY_CAPSENSE_CDAC_DITHERING_KREF * 3u) / \ + CY_CAPSENSE_MOD_CLOCK_MHZ) + #define CY_CAPSENSE_AOS_CTL_FR_TIMEOUT_INTERVAL_MAX_VALUE (MSCLP_AOS_CTL_FR_TIMEOUT_INTERVAL_Msk >> MSCLP_AOS_CTL_FR_TIMEOUT_INTERVAL_Pos) /******************************************************************************* @@ -141,23 +178,40 @@ uint32_t Cy_CapSense_GetPolySize(uint32_t lfsrPoly); #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)) -void Cy_CapSense_SetCompDivider( +cy_capsense_status_t Cy_CapSense_ScanSlotInternalCPU( + uint32_t startSlotId, + uint32_t numberSlots, + cy_stc_capsense_context_t * context); +cy_capsense_status_t Cy_CapSense_ScanWidgetInternalCPU( uint32_t widgetId, cy_stc_capsense_context_t * context); -void Cy_CapSense_SetMaxCompCdac( +uint32_t Cy_CapSense_MinRawSearch( uint32_t widgetId, + uint32_t rowFlag, cy_stc_capsense_context_t * context); -cy_capsense_status_t Cy_CapSense_ScanSlotInternalCPU( - uint32_t startSlotId, - uint32_t numberSlots, +uint32_t Cy_CapSense_CalculateAbsDiff( + uint32_t a, + uint32_t b); +void Cy_CapSense_SetWidgetFrameRefCdacCodes( + uint32_t widgetId, + cy_stc_capsense_context_t * context); +void Cy_CapSense_SetWidgetFrameCompCdacCode( + uint32_t widgetId, + uint32_t mode, + cy_stc_capsense_context_t * context); +void Cy_CapSense_SetCompDivider( + uint32_t widgetId, cy_stc_capsense_context_t * context); cy_capsense_status_t Cy_CapSense_CdacSuccessAppr( - uint32_t autoCalibrMode, - uint32_t calibConfigMsk, uint32_t widgetId, - uint32_t target, + uint32_t rowFlag, + uint8_t calibrMask, + uint8_t * cdacPtr, + cy_stc_capsense_context_t * context); +uint32_t Cy_CapSense_CalculateRawTarget( + uint32_t widgetId, + uint32_t rowFlag, cy_stc_capsense_context_t * context); - #endif void Cy_CapSense_TransferRawCounts( @@ -181,6 +235,19 @@ uint32_t Cy_CapSense_MsclpTimerCalcCycles( uint32_t wakeupTimer, cy_stc_capsense_context_t * context); +#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_CdacDitherGetMaxRaw( + uint32_t * ptrSnsFrame, + const cy_stc_capsense_widget_config_t * ptrWdCfg, + uint32_t snsFrameSize, + uint32_t * ptrRawCountMax, + cy_stc_capsense_context_t * context); +#endif + /** \} \endcond */ @@ -393,7 +460,7 @@ cy_capsense_status_t Cy_CapSense_MixedSensorsCheck(uint32_t startSlotId, snsIndex = ptrScanSlots[curSlotIndex].snsId; ptrWdCfg = &context->ptrWdConfig[wdIndex ]; - if((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && + if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && (CY_CAPSENSE_MPSC_MIN_ORDER <= ptrWdCfg->mpOrder)) { mpscWdCnt++; @@ -599,6 +666,7 @@ cy_capsense_status_t Cy_CapSense_ScanSlots_V3Lp( /* Unmask FRAME interrupt for ACTIVE and ALR modes (AS_MS and LP_AOS HW modes) */ ptrHwBase->INTR_LP_MASK = MSCLP_INTR_LP_FRAME_Msk; + (void)ptrHwBase->INTR_LP_MASK; /* Initialize internal context */ ptrIntrCxt->startSlotIndex = (uint16_t)startSlotId; @@ -646,7 +714,7 @@ cy_capsense_status_t Cy_CapSense_ScanSlots_V3Lp( * 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 clears the CY_CAPSENSE_MW_STATE_LP_ACTIVE_MASK status bit. It is -* set when a touch detect occurs during the low power slot scans and will remain +* set when a touch detection occurs during the low power slot scans and will remain * set until the next Cy_CapSense_ScanLpSlots() function call. * * \note @@ -722,7 +790,7 @@ cy_capsense_status_t Cy_CapSense_ScanLpSlots( /* Enable HW processing */ ptrHwBase->CE_CTL = MSCLP_CE_CTL_ENABLED_Msk | MSCLP_CE_CTL_BLSD_EN_Msk; - #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_RC_IIR_FILTER_EN) + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_RC_IIR_FILTER_EN) ptrHwBase->CE_CTL |= MSCLP_CE_CTL_RCF_EN_Msk; #endif @@ -755,7 +823,7 @@ cy_capsense_status_t Cy_CapSense_ScanLpSlots( ptrSensorFrameLp = &context->ptrSensorFrameLpContext[startLpSlotId * CY_MSCLP_11_SNS_REGS]; /* Copy sensor frame to Sensor Data RAM */ - for(index = 0u; index < (numberLpSlots * CY_MSCLP_11_SNS_REGS); index++) + for (index = 0u; index < (numberLpSlots * CY_MSCLP_11_SNS_REGS); index++) { ptrHwBase->SNS.SENSOR_DATA[index] = ptrSensorFrameLp[index]; } @@ -840,7 +908,7 @@ cy_capsense_status_t Cy_CapSense_ScanLpSlots( /* Disable HW block per IFX 005467-513 */ ptrHwBase->CTL &= ~MSCLP_CTL_ENABLED_Msk; - + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_EXT_FRM_START_EN) /* Clear the external start scan mode */ ptrHwBase->CTL &= ~MSCLP_CTL_EXT_FRAME_START_MODE_Msk; @@ -849,9 +917,9 @@ cy_capsense_status_t Cy_CapSense_ScanLpSlots( /* Enable HW IP to allow scans */ ptrHwBase->CTL |= MSCLP_CTL_ENABLED_Msk; - /* Un-mask FR_TIMEOUT and SIG_DETECT interrupts in LP-AOS mode */ - ptrHwBase->INTR_LP_MASK = MSCLP_INTR_LP_MASK_FR_TIMEOUT_Msk | MSCLP_INTR_LP_MASK_SIG_DET_Msk; - + /* Un-mask FR_TIMEOUT interrupt in LP-AOS mode */ + ptrHwBase->INTR_LP_MASK = MSCLP_INTR_LP_MASK_FR_TIMEOUT_Msk; + (void)ptrHwBase->INTR_LP_MASK; /* Start scan */ ptrHwBase->WAKEUP_CMD |= MSCLP_WAKEUP_CMD_START_FRAME_AOS_Msk; } @@ -1280,9 +1348,11 @@ cy_capsense_status_t Cy_CapSense_SetCalibrationTarget_V3Lp( * - 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_CALIBRATION_REF_CHECK_FAIL - The reference/fine CapDAC +* calibration stage is failed as the raw count +* minimum across widget is out of range. +* - CY_CAPSENSE_STATUS_CALIBRATION_CHECK_FAIL - The resulting rawcounts across +* all sensors in widget are out of defined range. * *******************************************************************************/ cy_capsense_status_t Cy_CapSense_CalibrateAllWidgets_V3Lp(cy_stc_capsense_context_t * context) @@ -1295,13 +1365,11 @@ cy_capsense_status_t Cy_CapSense_CalibrateAllWidgets_V3Lp(cy_stc_capsense_contex for (widgetId = 0u; widgetId < context->ptrCommonConfig->numWd; widgetId++) { #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) - if(context->ptrWdConfig[widgetId].wdType != (uint8_t)CY_CAPSENSE_WD_LOW_POWER_E) - { - calibStatus |= Cy_CapSense_CalibrateWidget_V3Lp(widgetId, context); - } - #else - calibStatus |= Cy_CapSense_CalibrateWidget_V3Lp(widgetId, context); + if (context->ptrWdConfig[widgetId].wdType != (uint8_t)CY_CAPSENSE_WD_LOW_POWER_E) #endif + { + calibStatus |= Cy_CapSense_CalibrateWidget_V3Lp(widgetId, context); + } } } @@ -1385,9 +1453,11 @@ cy_capsense_status_t Cy_CapSense_CalibrateAllLpSlots(cy_stc_capsense_context_t * * - 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_CALIBRATION_REF_CHECK_FAIL - The reference/fine CapDAC +* calibration stage is failed as the raw count +* minimum across widget is out of range. +* - CY_CAPSENSE_STATUS_CALIBRATION_CHECK_FAIL - The resulting rawcounts across +* all sensors in widget are out of defined range. * *******************************************************************************/ cy_capsense_status_t Cy_CapSense_CalibrateAllLpWidgets(cy_stc_capsense_context_t * context) @@ -1399,7 +1469,7 @@ cy_capsense_status_t Cy_CapSense_CalibrateAllLpWidgets(cy_stc_capsense_context_t { for (widgetId = 0u; widgetId < context->ptrCommonConfig->numWd; widgetId++) { - if(context->ptrWdConfig[widgetId].wdType == (uint8_t)CY_CAPSENSE_WD_LOW_POWER_E) + if (context->ptrWdConfig[widgetId].wdType == (uint8_t)CY_CAPSENSE_WD_LOW_POWER_E) { calibStatus |= Cy_CapSense_CalibrateWidget_V3Lp(widgetId, context); } @@ -1552,7 +1622,7 @@ cy_capsense_status_t Cy_CapSense_ConfigureMsclpWotTimer( * Function Name: Cy_CapSense_IloCompensate ****************************************************************************//** * -* Measures the actual ILO frequency and calculates compensation factor for MSCLP +* Measures the actual ILO frequency and calculates the compensation factor for MSCLP * Active and Wake-On-Touch mode timers. In order to keep timer intervals * accurate, call this function periodically. * To set Active and Wake-On-Touch mode timers, use @@ -1714,9 +1784,11 @@ uint32_t Cy_CapSense_MsclpTimerCalcCycles(uint32_t wakeupTimer, cy_stc_capsense_ * - 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_CALIBRATION_REF_CHECK_FAIL - The reference/fine CapDAC +* calibration stage is failed as the raw count +* minimum across widget is out of range. +* - CY_CAPSENSE_STATUS_CALIBRATION_CHECK_FAIL - The resulting rawcounts across +* all sensors in widget are out of defined range. * *******************************************************************************/ cy_capsense_status_t Cy_CapSense_CalibrateWidget_V3Lp( @@ -1724,116 +1796,121 @@ cy_capsense_status_t Cy_CapSense_CalibrateWidget_V3Lp( cy_stc_capsense_context_t * context) { cy_capsense_status_t calibrationStatus = CY_CAPSENSE_STATUS_SUCCESS; - cy_stc_capsense_widget_config_t const * ptrWdCfg; - uint32_t calibConfigMsk = 0u; - uint32_t target; - MSCLP_Type * ptrHwBase; + const cy_stc_capsense_widget_config_t * ptrWdCfg; + cy_stc_capsense_widget_context_t * ptrWdCxt; + uint32_t cdacConfig; + uint32_t snsIndex; if ((NULL != context) && (CY_CAPSENSE_TOTAL_WIDGET_COUNT > widgetId) && - (0u != Cy_CapSense_IsWidgetEnabled(widgetId, context))) + (0u != Cy_CapSense_IsWidgetEnabled(widgetId, context))) { ptrWdCfg = &context->ptrWdConfig[widgetId]; - ptrHwBase = context->ptrCommonConfig->ptrChConfig->ptrHwBase; - Cy_CapSense_SetupCpuOperatingMode(context); - switch (ptrWdCfg->senseMethod) - { - #if (CY_CAPSENSE_CSD_CDAC_CALIBRATION_USAGE) - case CY_CAPSENSE_CSD_GROUP: - calibConfigMsk = CY_CAPSENSE_CSD_CALIBRATION_MODE_MSK; - target = context->ptrInternalContext->intrCsdRawTarget; - break; - #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN) */ - - #if (CY_CAPSENSE_CSX_CDAC_CALIBRATION_USAGE) - case CY_CAPSENSE_CSX_GROUP: - calibConfigMsk = CY_CAPSENSE_CSX_CALIBRATION_MODE_MSK; - target = context->ptrInternalContext->intrCsxRawTarget; - break; - #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN) */ + ptrWdCxt = ptrWdCfg->ptrWdContext; + cdacConfig = ptrWdCfg->cdacConfig; - #if (CY_CAPSENSE_ISX_CDAC_CALIBRATION_USAGE) - case CY_CAPSENSE_ISX_GROUP: - calibConfigMsk = CY_CAPSENSE_ISX_CALIBRATION_MODE_MSK; - target = context->ptrInternalContext->intrIsxRawTarget; - break; - #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN) */ + context->ptrCommonContext->status |= CY_CAPSENSE_MW_STATE_CALIBRATION_MASK; - default: - /* Widget type is not valid */ - target = 0u; - break; + /* Reference CapDac configuration */ + if (CY_CAPSENSE_CDAC_REF_MODE_MANUAL_MASK != (cdacConfig & CY_CAPSENSE_CDAC_REF_MODE_MASK)) + { + ptrWdCxt->cdacRef = 0u; + ptrWdCxt->rowCdacRef = 0u; } - /* Proceed widgets only if calibration for method is enabled */ - if (0u != (calibConfigMsk & CY_CAPSENSE_CALIBRATION_EN_MSK)) + /* Fine CapDac configuration */ + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_FINE_AUTO_EN) + if (CY_CAPSENSE_CDAC_FINE_MODE_MANUAL_MASK != (cdacConfig & CY_CAPSENSE_CDAC_FINE_MODE_MASK)) + { + ptrWdCxt->cdacFine = 0u; + ptrWdCxt->rowCdacFine = 0u; + } + #endif + + /* Compensation CapDac configuration */ + if (CY_CAPSENSE_CDAC_COMP_MODE_MANUAL_MASK != (cdacConfig & CY_CAPSENSE_CDAC_COMP_MODE_MASK)) { - context->ptrCommonContext->status |= CY_CAPSENSE_MW_STATE_CALIBRATION_MASK; + for (snsIndex = 0u; snsIndex < (uint32_t)ptrWdCfg->numSns; snsIndex++) + { + ptrWdCfg->ptrSnsContext[snsIndex].cdacComp = 0u; + } + } - /* Calibrate RefCDAC with disabled CompCDAC */ - #if (CY_CAPSENSE_CDAC_REF_AUTO_USAGE) - if(0u != (calibConfigMsk & CY_CAPSENSE_CDAC_REF_AUTO_USAGE_MSK)) - { - context->ptrCommonContext->status |= CY_CAPSENSE_MW_STATE_CALIBRATION_SINGLE_MASK; + Cy_CapSense_SetWidgetFrameCompCdacCode(widgetId, CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_VAL, context); + Cy_CapSense_SetWidgetFrameRefCdacCodes(widgetId, context); - calibrationStatus |= Cy_CapSense_CdacSuccessAppr(CY_CAPSENSE_CAL_MODE_REF_CDAC_SUC_APPR, calibConfigMsk, - widgetId, target, context); + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) + if (0u != (cdacConfig & CY_CAPSENSE_CDAC_REF_MODE_AUTO_MASK)) + { + calibrationStatus |= Cy_CapSense_CalibrateRefCdac(widgetId, context); + Cy_CapSense_SetWidgetFrameRefCdacCodes(widgetId, context); + } + #endif - context->ptrCommonContext->status &= - (uint32_t)~((uint32_t)CY_CAPSENSE_MW_STATE_CALIBRATION_SINGLE_MASK); - } - #endif + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_FINE_AUTO_EN) + if (0u != (cdacConfig & CY_CAPSENSE_CDAC_FINE_MODE_AUTO_MASK)) + { + calibrationStatus |= Cy_CapSense_CalibrateFineCdac(widgetId, context); + Cy_CapSense_SetWidgetFrameRefCdacCodes(widgetId, context); + } + #endif - /* Find CompDivider with fixed Ref CDAC and maximum CompCDAC (for case #8 or #4) */ - #if (CY_CAPSENSE_CDAC_COMP_DIV_AUTO_USAGE) - if(0u != (calibConfigMsk & CY_CAPSENSE_CDAC_COMP_DIV_AUTO_USAGE_MSK)) - { - calibrationStatus |= Cy_CapSense_CalibrateCompDivider(widgetId, target, context); - } - #endif + #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_FINE_AUTO_EN)) + if (0u != (cdacConfig & (CY_CAPSENSE_CDAC_REF_MODE_AUTO_MASK | + CY_CAPSENSE_CDAC_FINE_MODE_AUTO_MASK))) + { + /* Check reference CapDac calibration result */ + calibrationStatus |= Cy_CapSense_VerifyReferenceCdac(widgetId, context); + } + #endif + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) + ptrWdCxt->cdacRef /= (uint8_t)((cdacConfig & CY_CAPSENSE_CDAC_BOOST_VAL_MASK) >> CY_CAPSENSE_CDAC_BOOST_VAL_POS); + ptrWdCxt->rowCdacRef /= (uint8_t)((cdacConfig & CY_CAPSENSE_CDAC_BOOST_VAL_MASK) >> CY_CAPSENSE_CDAC_BOOST_VAL_POS); + Cy_CapSense_SetWidgetFrameRefCdacCodes(widgetId, context); + #endif - /* Calibrate CompCDAC with fixed Ref CDAC and fixed CompDivider (case #3 and #7) */ - #if (CY_CAPSENSE_CDAC_COMP_USAGE) - if(0u != (calibConfigMsk & CY_CAPSENSE_CDAC_COMP_USAGE_MSK)) + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_COMP_AUTO_EN) + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_COMP_DIV_AUTO_EN) + if (0u != (cdacConfig & CY_CAPSENSE_CDAC_COMP_DIV_MODE_AUTO_MASK)) { - calibrationStatus |= Cy_CapSense_CdacSuccessAppr(CY_CAPSENSE_CAL_MODE_COMP_CDAC_SUC_APPR, calibConfigMsk, - widgetId, target, context); + calibrationStatus |= Cy_CapSense_CalibrateCompDivider(widgetId, context); } #endif - - /* Check calibration result */ - calibrationStatus |= Cy_CapSense_VerifyCalibration(widgetId, context); - - /* 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_UpdateCrcWidget(widgetId, context); - #endif - - if (CY_CAPSENSE_STATUS_SUCCESS != calibrationStatus) + if (0u != (cdacConfig & CY_CAPSENSE_CDAC_COMP_MODE_AUTO_MASK)) { - calibrationStatus |= CY_CAPSENSE_STATUS_CALIBRATION_FAIL; + calibrationStatus |= Cy_CapSense_CalibrateCompCdac(widgetId, context); } + Cy_CapSense_SetWidgetFrameCompCdacCode(widgetId, CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_VAL, context); + #endif - - /* Disable HW IP to allow MRSS operations */ - ptrHwBase->CTL &= (~MSCLP_CTL_ENABLED_Msk); - - /* Disable PUMP */ - #if (CY_MSCLP_VDDA_PUMP_TRESHOLD > CY_CAPSENSE_VDDA_MV) - ptrHwBase->PUMP_CTL = 0u; - #endif - - if (0u != (ptrHwBase->MRSS_STATUS & MSCLP_MRSS_STATUS_MRSS_UP_Msk)) + #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_FINE_AUTO_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_COMP_AUTO_EN)) + if (0u != (cdacConfig & (CY_CAPSENSE_CDAC_REF_MODE_AUTO_MASK | + CY_CAPSENSE_CDAC_FINE_MODE_AUTO_MASK | + CY_CAPSENSE_CDAC_COMP_MODE_AUTO_MASK | + CY_CAPSENSE_CDAC_COMP_DIV_MODE_AUTO_MASK))) { - /* Stop the MRSS to save power */ - ptrHwBase->MRSS_CMD = MSCLP_MRSS_CMD_MRSS_STOP_Msk; - (void)Cy_CapSense_WaitMrssStatusChange((CY_MSCLP_CLK_LF_PERIOD_MAX * CY_CAPSENSE_MULTIPLIER_TWO), CY_CAPSENSE_MRSS_TURN_OFF, context); + /* Check final calibration result */ + calibrationStatus |= Cy_CapSense_VerifyCalibration(widgetId, context); } + #endif - context->ptrCommonContext->status &= ~(uint32_t)CY_CAPSENSE_MW_STATE_CALIBRATION_MASK; + /* 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_UpdateCrcWidget(widgetId, context); + #endif - (void)Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_CAPTURED_DEFAULT, context); + if (CY_CAPSENSE_STATUS_SUCCESS != calibrationStatus) + { + calibrationStatus |= CY_CAPSENSE_STATUS_CALIBRATION_FAIL; } + + context->ptrCommonContext->status &= ~(uint32_t)CY_CAPSENSE_MW_STATE_CALIBRATION_MASK; + + (void)Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_UNDEFINED, context); } else { @@ -1845,346 +1922,900 @@ cy_capsense_status_t Cy_CapSense_CalibrateWidget_V3Lp( /******************************************************************************* -* Function Name: Cy_CapSense_CdacSuccessAppr +* Function Name: Cy_CapSense_SetWidgetFrameRefCdacCodes ****************************************************************************//** * -* The internal function that performs the specified CDAC successive -* approximation seek for the specified widget. -* -* The function performs some scans of the slots in specified widget in the CPU -* driven scan mode to seek a CDAC value which produce raw counts no more than -* the configured target. The CDAC is specified by the autoCalibrMode parameter. -* The number of scans is no more than the specified CDAC bit number plus one, -* if the fine CDAC enabled - additional 5 scans are added. -* The function also break the approximation process if raw counts are closer -* to the target less than a half of the configured calibration error. -* The function usage is limited by the CapDAC auto-calibration. +* This function updates reference and fine CDACs codes in sensor +* frame to match values in widget structure. * * \note * This function is available only * for the fifth-generation low power CAPSENSE™. * -* \param autoCalibrMode -* Specifies the widget auto-calibration mode: -* - CY_CAPSENSE_CAL_MODE_REF_CDAC_SUC_APPR - The successive approximation -* (up to 9 scans) of RefCDAC with disabled CompCDAC -* - CY_CAPSENSE_CAL_MODE_COMP_CDAC_SUC_APPR - The successive approximation -* (up to 9 scans) of CompCDAC with fixed RefCDAC -* -* \param calibConfigMsk -* Specifies the widget auto-calibration configuration mask. -* * \param widgetId -* The widget ID scans will be done for. -* -* \param target -* The calibrated sensor raw target. +* Specifies the ID number of the widget. * * \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_CALIBRATION_FAIL - The calibration is failed due to -* the issues with scanning (either -* watchdog timer, interrupt breaking, etc.). -* - CY_CAPSENSE_STATUS_BAD_PARAM - The wrong CDAC is specified -* by the autoCalibrMode parameter. -* *******************************************************************************/ -cy_capsense_status_t Cy_CapSense_CdacSuccessAppr( - uint32_t autoCalibrMode, - uint32_t calibConfigMsk, +void Cy_CapSense_SetWidgetFrameRefCdacCodes( uint32_t widgetId, - uint32_t target, cy_stc_capsense_context_t * context) { - cy_capsense_status_t calibStatus = CY_CAPSENSE_STATUS_SUCCESS; cy_stc_capsense_widget_config_t const * ptrWdCfg = &context->ptrWdConfig[widgetId]; - cy_stc_capsense_sensor_context_t * ptrSnsCxt; - - uint32_t calMaskNext; - uint32_t ii; - uint32_t rawTarget; + cy_stc_capsense_widget_context_t * ptrWdCxt = &context->ptrWdContext[widgetId]; uint32_t snsIndex; - uint32_t sensingGroup = context->ptrWdConfig[widgetId].senseMethod; - uint32_t snsFrameType; + uint32_t frameSize; uint32_t * ptrSnsFrmCdacCtlReg; - uint32_t snsFrameIndex; - uint32_t numberOfScans; - uint32_t frameSize = CY_CAPSENSE_SENSOR_FRAME_SIZE; - uint32_t cdacMsk; - uint32_t csdScanEn = CY_CAPSENSE_DISABLE; - uint32_t rowFlag = CY_CAPSENSE_DISABLE; - uint32_t cdacVal; - uint8_t * cdacRefPtr = &ptrWdCfg->ptrWdContext->cdacRef; - uint8_t * rowCdacRefPtr = &ptrWdCfg->ptrWdContext->rowCdacRef; - #if (CY_CAPSENSE_CDAC_FINE_USAGE) - uint32_t fineVal; - uint8_t * cdacFinePtr = &ptrWdCfg->ptrWdContext->cdacFine; - uint8_t * rowCdacFinePtr = &ptrWdCfg->ptrWdContext->rowCdacFine; - #endif - - snsFrameType = CY_CAPSENSE_SNS_FRAME_ACTIVE; - ptrSnsFrmCdacCtlReg = context->ptrSensorFrameContext + CY_CAPSENSE_SNS_CDAC_CTL_INDEX; + frameSize = CY_CAPSENSE_SENSOR_FRAME_SIZE; + ptrSnsFrmCdacCtlReg = &context->ptrSensorFrameContext[CY_CAPSENSE_SNS_CDAC_CTL_INDEX]; #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) if ((ptrWdCfg->wdType == (uint8_t)CY_CAPSENSE_WD_LOW_POWER_E)) { - snsFrameType = CY_CAPSENSE_SNS_FRAME_LOW_POWER; - ptrSnsFrmCdacCtlReg = context->ptrSensorFrameLpContext + CY_CAPSENSE_FRM_LP_SNS_CDAC_CTL_INDEX; + ptrSnsFrmCdacCtlReg = &context->ptrSensorFrameLpContext[CY_CAPSENSE_FRM_LP_SNS_CDAC_CTL_INDEX]; frameSize = CY_MSCLP_11_SNS_REGS; } #endif - /* Calculate raw target for current sensing method */ - rawTarget = context->ptrWdContext[widgetId].maxRawCount; - rawTarget = (rawTarget * target) / CY_CAPSENSE_PERCENTAGE_100; - /* Find number of scans */ - numberOfScans = CY_CAPSENSE_CAL_NUM_SCANS_VALUE; - - #if (CY_CAPSENSE_CDAC_REF_AUTO_USAGE) - if (CY_CAPSENSE_CAL_MODE_COMP_CDAC_SUC_APPR != autoCalibrMode) - { - ptrWdCfg->ptrWdContext->cdacRef = 0u; - ptrWdCfg->ptrWdContext->rowCdacRef = 0u; - #if (CY_CAPSENSE_CDAC_FINE_USAGE) - if (0u != (calibConfigMsk & CY_CAPSENSE_CDAC_CDAC_FINE_USAGE_MSK)) - { - numberOfScans = CY_CAPSENSE_CAL_FINE_NUM_SCANS_VALUE; - ptrWdCfg->ptrWdContext->cdacFine = 0u; - ptrWdCfg->ptrWdContext->rowCdacFine = 0u; - } - #endif - } - #endif - - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) - /* Dummy scan */ - if (CY_CAPSENSE_CSX_GROUP == sensingGroup) - { - calibStatus |= Cy_CapSense_ScanSlotInternalCPU(snsFrameType, (ptrWdCfg->firstSlotId), context); - } - #endif + ptrSnsFrmCdacCtlReg += (frameSize * ptrWdCfg->firstSlotId); - for (snsIndex = 0u; snsIndex < (uint32_t)ptrWdCfg->numSns; snsIndex++) + for (snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++) { - #if (CY_CAPSENSE_CDAC_FINE_USAGE) - fineVal = 0u; - #endif - cdacVal = 0u; - cdacMsk = CY_CAPSENSE_CAL_MIDDLE_VALUE; - calMaskNext = CY_CAPSENSE_CAL_MIDDLE_VALUE; - snsFrameIndex = frameSize * (ptrWdCfg->firstSlotId + snsIndex); - ptrSnsCxt = &ptrWdCfg->ptrSnsContext[snsIndex]; + *ptrSnsFrmCdacCtlReg &= (uint32_t)~(MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Msk | + MSCLP_SNS_SNS_CDAC_CTL_SEL_CF_Msk); #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) - if ((rowFlag != CY_CAPSENSE_ENABLE) && - (CY_CAPSENSE_CSD_GROUP == sensingGroup) && + if ((CY_CAPSENSE_CSD_GROUP == context->ptrWdConfig[widgetId].senseMethod) && (ptrWdCfg->numCols <= snsIndex) && (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType) || ((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType))) { - rowFlag = CY_CAPSENSE_ENABLE; - rawTarget = context->ptrWdContext[widgetId].maxRawCountRow; - rawTarget = (rawTarget * target) / CY_CAPSENSE_PERCENTAGE_100; + *ptrSnsFrmCdacCtlReg |= ((((uint32_t)ptrWdCxt->rowCdacRef)) << MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Pos); + #if (CY_CAPSENSE_CDAC_FINE_USAGE) + *ptrSnsFrmCdacCtlReg |= (((uint32_t)ptrWdCxt->rowCdacFine) << MSCLP_SNS_SNS_CDAC_CTL_SEL_CF_Pos); + #endif } + else #endif - - if(CY_CAPSENSE_CSD_GROUP == sensingGroup) { - /* Set CSD scan flag */ - csdScanEn = CY_CAPSENSE_ENABLE; - - /* Clear flag as compensation CapDAC code for MPSC widgets should be increased unlike reference CapDAC */ - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED) - if ((CY_CAPSENSE_MPSC_MIN_ORDER <= ptrWdCfg->mpOrder) && - (CY_CAPSENSE_CAL_MODE_COMP_CDAC_SUC_APPR == autoCalibrMode)) - { - csdScanEn = CY_CAPSENSE_DISABLE; - } + *ptrSnsFrmCdacCtlReg |= (((uint32_t)ptrWdCxt->cdacRef) << MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Pos); + #if (CY_CAPSENSE_CDAC_FINE_USAGE) + *ptrSnsFrmCdacCtlReg |= (((uint32_t)ptrWdCxt->cdacFine) << MSCLP_SNS_SNS_CDAC_CTL_SEL_CF_Pos); #endif } - /* Phase 1: Find DAC code to match raw target */ - for (ii = 0u; ii < numberOfScans; ii++) - { - cdacVal = (cdacMsk & CY_CAPSENSE_CAL_CDAC_Msk) >> CY_CAPSENSE_CAL_CDAC_Pos; - switch (autoCalibrMode) - { - #if (CY_CAPSENSE_CDAC_REF_AUTO_USAGE) - case CY_CAPSENSE_CAL_MODE_REF_CDAC_SUC_APPR: - ptrSnsFrmCdacCtlReg[snsFrameIndex] &= (uint32_t)~(MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Msk | - MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Msk | - MSCLP_SNS_SNS_CDAC_CTL_SEL_CF_Msk); - - #if (CY_CAPSENSE_CDAC_FINE_USAGE) - if (ii >= CY_CAPSENSE_CAL_NUM_SCANS_VALUE) - { - fineVal = (cdacMsk & CY_CAPSENSE_CAL_FINE_CDAC_Msk); - ptrSnsFrmCdacCtlReg[snsFrameIndex] |= (fineVal << MSCLP_SNS_SNS_CDAC_CTL_SEL_CF_Pos); - } - else - #endif - { - ptrSnsFrmCdacCtlReg[snsFrameIndex] |= (cdacVal << MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Pos); - } - break; - #endif - - #if (CY_CAPSENSE_CDAC_COMP_USAGE) - case CY_CAPSENSE_CAL_MODE_COMP_CDAC_SUC_APPR: - ptrSnsFrmCdacCtlReg[snsFrameIndex] &= (uint32_t)~MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Msk; - ptrSnsFrmCdacCtlReg[snsFrameIndex] |= (uint32_t)(cdacVal << MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Pos); - break; - #endif - - default: - /* The auto-calibration mode is not valid */ - calibStatus = CY_CAPSENSE_STATUS_BAD_PARAM; - break; - } - - calibStatus |= Cy_CapSense_ScanSlotInternalCPU(snsFrameType, (ptrWdCfg->firstSlotId + snsIndex), context); - Cy_CapSense_PreProcessSensor(widgetId, snsIndex, context); + ptrSnsFrmCdacCtlReg += frameSize; + } +} - /* Update CapDACs based on scan result - * Bits [4..0] fine CapDAC - * Bits [12..5] reference CapDAC / compensation CapDAC - */ - if (((csdScanEn == CY_CAPSENSE_ENABLE) && ((uint32_t)ptrSnsCxt->raw < rawTarget)) || - ((csdScanEn == CY_CAPSENSE_DISABLE) && ((uint32_t)ptrSnsCxt->raw >= rawTarget))) - { - cdacMsk &= ~calMaskNext; - } - calMaskNext >>= 1u; - cdacMsk |= calMaskNext; - } - /* In case of Comp CapDAC calibration - update data structure and go to the phase #4 */ - #if (CY_CAPSENSE_CDAC_COMP_USAGE) - if ((uint32_t)CY_CAPSENSE_CAL_MODE_COMP_CDAC_SUC_APPR == autoCalibrMode) - { - ptrSnsCxt->cdacComp = (uint8_t)cdacVal; - } - #endif +/******************************************************************************* +* Function Name: Cy_CapSense_SetWidgetFrameCompCdacCode +****************************************************************************//** +* +* Sets the Compensation CDAC code into sensor frames. +* +* This function applies Compensation CDAC code for all +* sensors within specified widget in sensor frame structures. +* +* \param widgetId +* Specifies widget ID. +* +* \param mode +* Specifies the Compensation CDAC code: +* +* * CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_MIN - Sets the minimum CDAC code. +* * CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_MAX - Sets the maximum CDAC code. +* * CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_VAL - Sets the CDAC code specified in the sensor configuration. +* +* \param context +* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. +* +*******************************************************************************/ +void Cy_CapSense_SetWidgetFrameCompCdacCode( + uint32_t widgetId, + uint32_t mode, + cy_stc_capsense_context_t * context) +{ + const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId]; + cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdCfg->ptrSnsContext; - /* Phase #2 - Find Max CapDAC Code across all sensors and populate it to the widget context structure */ - #if (CY_CAPSENSE_CDAC_REF_AUTO_USAGE) - if ((uint32_t)CY_CAPSENSE_CAL_MODE_REF_CDAC_SUC_APPR == autoCalibrMode) - { - if (rowFlag == CY_CAPSENSE_ENABLE) - { - if (((uint8_t)cdacVal) > *rowCdacRefPtr) - { - *rowCdacRefPtr = (uint8_t)cdacVal; - } - #if (CY_CAPSENSE_CDAC_FINE_USAGE) - if (((uint8_t)fineVal) > *rowCdacFinePtr) - { - *rowCdacFinePtr = ((uint8_t)fineVal); - } - #endif - } - else - { - if (((uint8_t)cdacVal) > *cdacRefPtr) - { - *cdacRefPtr = (uint8_t)cdacVal; - } - #if (CY_CAPSENSE_CDAC_FINE_USAGE) - if (((uint8_t)fineVal) > *cdacFinePtr) - { - *cdacFinePtr = (uint8_t)fineVal; - } - #endif - } - } - #endif - } + uint32_t snsCount = ptrWdCfg->numSns; + uint32_t frameSize; + uint32_t * ptrSnsFrmCdacCtlReg; - /* Phase #3 - Normalization */ - #if (CY_CAPSENSE_CDAC_REF_AUTO_USAGE) - if ((uint32_t)CY_CAPSENSE_CAL_MODE_REF_CDAC_SUC_APPR == autoCalibrMode) + frameSize = CY_CAPSENSE_SENSOR_FRAME_SIZE; + ptrSnsFrmCdacCtlReg = &context->ptrSensorFrameContext[CY_CAPSENSE_SNS_CDAC_CTL_INDEX]; + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) + if ((ptrWdCfg->wdType == (uint8_t)CY_CAPSENSE_WD_LOW_POWER_E)) { - /* Decreases CapDAC twice if compensation is enabled */ - if(0u != (calibConfigMsk & CY_CAPSENSE_CDAC_COMP_USAGE_MSK)) - { - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED) - /* Skip normalization for MPSC widgets*/ - if (!((CY_CAPSENSE_MPSC_MIN_ORDER <= ptrWdCfg->mpOrder) && - (CY_CAPSENSE_CSD_GROUP == sensingGroup))) - #endif - { - /* Division with rounding up for both ref and fine CDAC */ - *cdacRefPtr = (*cdacRefPtr + 1u) >> 1u; - *rowCdacRefPtr = (*rowCdacRefPtr + 1u) >> 1u; - - #if (CY_CAPSENSE_CDAC_FINE_USAGE) - *cdacFinePtr = (*cdacFinePtr + 1u) >> 1u; - *rowCdacFinePtr = (*rowCdacFinePtr + 1u) >> 1u; - if (CY_CAPSENSE_CAL_REF_CDAC_MIN_CODE > *cdacRefPtr) - { - *cdacRefPtr = 0u; - } - else - { - *cdacFinePtr = 0u; - } - - if ((CY_CAPSENSE_CSD_GROUP == sensingGroup) && - (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType) || - ((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType))) - { - if (CY_CAPSENSE_CAL_REF_CDAC_MIN_CODE > *rowCdacRefPtr) - { - *rowCdacRefPtr = 0u; - } - else - { - *rowCdacFinePtr = 0u; - } - } - #endif - } - } + frameSize = CY_MSCLP_11_SNS_REGS; + ptrSnsFrmCdacCtlReg = &context->ptrSensorFrameLpContext[CY_CAPSENSE_FRM_LP_SNS_CDAC_CTL_INDEX]; } #endif - /* Phase #4 - Populate CapDAC values to sensor frame structures */ - for (snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++) + ptrSnsFrmCdacCtlReg += (frameSize * ptrWdCfg->firstSlotId); + for (;snsCount-- > 0u;) { - snsFrameIndex = frameSize * (ptrWdCfg->firstSlotId + snsIndex); - ptrSnsCxt = &ptrWdCfg->ptrSnsContext[snsIndex]; + *ptrSnsFrmCdacCtlReg &= (uint32_t)~(MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Msk); + switch (mode) + { + case CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_MAX: + *ptrSnsFrmCdacCtlReg |= ((uint32_t)MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Msk); + break; - ptrSnsFrmCdacCtlReg[snsFrameIndex] &= (uint32_t)~(MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Msk | - MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Msk | - MSCLP_SNS_SNS_CDAC_CTL_SEL_CF_Msk); - ptrSnsFrmCdacCtlReg[snsFrameIndex] |= (((uint32_t)ptrSnsCxt->cdacComp) << MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Pos); - ptrSnsFrmCdacCtlReg[snsFrameIndex] |= (((uint32_t)*cdacRefPtr) << MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Pos); - #if (CY_CAPSENSE_CDAC_FINE_USAGE) - ptrSnsFrmCdacCtlReg[snsFrameIndex] |= (((uint32_t)*cdacFinePtr) << MSCLP_SNS_SNS_CDAC_CTL_SEL_CF_Pos); - #endif + case CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_VAL: + *ptrSnsFrmCdacCtlReg |= (((uint32_t)ptrSnsCxt->cdacComp) << MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Pos); + break; - #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + default: + /* No action for other modes */ + break; + } + ptrSnsFrmCdacCtlReg += frameSize; + ptrSnsCxt++; + } +} + + +/******************************************************************************* +* Function Name: Cy_CapSense_MinRawSearch +****************************************************************************//** +* +* This function seeks for a minimal raw count across the widget. +* +* \note +* This function is available only +* for the fifth-generation low power CAPSENSE™. +* +* \param widgetId +* The widget ID scans will be done for. +* +* \param rowFlag +* The flag for a row/column sensors seek. +* CY_CAPSENSE_ROW_SNS_CALIBRATION - seek performed for rows. +* CY_CAPSENSE_COL_SNS_CALIBRATION - seek performed for columns. +* +* \param context +* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. +* +* \return +* The minimal raw count. +* +*******************************************************************************/ +uint32_t Cy_CapSense_MinRawSearch( + uint32_t widgetId, + uint32_t rowFlag, + cy_stc_capsense_context_t * context) +{ + cy_stc_capsense_widget_config_t const * ptrWdCfg = &context->ptrWdConfig[widgetId]; + cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdCfg->ptrSnsContext; + uint32_t snsCount; + uint32_t minRaw = CY_CAPSENSE_32_BIT_MASK; + + snsCount = ptrWdCfg->numSns; + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + if ((CY_CAPSENSE_CSD_GROUP == context->ptrWdConfig[widgetId].senseMethod) && + (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == context->ptrWdConfig[widgetId].wdType) || + ((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == context->ptrWdConfig[widgetId].wdType))) + { + snsCount = ptrWdCfg->numCols; + if (CY_CAPSENSE_ROW_SNS_CALIBRATION != rowFlag) + { + ptrSnsCxt += snsCount; + snsCount = ptrWdCfg->numRows; + } + } + #else + (void)rowFlag; + #endif + + for (;snsCount-- > 0u;) + { + if (ptrSnsCxt->raw < minRaw) + { + minRaw = ptrSnsCxt->raw; + } + ptrSnsCxt++; + } + + return minRaw; +} + + +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) +/******************************************************************************* +* Function Name: Cy_CapSense_CalculateAbsDiff +****************************************************************************//** +* +* The internal function that returns absolute difference of two integers. +* +* \note +* This function is available only +* for the fifth-generation low power CAPSENSE™. +* +* \param a +* The first argument to calculate difference. +* +* \param b +* The second argument to calculate difference. +* +* \return +* Returns the absolute difference of arguments. +* +*******************************************************************************/ +uint32_t Cy_CapSense_CalculateAbsDiff( + uint32_t a, + uint32_t b) +{ + uint32_t result; + + if (a > b) + { + result = a - b; + } + else + { + result = b - a; + } + return result; +} +#endif + + +/******************************************************************************* +* Function Name: Cy_CapSense_CdacSuccessAppr +****************************************************************************//** +* +* The internal function that performs the specified CDAC successive +* approximation seek for the specified widget. +* +* The function performs some scans of the slots in specified widget in the CPU +* driven scan mode to seek a CDAC value which produce raw counts greater than +* the configured target. +* The function usage is limited by the CapDAC auto-calibration. +* +* \note +* This function is available only +* for the fifth-generation low power CAPSENSE™. +* +* \param widgetId +* The widget ID scans will be done for. +* +* \param rowFlag +* The flag for a row/column sensors calibration. +* CY_CAPSENSE_ROW_SNS_CALIBRATION - perform calibration for rows. +* CY_CAPSENSE_COL_SNS_CALIBRATION - perform calibration for columns. +* +* \param calibrMask +* The mask for further calibration. +* +* \param cdacPtr +* The pointer to the CDAC field in data structure. +* +* \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_CALIBRATION_FAIL - The calibration is failed due to +* the issues with scanning (either +* watchdog timer, interrupt breaking, etc.). +* +*******************************************************************************/ +cy_capsense_status_t Cy_CapSense_CdacSuccessAppr( + uint32_t widgetId, + uint32_t rowFlag, + uint8_t calibrMask, + uint8_t * cdacPtr, + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t calibrationStatus = CY_CAPSENSE_STATUS_SUCCESS; + uint32_t rawTarget; + uint32_t minRaw = 0u; + uint32_t csdScanEn = CY_CAPSENSE_DISABLE; + uint32_t cdacMask = calibrMask; + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) + uint32_t advancedSearchFlag = CY_CAPSENSE_DISABLE; + uint32_t minRawAbs = CY_CAPSENSE_16_BIT_MASK; + uint8_t minRawCode = 0u; + uint32_t tmpRaw; + + if (CY_CAPSENSE_DISABLE == (context->ptrWdConfig[widgetId].cdacConfig & CY_CAPSENSE_CDAC_FINE_MODE_AUTO_MASK)) + { + advancedSearchFlag = CY_CAPSENSE_ENABLE; + } + #endif + + /* Dummy scan */ + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) + if (CY_CAPSENSE_CSX_GROUP == context->ptrWdConfig[widgetId].senseMethod) + { + calibrationStatus |= Cy_CapSense_ScanWidgetInternalCPU(widgetId, context); + } + #endif + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) + if (CY_CAPSENSE_CSD_GROUP == context->ptrWdConfig[widgetId].senseMethod) + { + /* Set CSD scan flag */ + csdScanEn = CY_CAPSENSE_ENABLE; + /* Clear flag as compensation CapDAC code for MPSC widgets should be increased unlike reference CapDAC */ + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED) + if (CY_CAPSENSE_MPSC_MIN_ORDER <= context->ptrWdConfig[widgetId].mpOrder) + { + csdScanEn = CY_CAPSENSE_DISABLE; + } + #endif + } + #endif + + rawTarget = Cy_CapSense_CalculateRawTarget(widgetId, rowFlag, context); + *cdacPtr = 0u; + + while (cdacMask != 0u) + { + *cdacPtr |= (uint8_t)cdacMask; + Cy_CapSense_SetWidgetFrameRefCdacCodes(widgetId, context); + + calibrationStatus |= Cy_CapSense_ScanWidgetInternalCPU(widgetId, context); + Cy_CapSense_PreProcessWidget(widgetId, context); + /* Find minimal capacitance across sensors in widget */ + minRaw = Cy_CapSense_MinRawSearch(widgetId, rowFlag, context); + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) + if (CY_CAPSENSE_DISABLE != advancedSearchFlag) + { + tmpRaw = Cy_CapSense_CalculateAbsDiff(minRaw, rawTarget); + if (tmpRaw < minRawAbs) + { + minRawAbs = tmpRaw; + minRawCode = *cdacPtr; + } + } + #endif + + if (((csdScanEn == CY_CAPSENSE_ENABLE) && (minRaw < rawTarget)) || + ((csdScanEn == CY_CAPSENSE_DISABLE) && (minRaw >= rawTarget))) + { + *cdacPtr &= (uint8_t)~cdacMask; + } + cdacMask >>= 1u; + } + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) + if (CY_CAPSENSE_DISABLE != advancedSearchFlag) + { + *cdacPtr = minRawCode; + } + #endif + + return calibrationStatus; +} + + +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) +/******************************************************************************* +* Function Name: Cy_CapSense_CalibrateRefCdac +****************************************************************************//** +* +* The internal function that performs the reference CDAC successive +* approximation seek for the specified widget with compensation CDAC disabled. +* +* The function performs up to 9 scans of the slots in specified widget in the CPU +* driven scan mode to seek for a minimal reference CDAC value needed to match +* count target. +* +* The function usage is limited by the CapDAC auto-calibration. +* +* \note +* This function is available only +* for the fifth-generation low power CAPSENSE™. +* +* \param widgetId +* The widget ID scans will be done for. +* +* \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_CALIBRATION_FAIL - The calibration is failed due to +* the issues with scanning (either +* watchdog timer, interrupt breaking, etc.). +* +*******************************************************************************/ +cy_capsense_status_t Cy_CapSense_CalibrateRefCdac( + uint32_t widgetId, + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t calibrationStatus = CY_CAPSENSE_STATUS_SUCCESS; + cy_stc_capsense_widget_context_t * ptrWdCxt = &context->ptrWdContext[widgetId]; + + calibrationStatus |= Cy_CapSense_CdacSuccessAppr(widgetId, CY_CAPSENSE_ROW_SNS_CALIBRATION, CY_CAPSENSE_CAL_REF_CDAC_MIDDLE_CODE, &ptrWdCxt->cdacRef, context); + + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + if ((CY_CAPSENSE_CSD_GROUP == context->ptrWdConfig[widgetId].senseMethod) && + (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == context->ptrWdConfig[widgetId].wdType) || + ((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == context->ptrWdConfig[widgetId].wdType))) + { + calibrationStatus |= Cy_CapSense_CdacSuccessAppr(widgetId, CY_CAPSENSE_COL_SNS_CALIBRATION, CY_CAPSENSE_CAL_REF_CDAC_MIDDLE_CODE, &ptrWdCxt->rowCdacRef, context); + + /* Align Reference CDAC rows and cols if enabled */ + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_ROW_COL_ALIGN_EN) + if (ptrWdCxt->cdacRef < ptrWdCxt->rowCdacRef) + { + ptrWdCxt->cdacRef = ptrWdCxt->rowCdacRef; + } + ptrWdCxt->rowCdacRef = ptrWdCxt->cdacRef; + #endif + } + #endif + + return calibrationStatus; +} +#endif + + +#if (CY_CAPSENSE_CDAC_FINE_USAGE) +/******************************************************************************* +* Function Name: Cy_CapSense_CalibrateFineCdac +****************************************************************************//** +* +* The internal function that performs the fine CDAC successive +* approximation seek for the specified widget with compensation CDAC disabled and +* fixed reference CDAC. +* +* The function performs up to 6 scans of the slots in specified widget in the CPU +* driven scan mode to seek for a minimal fine CDAC value needed to match +* count target. +* +* The function usage is limited by the CapDAC auto-calibration. +* +* \note +* This function is available only +* for the fifth-generation low power CAPSENSE™. +* +* \param widgetId +* The widget ID scans will be done for. +* +* \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_CALIBRATION_FAIL - The calibration is failed due to +* the issues with scanning (either +* watchdog timer, interrupt breaking, etc.). +* +*******************************************************************************/ +cy_capsense_status_t Cy_CapSense_CalibrateFineCdac( + uint32_t widgetId, + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t calibrationStatus = CY_CAPSENSE_STATUS_SUCCESS; + cy_stc_capsense_widget_context_t * ptrWdCxt = &context->ptrWdContext[widgetId]; + + calibrationStatus |= Cy_CapSense_CdacSuccessAppr(widgetId, CY_CAPSENSE_ROW_SNS_CALIBRATION, CY_CAPSENSE_CAL_FINE_CDAC_MIDDLE_CODE, &ptrWdCxt->cdacFine, context); + + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + if ((CY_CAPSENSE_CSD_GROUP == context->ptrWdConfig[widgetId].senseMethod) && + (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == context->ptrWdConfig[widgetId].wdType) || + ((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == context->ptrWdConfig[widgetId].wdType))) + { + calibrationStatus |= Cy_CapSense_CdacSuccessAppr(widgetId, CY_CAPSENSE_COL_SNS_CALIBRATION, CY_CAPSENSE_CAL_FINE_CDAC_MIDDLE_CODE, &ptrWdCxt->rowCdacFine, context); + + /* Align Fine CDAC rows and cols if enabled */ + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_ROW_COL_ALIGN_EN) + if (ptrWdCxt->cdacFine < ptrWdCxt->rowCdacFine) + { + ptrWdCxt->cdacFine = ptrWdCxt->rowCdacFine; + } + ptrWdCxt->rowCdacFine = ptrWdCxt->cdacFine; + #endif + } + #endif + + return calibrationStatus; +} +#endif + + +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_COMP_DIV_AUTO_EN) +/******************************************************************************* +* Function Name: Cy_CapSense_CalibrateCompDivider +****************************************************************************//** +* +* This function adjusts the compensation CDAC divider for the specified widget. +* +* The function scans all widget sensors with fixed reference CDAC and maximum +* compensation CDAC values starting from the compensation CDAC divider value +* equal to the snsClk divider (Kcomp = snsClkDiv / CompDiv = 1). If raw counts +* are over the raw target, the function decreases compensation CDAC divider +* value providing Kcomp as integer until raw counts are less than the raw +* target. +* +* The function does not consider multi-frequency feature. I.e. only the first +* (base) frequency channel is used. +* +* \param widgetId +* Specifies the desired widget 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. +* The compensation CDAC divider is adjusted +* for the specified widget. +* - CY_CAPSENSE_STATUS_CALIBRATION_FAIL - The compensation CDAC divider can not be +* adjusted for the specified widget. +* - CY_CAPSENSE_STATUS_BAD_PARAM - Invalid parameter(s). +* +*******************************************************************************/ +cy_capsense_status_t Cy_CapSense_CalibrateCompDivider( + uint32_t widgetId, + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t calibStatus = CY_CAPSENSE_STATUS_SUCCESS; + uint32_t curSlotIndex; + uint32_t numSlots; + uint32_t snsOverflow = 0u; + uint32_t snsIndex; + uint32_t rawTemp; + uint32_t frameType; + uint32_t rawTarget; + uint32_t j; + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) + uint32_t dummyScanFlagEn = 1u; + #endif + + const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId]; + uint32_t compDivDefault = ptrWdCfg->ptrWdContext->snsClk; + const cy_stc_capsense_scan_slot_t * ptrScanSlots; + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) + if ((uint8_t)CY_CAPSENSE_WD_LOW_POWER_E == ptrWdCfg->wdType) + { + numSlots = CY_CAPSENSE_SLOT_LP_COUNT; + frameType = CY_CAPSENSE_SNS_FRAME_LOW_POWER; + ptrScanSlots = context->ptrLpScanSlots; + } + else + #endif + { + numSlots = CY_CAPSENSE_SLOT_COUNT; + frameType = CY_CAPSENSE_SNS_FRAME_ACTIVE; + ptrScanSlots = context->ptrScanSlots; + } + + /* Sets Max CompCDAC Code within specified widget */ + for (j = 0u; j < ptrWdCfg->numSns; j++) + { + ptrWdCfg->ptrSnsContext[j].cdacComp = CY_CAPSENSE_CDAC_MAX_CODE; + } + Cy_CapSense_SetWidgetFrameCompCdacCode(widgetId, CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_MAX, context); + + /* Defines initial value for Compensation Divider including rows and cols */ + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) ||\ + (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && + (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType) || + ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType))) + { + if (compDivDefault > ptrWdCfg->ptrWdContext->rowSnsClk) + { + compDivDefault = ptrWdCfg->ptrWdContext->rowSnsClk; + } + } + else + { + /* Initializes unused rowSnsClk for further optimization */ + ptrWdCfg->ptrWdContext->rowSnsClk = ptrWdCfg->ptrWdContext->snsClk; + } + #else + /* Initializes unused rowSnsClk for further optimization */ + ptrWdCfg->ptrWdContext->rowSnsClk = ptrWdCfg->ptrWdContext->snsClk; + #endif + + rawTarget = Cy_CapSense_CalculateRawTarget(widgetId, CY_CAPSENSE_ROW_SNS_CALIBRATION, context); + + compDivDefault++; + + /* + * Loop through all Compensation Divider values in descending order. + * + * Loop ends when CompDiv value equal 1 or Calibration fails. + * Switches to the next iteration is done when kComp is not an integer + * or calibration overflows. + */ + do + { + /* Switches to the next possible divider */ + compDivDefault--; + /* Checks if divider is valid */ + if (((ptrWdCfg->ptrWdContext->snsClk % compDivDefault) != 0u) || + ((ptrWdCfg->ptrWdContext->rowSnsClk % compDivDefault) != 0u)) + { + continue; + } + + ptrWdCfg->ptrWdContext->cdacCompDivider = (uint16_t)compDivDefault; + Cy_CapSense_SetCompDivider(widgetId, context); + + snsOverflow = 0u; + for (curSlotIndex = 0u; curSlotIndex < numSlots; curSlotIndex++) + { + /* Checks only the specified widget in the current slot */ + if (widgetId == ptrScanSlots[curSlotIndex].wdId) + { + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) + /* Dummy scan */ + if ((0u != dummyScanFlagEn) && (CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod)) + { + calibStatus |= Cy_CapSense_ScanSlotInternalCPU(frameType, curSlotIndex, context); + dummyScanFlagEn = 0u; + } + #endif + + calibStatus |= Cy_CapSense_ScanSlotInternalCPU(frameType, curSlotIndex, context); + + snsIndex = ptrScanSlots[curSlotIndex].snsId; + Cy_CapSense_PreProcessSensor(widgetId, snsIndex, context); + rawTemp = ptrWdCfg->ptrSnsContext[snsIndex].raw; + + switch (ptrWdCfg->senseMethod) + { + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) + case CY_CAPSENSE_CSD_GROUP: + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED) + /* Skip the CSD case for MPSC widgets */ + if (CY_CAPSENSE_MPSC_MIN_ORDER > ptrWdCfg->mpOrder) + #endif + { + if (rawTemp > rawTarget) + { + snsOverflow = 1u; + } + break; + } + #endif + + default: + if (rawTemp <= rawTarget) + { + snsOverflow = 1u; + } + break; + } + + if (0u != snsOverflow) + { + /* If at least one sensor of the specified widget has + * Raw Count too high (no enough compensation level) + * then switch to the next compensation divider value. + */ + break; + } + } + } + /* Finish the searching if no overflow across all sensors of the specified widget */ + if (0u == snsOverflow) + { + break; + } + } while ((compDivDefault > CY_CAPSENSE_CDAC_COMP_DIV_MIN_MSCLP) && + (CY_CAPSENSE_STATUS_SUCCESS == calibStatus)); + + return calibStatus; +} +#endif + + +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_COMP_AUTO_EN) +/******************************************************************************* +* Function Name: Cy_CapSense_CalibrateCompCdac +****************************************************************************//** +* +* The internal function that performs the compensation CDAC successive +* approximation seek for the specified widget with fixed reference CDAC and +* fixed compensation divider. +* +* The function performs up to 9 scans of the slots in specified widget in the CPU +* driven scan mode to seek for a minimal compensation CDAC value needed to match +* count target. +* +* The function usage is limited by the CapDAC auto-calibration. +* +* \note +* This function is available only +* for the fifth-generation low power CAPSENSE™. +* +* \param widgetId +* The widget ID scans will be done for. +* +* \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_CALIBRATION_FAIL - The calibration is failed due to +* the issues with scanning (either +* watchdog timer, interrupt breaking, etc.). +* +*******************************************************************************/ +cy_capsense_status_t Cy_CapSense_CalibrateCompCdac( + uint32_t widgetId, + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t calibStatus = CY_CAPSENSE_STATUS_SUCCESS; + cy_stc_capsense_widget_config_t const * ptrWdCfg = &context->ptrWdConfig[widgetId]; + cy_stc_capsense_sensor_context_t * ptrSnsCxt; + uint8_t cdacMask; + uint32_t rawTarget; + uint32_t snsIndex; + uint32_t sensingGroup = context->ptrWdConfig[widgetId].senseMethod; + uint32_t csdScanEn = CY_CAPSENSE_DISABLE; + + /* Calculate raw target for current sensing method */ + rawTarget = Cy_CapSense_CalculateRawTarget(widgetId, CY_CAPSENSE_ROW_SNS_CALIBRATION, context); + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) + /* Dummy scan */ + if (CY_CAPSENSE_CSX_GROUP == sensingGroup) + { + calibStatus |= Cy_CapSense_ScanWidgetInternalCPU(widgetId, context); + } + #endif + + for (snsIndex = 0u; snsIndex < (uint32_t)ptrWdCfg->numSns; snsIndex++) + { + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) if ((CY_CAPSENSE_CSD_GROUP == sensingGroup) && (ptrWdCfg->numCols <= snsIndex) && (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType) || ((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType))) { - ptrSnsFrmCdacCtlReg[snsFrameIndex] &= (uint32_t)~(MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Msk | - MSCLP_SNS_SNS_CDAC_CTL_SEL_CF_Msk); - ptrSnsFrmCdacCtlReg[snsFrameIndex] |= (((uint32_t)*rowCdacRefPtr) << MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Pos); - #if (CY_CAPSENSE_CDAC_FINE_USAGE) - ptrSnsFrmCdacCtlReg[snsFrameIndex] |= (((uint32_t)*rowCdacFinePtr) << MSCLP_SNS_SNS_CDAC_CTL_SEL_CF_Pos); - #endif + rawTarget = Cy_CapSense_CalculateRawTarget(widgetId, CY_CAPSENSE_COL_SNS_CALIBRATION, context); } #endif + + if (CY_CAPSENSE_CSD_GROUP == sensingGroup) + { + /* Set CSD scan flag */ + csdScanEn = CY_CAPSENSE_ENABLE; + /* Clear flag as compensation CapDAC code for MPSC widgets should be increased unlike reference CapDAC */ + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED) + if (CY_CAPSENSE_MPSC_MIN_ORDER <= ptrWdCfg->mpOrder) + { + csdScanEn = CY_CAPSENSE_DISABLE; + } + #endif + } + + cdacMask = (uint8_t)CY_CAPSENSE_CAL_COMP_CDAC_MIDDLE_CODE; + ptrSnsCxt = &ptrWdCfg->ptrSnsContext[snsIndex]; + ptrSnsCxt->cdacComp = 0u; + Cy_CapSense_SetWidgetFrameCompCdacCode(widgetId, CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_MIN, context); + + while (0u != cdacMask) + { + ptrSnsCxt->cdacComp |= cdacMask; + Cy_CapSense_SetWidgetFrameCompCdacCode(widgetId, CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_VAL, context); + + calibStatus |= Cy_CapSense_ScanWidgetInternalCPU(widgetId, context); + Cy_CapSense_PreProcessWidget(widgetId, context); + + if (calibStatus == CY_CAPSENSE_STATUS_SUCCESS) + { + if (((csdScanEn == CY_CAPSENSE_ENABLE) && ((uint32_t)ptrSnsCxt->raw < rawTarget)) || + ((csdScanEn == CY_CAPSENSE_DISABLE) && ((uint32_t)ptrSnsCxt->raw >= rawTarget))) + { + ptrSnsCxt->cdacComp &= ~cdacMask; + } + + cdacMask >>= 1u; + } + else + { + break; + } + } } return calibStatus; } +#endif + + +#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_FINE_AUTO_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_COMP_DIV_AUTO_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_COMP_AUTO_EN)) +/******************************************************************************* +* Function Name: Cy_CapSense_CalculateRawTarget +****************************************************************************//** +* +* The internal function that calculates the auto-calibration target in +* raw counts. +* +* \note +* This function is available only +* for the fifth-generation low power CAPSENSE™. +* +* \param widgetId +* The widget ID calculation will be done for. +* +* \param rowFlag +* The flag for a row/column raw target calculation. +* CY_CAPSENSE_ROW_SNS_CALIBRATION - target calculation performed for rows. +* CY_CAPSENSE_COL_SNS_CALIBRATION - target calculation performed for columns. +* +* \param context +* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. +* +* \return +* Returns the raw count target for widget sensing method. +* +*******************************************************************************/ +uint32_t Cy_CapSense_CalculateRawTarget( + uint32_t widgetId, + uint32_t rowFlag, + cy_stc_capsense_context_t * context) +{ + uint32_t rawTarget; + + /* Calculate raw target for current sensing method */ + switch (context->ptrWdConfig[widgetId].senseMethod) + { + #if (CY_CAPSENSE_CSD_CDAC_CALIBRATION_USAGE) + case CY_CAPSENSE_CSD_GROUP: + rawTarget = context->ptrInternalContext->intrCsdRawTarget; + break; + #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN) */ + + #if (CY_CAPSENSE_CSX_CDAC_CALIBRATION_USAGE) + case CY_CAPSENSE_CSX_GROUP: + rawTarget = context->ptrInternalContext->intrCsxRawTarget; + break; + #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN) */ + + #if (CY_CAPSENSE_ISX_CDAC_CALIBRATION_USAGE) + case CY_CAPSENSE_ISX_GROUP: + rawTarget = context->ptrInternalContext->intrIsxRawTarget; + break; + #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN) */ + + default: + /* Widget type is not valid */ + rawTarget = 0u; + break; + } + + if (CY_CAPSENSE_ROW_SNS_CALIBRATION == rowFlag) + { + rawTarget *= context->ptrWdContext[widgetId].maxRawCount; + } + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + else + { + rawTarget *= context->ptrWdContext[widgetId].maxRawCountRow; + } + #endif + + rawTarget /= CY_CAPSENSE_PERCENTAGE_100; + + return rawTarget; +} +#endif /******************************************************************************* @@ -2218,9 +2849,7 @@ cy_capsense_status_t Cy_CapSense_CdacSuccessAppr( * - 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_ScanSlotInternalCPU( @@ -2261,7 +2890,7 @@ cy_capsense_status_t Cy_CapSense_ScanSlotInternalCPU( snsIndex = ptrScanSlots[scanSlotId].snsId; ptrWdCfg = &context->ptrWdConfig[wdIndex]; - if((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && + if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && (CY_CAPSENSE_MPSC_MIN_ORDER <= ptrWdCfg->mpOrder)) { result = Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_MPSC_SCANNING, context); @@ -2283,7 +2912,7 @@ cy_capsense_status_t Cy_CapSense_ScanSlotInternalCPU( watchdog = Cy_CapSense_WaitEndOfCpuScan(watchdog, context); /* Check if the watchdog timeout happened */ - if(0u == watchdog) + if (0u == watchdog) { result = CY_CAPSENSE_STATUS_CALIBRATION_FAIL; } @@ -2335,6 +2964,62 @@ cy_capsense_status_t Cy_CapSense_ScanSlotInternalCPU( (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_CALIBRATION_EN)) */ +#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)) +/******************************************************************************* +* Function Name: Cy_CapSense_ScanWidgetInternalCPU +****************************************************************************//** +* +* Initiates the blocking scan of specified widget in CPU mode. +* +* This function initiates a scan of specified widget in the CPU driven scan +* mode, waits for operation completion and then exits. +* Use of this function is limited to the CapDAC auto-calibration. +* +* \note +* This function is available only for the fifth-generation low power CAPSENSE™. +* +* \param widgetId +* The widget ID scans will be done for. +* +* \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_t Cy_CapSense_ScanWidgetInternalCPU( + uint32_t widgetId, + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t result = CY_CAPSENSE_STATUS_SUCCESS; + cy_stc_capsense_widget_config_t const * ptrWdCfg = &context->ptrWdConfig[widgetId]; + uint32_t currSlot; + uint32_t snsFrameType = CY_CAPSENSE_SNS_FRAME_ACTIVE; + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) + if ((ptrWdCfg->wdType == (uint8_t)CY_CAPSENSE_WD_LOW_POWER_E)) + { + snsFrameType = CY_CAPSENSE_SNS_FRAME_LOW_POWER; + } + #endif + + for (currSlot = ptrWdCfg->firstSlotId; currSlot < ((uint32_t)ptrWdCfg->firstSlotId + ptrWdCfg->numSlots); currSlot++) + { + result |= Cy_CapSense_ScanSlotInternalCPU(snsFrameType, currSlot, context); + } + + return result; +} +#endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_CALIBRATION_EN)) */ + + /******************************************************************************* * Function Name: Cy_CapSense_WatchdogCyclesNum ****************************************************************************//** @@ -2456,11 +3141,23 @@ cy_capsense_status_t Cy_CapSense_SsInitialize(cy_stc_capsense_context_t * contex capStatus |= Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_REGULAR_SCANNING, context); } + #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) && \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC_RATE_MODE_AUTO_EN)) + capStatus |= Cy_CapSense_InitializeCic2Rate(context); + #endif + #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) && \ (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_AUTO_EN)) capStatus |= Cy_CapSense_InitializeCic2Shift(context); #endif + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) + if (CY_CAPSENSE_STATUS_SUCCESS == capStatus) + { + capStatus = Cy_CapSense_CdacDitherScaleCalc(context); + } + #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) */ + /* Find maximum raw count for each widget */ for (i = 0u; i < CY_CAPSENSE_TOTAL_WIDGET_COUNT; i++) { @@ -2573,11 +3270,8 @@ void Cy_CapSense_ScanISR(void * capsenseContext) cxt->ptrCommonContext->status |= (uint32_t)CY_CAPSENSE_MW_STATE_LP_ACTIVE_MASK; } - /* Clear all pending interrupts of the MSCLP HW block */ - ptrHwBase->INTR_LP = CY_CAPSENSE_MSCLP_INTR_LP_ALL_MSK; - /* Read the last low power frame raw counts */ - if((cxt->ptrCommonContext->lpDataSt & CY_CAPSENSE_LP_PROCESS_ENABLED_MASK) != 0u) + if ((cxt->ptrCommonContext->lpDataSt & CY_CAPSENSE_LP_PROCESS_ENABLED_MASK) != 0u) { Cy_CapSense_TransferLpRawCounts(ptrIntrCxt->currentSlotIndex, ptrIntrCxt->numSlots, cxt); @@ -2588,6 +3282,10 @@ void Cy_CapSense_ScanISR(void * capsenseContext) /* Disable HW IP */ ptrHwBase->CTL &= (~MSCLP_CTL_ENABLED_Msk); + /* Clear all pending interrupts of the MSCLP HW block */ + ptrHwBase->INTR_LP = CY_CAPSENSE_MSCLP_INTR_LP_ALL_MSK; + (void)ptrHwBase->INTR_LP; + /* Stop the MRSS to save power */ ptrHwBase->MRSS_CMD = MSCLP_MRSS_CMD_MRSS_STOP_Msk; @@ -2598,6 +3296,7 @@ void Cy_CapSense_ScanISR(void * capsenseContext) { /* Clear all pending interrupts of the MSCLP HW block */ ptrHwBase->INTR_LP = CY_CAPSENSE_MSCLP_INTR_LP_ALL_MSK; + (void)ptrHwBase->INTR_LP; /* Read the last ACTIVE frame raw counts */ Cy_CapSense_TransferRawCounts(ptrIntrCxt->currentSlotIndex, ptrIntrCxt->numSlots, cxt); @@ -3013,339 +3712,139 @@ cy_capsense_status_t Cy_CapSense_ScanAbort_V3Lp(cy_stc_capsense_context_t * cont (void)ptrChannelCfg->ptrHwBase->INTR_LP; Cy_SysLib_ExitCriticalSection(interruptState); - - /* Wait for possible MRSS status change */ - Cy_SysLib_DelayUs(CY_MSCLP_CLK_LF_PERIOD_MAX * CY_MSCLP_MRSS_TIMEOUT_FULL); - - /* Set required MRSS state */ - if (CY_CAPSENSE_MRSS_TURN_ON == context->ptrInternalContext->mrssStateAfterScan) - { - if (0u == (ptrCommonCfg->ptrChConfig->ptrHwBase->MRSS_STATUS & MSCLP_MRSS_STATUS_MRSS_UP_Msk)) - { - ptrCommonCfg->ptrChConfig->ptrHwBase->MRSS_CMD = MSCLP_MRSS_CMD_MRSS_START_Msk; - (void)Cy_CapSense_WaitMrssStatusChange(CY_MSCLP_CLK_LF_PERIOD_MAX * CY_MSCLP_MRSS_TIMEOUT_SMALL, CY_CAPSENSE_MRSS_TURN_ON, context); - } - } - else - { - if (0u != (ptrCommonCfg->ptrChConfig->ptrHwBase->MRSS_STATUS & MSCLP_MRSS_STATUS_MRSS_UP_Msk)) - { - ptrCommonCfg->ptrChConfig->ptrHwBase->MRSS_CMD = MSCLP_MRSS_CMD_MRSS_STOP_Msk; - (void)Cy_CapSense_WaitMrssStatusChange((CY_MSCLP_CLK_LF_PERIOD_MAX * CY_CAPSENSE_MULTIPLIER_TWO), CY_CAPSENSE_MRSS_TURN_OFF, context); - } - } - - context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY; - - return CY_CAPSENSE_STATUS_SUCCESS; -} - - -/******************************************************************************* -* Function Name: Cy_CapSense_MwState_V3Lp -****************************************************************************//** -* -* This function returns a detailed state of the CAPSENSE™ middleware and MSC -* hardware in Single- or Multi-channel mode. This feature is useful in -* multi-thread applications or in ISR. -* -* If the middleware is busy, do not initiate a new scan or set up widgets. -* Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. -* Use the Cy_CapSense_MwState() function to verify if MW executes any firmware -* tasks related to initialization, scanning, and processing at a particular moment. -* If the middleware is busy, a new scan, setup widgets, any kind of reconfiguration, -* or parameter change should not be initiated. -* -* \param context -* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. -* -* \return -* Returns the state of the middleware as a sum of the state and status masks: -* -* - CY_CAPSENSE_BUSY_CH_MASK - The set [x] bit of the result -* means that the previously initiated -* scan for the [x] channel is in progress. -* The next scan frame cannot be started. -* - CY_CAPSENSE_MW_STATE_ACTIVE_WD_SCAN_MASK - The last or currently scanned widget -* type is Active widget. -* - CY_CAPSENSE_MW_STATE_LP_WD_SCAN_MASK - The last or currently scanned widget -* type is Low Power widget -* - CY_CAPSENSE_BUSY - The previously initiated scan is -* in progress. -* - CY_CAPSENSE_MW_STATE_BIST_MASK - The BIST is in progress. -* The next scan frame cannot be started. -* - CY_CAPSENSE_MW_STATE_CALIBRATION_MASK - The auto-calibration is in progress. -* The next scan frame cannot be started. -* - CY_CAPSENSE_MW_STATE_SMARTSENSE_MASK - The smart sensing algorithm is -* in progress. -* The next scan frame cannot be started. -* - CY_CAPSENSE_MW_STATE_INITIALIZATION_MASK - Middleware initialization is -* in progress and the next scan frame -* cannot be initiated. -* - CY_CAPSENSE_MW_STATE_SCAN_SLOT_MASK[x] - The set [x] number of the result -* means that the previously initiated -* scan for the [x] slot is completed -* or in progress. -* -*******************************************************************************/ -cy_capsense_mw_state_t Cy_CapSense_MwState_V3Lp(const cy_stc_capsense_context_t * context) -{ - return ((context->ptrCommonContext->status & ~CY_CAPSENSE_MW_STATE_SCAN_SLOT_MASK) | - ((uint32_t)context->ptrInternalContext->currentSlotIndex << CY_CAPSENSE_MW_STATE_SCAN_SLOT_POS)); -} - - -/******************************************************************************* -* 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 |= (((uint32_t)CY_CAPSENSE_BUSY_CH_MASK) | 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 for the current channel */ - context->ptrCommonContext->status &= (uint32_t)(~((uint32_t)CY_CAPSENSE_BUSY_CH_MASK)); - context->ptrCommonContext->status &= ~CY_CAPSENSE_BUSY; - - /* Check for EndOfScan callback */ - if (NULL != context->ptrInternalContext->ptrEOSCallback) - { - context->ptrInternalContext->ptrEOSCallback(NULL); - } -} - - -#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)) -/******************************************************************************* -* Function Name: Cy_CapSense_CalibrateCompDivider -****************************************************************************//** -* -* This function adjusts the compensation CDAC divider for the specified widget. -* -* The function scans all widget sensors with fixed reference CDAC and maximum -* compensation CDAC values starting from the compensation CDAC divider value -* equal to the snsClk divider (Kcomp = snsClkDiv / CompDiv = 1). If raw counts -* are over the raw target, the function decreases compensation CDAC divider -* value providing Kcomp as integer until raw counts are less than the raw -* target. -* -* The function does not consider multi-frequency feature. I.e. only the first -* (base) frequency channel is used. -* -* \param widgetId -* Specifies the desired widget ID. -* -* \param target -* The calibrated sensor raw target. -* -* \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. -* The compensation CDAC divider is adjusted -* for the specified widget. -* - CY_CAPSENSE_STATUS_CALIBRATION_FAIL - The compensation CDAC divider can not be -* adjusted for the specified widget. -* - CY_CAPSENSE_STATUS_BAD_PARAM - Invalid parameter(s). -* -*******************************************************************************/ -cy_capsense_status_t Cy_CapSense_CalibrateCompDivider( - uint32_t widgetId, - uint32_t target, - cy_stc_capsense_context_t * context) -{ - cy_capsense_status_t calibStatus = CY_CAPSENSE_STATUS_SUCCESS; - uint32_t curSlotIndex; - uint32_t numSlots; - uint32_t snsOverflow = 0u; - uint32_t snsIndex; - uint32_t rawTemp; - uint32_t frameType; - uint32_t rawTarget; - uint32_t j; - - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) - uint32_t dummyScanFlagEn = 1u; - #endif - - const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId]; - uint32_t compDivDefault = ptrWdCfg->ptrWdContext->snsClk; - const cy_stc_capsense_scan_slot_t * ptrScanSlots; - - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) - if ((uint8_t)CY_CAPSENSE_WD_LOW_POWER_E == ptrWdCfg->wdType) - { - numSlots = CY_CAPSENSE_SLOT_LP_COUNT; - frameType = CY_CAPSENSE_SNS_FRAME_LOW_POWER; - ptrScanSlots = context->ptrLpScanSlots; - } - else - { - numSlots = CY_CAPSENSE_SLOT_COUNT; - frameType = CY_CAPSENSE_SNS_FRAME_ACTIVE; - ptrScanSlots = context->ptrScanSlots; - } - #else - numSlots = CY_CAPSENSE_SLOT_COUNT; - frameType = CY_CAPSENSE_SNS_FRAME_ACTIVE; - ptrScanSlots = context->ptrScanSlots; - #endif - - /* Sets Max CompCDAC Code within specified widget */ - for (j = 0u; j < ptrWdCfg->numSns; j++) - { - ptrWdCfg->ptrSnsContext[j].cdacComp = CY_CAPSENSE_CDAC_MAX_CODE; - } - Cy_CapSense_SetMaxCompCdac(widgetId, context); - - /* Defines initial value for Compensation Divider including rows and cols */ - #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) ||\ - (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) - if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && - (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType) || - ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType))) - { - if (compDivDefault > ptrWdCfg->ptrWdContext->rowSnsClk) - { - compDivDefault = ptrWdCfg->ptrWdContext->rowSnsClk; - } - } - else - { - /* Initializes unused rowSnsClk for further optimization */ - ptrWdCfg->ptrWdContext->rowSnsClk = ptrWdCfg->ptrWdContext->snsClk; - } - #else - /* Initializes unused rowSnsClk for further optimization */ - ptrWdCfg->ptrWdContext->rowSnsClk = ptrWdCfg->ptrWdContext->snsClk; - #endif - - /* Recalculate maxRawCount accordingly to frequency channel */ - rawTarget = (target * ptrWdCfg->ptrWdContext->maxRawCount) / CY_CAPSENSE_PERCENTAGE_100; - - compDivDefault++; - - /* - * Loop through all Compensation Divider values in descending order. - * - * Loop ends when CompDiv value equal 1 or Calibration fails. - * Switches to the next iteration is done when kComp is not an integer - * or calibration overflows. - */ - do + + /* Wait for possible MRSS status change */ + Cy_SysLib_DelayUs(CY_MSCLP_CLK_LF_PERIOD_MAX * CY_MSCLP_MRSS_TIMEOUT_FULL); + + /* Set required MRSS state */ + if (CY_CAPSENSE_MRSS_TURN_ON == context->ptrInternalContext->mrssStateAfterScan) { - /* Switches to the next possible divider */ - compDivDefault--; - /* Checks if divider is valid */ - if (((ptrWdCfg->ptrWdContext->snsClk % compDivDefault) != 0u) || - ((ptrWdCfg->ptrWdContext->rowSnsClk % compDivDefault) != 0u)) + if (0u == (ptrCommonCfg->ptrChConfig->ptrHwBase->MRSS_STATUS & MSCLP_MRSS_STATUS_MRSS_UP_Msk)) { - continue; + ptrCommonCfg->ptrChConfig->ptrHwBase->MRSS_CMD = MSCLP_MRSS_CMD_MRSS_START_Msk; + (void)Cy_CapSense_WaitMrssStatusChange(CY_MSCLP_CLK_LF_PERIOD_MAX * CY_MSCLP_MRSS_TIMEOUT_SMALL, CY_CAPSENSE_MRSS_TURN_ON, context); + } + } + else + { + if (0u != (ptrCommonCfg->ptrChConfig->ptrHwBase->MRSS_STATUS & MSCLP_MRSS_STATUS_MRSS_UP_Msk)) + { + ptrCommonCfg->ptrChConfig->ptrHwBase->MRSS_CMD = MSCLP_MRSS_CMD_MRSS_STOP_Msk; + (void)Cy_CapSense_WaitMrssStatusChange((CY_MSCLP_CLK_LF_PERIOD_MAX * CY_CAPSENSE_MULTIPLIER_TWO), CY_CAPSENSE_MRSS_TURN_OFF, context); } + } - ptrWdCfg->ptrWdContext->cdacCompDivider = (uint16_t)compDivDefault; - Cy_CapSense_SetCompDivider(widgetId, context); + context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY; - snsOverflow = 0u; - for (curSlotIndex = 0u; curSlotIndex < numSlots; curSlotIndex++) - { - /* Checks only the specified widget in the current slot */ - if (widgetId == ptrScanSlots[curSlotIndex].wdId) - { - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) - /* Dummy scan */ - if ((0u != dummyScanFlagEn) && (CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod)) - { - calibStatus |= Cy_CapSense_ScanSlotInternalCPU(frameType, curSlotIndex, context); - dummyScanFlagEn = 0u; - } - #endif + return CY_CAPSENSE_STATUS_SUCCESS; +} - calibStatus |= Cy_CapSense_ScanSlotInternalCPU(frameType, curSlotIndex, context); - snsIndex = ptrScanSlots[curSlotIndex].snsId; - Cy_CapSense_PreProcessSensor(widgetId, snsIndex, context); - rawTemp = ptrWdCfg->ptrSnsContext[snsIndex].raw; +/******************************************************************************* +* Function Name: Cy_CapSense_MwState_V3Lp +****************************************************************************//** +* +* This function returns a detailed state of the CAPSENSE™ middleware and MSC +* hardware in Single- or Multi-channel mode. This feature is useful in +* multi-thread applications or in ISR. +* +* If the middleware is busy, do not initiate a new scan or set up widgets. +* Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. +* Use the Cy_CapSense_MwState() function to verify if MW executes any firmware +* tasks related to initialization, scanning, and processing at a particular moment. +* If the middleware is busy, a new scan, setup widgets, any kind of reconfiguration, +* or parameter change should not be initiated. +* +* \param context +* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. +* +* \return +* Returns the state of the middleware as a sum of the state and status masks: +* +* - CY_CAPSENSE_BUSY_CH_MASK - The set [x] bit of the result +* means that the previously initiated +* scan for the [x] channel is in progress. +* The next scan frame cannot be started. +* - CY_CAPSENSE_MW_STATE_ACTIVE_WD_SCAN_MASK - The last or currently scanned widget +* type is Active widget. +* - CY_CAPSENSE_MW_STATE_LP_WD_SCAN_MASK - The last or currently scanned widget +* type is Low Power widget +* - CY_CAPSENSE_BUSY - The previously initiated scan is +* in progress. +* - CY_CAPSENSE_MW_STATE_BIST_MASK - The BIST is in progress. +* The next scan frame cannot be started. +* - CY_CAPSENSE_MW_STATE_CALIBRATION_MASK - The auto-calibration is in progress. +* The next scan frame cannot be started. +* - CY_CAPSENSE_MW_STATE_SMARTSENSE_MASK - The smart sensing algorithm is +* in progress. +* The next scan frame cannot be started. +* - CY_CAPSENSE_MW_STATE_INITIALIZATION_MASK - Middleware initialization is +* in progress and the next scan frame +* cannot be initiated. +* - CY_CAPSENSE_MW_STATE_SCAN_SLOT_MASK[x] - The set [x] number of the result +* means that the previously initiated +* scan for the [x] slot is completed +* or in progress. +* +*******************************************************************************/ +cy_capsense_mw_state_t Cy_CapSense_MwState_V3Lp(const cy_stc_capsense_context_t * context) +{ + return ((context->ptrCommonContext->status & ~CY_CAPSENSE_MW_STATE_SCAN_SLOT_MASK) | + ((uint32_t)context->ptrInternalContext->currentSlotIndex << CY_CAPSENSE_MW_STATE_SCAN_SLOT_POS)); +} - switch (ptrWdCfg->senseMethod) - { - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) - case CY_CAPSENSE_CSD_GROUP: - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED) - /* Skip the CSD case for MPSC widgets */ - if (CY_CAPSENSE_MPSC_MIN_ORDER > ptrWdCfg->mpOrder) - #endif - { - if (rawTemp > rawTarget) - { - snsOverflow = 1u; - } - break; - } - #endif - default: - if (rawTemp <= rawTarget) - { - snsOverflow = 1u; - } - break; - } +/******************************************************************************* +* 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 |= (((uint32_t)CY_CAPSENSE_BUSY_CH_MASK) | CY_CAPSENSE_BUSY); +} - if (0u != snsOverflow) - { - /* If at least one sensor of the specified widget has - * Raw Count too high (no enough compensation level) - * then switch to the next compensation divider value. - */ - break; - } - } - } - /* Finish the searching if no overflow across all sensors of the specified widget */ - if (0u == snsOverflow) - { - break; - } - } while ((compDivDefault > CY_CAPSENSE_CDAC_COMP_DIV_MIN_MSCLP) && - (CY_CAPSENSE_STATUS_SUCCESS == calibStatus)); - return calibStatus; +/******************************************************************************* +* 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 for the current channel */ + context->ptrCommonContext->status &= (uint32_t)(~((uint32_t)CY_CAPSENSE_BUSY_CH_MASK)); + context->ptrCommonContext->status &= ~CY_CAPSENSE_BUSY; + + /* Check for EndOfScan callback */ + if (NULL != context->ptrInternalContext->ptrEOSCallback) + { + context->ptrInternalContext->ptrEOSCallback(NULL); + } } +#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)) /******************************************************************************* * Function Name: Cy_CapSense_VerifyCalibration ****************************************************************************//** @@ -3500,14 +3999,132 @@ cy_capsense_status_t Cy_CapSense_VerifyCalibration( #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) || \ (CY_CAPSENSE_ENABLE == CY_CAPSENSE_ISX_EN)) */ - default: - calibStatus |= CY_CAPSENSE_STATUS_BAD_PARAM; - /* No action */ - break; + default: + calibStatus |= CY_CAPSENSE_STATUS_BAD_PARAM; + /* No action */ + break; + } + } + + return calibStatus; +} + + +/******************************************************************************* +* Function Name: Cy_CapSense_VerifyReferenceCdac +****************************************************************************//** +* +* Verifies the result of reference/fine CapDac calibration. +* +* This function checks whether the minimum raw count of the specified widget +* is within the raw count range defined by raw count target and +/- calibration +* error. +* +* \param widgetId +* Specifies the desired widget 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_CALIBRATION_FAIL - The calibration is failed due to +* the issues with scanning (either +* watchdog timer, interrupt breaking, etc.). +* - CY_CAPSENSE_STATUS_CALIBRATION_REF_CHECK_FAIL - The resulting rawcounts across +* all sensors in widget are out of defined range. +* +*******************************************************************************/ +cy_capsense_status_t Cy_CapSense_VerifyReferenceCdac( + uint32_t widgetId, + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t calibrationStatus = CY_CAPSENSE_STATUS_SUCCESS; + uint32_t target; + uint32_t minRaw; + uint32_t calibrationError; + uint32_t lowerLimit; + uint32_t upperLimit; + + /* Dummy scan */ + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) + if (CY_CAPSENSE_CSX_GROUP == context->ptrWdConfig[widgetId].senseMethod) + { + calibrationStatus |= Cy_CapSense_ScanWidgetInternalCPU(widgetId, context); + } + #endif + calibrationStatus |= Cy_CapSense_ScanWidgetInternalCPU(widgetId, context); + Cy_CapSense_PreProcessWidget(widgetId, context); + + /* Gets target in percentage */ + switch (context->ptrWdConfig[widgetId].senseMethod) + { + #if (CY_CAPSENSE_CSD_CDAC_CALIBRATION_USAGE) + case (uint8_t)CY_CAPSENSE_CSD_GROUP: + calibrationError = (uint32_t)context->ptrCommonConfig->csdCalibrationError; + target = (uint32_t)context->ptrInternalContext->intrCsdRawTarget; + break; + #endif + + #if (CY_CAPSENSE_CSX_CDAC_CALIBRATION_USAGE) + case (uint8_t)CY_CAPSENSE_CSX_GROUP: + calibrationError = (uint32_t)context->ptrCommonConfig->csxCalibrationError; + target = (uint32_t)context->ptrInternalContext->intrCsxRawTarget; + break; + #endif + + #if (CY_CAPSENSE_ISX_CDAC_CALIBRATION_USAGE) + case (uint8_t)CY_CAPSENSE_ISX_GROUP: + calibrationError = (uint32_t)context->ptrCommonConfig->isxCalibrationError; + target = (uint32_t)context->ptrInternalContext->intrIsxRawTarget; + break; + #endif + + default: + /* Widget type is not valid */ + target = 0u; + calibrationError = 0u; + calibrationStatus = CY_CAPSENSE_STATUS_BAD_PARAM; + break; + } + + minRaw = Cy_CapSense_MinRawSearch(widgetId, CY_CAPSENSE_ROW_SNS_CALIBRATION, context); + + lowerLimit = 0u; + if (target > calibrationError) + { + lowerLimit = target - calibrationError; + } + upperLimit = target + calibrationError; + if (upperLimit > CY_CAPSENSE_PERCENTAGE_100) + { + upperLimit = CY_CAPSENSE_PERCENTAGE_100; + } + + if ((minRaw < ((context->ptrWdContext[widgetId].maxRawCount * lowerLimit) / CY_CAPSENSE_PERCENTAGE_100)) || + (minRaw > ((context->ptrWdContext[widgetId].maxRawCount * upperLimit) / CY_CAPSENSE_PERCENTAGE_100))) + { + calibrationStatus |= CY_CAPSENSE_STATUS_CALIBRATION_REF_CHECK_FAIL; + } + + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + if ((CY_CAPSENSE_CSD_GROUP == context->ptrWdConfig[widgetId].senseMethod) && + (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == context->ptrWdConfig[widgetId].wdType) || + ((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == context->ptrWdConfig[widgetId].wdType))) + { + minRaw = Cy_CapSense_MinRawSearch(widgetId, CY_CAPSENSE_COL_SNS_CALIBRATION, context); + + if ((minRaw < ((context->ptrWdContext[widgetId].maxRawCountRow * lowerLimit) / CY_CAPSENSE_PERCENTAGE_100)) || + (minRaw > ((context->ptrWdContext[widgetId].maxRawCountRow * upperLimit) / CY_CAPSENSE_PERCENTAGE_100))) + { + calibrationStatus |= CY_CAPSENSE_STATUS_CALIBRATION_REF_CHECK_FAIL; + } } - } + #endif - return calibStatus; + return calibrationStatus; } @@ -3577,70 +4194,6 @@ void Cy_CapSense_SetCompDivider( } } } - - -/******************************************************************************* -* Function Name: Cy_CapSense_SetMaxCompCdac -****************************************************************************//** -* -* Sets the maximum Compensation CDAC code into sensor frames. -* -* This function applies maximum Compensation CDAC code for all -* sensors within specified widget in sensor frame structures. -* This function must not be called when AMUX mode is configured. -* -* \param widgetId -* Specifies widget 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. -* -*******************************************************************************/ -void Cy_CapSense_SetMaxCompCdac( - uint32_t widgetId, - cy_stc_capsense_context_t * context) -{ - uint32_t i; - uint32_t * currentFramePtr; - const cy_stc_capsense_scan_slot_t * ptrScanSlots; - - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) - if (((uint8_t)CY_CAPSENSE_WD_LOW_POWER_E == context->ptrWdConfig[widgetId].wdType)) - { - ptrScanSlots = context->ptrLpScanSlots; - currentFramePtr = &context->ptrSensorFrameLpContext[CY_CAPSENSE_FRM_LP_SNS_CDAC_CTL_INDEX]; - - for (i = 0u; i < CY_CAPSENSE_SLOT_LP_COUNT; i++) - { - if (ptrScanSlots->wdId == widgetId) - { - *currentFramePtr |= MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Msk; - } - ptrScanSlots++; - currentFramePtr = ¤tFramePtr[CY_MSCLP_11_SNS_REGS]; - } - } - else - #endif - { - ptrScanSlots = context->ptrScanSlots; - currentFramePtr = &context->ptrSensorFrameContext[CY_CAPSENSE_SNS_CDAC_CTL_INDEX]; - - for (i = 0u; i < CY_CAPSENSE_SLOT_COUNT; i++) - { - if (ptrScanSlots->wdId == widgetId) - { - *currentFramePtr |= MSCLP_SNS_SNS_CDAC_CTL_SEL_CO_Msk; - } - ptrScanSlots++; - currentFramePtr = ¤tFramePtr[CY_CAPSENSE_SENSOR_FRAME_SIZE]; - } - } -} #endif @@ -3769,7 +4322,7 @@ cy_capsense_status_t Cy_CapSense_SlotPinStateInternal( capStatus = CY_CAPSENSE_STATUS_SUCCESS; #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) - if(CY_CAPSENSE_PIN_STATE_IDX_CSX_VDDA2 == pinState) + if (CY_CAPSENSE_PIN_STATE_IDX_CSX_VDDA2 == pinState) { /* Close the reference to filter switch */ context->ptrBaseFrameContext->mode[CY_CAPSENSE_REG_MODE_CSX].swSelSh |= MSCLP_MODE_SW_SEL_SH_SOMB_Msk; @@ -4074,6 +4627,10 @@ cy_capsense_status_t Cy_CapSense_SwitchHwConfiguration( break; case CY_CAPSENSE_HW_CONFIG_SMARTSENSE: break; + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) + case CY_CAPSENSE_HW_CONFIG_AUTO_DITHERING: + break; + #endif default: capStatus = CY_CAPSENSE_STATUS_BAD_PARAM; break; @@ -4124,9 +4681,11 @@ cy_capsense_status_t Cy_CapSense_SwitchHwConfiguration( /* Disable ACTIVE domain interrupts */ ptrHwBase->INTR_MASK = 0x00u; + (void)ptrHwBase->INTR_MASK; /* Clear all pending interrupts */ ptrHwBase->INTR_LP = CY_CAPSENSE_MSCLP_INTR_LP_ALL_MSK; + (void)ptrHwBase->INTR_LP; /* Update Comp CDAC switch ctrl and replace CSD mode struct with the MPSC configuration */ #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED) @@ -4161,10 +4720,6 @@ cy_capsense_status_t Cy_CapSense_SwitchHwConfiguration( } } #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_PHASE_SELF_ENABLED) */ - - /* The time interval is required for settling analog part of the HW block. */ - Cy_SysLib_DelayUs(CY_CAPSENSE_ANALOG_SETTLING_TIME_US); - break; case CY_CAPSENSE_HW_CONFIG_BIST_FUNCTIONALITY: Cy_CapSense_SetIOsInDesiredState(CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_GPIO, 0u, @@ -4185,6 +4740,11 @@ cy_capsense_status_t Cy_CapSense_SwitchHwConfiguration( case CY_CAPSENSE_HW_CONFIG_SMARTSENSE: Cy_CapSense_SetupCpuOperatingMode(context); break; + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) + case CY_CAPSENSE_HW_CONFIG_AUTO_DITHERING: + Cy_CapSense_ConfigureAutoDitherMode(context); + break; + #endif default: capStatus = CY_CAPSENSE_STATUS_BAD_PARAM; break; @@ -4526,7 +5086,7 @@ uint32_t Cy_CapSense_GetClkSrcSSCAuto( lfsrDitherCycles = Cy_CapSense_GetLfsrDitherVal(lfsrRange, lfsrScale); /* Determine the MIN valid Sense Clock divider for the used sensing method. */ - if ((CY_CAPSENSE_CSD_GROUP == ptrWdConfig->senseMethod) ||\ + if ((CY_CAPSENSE_CSD_GROUP == ptrWdConfig->senseMethod) || (CY_CAPSENSE_ISX_GROUP == ptrWdConfig->senseMethod)) { snsClkDivMin = CY_CAPSENSE_4PH_DIRECT_SNS_CLOCK_DIVIDER_MIN; @@ -5155,6 +5715,7 @@ cy_capsense_status_t Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context) autoTuneConfig.refCdac = ptrWdCxt->cdacRef; autoTuneConfig.fingerCap = ptrWdCxt->fingerCap; + /* Find maximum rawcount to calculate max possible sensor clock frequency */ rawCountMax = 0u; for (snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++) { @@ -5171,14 +5732,14 @@ cy_capsense_status_t Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context) #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN) /* Checks for sub-widget */ - if(0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK)) + if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK)) { - if(0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_CH_1_MASK)) + if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_CH_1_MASK)) { autoTuneConfig.kRef1 += CY_CAPSENSE_CSD_MFS_DIVIDER_OFFSET_F1; } - if(0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_CH_2_MASK)) + if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_CH_2_MASK)) { autoTuneConfig.kRef1 += CY_CAPSENSE_CSD_MFS_DIVIDER_OFFSET_F2; } @@ -5188,16 +5749,29 @@ cy_capsense_status_t Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context) /* Configures widget sense clock divider by the calculated value */ ptrWdCxt->snsClk = autoTuneConfig.kRef1; ptrWdCxt->rowSnsClk = autoTuneConfig.kRef1; - autoTuneConfig.refCdac = context->ptrInternalContext->intrCsdRawTarget; + + /* Finds minimum rawcount starting from the previously defined max raw to define sensitivity properly */ + for (snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++) + { + if (rawCountMax > ptrWdCfg->ptrSnsContext[snsIndex].raw) + { + rawCountMax = ptrWdCfg->ptrSnsContext[snsIndex].raw; + } + } + autoTuneConfig.raw = (uint16_t)rawCountMax; + (void)Cy_CapSense_GetSmartSenseCapacitance(&autoTuneConfig); + autoTuneConfig.snsCapacitance /= ptrWdCfg->numChopCycles; + (void)Cy_CapSense_GetSmartSenseNumSubconversions(&autoTuneConfig); #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) numberSubConv = autoTuneConfig.nSub1; - #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) - /* Decreases scan duration twice if Compensation CDAC enabled */ - numberSubConv >>= 1u; + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) + /* Decreases scan duration per boost configuration */ + numberSubConv /= (uint8_t)((ptrWdCfg->cdacConfig & CY_CAPSENSE_CDAC_BOOST_VAL_MASK) >> CY_CAPSENSE_CDAC_BOOST_VAL_POS); #endif rawCountMax = numberSubConv * autoTuneConfig.kRef1; @@ -5239,9 +5813,9 @@ cy_capsense_status_t Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context) #else /* #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) */ numberSubConv = autoTuneConfig.nSub1; - #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) - /* Decreases Nsub when CompCDAC is enabled as it increases the sensitivity approximately twice */ - numberSubConv >>= 1u; + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) + /* Decreases scan duration per boost configuration */ + numberSubConv /= (uint8_t)((ptrWdCfg->cdacConfig & CY_CAPSENSE_CDAC_BOOST_VAL_MASK) >> CY_CAPSENSE_CDAC_BOOST_VAL_POS); #endif /* Limits Nsub to maximum possible value to avoid RawCount overflow */ @@ -5257,8 +5831,9 @@ cy_capsense_status_t Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context) ptrWdCxt->numSubConversions = (uint16_t)numberSubConv; numberSubConv *= ptrWdCfg->numChopCycles; - #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) - numberSubConv <<= 1u; + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) + /* Decreases scan duration per boost configuration */ + numberSubConv *= (uint8_t)((ptrWdCfg->cdacConfig & CY_CAPSENSE_CDAC_BOOST_VAL_MASK) >> CY_CAPSENSE_CDAC_BOOST_VAL_POS); #endif /* @@ -5544,6 +6119,127 @@ cy_capsense_status_t Cy_CapSense_WaitMrssStatusChange( } +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_RC_HW_IIR_FILTER_EN) +/******************************************************************************* +* Function Name: Cy_CapSense_ScanInitializeHwIirAllSlots +****************************************************************************//** +* +* Initializes (or re-initializes) the hardware IIR filter for all slots. +* +* This function initiates the blocking scan of all slots to initialize +* the hardware IIR filter. This should be done before firmware filters and +* baselines initialization. +* +* Calling this function is accompanied by +* * Cy_CapSense_InitializeAllFilters() +* * Cy_CapSense_InitializeAllBaselines() +* * Cy_CapSense_InitializeAllStatuses() +* +* \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_TIMEOUT - The software watchdog timeout occurred +* during the scan, the scan was not completed. +* +*******************************************************************************/ +cy_capsense_status_t Cy_CapSense_ScanInitializeHwIirAllSlots( + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t result; + + result = Cy_CapSense_ScanInitializeHwIirSlots(0u, CY_CAPSENSE_SLOT_COUNT, context); + + return result; +} + + +/******************************************************************************* +* Function Name: Cy_CapSense_ScanInitializeHwIirSlots +****************************************************************************//** +* +* Initializes (or re-initializes) the hardware IIR filter for specified slots. +* +* This function initiates the blocking scan of specified slots to initialize +* the hardware IIR filter. This should be done before firmware filters and +* baselines initialization. +* +* Calling this function is accompanied by +* * Cy_CapSense_InitializeWidgetFilter() +* * Cy_CapSense_InitializeWidgetBaseline() +* * Cy_CapSense_InitializeWidgetStatus() +* +* \note +* This function is available only for the fifth-generation low power CAPSENSE™. +* +* \param startSlotId +* The slot ID initialization will be started from. +* +* \param numberSlots +* The number of slots will be initialized. +* +* \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_TIMEOUT - The software watchdog timeout occurred +* during the scan, the scan was not completed. +* +*******************************************************************************/ +cy_capsense_status_t Cy_CapSense_ScanInitializeHwIirSlots( + uint32_t startSlotId, + uint32_t numberSlots, + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t result = CY_CAPSENSE_STATUS_SUCCESS; + MSCLP_Type * ptrHwBase = context->ptrCommonConfig->ptrChConfig->ptrHwBase; + uint32_t watchdog = 0u; + uint32_t slotIdx; + + /* Disable HW IP to allow MRSS operations */ + ptrHwBase->CTL &= (~MSCLP_CTL_ENABLED_Msk); + + /* Check for system VDDA value and enable PUMP if VDDA is less then threshold */ + #if (CY_MSCLP_VDDA_PUMP_TRESHOLD > CY_CAPSENSE_VDDA_MV) + ptrHwBase->PUMP_CTL = MSCLP_PUMP_CTL_PUMP_MODE_Msk; + #else + ptrHwBase->PUMP_CTL = 0x00u; + #endif + + /* Check if IMO is running */ + if (0u == (context->ptrCommonConfig->ptrChConfig->ptrHwBase->MRSS_STATUS & MSCLP_MRSS_STATUS_MRSS_UP_Msk)) + { + /* Enable only REF and IMO to provide access to the SNS_STC registers */ + ptrHwBase->MRSS_CMD = MSCLP_MRSS_CMD_MRSS_START_Msk; + (void)Cy_CapSense_WaitMrssStatusChange( + CY_MSCLP_CLK_LF_PERIOD_MAX * CY_MSCLP_MRSS_TIMEOUT_SMALL, + CY_CAPSENSE_MRSS_TURN_ON, context); + } + + /* Initialize the hardware raw count filter */ + ptrHwBase->SNS.CE_INIT_CTL |= MSCLP_SNS_CE_INIT_CTL_SENSOR_INIT_Msk; + + result |= Cy_CapSense_ScanSlots(startSlotId, numberSlots, context); + + for (slotIdx = startSlotId; slotIdx < (startSlotId + numberSlots); slotIdx++) + { + watchdog += Cy_CapSense_GetScanWatchdogTime(context->ptrScanSlots[slotIdx].wdId, slotIdx, context); + } + result |= Cy_CapSense_WaitEndScan(watchdog, context); + + return result; +} +#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_RC_HW_IIR_FILTER_EN) */ + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) /******************************************************************************* * Function Name: Cy_CapSense_GetCIC2SamplesMax @@ -5645,7 +6341,7 @@ uint32_t Cy_CapSense_GetCIC2HwShift( * Function Name: Cy_CapSense_InitializeCic2Shift ****************************************************************************//** * -* Performs the auto-selection of CIC2 HW filter parameter. +* Performs the auto-selection of CIC2 HW filter Shift parameter. * * \param context * The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. @@ -5665,7 +6361,9 @@ cy_capsense_status_t Cy_CapSense_InitializeCic2Shift( { uint32_t wdIndex; uint32_t scanSlotId; - uint16_t tmpVal; + uint32_t tmpVal; + uint32_t tmpShift; + uint32_t tmpSample; cy_capsense_status_t retVal = CY_CAPSENSE_STATUS_SUCCESS; cy_stc_capsense_widget_context_t * ptrWdCxt; @@ -5681,40 +6379,185 @@ cy_capsense_status_t Cy_CapSense_InitializeCic2Shift( { scanSlotId = ptrWdCfg->firstSlotId; - /* Obtain the scan duration in terms of Mod Clock cycles. */ + /* Obtain the scan duration in terms of Mod Clock cycles. */ + retVal |= Cy_CapSense_ExecuteSaturatedScan(&tmpVal, wdIndex, scanSlotId, CY_CAPSENSE_SATURATED_SCAN_TIME, context); + /* Obtain the number of valid (FullNumber - 1) CIC2 samples */ + tmpSample = (tmpVal / ptrWdCxt->cicRate) - 1u; + tmpShift = Cy_CapSense_GetCIC2HwShift(tmpSample); + tmpVal >>= tmpShift; + tmpVal *= ptrWdCfg->numChopCycles; + if (CY_CAPSENSE_16_BIT_MASK < tmpVal) + { + tmpShift++; + } + ptrWdCxt->cicShift = (uint8_t)tmpShift; + ptrWdCxt->cicShift |= CY_CAPSENSE_CIC_AUTO_MASK; + } + + #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || \ + (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) + if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && + (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType) || + ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType))) + { + if (0u != (ptrWdCxt->rowCicShift & CY_CAPSENSE_CIC_AUTO_MASK)) + { + scanSlotId = (uint32_t)ptrWdCfg->firstSlotId + ptrWdCfg->numCols; + + /* Obtain the scan duration in terms of Mod Clock cycles. */ + retVal |= Cy_CapSense_ExecuteSaturatedScan(&tmpVal, wdIndex, scanSlotId, CY_CAPSENSE_SATURATED_SCAN_TIME, context); + /* Obtain the number of valid (FullNumber - 1) CIC2 samples */ + tmpSample = (tmpVal / ptrWdCxt->cicRate) - 1u; + tmpShift = Cy_CapSense_GetCIC2HwShift(tmpSample); + tmpVal >>= tmpShift; + tmpVal *= ptrWdCfg->numChopCycles; + if (CY_CAPSENSE_16_BIT_MASK < tmpVal) + { + tmpShift++; + } + ptrWdCxt->rowCicShift = (uint8_t)tmpShift; + ptrWdCxt->rowCicShift |= CY_CAPSENSE_CIC_AUTO_MASK; + } + } + #endif + } + ptrWdCfg++; + } + + /* Update Active frame configuration with new calculated CIC2 shift value. */ + Cy_CapSense_GenerateAllSensorConfig(CY_CAPSENSE_SNS_FRAME_ACTIVE, context); + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) + /* Update LP frame configuration with new calculated CIC2 shift value. */ + Cy_CapSense_GenerateAllSensorConfig(CY_CAPSENSE_SNS_FRAME_LOW_POWER, context); + #endif /* CY_CAPSENSE_LP_EN */ + + /* Resetting the HW configuration in order to trigger the base frame initialization in scope of the + * next Cy_CapSense_SwitchHwConfiguration() function call with the desired HW configuration. + */ + if (CY_CAPSENSE_STATUS_SUCCESS == retVal) + { + retVal |= Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_CAPTURED_DEFAULT, context); + } + + if (CY_CAPSENSE_STATUS_SUCCESS == retVal) + { + retVal |= Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_REGULAR_SCANNING, context); + } + + return retVal; +} +#endif /* #if (CY_CAPSENSE_CIC2_FILTER_AUTO_EN) */ + + +#if (CY_CAPSENSE_CIC_RATE_MODE_AUTO_EN) +/******************************************************************************* +* Function Name: Cy_CapSense_InitializeCic2Rate +****************************************************************************//** +* +* Performs the auto-selection of CIC2 HW filter Decimation Rate parameter. +* +* \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_TIMEOUT - A timeout reached during the scan time measurement. +* - CY_CAPSENSE_STATUS_BAD_PARAM - Not valid input parameter. +* - CY_CAPSENSE_STATUS_HW_BUSY - The MSCLP HW block is busy and cannot be +* switched to another mode. +* - CY_CAPSENSE_STATUS_BAD_CONFIG - The parameters are out of specified range. +* +*******************************************************************************/ +cy_capsense_status_t Cy_CapSense_InitializeCic2Rate( + cy_stc_capsense_context_t * context) +{ + uint32_t wdIndex; + uint32_t scanSlotId; + uint32_t sampleOverflow; + uint32_t scanTime; + uint32_t tmpVal; + #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_MATRIX_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_TOUCHPAD_EN)) + uint32_t tmpValRow; + #endif + cy_capsense_status_t retVal = CY_CAPSENSE_STATUS_SUCCESS; + + cy_stc_capsense_widget_context_t * ptrWdCxt; + const cy_stc_capsense_widget_config_t * ptrWdCfg = context->ptrWdConfig; + + for (wdIndex = 0u; wdIndex < CY_CAPSENSE_TOTAL_WIDGET_COUNT; wdIndex++) + { + if (0u != Cy_CapSense_IsWidgetEnabled(wdIndex, context)) + { + if (CY_CAPSENSE_CIC_RATE_MODE_AUTO == ptrWdCfg->cicRateMode) + { + ptrWdCxt = ptrWdCfg->ptrWdContext; + scanSlotId = ptrWdCfg->firstSlotId; + + /* Obtain the scan duration in terms of Mod Clock cycles */ retVal |= Cy_CapSense_ExecuteSaturatedScan(&tmpVal, wdIndex, scanSlotId, CY_CAPSENSE_SATURATED_SCAN_TIME, context); - ptrWdCxt->cicShift = (uint8_t)Cy_CapSense_GetCIC2HwShift(tmpVal); - ptrWdCxt->cicShift |= CY_CAPSENSE_CIC_AUTO_MASK; - } - #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || \ - (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) - if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && - (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType) || - ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType))) - { - if (0u != (ptrWdCxt->rowCicShift & CY_CAPSENSE_CIC_AUTO_MASK)) + #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_MATRIX_EN) || \ + (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_TOUCHPAD_EN)) + if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && + (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType) || + ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType))) { scanSlotId = (uint32_t)ptrWdCfg->firstSlotId + ptrWdCfg->numCols; - /* Obtain the scan duration in terms of Mod Clock cycles. */ - retVal |= Cy_CapSense_ExecuteSaturatedScan(&tmpVal, wdIndex, scanSlotId, CY_CAPSENSE_SATURATED_SCAN_TIME, context); + retVal |= Cy_CapSense_ExecuteSaturatedScan(&tmpValRow, wdIndex, scanSlotId, CY_CAPSENSE_SATURATED_SCAN_TIME, context); + if (tmpValRow < tmpVal) + { + tmpVal = tmpValRow; + } + } + #endif - /* Obtain the number of valid (FullNumber - 1) CIC2 samples */ - ptrWdCxt->rowCicShift = (uint8_t)Cy_CapSense_GetCIC2HwShift(tmpVal); - ptrWdCxt->rowCicShift |= CY_CAPSENSE_CIC_AUTO_MASK; + scanTime = tmpVal; + + /* Phase 1 */ + tmpVal /= (CY_CAPSENSE_CIC2_MIN_VALID_SAMPLES + 1u); + if (0u == tmpVal) + { + tmpVal = 1u; + } + if (CY_CAPSENSE_MAX_DECIMATION_RATE > tmpVal) + { + ptrWdCxt->cicRate = (uint8_t)tmpVal; + } + else + { + /* Phase 2 */ + tmpVal = CY_CAPSENSE_MAX_DECIMATION_RATE; + sampleOverflow = (scanTime / CY_CAPSENSE_MAX_DECIMATION_RATE) - 1u; + + if ((CY_CAPSENSE_CIC2_MAX_VALID_SAMPLES / ptrWdCfg->numChopCycles) >= sampleOverflow) + { + ptrWdCxt->cicRate = (uint8_t)CY_CAPSENSE_MAX_DECIMATION_RATE; + } + else + { + /* Phase 3 */ + ptrWdCxt->cicRate = (uint8_t)(((uint32_t)CY_CAPSENSE_25_BIT_MASK / ptrWdCfg->numChopCycles) / (scanTime - 1u)); + if (0u == ptrWdCxt->cicRate) + { + retVal = CY_CAPSENSE_STATUS_BAD_CONFIG; + ptrWdCxt->cicRate = 1u; + } } } - #endif + } } ptrWdCfg++; } - /* Update Active frame configuration with new calculated CIC2 shift value. */ + /* Update Active frame configuration with new calculated CIC2 decimation value. */ Cy_CapSense_GenerateAllSensorConfig(CY_CAPSENSE_SNS_FRAME_ACTIVE, context); #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) - /* Update LP frame configuration with new calculated CIC2 shift value. */ + /* Update LP frame configuration with new calculated CIC2 decimation value. */ Cy_CapSense_GenerateAllSensorConfig(CY_CAPSENSE_SNS_FRAME_LOW_POWER, context); #endif /* CY_CAPSENSE_LP_EN */ @@ -5734,7 +6577,6 @@ cy_capsense_status_t Cy_CapSense_InitializeCic2Shift( return retVal; } #endif /* #if (CY_CAPSENSE_CIC2_FILTER_AUTO_EN) */ - #endif /* #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN) */ @@ -5847,10 +6689,13 @@ void Cy_CapSense_SetupCpuOperatingMode(cy_stc_capsense_context_t * context) /* Disable all interrupts */ ptrHwBase->INTR_LP_MASK = 0x00u; + (void)ptrHwBase->INTR_LP_MASK; /* Clear all pending interrupts */ ptrHwBase->INTR_LP = CY_CAPSENSE_MSCLP_INTR_LP_ALL_MSK; + (void)ptrHwBase->INTR_LP; ptrHwBase->INTR = CY_CAPSENSE_MSCLP_INTR_ALL_MSK; + (void)ptrHwBase->INTR; /* Set CPU operating mode */ context->ptrInternalContext->operatingMode = CY_CAPSENSE_CTL_OPERATING_MODE_CPU; @@ -5889,7 +6734,9 @@ void Cy_CapSense_StartCpuScan(const uint32_t * scanConfig, cy_stc_capsense_conte /* Clear all pending interrupts */ ptrHwBase->INTR_LP = CY_CAPSENSE_MSCLP_INTR_LP_ALL_MSK; + (void)ptrHwBase->INTR_LP; ptrHwBase->INTR = CY_CAPSENSE_MSCLP_INTR_ALL_MSK; + (void)ptrHwBase->INTR; /* Set sensor config registers (frame) */ Cy_MSCLP_ConfigureScan(ptrHwBase, CY_MSCLP_6_SNS_REGS, scanConfig); @@ -5948,7 +6795,7 @@ uint32_t Cy_CapSense_WaitEndOfCpuScan(uint32_t watchdogTime, cy_stc_capsense_con /* Clear all pending interrupts */ ptrHwBase->INTR = CY_CAPSENSE_MSCLP_INTR_ALL_MSK; - + (void)ptrHwBase->INTR; return tmpVal; } @@ -5961,7 +6808,8 @@ uint32_t Cy_CapSense_WaitEndOfCpuScan(uint32_t watchdogTime, cy_stc_capsense_con * the MAX raw count or the scan duration for the specified scan slot. * * \param ptrMaxRaw -* Specifies the pointer to store the resulting MAX raw count value. +* Specifies the pointer to store the resulting MAX raw count value or scan +* time in Mod Clock cycles. * * \param widgetId * Specifies the ID number of the widget. A macro for the widget ID can be found @@ -5988,7 +6836,7 @@ uint32_t Cy_CapSense_WaitEndOfCpuScan(uint32_t watchdogTime, cy_stc_capsense_con * *******************************************************************************/ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( - uint16_t * ptrMaxRaw, + uint32_t * ptrMaxRaw, uint32_t widgetId, uint32_t scanSlotId, uint32_t mode, @@ -5998,14 +6846,22 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( uint32_t slotFrameIdx; uint32_t * ptrSnsFrame; uint32_t scanConfigTmp[CY_MSCLP_6_SNS_REGS]; + cy_stc_capsense_widget_config_t const * ptrWdCfg = &context->ptrWdConfig[widgetId]; + cy_stc_capsense_widget_context_t * ptrWdCxt = &context->ptrWdContext[widgetId]; cy_capsense_status_t status; MSCLP_Type * ptrHwBase = context->ptrCommonConfig->ptrChConfig->ptrHwBase; - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) + #if (CY_CAPSENSE_DISABLE == CY_CAPSENSE_CIC2_FILTER_EN) uint32_t kref; - uint32_t nsub; + uint32_t epiCounts; + uint32_t epiKrefDelay; + #endif + + #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) && \ + ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_AUTO_EN) || (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC_RATE_MODE_AUTO_EN))) + uint32_t shiftTemp= 0u; #endif (void)mode; @@ -6020,7 +6876,7 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( ptrSnsFrame = &context->ptrSensorFrameContext[slotFrameIdx]; #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) - if (context->ptrWdConfig[widgetId].wdType == (uint8_t)CY_CAPSENSE_WD_LOW_POWER_E) + if (ptrWdCfg->wdType == (uint8_t)CY_CAPSENSE_WD_LOW_POWER_E) { /* Obtain the scan parameters offset in the cy_capsense_sensorFrameContext[] * array for the slots that are part of Low power widgets. @@ -6049,8 +6905,8 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( scanConfigTmp[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] &= ~MSCLP_SNS_SNS_SCAN_CTL_NUM_CONV_Msk; #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) && \ - (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_AUTO_EN)) - if(CY_CAPSENSE_SATURATED_SCAN_TIME == mode) + ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_AUTO_EN) || (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC_RATE_MODE_AUTO_EN))) + if (CY_CAPSENSE_SATURATED_SCAN_TIME == mode) { /* Disable the CIC2 shift and set the decimation rate to 1 (DECIM_RATE = 0) to increment the * CIC2 accumulator each Mod Clock cycle and then copy the result to FIFO without shifting. @@ -6060,10 +6916,38 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( */ scanConfigTmp[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] &= (uint32_t)(~MSCLP_SNS_SNS_SCAN_CTL_CIC2_SHIFT_Msk); scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] &= (uint32_t)(~MSCLP_SNS_SNS_CTL_DECIM_RATE_Msk); + + /* In case Max Rawcount are going to be overflowed let's use CIC2 shift */ + shiftTemp = 0u; + tmpVal = ptrWdCxt->snsClk; + if (tmpVal < ptrWdCxt->rowSnsClk) + { + tmpVal = ptrWdCxt->rowSnsClk; + } + tmpVal *= ptrWdCxt->numSubConversions; + if (CY_CAPSENSE_CLK_SOURCE_PRS == ((uint32_t)ptrWdCxt->snsClkSource & CY_CAPSENSE_CLK_SOURCE_MASK)) + { + tmpVal <<= 1u; + } + while ((tmpVal >> shiftTemp) > CY_CAPSENSE_16_BIT_MASK) + { + shiftTemp++; + } + if (CY_CAPSENSE_CIC2_SHIFT_MAX < shiftTemp) + { + status = CY_CAPSENSE_STATUS_CONFIG_OVERFLOW; + } + /* Consider System Chopping for overflow */ + tmpVal <<= (ptrWdCfg->numChopCycles - 1u); + if (CY_CAPSENSE_25_BIT_MASK < tmpVal) + { + status = CY_CAPSENSE_STATUS_CONFIG_OVERFLOW; + } + scanConfigTmp[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= (uint32_t)(shiftTemp << MSCLP_SNS_SNS_SCAN_CTL_CIC2_SHIFT_Pos); } #endif - if(status == CY_CAPSENSE_STATUS_SUCCESS) + if (status == CY_CAPSENSE_STATUS_SUCCESS) { /* Initiate the scan in the CPU operating mode. */ Cy_CapSense_StartCpuScan((const uint32_t *)scanConfigTmp, context); @@ -6071,7 +6955,7 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( tmpVal = Cy_CapSense_GetScanWatchdogTime(widgetId, scanSlotId, context); tmpVal = Cy_CapSense_WaitEndOfCpuScan(tmpVal, context); - if(0u == tmpVal) + if (0u == tmpVal) { status |= CY_CAPSENSE_STATUS_TIMEOUT; } @@ -6083,48 +6967,68 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( /* Disable HW IP */ ptrHwBase->CTL &= (~MSCLP_CTL_ENABLED_Msk); - #if (CY_CAPSENSE_ENABLE != CY_CAPSENSE_CIC2_FILTER_EN) - tmpVal <<= (context->ptrWdConfig[widgetId].numChopCycles - 1u); - #elif ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) && \ - (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_AUTO_EN)) - if(CY_CAPSENSE_SATURATED_SCAN_TIME == mode) + *ptrMaxRaw = CY_CAPSENSE_16_BIT_MASK; + + #if (CY_CAPSENSE_DISABLE == CY_CAPSENSE_CIC2_FILTER_EN) + + epiKrefDelay = CY_CAPSENSE_NUM_EPI_KREF_DELAY; + kref = ((scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] & MSCLP_SNS_SNS_CTL_SENSE_DIV_Msk) >> MSCLP_SNS_SNS_CTL_SENSE_DIV_Pos) + 1u; + if (CY_CAPSENSE_CLK_SOURCE_PRS == ((uint32_t)ptrWdCxt->snsClkSource & CY_CAPSENSE_CLK_SOURCE_MASK)) + { + epiKrefDelay = CY_CAPSENSE_NUM_EPI_KREF_DELAY_PRS; + } + epiCounts = epiKrefDelay * ((kref + 3u) >> 2u); + if (CY_CAPSENSE_CLK_SOURCE_PRS == ((uint32_t)ptrWdCxt->snsClkSource & CY_CAPSENSE_CLK_SOURCE_MASK)) { - if (CY_CAPSENSE_CLK_SOURCE_PRS == ((uint32_t)context->ptrWdContext[widgetId].snsClkSource & CY_CAPSENSE_CLK_SOURCE_MASK)) + if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) || (CY_CAPSENSE_ISX_GROUP == ptrWdCfg->senseMethod)) { - tmpVal >>= 1u; + kref <<= 1u; } + } + if (0uL == (kref & 0x01uL)) + { + epiCounts--; + } + tmpVal -= epiCounts; + tmpVal *= ptrWdCfg->numChopCycles; + if (tmpVal <= CY_CAPSENSE_16_BIT_MASK) + { + *ptrMaxRaw = (uint16_t)tmpVal; + } + + #elif ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) && \ + ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_AUTO_EN) || (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC_RATE_MODE_AUTO_EN))) + + if (CY_CAPSENSE_SATURATED_SCAN_TIME == mode) + { + tmpVal <<= shiftTemp; /* The final value in the FIFO fill is the equal number of Mod Clock cycles per scan minus 1 because - * the first CIC2 sample is invalid and will be skipped. The code below takes into account this skipped + * the first CIC2 sample is invalid and is always skipped. The code below takes into account this skipped * Mod Clock cycle. */ tmpVal++; - /* Obtain the number of valid (FullNumber - 1) CIC2 samples */ - tmpVal = (tmpVal / context->ptrWdContext[widgetId].cicRate) - 1u; + *ptrMaxRaw = tmpVal; } else { - kref = ((scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] & MSCLP_SNS_SNS_CTL_SENSE_DIV_Msk) >> MSCLP_SNS_SNS_CTL_SENSE_DIV_Pos) + 1u; - nsub = ((scanConfigTmp[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] & MSCLP_SNS_SNS_SCAN_CTL_NUM_SUB_CONVS_Msk) >> MSCLP_SNS_SNS_SCAN_CTL_NUM_SUB_CONVS_Pos) + 1u; - - tmpVal = (tmpVal * context->ptrWdConfig[widgetId].numChopCycles) + - (((kref * nsub) >> ((uint32_t)context->ptrWdContext[widgetId].cicShift & (uint32_t)(~(uint32_t)CY_CAPSENSE_CIC_AUTO_MASK))) * - (context->ptrWdConfig[widgetId].numChopCycles - 1u)); + tmpVal *= ptrWdCfg->numChopCycles; + if (tmpVal <= CY_CAPSENSE_16_BIT_MASK) + { + *ptrMaxRaw = (uint16_t)tmpVal; + } } #else - kref = ((scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] & MSCLP_SNS_SNS_CTL_SENSE_DIV_Msk) >> MSCLP_SNS_SNS_CTL_SENSE_DIV_Pos) + 1u; - nsub = ((scanConfigTmp[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] & MSCLP_SNS_SNS_SCAN_CTL_NUM_SUB_CONVS_Msk) >> MSCLP_SNS_SNS_SCAN_CTL_NUM_SUB_CONVS_Pos) + 1u; - - tmpVal = (tmpVal * context->ptrWdConfig[widgetId].numChopCycles) + - (((kref * nsub) >> ((uint32_t)context->ptrWdContext[widgetId].cicShift & (uint32_t)(~(uint32_t)CY_CAPSENSE_CIC_AUTO_MASK))) * - (context->ptrWdConfig[widgetId].numChopCycles - 1u)); + tmpVal *= ptrWdCfg->numChopCycles; + if (tmpVal <= CY_CAPSENSE_16_BIT_MASK) + { + *ptrMaxRaw = (uint16_t)tmpVal; + } #endif - *ptrMaxRaw = CY_CAPSENSE_16_BIT_MASK; - if(tmpVal <= CY_CAPSENSE_16_BIT_MASK) + if (0u == *ptrMaxRaw) { - *ptrMaxRaw = (uint16_t)tmpVal; + *ptrMaxRaw = 1u; } - return status; } @@ -6158,7 +7062,7 @@ void Cy_CapSense_ConfigureSaturationMode( /* Iterate through all the MODE structures and update them with the configuration, * required to saturate the measurement channel. */ - for(i = 0u; i < MSCLP_SENSE_MODE_NR; i++) + for (i = 0u; i < MSCLP_SENSE_MODE_NR; i++) { /* The 0x03 value of the RMF field enables the internal voltage divider and * configures it to generate VDDA*0.8 voltage at the output. @@ -6174,6 +7078,72 @@ void Cy_CapSense_ConfigureSaturationMode( } +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) +/******************************************************************************* +* Function Name: Cy_CapSense_ConfigureAutoDitherMode +****************************************************************************//** +* +* Configures the MSCLP HW block for operation in the auto-dithering mode. +* +* \param context +* The pointer to the context structure allocated by the user or middleware. +* +* \return +* Returns the status of the operation: +* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed successfully. +* - CY_CAPSENSE_STATUS_CONFIG_OVERFLOW - The numberSlots parameter exceeds +* the maximum number of sensor configurations +* which is possible to be loaded into the +* internal buffer of the CAPSENSE&trade HW block. +* - CY_CAPSENSE_STATUS_BAD_CONFIG - The function does not suppose to be +* called with the current CAPSENSE™ +* configuration. +* - CY_CAPSENSE_STATUS_HW_BUSY - The MSCLP HW block is busy and cannot be +* configured. +* +*******************************************************************************/ +static cy_capsense_status_t Cy_CapSense_ConfigureAutoDitherMode( + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t status = CY_CAPSENSE_STATUS_SUCCESS; + cy_en_msclp_status_t msclpStatus; + const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig; + MSCLP_Type * ptrHwBase = ptrCommonCfg->ptrChConfig->ptrHwBase; + + /* Generate sensor frame configuration for active widgets*/ + Cy_CapSense_GenerateAllSensorConfig(CY_CAPSENSE_SNS_FRAME_ACTIVE, context); + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) + /* Generate sensor frame configuration for LP widgets */ + Cy_CapSense_GenerateAllSensorConfig(CY_CAPSENSE_SNS_FRAME_LOW_POWER, context); + #endif /* CY_CAPSENSE_LP_EN */ + + /* Write configuration data into all MSCLP block registers */ + msclpStatus = Cy_MSCLP_Configure(ptrHwBase, + context->ptrBaseFrameContext, + CY_MSCLP_CAPSENSE_KEY, + ptrCommonCfg->ptrChConfig->ptrHwContext); + + Cy_CapSense_SetupCpuOperatingMode(context); + + if (CY_MSCLP_SUCCESS != msclpStatus) + { + status = CY_CAPSENSE_STATUS_HW_BUSY; + } + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) + /* Set FILTER_MODE to CIC1 */ + ptrHwBase->FILTER_CTL &= ~MSCLP_FILTER_CTL_FILTER_MODE_Msk; + #endif /* CY_CAPSENSE_CIC2_FILTER_EN */ + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_EXT_FRM_START_EN) + /* Clear the external start scan mode */ + ptrHwBase->CTL &= ~MSCLP_CTL_EXT_FRAME_START_MODE_Msk; + #endif + + return status; +} +#endif /******************************************************************************* * Function Name: Cy_CapSense_GetScanWatchdogTime @@ -6321,6 +7291,230 @@ uint32_t Cy_CapSense_GetScanWatchdogTime( return tmpVal; } +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) +/******************************************************************************* +* Function Name: Cy_CapSense_CdacDitherScaleCalc +****************************************************************************//** +* +* This internal function calculates the dither scale value based on highest +* raw count value in AUTO dithering mode. +* +* \param context +* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. +* +* \return status +* Returns the status of the operation (different statuses can be combined): +* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed +* successfully. +* - CY_CAPSENSE_STATUS_BAD_PARAM - At least one of input parameters is +* not valid. +* - CY_CAPSENSE_STATUS_HW_BUSY - The HW is busy with the previous scan. +* +*******************************************************************************/ +static cy_capsense_status_t Cy_CapSense_CdacDitherScaleCalc( + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t status = CY_CAPSENSE_STATUS_SUCCESS; + cy_en_msclp_status_t msclpStatus; + const cy_stc_capsense_widget_config_t * ptrWdCfg; + uint32_t wdIndex; + uint32_t * ptrSnsFrame; + uint32_t rawCountMax; + + const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig; + MSCLP_Type * ptrHwBase = ptrCommonCfg->ptrChConfig->ptrHwBase; + + /* Force HW configuration update on the next scan */ + status = Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_AUTO_DITHERING, context); + + ptrWdCfg = context->ptrWdConfig; + for (wdIndex = 0u; wdIndex < CY_CAPSENSE_TOTAL_WIDGET_COUNT; wdIndex++) + { + if (0u != Cy_CapSense_IsWidgetEnabled(wdIndex, context)) + { + if (CY_CAPSENSE_CDAC_DITHERING_MODE_AUTO == ptrWdCfg->cdacDitherScaleMode) + { + /* Handle only CSD and CSX widgets */ + if (CY_CAPSENSE_ISX_GROUP != ptrWdCfg->senseMethod) + { + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) + /* Scan low power widgets */ + if ((uint8_t)CY_CAPSENSE_WD_LOW_POWER_E == ptrWdCfg->wdType) + { + ptrSnsFrame = &context->ptrSensorFrameLpContext[ptrWdCfg->firstSlotId * CY_CAPSENSE_LP_SENSOR_FRAME_SIZE + + CY_CAPSENSE_FRM_LP_SNS_SW_SEL_CSW_LO_MASK2_INDEX]; + status |= Cy_CapSense_CdacDitherGetMaxRaw(ptrSnsFrame, ptrWdCfg, CY_CAPSENSE_LP_SENSOR_FRAME_SIZE, &rawCountMax, context); + } + else + #endif /* CY_CAPSENSE_LP_EN */ + /* Scan active widgets */ + { + ptrSnsFrame = &context->ptrSensorFrameContext[ptrWdCfg->firstSlotId * CY_CAPSENSE_SENSOR_FRAME_SIZE]; + status |= Cy_CapSense_CdacDitherGetMaxRaw(ptrSnsFrame, ptrWdCfg, CY_CAPSENSE_SENSOR_FRAME_SIZE, &rawCountMax, context); + } + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) + /* Divide the result by 2 for the FW CSX scanning method */ + if (CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod) + { + rawCountMax /= CY_CAPSENSE_DIVIDER_TWO; + } + #endif + + /* Set dither value according to measured widget raw counts */ + if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_300_FEMTO_RAW) + { + context->ptrWdContext[wdIndex].cdacDitherValue = 6u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_500_FEMTO_RAW) + { + context->ptrWdContext[wdIndex].cdacDitherValue = 5u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_1000_FEMTO_RAW) + { + context->ptrWdContext[wdIndex].cdacDitherValue = 4u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_3000_FEMTO_RAW) + { + context->ptrWdContext[wdIndex].cdacDitherValue = 3u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_5000_FEMTO_RAW) + { + context->ptrWdContext[wdIndex].cdacDitherValue = 2u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_10000_FEMTO_RAW) + { + context->ptrWdContext[wdIndex].cdacDitherValue = 1u; + } else + { + context->ptrWdContext[wdIndex].cdacDitherValue = 0u; + } + } + } + } + /* Increment pointer to the next widget */ + ptrWdCfg++; + } + + /* Update Active frame configuration */ + Cy_CapSense_GenerateAllSensorConfig(CY_CAPSENSE_SNS_FRAME_ACTIVE, context); + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_LP_EN) + /* Update LP frame configuration */ + Cy_CapSense_GenerateAllSensorConfig(CY_CAPSENSE_SNS_FRAME_LOW_POWER, context); + #endif /* CY_CAPSENSE_LP_EN */ + + /* Write configuration data into all MSCLP block registers */ + msclpStatus = Cy_MSCLP_Configure(ptrHwBase, + context->ptrBaseFrameContext, + CY_MSCLP_CAPSENSE_KEY, + ptrCommonCfg->ptrChConfig->ptrHwContext); + + if (CY_MSCLP_SUCCESS != msclpStatus) + { + status = CY_CAPSENSE_STATUS_HW_BUSY; + } + + return status; +} + +/******************************************************************************* +* Function Name: Cy_CapSense_CdacDitherGetMaxRaw +****************************************************************************//** +* +* This internal function performs scanning for each sensor in a widget and finds +* the biggest raw count value. +* +* \param ptrSnsFrame +* The pointer to sensor frame array for current widget. +* +* \param ptrWdCfg +* The pointer to the widget config structure. +* +* \param snsFrameSize +* Sensor frame size: +* - CY_CAPSENSE_SENSOR_FRAME_SIZE - for active widgets +* - CY_CAPSENSE_LP_SENSOR_FRAME_SIZE - for low power widgets +* +* \param ptrRawCountMax +* The pointer to variable for storing raw counts maximum value. +* +* \param context +* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. +* +* \return status +* Returns the status of the operation (different statuses can be combined): +* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed +* successfully. +* - CY_CAPSENSE_STATUS_TIMEOUT - The software watchdog timeout occurred +* during the scan, the scan was not completed. +* +*******************************************************************************/ +static cy_capsense_status_t Cy_CapSense_CdacDitherGetMaxRaw( + uint32_t * ptrSnsFrame, + const cy_stc_capsense_widget_config_t * ptrWdCfg, + uint32_t snsFrameSize, + uint32_t * ptrRawCountMax, + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t status = CY_CAPSENSE_STATUS_SUCCESS; + uint32_t tmpRawCount; + uint32_t watchdog; + uint32_t scanConfigTmp[CY_MSCLP_6_SNS_REGS]; + uint32_t scanSlotId; + uint32_t index; + + const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig; + MSCLP_Type * ptrHwBase = ptrCommonCfg->ptrChConfig->ptrHwBase; + + /* Reset maximum raw raw counts value before measurement */ + *ptrRawCountMax = 0u; + + /* Perform preliminary scans for active widgets */ + for (scanSlotId = 0u; scanSlotId < ptrWdCfg->numSns; scanSlotId++) + { + /* Inherit sensor frame to local array */ + for (index = 0u; index < CY_MSCLP_6_SNS_REGS; index++) + { + scanConfigTmp[index] = ptrSnsFrame[index]; + } + /* Configure Sensor Clock, Clock Sources */ + scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] &= (uint32_t)~(MSCLP_SNS_SNS_CTL_START_SCAN_Msk | + MSCLP_SNS_SNS_CTL_LAST_Msk | MSCLP_SNS_SNS_CTL_MULTI_CH_MODE_Msk | + MSCLP_SNS_SNS_CTL_SENSE_DIV_Msk | MSCLP_SNS_SNS_CTL_LFSR_MODE_Msk); + scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] |= (((CY_CAPSENSE_CDAC_DITHERING_KREF - 1u) << MSCLP_SNS_SNS_CTL_SENSE_DIV_Pos) | + (1u << MSCLP_SNS_SNS_CTL_LAST_Pos)); + + /* Configure Number of sub-conversions, Compensation divider */ + scanConfigTmp[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] = (((CY_CAPSENSE_CDAC_DITHERING_NUM_SUBCONV - 1u) << MSCLP_SNS_SNS_SCAN_CTL_NUM_SUB_CONVS_Pos) | + ((CY_CAPSENSE_CDAC_DITHERING_COMP_DIV - 1u) << MSCLP_SNS_SNS_SCAN_CTL_COMP_DIV_Pos)); + + /* Configure Cap DACs and Clock reference rate*/ + scanConfigTmp[CY_CAPSENSE_SNS_CDAC_CTL_INDEX] = 0u; + scanConfigTmp[CY_CAPSENSE_SNS_CDAC_CTL_INDEX] |= ((CY_CAPSENSE_CDAC_DITHERING_CDAC_REF << MSCLP_SNS_SNS_CDAC_CTL_SEL_RE_Pos) | + (CY_CAPSENSE_CDAC_DITHERING_CLOCK_REF_RATE << MSCLP_SNS_SNS_CDAC_CTL_CLOCK_REF_RATE_Pos)); + + Cy_CapSense_StartCpuScan((const uint32_t *)scanConfigTmp, context); + + watchdog = Cy_CapSense_WaitEndOfCpuScan(CY_CAPSENSE_CDAC_DITHERING_WATCHDOG_TIME, context); + + /* Check if the watchdog timeout happened */ + if (0u == watchdog) + { + status = CY_CAPSENSE_STATUS_TIMEOUT; + } + else + { + /* Read raw counts */ + tmpRawCount = ptrHwBase->SNS.RESULT_FIFO_RD & MSCLP_SNS_RESULT_FIFO_RD_RAW_COUNT_Msk; + if (*ptrRawCountMax < tmpRawCount) + { + /* Keep maximum raw counts */ + *ptrRawCountMax = tmpRawCount; + } + } + /* Increment pointer to the next sensor */ + ptrSnsFrame += snsFrameSize; + } + + return status; +} +#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) */ #endif /* CY_IP_M0S8MSCV3LP */ diff --git a/cy_capsense_sensing_lp.h b/cy_capsense_sensing_lp.h index ea5187d..227cb10 100644 --- a/cy_capsense_sensing_lp.h +++ b/cy_capsense_sensing_lp.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_sensing_lp.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes specific to the scanning module. * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 @@ -82,6 +82,15 @@ cy_capsense_status_t Cy_CapSense_CalibrateAllLpWidgets( cy_capsense_status_t Cy_CapSense_CalibrateAllLpSlots( cy_stc_capsense_context_t * context); #endif + +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_RC_HW_IIR_FILTER_EN) + cy_capsense_status_t Cy_CapSense_ScanInitializeHwIirAllSlots( + cy_stc_capsense_context_t * context); + cy_capsense_status_t Cy_CapSense_ScanInitializeHwIirSlots( + uint32_t startSlotId, + uint32_t numberSlots, + cy_stc_capsense_context_t * context); +#endif /** \} */ @@ -156,11 +165,30 @@ cy_capsense_status_t Cy_CapSense_SlotPinState_V3Lp( #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)) -cy_capsense_status_t Cy_CapSense_CalibrateCompDivider( +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_REF_AUTO_EN) + cy_capsense_status_t Cy_CapSense_CalibrateRefCdac( + uint32_t widgetId, + cy_stc_capsense_context_t * context); +#endif +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_FINE_AUTO_EN) + cy_capsense_status_t Cy_CapSense_CalibrateFineCdac( + uint32_t widgetId, + cy_stc_capsense_context_t * context); +#endif +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_COMP_DIV_AUTO_EN) + cy_capsense_status_t Cy_CapSense_CalibrateCompDivider( + uint32_t widgetId, + cy_stc_capsense_context_t * context); +#endif +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_COMP_AUTO_EN) + cy_capsense_status_t Cy_CapSense_CalibrateCompCdac( + uint32_t widgetId, + cy_stc_capsense_context_t * context); +#endif +cy_capsense_status_t Cy_CapSense_VerifyCalibration( uint32_t widgetId, - uint32_t target, cy_stc_capsense_context_t * context); -cy_capsense_status_t Cy_CapSense_VerifyCalibration( +cy_capsense_status_t Cy_CapSense_VerifyReferenceCdac( uint32_t widgetId, cy_stc_capsense_context_t * context); cy_capsense_status_t Cy_CapSense_CalibrateAllWidgets_V3Lp( @@ -220,13 +248,17 @@ cy_capsense_status_t Cy_CapSense_ScanAbort_V3Lp( cy_capsense_status_t Cy_CapSense_InitializeCic2Shift( cy_stc_capsense_context_t * context); #endif + #if (CY_CAPSENSE_CIC_RATE_MODE_AUTO_EN) + cy_capsense_status_t Cy_CapSense_InitializeCic2Rate( + cy_stc_capsense_context_t * context); + #endif #endif /* #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN) */ void Cy_CapSense_SetupCpuOperatingMode(cy_stc_capsense_context_t * context); void Cy_CapSense_StartCpuScan(const uint32_t * scanConfig, cy_stc_capsense_context_t * context); uint32_t Cy_CapSense_WaitEndOfCpuScan(uint32_t watchdogTime, cy_stc_capsense_context_t * context); cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( - uint16_t * ptrMaxRaw, + uint32_t * ptrMaxRaw, uint32_t widgetId, uint32_t scanSlotId, uint32_t mode, @@ -264,6 +296,10 @@ uint32_t Cy_CapSense_GetScanWatchdogTime( #define CY_CAPSENSE_REF_CDAC_LSB_X100 (886u) #define CY_CAPSENSE_MULTIPLIER_TWO (2u) +#define CY_CAPSENSE_CAL_REF_CDAC_MIDDLE_CODE (0x80u) +#define CY_CAPSENSE_CAL_FINE_CDAC_MIDDLE_CODE (0x10u) +#define CY_CAPSENSE_CAL_COMP_CDAC_MIDDLE_CODE (0x80u) + #define CY_CAPSENSE_CAL_FINE_CDAC_Msk (0x1FUL) #define CY_CAPSENSE_CAL_CDAC_Msk (0x1FE0UL) #define CY_CAPSENSE_CAL_CDAC_Pos (5u) @@ -275,6 +311,10 @@ uint32_t Cy_CapSense_GetScanWatchdogTime( #define CY_CAPSENSE_CAL_MODE_REF_CDAC_SUC_APPR (0u) #define CY_CAPSENSE_CAL_MODE_COMP_CDAC_SUC_APPR (2u) +#define CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_MIN (0u) +#define CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_MAX (1u) +#define CY_CAPSENSE_CAL_MODE_COMP_CDAC_CODE_VAL (2u) + #define CY_CAPSENSE_MRSS_TURN_ON (0u) #define CY_CAPSENSE_MRSS_TURN_OFF (1u) #define CY_CAPSENSE_MRSS_IMO_TURN_ON (2u) @@ -519,6 +559,29 @@ uint32_t Cy_CapSense_GetScanWatchdogTime( #define CY_CAPSENSE_CDAC_REF_AUTO_USAGE_MSK (CY_CAPSENSE_ENABLE << CY_CAPSENSE_CDAC_REF_AUTO_USAGE_POS) #define CY_CAPSENSE_CDAC_CDAC_FINE_USAGE_MSK (CY_CAPSENSE_ENABLE << CY_CAPSENSE_CDAC_CDAC_FINE_USAGE_POS) +#define CY_CAPSENSE_CDAC_REF_MODE_MASK (0x3u) +#define CY_CAPSENSE_CDAC_REF_MODE_POS (0u) +#define CY_CAPSENSE_CDAC_FINE_MODE_MASK (0xCu) +#define CY_CAPSENSE_CDAC_FINE_MODE_POS (2u) +#define CY_CAPSENSE_CDAC_COMP_MODE_MASK (0x30u) +#define CY_CAPSENSE_CDAC_COMP_MODE_POS (4u) +#define CY_CAPSENSE_CDAC_COMP_DIV_MODE_MASK (0xC0u) +#define CY_CAPSENSE_CDAC_COMP_DIV_MODE_POS (6u) +#define CY_CAPSENSE_CDAC_BOOST_VAL_MASK (0x700u) +#define CY_CAPSENSE_CDAC_BOOST_VAL_POS (8u) + +#define CY_CAPSENSE_CDAC_MODE_DISABLED (0x0u) +#define CY_CAPSENSE_CDAC_MODE_MANUAL (0x1u) +#define CY_CAPSENSE_CDAC_MODE_AUTO (0x2u) + +#define CY_CAPSENSE_CDAC_REF_MODE_MANUAL_MASK (CY_CAPSENSE_CDAC_MODE_MANUAL << CY_CAPSENSE_CDAC_REF_MODE_POS) +#define CY_CAPSENSE_CDAC_REF_MODE_AUTO_MASK (CY_CAPSENSE_CDAC_MODE_AUTO << CY_CAPSENSE_CDAC_REF_MODE_POS) +#define CY_CAPSENSE_CDAC_FINE_MODE_MANUAL_MASK (CY_CAPSENSE_CDAC_MODE_MANUAL << CY_CAPSENSE_CDAC_FINE_MODE_POS) +#define CY_CAPSENSE_CDAC_FINE_MODE_AUTO_MASK (CY_CAPSENSE_CDAC_MODE_AUTO << CY_CAPSENSE_CDAC_FINE_MODE_POS) +#define CY_CAPSENSE_CDAC_COMP_MODE_MANUAL_MASK (CY_CAPSENSE_CDAC_MODE_MANUAL << CY_CAPSENSE_CDAC_COMP_MODE_POS) +#define CY_CAPSENSE_CDAC_COMP_MODE_AUTO_MASK (CY_CAPSENSE_CDAC_MODE_AUTO << CY_CAPSENSE_CDAC_COMP_MODE_POS) +#define CY_CAPSENSE_CDAC_COMP_DIV_MODE_AUTO_MASK (CY_CAPSENSE_CDAC_MODE_AUTO << CY_CAPSENSE_CDAC_COMP_DIV_MODE_POS) + #if CY_CAPSENSE_CSD_CDAC_CALIBRATION_USAGE #define CY_CAPSENSE_CSD_CDAC_CALIBRATION_USAGE_EN (CY_CAPSENSE_ENABLE) #else @@ -645,11 +708,6 @@ uint32_t Cy_CapSense_GetScanWatchdogTime( (CY_CAPSENSE_ISX_CDAC_REF_AUTO_USAGE_MSK) |\ (CY_CAPSENSE_ISX_CDAC_CDAC_FINE_USAGE_MSK)) -/* CAPSENSE IMO clock values in MHz */ -#define CY_CAPSENSE_IMO_CLK_25_MHZ (25u) -#define CY_CAPSENSE_IMO_CLK_38_MHZ (38u) -#define CY_CAPSENSE_IMO_CLK_46_MHZ (46u) - #define CY_CAPSENSE_CPU_CLK_MHZ (CY_CAPSENSE_CPU_CLK / CY_CAPSENSE_CONVERSION_MEGA) /* Used for the Cy_CapSense_ExecuteSaturatedScan() function to obtain the MAX raw count. */ diff --git a/cy_capsense_sensing_v2.c b/cy_capsense_sensing_v2.c index 4fc1966..6cf4c76 100644 --- a/cy_capsense_sensing_v2.c +++ b/cy_capsense_sensing_v2.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_sensing_v2.c -* \version 4.0 +* \version 5.0 * * \brief * This file contains the source of functions common for different sensing @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 @@ -135,6 +135,10 @@ void Cy_CapSense_ClrBusyFlags(cy_stc_capsense_context_t * context) * * 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 @@ -229,14 +233,19 @@ cy_capsense_status_t Cy_CapSense_SetupWidget( * 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, status of the current scan -* should be checked using the Cy_CapSense_IsBusy() and wait until all scans +* 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. * diff --git a/cy_capsense_sensing_v2.h b/cy_capsense_sensing_v2.h index 82bccd4..7211203 100644 --- a/cy_capsense_sensing_v2.h +++ b/cy_capsense_sensing_v2.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_sensing_v2.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes specific to the sensing module. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_sensing_v3.c b/cy_capsense_sensing_v3.c index 3570a97..16e446f 100644 --- a/cy_capsense_sensing_v3.c +++ b/cy_capsense_sensing_v3.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_sensing_v3.c -* \version 4.0 +* \version 5.0 * * \brief * This file contains the source of functions common for different scanning @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 @@ -58,6 +58,35 @@ /* 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 @@ -135,6 +164,20 @@ 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 */ @@ -1213,7 +1256,7 @@ cy_capsense_status_t Cy_CapSense_SsInitialize(cy_stc_capsense_context_t * contex &context->ptrSensorFrameContext[(CY_CAPSENSE_SLOT_COUNT * (curChIndex + context->ptrCommonConfig->channelOffset)) * CY_MSC_6_SNS_REGS], context); - #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */ + #endif } /* Assign the ISR for scan */ @@ -1238,6 +1281,13 @@ cy_capsense_status_t Cy_CapSense_SsInitialize(cy_stc_capsense_context_t * contex capStatus |= Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_REGULAR_SCANNING, context); } + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) + if (CY_CAPSENSE_STATUS_SUCCESS == capStatus) + { + capStatus = Cy_CapSense_CdacDitherScaleCalc(context); + } + #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) */ + /* Find maximum raw count for each widget */ for (i = 0u; i < context->ptrCommonConfig->numWd; i++) { @@ -3431,6 +3481,17 @@ cy_capsense_status_t Cy_CapSense_CalibrateSlot( /* Checks a slot for auto-calibration */ for (chIndex = 0u; chIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; chIndex++) { + #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) + if (context->ptrInternalContext->hwConfigState != CY_CAPSENSE_HW_CONFIG_REGULAR_SCANNING) + { + /* Generates sensor frame configuration */ + Cy_CapSense_GenerateAllSensorConfig(chIndex, + &context->ptrSensorFrameContext[(CY_CAPSENSE_SLOT_COUNT * + (chIndex + context->ptrCommonConfig->channelOffset)) * + CY_MSC_6_SNS_REGS], context); + } + #endif + wdIndex = context->ptrScanSlots[scanSlotId + (CY_CAPSENSE_SLOT_COUNT * chIndex)].wdId; if (CY_CAPSENSE_SLOT_SHIELD_ONLY > wdIndex) { @@ -4371,6 +4432,10 @@ cy_capsense_status_t Cy_CapSense_SwitchHwConfiguration( #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */ case CY_CAPSENSE_HW_CONFIG_CHANNEL_SATURATION: break; + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) + case CY_CAPSENSE_HW_CONFIG_AUTO_DITHERING: + break; + #endif default: capStatus = CY_CAPSENSE_STATUS_BAD_PARAM; break; @@ -4422,8 +4487,6 @@ cy_capsense_status_t Cy_CapSense_SwitchHwConfiguration( ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->INTR = CY_CAPSENSE_MSC_INTR_ALL_MSK; (void)ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->INTR; } - /* The time interval is required for settling analog part of the HW block. */ - Cy_SysLib_DelayUs(CY_CAPSENSE_ANALOG_SETTLING_TIME_US); break; case CY_CAPSENSE_HW_CONFIG_BIST_FUNCTIONALITY: Cy_CapSense_SetIOsInDefaultState(context); @@ -4440,12 +4503,15 @@ cy_capsense_status_t Cy_CapSense_SwitchHwConfiguration( ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->INTR = CY_CAPSENSE_MSC_INTR_ALL_MSK; (void)ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->INTR; } - /* The time interval is required for settling analog part of the HW block. */ - Cy_SysLib_DelayUs(CY_CAPSENSE_ANALOG_SETTLING_TIME_US); break; case CY_CAPSENSE_HW_CONFIG_CHANNEL_SATURATION: - Cy_CapSense_ConfigureSaturationMode(context); + capStatus = Cy_CapSense_ConfigureSaturationMode(context); break; + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) + case CY_CAPSENSE_HW_CONFIG_AUTO_DITHERING: + capStatus = Cy_CapSense_ConfigureAutoDitherMode(context); + break; + #endif default: capStatus = CY_CAPSENSE_STATUS_BAD_PARAM; break; @@ -5300,14 +5366,14 @@ cy_capsense_status_t Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context) #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN) /* Check for sub-widget */ - if(0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK)) + if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK)) { - if(0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_CH_1_MASK)) + if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_CH_1_MASK)) { autoTuneConfig.kRef1 += CY_CAPSENSE_CSD_MFS_DIVIDER_OFFSET_F1; } - if(0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_CH_2_MASK)) + if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_CH_2_MASK)) { autoTuneConfig.kRef1 += CY_CAPSENSE_CSD_MFS_DIVIDER_OFFSET_F2; } @@ -5332,7 +5398,7 @@ cy_capsense_status_t Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context) ptrWdCxt->numSubConversions = (uint16_t)numberSubConv / ptrWdCfg->numChopCycles; /* Decrease Nsub when CompCDAC is enabled as it increases the sensitivity approximately twice */ - #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) ptrWdCxt->numSubConversions >>= 1u; numberSubConv = (uint32_t)ptrWdCxt->numSubConversions << 1u; #endif @@ -5611,7 +5677,7 @@ uint32_t Cy_CapSense_GetCIC2HwDivider( * *******************************************************************************/ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( - uint16_t * ptrMaxRaw, + uint32_t * ptrMaxRaw, uint32_t scanSlotId, uint32_t mode, cy_stc_capsense_context_t * context) @@ -5624,14 +5690,6 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( uint32_t * ptrSnsFrame; #endif - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) - uint32_t kref; - uint32_t nsub; - uint32_t decimRate; - uint32_t samples; - uint32_t hwDivider; - #endif - const uint32_t cpuCyclesPerLoop = 5u; MSC_Type * ptrHwBase = context->ptrCommonConfig->ptrChConfig[0u].ptrHwBase; @@ -5653,7 +5711,7 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( ptrHwBase->FILTER_CTL &= (~MSC_FILTER_CTL_FILTER_MODE_Msk); #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) - if(CY_CAPSENSE_SATURATED_MAX_COUNT == mode) + if (CY_CAPSENSE_SATURATED_MAX_COUNT == mode) { /* Keep CIC2 filtering enabled if it is used in the current MW configuration * to measure the MAX raw count. @@ -5689,13 +5747,19 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( scanConfigTmp[1u] = 0x00u; /* Set up the SNS_SW_SEL_CSW_MASK1 register configuration. */ scanConfigTmp[2u] = 0x00u; /* Set up the SNS_SW_SEL_CSW_MASK0 register configuration. */ - if(status == CY_CAPSENSE_STATUS_SUCCESS) + scanConfigTmp[3u] &= (uint32_t)(~MSC_SNS_SCAN_CTL_NUM_CONV_Msk); /* Disable System Chopping */ + + if (status == CY_CAPSENSE_STATUS_SUCCESS) { /* Initiate the scan in the CPU operating mode */ - Cy_MSC_ConfigureScan(ptrHwBase, CY_MSC_6_SNS_REGS, scanConfigTmp); + Cy_MSC_ConfigureScan(ptrHwBase, CY_MSC_6_SNS_REGS, &scanConfigTmp[0u]); + + /* Disable clock sync and external frame start */ + ptrHwBase->CTL &= ~(MSC_CTL_CLK_SYNC_EN_Msk | MSC_CTL_EXT_FRAME_START_EN_Msk); /* Clear all pending interrupts */ ptrHwBase->INTR = CY_CAPSENSE_MSC_INTR_ALL_MSK; + (void)ptrHwBase->INTR; /* Set the multi-channel mode configuration to OFF */ ptrHwBase->SNS_CTL &= (~MSC_SNS_CTL_MULTI_CH_MODE_Msk); @@ -5710,7 +5774,7 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( ptrHwBase->FRAME_CMD = MSC_FRAME_CMD_START_FRAME_Msk; watchdog = Cy_CapSense_GetScanWatchdogTime(scanSlotId, context); - tmpVal = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_KILO; + tmpVal = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA; watchdog = Cy_CapSense_WatchdogCyclesNum(watchdog, tmpVal, cpuCyclesPerLoop); while ((ptrHwBase->INTR & MSC_INTR_MASK_SCAN_Msk) == 0u) @@ -5724,31 +5788,26 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( tmpVal = (uint16_t)ptrHwBase->RESULT_FIFO_RD; - #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) - if (1u != context->ptrWdConfig->numChopCycles) - { - kref = ((scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] & MSC_SNS_CTL_SENSE_DIV_Msk) >> MSC_SNS_CTL_SENSE_DIV_Pos) + 1u; - decimRate = ((scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] & MSC_SNS_CTL_DECIM_RATE_Msk) >> MSC_SNS_CTL_DECIM_RATE_Pos) + 1u; - nsub = ((scanConfigTmp[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] & MSC_SNS_SCAN_CTL_NUM_SUB_CONVS_Msk) >> MSC_SNS_SCAN_CTL_NUM_SUB_CONVS_Pos) + 1u; - /* Valid Samples */ - samples = (((kref * nsub) / decimRate) - 1u) * context->ptrWdConfig->numChopCycles; - hwDivider = Cy_CapSense_GetCIC2HwDivider(samples); - tmpVal = ((((tmpVal * hwDivider) - (kref * nsub)) * context->ptrWdConfig->numChopCycles) + (kref * nsub)) / hwDivider; - } - #else + #if (CY_CAPSENSE_DISABLE == CY_CAPSENSE_CIC2_FILTER_EN) + tmpVal -= ((uint32_t)context->ptrInternalContext->numEpiCycles - 1u); tmpVal *= context->ptrWdConfig->numChopCycles; #endif *ptrMaxRaw = CY_CAPSENSE_16_BIT_MASK; - if(tmpVal <= CY_CAPSENSE_16_BIT_MASK) + if (tmpVal <= CY_CAPSENSE_16_BIT_MASK) { *ptrMaxRaw = (uint16_t)tmpVal; } /* Clear all pending interrupts */ ptrHwBase->INTR = CY_CAPSENSE_MSC_INTR_ALL_MSK; + (void)ptrHwBase->INTR; + + /* Restore clock sync and external frame start settings */ + ptrHwBase->CTL |= (uint32_t)(((uint32_t)context->ptrCommonConfig->syncFrameStartEn << MSC_CTL_EXT_FRAME_START_EN_Pos) | + ((uint32_t)context->ptrCommonConfig->syncClockEn << MSC_CTL_CLK_SYNC_EN_Pos)); - if(0u == watchdog) + if (0u == watchdog) { status |= CY_CAPSENSE_STATUS_TIMEOUT; } @@ -5770,46 +5829,96 @@ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( * \param context * The pointer to the context structure allocated by the user or middleware. * +* \return +* Returns the status of the operation: +* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed successfully. +* - CY_CAPSENSE_STATUS_HW_BUSY - The MSCLP HW block is busy and cannot be +* configured. +* *******************************************************************************/ -void Cy_CapSense_ConfigureSaturationMode( +cy_capsense_status_t Cy_CapSense_ConfigureSaturationMode( cy_stc_capsense_context_t * context) { + cy_capsense_status_t status = CY_CAPSENSE_STATUS_SUCCESS; + cy_en_msc_status_t mscStatus; + uint32_t curChIndex; uint32_t i; - MSC_Type * ptrHwBase = context->ptrCommonConfig->ptrChConfig[0u].ptrHwBase; + MSC_Type * ptrHwBase; + const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig; - /* Enable HW IP to allow a scan frame start */ - ptrHwBase->CTL |= MSC_CTL_ENABLED_Msk; + /* Initializes all enabled MSC channels for scan */ + for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++) + { + ptrHwBase = ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase; - /* Disable all interrupts */ - ptrHwBase->INTR_MASK = 0x00u; + /* Generates base frame configurations for all enabled MSC channels */ + status |= Cy_CapSense_GenerateBaseConfig(curChIndex, context); - /* The 0x00 value of the OPERATING_MODE field switches the HW to the CPU - * configures it to generate VDDA/2 voltage at the output. - */ - CY_REG32_CLR_SET(ptrHwBase->CTL, MSC_CTL_OPERATING_MODE, 0u); + if (CY_CAPSENSE_STATUS_SUCCESS != status) + { + break; + } - /* Configure the Switch Control Global Function #0 to have all switches open. - * All the sensing electrodes will be disconnected during the MAX raw count measurement. - */ - ptrHwBase->SW_SEL_CSW_FUNC[0u] = 0x00u; + #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) + /* Generates sensor frame configuration */ + Cy_CapSense_GenerateAllSensorConfig(curChIndex, + &context->ptrSensorFrameContext[(CY_CAPSENSE_SLOT_COUNT * + (curChIndex + context->ptrCommonConfig->channelOffset)) * + CY_MSC_6_SNS_REGS], context); + #endif - /* Iterate through all the MODE structures and update them with the configuration, - * required to saturate the measurement channel. - */ - for(i = 0u; i < MSC0_SENSE_MODE_NR; i++) + /* MSCv3 IP Block Base Register Configuration */ + mscStatus = Cy_MSC_Configure(ptrHwBase, + &context->ptrBaseFrameContext[curChIndex], + CY_MSC_CAPSENSE_KEY, + ptrCommonCfg->ptrChConfig[curChIndex].ptrHwContext); + + if (CY_MSC_SUCCESS != mscStatus) + { + status = CY_CAPSENSE_STATUS_HW_BUSY; + } + } + + if (CY_CAPSENSE_STATUS_SUCCESS == status) { - /* The 0x01 value of the RMF field enables the internal voltage divider and - * configures it to generate VDDA/2 voltage at the output. - */ - ptrHwBase->MODE[i].SW_SEL_TOP = _VAL2FLD(MSC_MODE_SW_SEL_TOP_RMF, 0x01u); + ptrHwBase = context->ptrCommonConfig->ptrChConfig[0u].ptrHwBase; - /* Set the CPF and the CMG bits to get the positive comparator input connected - * to the VDDA/2 voltage level and the negative comparator input to the GND. - */ - ptrHwBase->MODE[i].SW_SEL_COMP = _VAL2FLD(MSC_MODE_SW_SEL_COMP_CPF, 0x01u) | - _VAL2FLD(MSC_MODE_SW_SEL_COMP_CMG, 0x01u); + /* Enables HW IP to allow a scan frame start */ + ptrHwBase->CTL |= MSC_CTL_ENABLED_Msk; + + /* Disables all interrupts */ + ptrHwBase->INTR_MASK = 0x00u; + (void)ptrHwBase->INTR_MASK; + + /* The 0x00 value of the OPERATING_MODE field switches the HW to the CPU + * configures it to generate VDDA/2 voltage at the output. + */ + CY_REG32_CLR_SET(ptrHwBase->CTL, MSC_CTL_OPERATING_MODE, 0u); + + /* Configures the Switch Control Global Function #0 to have all switches open. + * All the sensing electrodes will be disconnected during the MAX raw count measurement. + */ + ptrHwBase->SW_SEL_CSW_FUNC[0u] = 0x00u; + + /* Iterates through all the MODE structures and update them with the configuration, + * required to saturate the measurement channel. + */ + for (i = 0u; i < MSC0_SENSE_MODE_NR; i++) + { + /* The 0x01 value of the RMF field enables the internal voltage divider and + * configures it to generate VDDA/2 voltage at the output. + */ + ptrHwBase->MODE[i].SW_SEL_TOP = _VAL2FLD(MSC_MODE_SW_SEL_TOP_RMF, 0x01u); + + /* Sets the CPF and the CMG bits to get the positive comparator input connected + * to the VDDA/2 voltage level and the negative comparator input to the GND. + */ + ptrHwBase->MODE[i].SW_SEL_COMP = _VAL2FLD(MSC_MODE_SW_SEL_COMP_CPF, 0x01u) | + _VAL2FLD(MSC_MODE_SW_SEL_COMP_CMG, 0x01u); + } } + return status; } @@ -5825,15 +5934,15 @@ void Cy_CapSense_ConfigureSaturationMode( * * where: * -* SCAN_CYCLES = (INIT_CYCLES + PRO_CYCLES + CONV_CYCLES + EPI_CYCLES) * NUM_CONV; +* SCAN_CYCLES = INIT_CYCLES + (PRO_CYCLES + CONV_CYCLES + EPI_CYCLES) * NUM_CONV; * INIT_CYCLES = INIT_CMOD_RAIL_CYCLES + INIT_CMOD_SHORT_CYCLES; -* PRO_CYCLES = PRO_OFFSET_CYCLES + (PRO_WAIT_KREF_DELAY * SENSE_DIV / 4); +* PRO_CYCLES = PRO_OFFSET_CYCLES + PRO_WAIT_KREF_DELAY; * CONV_CYCLES = (PRO_DUMMY_SUB_CONVS + NUM_SUB_CONVS) * SENSE_DIV; -* EPI_CYCLES = EPI_KREF_DELAY * SENSE_DIV / 4; +* EPI_CYCLES = EPI_KREF_DELAY; * * The corresponding parameters are listed below: * - EPI_KREF_DELAY - The duration of EPILOGUE defined in relation to Kref. -* The value is interpreted as SENSE_DIV/4 increments. +* The value is interpreted as number of clk_mod cycles. * - INIT_CMOD_RAIL_CYCLES - Duration of the coarse initialization phase when * Cmod1 is connected to VDDA and Cmod2 is connected to VSSA. The parameter is * defined in terms of Mod Clock cycles. @@ -5846,7 +5955,7 @@ void Cy_CapSense_ConfigureSaturationMode( * - PRO_DUMMY_SUB_CONVS - Number of sub-conversions (dummy cycles) to be run * during PRO_DUMMY. * - PRO_WAIT_KREF_DELAY - The duration of PRO_WAIT defined in relation to Kref. -* The value is interpreted as SENSE_DIV/4 increments. +* The value is interpreted as SENSE_DIV increments. * - SENSE_DIV - The length of one sub-conversion in terms of Mod Clock cycles. * - NUM_SUB_CONVS - Number of sub-conversions. * - NUM_CONV - Number of chop cycles. @@ -5890,7 +5999,7 @@ uint32_t Cy_CapSense_GetScanWatchdogTime( for (tmpVal = 0u; tmpVal < CY_CAPSENSE_TOTAL_CH_NUMBER; tmpVal++) { ptrScanSlots = &context->ptrScanSlots[scanSlotId + (CY_CAPSENSE_SLOT_COUNT * tmpVal)]; - if(CY_CAPSENSE_SLOT_SHIELD_ONLY > ptrScanSlots->wdId) + if (CY_CAPSENSE_SLOT_SHIELD_ONLY > ptrScanSlots->wdId) { ptrWdCfg = &context->ptrWdConfig[ptrScanSlots->wdId]; break; @@ -5915,19 +6024,8 @@ uint32_t Cy_CapSense_GetScanWatchdogTime( } #endif /* CY_CAPSENSE_CSD_EN */ - /* Calculate the INIT_CYCLES number. */ - tmpVal = ((uint32_t)context->ptrInternalContext->numCoarseInitChargeCycles + context->ptrInternalContext->numCoarseInitSettleCycles); - - /* Add the PRO_OFFSET_CYCLES number. */ - tmpVal += (uint32_t)context->ptrInternalContext->numProOffsetCycles; - - /* Add the sum of PRO_CYCLES and EPI_CYCLES. The .numFineInitWaitCycles and the .numEpiCycles parameters are defined in terms of - * Mod Clock cycles for the fifth-generation devices. - */ - tmpVal += ((uint32_t)context->ptrInternalContext->numFineInitWaitCycles + context->ptrInternalContext->numEpiCycles); - - /* Add the CONV_CYCLES number. */ - tmpVal += ((uint32_t)context->ptrInternalContext->numFineInitCycles + ptrWdCfg->ptrWdContext->numSubConversions); + /* Calculate the CONV_CYCLES number. */ + tmpVal = ((uint32_t)context->ptrInternalContext->numFineInitCycles + ptrWdCfg->ptrWdContext->numSubConversions); tmpVal *= snsClkDivider; if (CY_CAPSENSE_CLK_SOURCE_PRS == (ptrWdCfg->ptrWdContext->snsClkSource & CY_CAPSENSE_CLK_SOURCE_MASK)) @@ -5938,11 +6036,22 @@ uint32_t Cy_CapSense_GetScanWatchdogTime( tmpVal <<= 1u; } + /* Add the PRO_CYCLES number. */ + tmpVal += ((uint32_t)context->ptrInternalContext->numProOffsetCycles + context->ptrInternalContext->numFineInitWaitCycles); + + /* Add the EPI_CYCLES. The .numEpiCycles parameter is defined in terms of + * Mod Clock cycles for the fifth-generation devices. + */ + tmpVal += (uint32_t)context->ptrInternalContext->numEpiCycles; + /* Calculate the SCAN_CYCLES number by multiplying the Mod Clock cycles number per one chop cycle by * number of chop cycles. */ tmpVal *= ptrWdCfg->numChopCycles; + /* Add the INIT_CYCLES number. */ + tmpVal += ((uint32_t)context->ptrInternalContext->numCoarseInitChargeCycles + context->ptrInternalContext->numCoarseInitSettleCycles); + /* Convert the calculated duration in terms of clk_mod cycles to the microseconds. */ tmpVal /= modClkFreqMhz; @@ -5953,6 +6062,427 @@ uint32_t Cy_CapSense_GetScanWatchdogTime( } +#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CDAC_AUTO_DITHER_EN) +/******************************************************************************* +* Function Name: Cy_CapSense_ConfigureAutoDitherMode +****************************************************************************//** +* +* Configures the MSC HW block for operation in the auto-dithering mode. +* +* \param context +* The pointer to the context structure allocated by the user or middleware. +* +* \return +* Returns the status of the operation: +* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed successfully. +* - CY_CAPSENSE_STATUS_CONFIG_OVERFLOW - The number of pin function exceeds the limit. +* - CY_CAPSENSE_STATUS_BAD_CONFIG - The function does not suppose to be +* called with the current CAPSENSE™ +* configuration. +* - CY_CAPSENSE_STATUS_HW_BUSY - The MSCLP HW block is busy and cannot be +* configured. +* +*******************************************************************************/ +static cy_capsense_status_t Cy_CapSense_ConfigureAutoDitherMode( + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t status = CY_CAPSENSE_STATUS_SUCCESS; + cy_en_msc_status_t mscStatus; + const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig; + uint32_t curChIndex; + MSC_Type * ptrHwBase; + + Cy_CapSense_SetModClkDivider(context->ptrInternalContext->modClk, context); + Cy_CapSense_SetIOsInDefaultState(context); + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) + Cy_CapSense_SetShieldPinsInDefaultState(context); + #endif + + /* Initializes all enabled MSC channels for scan */ + for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++) + { + context->ptrActiveScanSns[curChIndex].currentSenseMethod = CY_CAPSENSE_UNDEFINED_GROUP; + + #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) + Cy_CapSense_SetCmodInAmuxModeState(curChIndex, context); + #else + Cy_CapSense_SetCmodInDefaultState(curChIndex, context); + #endif + + ptrHwBase = ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase; + + /* Generates base frame configurations for all enabled MSC channels */ + status |= Cy_CapSense_GenerateBaseConfig(curChIndex, context); + + if (CY_CAPSENSE_STATUS_SUCCESS != status) + { + break; + } + + #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) + /* Generates sensor frame configuration */ + Cy_CapSense_GenerateAllSensorConfig(curChIndex, + &context->ptrSensorFrameContext[(CY_CAPSENSE_SLOT_COUNT * + (curChIndex + context->ptrCommonConfig->channelOffset)) * + CY_MSC_6_SNS_REGS], context); + #endif + + /* MSCv3 IP Block Base Register Configuration */ + mscStatus = Cy_MSC_Configure(ptrHwBase, + &context->ptrBaseFrameContext[curChIndex], + CY_MSC_CAPSENSE_KEY, + ptrCommonCfg->ptrChConfig[curChIndex].ptrHwContext); + + if (CY_MSC_SUCCESS != mscStatus) + { + status = CY_CAPSENSE_STATUS_HW_BUSY; + break; + } + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CIC2_FILTER_EN) + /* Sets FILTER_MODE to CIC1 */ + ptrHwBase->FILTER_CTL &= ~MSC_FILTER_CTL_FILTER_MODE_Msk; + #endif /* CY_CAPSENSE_CIC2_FILTER_EN */ + + /* Clears all pending interrupts of the current MSC HW block */ + ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->INTR = CY_CAPSENSE_MSC_INTR_ALL_MSK; + (void)ptrCommonCfg->ptrChConfig[curChIndex].ptrHwBase->INTR; + + /* Disables all interrupts */ + ptrHwBase->INTR_MASK = 0x00u; + (void)ptrHwBase->INTR_MASK; + + /* Enables HW IP to allow a scan frame start */ + ptrHwBase->CTL |= MSC_CTL_ENABLED_Msk; + + ptrHwBase->CTL &= ~MSC_CTL_OPERATING_MODE_Msk; + } + + return status; +} + + +/******************************************************************************* +* Function Name: Cy_CapSense_CdacDitherScaleCalc +****************************************************************************//** +* +* This internal function calculates the dither scale value based on highest +* raw count value in AUTO dithering mode. +* +* \param context +* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. +* +* \return status +* Returns the status of the operation (different statuses can be combined): +* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed +* successfully. +* - CY_CAPSENSE_STATUS_BAD_PARAM - At least one of input parameters is +* not valid. +* - CY_CAPSENSE_STATUS_HW_BUSY - The HW is busy with the previous scan. +* +*******************************************************************************/ +static cy_capsense_status_t Cy_CapSense_CdacDitherScaleCalc( + cy_stc_capsense_context_t * context) +{ + cy_capsense_status_t status = CY_CAPSENSE_STATUS_SUCCESS; + const cy_stc_capsense_widget_config_t * ptrWdCfg; + cy_stc_capsense_sensor_context_t * ptrSnsCxt; + uint32_t watchdog; + uint32_t wdIndex; + uint32_t slotId; + uint32_t rawCountMax; + uint32_t curChIndex; + uint32_t slotValue; + uint32_t scanSlotIndexValid; + uint32_t scanFlag; + #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) + uint32_t snsIndex; + #endif + uint32_t slotIndex; + MSC_Type * ptrHwBase; + const cy_stc_capsense_scan_slot_t * ptrScanSlots; + + /* Forces HW configuration update on the next scan */ + status = Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_AUTO_DITHERING, context); + + /* Performs scans for active slots */ + for (slotId = 0u; slotId < CY_CAPSENSE_SLOT_COUNT; slotId++) + { + scanFlag = 0u; + + for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++) + { + context->ptrActiveScanSns[curChIndex].currentChannelSlotIndex = (uint16_t)slotId; + slotIndex = slotId + (curChIndex * CY_CAPSENSE_SLOT_COUNT); + ptrScanSlots = &context->ptrScanSlots[slotIndex]; + slotValue = ptrScanSlots->wdId; + scanSlotIndexValid = slotIndex; + + if (CY_CAPSENSE_SLOT_EMPTY == slotValue) + { + #if (CY_CAPSENSE_TOTAL_CH_NUMBER > 1u) + if (slotIndex < 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)ptrScanSlots->snsId * CY_CAPSENSE_SLOT_COUNT) + slotId; + } + else + { + /* Do nothing */ + } + + /* Initializes for each channel the active sensor structure for the current sensor */ + wdIndex = context->ptrScanSlots[scanSlotIndexValid].wdId; + ptrWdCfg = &context->ptrWdConfig[wdIndex]; + + #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) + snsIndex = context->ptrScanSlots[scanSlotIndexValid].snsId; + (void)Cy_CapSense_ConfigureAnalogMuxResource(curChIndex, context->ptrWdConfig[wdIndex].senseMethod, context); + Cy_CapSense_InitActivePtr(curChIndex, wdIndex, snsIndex, context); + + if ((slotValue != CY_CAPSENSE_SLOT_EMPTY) && + (slotValue != CY_CAPSENSE_SLOT_SHIELD_ONLY)) + { + /* Connects the widget first sensor electrodes */ + Cy_CapSense_ConnectSensor(curChIndex, context); + } + #endif + + if (CY_CAPSENSE_CDAC_DITHERING_MODE_AUTO == ptrWdCfg->cdacDitherScaleMode) + { + /* Handles only CSD and CSX widgets */ + if (CY_CAPSENSE_ISX_GROUP != ptrWdCfg->senseMethod) + { + /* Sets a flag to perform scan */ + scanFlag = 1u; + } + } + } + + if (0u != scanFlag) + { + for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++) + { + ptrHwBase = context->ptrCommonConfig->ptrChConfig[curChIndex].ptrHwBase; + ptrHwBase->FRAME_CMD = MSC_FRAME_CMD_START_FRAME_Msk; + } + + for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++) + { + ptrHwBase = context->ptrCommonConfig->ptrChConfig[curChIndex].ptrHwBase; + slotIndex = slotId + (curChIndex * CY_CAPSENSE_SLOT_COUNT); + status = Cy_CapSense_CdacDitherConfigScan(ptrHwBase, curChIndex, ((curChIndex * CY_CAPSENSE_SLOT_COUNT) + slotId), slotIndex * CY_MSC_6_SNS_REGS, context); + } + watchdog = CY_CAPSENSE_CDAC_DITHERING_MOD_CLK_PERIODS; + ptrHwBase = context->ptrCommonConfig->ptrChConfig[0u].ptrHwBase; + + /* Waits end of scan */ + while ((ptrHwBase->INTR & MSC_INTR_MASK_SCAN_Msk) == 0u) + { + if (0uL == watchdog) + { + break; + } + watchdog--; + } + + if (0u == watchdog) + { + status |= CY_CAPSENSE_STATUS_TIMEOUT; + } + else + { + for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++) + { + ptrHwBase = context->ptrCommonConfig->ptrChConfig[curChIndex].ptrHwBase; + ptrScanSlots = &context->ptrScanSlots[slotId + (CY_CAPSENSE_SLOT_COUNT * curChIndex)]; + + if (CY_CAPSENSE_SLOT_SHIELD_ONLY > ptrScanSlots->wdId) + { + ptrWdCfg = &context->ptrWdConfig[context->ptrScanSlots[slotId + (curChIndex * CY_CAPSENSE_SLOT_COUNT)].wdId]; + + if (CY_CAPSENSE_CDAC_DITHERING_MODE_AUTO == ptrWdCfg->cdacDitherScaleMode) + { + /* Handles only CSD and CSX widgets */ + if (CY_CAPSENSE_ISX_GROUP != ptrWdCfg->senseMethod) + { + ptrSnsCxt = &ptrWdCfg->ptrSnsContext[context->ptrScanSlots[slotId + (curChIndex * CY_CAPSENSE_SLOT_COUNT)].snsId]; + + /* Reads raw counts */ + ptrSnsCxt->raw = (uint16_t)(ptrHwBase->RESULT_FIFO_RD & MSC_RESULT_FIFO_RD_RAW_COUNT_Msk); + } + } + } + /* Clears all pending interrupts */ + ptrHwBase->INTR = CY_CAPSENSE_MSC_INTR_ALL_MSK; + (void)ptrHwBase->INTR; + + #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) + if (CY_CAPSENSE_SNS_CONNECTED == context->ptrActiveScanSns[curChIndex].connectedSnsState) + { + /* Disconnects the scanned sensor */ + Cy_CapSense_DisconnectSensor(curChIndex, context); + } + #endif + } + } + } + } + + if (status == CY_CAPSENSE_STATUS_SUCCESS) + { + for (wdIndex = 0u; wdIndex < CY_CAPSENSE_TOTAL_WIDGET_COUNT; wdIndex++) + { + ptrWdCfg = &context->ptrWdConfig[wdIndex]; + if (CY_CAPSENSE_CDAC_DITHERING_MODE_AUTO == ptrWdCfg->cdacDitherScaleMode) + { + rawCountMax = 0u; + ptrSnsCxt = ptrWdCfg->ptrSnsContext; + + for (slotId = 0u; slotId < ptrWdCfg->numSns; slotId++) + { + /* Finds the biggest raw count value in widget */ + if (ptrSnsCxt->raw > rawCountMax) + { + rawCountMax = ptrSnsCxt->raw; + } + ptrSnsCxt++; + } + + #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) + /* Divides the result by 2 for the FW CSX scanning method */ + if (CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod) + { + rawCountMax >>= 1u; + } + #endif + + /* Sets dither value according to measured widget raw counts */ + if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_300_FEMTO_RAW) + { + ptrWdCfg->ptrWdContext->cdacDitherValue = 6u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_500_FEMTO_RAW) + { + ptrWdCfg->ptrWdContext->cdacDitherValue = 5u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_1000_FEMTO_RAW) + { + ptrWdCfg->ptrWdContext->cdacDitherValue = 4u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_3000_FEMTO_RAW) + { + ptrWdCfg->ptrWdContext->cdacDitherValue = 3u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_5000_FEMTO_RAW) + { + ptrWdCfg->ptrWdContext->cdacDitherValue = 2u; + } else if (rawCountMax < CY_CAPSENSE_DITHERING_SNS_CAP_10000_FEMTO_RAW) + { + ptrWdCfg->ptrWdContext->cdacDitherValue = 1u; + } else + { + ptrWdCfg->ptrWdContext->cdacDitherValue = 0u; + } + } + } + } + + return status; +} + + +/******************************************************************************* +* Function Name: Cy_CapSense_CdacDitherConfigScan +****************************************************************************//** +* +* This internal function configures and performs scanning for a slot. +* +* \param ptrHwBase +* The pointer to HW base pointer for current channel. +* +* \param chId +* Specifies the ID number of the channel +* +* \param slotId +* Specifies the ID number of the slot. +* +* \param snsFrameIdx +* The index of sensor frame context structure. +* +* \param context +* The pointer to the CAPSENSE™ context structure \ref cy_stc_capsense_context_t. +* +* \return status +* Returns the status of the operation (different statuses can be combined): +* - CY_CAPSENSE_STATUS_SUCCESS - The operation is performed +* successfully. +* - CY_CAPSENSE_STATUS_TIMEOUT - The software watchdog timeout occurred +* during the scan, the scan was not completed. +* +*******************************************************************************/ +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) +{ + cy_capsense_status_t status = CY_CAPSENSE_STATUS_SUCCESS; + + uint32_t scanConfigTmp[CY_MSC_6_SNS_REGS] = {0u, 0u, 0u, 0u, 0u, 0u}; + #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) + (void)snsFrameIdx; + uint32_t index; + #endif + + #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) + /* Inherits sensor frame to local array */ + for (index = 0; index < CY_MSC_6_SNS_REGS; index++) + { + scanConfigTmp[index] = context->ptrSensorFrameContext[snsFrameIdx + index]; + } + #else /* CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD */ + /* Getting the sensor frame configuration */ + (void)Cy_CapSense_GenerateSensorConfig(chId, slotId, &scanConfigTmp[0u], context); + #endif + + /* Configures Sensor Clock, Clock Sources, set the multi-channel mode configuration to OFF */ + scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] &= (uint32_t)~(MSC_SNS_CTL_START_SCAN_Msk | MSC_SNS_CTL_MULTI_CH_MODE_Msk | + MSC_SNS_CTL_SENSE_DIV_Msk | MSC_SNS_CTL_LFSR_MODE_Msk); + scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] |= (((CY_CAPSENSE_CDAC_DITHERING_KREF - 1u) << MSC_SNS_CTL_SENSE_DIV_Pos) | + MSC_SNS_CTL_LAST_Msk | MSC_SNS_CTL_VALID_Msk | MSC_SNS_CTL_START_SCAN_Msk); + + if (1u < CY_CAPSENSE_TOTAL_CH_NUMBER) + { + scanConfigTmp[CY_CAPSENSE_SNS_CTL_INDEX] |= (CY_CAPSENSE_SYNC_INTERNAL << MSC_SNS_CTL_MULTI_CH_MODE_Pos); + } + + /* Disables chopping. Configures Number of sub-conversions, Compensation divider */ + scanConfigTmp[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] &= (uint32_t)~(MSC_SNS_SCAN_CTL_NUM_CONV_Msk | + MSC_SNS_SCAN_CTL_NUM_SUB_CONVS_Msk | + MSC_SNS_SCAN_CTL_COMP_DIV_Msk); + scanConfigTmp[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= (((CY_CAPSENSE_CDAC_DITHERING_NUM_SUBCONV - 1u) << MSC_SNS_SCAN_CTL_NUM_SUB_CONVS_Pos) | + ((CY_CAPSENSE_CDAC_DITHERING_COMP_DIV - 1u) << MSC_SNS_SCAN_CTL_COMP_DIV_Pos)); + + /* Configures Cap DACs and Clock reference rate*/ + scanConfigTmp[CY_CAPSENSE_SNS_CDAC_CTL_INDEX] = 0u; + scanConfigTmp[CY_CAPSENSE_SNS_CDAC_CTL_INDEX] |= ((CY_CAPSENSE_CDAC_DITHERING_CDAC_REF << MSC_SNS_CDAC_CTL_SEL_RE_Pos) | + (CY_CAPSENSE_CDAC_DITHERING_CLOCK_REF_RATE << MSC_SNS_CDAC_CTL_CLOCK_REF_RATE_Pos)); + + /* Initiates the scan in the CPU operating mode */ + Cy_MSC_ConfigureScan(ptrHwBase, CY_MSC_6_SNS_REGS, &scanConfigTmp[0u]); + + return status; +} +#endif /* CY_CAPSENSE_CDAC_AUTO_DITHER_EN */ + + #endif /* CY_IP_M0S8MSCV3 */ diff --git a/cy_capsense_sensing_v3.h b/cy_capsense_sensing_v3.h index 39cf2e2..1812ee2 100644 --- a/cy_capsense_sensing_v3.h +++ b/cy_capsense_sensing_v3.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_sensing_v3.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the function prototypes specific to the scanning module. * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 @@ -266,11 +266,11 @@ cy_capsense_status_t Cy_CapSense_SlotPinState_V3( #endif /* #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN) */ cy_capsense_status_t Cy_CapSense_ExecuteSaturatedScan( - uint16_t * ptrMaxRaw, + uint32_t * ptrMaxRaw, uint32_t scanSlotId, uint32_t mode, cy_stc_capsense_context_t * context); -void Cy_CapSense_ConfigureSaturationMode( +cy_capsense_status_t Cy_CapSense_ConfigureSaturationMode( cy_stc_capsense_context_t * context); uint32_t Cy_CapSense_GetScanWatchdogTime( uint32_t scanSlotId, diff --git a/cy_capsense_sm_base_full_wave_lp.h b/cy_capsense_sm_base_full_wave_lp.h index 503b81c..90102a1 100644 --- a/cy_capsense_sm_base_full_wave_lp.h +++ b/cy_capsense_sm_base_full_wave_lp.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_sm_base_full_wave_lp.h -* \version 4.0 +* \version 5.0 * * \brief * This file lists a set of macros for each register bit-field for the specified @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 @@ -320,18 +320,19 @@ extern "C" { * Consists 7 registers per each supported mode: * * MODE0: CSD RM * * MODE1: CSX RM -* * MODE2: ISX 2 pin Flyback Ext VDDA/2 +* * MODE2: ISX RM (external VDDA/2) * * MODE3: CSD RM with CapDAC dithering * * MODE4: CSX RM with CapDAC dithering -* * MODE5: ISX RM with CapDAC dithering +* * MODE5: ISX RM with CapDAC dithering (external VDDA/2) * * MODE6: CSD RM + ACTIVE SHIELD * * MODE7: CSD RM with CapDAC dithering + ACTIVE SHIELD * * MODE8: CSD RM + PASIVE SHIELD * * MODE9: CSD RM with CapDAC dithering + PASIVE SHIELD * * MODE10: CSD MPSC-C or CSD MPSC-D * * MODE11: CSD MPSC-C or CSD MPSC-D with CapDAC dithering(Dithering only wrt CsP) -* * MODE 12: CMOD/VDDA BIST Balancing Phase. Balancing to VDDA/2 -* * MODE 13: VDDA BIST Balancing Phase. Balancing to VBG +* * MODE12: CMOD/VDDA BIST Balancing Phase. Balancing to VDDA/2 +* * MODE13: ISX (internal VDDA/2) +* * MODE14: ISX RM with CapDAC dithering (internal VDDA/2) *******************************************************************************/ /********************************* CSD RM *************************************/ @@ -498,7 +499,7 @@ extern "C" { #define CY_CAPSENSE_SM_REG_MODE1_SW_SEL_CMOD2_FLD_REF_MODE (0x0uL) #define CY_CAPSENSE_SM_REG_MODE1_SW_SEL_CMOD2_FLD_DDRV_EN (0x0uL) -/********************************* ISX RM *************************************/ +/********************************* ISX RM (External VDDA/2) *******************/ /* ISX RM - MODE2_SENSE_DUTY_CTL: Sense Clock Duty Cycle Control */ #define CY_CAPSENSE_SM_REG_MODE2_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN (0x0uL) @@ -561,7 +562,7 @@ extern "C" { #define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_SH_FLD_BUF_EN (0x1uL) /* ISX RM - MODE2_SW_SEL_CMOD1: CMOD Switch Control 1 */ -#define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD1_FLD_SW_AMUXA (0x3uL) +#define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD1_FLD_SW_AMUXA (0x1uL) #define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD1_FLD_SW_C1CA (0x1uL) #define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD1_FLD_SW_C1CC (0x1uL) #define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD1_FLD_SW_AMUXB (0x0uL) @@ -571,8 +572,8 @@ extern "C" { #define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD1_FLD_DDRV_EN (0x0uL) /* ISX RM - MODE2_SW_SEL_CMOD2: CMOD Switch Control 2 */ -#define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD2_FLD_SW_AMUXA (0x4uL) -#define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD2_FLD_SW_AMUXB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD2_FLD_SW_AMUXA (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD2_FLD_SW_AMUXB (0x1uL) #define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD2_FLD_SW_C2CB (0x1uL) #define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD2_FLD_SW_C2CD (0x1uL) #define CY_CAPSENSE_SM_REG_MODE2_SW_SEL_CMOD2_FLD_SW_PU (0x0uL) @@ -807,7 +808,7 @@ extern "C" { #define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_SH_FLD_BUF_EN (0x1uL) /* ISX RM w/dither - MODE5_SW_SEL_CMOD1: CMOD Switch Control 1 */ -#define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD1_FLD_SW_AMUXA (0x3uL) +#define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD1_FLD_SW_AMUXA (0x1uL) #define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD1_FLD_SW_C1CA (0x1uL) #define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD1_FLD_SW_C1CC (0x1uL) #define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD1_FLD_SW_AMUXB (0x0uL) @@ -817,8 +818,8 @@ extern "C" { #define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD1_FLD_DDRV_EN (0x0uL) /* ISX RM w/dither - MODE5_SW_SEL_CMOD2: CMOD Switch Control 2 */ -#define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD2_FLD_SW_AMUXA (0x4uL) -#define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD2_FLD_SW_AMUXB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD2_FLD_SW_AMUXA (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD2_FLD_SW_AMUXB (0x1uL) #define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD2_FLD_SW_C2CB (0x1uL) #define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD2_FLD_SW_C2CD (0x1uL) #define CY_CAPSENSE_SM_REG_MODE5_SW_SEL_CMOD2_FLD_SW_PU (0x0uL) @@ -1372,6 +1373,171 @@ extern "C" { /* SW_SEL_BGR: Bandgap Reference Switch Control */ #define CY_CAPSENSE_BIST_CMOD_MEAS_SW_SEL_BGR_FLD_SW_BGRCM (0x1uL) + +/********************************* ISX RM (Internal VDDA/2) *******************/ + +/* ISX RM - MODE13_SENSE_DUTY_CTL: Sense Clock Duty Cycle Control */ +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL (0x0uL) + +/* ISX RM - MODE13_SW_SEL_CDAC_FL: Flatspot/Dither CAPDAC Switch Control */ +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLTCA (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLCB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLTV (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLTG (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLBV (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_SW_FLBG (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CDAC_FL_FLD_ACTIVATION_MODE (0x0uL) + +/* ISX RM - MODE13_SW_SEL_TOP: Top Level Switch Control */ +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_CACB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_CACC (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_CBCD (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_AYA_CTL (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_AYA_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_AYB_CTL (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_AYB_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_BYB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_BGRF (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_RMF (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_TOP_FLD_MBF (0x0uL) + +/* ISX RM - MODE13_SW_SEL_COMP: MSC Comparator Switch Control */ +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPCS1 (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPCS3 (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPMA (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPCA (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPCB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMCB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CPF (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMCS2 (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMCS4 (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMV (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMG (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_CMF (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_COMP_FLD_HALF_WAVE_EN (0x0uL) + +/* ISX RM - MODE13_SW_SEL_SH: Shielding Switch Control */ +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_SOMB (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_CBSO (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_SPCS1 (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_SPCS3 (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_FSP (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_BUF_SEL (0x7uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_SH_FLD_BUF_EN (0x1uL) + +/* ISX RM - MODE13_SW_SEL_CMOD1: CMOD Switch Control 1 */ +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_AMUXA (0x3uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_C1CA (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_C1CC (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_AMUXB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_PU (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_SW_PD (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_REF_MODE (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD1_FLD_DDRV_EN (0x0uL) + +/* ISX RM - MODE13_SW_SEL_CMOD2: CMOD Switch Control 2 */ +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_AMUXA (0x4uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_AMUXB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_C2CB (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_C2CD (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_PU (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_SW_PD (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_REF_MODE (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE13_SW_SEL_CMOD2_FLD_DDRV_EN (0x0uL) + +/************************ ISX RM with CapDAC dithering (internal VDDA/2) ******/ + +/* ISX RM - MODE14_SENSE_DUTY_CTL: Sense Clock Duty Cycle Control */ +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL (0x0uL) + +/* ISX RM - MODE14_SW_SEL_CDAC_FL: Flatspot/Dither CAPDAC Switch Control */ +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLTCA (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLCB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLTV (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLTG (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLBV (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_SW_FLBG (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CDAC_FL_FLD_ACTIVATION_MODE (0x0uL) + +/* ISX RM - MODE14_SW_SEL_TOP: Top Level Switch Control */ +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_CACB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_CACC (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_CBCD (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_AYA_CTL (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_AYA_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_AYB_CTL (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_AYB_EN (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_BYB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_BGRF (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_RMF (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_TOP_FLD_MBF (0x0uL) + +/* ISX RM - MODE14_SW_SEL_COMP: MSC Comparator Switch Control */ +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPCS1 (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPCS3 (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPMA (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPCA (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPCB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMCB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CPF (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMCS2 (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMCS4 (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMV (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMG (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_CMF (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_COMP_FLD_HALF_WAVE_EN (0x0uL) + +/* ISX RM - MODE14_SW_SEL_SH: Shielding Switch Control */ +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_SOMB (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_CBSO (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_SPCS1 (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_SPCS3 (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_FSP (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_BUF_SEL (0x7uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_SH_FLD_BUF_EN (0x1uL) + +/* ISX RM - MODE14_SW_SEL_CMOD1: CMOD Switch Control 1 */ +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_AMUXA (0x3uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_C1CA (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_C1CC (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_AMUXB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_PU (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_SW_PD (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_REF_MODE (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD1_FLD_DDRV_EN (0x0uL) + +/* ISX RM - MODE14_SW_SEL_CMOD2: CMOD Switch Control 2 */ +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_AMUXA (0x4uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_AMUXB (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_C2CB (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_C2CD (0x1uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_PU (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_SW_PD (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_REF_MODE (0x0uL) +#define CY_CAPSENSE_SM_REG_MODE14_SW_SEL_CMOD2_FLD_DDRV_EN (0x0uL) + /******************************************************* * Pin state specific registers. One register per state: * * CSW_FUNC0: GND @@ -1380,14 +1546,18 @@ extern "C" { * * CSW_FUNC3: CSX TX * * CSW_FUNC4: CSX NTX * * CSW_FUNC5: CSD SNS -* * CSW_FUNC6: ISX LX -* * CSW_FUNC7: ISX RX +* * CSW_FUNC6: ISX LX (two-pin cfg) +* * CSW_FUNC7: ISX RX (two-pin cfg, external VDDA/2) * * CSW_FUNC8: SHIELD Active * * CSW_FUNC9: SHIELD Passive * * CSW_FUNC10: CSX VDDA/2 * * CSW_FUNC11: MPSC CSP * * CSW_FUNC12: MPSC CSN * * CSW_FUNC13: MPSC CSZ +* * CSW_FUNC14: ISX RX (two-pin cfg, internal VDDA/2) +* * CSW_FUNC15: ISX RX (one-pin cfg, external VDDA/2) +* * CSW_FUNC16: ISX RX (one-pin cfg, internal VDDA/2) +* ************************************************************************/ /*********** SW_SEL_CSW_FUNC0: GND *************/ @@ -1438,7 +1608,7 @@ extern "C" { #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC5_FLD_REF_MODE (0x0uL) #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC5_FLD_DDRV_EN (0x0uL) -/*********** SW_SEL_CSW_FUNC6: ISX LX *************/ +/*********** SW_SEL_CSW_FUNC6: ISX LX (two-pin cfg) *************/ #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC6_FLD_SW_AMUXA (0x0uL) #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC6_FLD_SW_AMUXB (0x0uL) #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC6_FLD_SW_PU (0x4uL) @@ -1446,9 +1616,9 @@ extern "C" { #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC6_FLD_REF_MODE (0x0uL) #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC6_FLD_DDRV_EN (0x0uL) -/*********** SW_SEL_CSW_FUNC7: ISX RX *************/ -#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC7_FLD_SW_AMUXA (0xAuL) -#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC7_FLD_SW_AMUXB (0x0uL) +/*********** SW_SEL_CSW_FUNC7: ISX RX (two-pin cfg, external VDDA/2) */ +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC7_FLD_SW_AMUXA (0x6uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC7_FLD_SW_AMUXB (0x3uL) #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC7_FLD_SW_PU (0x0uL) #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC7_FLD_SW_PD (0x0uL) #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC7_FLD_REF_MODE (0x0uL) @@ -1502,6 +1672,31 @@ extern "C" { #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC13_FLD_REF_MODE (0x0uL) #define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC13_FLD_DDRV_EN (0x0uL) +/*********** SW_SEL_CSW_FUNC14: ISX RX (two-pin cfg, internal VDDA/2) */ +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_SW_AMUXA (0xAuL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_SW_AMUXB (0x0uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_SW_PU (0x0uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_SW_PD (0x0uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_REF_MODE (0x0uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC14_FLD_DDRV_EN (0x0uL) + +/*********** SW_SEL_CSW_FUNC15: ISX RX (one-pin cfg, external VDDA/2) */ +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_SW_AMUXA (0x6uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_SW_AMUXB (0x3uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_SW_PU (0x4uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_SW_PD (0x2uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_REF_MODE (0x0uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC15_FLD_DDRV_EN (0x0uL) + +/*********** SW_SEL_CSW_FUNC16: ISX RX (one-pin cfg, internal VDDA/2) */ +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_SW_AMUXA (0xAuL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_SW_AMUXB (0x0uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_SW_PU (0x4uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_SW_PD (0x2uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_REF_MODE (0x0uL) +#define CY_CAPSENSE_SM_REG_SW_SEL_CSW_FUNC16_FLD_DDRV_EN (0x0uL) + + #if defined(__cplusplus) } #endif diff --git a/cy_capsense_sm_base_full_wave_v3.h b/cy_capsense_sm_base_full_wave_v3.h index 83f55ca..f387bd6 100644 --- a/cy_capsense_sm_base_full_wave_v3.h +++ b/cy_capsense_sm_base_full_wave_v3.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_sm_base_full_wave_v3.h -* \version 4.0 +* \version 5.0 * * \brief * This file lists a set of macros for each register bit-field for the specified @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2020-2023, Cypress Semiconductor Corporation (an Infineon company) +* Copyright 2020-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 diff --git a/cy_capsense_structure.c b/cy_capsense_structure.c index e5d9069..6a64d1b 100644 --- a/cy_capsense_structure.c +++ b/cy_capsense_structure.c @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_structure.c -* \version 4.0 +* \version 5.0 * * \brief * This file defines the data structure global variables and provides the @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 @@ -194,7 +194,7 @@ uint32_t Cy_CapSense_IsWidgetActive( * Function Name: Cy_CapSense_IsSensorActive ****************************************************************************//** * -* Reports whether the specified sensor in the widget detected touch. +* Reports whether the specified sensor in the widget is sensor detects a touch. * * This function reports whether the specified sensor in the widget has detected a * touch by extracting information from the widget status register. @@ -881,8 +881,8 @@ cy_capsense_status_t Cy_CapSense_SetParam( * 5. Bit [4] - CY_CAPSENSE_WD_MAXCOUNT_ROW_CALC_MASK. * * \param mask -* Specifies the value to be configured. All bit values not set by -* the mode parameter are ignored. +* Specifies the value of widget status field to be configured. All bit values +* not set by the mask passed as the mode parameter are ignored. * * \param context * The pointer to the CAPSENSE™ context diff --git a/cy_capsense_structure.h b/cy_capsense_structure.h index f01e49e..1b961c6 100644 --- a/cy_capsense_structure.h +++ b/cy_capsense_structure.h @@ -1,6 +1,6 @@ /***************************************************************************//** * \file cy_capsense_structure.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides the top-level declarations of the CAPSENSE™ data @@ -8,7 +8,7 @@ * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 @@ -176,6 +176,22 @@ typedef enum CY_CAPSENSE_BIST_FAIL_E = 0x0Fu, /**< The failed test status */ } cy_en_capsense_bist_status_t; +#if ((CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)) +/** Defines IDs of the external capacitors */ +typedef enum +{ + #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP) + CY_CAPSENSE_BIST_CMOD01_ID_E = 0x00u, /**< ID for the MSC0 Cmod1 external capacitor \note This value is available for the fifth-generation low power CAPSENSE™.*/ + CY_CAPSENSE_BIST_CMOD02_ID_E = 0x01u, /**< ID for the MSC0 Cmod2 external capacitor \note This value is available for the fifth-generation low power CAPSENSE™.*/ + #endif + #if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) + CY_CAPSENSE_BIST_CMOD_ID_E = 0x00u, /**< ID for Cmod external capacitor \note This value is available only for the fourth-generation CAPSENSE™.*/ + CY_CAPSENSE_BIST_CINTA_ID_E = 0x01u, /**< ID for CintA external capacitor \note This value is available only for the fourth-generation CAPSENSE™.*/ + CY_CAPSENSE_BIST_CINTB_ID_E = 0x02u, /**< ID for CintB external capacitor \note This value is available only for the fourth-generation CAPSENSE™.*/ + CY_CAPSENSE_BIST_CSH_ID_E = 0x03u, /**< ID for Csh external capacitor \note This value is available only for the fourth-generation CAPSENSE™.*/ + #endif +} cy_en_capsense_bist_external_cap_id_t; +#endif /** Defines the raw count accumulation mode for MSC HW block */ typedef enum @@ -371,6 +387,7 @@ typedef struct * Touchpad and CSD Matrix buttons widgets * \note This field is available for the fifth-generation CAPSENSE™ and fifth-generation low power CAPSENSE™. */ + #if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP) && \ ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_FINE_EN) || \ (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CDAC_FINE_EN) || \ @@ -393,7 +410,7 @@ typedef struct */ #endif /* CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN */ - uint8_t cdacDitherValue; /**< CDAC dither value in percentage + uint8_t cdacDitherValue; /**< CDAC dither scale value in bits * \note This field is available for the fifth-generation CAPSENSE™ and fifth-generation low power CAPSENSE™. */ uint8_t coarseInitBypassEn; /**< Skip Cmod coarse initialization sensors scan within widget @@ -585,7 +602,7 @@ typedef struct uint8_t snsClkSourceAutoSelMode; /**< Defines set of rules that are used by clock source auto-selection algorithm * \note This field is available for the fifth-generation CAPSENSE™ and fifth-generation low power CAPSENSE™. */ - uint8_t mfsConfig; /**< Multi-frequency Scan (MFS) widget configuration. + uint8_t mfsConfig; /**< Multi-frequency Scan (MFS) widget configuration ** Contains masks: * * bit[0:3] - Number of MFS Channels (CY_CAPSENSE_MFS_FREQ_CHANNELS_NUM_MASK). * * bit[4] - MFS Configuration (CY_CAPSENSE_MFS_EN_MASK): @@ -597,14 +614,49 @@ typedef struct * * 2 - Frequency channel 2 widget (CY_CAPSENSE_MFS_WIDGET_FREQ_CH_2_MASK) * \note This field is available for the fifth-generation CAPSENSE™ and fifth-generation low power CAPSENSE™. */ + uint8_t cdacDitherScaleMode; /**< CDAC dither scale mode + * * 0 (CY_CAPSENSE_CDAC_DITHERING_MODE_DISABLE) - CDAC dithering is disabled + * * 1 (CY_CAPSENSE_CDAC_DITHERING_MODE_MANUAL) - CDAC dither value set manually + * * 2 (CY_CAPSENSE_CDAC_DITHERING_MODE_AUTO) - CDAC dither value set automatically + * \note This field is available for the fifth-generation CAPSENSE™ and fifth-generation low power CAPSENSE™. + */ #endif #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP) + uint8_t cicRateMode; /**< CIC2 filter decimation rate mode + * * 0 (CY_CAPSENSE_CIC_RATE_MODE_MANUAL) - The cicRate value set by users + * * 1 (CY_CAPSENSE_CIC_RATE_MODE_AUTO) - The cicRate value configured by middleware + * * 2 (CY_CAPSENSE_CIC_RATE_MODE_SMARTSENSE) - The cicRate value configured by SMARTSENSE™ algorithm + * \note This field is available for the fifth-generation CAPSENSE™ and fifth-generation low power CAPSENSE™. + */ uint8_t iirCoeffHw; /**< Raw count HW IIR filter coefficient. Smaller value leads to lower filtering. - * \note This field is available only for the fifth-generation low power CAPSENSE™. - */ + * \note This field is available only for the fifth-generation low power CAPSENSE™. + */ + uint16_t cdacConfig; /**< Bit-mask for widget CDAC configuration: + * * bit[0..1] - Reference CDAC mode (CY_CAPSENSE_CDAC_REF_MODE_MASK) + * * 0 (CY_CAPSENSE_CDAC_MODE_DISABLED) - The reference CDAC is disabled + * * 1 (CY_CAPSENSE_CDAC_MODE_MANUAL) - The value of reference CDAC set manually + * * 2 (CY_CAPSENSE_CDAC_MODE_AUTO) - The value of reference CDAC set automatically + * * bit[2..3] - Fine CDAC mode (CY_CAPSENSE_CDAC_FINE_MODE_MASK) + * * 0 (CY_CAPSENSE_CDAC_MODE_DISABLED) - The fine CDAC is disabled + * * 1 (CY_CAPSENSE_CDAC_MODE_MANUAL) - The value of fine CDAC set manually + * * 2 (CY_CAPSENSE_CDAC_MODE_AUTO) - The value of fine CDAC set automatically + * * bit[4..5] - Compensation CDAC mode (CY_CAPSENSE_CDAC_COMP_MODE_MASK) + * * 0 (CY_CAPSENSE_CDAC_MODE_DISABLED) - The compensation CDAC is disabled + * * 1 (CY_CAPSENSE_CDAC_MODE_MANUAL) - The value of compensation CDAC set manually + * * 2 (CY_CAPSENSE_CDAC_MODE_AUTO) - The value of compensation CDAC set automatically + * * bit[6..7] - Compensation CDAC divider mode (CY_CAPSENSE_CDAC_COMP_DIV_MODE_MASK) + * * 0 (CY_CAPSENSE_CDAC_MODE_MANUAL) - The value of compensation CDAC divider set manually + * * 2 (CY_CAPSENSE_CDAC_MODE_AUTO) - The value of compensation CDAC divider set automatically + * * bit[8..9] - Sensitivity boost (CY_CAPSENSE_CDAC_BOOST_VAL_MASK) + * * 1 (CY_CAPSENSE_CDAC_BOOST_DISABLED) - Boost disabled + * * 2 (CY_CAPSENSE_CDAC_BOOST_2X) - 2X Boost + * * 3 (CY_CAPSENSE_CDAC_BOOST_3X) - 3X Boost + * * 4 (CY_CAPSENSE_CDAC_BOOST_4X) - 4X Boost + * \note This field is available for the fifth-generation low power CAPSENSE™. + */ #endif - + } cy_stc_capsense_widget_config_t; #if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) @@ -1963,6 +2015,14 @@ cy_capsense_status_t Cy_CapSense_SetWidgetStatus( uint32_t mode, uint32_t value, cy_stc_capsense_context_t * context); +uint32_t Cy_CapSense_IsWidgetEnabled( + uint32_t widgetId, + const cy_stc_capsense_context_t * context); +#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)) + uint32_t Cy_CapSense_IsSlotEnabled( + uint32_t slotId, + const cy_stc_capsense_context_t * context); +#endif /** \} */ @@ -1976,19 +2036,11 @@ cy_capsense_status_t Cy_CapSense_CheckConfigIntegrity( uint16_t Cy_CapSense_GetCrcWidget( uint32_t widgetId, cy_stc_capsense_context_t * context); -uint32_t Cy_CapSense_IsWidgetEnabled( - uint32_t widgetId, - const cy_stc_capsense_context_t * context); #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP) void Cy_CapSense_SetSnsFrameValidity( uint32_t widgetId, cy_stc_capsense_context_t * context); #endif -#if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) || (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN_LP)) - uint32_t Cy_CapSense_IsSlotEnabled( - uint32_t slotId, - const cy_stc_capsense_context_t * context); -#endif /** This enumeration is obsolete and should not be used further. * Instead some of the following macros with the _GROUP suffix should be used: diff --git a/cy_capsense_tuner.c b/cy_capsense_tuner.c index 173b480..cc03014 100644 --- a/cy_capsense_tuner.c +++ b/cy_capsense_tuner.c @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_tuner.c -* \version 4.0 +* \version 5.0 * * \brief * This file provides the source code for the Tuner module functions. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/cy_capsense_tuner.h b/cy_capsense_tuner.h index c8e42e0..a6705c9 100644 --- a/cy_capsense_tuner.h +++ b/cy_capsense_tuner.h @@ -1,13 +1,13 @@ /***************************************************************************//** * \file cy_capsense_tuner.h -* \version 4.0 +* \version 5.0 * * \brief * This file provides CAPSENSE™ MW Tuner module function prototypes. * ******************************************************************************** * \copyright -* Copyright 2018-2023, Cypress Semiconductor Corporation (an Infineon company) +* 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 diff --git a/docs/capsense_api_reference_manual/html/annotated.html b/docs/capsense_api_reference_manual/html/annotated.html index d9ce645..71d1134 100644 --- a/docs/capsense_api_reference_manual/html/annotated.html +++ b/docs/capsense_api_reference_manual/html/annotated.html @@ -6,7 +6,7 @@ -CAPSENSE™ Middleware Library 4.0: Data Structures +CAPSENSE™ Middleware Library 5.0: Data Structures @@ -30,7 +30,7 @@ Logo -
CAPSENSE™ Middleware Library 4.0
+
CAPSENSE™ Middleware Library 5.0
@@ -141,7 +141,7 @@