- ModusToolbox CSD Personality for PSoC4 devices in Device Configurator
+*
1.0
*
*
-*
- ModusToolbox CSD Personality in Device Configurator
+*
- ModusToolbox CSD Personality for PSoC6 devices in Device Configurator
*
2.0
*
*
*
- ModusToolbox CapSense Configurator tool
-*
2.0
+*
3.0
*
*
*
- ModusToolbox CapSense Tuner tool
-*
2.0
+*
3.0
+*
+*
+*
PSoC4 Peripheral Driver Library (PDL)
+*
1.0.0
*
*
*
PSoC6 Peripheral Driver Library (PDL)
-*
1.2.0
+*
1.5.0
*
*
*
GCC Compiler
@@ -210,8 +217,8 @@
*
6.11
*
*
-*
MBED OS
-*
5.13.1
+*
MBED OS (only for PSoC6)
+*
5.15.1
*
*
*
FreeRTOS
@@ -244,7 +251,7 @@
* to re-generate the middleware configuration.
* * The toolchains are set up properly for your environment per the settings
* outlined in the Supported Software and Tools.
-* * The project is re-built once the the toolchains are configured and the
+* * The project is re-built once the toolchains are configured and the
* configuration is completed.
*
* You might need to re-generate the configuration structures for either the
@@ -273,39 +280,40 @@
* the Release mode with optimization set for Size.
*
*
+* Scanning a sensor with low capacitance (about 8pF and less) with low
+* frequency (around 300kHz and less) might lead to raw count variation
+* from scan to scan.
+*
+*
+* There are several possible workarounds:
+* 1. Increase the Scan resolution.
+* 2. Increase the Sense clock frequency. For the best results, perform
+* scanning with as high as possible Sense clock frequency.
+* 3. If shield is required for a design, enable the shield tank (Csh)
+* capacitor.
+* 4. Increase the sensor capacitance by changing its layout or introduce
+* extra capacitor between the sensor pin and ground.
+* 5. Increase number of Fine initialization cycles. Open the cycfg_capsense.c
+* file and modify the .csdFineInitTime field of the cy_capsense_commonConfig
+* structure.
+* 6. Increase the CSD init switch resistance. Open the cycfg_capsernse.c file
+* and update the .csdInitSwRes field of the cy_capsense_commonConfig structure
+* with the CY_CAPSENSE_INIT_SW_RES_HIGH value.
+*
+*
+*
+*
3191
+*
+* Channel 0 is scanned with the incorrect settings when all of the following
+* conditions are met:
+* 1. Multi-frequency scan is enabled.
+* 2. The Cy_CapSense_CSDSetupWidgetExt() function called only once.
+* 3. The Cy_CapSense_CSDScanExt() function called multiple times.
+*
+*
+* Call the Cy_CapSense_CSDSetupWidgetExt() function before each call of
+* the Cy_CapSense_CSDScanExt() function.
+*
Support Class B (IEC-60730), safety integrity-level compliant design
+*
+*
+*
Improved the Csh and Cmod coarse initialization functionality.
+*
Feature enhancement
+*
+*
+*
Improved the shield performance when Csh is enabled
+*
Feature enhancement
+*
+*
+*
Fixed Cy_CapSense_ScanExt() operation
+*
Defect fixing
+*
+*
+*
Fixed the bug in the Cy_CapSense_SetPinState() function
+*
Defect fixing
+*
+*
+*
Optimized software watch-dog values used in monitoring CapSense
+* scanning duration
+*
User experience improvement
+*
+*
+*
Improved IDAC auto-calibration
+*
Operation accuracy increasing
+*
+*
+*
Added the following functions:
+* * Cy_CapSense_GetParam()
+* * Cy_CapSense_SetParam()
+* * Cy_CapSense_GetCRC()
+*
+*
Feature enhancement
+*
+*
+*
Changed the type of context argument to const in the following
+* functions:
+* * Cy_CapSense_CSDConnectSns()
+* * Cy_CapSense_CSXConnectRx()
+* * Cy_CapSense_CSXConnectTx()
+* * Cy_CapSense_CSXDisconnectRx()
+* * Cy_CapSense_CSXDisconnectTx()
+* * Cy_CapSense_SetPinState()
+*
+*
Defect fixing
+*
+*
*
2.0
*
Added memory usage section to the CapSense API Ref Guide
*
User experience improvement
@@ -475,8 +571,7 @@
* of a CapSense system is available in the Getting Started with CapSense
* document and the product-specific CapSense design guide. Cypress highly
* recommends starting with these documents. They can be found on the
-* Cypress web site at www.cypress.com. For details about application notes,
-* code examples, and kits, see the References section in this datasheet.
+* Cypress web site at www.cypress.com.
*
* For more information, refer to the following documents:
*
@@ -511,7 +606,7 @@
* *
* CSDIDAC Middleware API Reference Guide
*
-* *
+* *
* PDL API Reference
*
* * AN210781 Getting Started with
@@ -570,6 +665,9 @@
* \defgroup group_capsense_macros_miscellaneous Miscellaneous Macros
* \ingroup group_capsense_macros
* \brief Miscellaneous macros
+* \defgroup group_capsense_macros_bist Built-in Self-test Macros
+* \ingroup group_capsense_macros
+* \brief Built-in Self-test macros
*
* \defgroup group_capsense_callbacks Callbacks
*
@@ -764,6 +862,7 @@
#include "cy_capsense_sensing.h"
#include "cy_capsense_structure.h"
#include "cy_capsense_tuner.h"
+#include "cy_capsense_selftest.h"
#endif /* CY_CAPSENSE_H */
diff --git a/cy_capsense_centroid.c b/cy_capsense_centroid.c
index 9b357a2..03cca93 100644
--- a/cy_capsense_centroid.c
+++ b/cy_capsense_centroid.c
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_centroid.c
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the source code for the centroid calculation methods
@@ -8,7 +8,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -25,7 +25,7 @@
#include "cy_capsense_structure.h"
#include "cy_capsense_filter.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
/*******************************************************************************
@@ -159,7 +159,7 @@ void Cy_CapSense_DpCentroidDiplex(
}
}
- if (maxIndex != CY_CAPSENSE_NO_LOCAL_MAX)
+ if ((maxIndex != CY_CAPSENSE_NO_LOCAL_MAX) && (maxSum > 0u))
{
multiplier = (uint32_t)ptrWdConfig->xResolution << 8u;
/* Calculate position */
@@ -220,12 +220,14 @@ void Cy_CapSense_DpCentroidLinear(
uint32_t sum = 0u;
uint32_t maxSum = 0u;
uint32_t maxDiff = 0u;
- uint32_t maxIndex = 0u;
+ uint32_t maxIndex = CY_CAPSENSE_NO_LOCAL_MAX;
cy_stc_capsense_sensor_context_t * ptrSnsCxt;
int32_t numerator = 0;
int32_t denominator = 0;
uint32_t multiplier;
uint32_t offset;
+
+ CY_ASSERT(snsCount > 2u);
if (1u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_NUMBER_MASK))
{
@@ -262,25 +264,32 @@ void Cy_CapSense_DpCentroidLinear(
ptrSnsCxt++;
}
- /* Calculate position */
- multiplier = (uint32_t)ptrWdConfig->xResolution << 8u;
- if (0u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CALC_METHOD_MASK))
- {
- multiplier /= (snsCount - 1u);
- offset = 0u;
+ if ((maxIndex != CY_CAPSENSE_NO_LOCAL_MAX) && (maxSum > 0u))
+ {
+ /* Calculate position */
+ multiplier = (uint32_t)ptrWdConfig->xResolution << 8u;
+ if (0u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CALC_METHOD_MASK))
+ {
+ multiplier /= (snsCount - 1u);
+ offset = 0u;
+ }
+ else
+ {
+ multiplier /= snsCount;
+ offset = multiplier >> 1u;
+ }
+
+ denominator = (int32_t)maxSum;
+ denominator = ((numerator * (int32_t)multiplier) / denominator) + (((int32_t)maxIndex * (int32_t)multiplier) + (int32_t)offset);
+
+ /* Round result and shift 8 bits left */
+ newTouch->numPosition = CY_CAPSENSE_POSITION_ONE;
+ newTouch->ptrPosition[0u].x = CY_LO16(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
}
else
{
- multiplier /= snsCount;
- offset = multiplier >> 1u;
+ newTouch->numPosition = CY_CAPSENSE_POSITION_NONE;
}
-
- denominator = (int32_t)maxSum;
- denominator = ((numerator * (int32_t)multiplier) / denominator) + (((int32_t)maxIndex * (int32_t)multiplier) + (int32_t)offset);
-
- /* Round result and shift 8 bits left */
- newTouch->numPosition = 1u;
- newTouch->ptrPosition[0u].x = CY_LO16(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
}
else
{
@@ -321,7 +330,7 @@ void Cy_CapSense_DpCentroidRadial(
uint32_t sum = 0u;
uint32_t maxSum = 0u;
uint32_t maxDiff = 0u;
- uint32_t maxIndex = 0u;
+ uint32_t maxIndex = CY_CAPSENSE_NO_LOCAL_MAX;
cy_stc_capsense_sensor_context_t * ptrSnsCxt;
int32_t numerator = 0;
int32_t denominator = 0;
@@ -362,18 +371,26 @@ void Cy_CapSense_DpCentroidRadial(
ptrSnsCxt++;
}
- /* Calculate position */
- multiplier = ((uint32_t)ptrWdConfig->xResolution << 8u) / snsCount;
-
- denominator = (int32_t)maxSum;
- denominator = ((numerator * (int32_t)multiplier) / denominator) + ((int32_t)maxIndex * (int32_t)multiplier);
- if (denominator < 0)
+ if ((maxIndex != CY_CAPSENSE_NO_LOCAL_MAX) && (maxSum > 0u))
+ {
+ /* Calculate position */
+ multiplier = ((uint32_t)ptrWdConfig->xResolution << 8u) / snsCount;
+
+ denominator = (int32_t)maxSum;
+ denominator = ((numerator * (int32_t)multiplier) / denominator) + ((int32_t)maxIndex * (int32_t)multiplier);
+
+ if (denominator < 0)
+ {
+ denominator += ((int32_t)snsCount * (int32_t)multiplier);
+ }
+ /* Round result and shift 8 bits left */
+ newTouch->numPosition = CY_CAPSENSE_POSITION_ONE;
+ newTouch->ptrPosition[0u].x = CY_LO16(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
+ }
+ else
{
- denominator += ((int32_t)snsCount * (int32_t)multiplier);
+ newTouch->numPosition = CY_CAPSENSE_POSITION_NONE;
}
- /* Round result and shift 8 bits left */
- newTouch->numPosition = 1u;
- newTouch->ptrPosition[0u].x = CY_LO16(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
}
else
{
@@ -416,12 +433,15 @@ void Cy_CapSense_DpCentroidTouchpad(
uint32_t sum = 0u;
uint32_t maxSum = 0u;
uint32_t maxDiff = 0u;
- uint32_t maxIndex = 0u;
+ uint32_t maxIndex = CY_CAPSENSE_NO_LOCAL_MAX;
cy_stc_capsense_sensor_context_t * ptrSnsCxt;
int32_t numerator = 0;
int32_t denominator = 0;
uint32_t multiplier;
uint32_t offset;
+
+ CY_ASSERT(colCount > 2u);
+ CY_ASSERT(rowCount > 2u);
if (1u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_NUMBER_MASK))
{
@@ -465,86 +485,102 @@ void Cy_CapSense_DpCentroidTouchpad(
ptrSnsCxt++;
}
- /* Calculate position */
- multiplier = (uint32_t)ptrWdConfig->xResolution << 8u;
- if (0u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CALC_METHOD_MASK))
- {
- multiplier /= (colCount - 1u);
- offset = 0u;
+ if ((maxIndex != CY_CAPSENSE_NO_LOCAL_MAX) && (maxSum > 0u))
+ {
+ /* Calculate position */
+ multiplier = (uint32_t)ptrWdConfig->xResolution << 8u;
+ if (0u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CALC_METHOD_MASK))
+ {
+ multiplier /= (colCount - 1u);
+ offset = 0u;
+ }
+ else
+ {
+ multiplier /= colCount;
+ offset = multiplier >> 1u;
+ }
+
+ denominator = (int32_t)maxSum;
+ denominator = ((numerator * (int32_t)multiplier) / denominator) + (((int32_t)maxIndex * (int32_t)multiplier) + (int32_t)offset);
+
+ /* Round result and shift 8 bits left */
+ newTouch->numPosition = CY_CAPSENSE_POSITION_ONE;
+ newTouch->ptrPosition[0u].x = CY_LO16(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
}
else
{
- multiplier /= colCount;
- offset = multiplier >> 1u;
+ newTouch->numPosition = CY_CAPSENSE_POSITION_NONE;
}
- denominator = (int32_t)maxSum;
- denominator = ((numerator * (int32_t)multiplier) / denominator) + (((int32_t)maxIndex * (int32_t)multiplier) + (int32_t)offset);
-
- /* Round result and shift 8 bits left */
- newTouch->ptrPosition[0u].x = CY_LO16(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
-
- /***********************************************************************
- * Y Axis (Rows)
- ***********************************************************************/
- sum = 0u;
- maxSum = 0u;
- maxDiff = 0u;
- maxIndex = 0u;
- /* Find maximum signal */
- ptrSnsCxt = &ptrWdConfig->ptrSnsContext[colCount];
- for (snsIndex = colCount; snsIndex < snsCount; snsIndex++)
- {
- if (ptrSnsCxt->diff > maxDiff)
+ if(newTouch->numPosition != CY_CAPSENSE_POSITION_NONE)
+ {
+ /***********************************************************************
+ * Y Axis (Rows)
+ ***********************************************************************/
+ sum = 0u;
+ maxSum = 0u;
+ maxDiff = 0u;
+ maxIndex = CY_CAPSENSE_NO_LOCAL_MAX;
+ /* Find maximum signal */
+ ptrSnsCxt = &ptrWdConfig->ptrSnsContext[colCount];
+ for (snsIndex = colCount; snsIndex < snsCount; snsIndex++)
{
- maxDiff = ptrSnsCxt->diff;
+ if (ptrSnsCxt->diff > maxDiff)
+ {
+ maxDiff = ptrSnsCxt->diff;
+ }
+ ptrSnsCxt++;
}
- ptrSnsCxt++;
- }
-
- /* Find index of sensor with maximum signal */
- ptrSnsCxt = &ptrWdConfig->ptrSnsContext[colCount];
- for (snsIndex = 0u; snsIndex < rowCount; snsIndex++)
- {
- /* Potential maximum */
- if (maxDiff == ptrSnsCxt->diff)
+
+ /* Find index of sensor with maximum signal */
+ ptrSnsCxt = &ptrWdConfig->ptrSnsContext[colCount];
+ for (snsIndex = 0u; snsIndex < rowCount; snsIndex++)
{
- /* Get sum of differences around maximum */
- diffM = (snsIndex > 0u) ? (ptrSnsCxt - 1u)->diff : 0u;
- diffP = (snsIndex < (rowCount - 1u)) ? (ptrSnsCxt + 1u)->diff : 0u;
- sum = ptrSnsCxt->diff + diffM + diffP;
- /* Check if this sum is maximum sum */
- if (maxSum < sum)
+ /* Potential maximum */
+ if (maxDiff == ptrSnsCxt->diff)
{
- /* New maximum */
- maxIndex = snsIndex;
- maxSum = sum;
- numerator = (int32_t)diffP - (int32_t)diffM;
+ /* Get sum of differences around maximum */
+ diffM = (snsIndex > 0u) ? (ptrSnsCxt - 1u)->diff : 0u;
+ diffP = (snsIndex < (rowCount - 1u)) ? (ptrSnsCxt + 1u)->diff : 0u;
+ sum = ptrSnsCxt->diff + diffM + diffP;
+ /* Check if this sum is maximum sum */
+ if (maxSum < sum)
+ {
+ /* New maximum */
+ maxIndex = snsIndex;
+ maxSum = sum;
+ numerator = (int32_t)diffP - (int32_t)diffM;
+ }
}
+ ptrSnsCxt++;
+ }
+
+ if ((maxIndex != CY_CAPSENSE_NO_LOCAL_MAX) && (maxSum > 0u))
+ {
+ /* Calculate position */
+ multiplier = (uint32_t)ptrWdConfig->yResolution << 8u;
+ if (0u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CALC_METHOD_MASK))
+ {
+ multiplier /= (rowCount - 1u);
+ offset = 0u;
+ }
+ else
+ {
+ multiplier /= rowCount;
+ offset = multiplier >> 1u;
+ }
+
+ denominator = (int32_t)maxSum;
+ denominator = ((numerator * (int32_t)multiplier) / denominator) + (((int32_t)maxIndex * (int32_t)multiplier) + (int32_t)offset);
+
+ /* Round result and shift 8 bits left */
+ newTouch->ptrPosition[0].y = CY_LO16(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
+ }
+ else
+ {
+ newTouch->numPosition = CY_CAPSENSE_POSITION_NONE;
}
- ptrSnsCxt++;
- }
-
- /* Calculate position */
- multiplier = (uint32_t)ptrWdConfig->yResolution << 8u;
- if (0u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CALC_METHOD_MASK))
- {
- multiplier /= (rowCount - 1u);
- offset = 0u;
- }
- else
- {
- multiplier /= rowCount;
- offset = multiplier >> 1u;
}
-
- denominator = (int32_t)maxSum;
- denominator = ((numerator * (int32_t)multiplier) / denominator) + (((int32_t)maxIndex * (int32_t)multiplier) + (int32_t)offset);
-
- /* Round result and shift 8 bits left */
- newTouch->ptrPosition[0].y = CY_LO16(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
-
- newTouch->numPosition = 1u;
}
else
{
diff --git a/cy_capsense_centroid.h b/cy_capsense_centroid.h
index d5aa6e7..c23b00f 100644
--- a/cy_capsense_centroid.h
+++ b/cy_capsense_centroid.h
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_centroid.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the function prototypes for the centroid calculation
@@ -8,7 +8,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -22,7 +22,7 @@
#include "cy_capsense_common.h"
#include "cy_capsense_structure.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
diff --git a/cy_capsense_common.h b/cy_capsense_common.h
index 681df18..04cebe8 100644
--- a/cy_capsense_common.h
+++ b/cy_capsense_common.h
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_common.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the common CapSense definitions.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -20,7 +20,7 @@
#include "cy_device_headers.h"
#include "cy_sysint.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
@@ -31,13 +31,38 @@ extern "C" {
* Macros
*******************************************************************************/
+#if (defined(CY_IP_M0S8CSDV2))
+ #define CY_CAPSENSE_PSOC4_CSDV2 (1)
+ #define CY_CAPSENSE_PSOC6_CSDV2 (0)
+#else
+ #define CY_CAPSENSE_PSOC4_CSDV2 (0)
+ #define CY_CAPSENSE_PSOC6_CSDV2 (1)
+#endif
+
+
/******************************************************************************/
/** \addtogroup group_capsense_macros_general *//** \{ */
/******************************************************************************/
/** Middleware major version */
#define CY_CAPSENSE_MW_VERSION_MAJOR (2)
/** Middleware minor version */
-#define CY_CAPSENSE_MW_VERSION_MINOR (0)
+#define CY_CAPSENSE_MW_VERSION_MINOR (10)
+/** Middleware version */
+#define CY_CAPSENSE_MW_VERSION (210)
+
+/** Defined supported CSD driver version */
+#define CY_CSD_DRV_VERSION_REQUIRED (100)
+
+#if !defined (CY_CSD_DRV_VERSION)
+ /** If CSD driver version not defined by driver then define it here */
+ #define CY_CSD_DRV_VERSION (100)
+#endif
+
+/* Check used driver version */
+#if (CY_CSD_DRV_VERSION_REQUIRED > CY_CSD_DRV_VERSION)
+ #error Some of the features supported by the CapSense Middleware version CY_CAPSENSE_MW_VERSION require newer version of the PDL. Update the PDL in your project.
+#endif
+
/** Middleware ID */
#define CY_CAPSENSE_ID (CY_PDL_DRV_ID(0x07uL))
@@ -180,6 +205,9 @@ extern "C" {
/** Iref source is taken from PASS */
#define CY_CAPSENSE_IREF_PASS (0x00000001uL)
+/** Voltage limit to switch to low-voltage configuration */
+#define CY_CAPSENSE_LOW_VOLTAGE_LIMIT (2000u)
+
/* Position Filter Configuration */
/** Mask of all filters enabling */
#define CY_CAPSENSE_POSITION_FILTERS_MASK (0x000000FFu)
@@ -377,6 +405,29 @@ extern "C" {
/** \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_bist *//** \{ */
+/******************************************************************************/
+/** The mask for a widget CRC test */
+#define CY_CAPSENSE_BIST_CRC_WDGT (0x0001uL)
+/** The mask for a baseline integrity test */
+#define CY_CAPSENSE_BIST_BSLN_INTEGRITY (0x0002uL)
+/** The mask for a rawcount integrity test */
+#define CY_CAPSENSE_BIST_RAW_INTEGRITY (0x0004uL)
+/** The mask for a pin integrity test */
+#define CY_CAPSENSE_BIST_SNS_INTEGRITY (0x0008uL)
+/** The mask for a sensor capacitance measurement test */
+#define CY_CAPSENSE_BIST_SNS_CAP (0x0010uL)
+/** The mask for a shield capacitance measurement test */
+#define CY_CAPSENSE_BIST_SHIELD_CAP (0x0020uL)
+/** The mask for an external capacitor capacitance measurement test */
+#define CY_CAPSENSE_BIST_EXTERNAL_CAP (0x0040uL)
+/** The mask for a VDDA measurement test */
+#define CY_CAPSENSE_BIST_VDDA (0x0080uL)
+
+/** \} */
+
#define CY_CAPSENSE_CONVERSION_MEGA (1000000u)
/*
diff --git a/cy_capsense_control.c b/cy_capsense_control.c
index 5b54353..03d1cff 100644
--- a/cy_capsense_control.c
+++ b/cy_capsense_control.c
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_control.c
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the source code to the Control module functions.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -25,8 +25,9 @@
#include "cy_capsense_filter.h"
#include "cy_capsense_sensing.h"
#include "cy_capsense_tuner.h"
+#include "cy_capsense_selftest.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
/*******************************************************************************
@@ -194,7 +195,7 @@ cy_status Cy_CapSense_Enable(cy_stc_capsense_context_t * context)
{
if (CY_CAPSENSE_CSD_SS_DIS != context->ptrCommonConfig->csdAutotuneEn)
{
- result |= Cy_CapSense_SsAutoTune_Call(context);
+ result = Cy_CapSense_SsAutoTune_Call(context);
}
if ((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdEn) &&
@@ -256,20 +257,24 @@ cy_status Cy_CapSense_Enable(cy_stc_capsense_context_t * context)
*******************************************************************************/
cy_status Cy_CapSense_Initialize(cy_stc_capsense_context_t * context)
{
- cy_status result = CY_RET_INVALID_STATE;
+ cy_status result;
result = Cy_CapSense_CheckConfigIntegrity(context);
if (CY_RET_SUCCESS == result)
{
- /* The Tuner is initialized only once */
+ Cy_CapSense_InitializeAllStatuses(context);
+ result = Cy_CapSense_SsInitialize(context);
+
+ /* The Tuner and the BIST are initialized only once */
if (CY_CAPSENSE_INIT_NEEDED == context->ptrCommonContext->initDone)
{
Cy_CapSense_TuInitialize(context);
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ Cy_CapSense_BistDsInitialize_Call(context);
+ }
context->ptrCommonContext->initDone = CY_CAPSENSE_INIT_DONE;
}
-
- Cy_CapSense_InitializeAllStatuses(context);
- result = Cy_CapSense_SsInitialize(context);
}
return (result);
@@ -381,11 +386,6 @@ cy_status Cy_CapSense_ProcessAllWidgets(cy_stc_capsense_context_t * context)
* widget. This function is called only after all the sensors in the
* widgets are scanned. A disabled widget is not processed by this function.
*
-* A pipeline scan method (i.e. during scanning of a widget performing processing
-* of the previously scanned widget) can be implemented using this function and
-* it may reduce the total execution time, increase the refresh rate and
-* decrease the average power consumption.
-*
* A pipeline scan method (i.e. during scanning of a current widget (N),
* perform processing of the previously scanned widget (N-1)) can be
* implemented using this function and it may reduce the total execution time,
@@ -525,27 +525,29 @@ cy_status Cy_CapSense_ProcessWidgetExt(
uint16_t * ptrHistoryCh;
uint16_t * ptrHistorySns;
uint8_t * ptrHistoryLowCh = NULL;
- uint8_t * ptrHistoryLowSns = NULL;
+ uint8_t * ptrHistoryLowSns;
cy_stc_capsense_sensor_context_t * ptrSnsCxtCh;
cy_stc_capsense_sensor_context_t * ptrSnsCxtSns;
const cy_stc_capsense_widget_config_t * ptrWdCfg;
-
-
+ uint16_t * ptrBslnInvCh;
+ uint16_t * ptrBslnInvSns;
+
/* Check parameter validity */
if (widgetId < context->ptrCommonConfig->numWd)
{
ptrWdCfg = &context->ptrWdConfig[widgetId];
snsHistorySize = (uint32_t)ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_MASK;
- freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
+ freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
ptrSnsCxtCh = &ptrWdCfg->ptrSnsContext[0u];
ptrHistoryCh = &ptrWdCfg->ptrRawFilterHistory[0u];
+ ptrBslnInvCh = ptrWdCfg->ptrBslnInv;
+
if(CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
{
ptrHistoryLowCh = &ptrWdCfg->ptrRawFilterHistoryLow[0u];
}
-
switch(ptrWdCfg->senseMethod)
{
case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E:
@@ -556,26 +558,32 @@ cy_status Cy_CapSense_ProcessWidgetExt(
ptrSnsCxtSns = ptrSnsCxtCh;
ptrHistorySns = ptrHistoryCh;
ptrHistoryLowSns = ptrHistoryLowCh;
+ ptrBslnInvSns = ptrBslnInvCh;
for (snsIndex = 0uL; snsIndex < ptrWdCfg->numSns; snsIndex++)
{
- result = Cy_CapSense_DpProcessCsdSensorRawCountsExt(ptrWdCfg, ptrSnsCxtSns, ptrHistorySns, ptrHistoryLowSns, mode, context);
-
+ result = Cy_CapSense_DpProcessCsdSensorRawCountsExt(ptrWdCfg,
+ ptrSnsCxtSns,
+ ptrHistorySns,
+ ptrHistoryLowSns,
+ mode,
+ ptrBslnInvSns,
+ context);
ptrSnsCxtSns++;
+ ptrBslnInvSns++;
ptrHistorySns += snsHistorySize;
if(NULL != ptrHistoryLowSns)
{
ptrHistoryLowSns++;
}
-
}
ptrSnsCxtCh += context->ptrCommonConfig->numSns;
+ ptrBslnInvCh += context->ptrCommonConfig->numSns;
ptrHistoryCh += context->ptrCommonConfig->numSns * snsHistorySize;
if(NULL != ptrHistoryLowCh)
{
ptrHistoryLowCh += context->ptrCommonConfig->numSns;
}
-
}
if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn)
@@ -602,26 +610,32 @@ cy_status Cy_CapSense_ProcessWidgetExt(
ptrSnsCxtSns = ptrSnsCxtCh;
ptrHistorySns = ptrHistoryCh;
ptrHistoryLowSns = ptrHistoryLowCh;
+ ptrBslnInvSns = ptrBslnInvCh;
for (snsIndex = 0uL; snsIndex < ptrWdCfg->numSns; snsIndex++)
{
- result = Cy_CapSense_DpProcessCsxSensorRawCountsExt(ptrWdCfg, ptrSnsCxtSns, ptrHistorySns, ptrHistoryLowSns, mode, context);
-
+ result = Cy_CapSense_DpProcessCsxSensorRawCountsExt(ptrWdCfg,
+ ptrSnsCxtSns,
+ ptrHistorySns,
+ ptrHistoryLowSns,
+ mode,
+ ptrBslnInvSns,
+ context);
ptrSnsCxtSns++;
+ ptrBslnInvSns++;
ptrHistorySns += snsHistorySize;
if(NULL != ptrHistoryLowSns)
{
ptrHistoryLowSns++;
}
-
}
ptrSnsCxtCh += context->ptrCommonConfig->numSns;
+ ptrBslnInvCh += context->ptrCommonConfig->numSns;
ptrHistoryCh += context->ptrCommonConfig->numSns * snsHistorySize;
if(NULL != ptrHistoryLowCh)
{
ptrHistoryLowCh += context->ptrCommonConfig->numSns;
}
-
}
if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn)
@@ -710,6 +724,7 @@ cy_status Cy_CapSense_ProcessSensorExt(
const cy_stc_capsense_context_t * context)
{
cy_status result = CY_RET_BAD_PARAM;
+ cy_status resultTmp;
uint32_t freqChIndex;
uint32_t freqChNumber;
@@ -721,6 +736,7 @@ cy_status Cy_CapSense_ProcessSensorExt(
uint8_t * ptrHistoryLow = NULL;
const cy_stc_capsense_widget_config_t * ptrWdCfg;
cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+ uint16_t * ptrSnsBslnInv;
if (widgetId < context->ptrCommonConfig->numWd)
{
@@ -730,44 +746,51 @@ cy_status Cy_CapSense_ProcessSensorExt(
snsHistorySize = (uint32_t)ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_MASK;
freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
ptrHistory = &ptrWdCfg->ptrRawFilterHistory[sensorId * snsHistorySize];
- if((uint32_t)CY_CAPSENSE_IIR_FILTER_PERFORMANCE == ((uint32_t)ptrWdCfg->rawFilterConfig & (uint32_t)CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
+ if((uint32_t)CY_CAPSENSE_IIR_FILTER_PERFORMANCE == ((uint32_t)ptrWdCfg->rawFilterConfig &
+ (uint32_t)CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
{
ptrHistoryLow = &ptrWdCfg->ptrRawFilterHistoryLow[sensorId];
}
ptrSnsCxt = &ptrWdCfg->ptrSnsContext[sensorId];
+ ptrSnsBslnInv = &ptrWdCfg->ptrBslnInv[sensorId];
cxtOffset = context->ptrCommonConfig->numSns;
historyOffset = snsHistorySize * context->ptrCommonConfig->numSns;
+ result = CY_RET_SUCCESS;
switch(ptrWdCfg->senseMethod)
{
case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E:
for(freqChIndex = 0u; freqChIndex < freqChNumber; freqChIndex++)
{
- result = Cy_CapSense_DpProcessCsdSensorRawCountsExt(
- ptrWdCfg,
- ptrSnsCxt,
- ptrHistory,
- ptrHistoryLow,
- mode, context);
+ resultTmp = Cy_CapSense_DpProcessCsdSensorRawCountsExt(ptrWdCfg, ptrSnsCxt,
+ ptrHistory, ptrHistoryLow,
+ mode, ptrSnsBslnInv, context);
+ if (CY_RET_SUCCESS != resultTmp)
+ {
+ result = CY_RET_BAD_DATA;
+ }
ptrSnsCxt += cxtOffset;
ptrHistory += historyOffset;
ptrHistoryLow += cxtOffset;
+ ptrSnsBslnInv += cxtOffset;
}
break;
case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E:
for(freqChIndex = 0u; freqChIndex < freqChNumber; freqChIndex++)
{
- result = Cy_CapSense_DpProcessCsxSensorRawCountsExt(
- ptrWdCfg,
- ptrSnsCxt,
- ptrHistory,
- ptrHistoryLow,
- mode, context);
+ resultTmp = Cy_CapSense_DpProcessCsxSensorRawCountsExt(ptrWdCfg, ptrSnsCxt,
+ ptrHistory, ptrHistoryLow,
+ mode, ptrSnsBslnInv, context);
+ if (CY_RET_SUCCESS != resultTmp)
+ {
+ result = CY_RET_BAD_DATA;
+ }
ptrSnsCxt += cxtOffset;
ptrHistory += historyOffset;
- ptrHistoryLow += cxtOffset;
+ ptrHistoryLow += cxtOffset;
+ ptrSnsBslnInv += cxtOffset;
}
break;
@@ -782,7 +805,6 @@ cy_status Cy_CapSense_ProcessSensorExt(
Cy_CapSense_RunMfsFiltering(ptrSnsCxt, context);
}
- result = CY_RET_SUCCESS;
}
}
return result;
@@ -793,10 +815,10 @@ cy_status Cy_CapSense_ProcessSensorExt(
* Function Name: Cy_CapSense_Wakeup
****************************************************************************//**
*
-* Resumes the middleware after CPU / System Deep Sleep.
+* Resumes the middleware after System Deep Sleep.
*
* This function is used to resume the middleware operation after exiting
-* CPU / System Deep Sleep. After the CSD HW block has been powered off,
+* System Deep Sleep. After the CSD HW block has been powered off,
* an extra delay is required to establish correct operation of
* the CSD HW block.
*
@@ -814,11 +836,11 @@ void Cy_CapSense_Wakeup(const cy_stc_capsense_context_t * context)
* Function Name: Cy_CapSense_DeepSleepCallback
****************************************************************************//**
*
-* Handles CPU active to CPU / System Deep Sleep power mode transition for the CapSense
+* Handles CPU active to System Deep Sleep power mode transition for the CapSense
* middleware.
*
* Calling this function directly from the application program is not recommended.
-* Instead, Cy_SysPm_CpuEnterDeepSleep() should be used for the CPU active to CPU / System Deep Sleep
+* Instead, Cy_SysPm_CpuEnterDeepSleep() should be used for the CPU active to System Deep Sleep
* power mode transition of the device.
* \note
* After the CPU Deep Sleep transition, the device automatically goes
@@ -827,7 +849,7 @@ void Cy_CapSense_Wakeup(const cy_stc_capsense_context_t * context)
* (see details in the device TRM).
*
* For proper operation of the CapSense middleware during the CPU active to
-* CPU / System Deep Sleep mode transition, a callback to this function should be registered
+* System Deep Sleep mode transition, a callback to this function should be registered
* using the Cy_SysPm_RegisterCallback() function with CY_SYSPM_DEEPSLEEP
* type. After the callback is registered, this function is called by the
* Cy_SysPm_CpuEnterDeepSleep() function to prepare the middleware to the device
@@ -837,13 +859,11 @@ void Cy_CapSense_Wakeup(const cy_stc_capsense_context_t * context)
* function returns CY_SYSPM_SUCCESS if no scanning is in progress. Otherwise
* CY_SYSPM_FAIL is returned. If CY_SYSPM_FAIL status is returned, a device
* cannot change the power mode without completing the current scan as
-* a transition to CPU / System Deep Sleep during the scan can disrupt the middleware
+* a transition to System Deep Sleep during the scan can disrupt the middleware
* operation.
*
* For details of SysPm types and macros refer to the SysPm section of the
-* PDL documentation
-* PDL API Reference.
+* PDL documentation.
*
* \param callbackParams
* Refer to the description of the cy_stc_syspm_callback_params_t type in the
@@ -855,8 +875,8 @@ void Cy_CapSense_Wakeup(const cy_stc_capsense_context_t * context)
* \return
* Returns the status cy_en_syspm_status_t of the operation requested
* by the mode parameter:
-* - CY_SYSPM_SUCCESS - CPU / System Deep Sleep power mode can be entered.
-* - CY_SYSPM_FAIL - CPU / System Deep Sleep power mode cannot be entered.
+* - CY_SYSPM_SUCCESS - System Deep Sleep power mode can be entered.
+* - CY_SYSPM_FAIL - System Deep Sleep power mode cannot be entered.
*
*******************************************************************************/
cy_en_syspm_status_t Cy_CapSense_DeepSleepCallback(
@@ -1012,7 +1032,7 @@ cy_status Cy_CapSense_Restore(cy_stc_capsense_context_t * context)
cy_en_csd_key_t mvKey;
cy_status result = CY_RET_INVALID_STATE;
- cy_en_csd_status_t csdHwStatus = CY_CSD_SUCCESS;
+ cy_en_csd_status_t csdHwStatus;
cy_stc_csd_context_t * ptrCsdCxt = context->ptrCommonConfig->ptrCsdContext;
CSD_Type * ptrCsdBaseAdd = context->ptrCommonConfig->ptrCsdBase;
@@ -1107,12 +1127,12 @@ cy_status Cy_CapSense_Restore(cy_stc_capsense_context_t * context)
cy_status Cy_CapSense_Save(cy_stc_capsense_context_t * context)
{
cy_status result = CY_RET_INVALID_STATE;
- cy_en_csd_status_t initStatus = CY_CSD_LOCKED;
+ cy_en_csd_status_t initStatus;
if (CY_CAPSENSE_BUSY != Cy_CapSense_IsBusy(context))
{
/* Disconnect external capacitors and sensor pins from analog bus */
- Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_UNDEFINED_E, context);
+ (void)Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_UNDEFINED_E, context);
/* Release the CSD HW block */
initStatus = Cy_CSD_DeInit(
diff --git a/cy_capsense_control.h b/cy_capsense_control.h
index 0694c65..de96934 100644
--- a/cy_capsense_control.h
+++ b/cy_capsense_control.h
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_control.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the function prototypes of the Control module.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -21,7 +21,7 @@
#include "cy_capsense_structure.h"
#include "cy_capsense_common.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
diff --git a/cy_capsense_csd.c b/cy_capsense_csd.c
index 4afff5c..ac63128 100644
--- a/cy_capsense_csd.c
+++ b/cy_capsense_csd.c
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_csd.c
-* \version 2.0
+* \version 2.10
*
* \brief
* This file defines the data structure global variables and provides
@@ -10,7 +10,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -29,7 +29,7 @@
#include "cy_capsense_sensing.h"
#include "cy_capsense_csd.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
/*******************************************************************************
@@ -40,6 +40,13 @@
#define CY_CAPSENSE_EXTRA_COUNTS_MAX (CY_CAPSENSE_FILTER_DELAY_MAX + 5u + 20u)
#define CY_CAPSENSE_16_BIT_RESOLUTION (16uL)
+#define CY_CAPSENSE_CSD_PRECHARGE_MAX_TIME_US (6000u)
+#define CY_CAPSENSE_CSD_WATCHDOG_MARGIN_COEFF (3u)
+#define CY_CAPSENSE_CSD_PRECHARGE_WATCHDOG_TIME_US (CY_CAPSENSE_CSD_PRECHARGE_MAX_TIME_US *\
+ CY_CAPSENSE_CSD_WATCHDOG_MARGIN_COEFF)
+
+
+
/*******************************************************************************
* Static Function Prototypes
*******************************************************************************/
@@ -55,15 +62,13 @@ static void Cy_CapSense_CSDInitNextSnsScan(cy_stc_capsense_context_t * context);
static void Cy_CapSense_CSDInitNextChScan(cy_stc_capsense_context_t * context);
static void Cy_CapSense_CSDEnableShieldElectrodes(const cy_stc_capsense_context_t * context);
-static void Cy_CapSense_CSDCmodPrecharge(cy_stc_capsense_context_t * context);
static void Cy_CapSense_CSDTriggerScan(cy_stc_capsense_context_t * context);
-static void Cy_CapSense_CSDDischargeCmod(cy_stc_capsense_context_t * context);
-static void Cy_CapSense_CSDCalibrate(uint32_t widgetId, uint32_t target,
+static void Cy_CapSense_CSDCalibrate(uint32_t widgetId, uint32_t target,
cy_stc_capsense_context_t * context);
static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * context);
static void Cy_CapSense_CSDNormalizeIdac(
- cy_stc_capsense_widget_config_t const * ptrWdConfig,
+ cy_stc_capsense_widget_config_t const * ptrWdConfig,
uint32_t target,
const cy_stc_capsense_context_t * context);
/** \} \endcond */
@@ -93,21 +98,21 @@ void Cy_CapSense_CSDDisableMode(cy_stc_capsense_context_t * context)
{
/* Disconnect shields */
Cy_CapSense_CSDDisableShieldElectrodes(context);
-
+
if (0u != context->ptrCommonConfig->csdCTankShieldEn)
{
/* Csh pin to default state */
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh, CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_GPIO);
}
}
-
+
/* Disconnect IDACA, IDACB and RefGen input */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, 0u);
/* Disconnect previous CSD sensor if it has been connected */
Cy_CapSense_CSDSnsStateCheck(context);
}
-
+
/*******************************************************************************
* Function Name: Cy_CapSense_CSDEnableShieldElectrodes
@@ -130,7 +135,7 @@ static void Cy_CapSense_CSDEnableShieldElectrodes(const cy_stc_capsense_context_
for (shieldIndex = 0u; shieldIndex < context->ptrCommonConfig->csdShieldNumPin; shieldIndex++)
{
- Cy_CapSense_SsConfigPinRegisters(ptrShieldPin->pcPtr, (uint32_t)ptrShieldPin->pinNumber, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD);
+ Cy_CapSense_SsConfigPinRegisters(ptrShieldPin->pcPtr, (uint32_t)ptrShieldPin->pinNumber, CY_CAPSENSE_CSD_SCAN_PIN_DM, CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD);
ptrShieldPin++;
}
}
@@ -144,7 +149,7 @@ static void Cy_CapSense_CSDEnableShieldElectrodes(const cy_stc_capsense_context_
*
* The function resets the bit in the HSIOM register which disables the shield
* electrode functionality on the pin. The port and pin configurations are
-* stored in the cy_capsense_shieldIoList structure.
+* stored in the cy_capsense_shieldIoList structure.
*
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
@@ -153,16 +158,12 @@ static void Cy_CapSense_CSDEnableShieldElectrodes(const cy_stc_capsense_context_
void Cy_CapSense_CSDDisableShieldElectrodes(const cy_stc_capsense_context_t * context)
{
uint32_t shieldIndex;
- uint32_t interruptState;
const cy_stc_capsense_pin_config_t * ptrShieldPin = context->ptrShieldPinConfig;
for (shieldIndex = 0u; shieldIndex < context->ptrCommonConfig->csdShieldNumPin; shieldIndex++)
{
- Cy_CapSense_SsConfigPinRegisters(ptrShieldPin->pcPtr, (uint32_t)ptrShieldPin->pinNumber, CY_GPIO_DM_STRONG, CY_CAPSENSE_HSIOM_SEL_GPIO);
-
- interruptState = Cy_SysLib_EnterCriticalSection();
+ Cy_CapSense_SsConfigPinRegisters(ptrShieldPin->pcPtr, (uint32_t)ptrShieldPin->pinNumber, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
Cy_GPIO_Clr(ptrShieldPin->pcPtr, (uint32_t)ptrShieldPin->pinNumber);
- Cy_SysLib_ExitCriticalSection(interruptState);
ptrShieldPin++;
}
@@ -198,7 +199,7 @@ void Cy_CapSense_CSDInitialize(cy_stc_capsense_context_t * context)
{
uint32_t interruptState;
cy_stc_capsense_fptr_config_t * ptrFptrCfg = (cy_stc_capsense_fptr_config_t *)context->ptrFptrConfig;
-
+
/* Set all the sensors to inactive state */
Cy_CapSense_CSDClearSensors(context);
Cy_CapSense_DischargeExtCapacitors(context);
@@ -207,28 +208,30 @@ void Cy_CapSense_CSDInitialize(cy_stc_capsense_context_t * context)
{
/* Connect shields to AMUX-B bus (config HSIOM regs) */
Cy_CapSense_CSDEnableShieldElectrodes(context);
-
+
if (0u != context->ptrCommonConfig->csdCTankShieldEn)
{
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh, CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXB);
}
}
-
+
/* Initialize the unused CSD IP registers to default state */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_DUTY, CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_POL_PHI_HIGH);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_HSCMP, 0u);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_TIME, 0u);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_DUTY, CY_CAPSENSE_CSD_SENSE_DUTY_CFG);
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IO_SEL, context->ptrInternalContext->csdRegIoSel);
+ #endif
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR_SET, CY_CAPSENSE_DEFAULT_CSD_INTR_SET);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_DSI_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_DSI_SEL, context->ptrInternalContext->csdRegSwDsiSel);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_ADC_CTL, CY_CAPSENSE_DEFAULT_CSD_ADC_CTL);
-
+
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, 0u);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, context->ptrInternalContext->csdRegSwFwTankSelScan);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, 0u);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, 0u);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_AMUXBUF_SEL, context->ptrInternalContext->csdRegSwAmuxbufSel);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrInternalContext->csdRegSwHsPSelScan);
-
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_HS_N_SEL, CY_CAPSENSE_DEFAULT_SW_HS_N_SEL);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_HSCMP, context->ptrInternalContext->csdRegHscmpScan);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IO_SEL, context->ptrInternalContext->csdRegIoSel);
-
+
/* Connection AMUXBUS-A to CSDBUS-A / AMUXBUS-B to CSDBUS-B */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_BYP_SEL, context->ptrInternalContext->csdRegSwBypSel);
@@ -238,8 +241,6 @@ void Cy_CapSense_CSDInitialize(cy_stc_capsense_context_t * context)
Cy_GPIO_SetHSIOM((GPIO_PRT_Type*)context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod, CY_CAPSENSE_HSIOM_SEL_AMUXA);
Cy_SysLib_ExitCriticalSection(interruptState);
- /* Set Csd Auto Zero time (set AZ_TIME bitmask) */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_TIME, 0u);
/* Select CMOD and Csh_tank/shield initialization switch resistance */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_RES, context->ptrInternalContext->csdRegSwResScan);
/* Set the number of dummy fine initialization cycles */
@@ -249,17 +250,12 @@ void Cy_CapSense_CSDInitialize(cy_stc_capsense_context_t * context)
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_CMP_P_SEL, context->ptrInternalContext->csdRegSwCmpPSel);
/* Configure VREF */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL,
- context->ptrInternalContext->regSwRefGenSel | CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_IAIB_MSK);
-
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, context->ptrInternalContext->csdRegSwRefGenSel);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_AMBUF, context->ptrInternalContext->csdRegAmuxbufInit);
/* Connect VREFHI to HSCOMP */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_HS_N_SEL, CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_CLOSE);
-
- /* Connect VREFHI (from RefGen) to CSDCOMP when Vdda >= 2 V */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_CMP_N_SEL, CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE);
-
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_CMP_N_SEL, context->ptrInternalContext->csdRegSwCmpNSel);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_REFGEN, context->ptrInternalContext->csdRegRefgen);
/* Configure IDACs mode */
@@ -269,7 +265,7 @@ void Cy_CapSense_CSDInitialize(cy_stc_capsense_context_t * context)
/* Configure ModClk */
Cy_CapSense_SetClkDivider((uint32_t)context->ptrCommonContext->modCsdClk - 1u, context);
-
+
/* Setup ISR handler to single-sensor scan function */
if(NULL != ptrFptrCfg->fptrCSDScanISR)
{
@@ -303,12 +299,12 @@ void Cy_CapSense_CSDSnsStateCheck(cy_stc_capsense_context_t * context)
* Function Name: Cy_CapSense_CSDSetUpIdacs
****************************************************************************//**
*
-* This function writes both IDACs available in CSD method into corresponding
+* This function writes both IDACs available in CSD method into corresponding
* the CSD HW block registers.
*
* Modulator IDAC is taken from widget context structure and Compensation
* IDAC is taken from sensor context structure.
-* The cy_stc_active_scan_sns_t structure must be updated to the current
+* The cy_stc_active_scan_sns_t structure must be updated to the current
* widget/sensor by Cy_CapSense_InitActivePtr() before calling this function.
*
* \param context
@@ -351,7 +347,7 @@ void Cy_CapSense_CSDSetUpIdacs(cy_stc_capsense_context_t * context)
/* IDAC B Code */
regValue = ptrActive->ptrSnsContext->idacComp;
regValue |= context->ptrCommonConfig->idacGainTable[ptrActive->ptrWdContext->idacGainIndex].gainReg;
-
+
Cy_CSD_WriteBits(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IDACB, idacbBitsToWrite, regValue);
}
}
@@ -363,7 +359,7 @@ void Cy_CapSense_CSDSetUpIdacs(cy_stc_capsense_context_t * context)
*
* This function calculate number of sub-conversions.
*
-* \param snsClkDivider
+* \param snsClkDivider
* The divider value of the sense clock.
*
* \param resolution
@@ -372,7 +368,7 @@ void Cy_CapSense_CSDSetUpIdacs(cy_stc_capsense_context_t * context)
* \param snsClkSrc
* The widget Sense Clock Source.
*
-* \return
+* \return
* Returns the number of sub-conversions.
*
*******************************************************************************/
@@ -381,23 +377,23 @@ uint32_t Cy_CapSense_CSDGetNumberOfConversions(uint32_t snsClkDivider, uint32_t
/* CY_ID304273 */
uint32_t conversionsNum = 1uL << resolution;
uint32_t extraCounts = 0u;
-
+
if (0u == snsClkDivider)
{
snsClkDivider = 1u;
}
-
+
if ((CY_CAPSENSE_CLK_SOURCE_PRS8 == snsClkSrc) || (CY_CAPSENSE_CLK_SOURCE_PRS12 == snsClkSrc))
{
snsClkDivider <<= 1u;
}
-
+
if(CY_CAPSENSE_16_BIT_RESOLUTION <= resolution)
{
/* CY_ID285392 */
extraCounts = CY_CAPSENSE_EXTRA_COUNTS_MAX;
}
-
+
conversionsNum = (conversionsNum - extraCounts) / snsClkDivider;
return((conversionsNum > 0u) ? (conversionsNum) : 1u);
@@ -419,7 +415,7 @@ void Cy_CapSense_CSDConfigClock(cy_stc_capsense_context_t * context)
const cy_stc_capsense_widget_context_t * ptrWdCxt = context->ptrActiveScanSns->ptrWdContext;
uint32_t snsClkDivider;
uint32_t snsClkSrc = (uint32_t)ptrWdCxt->snsClkSource & ((uint32_t)~(uint32_t)CY_CAPSENSE_CLK_SOURCE_AUTO_MASK);
- uint32_t regConfig = 0u;
+ uint32_t regValue = 0u;
/* Getting row clock divider for matrix buttons or touchpad widgets */
if (context->ptrActiveScanSns->ptrWdConfig->numCols <= context->ptrActiveScanSns->sensorIndex)
@@ -430,24 +426,24 @@ void Cy_CapSense_CSDConfigClock(cy_stc_capsense_context_t * context)
{
snsClkDivider = ptrWdCxt->snsClk;
}
-
+
/* Configuring PRS SEL_BIT and decreasing divider in case of PRS */
if ((CY_CAPSENSE_CLK_SOURCE_PRS8 == snsClkSrc) || (CY_CAPSENSE_CLK_SOURCE_PRS12 == snsClkSrc))
{
- regConfig = CY_CAPSENSE_CSD_SENSE_PERIOD_SEL_LFSR_MSB_MSK;
+ regValue = CY_CAPSENSE_CSD_SENSE_PERIOD_SEL_LFSR_MSB_MSK;
snsClkDivider >>= 1u;
}
-
+
/* Check divider value */
if (0u == snsClkDivider)
{
snsClkDivider = 1u;
}
- regConfig |= ((snsClkSrc << CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_POS) | (snsClkDivider - 1u));
-
+ regValue |= ((snsClkSrc << CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_POS) | (snsClkDivider - 1u));
+
/* Update reg value with divider and configuration */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD, regConfig);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD, regValue);
}
@@ -470,13 +466,13 @@ void Cy_CapSense_CSDCalculateScanDuration(cy_stc_capsense_context_t * context)
uint32_t subConv;
cy_stc_capsense_widget_context_t * ptrWdCxt = context->ptrActiveScanSns->ptrWdContext;
uint32_t divider = ptrWdCxt->snsClk;
-
+
if (context->ptrActiveScanSns->ptrWdConfig->numCols <= context->ptrActiveScanSns->sensorIndex)
{
divider = ptrWdCxt->rowSnsClk;
}
- subConv = Cy_CapSense_CSDGetNumberOfConversions(divider, (uint32_t)ptrWdCxt->resolution,
+ subConv = Cy_CapSense_CSDGetNumberOfConversions(divider, (uint32_t)ptrWdCxt->resolution,
((uint32_t)ptrWdCxt->snsClkSource & ((uint32_t)~(uint32_t)CY_CAPSENSE_CLK_SOURCE_AUTO_MASK)));
/* Write number of sub-conversions into the CSD HW block register */
@@ -490,10 +486,10 @@ void Cy_CapSense_CSDCalculateScanDuration(cy_stc_capsense_context_t * context)
*
* Performs the initialization required to scan the specified CSD widget.
*
-* \note This function is obsolete and kept for backward compatibility only.
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_SetupWidget() function should be used instead.
*
-* This function prepares the middleware to scan all the sensors in the
+* This function prepares the middleware to scan all the sensors in the
* specified CSD widget by executing the following tasks:
* 1. Configure the CSD HW block if it is not configured to perform the
* CSD sensing method used by the specified widget.
@@ -505,17 +501,17 @@ void Cy_CapSense_CSDCalculateScanDuration(cy_stc_capsense_context_t * context)
*
* This function does not start sensor scanning. The Cy_CapSense_CSDScan()
* function must be called to start the scan sensors in the widget. If this
-* function is called more than once, it does not break the middleware
+* function is called more than once, it does not break the middleware
* operation, but only the last initialized widget is in effect.
* Calling this function directly from the application program is not
* recommended. This function is used to implement only the user's specific
* use cases (for example faster execution).
*
-* The status of a sensor scan must be checked using the Cy_CapSense_IsBusy()
+* The status of a sensor scan must be checked using the Cy_CapSense_IsBusy()
* function prior to starting a next scan or setting up another widget.
-*
+*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param context
@@ -525,7 +521,7 @@ void Cy_CapSense_CSDCalculateScanDuration(cy_stc_capsense_context_t * context)
void Cy_CapSense_CSDSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * context)
{
/* Setup new scanning mode */
- Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E, context);
+ (void)Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E, context);
/* Disconnect previous sensors if they have been connected */
Cy_CapSense_CSDSnsStateCheck(context);
@@ -543,35 +539,35 @@ void Cy_CapSense_CSDSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * c
* Function Name: Cy_CapSense_CSDSetupWidgetExt
****************************************************************************//**
*
-* Performs extended initialization required to scan a specified sensor in
+* Performs extended initialization required to scan a specified sensor in
* a widget using CSD sensing method.
-*
-* \note This function is obsolete and kept for backward compatibility only.
+*
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_SetupWidgetExt() function should be used instead.
*
-* This function performs the same tasks of Cy_CapSense_CSDSetupWidget() and
-* also connects and configures specified sensor for scan. Hence this
-* function, along with Cy_CapSense_CSDScanExt() function, can be used to
+* This function performs the same tasks of Cy_CapSense_CSDSetupWidget() and
+* also connects and configures specified sensor for scan. Hence this
+* function, along with Cy_CapSense_CSDScanExt() function, can be used to
* scan a specific sensor in the widget.
-*
-* This function should be called for widget that is configured to use
-* CSD sensing method, using this function on a non-CSD sensing widget
+*
+* This function should be called for widget that is configured to use
+* CSD sensing method, using this function on a non-CSD sensing widget
* would cause unexpected result.
-*
-* This function requires using the Cy_CapSense_CSDScanExt() function to
+*
+* This function requires using the Cy_CapSense_CSDScanExt() function to
* initiate a scan.
-*
-* Calling this function directly from the application layer is not
-* recommended. This function is used to implement only the user's
+*
+* Calling this function directly from the application layer is not
+* recommended. This function is used to implement only the user's
* specific use cases (for example faster execution).
-*
+*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param sensorId
-* Specifies the ID number of the sensor within the widget. A macro for the
-* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE__SNS_ID.
*
* \param context
@@ -581,7 +577,7 @@ void Cy_CapSense_CSDSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * c
void Cy_CapSense_CSDSetupWidgetExt(uint32_t widgetId, uint32_t sensorId, cy_stc_capsense_context_t * context)
{
/* Switch Mode if needed */
- Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E, context);
+ (void)Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E, context);
/* Disconnect previous sensors if they have been connected */
Cy_CapSense_CSDSnsStateCheck(context);
@@ -628,29 +624,29 @@ void Cy_CapSense_CSDStartSample(cy_stc_capsense_context_t * context)
* Function Name: Cy_CapSense_CSDScanExt
****************************************************************************//**
*
-* Starts the CSD conversion on the preconfigured sensor.
-*
-* \note This function is obsolete and kept for backward compatibility only.
+* Starts the CSD conversion on the preconfigured sensor.
+*
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_ScanExt() function should be used instead.
*
-* This function performs scanning of a specific sensor in the widget
-* previously initialized using the Cy_CapSense_CSDSetupWidgetExt() function.
-*
-* This function is called when no scanning is in progress.
-* I.e. Cy_CapSense_IsBusy() returns a non-busy status and the widget must
-* be preconfigured using Cy_CapSense_CSDSetupWidgetExt() function prior
-* to calling this function. Calling this function directly from
-* the application program is not recommended. This function is used to
+* This function performs scanning of a specific sensor in the widget
+* previously initialized using the Cy_CapSense_CSDSetupWidgetExt() function.
+*
+* This function is called when no scanning is in progress.
+* I.e. Cy_CapSense_IsBusy() returns a non-busy status and the widget must
+* be preconfigured using Cy_CapSense_CSDSetupWidgetExt() function prior
+* to calling this function. Calling this function directly from
+* the application program is not recommended. This function is used to
* implement only the user's specific use cases (for example faster execution).
-*
-* This function does not disconnect sensor GPIOs from CSD HW block at the
-* end of a scan, therefore making subsequent scan of the same sensor is faster.
-* If sensor needs to be disconnected after the scan,
+*
+* This function does not disconnect sensor GPIOs from CSD HW block at the
+* end of a scan, therefore making subsequent scan of the same sensor is faster.
+* If sensor needs to be disconnected after the scan,
* Cy_CapSense_CSDDisconnectSns() function can be used.
-*
-* Calling Cy_CapSense_SetupWidget(), Cy_CapSense_CSDSetupWidget(),
-* Cy_CapSense_ScanAllWidgets(), or if Cy_CapSense_RunTuner() returns
-* CY_CAPSENSE_STATUS_RESTART_DONE status invalidated initialization
+*
+* Calling Cy_CapSense_SetupWidget(), Cy_CapSense_CSDSetupWidget(),
+* Cy_CapSense_ScanAllWidgets(), or if Cy_CapSense_RunTuner() returns
+* CY_CAPSENSE_STATUS_RESTART_DONE status invalidated initialization
* made by this function.
*
* \param context
@@ -682,10 +678,10 @@ void Cy_CapSense_CSDScanExt(cy_stc_capsense_context_t * context)
* Function Name: Cy_CapSense_CSDScan
****************************************************************************//**
*
-* This function initiates a scan for the sensors of the widget initialized
+* This function initiates a scan for the sensors of the widget initialized
* by the Cy_CapSense_CSDSetupWidget() function.
*
-* \note This function is obsolete and kept for backward compatibility only.
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_Scan() function should be used instead.
*
* This function does the following tasks:
@@ -712,7 +708,7 @@ void Cy_CapSense_CSDScanExt(cy_stc_capsense_context_t * context)
void Cy_CapSense_CSDScan(cy_stc_capsense_context_t * context)
{
Cy_CapSense_InitActivePtrSns(0u, context);
-
+
/* Setup Idac Value */
Cy_CapSense_CSDSetUpIdacs(context);
Cy_CapSense_CSDConnectSnsExt(context);
@@ -779,7 +775,7 @@ void Cy_CapSense_CSDDisconnectSnsExt(cy_stc_capsense_context_t * context)
cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
const cy_stc_capsense_electrode_config_t * ptrActiveSns = ptrActive->ptrEltdConfig;
const cy_stc_capsense_pin_config_t * ptrActivePin = ptrActiveSns->ptrPin;
-
+
uint32_t i;
/* Disconnect all pins of current sensors */
@@ -797,24 +793,24 @@ void Cy_CapSense_CSDDisconnectSnsExt(cy_stc_capsense_context_t * context)
****************************************************************************//**
*
* Connects port pin to the CSD HW block using AMUX bus.
-*
-* This function can be used to customize the default sensor connection
-* by connecting one or more pins to an existing sensor prior to initiating
+*
+* This function can be used to customize the default sensor connection
+* by connecting one or more pins to an existing sensor prior to initiating
* scan of the sensor.
-*
-* The function ignores whether the sensor is a ganged sensor and
-* connects only a specified port pin to the CSD HW block. This function can
+*
+* The function ignores whether the sensor is a ganged sensor and
+* connects only a specified port pin to the CSD HW block. This function can
* only use GPIOs that are already assigned to CapSense middleware.
-*
-* The functions that perform a setup and scan of a sensor/widget do not
-* take into account changes in the design made by
-* the Cy_CapSense_CSDConnectSns() function, hence all GPIOs connected
-* using this function must be disconnected using
-* the Cy_CapSense_CSDDisconnectSns() function prior to initializing
-* new widgets. Use this function in StartSample
-* callback (see the \ref group_capsense_callbacks section for details)
+*
+* The functions that perform a setup and scan of a sensor/widget do not
+* take into account changes in the design made by
+* the Cy_CapSense_CSDConnectSns() function, hence all GPIOs connected
+* using this function must be disconnected using
+* the Cy_CapSense_CSDDisconnectSns() function prior to initializing
+* new widgets. Use this function in StartSample
+* callback (see the \ref group_capsense_callbacks section for details)
* or with low-level functions that perform a single-sensor scanning.
-*
+*
* Scanning should be completed before calling this function.
*
* \param snsAddrPtr
@@ -825,16 +821,17 @@ void Cy_CapSense_CSDDisconnectSnsExt(cy_stc_capsense_context_t * context)
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
* \funcusage
-*
-* An example of using the function to perform port pin re-connection:
+*
+* An example of using the function to perform port pin re-connection:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_CSDConnect
-*
+*
*******************************************************************************/
void Cy_CapSense_CSDConnectSns(
- const cy_stc_capsense_pin_config_t * snsAddrPtr,
- cy_stc_capsense_context_t * context)
+ const cy_stc_capsense_pin_config_t * snsAddrPtr,
+ const cy_stc_capsense_context_t * context)
{
- Cy_CapSense_SsConfigPinRegisters(snsAddrPtr->pcPtr, (uint32_t)snsAddrPtr->pinNumber, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_CSD_SENSE);
+ (void) context;
+ Cy_CapSense_SsConfigPinRegisters(snsAddrPtr->pcPtr, (uint32_t)snsAddrPtr->pinNumber, CY_CAPSENSE_CSD_SCAN_PIN_DM, CY_CAPSENSE_HSIOM_SEL_CSD_SENSE);
}
@@ -843,14 +840,14 @@ void Cy_CapSense_CSDConnectSns(
****************************************************************************//**
*
* Disconnects port pin from the CSD HW block by disconnecting it from AMUX bus.
-*
-* This function can be used to disconnect a sensor connected
-* using the Cy_CapSense_CSDConnectSns() function. In addition, this
-* function can be used to customize a default sensor connection by
-* disconnecting one or more already connected sensors prior to
+*
+* This function can be used to disconnect a sensor connected
+* using the Cy_CapSense_CSDConnectSns() function. In addition, this
+* function can be used to customize a default sensor connection by
+* disconnecting one or more already connected sensors prior to
* initiating a scan of the sensor.
-*
-* This function works identically to the Cy_CapSense_CSDConnectSns() function
+*
+* This function works identically to the Cy_CapSense_CSDConnectSns() function
* except it disconnects the specified port pin used by the sensor.
*
* Scanning should be completed before calling this function.
@@ -863,24 +860,19 @@ void Cy_CapSense_CSDConnectSns(
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
* \funcusage
-*
-* An example of using the function to perform port pin re-connection:
+*
+* An example of using the function to perform port pin re-connection:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_CSDConnect
-*
+*
*******************************************************************************/
void Cy_CapSense_CSDDisconnectSns(
- const cy_stc_capsense_pin_config_t * snsAddrPtr,
+ const cy_stc_capsense_pin_config_t * snsAddrPtr,
const cy_stc_capsense_context_t * context)
{
- uint32_t interruptState;
-
- Cy_CapSense_SsConfigPinRegisters(snsAddrPtr->pcPtr, (uint32_t)snsAddrPtr->pinNumber,
- context->ptrInternalContext->csdInactiveSnsDm,
+ Cy_CapSense_SsConfigPinRegisters(snsAddrPtr->pcPtr, (uint32_t)snsAddrPtr->pinNumber,
+ context->ptrInternalContext->csdInactiveSnsDm,
context->ptrInternalContext->csdInactiveSnsHsiom);
-
- interruptState = Cy_SysLib_EnterCriticalSection();
Cy_GPIO_Clr(snsAddrPtr->pcPtr, (uint32_t)snsAddrPtr->pinNumber);
- Cy_SysLib_ExitCriticalSection(interruptState);
}
@@ -908,7 +900,7 @@ void Cy_CapSense_CSDClearSensors(const cy_stc_capsense_context_t * context)
uint32_t pinIndex;
const cy_stc_capsense_widget_config_t * ptrWdCfg;
const cy_stc_capsense_electrode_config_t * ptrSnsCfg;
-
+
/* Go through all CSD widgets and configure each sensor/pin to the defined state */
for (wdgtIndex = 0u; wdgtIndex < context->ptrCommonConfig->numWd; wdgtIndex++)
{
@@ -948,7 +940,7 @@ void Cy_CapSense_CSDSetWidgetSenseClkSrc(const cy_stc_capsense_widget_config_t *
uint32_t rowLfsrSize;
uint8_t widgetType = ptrWdConfig->wdType;
cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
-
+
if (0u != (ptrWdCxt->snsClkSource & CY_CAPSENSE_CLK_SOURCE_AUTO_MASK))
{
conversionsNum = Cy_CapSense_CSDGetNumberOfConversions((uint32_t)ptrWdCxt->snsClk, (uint32_t)ptrWdCxt->resolution, CY_CAPSENSE_CLK_SOURCE_DIRECT);
@@ -957,7 +949,7 @@ void Cy_CapSense_CSDSetWidgetSenseClkSrc(const cy_stc_capsense_widget_config_t *
{
lfsrSize = Cy_CapSense_CSDCalcPrsSize((uint32_t)ptrWdCxt->snsClk << 1uL, (uint32_t)ptrWdCxt->resolution);
}
-
+
if (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == widgetType) || ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == widgetType))
{
if (ptrWdCxt->rowSnsClk != ptrWdCxt->snsClk)
@@ -996,7 +988,7 @@ void Cy_CapSense_CSDSetWidgetSenseClkSrc(const cy_stc_capsense_widget_config_t *
* \param resolution
* The widget resolution.
*
-* \return
+* \return
* Returns the size of PRS value for SENSE_PERIOD register.
*
*******************************************************************************/
@@ -1027,19 +1019,19 @@ uint32_t Cy_CapSense_CSDCalcPrsSize(uint32_t snsClkDivider, uint32_t resolution)
* Function Name: Cy_CapSense_CSDDischargeCmod
****************************************************************************//**
*
-* Discharges Cmod capacitor related to CSD sensing method and restores
+* Discharges Cmod capacitor related to CSD sensing method and restores
* it state.
*
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
*******************************************************************************/
-static void Cy_CapSense_CSDDischargeCmod(cy_stc_capsense_context_t * context)
+void Cy_CapSense_CSDDischargeCmod(cy_stc_capsense_context_t * context)
{
en_hsiom_sel_t hsiomReg;
uint32_t pcReg;
uint32_t interruptState;
-
+
/* Disconnect Ext Cap from AMUXBUS-A / AMUXBUSB using HSIOM registers */
interruptState = Cy_SysLib_EnterCriticalSection();
hsiomReg = Cy_GPIO_GetHSIOM(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod);
@@ -1051,8 +1043,7 @@ static void Cy_CapSense_CSDDischargeCmod(cy_stc_capsense_context_t * context)
interruptState = Cy_SysLib_EnterCriticalSection();
pcReg = Cy_GPIO_GetDrivemode(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod);
Cy_GPIO_Clr(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod);
- Cy_GPIO_SetDrivemode(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod,
- CY_GPIO_DM_STRONG_IN_OFF);
+ Cy_GPIO_SetDrivemode(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod, CY_GPIO_DM_STRONG_IN_OFF);
Cy_SysLib_ExitCriticalSection(interruptState);
/* Now external CSD-related capacitors discharging */
@@ -1102,10 +1093,10 @@ static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * contex
maxIdac = 0u;
minIdac = CY_CAPSENSE_CAL_IDAC_MAX_VALUE;
-
+
freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
for(freqChIndex = 0u; freqChIndex < freqChNumber; freqChIndex++)
- {
+ {
/* Find maximum and minimum IDACs */
idacVal = ptrActive->ptrWdContext->idacMod[freqChIndex];
if (maxIdac < idacVal)
@@ -1117,7 +1108,7 @@ static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * contex
minIdac = idacVal;
}
/* Check for sensorIndex >= numCols added and choose rowIdac if needed */
- if ((((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrActive->ptrWdConfig->wdType) ||
+ if ((((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrActive->ptrWdConfig->wdType) ||
((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrActive->ptrWdConfig->wdType)) &&
(ptrActive->ptrWdConfig->numCols <= ptrActive->sensorIndex))
{
@@ -1131,10 +1122,10 @@ static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * contex
minIdac = idacVal;
}
}
-
+
/* Set value for iDac comp */
if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdIdacCompEn)
- {
+ {
for(snsIndex = 0u; snsIndex < ptrActive->ptrWdConfig->numSns; snsIndex++)
{
ptrSnsCxt = &ptrActive->ptrWdConfig->ptrSnsContext[snsIndex];
@@ -1146,13 +1137,13 @@ static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * contex
}
}
}
-
+
/* Check gain switch conditions */
if (gainIndex != 0u)
{
if (minIdac < context->ptrCommonConfig->csdIdacMin)
{
- ratio = context->ptrCommonConfig->idacGainTable[gainIndex].gainValue /
+ ratio = context->ptrCommonConfig->idacGainTable[gainIndex].gainValue /
context->ptrCommonConfig->idacGainTable[gainIndex - 1u].gainValue;
if ((maxIdac * ratio) < CY_CAPSENSE_CAL_IDAC_MAX_VALUE)
{
@@ -1164,7 +1155,7 @@ static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * contex
}
return (swStatus);
}
-
+
/*******************************************************************************
* Function Name: Cy_CapSense_SsCSDNormalizeIdac
@@ -1172,7 +1163,7 @@ static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * contex
*
* This function normalizes compensation IDAC.
*
-* \param ptrWdConfig
+* \param ptrWdConfig
* Specifies the pointer to a widget configuration structure.
*
* \param target
@@ -1183,7 +1174,7 @@ static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * contex
*
*******************************************************************************/
static void Cy_CapSense_CSDNormalizeIdac(
- cy_stc_capsense_widget_config_t const * ptrWdConfig,
+ cy_stc_capsense_widget_config_t const * ptrWdConfig,
uint32_t target,
const cy_stc_capsense_context_t * context)
{
@@ -1196,11 +1187,11 @@ static void Cy_CapSense_CSDNormalizeIdac(
uint8_t freqChIndex;
uint8_t freqChNumber;
-
+
cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
uint32_t maxRawLevel = ptrWdCxt->maxRawCount;
cy_stc_capsense_sensor_context_t * ptrSnsCxt;
-
+
freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
for(freqChIndex = 0u; freqChIndex < freqChNumber; freqChIndex++)
{
@@ -1218,22 +1209,22 @@ static void Cy_CapSense_CSDNormalizeIdac(
}
ptrSnsCxt++;
}
-
+
/* Define new modulator IDAC */
rawLevel = ((minRaw * CY_CAPSENSE_PERCENTAGE_100) / maxRawLevel) + CY_CAPSENSE_PERCENTAGE_100;
iMod = (rawLevel * minIdac) / target;
-
+
if (iMod > maxIdac)
{
iMod = maxIdac;
}
ptrWdCxt->idacMod[freqChIndex] = (uint8_t)iMod;
-
+
/* Re-calculate compensation IDAC */
ptrSnsCxt = &ptrWdConfig->ptrSnsContext[freqChIndex * context->ptrCommonConfig->numSns];
for(snsIndex = 0u; snsIndex < ptrWdConfig->numCols; snsIndex++)
{
- rawLevel = ((((uint32_t)ptrSnsCxt->raw * CY_CAPSENSE_PERCENTAGE_100) / maxRawLevel) +
+ rawLevel = ((((uint32_t)ptrSnsCxt->raw * CY_CAPSENSE_PERCENTAGE_100) / maxRawLevel) +
CY_CAPSENSE_PERCENTAGE_100) * ptrSnsCxt->idacComp;
if (rawLevel < (iMod * target))
{
@@ -1241,13 +1232,13 @@ static void Cy_CapSense_CSDNormalizeIdac(
}
else
{
- ptrSnsCxt->idacComp = (uint8_t)(((rawLevel - (iMod * target)) +
+ ptrSnsCxt->idacComp = (uint8_t)(((rawLevel - (iMod * target)) +
(CY_CAPSENSE_PERCENTAGE_100 >> 1u)) / CY_CAPSENSE_PERCENTAGE_100);
}
ptrSnsCxt++;
}
/* IDAC Normalization is performed separately for row and column */
- if (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdConfig->wdType) ||
+ if (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdConfig->wdType) ||
((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdConfig->wdType))
{
/* Find maximum and minimum IDACs */
@@ -1264,22 +1255,22 @@ static void Cy_CapSense_CSDNormalizeIdac(
}
ptrSnsCxt++;
}
-
+
/* Define new modulator IDAC */
rawLevel = ((minRaw * CY_CAPSENSE_PERCENTAGE_100) / maxRawLevel) + CY_CAPSENSE_PERCENTAGE_100;
iMod = (rawLevel * minIdac) / target;
-
+
if (iMod > maxIdac)
{
iMod = maxIdac;
}
ptrWdCxt->rowIdacMod[freqChIndex] = (uint8_t)iMod;
-
+
/* Re-calculate compensation IDAC */
ptrSnsCxt = &(ptrWdConfig->ptrSnsContext[(freqChIndex * context->ptrCommonConfig->numSns) + ptrWdConfig->numCols]);
for(snsIndex = 0u; snsIndex < ptrWdConfig->numCols; snsIndex++)
{
- rawLevel = ((((uint32_t)ptrSnsCxt->raw * CY_CAPSENSE_PERCENTAGE_100) / maxRawLevel) +
+ rawLevel = ((((uint32_t)ptrSnsCxt->raw * CY_CAPSENSE_PERCENTAGE_100) / maxRawLevel) +
CY_CAPSENSE_PERCENTAGE_100) * ptrSnsCxt->idacComp;
if (rawLevel < (iMod * target))
{
@@ -1287,7 +1278,7 @@ static void Cy_CapSense_CSDNormalizeIdac(
}
else
{
- ptrSnsCxt->idacComp = (uint8_t)(((rawLevel - (iMod * target)) +
+ ptrSnsCxt->idacComp = (uint8_t)(((rawLevel - (iMod * target)) +
(CY_CAPSENSE_PERCENTAGE_100 >> 1u)) / CY_CAPSENSE_PERCENTAGE_100);
}
ptrSnsCxt++;
@@ -1301,28 +1292,28 @@ static void Cy_CapSense_CSDNormalizeIdac(
* Function Name: Cy_CapSense_SsCSDCalibrate
****************************************************************************//**
*
-* Implements IDAC calibration for a desired widget using successive
+* Implements IDAC calibration for a desired widget using successive
* approximation algorithm.
*
-* It supports any type of CSD widgets, and works
+* It supports any type of CSD widgets, and works
* with multi-frequency scan and compensation IDAC features enabled.
*
-* As result of function operation, the modulator IDAC that corresponds to the
+* As result of function operation, the modulator IDAC that corresponds to the
* sensor with the highest capacitance (the biggest modulator IDAC) is stored
-* into widget data structure. If it is dual-axis widget type (touchpad or matrix
-* buttons) or if multi-frequency scan feature is enabled then the maximum
-* modulator IDAC found separately for each multi-frequency channel and for
+* into widget data structure. If it is dual-axis widget type (touchpad or matrix
+* buttons) or if multi-frequency scan feature is enabled then the maximum
+* modulator IDAC found separately for each multi-frequency channel and for
* rows/columns.
*
-* If compensation IDAC is enabled, then it preserves IDAC value of
-* single-sensor calibration. In dual IDAC mode each sensor was calibrated with
+* If compensation IDAC is enabled, then it preserves IDAC value of
+* single-sensor calibration. In dual IDAC mode each sensor was calibrated with
* equal values of modulator and compensation IDAC.
*
-* After IDACs were found each sensor scanned again to get real raw count stored
+* After IDACs were found each sensor scanned again to get real raw count stored
* in sensor structure.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param target
@@ -1333,8 +1324,8 @@ static void Cy_CapSense_CSDNormalizeIdac(
*
*******************************************************************************/
static void Cy_CapSense_CSDCalibrate(
- uint32_t widgetId,
- uint32_t target,
+ uint32_t widgetId,
+ uint32_t target,
cy_stc_capsense_context_t * context)
{
uint32_t freqChIndex;
@@ -1342,6 +1333,7 @@ static void Cy_CapSense_CSDCalibrate(
uint32_t snsIndex;
uint32_t rawTarget;
uint32_t tmpVal;
+ uint32_t modClkDivider;
uint32_t cpuFreqMHz;
uint32_t watchdogCounter;
@@ -1359,18 +1351,18 @@ static void Cy_CapSense_CSDCalibrate(
const uint32_t isBusyLoopDuration = 5uL;
/* Wait For Init watchdog timeout in microseconds */
- const uint32_t isBusyWatchdogTimeUs = 200000uL;
+ uint64_t isBusyWatchdogTimeUs = 0u;
rawTarget = ((uint32_t)ptrWdCxt->maxRawCount * target) / CY_CAPSENSE_PERCENTAGE_100;
freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
-
+
for(snsIndex = 0u; snsIndex < (uint32_t)ptrWdCfg->numSns; snsIndex++)
{
/* Set default IDAC code */
calMask = (uint8_t)CY_CAPSENSE_CAL_MIDDLE_VALUE;
ptrSnsCxt = &ptrWdCfg->ptrSnsContext[snsIndex];
-
+
if (ptrWdCfg->numCols > snsIndex)
{
ptrIdacMod = ptrWdCxt->idacMod;
@@ -1390,7 +1382,24 @@ static void Cy_CapSense_CSDCalibrate(
ptrSnsCxt[freqChIndex * context->ptrCommonConfig->numSns].idacComp = calMask;
}
}
-
+
+ modClkDivider = context->ptrCommonContext->modCsdClk;
+ if(0u == modClkDivider)
+ {
+ modClkDivider = 1u;
+ }
+
+ isBusyWatchdogTimeUs = (uint64_t)freqChNumber * ptrWdCxt->maxRawCount;
+ isBusyWatchdogTimeUs *= (uint64_t)modClkDivider * CY_CAPSENSE_CONVERSION_MEGA;
+ isBusyWatchdogTimeUs /= context->ptrCommonConfig->periClkHz;
+
+ if(0u == isBusyWatchdogTimeUs)
+ {
+ isBusyWatchdogTimeUs = 1u;
+ }
+
+ isBusyWatchdogTimeUs *= CY_CAPSENSE_CSD_WATCHDOG_MARGIN_COEFF;
+
do
{
/* Need to configure the CSD HW block with each IDAC change */
@@ -1401,8 +1410,8 @@ static void Cy_CapSense_CSDCalibrate(
Cy_CapSense_CSDScanExt(context);
cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
- watchdogCounter = Cy_CapSense_WatchdogCyclesNum(isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
-
+ watchdogCounter = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
/* Wait for EOS */
while (CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
{
@@ -1414,16 +1423,15 @@ static void Cy_CapSense_CSDCalibrate(
}
/* Switch to the lower IDAC mask */
- calMask >>= 1u;
for(freqChIndex = 0u; freqChIndex < freqChNumber; freqChIndex++)
{
/* Update IDAC based on scan result */
if (ptrSnsCxt[freqChIndex * context->ptrCommonConfig->numSns].raw < rawTarget)
{
- ptrIdacMod[freqChIndex] &= (uint8_t)(~(uint8_t)(calMask << 1u));
+ ptrIdacMod[freqChIndex] &= (uint8_t)(~calMask);
}
- ptrIdacMod[freqChIndex] |= (uint8_t)calMask;
+ ptrIdacMod[freqChIndex] |= (uint8_t)(calMask >> 1u);
if(0u == ptrIdacMod[freqChIndex])
{
@@ -1434,7 +1442,7 @@ static void Cy_CapSense_CSDCalibrate(
ptrSnsCxt[freqChIndex * context->ptrCommonConfig->numSns].idacComp = ptrIdacMod[freqChIndex];
}
}
-
+ calMask >>= 1u;
}
while(calMask != 0u);
@@ -1446,13 +1454,13 @@ static void Cy_CapSense_CSDCalibrate(
ptrIdacMax[freqChIndex] = ptrIdacMod[freqChIndex];
}
}
-
+
/* Perform scan again to get real raw count if IDAC was changed last iteration */
Cy_CapSense_CSDSetupWidgetExt(widgetId, snsIndex, context);
Cy_CapSense_CSDScanExt(context);
cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
- watchdogCounter = Cy_CapSense_WatchdogCyclesNum(isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+ watchdogCounter = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
/* Wait for EOS */
while (CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
@@ -1469,7 +1477,7 @@ static void Cy_CapSense_CSDCalibrate(
{
ptrWdCxt->idacMod[freqChIndex] = maxColIdac[freqChIndex];
- if (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType) ||
+ if (((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType) ||
((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType))
{
ptrWdCxt->rowIdacMod[freqChIndex] = maxRowIdac[freqChIndex];
@@ -1508,24 +1516,24 @@ static void Cy_CapSense_CSDCalibrate(
* Executes the IDAC calibration for all the sensors in the widget specified in
* the input.
*
-* \note This function is obsolete and kept for backward compatibility only.
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_CalibrateWidget() function should be used instead.
*
* Performs a successive approximation search algorithm to find appropriate
-* modulator and compensation IDAC (if enabled) values for all sensors in
-* the specified widget that provide the raw count to the level
+* modulator and compensation IDAC (if enabled) values for all sensors in
+* the specified widget that provide the raw count to the level
* specified by the target parameter.
*
-* Calibration returns CYRET_BAD_DATA if the achieved raw count is outside
+* Calibration returns CY_RET_BAD_DATA if the achieved raw count is outside
* of the range specified by the target and acceptable calibration deviation
* parameters.
*
* This function could be used when the CSD Enable IDAC auto-calibration
-* parameter is enabled. Do not use this function when
+* parameter is enabled. Do not use this function when
* the SmartSense auto-tuning mode is configured.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param target
@@ -1536,31 +1544,33 @@ static void Cy_CapSense_CSDCalibrate(
*
* \return
* Returns the status of the specified widget calibration:
-* - CYRET_SUCCESS - The operation is successfully completed.
-* - CYRET_BAD_PARAM - The input parameter is invalid.
-* - CYRET_BAD_DATA - The calibration failed and CapSense may not operate
-* as expected.
-* - CYRET_INVALID_STATE - The previous scanning is not completed, and
+* - CY_RET_SUCCESS - The operation is successfully completed.
+* - CY_RET_BAD_PARAM - The input parameter is invalid.
+* - CY_RET_BAD_DATA - The calibration failed and CapSense may not operate
+* as expected.
+* - CY_RET_INVALID_STATE - The previous scanning is not completed, and
* the CapSense middleware is busy.
*
*******************************************************************************/
cy_status Cy_CapSense_CSDCalibrateWidget(
- uint32_t widgetId,
- uint32_t target,
+ uint32_t widgetId,
+ uint32_t target,
cy_stc_capsense_context_t * context)
{
- cy_status calibrateStatus = CYRET_SUCCESS;
+ cy_status calibrateStatus = CY_RET_SUCCESS;
uint32_t gainSwitch;
uint32_t cpuFreqMHz;
uint32_t watchdogCounter;
+ uint32_t modClkDivider;
+ uint32_t freqChNumber;
const cy_stc_capsense_widget_config_t * ptrWdCfg;
/* Approximate duration of Wait For Init loop */
const uint32_t isBusyLoopDuration = 5uL;
/* Wait For Init watchdog timeout in microseconds */
- const uint32_t isBusyWatchdogTimeUs = 200000uL;
+ uint64_t isBusyWatchdogTimeUs;
if((context->ptrCommonConfig->numWd <= widgetId) ||
(CY_CAPSENSE_DISABLE == context->ptrCommonConfig->csdIdacAutocalEn))
@@ -1576,12 +1586,13 @@ cy_status Cy_CapSense_CSDCalibrateWidget(
if(CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
{
/* Previous widget is being scanned, return error */
- calibrateStatus = CYRET_INVALID_STATE;
+ calibrateStatus = CY_RET_INVALID_STATE;
}
if(CY_RET_SUCCESS == calibrateStatus)
{
ptrWdCfg = &context->ptrWdConfig[widgetId];
+ freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
ptrWdCfg->ptrWdContext->idacGainIndex = context->ptrCommonConfig->csdIdacGainInitIndex;
/* Perform calibration */
@@ -1603,14 +1614,30 @@ cy_status Cy_CapSense_CSDCalibrateWidget(
/* IDAC Normalization in Dual IDAC mode */
Cy_CapSense_CSDNormalizeIdac(ptrWdCfg, target, context);
}
-
+
/* Perform specified widget scan to check calibration result */
Cy_CapSense_CSDSetupWidget_Call(widgetId, context);
Cy_CapSense_CSDScan_Call(context);
+ modClkDivider = context->ptrCommonContext->modCsdClk;
+ if(0u == modClkDivider)
+ {
+ modClkDivider = 1u;
+ }
+
+ isBusyWatchdogTimeUs = (uint64_t)freqChNumber * ptrWdCfg->numSns * ptrWdCfg->ptrWdContext->maxRawCount;
+ isBusyWatchdogTimeUs *= (uint64_t)modClkDivider * CY_CAPSENSE_CONVERSION_MEGA;
+ isBusyWatchdogTimeUs /= context->ptrCommonConfig->periClkHz;
+
+ if(0u == isBusyWatchdogTimeUs)
+ {
+ isBusyWatchdogTimeUs = 1u;
+ }
+
+ isBusyWatchdogTimeUs *= CY_CAPSENSE_CSD_WATCHDOG_MARGIN_COEFF;
cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
- watchdogCounter = Cy_CapSense_WatchdogCyclesNum(isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
-
+ watchdogCounter = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
while (CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
{
if(0uL == watchdogCounter)
@@ -1619,17 +1646,16 @@ cy_status Cy_CapSense_CSDCalibrateWidget(
}
watchdogCounter--;
}
-
+
/* Verification of calibration result */
calibrateStatus = Cy_CapSense_CalibrateCheck(widgetId, target, (uint32_t)CY_CAPSENSE_SENSE_METHOD_CSD_E, context);
}
-
+
return calibrateStatus;
}
-
/*******************************************************************************
* Function Name: Cy_CapSense_CSDCmodPrecharge
****************************************************************************//**
@@ -1646,7 +1672,7 @@ cy_status Cy_CapSense_CSDCalibrateWidget(
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
*******************************************************************************/
-static void Cy_CapSense_CSDCmodPrecharge(cy_stc_capsense_context_t * context)
+void Cy_CapSense_CSDCmodPrecharge(cy_stc_capsense_context_t * context)
{
uint32_t cpuFreqMHz;
uint32_t watchdogCounter;
@@ -1655,57 +1681,50 @@ static void Cy_CapSense_CSDCmodPrecharge(cy_stc_capsense_context_t * context)
const uint32_t intrInitLoopDuration = 5uL;
/* Wait For Init watchdog timeout in microseconds */
- const uint32_t initWatchdogTimeUs = 200000uL;
+ const uint32_t initWatchdogTimeUs = CY_CAPSENSE_CSD_PRECHARGE_WATCHDOG_TIME_US;
/* Disable INIT interrupt */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR_MASK, CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK);
+ (void)Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR_MASK);
- /* Clear all interrupt pending requests */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
- (void)Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR);
-
- /* Enable power to sub-blocks */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_HSCMP, context->ptrInternalContext->csdRegHscmpInit);
-
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_CSDCMP, CY_CAPSENSE_CSD_CSDCMP_CSDCMP_EN_MSK);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, CY_CAPSENSE_CSD_SW_FW_MOD_SEL_INIT);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, context->ptrInternalContext->csdRegSwFwTankSelInit);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, context->ptrInternalContext->csdRegSwShieldSelInit);
-
- /* Connect CMOD to (sense path) to HSCOMP: HMPM or HMPS or HMPT switches depend on Cmod connects to certain pad */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrInternalContext->csdRegSwHsPSelInit);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_RES, context->ptrInternalContext->csdRegSwResInit);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, 0u);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, 0u);
- if (0u != context->ptrCommonConfig->csdShieldEn)
+ if((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn) &&
+ (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn))
{
- if (0u != context->ptrCommonConfig->csdCTankShieldEn)
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_HSCMP);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrInternalContext->csdRegSwHsPSelCtankInit);
+
+ /* Start SEQUENCER for coarse initialization for Csh */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_SEQ_MODE_MSK |
+ CY_CAPSENSE_CSD_SEQ_START_START_MSK);
+ /* Init Watchdog Counter to prevent a hang */
+ cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
+ watchdogCounter = Cy_CapSense_WatchdogCyclesNum(initWatchdogTimeUs, cpuFreqMHz, intrInitLoopDuration);
+ watchdogCounter = Cy_CapSense_WaitForSeqIdle(watchdogCounter, context);
+
+ if (0u == watchdogCounter)
{
- Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh,
- CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+ /* Set sequencer to idle state if coarse initialization fails */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK);
}
}
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_RES, context->ptrInternalContext->csdRegSwResInit);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrInternalContext->csdRegSwHsPSelCmodInit);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_HSCMP);
/* Start SEQUENCER for coarse initialization for Cmod */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_SEQ_MODE_MSK |
- CY_CAPSENSE_CSD_SEQ_START_START_MSK);
-
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_SEQ_MODE_MSK |
+ CY_CAPSENSE_CSD_SEQ_START_START_MSK);
/* Init Watchdog Counter to prevent a hang */
cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
watchdogCounter = Cy_CapSense_WatchdogCyclesNum(initWatchdogTimeUs, cpuFreqMHz, intrInitLoopDuration);
-
- /* Approximate duration of Wait For Init loop */
- while((0u != (CY_CAPSENSE_CSD_SEQ_START_START_MSK &
- Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START))))
- {
- if(0uL == watchdogCounter)
- {
- break;
- }
-
- watchdogCounter--;
- }
+ watchdogCounter = Cy_CapSense_WaitForSeqIdle(watchdogCounter, context);
if (0u == watchdogCounter)
{
@@ -1721,13 +1740,13 @@ static void Cy_CapSense_CSDCmodPrecharge(cy_stc_capsense_context_t * context)
*
* Triggers the scanning.
*
-* This function trigger the fine initialization (scan some dummy cycles) and
+* This function trigger the fine initialization (scan some dummy cycles) and
* start sampling.
-* For the fine initialization and sampling, Cmod is statically connected to
-* AMUXBUS-A and in every conversion (one cycle of SnsClk), the sensor
-* capacitance is charged from Cmod and discharged to ground using the
-* switches in GPIO cell. The CSDCOMP monitors voltage on Cmod using the
-* sense path and charges Cmod back to Vref using IDACs by connecting IDAC
+* For the fine initialization and sampling, Cmod is statically connected to
+* AMUXBUS-A and in every conversion (one cycle of SnsClk), the sensor
+* capacitance is charged from Cmod and discharged to ground using the
+* switches in GPIO cell. The CSDCOMP monitors voltage on Cmod using the
+* sense path and charges Cmod back to Vref using IDACs by connecting IDAC
* to CSDBUS-A and then the AMUXBUS-A.
*
* \param context
@@ -1742,36 +1761,24 @@ static void Cy_CapSense_CSDTriggerScan(cy_stc_capsense_context_t * context)
/* Enable SAMPLE interrupt */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR_MASK, CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK);
-
-
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrInternalContext->csdRegSwHsPSelScan);
/* Set scanning configuration for switches */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SCAN);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, context->ptrInternalContext->csdRegSwFwTankSelScan);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, 0u);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, 0u);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, context->ptrInternalContext->csdRegSwShieldSelScan);
- if (0u != context->ptrCommonConfig->csdShieldEn)
- {
- if (0u != context->ptrCommonConfig->csdCTankShieldEn)
- {
- Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh,
- CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXB);
- }
- }
-
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_RES, context->ptrInternalContext->csdRegSwResScan);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_CSDCMP, CY_CAPSENSE_CSD_CSDCMP_CSDCMP_EN_MSK);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_HSCMP, context->ptrInternalContext->csdRegHscmpScan);
/* Force the LFSR to it's initial state (all ones) */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD,
- Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD) |
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD,
+ Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD) |
CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_CLEAR_MSK | CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_BITS_MSK);
/* Start SEQUENCER for fine initialization scan for Cmod and then for normal scan */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_AZ0_SKIP_MSK |
- CY_CAPSENSE_CSD_SEQ_START_AZ1_SKIP_MSK |
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_AZ0_SKIP_MSK |
+ CY_CAPSENSE_CSD_SEQ_START_AZ1_SKIP_MSK |
CY_CAPSENSE_CSD_SEQ_START_START_MSK);
}
@@ -1783,7 +1790,7 @@ static void Cy_CapSense_CSDTriggerScan(cy_stc_capsense_context_t * context)
* This is an internal ISR function to handle the CSD sensing method operation.
*
* This handler covers the following functionality:
-* - Read the result of the measurement and store it into the corresponding
+* - Read the result of the measurement and store it into the corresponding
* register of the data structure.
* - If the Noise Metric functionality is enabled, then check the number of bad
* conversions and repeat the scan of the current sensor of the number of bad
@@ -1805,7 +1812,7 @@ void Cy_CapSense_CSDScanISR(void * capsenseContext)
uint32_t maxCount;
cy_stc_capsense_context_t * cxt = (cy_stc_capsense_context_t *)capsenseContext;
cy_stc_active_scan_sns_t * ptrActive = cxt->ptrActiveScanSns;
-
+
/* Clear pending interrupt */
Cy_CSD_WriteReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
(void)Cy_CSD_ReadReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR);
@@ -1816,7 +1823,7 @@ void Cy_CapSense_CSDScanISR(void * capsenseContext)
/* Save raw count */
maxCount = (1uL << ptrActive->ptrWdContext->resolution) - 1uL;
rawData = Cy_CSD_ReadReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_RESULT_VAL1) & CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK;
-
+
if(rawData > maxCount)
{
rawData = maxCount;
@@ -1852,7 +1859,7 @@ void Cy_CapSense_CSDScanISR(void * capsenseContext)
*
* The function increments the sensor index, updates sense clock for matrix
* or touchpad widgets only, sets up Compensation IDAC, enables the sensor and
-* scans it. When all the sensors are scanned it continues to set up the next
+* scans it. When all the sensors are scanned it continues to set up the next
* widget until all the widgets are scanned.
*
* \param context
@@ -1863,7 +1870,7 @@ static void Cy_CapSense_CSDInitNextSnsScan(cy_stc_capsense_context_t * context)
{
cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
uint32_t sensorId = ptrActive->sensorIndex + 1uL;
-
+
/* Check if all the sensors are scanned in widget */
if (ptrActive->ptrWdConfig->numSns > sensorId)
{
@@ -1937,7 +1944,7 @@ __STATIC_INLINE void Cy_CapSense_CSDChangeClkFreq(uint32_t channelIndex, cy_stc_
const cy_stc_capsense_widget_context_t * ptrWdCxt = context->ptrActiveScanSns->ptrWdContext;
uint32_t snsClkDivider;
uint32_t snsClkSrc = (uint32_t)ptrWdCxt->snsClkSource & ((uint32_t)~(uint32_t)CY_CAPSENSE_CLK_SOURCE_AUTO_MASK);
- uint32_t regConfig = 0u;
+ uint32_t regValue = 0u;
uint32_t freqOffset;
uint32_t conversionsNum;
@@ -1970,7 +1977,7 @@ __STATIC_INLINE void Cy_CapSense_CSDChangeClkFreq(uint32_t channelIndex, cy_stc_
break;
}
}
-
+
if ((CY_CAPSENSE_CLK_SOURCE_PRS8 == snsClkSrc) || (CY_CAPSENSE_CLK_SOURCE_PRS12 == snsClkSrc))
{
freqOffset <<= 1uL;
@@ -1985,20 +1992,20 @@ __STATIC_INLINE void Cy_CapSense_CSDChangeClkFreq(uint32_t channelIndex, cy_stc_
/* Configuring PRS SEL_BIT and decreasing divider in case of PRS */
if ((CY_CAPSENSE_CLK_SOURCE_PRS8 == snsClkSrc) || (CY_CAPSENSE_CLK_SOURCE_PRS12 == snsClkSrc))
{
- regConfig = CY_CAPSENSE_CSD_SENSE_PERIOD_SEL_LFSR_MSB_MSK;
+ regValue = CY_CAPSENSE_CSD_SENSE_PERIOD_SEL_LFSR_MSB_MSK;
snsClkDivider >>= 1u;
}
-
+
/* Check divider value */
if (0u == snsClkDivider)
{
snsClkDivider = 1u;
}
- regConfig |= ((snsClkSrc << CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_POS) | (snsClkDivider - 1u));
-
+ regValue |= ((snsClkSrc << CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_POS) | (snsClkDivider - 1u));
+
/* Update reg value with divider and configuration */
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD, regConfig);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD, regValue);
}
#endif /* CY_IP_MXCSDV2 */
diff --git a/cy_capsense_csd.h b/cy_capsense_csd.h
index 8a84dd2..a4acbac 100644
--- a/cy_capsense_csd.h
+++ b/cy_capsense_csd.h
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_csd.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the function prototypes specific to the CSD sensing
@@ -8,7 +8,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -22,7 +22,7 @@
#include "cy_capsense_common.h"
#include "cy_capsense_structure.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
@@ -37,10 +37,6 @@ extern "C" {
#define CY_CAPSENSE_DEFAULT_SW_HS_N_SEL (0x00000000uL)
#define CY_CAPSENSE_DEFAULT_CSD_ADC_CTL (0x00000000uL)
-/* SW_FW_MOD_SEL switches states */
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SCAN (0x00000000uL)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_INIT (0x00000000uL)
-
#define CY_CAPSENSE_EXT_CAP_DISCHARGE_TIME (1u)
/***************************************
@@ -56,7 +52,7 @@ void Cy_CapSense_CSDSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * c
void Cy_CapSense_CSDSetupWidgetExt(uint32_t widgetId, uint32_t sensorId, cy_stc_capsense_context_t * context);
void Cy_CapSense_CSDScan(cy_stc_capsense_context_t * context);
void Cy_CapSense_CSDScanExt(cy_stc_capsense_context_t * context);
-void Cy_CapSense_CSDConnectSns(const cy_stc_capsense_pin_config_t * snsAddrPtr, cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSDConnectSns(const cy_stc_capsense_pin_config_t * snsAddrPtr, const cy_stc_capsense_context_t * context);
void Cy_CapSense_CSDDisconnectSns(const cy_stc_capsense_pin_config_t * snsAddrPtr, const cy_stc_capsense_context_t * context);
/** \} */
@@ -82,6 +78,8 @@ void Cy_CapSense_CSDClearSensors(const cy_stc_capsense_context_t * context);
void Cy_CapSense_CSDSetWidgetSenseClkSrc(const cy_stc_capsense_widget_config_t * ptrWdConfig);
uint32_t Cy_CapSense_CSDCalcPrsSize(uint32_t snsClkDivider, uint32_t resolution);
void Cy_CapSense_CSDScanISR(void * capsenseContext);
+void Cy_CapSense_CSDCmodPrecharge(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSDDischargeCmod(cy_stc_capsense_context_t * context);
/** \} \endcond */
diff --git a/cy_capsense_csx.c b/cy_capsense_csx.c
index 379ab8e..1f51d0d 100644
--- a/cy_capsense_csx.c
+++ b/cy_capsense_csx.c
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_csx.c
-* \version 2.0
+* \version 2.10
*
* \brief
* This file defines the data structure global variables and provides
@@ -10,7 +10,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -29,7 +29,7 @@
#include "cy_capsense_csx.h"
#include "cy_capsense_sensing.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
/*******************************************************************************
@@ -58,26 +58,26 @@ __STATIC_INLINE void Cy_CapSense_CSXStartSampleExt(cy_stc_capsense_context_t * c
* Performs hardware and firmware initialization required for the CSX operation
* of the CapSense middleware.
*
-* This function initializes hardware to perform the CSX sensing operation.
-* If both CSX and CSD sensing methods are used in the
-* middleware, this function is called by the Cy_CapSense_SetupWidget() to
-* change hardware configured for CSD sensing method to re-initialize for the
+* This function initializes hardware to perform the CSX sensing operation.
+* If both CSX and CSD sensing methods are used in the
+* middleware, this function is called by the Cy_CapSense_SetupWidget() to
+* change hardware configured for CSD sensing method to re-initialize for the
* CSX sensing method.
*
* If the CSD and CSX widgets are used in the middleware, do not
-* mix the CSD widgets between the CSX widgets. Instead, place all
-* CSX widgets in the required scanning order and then place the CSD widgets
+* mix the CSD widgets between the CSX widgets. Instead, place all
+* CSX widgets in the required scanning order and then place the CSD widgets
* in the CapSense Configurator tool.
* For the middleware, this action will eliminate the need for changing
-* the CSD HW block configuration for every widget scan and will increase the
-* execution speed in the Cy_CapSense_ScanAllWidgets() when the function is
+* the CSD HW block configuration for every widget scan and will increase the
+* execution speed in the Cy_CapSense_ScanAllWidgets() when the function is
* called.
*
* Similarly, set up and scan all the CSX widgets in such
-* a sequence that the Cy_CapSense_SetupWidget() does not need to perform
+* a sequence that the Cy_CapSense_SetupWidget() does not need to perform
* hardware sensing-configuration switches.
*
-* Do not call this function directly from
+* Do not call this function directly from
* the application program.
*
* \param context
@@ -86,59 +86,39 @@ __STATIC_INLINE void Cy_CapSense_CSXStartSampleExt(cy_stc_capsense_context_t * c
*******************************************************************************/
void Cy_CapSense_CSXInitialize(cy_stc_capsense_context_t * context)
{
- uint32_t interruptState;
- uint32_t tmpRegVal;
+ uint32_t modClkDivider;
cy_stc_capsense_fptr_config_t * ptrFptrCfg = (cy_stc_capsense_fptr_config_t *)context->ptrFptrConfig;
Cy_CapSense_DischargeExtCapacitors(context);
- interruptState = Cy_SysLib_EnterCriticalSection();
- Cy_GPIO_SetDrivemode(context->ptrCommonConfig->portCintA, (uint32_t)context->ptrCommonConfig->pinCintA, CY_GPIO_DM_ANALOG);
- Cy_GPIO_SetDrivemode(context->ptrCommonConfig->portCintB, (uint32_t)context->ptrCommonConfig->pinCintB, CY_GPIO_DM_ANALOG);
- Cy_SysLib_ExitCriticalSection(interruptState);
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA, (uint32_t)context->ptrCommonConfig->pinCintA, CY_GPIO_DM_ANALOG, CY_CAPSENSE_CSX_CINT_SCAN_PIN_HSIOM);
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB, (uint32_t)context->ptrCommonConfig->pinCintB, CY_GPIO_DM_ANALOG, CY_CAPSENSE_CSX_CINT_SCAN_PIN_HSIOM);
/* Clear all pending interrupts of the CSD HW block */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
/* Enable the End Of Scan interrupt */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR_MASK, CY_CAPSENSE_DEFAULT_CSD_INTR_MASK_CFG);
-
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR_SET, 0u);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_HSCMP, CY_CAPSENSE_DEFAULT_CSD_HSCMP_CFG);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_AMBUF, CY_CAPSENSE_DEFAULT_CSD_AMBUF_CFG);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_REFGEN, context->ptrInternalContext->csxRegRefgen );
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_AMBUF, context->ptrInternalContext->csxRegAMuxBuf);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_REFGEN, context->ptrInternalContext->csxRegRefgen);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_CSDCMP, CY_CAPSENSE_DEFAULT_CSD_CSDCMP_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IDACA, CY_CAPSENSE_DEFAULT_CSD_IDACA_CFG);
-
- if (0u != context->ptrCommonConfig->csdIdacCompEn)
- {
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IDACB, CY_CAPSENSE_DEFAULT_CSD_IDACB_CFG);
- }
-
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_RES,context->ptrInternalContext->csxRegSwResInit);
-
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IDACB, CY_CAPSENSE_DEFAULT_CSD_IDACB_CFG);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_RES, context->ptrInternalContext->csxRegSwResInit);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_DUTY, CY_CAPSENSE_DEFAULT_CSD_SENSE_DUTY_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_HS_P_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_HS_N_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_HS_N_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_SHIELD_SEL_CFG);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_AMUXBUF_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_AMUXBUF_SEL_CFG);
-
- tmpRegVal = Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_BYP_SEL);
- tmpRegVal &= ~(CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK);
- tmpRegVal |= CY_CAPSENSE_DEFAULT_CSD_SW_BYP_SEL_CFG;
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_BYP_SEL, tmpRegVal);
-
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_AMUXBUF_SEL, context->ptrInternalContext->csxRegRefgenSel);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_BYP_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_BYP_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_CMP_P_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_CMP_P_SEL_CFG);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_CMP_N_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_CMP_N_SEL_CFG);
-
- tmpRegVal = Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL);
- tmpRegVal &= ~CY_CAPSENSE_DEFAULT_CSD_SW_REFGEN_SEL_MSK;
- tmpRegVal |= context->ptrInternalContext->regSwRefGenSel ;
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, tmpRegVal);
-
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_CMP_N_SEL, context->ptrInternalContext->csxRegSwCmpNSel);
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, context->ptrInternalContext->csxRegSwRefGenSel);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_FW_MOD_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_FW_TANK_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_DSI_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL_CFG);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IO_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_IO_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_TIME, 0u);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_INIT_CNT, (uint32_t)context->ptrCommonConfig->csxFineInitTime);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_NORM_CNT, CY_CAPSENSE_DEFAULT_CSD_SEQ_NORM_CNT_CFG);
@@ -146,10 +126,20 @@ void Cy_CapSense_CSXInitialize(cy_stc_capsense_context_t * context)
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_DEFAULT_CSD_SEQ_START_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_CONFIG, context->ptrInternalContext->csxRegConfigInit);
- Cy_CapSense_SetClkDivider((uint32_t)context->ptrCommonContext->modCsxClk - 1u, context);
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IO_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_IO_SEL_CFG);
+ #endif
+
+ modClkDivider = (uint32_t)context->ptrCommonContext->modCsxClk;
+ if(0u == modClkDivider)
+ {
+ modClkDivider = 1u;
+ }
+
+ Cy_CapSense_SetClkDivider(modClkDivider - 1u, context);
/* Set all IO states to the default state */
- Cy_CapSense_SetIOsInDefaultState(context);
+ Cy_CapSense_SetIOsInDesiredState(CY_GPIO_DM_STRONG_IN_OFF, 0u, CY_CAPSENSE_HSIOM_SEL_GPIO, context);
/* Enable the CSD HW block interrupt and set interrupt vector to CSX sensing method */
if(NULL != ptrFptrCfg->fptrCSXScanISR)
@@ -194,6 +184,7 @@ void Cy_CapSense_CSXElectrodeCheck(cy_stc_capsense_context_t * context)
*
* To disable CSX mode, the following tasks are performed:
* 1. Disconnect previous CSX electrode if it has been connected.
+* 2. Disconnect the external capacitors (CintA and CintB).
*
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
@@ -203,6 +194,10 @@ void Cy_CapSense_CSXDisableMode(cy_stc_capsense_context_t * context)
{
/* Disconnect previous CSX electrode if it has been connected */
Cy_CapSense_CSXElectrodeCheck(context);
+
+ /* Disconnect the external capacitors (CintA and CintB) */
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA, (uint32_t)context->ptrCommonConfig->pinCintA, CY_GPIO_DM_ANALOG, HSIOM_SEL_GPIO);
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB, (uint32_t)context->ptrCommonConfig->pinCintB, CY_GPIO_DM_ANALOG, HSIOM_SEL_GPIO);
}
@@ -212,10 +207,10 @@ void Cy_CapSense_CSXDisableMode(cy_stc_capsense_context_t * context)
*
* Performs the initialization required to scan the specified CSX widget.
*
-* \note This function is obsolete and kept for backward compatibility only.
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_SetupWidget() function should be used instead.
*
-* This function prepares the middleware to scan all the sensors in the
+* This function prepares the middleware to scan all the sensors in the
* specified CSX widget by executing the following tasks:
* 1. Configure the CSD HW block if it is not configured to perform the
* CSX sensing method used by the specified widget.
@@ -227,17 +222,17 @@ void Cy_CapSense_CSXDisableMode(cy_stc_capsense_context_t * context)
*
* This function does not start sensor scanning. The Cy_CapSense_CSXScan()
* function must be called to start the scan sensors in the widget. If this
-* function is called more than once, it does not break the middleware
+* function is called more than once, it does not break the middleware
* operation, but only the last initialized widget is in effect.
* Calling this function directly from the application program is not
* recommended. This function is used to implement only the user's specific
* use cases (for example faster execution).
*
-* The status of a sensor scan must be checked using the Cy_CapSense_IsBusy()
+* The status of a sensor scan must be checked using the Cy_CapSense_IsBusy()
* function prior to starting a next scan or setting up another widget.
-*
+*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param context
@@ -251,7 +246,7 @@ void Cy_CapSense_CSXSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * c
uint32_t snsClkSrc;
uint32_t tmpRegVal;
- Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E, context);
+ (void)Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E, context);
/*
* Check whether CSX electrodes were previously connected using
* Cy_CapSense_CSXSetupWidgetExt and if yes, disconnect them
@@ -260,14 +255,14 @@ void Cy_CapSense_CSXSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * c
/* Set up widget and its first sensor IDs and pointers to have assess to them after scanning */
Cy_CapSense_InitActivePtr(widgetId, 0u, context);
/* Number of conversion and maxRawCount setup */
- tmpRegVal = (uint32_t)context->ptrActiveScanSns->ptrWdContext->resolution;
+ tmpRegVal = (uint32_t)context->ptrActiveScanSns->ptrWdContext->resolution;
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_NORM_CNT, tmpRegVal);
- context->ptrActiveScanSns->ptrWdContext->maxRawCount = (uint16_t)tmpRegVal *
+ context->ptrActiveScanSns->ptrWdContext->maxRawCount = (uint16_t)tmpRegVal *
(context->ptrActiveScanSns->ptrWdContext->snsClk - CY_CAPSENSE_CSX_DEADBAND_CYCLES_NUMBER);
/* SnsClk setup */
snsClkDivider = (uint32_t) context->ptrActiveScanSns->ptrWdContext->snsClk;
-
+
/* Check divider value */
if (0u == snsClkDivider)
{
@@ -284,35 +279,35 @@ void Cy_CapSense_CSXSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * c
* Function Name: Cy_CapSense_CSXSetupWidgetExt
****************************************************************************//**
*
-* Performs extended initialization required to scan a specified sensor in
+* Performs extended initialization required to scan a specified sensor in
* a widget using CSX sensing method.
-*
-* \note This function is obsolete and kept for backward compatibility only.
+*
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_SetupWidgetExt() function should be used instead.
*
-* This function performs the same tasks of Cy_CapSense_CSXSetupWidget() and
-* also connects and configures specified sensor for scan. Hence this
-* function, along with Cy_CapSense_CSXScanExt() function, can be used to
+* This function performs the same tasks of Cy_CapSense_CSXSetupWidget() and
+* also connects and configures specified sensor for scan. Hence this
+* function, along with Cy_CapSense_CSXScanExt() function, can be used to
* scan a specific sensor in the widget.
-*
-* This function should be called for a widget that is configured to use
-* CSX sensing method. Using this function on a non-CSX sensing widget
+*
+* This function should be called for a widget that is configured to use
+* CSX sensing method. Using this function on a non-CSX sensing widget
* would cause an unexpected result.
-*
-* This function requires using the Cy_CapSense_CSXScanExt() function to
+*
+* This function requires using the Cy_CapSense_CSXScanExt() function to
* initiate a scan.
-*
-* Calling this function directly from the application program is not
-* recommended. This function is used to implement only the user's
+*
+* Calling this function directly from the application program is not
+* recommended. This function is used to implement only the user's
* specific use cases (for example faster execution).
-*
+*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param sensorId
-* Specifies the ID number of the sensor within the widget. A macro for the
-* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE__SNS_ID.
*
* \param context
@@ -320,8 +315,8 @@ void Cy_CapSense_CSXSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * c
*
*******************************************************************************/
void Cy_CapSense_CSXSetupWidgetExt(
- uint32_t widgetId,
- uint32_t sensorId,
+ uint32_t widgetId,
+ uint32_t sensorId,
cy_stc_capsense_context_t * context)
{
/* Initialize widget */
@@ -330,8 +325,10 @@ void Cy_CapSense_CSXSetupWidgetExt(
/* Initialize sensor data structure pointer to appropriate address */
Cy_CapSense_InitActivePtrSns(sensorId, context);
- /* Connect current sensor`s Tx and Rx IOs for scan
- * and set flag to indicate that IOs should be disconnected */
+ /*
+ * Connect current sensor's Tx and Rx IOs for scan and set flag
+ * to indicate that IOs should be disconnected
+ */
Cy_CapSense_CSXConnectTxExt(context);
Cy_CapSense_CSXConnectRxExt(context);
}
@@ -340,10 +337,10 @@ void Cy_CapSense_CSXSetupWidgetExt(
* Function Name: Cy_CapSense_CSXScan
****************************************************************************//**
*
-* This function initiates a scan for the sensors of the widget initialized
+* This function initiates a scan for the sensors of the widget initialized
* by the Cy_CapSense_CSXSetupWidget() function.
*
-* \note This function is obsolete and kept for backward compatibility only.
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_Scan() function should be used instead.
*
* This function does the following tasks:
@@ -370,7 +367,7 @@ void Cy_CapSense_CSXSetupWidgetExt(
void Cy_CapSense_CSXScan(cy_stc_capsense_context_t * context)
{
Cy_CapSense_InitActivePtrSns(0u, context);
-
+
/* Connect electrodes */
Cy_CapSense_CSXConnectTxExt(context);
Cy_CapSense_CSXConnectRxExt(context);
@@ -387,30 +384,30 @@ void Cy_CapSense_CSXScan(cy_stc_capsense_context_t * context)
* Function Name: Cy_CapSense_CSXScanExt()
****************************************************************************//**
*
-* Starts the CSD conversion on the preconfigured sensor.
-*
-* \note This function is obsolete and kept for backward compatibility only.
+* Starts the CSD conversion on the preconfigured sensor.
+*
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_ScanExt() function should be used instead.
*
-* This function performs scanning of a specific sensor in the widget
-* previously initialized using the Cy_CapSense_CSXSetupWidgetExt() function.
-*
-* This function is called when no scanning is in progress.
-* I.e. Cy_CapSense_IsBusy() returns a non-busy status and the widget must
-* be preconfigured using Cy_CapSense_CSXSetupWidgetExt() function prior
-* to calling this function. Calling this function directly from
-* the application program is not recommended. This function is used to
+* This function performs scanning of a specific sensor in the widget
+* previously initialized using the Cy_CapSense_CSXSetupWidgetExt() function.
+*
+* This function is called when no scanning is in progress.
+* I.e. Cy_CapSense_IsBusy() returns a non-busy status and the widget must
+* be preconfigured using Cy_CapSense_CSXSetupWidgetExt() function prior
+* to calling this function. Calling this function directly from
+* the application program is not recommended. This function is used to
* implement only the user's specific use cases (for example faster execution).
-*
-* This function does not disconnect sensor GPIOs from CSD HW block at the
-* end of a scan, therefore making subsequent scan of the same sensor is faster.
-* If sensor must be disconnected after the scan,
+*
+* This function does not disconnect sensor GPIOs from CSD HW block at the
+* end of a scan, therefore making subsequent scan of the same sensor is faster.
+* If sensor must be disconnected after the scan,
* the Cy_CapSense_CSXDisconnectTx() or Cy_CapSense_CSXDisconnectRx() functions
* can be used.
-*
-* Calling Cy_CapSense_SetupWidget(), Cy_CapSense_CSXSetupWidget(),
-* Cy_CapSense_ScanAllWidgets(), or if Cy_CapSense_RunTuner() returns
-* CY_CAPSENSE_STATUS_RESTART_DONE status invalidated initialization
+*
+* Calling Cy_CapSense_SetupWidget(), Cy_CapSense_CSXSetupWidget(),
+* Cy_CapSense_ScanAllWidgets(), or if Cy_CapSense_RunTuner() returns
+* CY_CAPSENSE_STATUS_RESTART_DONE status invalidated initialization
* made by this function.
*
* \param context
@@ -426,7 +423,7 @@ void Cy_CapSense_CSXScanExt(cy_stc_capsense_context_t * context)
/* Initialize the Active Context pointer with the CH0 context */
ptrActive->ptrSnsContext = &ptrActive->ptrWdConfig->ptrSnsContext[ptrActive->sensorIndex];
-
+
/* Set busy flag and start conversion */
Cy_CapSense_SetBusyFlags(context);
/* Set scope flag */
@@ -443,22 +440,22 @@ void Cy_CapSense_CSXScanExt(cy_stc_capsense_context_t * context)
* Executes the IDAC calibration for all the sensors in the widget specified in
* the input.
*
-* \note This function is obsolete and kept for backward compatibility only.
+* \note This function is obsolete and kept for backward compatibility only.
* The Cy_CapSense_CalibrateWidget() function should be used instead.
*
* Performs a successive approximation search algorithm to find appropriate
-* IDAC values for all sensors in the specified widget that provide
+* IDAC values for all sensors in the specified widget that provide
* the raw count to the level specified by the target parameter.
*
-* Calibration returns CYRET_BAD_DATA if the achieved raw count is outside
+* Calibration returns CY_RET_BAD_DATA if the achieved raw count is outside
* of the range specified by the target and acceptable calibration deviation
* parameters.
*
* This function could be used when the CSX Enable IDAC auto-calibration
-* parameter is enabled.
+* parameter is enabled.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param target
@@ -469,17 +466,17 @@ void Cy_CapSense_CSXScanExt(cy_stc_capsense_context_t * context)
*
* \return
* Returns the status of the specified widget calibration:
-* - CYRET_SUCCESS - The operation is successfully completed.
-* - CYRET_BAD_PARAM - The input parameter is invalid.
-* - CYRET_BAD_DATA - The calibration failed and CapSense may not operate
+* - CY_RET_SUCCESS - The operation is successfully completed.
+* - CY_RET_BAD_PARAM - The input parameter is invalid.
+* - CY_RET_BAD_DATA - The calibration failed and CapSense may not operate
* as expected.
-* - CYRET_INVALID_STATE - The previous scanning is not completed, and
+* - CY_RET_INVALID_STATE - The previous scanning is not completed, and
* the CapSense middleware is busy.
*
*******************************************************************************/
cy_status Cy_CapSense_CSXCalibrateWidget(
- uint32_t widgetId,
- uint32_t target,
+ uint32_t widgetId,
+ uint32_t target,
cy_stc_capsense_context_t * context)
{
uint32_t cpuFreqMHz;
@@ -494,21 +491,23 @@ cy_status Cy_CapSense_CSXCalibrateWidget(
uint32_t rawTarget;
uint32_t totalSns;
+ uint32_t modClkDivider;
+ uint32_t snsClkDivider;
uint32_t calibrationIndex;
/* Currently used IDAC-bit */
uint8_t curIdacMask = CY_CAPSENSE_CAL_MIDDLE_VALUE;
/* Next used IDAC-bit */
- uint8_t nextIdacMask = (curIdacMask >> 1u);
+ uint8_t nextIdacMask = ((uint8_t)CY_CAPSENSE_CAL_MIDDLE_VALUE) >> 1u;
/* Approximate duration of Wait For Init loop */
- const uint32_t isBusyLoopDuration = 5uL;
+ const uint32_t isBusyLoopDuration = 5u;
/* Wait For Init watchdog timeout in microseconds */
- const uint32_t isBusyWatchdogTimeUs = 200000uL;
+ uint64_t isBusyWatchdogTimeUs = 0u;
if((context->ptrCommonConfig->numWd <= widgetId) ||
- (CY_CAPSENSE_DISABLE == context->ptrCommonConfig->csxIdacAutocalEn))
+ (CY_CAPSENSE_DISABLE == context->ptrCommonConfig->csxIdacAutocalEn))
{
calibrateStatus = CY_RET_BAD_PARAM;
}
@@ -521,7 +520,7 @@ cy_status Cy_CapSense_CSXCalibrateWidget(
if(CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
{
/* Previous widget is being scanned, return error */
- calibrateStatus = CYRET_INVALID_STATE;
+ calibrateStatus = CY_RET_INVALID_STATE;
}
if(CY_RET_SUCCESS == calibrateStatus)
@@ -531,7 +530,7 @@ cy_status Cy_CapSense_CSXCalibrateWidget(
ptrActSnsContext = ptrWdCfg->ptrSnsContext;
totalSns = ptrWdCfg->numSns;
-
+
/* Calculate target raw count */
rawTarget = ((uint32_t)context->ptrWdContext[widgetId].maxRawCount * target) / CY_CAPSENSE_PERCENTAGE_100;
freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
@@ -545,6 +544,44 @@ cy_status Cy_CapSense_CSXCalibrateWidget(
ptrActSnsContext[calibrationIndex + (freqChIndex * context->ptrCommonConfig->numSns)].idacComp = curIdacMask;
}
}
+
+ modClkDivider = (uint32_t)context->ptrCommonContext->modCsxClk;
+ snsClkDivider = (uint32_t)ptrWdCfg->ptrWdContext->snsClk;
+
+ if(0u == modClkDivider)
+ {
+ modClkDivider = 1u;
+ }
+
+ if(0u == snsClkDivider)
+ {
+ snsClkDivider = 1u;
+ }
+
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn)
+ {
+ if(context->ptrCommonConfig->csxMfsDividerOffsetF1 >
+ context->ptrCommonConfig->csxMfsDividerOffsetF2)
+ {
+ snsClkDivider += context->ptrCommonConfig->csxMfsDividerOffsetF1;
+ }
+ else
+ {
+ snsClkDivider += context->ptrCommonConfig->csxMfsDividerOffsetF2;
+ }
+ }
+
+ isBusyWatchdogTimeUs = (uint64_t)totalSns * freqChNumber * ptrWdCfg->ptrWdContext->resolution;
+ isBusyWatchdogTimeUs *= (uint64_t)snsClkDivider * modClkDivider * CY_CAPSENSE_CONVERSION_MEGA;
+ isBusyWatchdogTimeUs /= context->ptrCommonConfig->periClkHz;
+
+ if(0uL == isBusyWatchdogTimeUs)
+ {
+ isBusyWatchdogTimeUs = 1u;
+ }
+
+ isBusyWatchdogTimeUs *= CY_CAPSENSE_CSX_WATCHDOG_MARGIN_COEFF;
+
/* Perform binary search for accurate IDAC value for each sensor/node */
do
{
@@ -553,8 +590,8 @@ cy_status Cy_CapSense_CSXCalibrateWidget(
(void)Cy_CapSense_Scan(context);
cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
- watchdogCounter = Cy_CapSense_WatchdogCyclesNum(isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
-
+ watchdogCounter = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
/* Wait for EOS */
while (CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
{
@@ -562,10 +599,10 @@ cy_status Cy_CapSense_CSXCalibrateWidget(
{
break;
}
-
+
watchdogCounter--;
}
-
+
/* Set pointer to the widget's first sensor data */
ptrActSnsContext = ptrWdCfg->ptrSnsContext;
@@ -601,8 +638,8 @@ cy_status Cy_CapSense_CSXCalibrateWidget(
(void)Cy_CapSense_Scan(context);
cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
- watchdogCounter = Cy_CapSense_WatchdogCyclesNum(isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
-
+ watchdogCounter = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
/* Wait for EOS */
while (CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
{
@@ -611,11 +648,14 @@ cy_status Cy_CapSense_CSXCalibrateWidget(
calibrateStatus = CY_RET_TIMEOUT;
break;
}
-
+
watchdogCounter--;
}
- calibrateStatus = Cy_CapSense_CalibrateCheck(widgetId, target, (uint32_t)CY_CAPSENSE_SENSE_METHOD_CSX_E, context);
+ if(CY_RET_SUCCESS == calibrateStatus)
+ {
+ calibrateStatus = Cy_CapSense_CalibrateCheck(widgetId, target, (uint32_t)CY_CAPSENSE_SENSE_METHOD_CSX_E, context);
+ }
}
return(calibrateStatus);
@@ -659,14 +699,14 @@ static void Cy_CapSense_CSXStartSample(cy_stc_capsense_context_t * context)
{
/* Set up IDAC Value */
Cy_CapSense_CSXSetUpIdacs(context);
-
+
/* Clear previous interrupts */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
(void)Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR);
/* Enable interrupt */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR_MASK, CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK);
-
+
if(NULL != context->ptrCommonContext->ptrSSCallback)
{
context->ptrCommonContext->ptrSSCallback(context->ptrActiveScanSns);
@@ -681,24 +721,24 @@ static void Cy_CapSense_CSXStartSample(cy_stc_capsense_context_t * context)
****************************************************************************//**
*
* Connects port pin (an Rx electrode) to the CSD HW block using AMUX bus.
-*
-* This function can be used to customize the default sensor connection
+*
+* This function can be used to customize the default sensor connection
* by connecting one or more pins to an existing sensor as an Rx electrode
* prior to initiating scan of the sensor.
-*
-* The function ignores whether the sensor is a ganged sensor and
-* connects only a specified port pin to the CSD HW block. This function can
+*
+* The function ignores whether the sensor is a ganged sensor and
+* connects only a specified port pin to the CSD HW block. This function can
* only use GPIOs that is already assigned to CapSense middleware.
-*
-* The functions that perform a setup and scan of a sensor/widget do not
-* take into account changes in the design made by
-* the Cy_CapSense_CSXConnectRx() function. Hence all GPIOs connected
-* using this function must be disconnected using
-* the Cy_CapSense_CSXDisconnectRx() function prior to initializing
-* new widgets. Use this function in StartSample
-* callback (see the \ref group_capsense_callbacks section for details)
+*
+* The functions that perform a setup and scan of a sensor/widget do not
+* take into account changes in the design made by
+* the Cy_CapSense_CSXConnectRx() function. Hence all GPIOs connected
+* using this function must be disconnected using
+* the Cy_CapSense_CSXDisconnectRx() function prior to initializing
+* new widgets. Use this function in StartSample
+* callback (see the \ref group_capsense_callbacks section for details)
* or with low-level functions that perform a single-sensor scanning.
-*
+*
* Scanning should be completed before calling this function.
*
* \param rxPtr
@@ -709,15 +749,16 @@ static void Cy_CapSense_CSXStartSample(cy_stc_capsense_context_t * context)
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
* \funcusage
-*
-* An example of using the function to perform port pin re-connection:
+*
+* An example of using the function to perform port pin re-connection:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_CSXConnect
-*
+*
*******************************************************************************/
void Cy_CapSense_CSXConnectRx(
- const cy_stc_capsense_pin_config_t * rxPtr,
- cy_stc_capsense_context_t * context)
+ const cy_stc_capsense_pin_config_t * rxPtr,
+ const cy_stc_capsense_context_t * context)
{
+ (void) context;
Cy_CapSense_SsConfigPinRegisters(rxPtr->pcPtr, (uint32_t)rxPtr->pinNumber, CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
}
@@ -727,24 +768,24 @@ void Cy_CapSense_CSXConnectRx(
****************************************************************************//**
*
* Connects port pin (a Tx electrode) to the CSD HW block.
-*
-* This function can be used to customize the default sensor connection
+*
+* This function can be used to customize the default sensor connection
* by connecting one or more pins to an existing sensor as a Tx electrode
* prior to initiating scan of the sensor.
-*
-* The function ignores whether the sensor is a ganged sensor and
-* connects only a specified port pin to the CSD HW block. This function can
+*
+* The function ignores whether the sensor is a ganged sensor and
+* connects only a specified port pin to the CSD HW block. This function can
* only use GPIOs that is already assigned to CapSense middleware.
-*
-* The functions that perform a setup and scan of a sensor/widget do not
-* take into account changes in the design made by
-* the Cy_CapSense_CSXConnectTx() function. Hence all GPIOs connected
-* using this function must be disconnected using
-* the Cy_CapSense_CSXDisconnectTx() function prior to initializing
-* new widgets. Use this function in StartSample
-* callback (see the \ref group_capsense_callbacks section for details)
+*
+* The functions that perform a setup and scan of a sensor/widget do not
+* take into account changes in the design made by
+* the Cy_CapSense_CSXConnectTx() function. Hence all GPIOs connected
+* using this function must be disconnected using
+* the Cy_CapSense_CSXDisconnectTx() function prior to initializing
+* new widgets. Use this function in StartSample
+* callback (see the \ref group_capsense_callbacks section for details)
* or with low-level functions that perform a single-sensor scanning.
-*
+*
* Scanning should be completed before calling this function.
*
* \param txPtr
@@ -755,33 +796,34 @@ void Cy_CapSense_CSXConnectRx(
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
* \funcusage
-*
-* An example of using the function to perform port pin re-connection:
+*
+* An example of using the function to perform port pin re-connection:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_CSXConnect
-*
+*
*******************************************************************************/
void Cy_CapSense_CSXConnectTx(
- const cy_stc_capsense_pin_config_t * txPtr,
- cy_stc_capsense_context_t * context)
+ const cy_stc_capsense_pin_config_t * txPtr,
+ const cy_stc_capsense_context_t * context)
{
- Cy_CapSense_SsConfigPinRegisters(txPtr->pcPtr, (uint32_t)txPtr->pinNumber, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD);
+ (void) context;
+ Cy_CapSense_SsConfigPinRegisters(txPtr->pcPtr, (uint32_t)txPtr->pinNumber, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_CSX_TX_SCAN_PIN_HSIOM);
}
/*******************************************************************************
* Function Name: Cy_CapSense_CSXDisconnectRx
****************************************************************************//**
-*
-* Disconnects port pin (an Rx electrode) from the CSD HW block by disconnecting
+*
+* Disconnects port pin (an Rx electrode) from the CSD HW block by disconnecting
* it from the AMUX bus.
-*
-* This function can be used to disconnect a sensor connected
-* using the Cy_CapSense_CSXConnectRx() function. In addition, this
-* function can be used to customize default sensor connection by
-* disconnecting one or more already connected sensors prior to
+*
+* This function can be used to disconnect a sensor connected
+* using the Cy_CapSense_CSXConnectRx() function. In addition, this
+* function can be used to customize default sensor connection by
+* disconnecting one or more already connected sensors prior to
* initiating scan of the sensor.
-*
-* This function works identically to the Cy_CapSense_CSDConnectRx() function
+*
+* This function works identically to the Cy_CapSense_CSDConnectRx() function
* except it disconnects the specified port pin used by the sensor.
*
* Scanning should be completed before calling this function.
@@ -794,38 +836,34 @@ void Cy_CapSense_CSXConnectTx(
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
* \funcusage
-*
-* An example of using the function to perform port pin re-connection:
+*
+* An example of using the function to perform port pin re-connection:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_CSXConnect
-*
+*
*******************************************************************************/
void Cy_CapSense_CSXDisconnectRx(
- const cy_stc_capsense_pin_config_t * rxPtr,
- cy_stc_capsense_context_t * context)
+ const cy_stc_capsense_pin_config_t * rxPtr,
+ const cy_stc_capsense_context_t * context)
{
- uint32_t interruptState;
-
+ (void) context;
Cy_CapSense_SsConfigPinRegisters(rxPtr->pcPtr, (uint32_t)rxPtr->pinNumber, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
-
- interruptState = Cy_SysLib_EnterCriticalSection();
Cy_GPIO_Clr(rxPtr->pcPtr, (uint32_t)rxPtr->pinNumber);
- Cy_SysLib_ExitCriticalSection(interruptState);
}
/*******************************************************************************
* Function Name: Cy_CapSense_CSXDisconnectTx
****************************************************************************//**
-*
+*
* Disconnects port pin (a Tx electrode) from the CSD HW block.
-*
-* This function can be used to disconnect a sensor connected
-* using the Cy_CapSense_CSXConnectTx() function. In addition, this
-* function can be used to customize default sensor connection by
-* disconnecting one or more already connected sensors prior to
+*
+* This function can be used to disconnect a sensor connected
+* using the Cy_CapSense_CSXConnectTx() function. In addition, this
+* function can be used to customize default sensor connection by
+* disconnecting one or more already connected sensors prior to
* initiating scan of the sensor.
-*
-* This function works identically to the Cy_CapSense_CSDConnectTx() function
+*
+* This function works identically to the Cy_CapSense_CSDConnectTx() function
* except it disconnects the specified port pin used by the sensor.
*
* Scanning should be completed before calling this function.
@@ -838,16 +876,18 @@ void Cy_CapSense_CSXDisconnectRx(
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
* \funcusage
-*
-* An example of using the function to perform port pin re-connection:
+*
+* An example of using the function to perform port pin re-connection:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_CSXConnect
-*
+*
*******************************************************************************/
void Cy_CapSense_CSXDisconnectTx(
- const cy_stc_capsense_pin_config_t * txPtr,
- cy_stc_capsense_context_t * context)
+ const cy_stc_capsense_pin_config_t * txPtr,
+ const cy_stc_capsense_context_t * context)
{
+ (void) context;
Cy_CapSense_SsConfigPinRegisters(txPtr->pcPtr, (uint32_t)txPtr->pinNumber, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
+
Cy_GPIO_Clr(txPtr->pcPtr, (uint32_t)txPtr->pinNumber);
}
@@ -875,7 +915,7 @@ void Cy_CapSense_CSXConnectTxExt(cy_stc_capsense_context_t * context)
{
uint32_t pinIndex;
const cy_stc_capsense_pin_config_t * pinPointer = context->ptrActiveScanSns->ptrTxConfig->ptrPin;
-
+
for (pinIndex = context->ptrActiveScanSns->ptrTxConfig->numPins; pinIndex-- > 0u;)
{
Cy_CapSense_CSXConnectTx(pinPointer, context);
@@ -908,7 +948,7 @@ void Cy_CapSense_CSXConnectRxExt(cy_stc_capsense_context_t * context)
{
uint32_t pinIndex;
const cy_stc_capsense_pin_config_t * pinPointer = context->ptrActiveScanSns->ptrRxConfig->ptrPin;
-
+
for (pinIndex = context->ptrActiveScanSns->ptrRxConfig->numPins; pinIndex-- > 0u;)
{
Cy_CapSense_CSXConnectRx(pinPointer, context);
@@ -937,11 +977,11 @@ void Cy_CapSense_CSXConnectRxExt(cy_stc_capsense_context_t * context)
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
*******************************************************************************/
-void Cy_CapSense_CSXDisconnectTxExt(cy_stc_capsense_context_t * context)
+void Cy_CapSense_CSXDisconnectTxExt(const cy_stc_capsense_context_t * context)
{
uint32_t pinIndex;
const cy_stc_capsense_pin_config_t * pinPointer = context->ptrActiveScanSns->ptrTxConfig->ptrPin;
-
+
for (pinIndex = context->ptrActiveScanSns->ptrTxConfig->numPins; pinIndex-- > 0u;)
{
Cy_CapSense_CSXDisconnectTx(pinPointer, context);
@@ -969,11 +1009,11 @@ void Cy_CapSense_CSXDisconnectTxExt(cy_stc_capsense_context_t * context)
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
*******************************************************************************/
-void Cy_CapSense_CSXDisconnectRxExt(cy_stc_capsense_context_t * context)
+void Cy_CapSense_CSXDisconnectRxExt(const cy_stc_capsense_context_t * context)
{
uint32_t pinIndex;
const cy_stc_capsense_pin_config_t * pinPointer = context->ptrActiveScanSns->ptrRxConfig->ptrPin;
-
+
for (pinIndex = context->ptrActiveScanSns->ptrRxConfig->numPins; pinIndex-- > 0u;)
{
Cy_CapSense_CSXDisconnectRx(pinPointer, context);
@@ -1028,15 +1068,15 @@ void Cy_CapSense_CSXScanISR(void * capsenseContext)
{
uint32_t tmpRawCount;
cy_stc_capsense_context_t * cxt = (cy_stc_capsense_context_t *)capsenseContext;
- cy_stc_active_scan_sns_t * ptrActive = cxt->ptrActiveScanSns;
+ cy_stc_active_scan_sns_t * ptrActive = cxt->ptrActiveScanSns;
uint32_t maxCount = (uint32_t) ptrActive->ptrWdContext->maxRawCount;
Cy_CSD_WriteReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR_MASK, CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK);
-
+
/* Clear all pending interrupts of the CSD HW block */
Cy_CSD_WriteReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
(void)Cy_CSD_ReadReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR);
-
+
tmpRawCount = (uint16_t)(Cy_CSD_ReadReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_RESULT_VAL1) &
CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK);
@@ -1064,21 +1104,20 @@ void Cy_CapSense_CSXScanISR(void * capsenseContext)
Cy_CapSense_ClrBusyFlags(cxt);
}
else
- {
+ {
/* Disconnect Tx electrodes of previously scanned sensor as preparation for next sensor scan */
Cy_CapSense_CSXDisconnectTxExt(cxt);
/* Scan the next sensor */
Cy_CapSense_CSXInitNextScan(cxt);
}
-
+
if(CY_CAPSENSE_NOT_BUSY == (cxt->ptrCommonContext->status & CY_CAPSENSE_BUSY))
{
Cy_CSD_WriteReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_CONFIG, cxt->ptrInternalContext->csxRegConfigInit);
Cy_CSD_WriteReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_CSDCMP, CY_CAPSENSE_DEFAULT_CSD_CSDCMP_CFG);
Cy_CSD_WriteReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IDACA, CY_CAPSENSE_DEFAULT_CSD_IDACA_CFG);
- Cy_CSD_WriteReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IO_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_IO_SEL_CFG);
}
-
+
/* Clear previous interrupts */
Cy_CSD_WriteReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
(void)Cy_CSD_ReadReg(cxt->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR);
@@ -1097,7 +1136,7 @@ void Cy_CapSense_CSXScanISR(void * capsenseContext)
*
* The function increments the sensor index, updates sense clock for matrix
* or touchpad widgets only, sets up Compensation IDAC, enables the sensor and
-* scans it. When all the sensors are scanned it continues to set up the next
+* scans it. When all the sensors are scanned it continues to set up the next
* widget until all the widgets are scanned.
*
* \param context
@@ -1107,16 +1146,16 @@ void Cy_CapSense_CSXScanISR(void * capsenseContext)
static void Cy_CapSense_CSXInitNextScan(cy_stc_capsense_context_t * context)
{
cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
-
+
ptrActive->mfsChannelIndex = 0u;
ptrActive->ptrSnsContext = &ptrActive->ptrWdConfig->ptrSnsContext[ptrActive->sensorIndex];
-
+
/* Increment sensor index and sensor's context pointer to scope next sensor in widget */
ptrActive->sensorIndex++;
ptrActive->ptrSnsContext++;
/* Initiate scan for next sensor in widget, if all the sensors in widget are not scanned */
ptrActive->txIndex--;
-
+
if (ptrActive->txIndex > 0u)
{
/* Increment pointer to the next Tx electrode and connect it for scan */
@@ -1189,8 +1228,7 @@ __STATIC_INLINE void Cy_CapSense_CSXStartSampleExt(cy_stc_capsense_context_t * c
const uint32_t intrInitLoopDuration = 5uL;
/* Wait For Init watchdog timeout in microseconds */
- const uint32_t initWatchdogTimeUs = 200000uL;
-
+ const uint32_t initWatchdogTimeUs = CY_CAPSENSE_CSX_PRECHARGE_WATCHDOG_TIME_US;
/* Configure the HW sequencer to perform the coarse initialization. */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_CONFIG, context->ptrInternalContext->csxRegConfigInit);
@@ -1201,15 +1239,13 @@ __STATIC_INLINE void Cy_CapSense_CSXStartSampleExt(cy_stc_capsense_context_t * c
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, CY_CAPSENSE_PRECHARGE_CSD_SW_SHIELD_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, CY_CAPSENSE_PRECHARGE_CSD_SW_FW_MOD_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, CY_CAPSENSE_PRECHARGE_CSD_SW_FW_TANK_SEL_CFG);
-
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_RES, context->ptrInternalContext->csxRegSwResPrech);
-
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_PRECHARGE_CSD_SEQ_START_CFG);
/* Init Watchdog Counter to prevent a hang */
cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
watchdogCounter = Cy_CapSense_WatchdogCyclesNum(initWatchdogTimeUs, cpuFreqMHz, intrInitLoopDuration);
-
+
/* Approximate duration of Wait For Init loop */
while((0u != (CY_CAPSENSE_CSD_SEQ_START_START_MSK &
Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START))))
@@ -1239,9 +1275,7 @@ __STATIC_INLINE void Cy_CapSense_CSXStartSampleExt(cy_stc_capsense_context_t * c
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_SHIELD_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_FW_MOD_SEL_CFG);
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, CY_CAPSENSE_DEFAULT_CSD_SW_FW_TANK_SEL_CFG);
-
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SW_RES, context->ptrInternalContext->csxRegSwResScan);
- Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IO_SEL, CY_CAPSENSE_SCAN_CSD_SW_IO_SEL_CFG);
/* Clear all pending interrupts of the CSD HW block */
Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
@@ -1265,7 +1299,7 @@ __STATIC_INLINE void Cy_CapSense_CSXStartSampleExt(cy_stc_capsense_context_t * c
static void Cy_CapSense_CSXInitNextChScan(cy_stc_capsense_context_t * context)
{
cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
-
+
ptrActive->mfsChannelIndex++;
ptrActive->ptrSnsContext += context->ptrCommonConfig->numSns;
@@ -1293,10 +1327,10 @@ static void Cy_CapSense_CSXChangeClkFreq(uint32_t channelIndex, cy_stc_capsense_
{
uint32_t tmpRegVal;
uint32_t snsClkDivider;
-
+
/* SnsClk setup */
snsClkDivider = (uint32_t) context->ptrActiveScanSns->ptrWdContext->snsClk;
-
+
/* Check divider value */
if (0u == snsClkDivider)
{
@@ -1321,7 +1355,7 @@ static void Cy_CapSense_CSXChangeClkFreq(uint32_t channelIndex, cy_stc_capsense_
break;
}
}
-
+
tmpRegVal = (uint32_t)context->ptrActiveScanSns->ptrWdContext->snsClkSource & (uint32_t)~((uint32_t)CY_CAPSENSE_CLK_SOURCE_AUTO_MASK);
tmpRegVal = ((tmpRegVal << CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_POS) | (snsClkDivider - 1u) |
CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_CLEAR_MSK | CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_BITS_MSK);
diff --git a/cy_capsense_csx.h b/cy_capsense_csx.h
index e8188a8..a39e40b 100644
--- a/cy_capsense_csx.h
+++ b/cy_capsense_csx.h
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_csx.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the function prototypes specific to the CSX sensing
@@ -8,7 +8,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -22,7 +22,7 @@
#include "cy_capsense_structure.h"
#include "cy_capsense_common.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
@@ -43,10 +43,10 @@ void Cy_CapSense_CSXSetupWidgetExt(uint32_t widgetId, uint32_t sensorId, cy_stc_
void Cy_CapSense_CSXScan(cy_stc_capsense_context_t * context);
void Cy_CapSense_CSXScanExt(cy_stc_capsense_context_t * context);
-void Cy_CapSense_CSXConnectRx(const cy_stc_capsense_pin_config_t * rxPtr, cy_stc_capsense_context_t * context);
-void Cy_CapSense_CSXConnectTx(const cy_stc_capsense_pin_config_t * txPtr, cy_stc_capsense_context_t * context);
-void Cy_CapSense_CSXDisconnectRx(const cy_stc_capsense_pin_config_t * rxPtr, cy_stc_capsense_context_t * context);
-void Cy_CapSense_CSXDisconnectTx(const cy_stc_capsense_pin_config_t * txPtr, cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSXConnectRx(const cy_stc_capsense_pin_config_t * rxPtr, const cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSXConnectTx(const cy_stc_capsense_pin_config_t * txPtr, const cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSXDisconnectRx(const cy_stc_capsense_pin_config_t * rxPtr, const cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSXDisconnectTx(const cy_stc_capsense_pin_config_t * txPtr, const cy_stc_capsense_context_t * context);
/** \} */
@@ -62,8 +62,8 @@ void Cy_CapSense_CSXDisconnectTx(const cy_stc_capsense_pin_config_t * txPtr, cy_
void Cy_CapSense_CSXConnectRxExt(cy_stc_capsense_context_t * context);
void Cy_CapSense_CSXConnectTxExt(cy_stc_capsense_context_t * context);
-void Cy_CapSense_CSXDisconnectRxExt(cy_stc_capsense_context_t * context);
-void Cy_CapSense_CSXDisconnectTxExt(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSXDisconnectRxExt(const cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSXDisconnectTxExt(const cy_stc_capsense_context_t * context);
void Cy_CapSense_CSXSetUpIdacs(cy_stc_capsense_context_t * context);
void Cy_CapSense_CSXDisableMode(cy_stc_capsense_context_t * context);
@@ -78,530 +78,123 @@ void Cy_CapSense_CSXScanISR(void * capsenseContext);
/*******************************************************************************
* Local definition
*******************************************************************************/
-#define CY_CAPSENSE_CSX_DEADBAND_CYCLES_NUMBER (2u)
+#define CY_CAPSENSE_CSX_DEADBAND_CYCLES_NUMBER (2u)
+#define CY_CAPSENSE_CSX_PRECHARGE_MAX_TIME_US (1000u)
+#define CY_CAPSENSE_CSX_WATCHDOG_MARGIN_COEFF (3u)
+#define CY_CAPSENSE_CSX_PRECHARGE_WATCHDOG_TIME_US (CY_CAPSENSE_CSX_PRECHARGE_MAX_TIME_US *\
+ CY_CAPSENSE_CSX_WATCHDOG_MARGIN_COEFF)
+
/*******************************************************************************
-* Register Configuration
+* CSD HW block registers configuration, required for the CSX mode initialization
*******************************************************************************/
+#define CY_CAPSENSE_DEFAULT_CSD_CONFIG_CFG (0x800C1020u)
+#define CY_CAPSENSE_DEFAULT_CSD_INTR_MASK_CFG (CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK)
+#define CY_CAPSENSE_DEFAULT_CSD_HSCMP_CFG (0x00000000u)
+#define CY_CAPSENSE_DEFAULT_CSD_AMBUF_CFG (0x00000000u)
+#define CY_CAPSENSE_LOW_VOLTAGE_CSD_AMBUF_CFG (0x00000001u)
+/* Intended to be used for PSoC4 devices in case if VDDA >= 2V */
+#define CY_CAPSENSE_DEFAULT_CSD_REFGEN_CFG (0x00001F41u)
+/* Intended to be used for PSoC4 devices in case if VDDA < 2V */
+#define CY_CAPSENSE_LOW_VOLTAGE_CSD_REFGEN_CFG (0x00800011u)
+/* Intended to be used for PSoC6 devices in case if the PASS is selected as the VREF source */
+#define CY_CAPSENSE_PASS_CSD_REFGEN_CFG (0x00001F41u)
+/* Intended to be used for PSoC6 devices in case if the SRSS is selected as the VREF source */
+#define CY_CAPSENSE_SRSS_CSD_REFGEN_CFG (0x00001541u)
+#define CY_CAPSENSE_DEFAULT_CSD_CSDCMP_CFG (0x00000300u)
+#define CY_CAPSENSE_DEFAULT_CSD_IDACA_CFG (0x010F0E80u)
+#define CY_CAPSENSE_DEFAULT_CSD_IDACB_CFG (0x00000000u)
+#define CY_CAPSENSE_DEFAULT_CSD_SENSE_DUTY_CFG (0x00000000u)
+#define CY_CAPSENSE_DEFAULT_CSD_SW_HS_P_SEL_CFG (0x00000000u)
+#define CY_CAPSENSE_DEFAULT_CSD_SW_HS_N_SEL_CFG (0x00000000u)
+#define CY_CAPSENSE_DEFAULT_CSD_SW_SHIELD_SEL_CFG (0x00000000u)
+#define CY_CAPSENSE_DEFAULT_CSD_SW_AMUXBUF_SEL_CFG (0x00000000u)
+#define CY_CAPSENSE_LOW_VOLTAGE_CSD_SW_AMUXBUF_SEL_CFG (0x01000100u)
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_BYP_SEL_CFG (0x00001000u)
+#else
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_BYP_SEL_CFG (0x00000000u)
+#endif
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_CMP_P_SEL_CFG (0x00000032u)
+#else
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_CMP_P_SEL_CFG (0x00000023u)
+#endif
+
+#define CY_CAPSENSE_DEFAULT_CSD_SW_CMP_N_SEL_CFG (0x01000000u)
+#define CY_CAPSENSE_LOW_VOLTAGE_CSD_SW_CMP_N_SEL_CFG (0x10000000u)
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_FW_MOD_SEL_CFG (0x00000000u)
+#else
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_FW_MOD_SEL_CFG (0x00030301u)
+#endif
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_FW_TANK_SEL_CFG (0x00000000u)
+#else
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_FW_TANK_SEL_CFG (0x00002210u)
+#endif
+
+#define CY_CAPSENSE_DEFAULT_CSD_SW_IO_SEL_CFG (0x0000001Fu)
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL_CFG (0x00000023u)
+#else
+ #define CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL_CFG (0x00000000u)
+#endif
+
+#define CY_CAPSENSE_DEFAULT_CSD_SEQ_NORM_CNT_CFG (0x00000000u)
+#define CY_CAPSENSE_DEFAULT_CSD_ADC_CTL_CFG (0x00000000u)
+#define CY_CAPSENSE_DEFAULT_CSD_SEQ_START_CFG (0x00000308u)
+
+
+/*******************************************************************************
+* CSD HW block registers configuration, required for coarse initialization of
+* integration capacitors
+*******************************************************************************/
+#define CY_CAPSENSE_PRESCAN_CSD_CONFIG_CFG (0x800C1000u)
+#define CY_CAPSENSE_PRESCAN_CSD_CSDCMP_CFG (0x00000301u)
+#define CY_CAPSENSE_PRECHARGE_CSD_HSCMP_CFG (0x00000001u)
+#define CY_CAPSENSE_PRECHARGE_CSD_SW_HS_P_SEL_CFG (0x00000011u)
+#define CY_CAPSENSE_PRECHARGE_CSD_SW_HS_N_SEL_CFG (0x01000000u)
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_PRECHARGE_CSD_SW_DSI_SEL_CFG (0x00000011u)
+#else
+ #define CY_CAPSENSE_PRECHARGE_CSD_SW_DSI_SEL_CFG (0x00000000u)
+#endif
+
+#define CY_CAPSENSE_PRECHARGE_CSD_SW_SHIELD_SEL_CFG (0x00000006u)
+#define CY_CAPSENSE_PRECHARGE_CSD_SW_FW_MOD_SEL_CFG (0x00010101u)
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_PRECHARGE_CSD_SW_FW_TANK_SEL_CFG (0x00001010u)
+#else
+ #define CY_CAPSENSE_PRECHARGE_CSD_SW_FW_TANK_SEL_CFG (0x00001110u)
+#endif
+
+#define CY_CAPSENSE_PRECHARGE_CSD_SEQ_START_CFG (0x00000303u)
+
+
+/*******************************************************************************
+* CSD HW block registers configuration, required to perform the CSX scan
+*******************************************************************************/
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_SCAN_CSD_SW_FW_MOD_SEL_CFG (0x00000000u)
+#else
+ #define CY_CAPSENSE_SCAN_CSD_SW_FW_MOD_SEL_CFG (0x00030301u)
+#endif
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_SCAN_CSD_SW_FW_TANK_SEL_CFG (0x00000000u)
+#else
+ #define CY_CAPSENSE_SCAN_CSD_SW_FW_TANK_SEL_CFG (0x00002210u)
+#endif
-/*
- * +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | IREF_SEL | Select Iref according to IrefSel parameter |
- * | 8:4 | FILTER_DELAY | 0x02(2-SampleClk cycles) |
- * | 11:10 | SHIELD_DELAY | 0x00(Delay Line is OFF) |
- * | 12 | SENSE_EN | 0x01(Enabled. Switches can be closed) |
- * | 17 | FULL_WAVE | 0x00(Half Wave Mode) |
- * | 18 | MUTUAL_CAP | 0x01(Mutual-cap mode) |
- * | 19 | CSX_DUAL_CNT | 0x01(Use two counters) |
- * | 24 | DSI_COUNT_SEL | 0x00(CSD-Result on DSI_COUNT bus) |
- * | 25 | DSI_SAMPLE_EN | 0x00(DSI_SAMPLE_IN is disabled) |
- * | 26 | SAMPLE_SYNC | 0x00(Double sync is disabled) |
- * | 27 | DSI_SENSE_EN | 0x00(DSI_SENSE_IN is disabled) |
- * | 30 | LP_MODE | 0x00(High power mode) |
- * | 31 | ENABLE | 0x01(Analog part is ON) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_CONFIG_DEFAULT_EN_CFG (0x80001000uL)
-#define CY_CAPSENSE_CONFIG_DEFAULT_FILTER_DELAY_CFG (0x00000020uL)
-#define CY_CAPSENSE_CONFIG_DEFAULT_MUTUAL_CFG (0x00040000uL)
-#define CY_CAPSENSE_CONFIG_DEFAULT_DUAL_CNT_CFG (0x00080000uL)
-
-#define CY_CAPSENSE_DEFAULT_CSD_CONFIG_CFG (CY_CAPSENSE_CONFIG_DEFAULT_FILTER_DELAY_CFG |\
- CY_CAPSENSE_CONFIG_DEFAULT_MUTUAL_CFG |\
- CY_CAPSENSE_CONFIG_DEFAULT_DUAL_CNT_CFG |\
- CY_CAPSENSE_CONFIG_DEFAULT_EN_CFG)
-
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 1 | SAMPLE | 0x01(Clear CSD End Of Scan interrupt) |
- * | 2 | INIT | 0x01(Clear CSD End Of Coarse Init interrupt) |
- * | 8 | ADC_RES | 0x01(Clear ADC End Of Scan interrupt) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_INTR_CFG (CY_CAPSENSE_CSD_INTR_ALL_MSK)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 1 | SAMPLE | 0x00(CSD End Of Scan interrupt is cleared) |
- * | 2 | INIT | 0x00(CSD End Of Coarse Init interrupt is cleared) |
- * | 8 | ADC_RES | 0x00(ADC End Of Scan interrupt is cleared) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_INTR_SET_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 1 | SAMPLE | 0x01(CSD End Of Scan interrupt is masked) |
- * | 2 | INIT | 0x00(CSD End Of Coarse Init interrupt is cleared) |
- * | 8 | ADC_RES | 0x00(ADC End Of Scan interrupt is cleared) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_INTR_MASK_CFG (CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | HSCMP_EN | 0x00(High Speed comparator is disabled) |
- * | 4 | HSCMP_INVERT | 0x00(High Speed comparator output is not inverted) |
- * | 31 | AZ_EN | 0x00(Auto-Zero is disabled) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_HSCMP_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 1:0 | PWR_MODE | 0x00(Amux buffer is disabled) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_AMBUF_CFG (0x00000000uL)
-
-/* +--------+---------------+------------------------------------------+---------------------------------------------+
- * | | | VDDA >= 2V | VDDA <2V |
- * + BITS + FIELD +------------------------------------------+---------------------------------------------+
- * | | | MODE | MODE |
- * |--------|---------------|------------------------------------------|---------------------------------------------|
- * | 0 | REFGEN_EN | 0x01(Reference generator is enabled) | 0x01(Reference generator is enabled) |
- * | 4 | BYPASS | 0x00(BYPASS mode switch is open) | 0x00(BYPASS mode switch is open) |
- * | 5 | VDDA_EN | 0x00(VDDA mode switch is open) | 0x00(VDDA mode switch is open) |
- * | 6 | RES_EN | 0x01(Resistor string is enabled) | 0x01(Resistor string is enabled) |
- * | 12:08 | GAIN | 0x1F(Gain = 31) | 0x15(Gain = 21) |
- * | 20:16 | VREFLO_SEL | 0x00(Open all VREFLO switches) | 0x00(Open all VREFLO switches) |
- * | 23 | VREFHI_SEL | 0x00(Open VREF_LO_INT switch) | 0x00(Open VREF_LO_INT switch) |
- * +--------+---------------+------------------------------------------+---------------------------------------------+*/
-
-#define CY_CAPSENSE_REFGEN_DEFAULT_EN_CFG (0x00000001uL)
-#define CY_CAPSENSE_REFGEN_DEFAULT_RES_EN_CFG (0x00000040uL)
-
-#define CY_CAPSENSE_DEFAULT_CSD_REFGEN_CFG (CY_CAPSENSE_REFGEN_DEFAULT_EN_CFG |\
- CY_CAPSENSE_REFGEN_DEFAULT_RES_EN_CFG)
-
-
-/* +--------+---------------+------------------------------------------+---------------------------------------------+
- * | | | AUTO_ZERO_EN=TRUE | AUTO_ZERO_EN=FALSE |
- * + BITS + FIELD +------------------------------------------+---------------------------------------------+
- * | | | MODE | MODE |
- * |--------|---------------|------------------------------------------|---------------------------------------------|
- * | 0 | CSDCMP_EN | 0x00(CSD comparator is disabled) | 0x00(CSD comparator is disabled) |
- * | 5:04 | POLARITY_SEL | 0x00(IDAC_A polarity is used) | 0x00(IDAC_A polarity is used) |
- * | 9:08 | CMP_PHASE | 0x03(Comparator activated on both phases)| 0x03(Comparator activated in both phases) |
- * | 28 | CMP_MODE | 0x00(CSD mode) | 0x00(CSD mode) |
- * | 29 | FEEDBACK_MODE | 0x00(Feedback from sampling flip-flop) | 0x00(Feedback from sampling flip-flop) |
- * | 31 | AZ_EN | 0x01(Auto-Zero functionality is enabled) | 0x00(Auto-Zero functionality is disabled) |
- * +--------+---------------+------------------------------------------+---------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_CSDCMP_CFG (0x00000300uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 6:0 | VAL | 0x00(Set IDAC value to "0") |
- * | 7 | POL_DYN | 0x01(Set dynamic IDAC polarity) |
- * | 9:8 | POLARITY | 0x02(IDAC polarity follows CSD_SENSE signal) |
- * | 11:10 | BAL_MODE | 0x03(IDAC is enabled in both phases and disabled by CSDCOMP at the end of balancing) |
- * | 17:16 | LEG1_MODE | 0x03(Configure LEG1 to CSD dynamic mode) |
- * | 19:18 | LEG2_MODE | 0x00(Configure LEG2 same as LEG 1) |
- * | 21 | DSI_CTRL_EN | 0x00(IDAC DSI control is disabled) |
- * | 23:22 | RANGE | Set range according to Csx0IdacGainV2 parameter value |
- * | 24 | LEG1_EN | 0x01(Output for LEG1 is enabled) |
- * | 25 | LEG2_EN | 0x00(Output for LEG2 is disabled) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_IDACA_CFG (0x010F0E80uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 6:0 | VAL | 0x00(Set IDAC value to "0") |
- * | 7 | POL_DYN | 0x00(Set to "0" since IDACB is not used) |
- * | 9:8 | POLARITY | 0x00(Set to "0" since IDACB is not used) |
- * | 11:10 | BAL_MODE | 0x00(Set to "0" since IDACB is not used) |
- * | 17:16 | LEG1_MODE | 0x00(Set to "0" since IDACB is not used) |
- * | 19:18 | LEG2_MODE | 0x00(Set to "0" since IDACB is not used) |
- * | 21 | DSI_CTRL_EN | 0x00(Set to "0" since IDACB is not used) |
- * | 23:22 | RANGE | 0x00(Set to "0" since IDACB is not used) |
- * | 24 | LEG1_EN | 0x00(Output for LEG2 is disabled) |
- * | 25 | LEG2_EN | 0x00(Output for LEG2 is disabled) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_IDACB_CFG (0x00000000uL)
-
-/* +--------+---------------+--------------------------------------------+-------------------------------------------+
- * | | | TX_CLK_SOURCE=PRSAUTO | TX_CLK_SOURCE!=PRSAUTO |
- * + BITS + FIELD +--------------------------------------------+-------------------------------------------+
- * | | | MODE | MODE |
- * |--------|---------------|--------------------------------------------|-------------------------------------------|
- * | 11:00 | SENSE_DIV | Set to CSX_TX_CLK_DIVIDER value | Set to CSX_TX_CLK_DIVIDER value |
- * | 18:16 | LFSR_SIZE | 0x00(Will be reconfigured in Run Time) | 0x00(Set to "0" since not used) |
- * | 23:20 | LFSR_SCALE | 0x00(Will be reconfigured in Run Time) | Set to CSX_TX_CLK_SOURCE value |
- * | 24 | LFSR_CLEAR | 0x00(Will be reconfigured in Run Time) | 0x00(Will be reconfigured in Run Time) |
- * | 25 | SEL_LFSR_MSB | 0x00(Not used for CSX scanning method) | 0x00(Not used for CSX scanning method) |
- * | 27:26 | LFSR_BITS | 0x0C(Use 5 bits. Range=[-16:15]) | 0x0C(Use 5 bits. Range=[-16:15]) |
- * +--------+---------------+-----------------------------+----------------------------------------------------------+*/
-
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 11:0 | SENSE_WIDTH | 0x0000(Set to "0" SenseClk cycles) |
- * | 16 | SENSE_POL | 0x00(Start with low phase) |
- * | 18 | OVERLAP_PHI1 | 0x00(Non overlap for Phi1) |
- * | 19 | OVERLAP_PHI2 | 0x00(Non overlap for Phi2) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SENSE_DUTY_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | SW_HMPM | 0x00(HMPM switch is statically open) |
- * | 4 | SW_HMPT | 0x00(HMPT switch is statically open) |
- * | 8 | SW_HMPS | 0x00(HMPS switch is statically open) |
- * | 12 | SW_HMMA | 0x00(HMMA switch is statically open) |
- * | 16 | SW_HMMB | 0x00(HMMB switch is statically open) |
- * | 20 | SW_HMCA | 0x00(HMCA switch is statically open) |
- * | 24 | SW_HMCB | 0x00(HMCB switch is statically open) |
- * | 28 | SW_HMRH | 0x00(HMRH switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_HS_P_SEL_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 16 | SW_HCCC | 0x00(HCCC switch is statically open) |
- * | 20 | SW_HCCD | 0x00(HCCD switch is statically open) |
- * | 26:24 | SW_HCRH | 0x00(HCRH switch is statically open) |
- * | 30:28 | SW_HCRL | 0x00(HCRL switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_HS_N_SEL_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 2:0 | SW_HCAV | 0x00(HCAV switch is statically open) |
- * | 6:4 | SW_HCAG | 0x00(HCAG switch is statically open) |
- * | 10:8 | SW_HCBV | 0x00(HCBV switch is statically open) |
- * | 14:12 | SW_HCBG | 0x00(HCBG switch is statically open) |
- * | 16 | SW_HCCV | 0x00(HCCV switch is statically open) |
- * | 20 | SW_HCCG | 0x00(HCCG switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_SHIELD_SEL_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 4 | SW_IRBY | 0x00(IRBY switch is statically open) |
- * | 8 | SW_IRLB | 0x00(IRLB switch is statically open) |
- * | 12 | SW_ICA | 0x00(ICA switch is statically open) |
- * | 18:16 | SW_ICB | 0x00(ICB switch is statically open) |
- * | 20 | SW_IRLI | 0x00(IRLI switch is statically open) |
- * | 24 | SW_IRH | 0x00(IRH switch is statically open) |
- * | 28 | SW_IRL | 0x00(IRL switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_AMUXBUF_SEL_CFG (0x00000000uL)
-
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 12 | SW_BYA | 0x01(BYA switch is statically open) |
- * | 16 | SW_BYB | 0x00(BYB switch is statically open) |
- * | 20 | SW_CBCC | 0x00(CBCC switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_BYP_SEL_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 2:0 | SW_SFPM | 0x03(SFPM switch is controlled by Phi2 of SenseClk signal) |
- * | 6:4 | SW_SFPT | 0x02(SFPM switch is controlled by Phi1 of the SenseClk signal) |
- * | 10:8 | SW_SFPS | 0x00(SFPS switch is statically open) |
- * | 12 | SW_SFMA | 0x00(SFMA switch is statically open) |
- * | 16 | SW_SFMB | 0x00(SFMB switch is statically open) |
- * | 20 | SW_SFCA | 0x00(SFCA switch is statically open) |
- * | 24 | SW_SFCB | 0x00(SFCB switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_CMP_P_SEL_CFG (0x00000023uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 26:24 | SW_SCRH | 0x01(SFPS switch is statically closed) |
- * | 30:28 | SW_SCRL | 0x00(SFPS switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_CMP_N_SEL_CFG (0x01000000uL)
-
-/* +--------+---------------+--------------------------------------------+-------------------------------------------+
- * | | | VREF_SRC=SRSS | VREF_SRC=PASS |
- * + BITS + FIELD +--------------------------------------------+-------------------------------------------+
- * | | | MODE | MODE |
- * |--------|---------------|--------------------------------------------|-------------------------------------------|
- * | 0 | SW_IAIB | 0x00(IAIB switch is statically open) | 0x00(IAIB switch is statically open) |
- * | 4 | SW_IBCB | 0x00(IBCB switch is statically open) | 0x00(IBCB switch is statically open) |
- * | 16 | SW_SGMB | 0x00(SGMB switch is statically open) | 0x00(SGMB switch is statically open) |
- * | 20 | SW_SGRP | 0x00(SGRP switch is statically open) | 0x01(SGRP switch is statically closed) |
- * | 24 | SW_SGRE | 0x00(SGRE switch is statically open) | 0x00(SGRE switch is statically open) |
- * | 28 | SW_SGR | 0x01(SGR switch is statically closed) | 0x00(SGR switch is statically open) |
- * +--------+---------------+--------------------------------------------+-------------------------------------------+*/
-
-#define CY_CAPSENSE_DEFAULT_CSD_SW_REFGEN_SEL_MSK (0x10100000uL)
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | SW_F1PM | 0x00(F1PM switch is statically closed) |
- * | 10:8 | SW_F1MA | 0x00(F1MA switch is controlled by Phi2 of SenseClk signal) |
- * | 18:16 | SW_F1CA | 0x00(F1CA switch is controlled by Phi2 of SenseClk signal) |
- * | 20 | SW_C1CC | 0x00(C1CC switch is statically open) |
- * | 24 | SW_C1CD | 0x00(C1CD switch is statically open) |
- * | 28 | SW_C1F1 | 0x00(C1F1 switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_FW_MOD_SEL_CFG (0x00030301uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 4 | SW_F2PT | 0x00(F2PT switch is statically closed) |
- * | 10:8 | SW_F2MA | 0x00(F2MA switch is controlled by Phi1 of the SenseClk signal) |
- * | 14:12 | SW_F2CA | 0x00(F2CA switch is controlled by Phi1 of the SenseClk signal) |
- * | 18:16 | SW_F2CB | 0x00(F2CB switch is statically open) |
- * | 20 | SW_C2CC | 0x00(C2CC switch is statically open) |
- * | 24 | SW_C2CD | 0x00(C2CD switch is statically open) |
- * | 28 | SW_C2F2 | 0x00(C2F2 switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_FW_TANK_SEL_CFG (0x00002210uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 3:0 | TX_OUT | 0x00(The TX_OUT signal is controlled by SenseClk signal) |
- * | 7:4 | TX_OUT_EN | 0x00(The TX_OUT_EN signal is set to the static "1") |
- * | 15:12 | TX_AMUXB_EN | 0x00(The TX_AMUXB_EN signal is set to the static "0") |
- * | 19:16 | TX_N_OUT | 0x00(The TX_N_OUT signal is set to the static "0") |
- * | 23:20 | TX_N_OUT_EN | 0x00(The TX_N_OUT_EN signal is set to the static "0") |
- * | 27:24 | TX_N_AMUXA_EN | 0x00(The TX_N_AMUXA_EN signal is set to the static "0") |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_IO_SEL_CFG (0x0000001FuL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 2:0 | DSI_CSH_TANK | 0x00(DSI_CSH_TANK switch is statically open) |
- * | 6:4 | DSI_CMOD | 0x00(DSI_CMOD switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 15:0 | CONV_CNT | 0x0000(Sets the number of conversions per sample to "0") |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SEQ_NORM_CNT_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 7:0 | ADC_TIME | 0x00(Set to "0" since ADC is not used) |
- * | 17:16 | ADC_MODE | 0b00(Set to "0" since ADC is not used) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_ADC_CTL_CFG (0x00000000uL)
-
-/* +--------+---------------+--------------------------------------------+-------------------------------------------+
- * | | | AUTO_ZERO_EN=TRUE | AUTO_ZERO_EN=FALSE |
- * + BITS + FIELD +--------------------------------------------+-------------------------------------------+
- * | | | MODE | MODE |
- * |--------|---------------|--------------------------------------------|-------------------------------------------|
- * | 0 | START | 0x00(CSD sequencer is stopped) | 0x00(CSD sequencer is stopped) |
- * | 1 | SEQ_MODE | 0x00(Regular scan mode is used) | 0x00(Regular scan mode is used) |
- * | 3 | ABORT | 0x01(Reset CSD sequencer to IDLE state) | 0x01(Reset CSD sequencer to IDLE state) |
- * | 4 | DSI_START_EN | 0x00(Disable control by DSI) | 0x00(Disable control by DSI) |
- * | 8 | AZ0_SKIP | 0x00(Do not skip AZ0 state) | 0x01(Skip AZ0 state) |
- * | 9 | AZ1_SKIP | 0x00(Do not skip AZ1 state) | 0x01(Skip AZ1 state) |
- * +--------+---------------+--------------------------------------------+-------------------------------------------+*/
-#define CY_CAPSENSE_DEFAULT_CSD_SEQ_START_CFG (0x00000308uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | IREF_SEL | 0x00(Select SRSS Iref) |
- * | 8:4 | FILTER_DELAY | 0x00(Will be reconfigured in Run Time) |
- * | 11:10 | SHIELD_DELAY | 0x00(Delay Line is OFF) |
- * | 12 | SENSE_EN | 0x01(Enabled. Switches can be closed) |
- * | 17 | FULL_WAVE | 0x00(Half Wave Mode) |
- * | 18 | MUTUAL_CAP | 0x01(Mutual-cap mode) |
- * | 19 | CSX_DUAL_CNT | 0x01(Use two counters) |
- * | 24 | DSI_COUNT_SEL | 0x00(CSD-Result on DSI_COUNT bus) |
- * | 25 | DSI_SAMPLE_EN | 0x00(DSI_SAMPLE_IN is disabled) |
- * | 26 | SAMPLE_SYNC | 0x00(Double sync is disabled) |
- * | 27 | DSI_SENSE_EN | 0x00(DSI_SENSE_IN is disabled) |
- * | 30 | LP_MODE | 0x00(High power mode) |
- * | 31 | ENABLE | 0x01(Analog part is ON) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-
-#define CY_CAPSENSE_CONFIG_PRESCAN_LP_MODE_CFG (0x00000000uL)
-#define CY_CAPSENSE_CONFIG_PRESCAN_EN_CFG (0x80000000uL)
-#define CY_CAPSENSE_CONFIG_PRESCAN_SENSE_EN_CFG (0x00001000uL)
-#define CY_CAPSENSE_CONFIG_PRESCAN_FILTER_DELAY_CFG (0x00000000uL)
-#define CY_CAPSENSE_CONFIG_PRESCAN_MUTUAL_CFG (0x00040000uL)
-#define CY_CAPSENSE_CONFIG_PRESCAN_DUAL_CNT_CFG (0x00080000uL)
-
-#define CY_CAPSENSE_PRESCAN_CSD_CONFIG_CFG (CY_CAPSENSE_CONFIG_PRESCAN_FILTER_DELAY_CFG |\
- CY_CAPSENSE_CONFIG_PRESCAN_SENSE_EN_CFG |\
- CY_CAPSENSE_CONFIG_PRESCAN_MUTUAL_CFG |\
- CY_CAPSENSE_CONFIG_PRESCAN_DUAL_CNT_CFG |\
- CY_CAPSENSE_CONFIG_PRESCAN_LP_MODE_CFG |\
- CY_CAPSENSE_CONFIG_PRESCAN_EN_CFG)
-
-/* +--------+---------------+--------------------------------------------+-------------------------------------------+
- * | | | AUTO_ZERO_EN=TRUE | AUTO_ZERO_EN=FALSE |
- * + BITS + FIELD +--------------------------------------------+-------------------------------------------+
- * | | | MODE | MODE |
- * |--------|---------------|--------------------------------------------|-------------------------------------------|
- * | 0 | CSDCMP_EN | 0x01(CSD comparator is Enabled) | 0x01(CSD comparator is Enabled) |
- * | 5:4 | POLARITY_SEL | 0x00(IDAC_A polarity is used) | 0x00(IDAC_A polarity is used) |
- * | 9:8 | CMP_PHASE | 0x03(Comparator activated in both phases) | 0x03(Comparator activated in both phases) |
- * | 28 | CMP_MODE | 0x00(CSD mode) | 0x00(CSD mode) |
- * | 29 | FEEDBACK_MODE | 0x00(Feedback from sampling flip-flop) | 0x00(Feedback from sampling flip-flop) |
- * | 31 | AZ_EN | 0x01(Auto-Zero functionality is enabled) | 0x00(Auto-Zero functionality is disabled) |
- * +--------+---------------+--------------------------------------------+-------------------------------------------+*/
-#define CY_CAPSENSE_PRESCAN_CSD_CSDCMP_CFG (0x00000301uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | HSCMP_EN | 0x01(High Speed comparator is Enabled) |
- * | 4 | HSCMP_INVERT | 0x00(High Speed comparator output is not inverted) |
- * | 31 | AZ_EN | 0x00(Auto-Zero is Disabled) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_PRECHARGE_CSD_HSCMP_CFG (0x00000001uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | SW_HMPM | 0x01(HMPM switch is statically closed) |
- * | 4 | SW_HMPT | 0x01(HMPT switch is statically closed) |
- * | 8 | SW_HMPS | 0x00(HMPS switch is statically open) |
- * | 12 | SW_HMMA | 0x00(HMMA switch is statically open) |
- * | 16 | SW_HMMB | 0x00(HMMB switch is statically open) |
- * | 20 | SW_HMCA | 0x00(HMCA switch is statically open) |
- * | 24 | SW_HMCB | 0x00(HMCB switch is statically open) |
- * | 28 | SW_HMRH | 0x00(HMRH switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_PRECHARGE_CSD_SW_HS_P_SEL_CFG (0x00000011uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 16 | SW_HCCC | 0x00(HCCC switch is statically open) |
- * | 20 | SW_HCCD | 0x00(HCCD switch is statically open) |
- * | 26:24 | SW_HCRH | 0x01(HCRH switch is statically closed) |
- * | 30:28 | SW_HCRL | 0x00(HCRL switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_PRECHARGE_CSD_SW_HS_N_SEL_CFG (0x01000000uL)
-
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 2:0 | DSI_CSH_TANK | 0x00(DSI_CSH_TANK switch is statically open) |
- * | 6:4 | DSI_CMOD | 0x00(DSI_CMOD switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_PRECHARGE_CSD_SW_DSI_SEL_CFG (0x00000000uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 2:0 | SW_HCAV | 0x06(HCAV switch is controlled by HSCMP output) |
- * | 6:4 | SW_HCAG | 0x00(HCAG switch is statically open) |
- * | 10:8 | SW_HCBV | 0x00(HCBV switch is statically open) |
- * | 14:12 | SW_HCBG | 0x00(HCBG switch is statically open) |
- * | 16 | SW_HCCV | 0x00(HCCV switch is statically open) |
- * | 20 | SW_HCCG | 0x00(HCCG switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_PRECHARGE_CSD_SW_SHIELD_SEL_CFG (0x00000006uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | SW_F1PM | 0x00(F1PM switch is statically closed) |
- * | 10:8 | SW_F1MA | 0x00(F1MA switch is statically closed) |
- * | 18:16 | SW_F1CA | 0x00(F1CA switch is statically closed) |
- * | 20 | SW_C1CC | 0x00(C1CC switch is statically open) |
- * | 24 | SW_C1CD | 0x00(C1CD switch is statically open) |
- * | 28 | SW_C1F1 | 0x00(C1F1 switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_PRECHARGE_CSD_SW_FW_MOD_SEL_CFG (0x00010101uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 4 | SW_F2PT | 0x00(F2PT switch is statically closed) |
- * | 10:8 | SW_F2MA | 0x00(F2MA switch is statically closed) |
- * | 14:12 | SW_F2CA | 0x00(F2CA switch is statically closed) |
- * | 18:16 | SW_F2CB | 0x00(F2CB switch is statically open) |
- * | 20 | SW_C2CC | 0x00(C2CC switch is statically open) |
- * | 24 | SW_C2CD | 0x00(C2CD switch is statically open) |
- * | 28 | SW_C2F2 | 0x00(C2F2 switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_PRECHARGE_CSD_SW_FW_TANK_SEL_CFG (0x00001110uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | START | 0x01(STARTED) |
- * | 1 | SEQ_MODE | 0x01(INIT_COARSE) |
- * | 3 | ABORT | 0x00(RESET_TO_IDLE_STATE) |
- * | 4 | DSI_START_EN | 0x00(DISABLE_CONTROL_BY_DSI) |
- * | 8 | AZ0_SKIP | 0x01(SKIP_AZ0) |
- * | 9 | AZ1_SKIP | 0x01(SKIP_AZ1) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_PRECHARGE_CSD_SEQ_START_CFG (0x00000303uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 0 | SW_F1PM | 0x01(F1PM switch is statically closed) |
- * | 10:8 | SW_F1MA | 0x03(F1MA switch is controlled by Phi2 of the SenseClk signal) |
- * | 18:16 | SW_F1CA | 0x03(F1CA switch is controlled by Phi2 of the SenseClk signal) |
- * | 20 | SW_C1CC | 0x00(C1CC switch is statically open) |
- * | 24 | SW_C1CD | 0x00(C1CD switch is statically open) |
- * | 28 | SW_C1F1 | 0x00(C1F1 switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_SCAN_CSD_SW_FW_MOD_SEL_CFG (0x00030301uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 4 | SW_F2PT | 0x01(F2PT switch is statically closed) |
- * | 10:8 | SW_F2MA | 0x02(F2MA switch is controlled by Phi1 of the SenseClk signal) |
- * | 14:12 | SW_F2CA | 0x02(F2CA switch is controlled by Phi1 of the SenseClk signal) |
- * | 18:16 | SW_F2CB | 0x00(F2CB switch is statically open) |
- * | 20 | SW_C2CC | 0x00(C2CC switch is statically open) |
- * | 24 | SW_C2CD | 0x00(C2CD switch is statically open) |
- * | 28 | SW_C2F2 | 0x00(C2F2 switch is statically open) |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_SCAN_CSD_SW_FW_TANK_SEL_CFG (0x00002210uL)
-
-/* +--------+---------------+----------------------------------------------------------------------------------------+
- * | BITS | FIELD | MODE |
- * |--------|---------------|----------------------------------------------------------------------------------------|
- * | 3:0 | TX_OUT | 0x00(The TX_OUT signal is controlled by SenseClk signal) |
- * | 7:4 | TX_OUT_EN | 0x00(The TX_OUT_EN signal is set to the static "1") |
- * | 15:12 | TX_AMUXB_EN | 0x00(The TX_AMUXB_EN signal is set to the static "0") |
- * | 19:16 | TX_N_OUT | 0x00(The TX_N_OUT signal is set to the static "0") |
- * | 23:20 | TX_N_OUT_EN | 0x00(The TX_N_OUT_EN signal is set to the static "0") |
- * | 27:24 | TX_N_AMUXA_EN | 0x00(The TX_N_AMUXA_EN signal is set to the static "0") |
- * +--------+---------------+----------------------------------------------------------------------------------------+*/
-#define CY_CAPSENSE_SCAN_CSD_SW_IO_SEL_CFG (0x0000001FuL)
-
-/* +--------+---------------+--------------------------------------------+-------------------------------------------+
- * | | | AUTO_ZERO_EN=TRUE | AUTO_ZERO_EN=FALSE |
- * + BITS + FIELD +--------------------------------------------+-------------------------------------------+
- * | | | MODE | MODE |
- * |--------|---------------|--------------------------------------------|-------------------------------------------|
- * | 0 | START | 0x01(CSD sequencer is stopped) | 0x01(CSD sequencer is stopped) |
- * | 1 | SEQ_MODE | 0x00(Regular CSD scan mode is used) | 0x00(Regular CSD scan mode is used) |
- * | 3 | ABORT | 0x00(Do not reset CSD sequencer) | 0x00(Do not reset CSD sequencer) |
- * | 4 | DSI_START_EN | 0x00(Disable control by DSI) | 0x00(Disable control by DSI) |
- * | 8 | AZ0_SKIP | 0x00(Do not skip AZ0 state) | 0x01(Skip AZ0 state) |
- * | 9 | AZ1_SKIP | 0x00(Do not skip AZ1 state) | 0x01(Skip AZ1 state) |
- * +--------+---------------+--------------------------------------------+-------------------------------------------+*/
-#define CY_CAPSENSE_SCAN_CSD_SEQ_START_CFG (0x00000301uL)
+#define CY_CAPSENSE_SCAN_CSD_SEQ_START_CFG (0x00000301u)
#if defined(__cplusplus)
}
diff --git a/cy_capsense_filter.c b/cy_capsense_filter.c
index 54c3d8a..a06fd19 100644
--- a/cy_capsense_filter.c
+++ b/cy_capsense_filter.c
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_filter.c
-* \version 2.0
+* \version 2.10
*
* \brief
* This file contains the source code of all filters implementation.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -19,7 +19,7 @@
#include "cy_capsense_common.h"
#include "cy_capsense_lib.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
/*******************************************************************************
@@ -167,8 +167,9 @@ cy_status Cy_CapSense_UpdateSensorBaseline(
{
uint32_t result;
const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+ cy_stc_capsense_sensor_context_t * ptrSnsCxt = &ptrWdCfg->ptrSnsContext[sensorId];
- result = Cy_CapSense_FtUpdateBaseline(ptrWdCfg->ptrWdContext, &ptrWdCfg->ptrSnsContext[sensorId], context);
+ result = Cy_CapSense_FtUpdateBaseline(ptrWdCfg->ptrWdContext, ptrSnsCxt, &ptrWdCfg->ptrBslnInv[sensorId], context);
return (result);
}
@@ -192,60 +193,77 @@ cy_status Cy_CapSense_UpdateSensorBaseline(
* The pointer to the sensor context structure where the sensor data
* is stored.
*
+* \param ptrSnsBslnInv
+* The pointer to the sensor baseline inversion used for BIST if enabled.
+*
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns a status indicating whether the baseline has been updated:
-* - Zero - if baseline updating was successful.
-* - Non-zero - if present sensor's any channel baseline and its inversion
+* - CY_RET_SUCCESS - if baseline updating was successful.
+* - CY_RET_BAD_DATA - if present sensor's any channel baseline and its inversion
* doesn't match.
*
*******************************************************************************/
uint32_t Cy_CapSense_FtUpdateBaseline(
const cy_stc_capsense_widget_context_t * ptrWdContext,
cy_stc_capsense_sensor_context_t * ptrSnsContext,
+ uint16_t * ptrSnsBslnInv,
const cy_stc_capsense_context_t * context)
{
uint32_t result = CY_RET_SUCCESS;
uint32_t bslnHistory;
+ uint16_t bslnInv = (uint16_t)(~ptrSnsContext->bsln);
- /* Reset negative baseline counter */
- if(ptrSnsContext->raw >= ptrSnsContext->bsln)
+ if ((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn) && (*ptrSnsBslnInv != bslnInv))
{
- ptrSnsContext->negBslnRstCnt = 0u;
+ result = CY_RET_BAD_DATA;
}
-
- /* Reset baseline */
- if (ptrSnsContext->bsln > (ptrWdContext->nNoiseTh + ptrSnsContext->raw))
+ if (CY_RET_SUCCESS == result)
{
- if (ptrSnsContext->negBslnRstCnt >= ptrWdContext->lowBslnRst)
+ /* Reset negative baseline counter */
+ if(ptrSnsContext->raw >= ptrSnsContext->bsln)
+ {
+ ptrSnsContext->negBslnRstCnt = 0u;
+ }
+
+ /* Reset baseline */
+ if (ptrSnsContext->bsln > (ptrWdContext->nNoiseTh + ptrSnsContext->raw))
{
- Cy_CapSense_FtInitializeBaseline(ptrSnsContext);
+ if (ptrSnsContext->negBslnRstCnt >= ptrWdContext->lowBslnRst)
+ {
+ Cy_CapSense_FtInitializeBaseline(ptrSnsContext);
+ }
+ else
+ {
+ ptrSnsContext->negBslnRstCnt++;
+ }
}
else
{
- ptrSnsContext->negBslnRstCnt++;
+ /*
+ * Update baseline only if:
+ * - signal is in range between noiseThreshold and negativenoiseThreshold
+ * or
+ * - sensor Auto-reset is enabled
+ */
+ if ((0u != context->ptrCommonConfig->swSensorAutoResetEn) ||
+ (ptrSnsContext->raw <= (ptrWdContext->noiseTh + ptrSnsContext->bsln)))
+ {
+ /* Get real baseline */
+ bslnHistory = ((uint32_t)ptrSnsContext->bsln << CY_CAPSENSE_IIR_BL_SHIFT) | ptrSnsContext->bslnExt;
+ /* Calculate baseline value */
+ bslnHistory = Cy_CapSense_FtIIR1stOrder((uint32_t)ptrSnsContext->raw << CY_CAPSENSE_IIR_BL_SHIFT, bslnHistory, (uint32_t)ptrWdContext->bslnCoeff);
+ /* Split baseline */
+ ptrSnsContext->bsln = CY_LO16(bslnHistory >> CY_CAPSENSE_IIR_BL_SHIFT);
+ ptrSnsContext->bslnExt = CY_LO8(bslnHistory);
+ }
}
- }
- else
- {
- /*
- * Update baseline only if:
- * - signal is in range between noiseThreshold and negativenoiseThreshold
- * or
- * - sensor Auto-reset is enabled
- */
- if ((0u != context->ptrCommonConfig->swSensorAutoResetEn) ||
- (ptrSnsContext->raw <= (ptrWdContext->noiseTh + ptrSnsContext->bsln)))
+ /* If BIST enabled, update the baseline inverse duplication */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
{
- /* Get real baseline */
- bslnHistory = ((uint32_t)ptrSnsContext->bsln << CY_CAPSENSE_IIR_BL_SHIFT) | ptrSnsContext->bslnExt;
- /* Calculate baseline value */
- bslnHistory = Cy_CapSense_FtIIR1stOrder((uint32_t)ptrSnsContext->raw << CY_CAPSENSE_IIR_BL_SHIFT, bslnHistory, (uint32_t)ptrWdContext->bslnCoeff);
- /* Split baseline */
- ptrSnsContext->bsln = CY_LO16(bslnHistory >> CY_CAPSENSE_IIR_BL_SHIFT);
- ptrSnsContext->bslnExt = CY_LO8(bslnHistory);
+ *ptrSnsBslnInv = ~ptrSnsContext->bsln;
}
}
return result;
@@ -362,6 +380,12 @@ void Cy_CapSense_InitializeSensorBaseline(
{
cxtOffset = sensorId + (freqChIndex * context->ptrCommonConfig->numSns);
Cy_CapSense_FtInitializeBaseline(&context->ptrWdConfig[widgetId].ptrSnsContext[cxtOffset]);
+ /* If BIST enabled, create a baseline inverse duplication */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ context->ptrWdConfig[widgetId].ptrBslnInv[cxtOffset] =
+ ~context->ptrWdConfig[widgetId].ptrSnsContext[cxtOffset].bsln;
+ }
}
}
@@ -610,6 +634,9 @@ void Cy_CapSense_InitializeIIRInternal(
uint16_t * ptrSnsRawHistory,
uint8_t * ptrSnsRawHistoryLow)
{
+ CY_ASSERT(NULL != ptrSnsRawHistory);
+ CY_ASSERT(NULL != ptrSnsRawHistoryLow);
+
ptrSnsRawHistory[0u] = ptrSnsContext->raw;
if(CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdConfig->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
diff --git a/cy_capsense_filter.h b/cy_capsense_filter.h
index 3e028ce..d0d6383 100644
--- a/cy_capsense_filter.h
+++ b/cy_capsense_filter.h
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_filter.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file contains the definitions for all the filters implementation.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -23,7 +23,7 @@
#include "cy_capsense_structure.h"
#include "cy_capsense_common.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
@@ -97,6 +97,7 @@ void Cy_CapSense_FtInitializeBaseline(
uint32_t Cy_CapSense_FtUpdateBaseline(
const cy_stc_capsense_widget_context_t * ptrWdContext,
cy_stc_capsense_sensor_context_t * ptrSnsContext,
+ uint16_t * ptrSnsBslnInv,
const cy_stc_capsense_context_t * context);
uint32_t Cy_CapSense_FtMedian(uint32_t x1, uint32_t x2, uint32_t x3);
diff --git a/cy_capsense_gesture_lib.h b/cy_capsense_gesture_lib.h
index e044859..db66ac6 100644
--- a/cy_capsense_gesture_lib.h
+++ b/cy_capsense_gesture_lib.h
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_gesture_lib.h
-* \version 2.0
+* \version 2.10
*
* \brief
* Provides the gesture interface.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -19,7 +19,7 @@
#include
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
diff --git a/cy_capsense_lib.h b/cy_capsense_lib.h
index 67c60d8..f7ba2e5 100644
--- a/cy_capsense_lib.h
+++ b/cy_capsense_lib.h
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_lib.h
-* \version 2.0
+* \version 2.10
*
* \brief
* The file contains application programming interface to the CapSense library.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -19,7 +19,7 @@
#include "cy_syslib.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
@@ -35,7 +35,7 @@ extern "C" {
/******************************************************************************/
/** No touch detected */
#define CY_CAPSENSE_ADVANCED_CENTROID_NO_TOUCHES (0x00u)
-/** Multiple touches detected */
+/** An error in touch calculation or number of detected touches is above supported touches */
#define CY_CAPSENSE_ADVANCED_CENTROID_POSITION_ERROR (0xFFu)
/** \} */
diff --git a/cy_capsense_processing.c b/cy_capsense_processing.c
index f74aa37..8c31707 100644
--- a/cy_capsense_processing.c
+++ b/cy_capsense_processing.c
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_processing.c
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the source code for the Data Processing module functions.
@@ -11,7 +11,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -28,7 +28,7 @@
#include "cy_capsense_sensing.h"
#include "cy_capsense_centroid.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
/*******************************************************************************
@@ -258,7 +258,7 @@ void Cy_CapSense_InitializeWidgetGestures(
* Function Name: Cy_CapSense_DecodeWidgetGestures
****************************************************************************//**
*
-* Performs processing of all gestures for the specified widget.
+* Performs decoding of all gestures for the specified widget.
*
* This function should be called by application program only after all sensors
* are scanned and all data processing is executed using
@@ -390,6 +390,8 @@ uint32_t Cy_CapSense_DpProcessCsxWidgetRawCounts(
uint32_t freqChNumber;
uint16_t * ptrHistoryCh;
uint16_t * ptrHistorySns;
+ uint16_t * ptrBslnInvCh = ptrWdConfig->ptrBslnInv;
+ uint16_t * ptrBslnInvSns;
uint8_t * ptrHistoryLowCh = NULL;
uint8_t * ptrHistoryLowSns = NULL;
cy_stc_capsense_sensor_context_t * ptrSnsCxtCh;
@@ -410,6 +412,7 @@ uint32_t Cy_CapSense_DpProcessCsxWidgetRawCounts(
ptrSnsCxtSns = ptrSnsCxtCh;
ptrHistorySns = ptrHistoryCh;
ptrHistoryLowSns = ptrHistoryLowCh;
+ ptrBslnInvSns = ptrBslnInvCh;
for (snsIndex = 0u; snsIndex < ptrWdConfig->numSns; snsIndex++)
{
Cy_CapSense_FtRunEnabledFiltersInternal_Call(ptrWdConfig,
@@ -417,9 +420,10 @@ uint32_t Cy_CapSense_DpProcessCsxWidgetRawCounts(
ptrHistorySns,
ptrHistoryLowSns,
context);
- result |= Cy_CapSense_FtUpdateBaseline(ptrWdConfig->ptrWdContext, ptrSnsCxtSns, context);
+ result |= Cy_CapSense_FtUpdateBaseline(ptrWdConfig->ptrWdContext, ptrSnsCxtSns, ptrBslnInvSns, context);
Cy_CapSense_DpUpdateDifferences(ptrWdConfig->ptrWdContext, ptrSnsCxtSns);
ptrSnsCxtSns++;
+ ptrBslnInvSns++;
ptrHistorySns += snsHistorySize;
if(NULL != ptrHistoryLowSns)
{
@@ -428,6 +432,7 @@ uint32_t Cy_CapSense_DpProcessCsxWidgetRawCounts(
}
ptrSnsCxtCh += context->ptrCommonConfig->numSns;
+ ptrBslnInvCh += context->ptrCommonConfig->numSns;
ptrHistoryCh += context->ptrCommonConfig->numSns * snsHistorySize;
if(NULL != ptrHistoryLowCh)
{
@@ -519,6 +524,9 @@ void Cy_CapSense_DpProcessCsxWidgetStatus(
* - CY_CAPSENSE_PROCESS_DIFFCOUNTS (0x04) Update Difference Counts
* - CY_CAPSENSE_PROCESS_ALL Execute all tasks
*
+* \param ptrSnsBslnInv
+* The pointer to the sensor baseline inversion used for BIST if enabled.
+*
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
@@ -536,6 +544,7 @@ uint32_t Cy_CapSense_DpProcessCsxSensorRawCountsExt(
uint16_t * ptrSnsRawHistory,
uint8_t * ptrSnsRawHistoryLow,
uint32_t mode,
+ uint16_t * ptrSnsBslnInv,
const cy_stc_capsense_context_t * context)
{
uint32_t result = CY_RET_SUCCESS;
@@ -553,7 +562,7 @@ uint32_t Cy_CapSense_DpProcessCsxSensorRawCountsExt(
if (0u != (mode & CY_CAPSENSE_PROCESS_BASELINE))
{
- result = Cy_CapSense_FtUpdateBaseline(ptrWdCxt, ptrSnsContext, context);
+ result = Cy_CapSense_FtUpdateBaseline(ptrWdCxt, ptrSnsContext, ptrSnsBslnInv, context);
}
if (0u != (mode & CY_CAPSENSE_PROCESS_DIFFCOUNTS))
{
@@ -600,6 +609,8 @@ uint32_t Cy_CapSense_DpProcessCsdWidgetRawCounts(
uint32_t freqChNumber;
uint16_t * ptrHistoryCh;
uint16_t * ptrHistorySns;
+ uint16_t * ptrBslnInvCh = ptrWdConfig->ptrBslnInv;
+ uint16_t * ptrBslnInvSns;
uint8_t * ptrHistoryLowCh = NULL;
uint8_t * ptrHistoryLowSns = NULL;
cy_stc_capsense_sensor_context_t * ptrSnsCxtCh;
@@ -620,6 +631,7 @@ uint32_t Cy_CapSense_DpProcessCsdWidgetRawCounts(
{
ptrSnsCxtSns = ptrSnsCxtCh;
ptrHistorySns = ptrHistoryCh;
+ ptrBslnInvSns = ptrBslnInvCh;
ptrHistoryLowSns = ptrHistoryLowCh;
for (snsIndex = 0u; snsIndex < ptrWdConfig->numSns; snsIndex++)
{
@@ -644,10 +656,11 @@ uint32_t Cy_CapSense_DpProcessCsdWidgetRawCounts(
ptrNEHistory++;
}
- result |= Cy_CapSense_FtUpdateBaseline(ptrWdConfig->ptrWdContext, ptrSnsCxtSns, context);
+ result |= Cy_CapSense_FtUpdateBaseline(ptrWdConfig->ptrWdContext, ptrSnsCxtSns, ptrBslnInvSns, context);
Cy_CapSense_DpUpdateDifferences(ptrWdConfig->ptrWdContext, ptrSnsCxtSns);
ptrSnsCxtSns++;
+ ptrBslnInvSns++;
ptrHistorySns += snsHistorySize;
if(NULL != ptrHistoryLowSns)
{
@@ -657,6 +670,7 @@ uint32_t Cy_CapSense_DpProcessCsdWidgetRawCounts(
}
ptrSnsCxtCh += context->ptrCommonConfig->numSns;
+ ptrBslnInvCh += context->ptrCommonConfig->numSns;
ptrHistoryCh += context->ptrCommonConfig->numSns * snsHistorySize;
if(NULL != ptrHistoryLowCh)
{
@@ -712,15 +726,17 @@ uint32_t Cy_CapSense_DpProcessCsdWidgetRawCounts(
* - CY_CAPSENSE_PROCESS_THRESHOLDS (0x10) Update Thresholds (only if FW Tuning is enabled)
* - CY_CAPSENSE_PROCESS_ALL Execute all tasks
*
+* \param ptrBslnInvSns
+* The pointer to the sensor baseline inversion used for BIST if enabled.
+*
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
* \return
* Returns the status of the specified sensor processing operation:
* - CY_RET_SUCCESS if operation was successfully completed.
-* - CY_CAPSENSE_PROCESS_BASELINE_FAILED if baseline processing of any
-* sensor of the specified widget failed. The result is concatenated with the index
-* of the failed sensor.
+* - CY_RET_BAD_DATA if baseline processing of any sensor of the specified widget
+* failed.
*
*******************************************************************************/
uint32_t Cy_CapSense_DpProcessCsdSensorRawCountsExt(
@@ -729,6 +745,7 @@ uint32_t Cy_CapSense_DpProcessCsdSensorRawCountsExt(
uint16_t * ptrSnsRawHistory,
uint8_t * ptrSnsRawHistoryLow,
uint32_t mode,
+ uint16_t * ptrBslnInvSns,
const cy_stc_capsense_context_t * context)
{
uint32_t result = CY_RET_SUCCESS;
@@ -736,16 +753,14 @@ uint32_t Cy_CapSense_DpProcessCsdSensorRawCountsExt(
if (0u != (mode & CY_CAPSENSE_PROCESS_FILTER))
{
- Cy_CapSense_FtRunEnabledFiltersInternal_Call(ptrWdConfig,
- ptrSnsContext,
- ptrSnsRawHistory,
- ptrSnsRawHistoryLow,
+ Cy_CapSense_FtRunEnabledFiltersInternal_Call(ptrWdConfig, ptrSnsContext,
+ ptrSnsRawHistory, ptrSnsRawHistoryLow,
context);
}
if (0u != (mode & CY_CAPSENSE_PROCESS_BASELINE))
{
- result = Cy_CapSense_FtUpdateBaseline(ptrWdCxt, ptrSnsContext, context);
+ result = Cy_CapSense_FtUpdateBaseline(ptrWdCxt, ptrSnsContext, ptrBslnInvSns, context);
}
if (0u != (mode & CY_CAPSENSE_PROCESS_DIFFCOUNTS))
{
@@ -896,12 +911,15 @@ void Cy_CapSense_DpUpdateDifferences(
*******************************************************************************/
void Cy_CapSense_DpProcessButton(
const cy_stc_capsense_widget_config_t * ptrWdConfig,
- cy_stc_capsense_context_t * context)
+ const cy_stc_capsense_context_t * context)
{
uint32_t snsIndex;
uint32_t activeCount = 0u;
uint32_t startIndex = 0u;
uint32_t touchTh;
+
+ (void) context;
+
uint8_t * ptrDebounceCnt = ptrWdConfig->ptrDebounceArr;
cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdConfig->ptrSnsContext;
cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
@@ -1199,10 +1217,13 @@ void Cy_CapSense_DpProcessSlider(
*******************************************************************************/
void Cy_CapSense_DpProcessCsdMatrix(
const cy_stc_capsense_widget_config_t * ptrWdConfig,
- cy_stc_capsense_context_t * context)
+ const cy_stc_capsense_context_t * context)
{
uint32_t snsIndex;
uint32_t touchTh;
+
+ (void) context;
+
uint32_t colNumber = ptrWdConfig->numCols;
uint8_t * ptrDebounceCnt = ptrWdConfig->ptrDebounceArr;
cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdConfig->ptrSnsContext;
diff --git a/cy_capsense_processing.h b/cy_capsense_processing.h
index f8daaf5..0e59425 100644
--- a/cy_capsense_processing.h
+++ b/cy_capsense_processing.h
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_processing.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the function prototypes for the Data Processing module.
@@ -11,7 +11,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -25,7 +25,7 @@
#include "cy_capsense_structure.h"
#include "cy_capsense_lib.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
@@ -63,7 +63,7 @@ void Cy_CapSense_InitializeWidgetStatus(
/******************************************************************************/
void Cy_CapSense_DpProcessButton(
const cy_stc_capsense_widget_config_t * ptrWdConfig,
- cy_stc_capsense_context_t * context);
+ const cy_stc_capsense_context_t * context);
void Cy_CapSense_DpProcessCsxTouchpad(
const cy_stc_capsense_widget_config_t * ptrWdConfig,
@@ -81,7 +81,7 @@ void Cy_CapSense_DpProcessSlider(
const cy_stc_capsense_context_t * context);
void Cy_CapSense_DpProcessCsdMatrix(
const cy_stc_capsense_widget_config_t * ptrWdConfig,
- cy_stc_capsense_context_t * context);
+ const cy_stc_capsense_context_t * context);
void Cy_CapSense_DpProcessCsdWidgetStatus(
const cy_stc_capsense_widget_config_t * ptrWdConfig,
@@ -97,6 +97,7 @@ uint32_t Cy_CapSense_DpProcessCsdSensorRawCountsExt(
uint16_t * ptrSnsRawHistory,
uint8_t * ptrSnsRawHistoryLow,
uint32_t mode,
+ uint16_t * ptrBslnInvSns,
const cy_stc_capsense_context_t * context);
void Cy_CapSense_DpProcessCsxWidgetStatus(
@@ -113,6 +114,7 @@ uint32_t Cy_CapSense_DpProcessCsxSensorRawCountsExt(
uint16_t * ptrSnsRawHistory,
uint8_t * ptrSnsRawHistoryLow,
uint32_t mode,
+ uint16_t * ptrSnsBslnInv,
const cy_stc_capsense_context_t * context);
void Cy_CapSense_DpUpdateDifferences(
diff --git a/cy_capsense_selftest.c b/cy_capsense_selftest.c
new file mode 100644
index 0000000..84d4dbc
--- /dev/null
+++ b/cy_capsense_selftest.c
@@ -0,0 +1,4430 @@
+/***************************************************************************//**
+* \file cy_capsense_selftest.c
+* \version 2.10
+*
+* \brief
+* This file provides the source code to the Built-in Self-test (BIST)
+* functions.
+*
+********************************************************************************
+* \copyright
+* Copyright 2019-2020, Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include
+#include
+#include "cy_syslib.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_sensing.h"
+#include "cy_capsense_lib.h"
+#include "cy_capsense_selftest.h"
+#include "cy_gpio.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
+
+
+/*******************************************************************************
+* Common local definitions for self-test
+*******************************************************************************/
+
+/* Port Data Register macros for BIST */
+#define CY_CAPSENSE_BIST_DR_PIN2GND (0u)
+#define CY_CAPSENSE_BIST_DR_PIN2VDD (1u)
+
+#define CY_CAPSENSE_BIST_CP_MAX_VALUE (400000u)
+#define CY_CAPSENSE_BIST_PROMILLE_FACTOR (1000u)
+#define CY_CAPSENSE_BIST_SNS_CLK_MIN_DIVIDER (4u)
+#define CY_CAPSENSE_BIST_SNS_CLK_MAX_DIVIDER (4096u)
+
+/* Macros for the electrode capacitance measurement test */
+#define CY_CAPSENSE_BIST_ELTD_CAP_MAX_RAW_PROMILLE (450u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_MIN_RAW_PROMILLE (75u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_MAX_RESOLUTION (15u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_MIN_RESOLUTION (8u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_CYCLES_NUM (4u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_MAX_MODCLK (50000000u)
+#define CY_CAPSENSE_BIST_SW_DSI_SEL_DEFAULT (0x00000000uL)
+
+/* IDAC register mask */
+#define CY_CAPSENSE_BIST_IDAC_BITS_TO_WRITE (CSD_IDACA_VAL_Msk |\
+ CSD_IDACA_RANGE_Msk |\
+ CSD_IDACA_LEG1_EN_Msk |\
+ CSD_IDACA_LEG2_EN_Msk |\
+ CSD_IDACA_LEG1_MODE_Msk |\
+ CSD_IDACA_LEG2_MODE_Msk)
+
+#define CY_CAPSENSE_BIST_FSM_AZ0_SKIP (0x100u)
+#define CY_CAPSENSE_BIST_FSM_AZ1_SKIP (0x200u)
+
+/*******************************************************************************
+* Macros for the external capacitor capacitance measurement test
+*******************************************************************************/
+
+#define CY_CAPSENSE_BIST_CAP_MEAS_DUTY_WIDTH (10u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_MAX_MODCLK (12500000u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_ACCURACY_FACTOR (1150u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_MIN_RAWCOUNT (10u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_MAX_CAP (25u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_CMOD_MAX_VALUE (5u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_CINT_MAX_VALUE (1u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_CSH_MAX_VALUE (20u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_VREF_MV_DEFAULT (1200u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_WDT_CYCLES_PER_LOOP (5u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_WDT_TIMEOUT (3000u)
+
+#define CY_CAPSENSE_BIST_PRECHARGE_MAX_TIME_US (6000u)
+#define CY_CAPSENSE_BIST_WATCHDOG_MARGIN_COEFF (3u)
+#define CY_CAPSENSE_BIST_PRECHARGE_WATCHDOG_TIME_US (CY_CAPSENSE_BIST_PRECHARGE_MAX_TIME_US *\
+ CY_CAPSENSE_BIST_WATCHDOG_MARGIN_COEFF)
+
+/* HW block register values */
+#define CY_CAPSENSE_BIST_CAP_SEQ_START_DEFAULT (CY_CAPSENSE_CSD_SEQ_START_AZ0_SKIP_MSK | \
+ CY_CAPSENSE_CSD_SEQ_START_AZ1_SKIP_MSK | \
+ CY_CAPSENSE_CSD_SEQ_START_START_MSK)
+#define CY_CAPSENSE_BIST_CAP_CSDCMP_DEFAULT (CY_CAPSENSE_CSD_CSDCMP_CMP_PHASE_PHI2_MSK | \
+ CY_CAPSENSE_CSD_CSDCMP_CSDCMP_EN_MSK)
+#define CY_CAPSENSE_BIST_CAP_SENSE_DUTY_DEFAULT (CSD_SENSE_DUTY_OVERLAP_PHI1_Msk | \
+ CSD_SENSE_DUTY_OVERLAP_PHI2_Msk | \
+ CY_CAPSENSE_BIST_CAP_MEAS_DUTY_WIDTH)
+#define CY_CAPSENSE_BIST_CAP_SW_BYP_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK)
+#define CY_CAPSENSE_BIST_CAP_SW_CMP_N_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE)
+#define CY_CAPSENSE_BIST_CAP_SW_CMP_P_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFMA_STATIC_CLOSE)
+#define CY_CAPSENSE_BIST_CAP_SW_REFGEN_SEL_SRSS_DEFAULT (CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGR_MSK)
+#if (CY_CAPSENSE_PSOC6_CSDV2)
+ #define CY_CAPSENSE_BIST_CAP_SW_REFGEN_SEL_PASS_DEFAULT (CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRP_MSK)
+ #define CY_CAPSENSE_BIST_CAP_IO_SEL_DEFAULT (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 | \
+ CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2)
+#endif
+#define CY_CAPSENSE_BIST_CAP_REFGEN_DEFAULT (CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_RES_EN_Msk)
+#define CY_CAPSENSE_BIST_CAP_REFGEN_LOW_VOLTAGE_DEFAULT (CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk)
+#define CY_CAPSENSE_BIST_CAP_CONFIG_DEFAULT (CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_48MHZ | \
+ CSD_CONFIG_SENSE_EN_Msk | \
+ CSD_CONFIG_ENABLE_Msk)
+#if (CY_CAPSENSE_PSOC6_CSDV2)
+ #define CY_CAPSENSE_BIST_CAP_CONFIG_IREF_DEFAULT (CY_CAPSENSE_BIST_CAP_CONFIG_DEFAULT | \
+ CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK)
+#endif
+#define CY_CAPSENSE_BIST_CAP_IDAC_MODE_DEFAULT (CSD_IDACA_LEG1_MODE_Msk |\
+ CSD_IDACA_LEG2_MODE_Msk)
+
+
+/*******************************************************************************
+* Macros for the VDDA measurement test
+*******************************************************************************/
+
+/* SenseClkDivider value for VDDA measurement mode */
+#define CY_CAPSENSE_BIST_VDDA_SENSE_DIV_DEFAULT (0x4u)
+/* Minimal acceptable difference between the VDDA and VREF.
+ It is not allowed to have (VDDA - VREF) > CY_CAPSENSE_BIST_VDDA_MIN_DIFF. */
+#define CY_CAPSENSE_BIST_VDDA_MIN_DIFF (600u)
+/* VREF voltage value, used for the VDDA measurement */
+#define CY_CAPSENSE_BIST_VDDA_VREF_MIN_MV (1200u)
+/* VDDA measurement resolution */
+#define CY_CAPSENSE_BIST_VDDA_RES (2047u)
+/* The total capacitance value of reference capacitors */
+#define CY_CAPSENSE_BIST_VDDA_CREF (21500u)
+/* The IDAC gain value, used for the VDDA measurement */
+#define CY_CAPSENSE_BIST_VDDA_IDAC_LSB (37500u)
+/* The MAX possible IDAC code value. */
+#define CY_CAPSENSE_BIST_IDAC_MAX (127u)
+/* The number of initial conversions per sample, used for the VDDA measurement */
+#define CY_CAPSENSE_BIST_VDDA_INIT_CYCLES_NUM (1u)
+/* The number of normal conversions per sample, used for the VDDA measurement */
+#define CY_CAPSENSE_BIST_VDDA_NORM_CYCLES_NUM (2u)
+/* The duration of the Auto-zero stage in microseconds */
+#define CY_CAPSENSE_BIST_VDDA_AZ_TIME_US (5u)
+/* Acquisition time in microseconds */
+#define CY_CAPSENSE_BIST_VDDA_ACQ_TIME_US (10u)
+/* Acquisition time in microseconds */
+#define CY_CAPSENSE_BIST_VDDA_MAX_MODCLK (50000000u)
+/* Configures the count time A to bring Cref1 + Cref2 up from Vssa to Vrefhi with IDACB */
+#define CY_CAPSENSE_BIST_VDDA_MEASMODE_VREF (0x1uL << CSD_ADC_CTL_ADC_MODE_Pos)
+/*
+ * Configures count time B to bring Cref1 + Cref2 back up to Vrefhi with IDACB
+ * (after bringing them down for time A/2 cycles with IDACB sinking)
+ */
+#define CY_CAPSENSE_BIST_VDDA_MEASMODE_VREFBY2 (0x2uL << CSD_ADC_CTL_ADC_MODE_Pos)
+/* Configures the HSCMP polarity and count time C to source/sink Cref1 + Cref2 from Vin to Vrefhi */
+#define CY_CAPSENSE_BIST_VDDA_MEASMODE_VIN (0x3uL << CSD_ADC_CTL_ADC_MODE_Pos)
+
+/* Default HW block operation settings that are required for VDDA measurement */
+#define CY_CAPSENSE_BIST_VDDA_CONFIG_DEFAULT (CY_CAPSENSE_CSD_CONFIG_ENABLE_MSK |\
+ CY_CAPSENSE_CSD_CONFIG_SAMPLE_SYNC_MSK |\
+ CY_CAPSENSE_CSD_CONFIG_SENSE_EN_MSK |\
+ CY_CAPSENSE_CSD_CONFIG_DSI_COUNT_SEL_MSK)
+#define CY_CAPSENSE_BIST_VDDA_AMBUF_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_CSDCMP_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_HSCMP_DEFAULT (CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK |\
+ CY_CAPSENSE_CSD_HSCMP_AZ_EN_MSK)
+#define CY_CAPSENSE_BIST_VDDA_IDACA_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_IDACB_DEFAULT ((CY_CAPSENSE_CSD_IDACB_POL_DYN_DYNAMIC << \
+ CY_CAPSENSE_CSD_IDACB_POL_DYN_POS) |\
+ CY_CAPSENSE_CSD_IDACB_LEG3_EN_MSK)
+#define CY_CAPSENSE_BIST_VDDA_SW_RES_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_SENSE_PERIOD_DEFAULT (CY_CAPSENSE_BIST_VDDA_SENSE_DIV_DEFAULT)
+#define CY_CAPSENSE_BIST_VDDA_SENSE_DUTY_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_SEQ_INIT_CNT_DEFAULT (CY_CAPSENSE_BIST_VDDA_INIT_CYCLES_NUM)
+#define CY_CAPSENSE_BIST_VDDA_SEQ_NORM_CNT_DEFAULT (CY_CAPSENSE_BIST_VDDA_NORM_CYCLES_NUM)
+#define CY_CAPSENSE_BIST_VDDA_IO_SEL_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_SEQ_START_MEASURE (CY_CAPSENSE_CSD_SEQ_START_AZ0_SKIP_MSK |\
+ CY_CAPSENSE_CSD_SEQ_START_START_MSK)
+#define CY_CAPSENSE_BIST_VDDA_SW_HS_P_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMRH_STATIC_CLOSE)
+#define CY_CAPSENSE_BIST_VDDA_SW_HS_N_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCCD_STATIC_CLOSE)
+#define CY_CAPSENSE_BIST_VDDA_SW_SHIELD_SEL_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_SW_AMUXBUF_SEL_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_SW_BYP_SEL_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_SW_CMP_P_SEL_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_SW_CMP_N_SEL_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_SW_DSI_SEL_DEFAULT (0u)
+#define CY_CAPSENSE_BIST_VDDA_SW_FW_MOD_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CC_STATIC_CLOSE |\
+ CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CD_STATIC_CLOSE)
+#define CY_CAPSENSE_BIST_VDDA_SW_FW_TANK_SEL_DEFAULT (CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CC_STATIC_CLOSE |\
+ CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CD_STATIC_CLOSE)
+#define CY_CAPSENSE_BIST_VDDA_WDT_CYCLES_PER_LOOP (5u)
+#define CY_CAPSENSE_BIST_VDDA_MAX_16_BITS (65535u)
+/* In milliseconds */
+#define CY_CAPSENSE_BIST_VDDA_WDT_TIMEOUT (10000u)
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+/* CRC test-related functions */
+static cy_en_capsense_bist_status_t Cy_CapSense_CheckAllWidgetCRC(
+ cy_stc_capsense_context_t * context);
+
+/* Check Integrity Sensor Pins test-related functions */
+static cy_en_capsense_bist_status_t Cy_CapSense_SnsShortCheckSensor(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ uint32_t mode,
+ cy_stc_capsense_context_t * context);
+static cy_en_capsense_bist_status_t Cy_CapSense_SnsShortCheckElectrode(
+ uint32_t widgetId,
+ uint32_t ioSnsId,
+ uint32_t mode,
+ const cy_stc_capsense_context_t * context);
+static void Cy_CapSense_SnsShortUpdateTestResult(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ cy_stc_capsense_context_t * context);
+static cy_en_capsense_bist_status_t Cy_CapSense_SnsShortCheckAllSensors(
+ cy_stc_capsense_context_t * context);
+static void Cy_CapSense_SetPinDr(
+ cy_stc_capsense_pin_config_t const *ioPtr,
+ uint32_t value);
+static void Cy_CapSense_SetPinPc(
+ cy_stc_capsense_pin_config_t const *ioPtr,
+ uint32_t value);
+
+/* Measure Capacitance Sensor and Shield test-related functions */
+static void Cy_CapSense_BistMeasureCapacitanceSensorInit(
+ cy_stc_capsense_context_t * context);
+static void Cy_CapSense_BistMeasureCapacitanceSensorEnable(
+ cy_stc_capsense_context_t * context);
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensor(
+ uint32_t * cpPtr,
+ cy_stc_capsense_context_t * context);
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensorRun(
+ cy_stc_capsense_context_t * context);
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensorAll(
+ cy_stc_capsense_context_t * context);
+
+/* Measure Capacitance Capacitor test-related functions */
+static void Cy_CapSense_BistMeasureCapacitanceCapInit(
+ cy_stc_capsense_context_t * context);
+static void Cy_CapSense_BistMeasureCapacitanceCapEnable(
+ cy_stc_capsense_context_t * context);
+static void Cy_CapSense_BistMeasureCapacitanceSensorShieldEnable(
+ cy_stc_capsense_context_t * context);
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceCapRun(
+ uint32_t * ptrExtCapValue,
+ cy_stc_capsense_context_t * context);
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceCapAll(
+ cy_stc_capsense_context_t * context);
+
+/* Measure VDDA test-related functions */
+static void Cy_CapSense_BistMeasureVddaInit(
+ cy_stc_capsense_context_t * context);
+static void Cy_CapSense_BistMeasureVddaEnable(
+ cy_stc_capsense_context_t * context);
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureVddaRun(
+ cy_stc_capsense_context_t * context);
+
+/* Common functions for all tests */
+static void Cy_CapSense_BistSwitchHwConfig(
+ cy_en_capsense_bist_hw_config_t hwCfg,
+ cy_stc_capsense_context_t * context);
+static void Cy_CapSense_BistSwitchAllSnsPinState(
+ cy_en_capsense_bist_io_state_t desiredPinState,
+ const cy_stc_capsense_context_t * context);
+static void Cy_CapSense_BistSwitchAllShieldPinState(
+ cy_en_capsense_bist_io_state_t desiredPinState,
+ const cy_stc_capsense_context_t * context);
+static void Cy_CapSense_BistSwitchAllExternalCapPinState(
+ cy_en_capsense_bist_io_state_t desiredPinState,
+ const cy_stc_capsense_context_t * context);
+static void Cy_CapSense_SetShieldPinState(
+ uint32_t desiredDriveMode,
+ uint32_t desiredPinOutput,
+ en_hsiom_sel_t desiredHsiom,
+ const cy_stc_capsense_context_t * context);
+static void Cy_CapSense_BistConnectElectrode(
+ uint32_t widgetId,
+ uint32_t electrodeId,
+ const cy_stc_capsense_context_t * context);
+static void Cy_CapSense_BistDisconnectElectrode(
+ uint32_t widgetId,
+ uint32_t electrodeId,
+ const cy_stc_capsense_context_t * context);
+static uint32_t Cy_CapSense_BistWaitEndOfScan(
+ uint32_t watchdogCycleNum,
+ const cy_stc_capsense_context_t * context);
+/** \} \endcond */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunSelfTest
+****************************************************************************//**
+*
+* Runs built-in self-tests specified by the test enable mask.
+*
+* The function performs various self-tests on all the enabled widgets
+* and sensors in the project. Select the required set of tests
+* using the bit-mask in testEnMask parameter.
+*
+* Use CY_CAPSENSE_TST_RUN_SELF_TEST_MASK to execute all the self-tests or
+* any combination of the masks (defined in testEnMask parameter) to specify the
+* desired test list.
+*
+* To execute a single-element test (i.e. for one widget or one sensor),
+* the following low-level functions are available:
+* - Cy_CapSense_CheckCRCWidget()
+* - Cy_CapSense_CheckIntegritySensorPins()
+* - Cy_CapSense_MeasureCapacitanceSensor()
+* - Cy_CapSense_MeasureCapacitanceShield()
+* - Cy_CapSense_MeasureCapacitanceCap()
+* - Cy_CapSense_MeasureVdda()
+*
+* Refer to these functions descriptions for detail information
+* on the corresponding test.
+*
+* \param testEnMask
+* Specifies the tests to be executed. Each bit corresponds to one test. It is
+* possible to launch the function with any combination of the available tests.
+* - CY_CAPSENSE_BIST_CRC_WDGT - Verifies the RAM widget structure CRC
+* for all the widgets.
+* - CY_CAPSENSE_BIST_SNS_INTEGRITY - Checks all the sensors for a short
+* to GND / VDD / other sensors.
+* - CY_CAPSENSE_BIST_SNS_CAP - Measures all the sensors capacitance.
+* - CY_CAPSENSE_BIST_SHIELD_CAP - Measures the shield capacitance.
+* - CY_CAPSENSE_BIST_EXTERNAL_CAP - Measures the capacitance of the available
+* external capacitors.
+* - CY_CAPSENSE_BIST_VDDA - Measures the VDDA voltage.
+* - CY_CAPSENSE_TST_RUN_SELF_TEST_MASK - Executes all available tests.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a bit-mask with a status of execution of the specified tests:
+* - CY_CAPSENSE_BIST_SUCCESS_E - All the tests passed successfully.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The function was not
+* performed.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - A non-defined test was requested in the
+* testEnMask parameter or the context is
+* a NULL pointer. The function
+* was not performed.
+* - CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a previous
+* operation. The function was not performed.
+* - CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during
+* the measurement, you may need to repeat
+* the measurement.
+* - CY_CAPSENSE_BIST_FAIL_E - Any of tests specified by the testEnMask
+* parameters has faulted.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_RunSelfTest(
+ uint32_t testEnMask,
+ cy_stc_capsense_context_t * context)
+
+{
+ uint32_t tmpVal;
+ cy_en_capsense_bist_status_t bistStatus;
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+
+ if (0u == (testEnMask & (~CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK)))
+ {
+ if(NULL != context)
+ {
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ if(CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(context))
+ {
+ if (0u != (CY_CAPSENSE_BIST_CRC_WDGT & testEnMask))
+ {
+ bistStatus = Cy_CapSense_CheckAllWidgetCRC(context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ context->ptrBistContext->testResultMask |= (uint32_t)CY_CAPSENSE_BIST_CRC_WDGT;
+ }
+ }
+ /* The next group of tests is hardware-dependent, the request is to switch the sense method */
+ if(CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_BIST_E,
+ context))
+ {
+ if (0u != (CY_CAPSENSE_BIST_VDDA & testEnMask))
+ {
+ bistStatus = Cy_CapSense_MeasureVdda(&tmpVal, context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ context->ptrBistContext->testResultMask |= (uint32_t)CY_CAPSENSE_BIST_VDDA;
+ }
+ }
+ if (0u != (CY_CAPSENSE_BIST_EXTERNAL_CAP & testEnMask))
+ {
+ bistStatus = Cy_CapSense_BistMeasureCapacitanceCapAll(context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ context->ptrBistContext->testResultMask |= (uint32_t)CY_CAPSENSE_BIST_EXTERNAL_CAP;
+ }
+ }
+ if ((0u != (CY_CAPSENSE_BIST_SHIELD_CAP & testEnMask)) &&
+ (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn))
+ {
+ bistStatus = Cy_CapSense_MeasureCapacitanceShield(&tmpVal, context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ context->ptrBistContext->testResultMask |= (uint32_t)CY_CAPSENSE_BIST_SHIELD_CAP;
+ }
+ }
+ if (0u != (CY_CAPSENSE_BIST_SNS_INTEGRITY & testEnMask))
+ {
+ bistStatus = Cy_CapSense_SnsShortCheckAllSensors(context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ context->ptrBistContext->testResultMask |= (uint32_t)CY_CAPSENSE_BIST_SNS_INTEGRITY;
+ }
+ }
+ if (0u != (CY_CAPSENSE_BIST_SNS_CAP & testEnMask))
+ {
+ bistStatus = Cy_CapSense_BistMeasureCapacitanceSensorAll(context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ context->ptrBistContext->testResultMask |= (uint32_t)CY_CAPSENSE_BIST_SNS_CAP;
+ }
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_ERROR_E;
+ }
+ if (CY_CAPSENSE_BIST_FAIL_E != result)
+ {
+ result = CY_CAPSENSE_BIST_SUCCESS_E;
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_HW_BUSY_E;
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckCRCWidget
+****************************************************************************//**
+*
+* Checks the stored CRC of the \ref cy_stc_capsense_widget_context_t data
+* structure of the specified widget.
+*
+* This function validates the data integrity of the
+* \ref cy_stc_capsense_widget_context_t data structure of the specified widget
+* by calculating the CRC and comparing it with the stored CRC value of the
+* specified widget.
+*
+* Initially, after the device power up, the Cy_CapSense_Enable() function
+* calculates CRC for each widget and stores them in the .ptrWdgtCrc[] array
+* of the \ref cy_stc_capsense_bist_context_t structure. The test execution
+* compares this stored CRC value with the newly calculated and if the stored
+* and calculated CRC values differ:
+* 1. The calculated CRC is stored to the .wdgtCrcCalc field
+* of the \ref cy_stc_capsense_bist_context_t data structure.
+* 2. The widget ID is stored to the .crcWdgtId field.
+* 3. The CY_CAPSENSE_BIST_CRC_WDGT bit is set in the .testResultMask field.
+*
+* The function never clears the CY_CAPSENSE_BIST_CRC_WDGT bit.
+* If the CY_CAPSENSE_BIST_CRC_WDGT bit is set, the wdgtCrcCalc
+* and .crcWdgtId fields are not updated.
+*
+* It is recommended to use the Cy_CapSense_SetParam() function to change
+* the value of the \ref cy_stc_capsense_widget_context_t data structure elements
+* as the CRC is updated by Cy_CapSense_SetParam() function.
+*
+* You can initiate this test by the Cy_CapSense_RunSelfTest() function with
+* the CY_CAPSENSE_BIST_CRC_WDGT mask as an input.
+*
+* The function clears the CY_CAPSENSE_WD_WORKING_MASK bit of the .status
+* field in \ref cy_stc_capsense_widget_context_t structure if the calculated
+* CRC value differs to the stored CRC value.
+* Those non-working widgets are skipped by the high-level scanning and
+* processing functions. Restoring a widget to its working state should
+* be done by the application level.
+*
+* For details of the used CRC algorithm, refer to the Cy_CapSense_GetCRC()
+* function.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The stored CRC matches
+* the calculated CRC.
+* - CY_CAPSENSE_BIST_FAIL_E - The widget CRC differs to
+* the stored CRC.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameters are invalid.
+* The test was not executed.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The test was
+* not executed.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_CheckCRCWidget(
+ uint32_t widgetId,
+ cy_stc_capsense_context_t * context)
+{
+ uint16_t crcValue;
+ cy_stc_capsense_widget_context_t * ptrWdCxt;
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+
+ if(NULL != context)
+ {
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ if (context->ptrCommonConfig->numWd > widgetId)
+ {
+ crcValue = Cy_CapSense_GetCrcWidget(widgetId, context);
+ if ((context->ptrBistContext->ptrWdgtCrc[widgetId]) != crcValue)
+ {
+ /* Get a pointer to the specified widget context structure */
+ ptrWdCxt = &context->ptrWdContext[widgetId];
+
+ /* Write to the self-test data structure widgetId of the first badly-tested widget */
+ if (0Lu == (context->ptrBistContext->testResultMask & CY_CAPSENSE_BIST_CRC_WDGT))
+ {
+ context->ptrBistContext->wdgtCrcCalc = crcValue;
+ context->ptrBistContext->crcWdgtId = (uint8_t)widgetId;
+ context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_CRC_WDGT;
+ }
+ ptrWdCxt->status &= (uint8_t)~CY_CAPSENSE_WD_WORKING_MASK;
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_SUCCESS_E;
+ }
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckAllWidgetCRC
+****************************************************************************//**
+*
+* The internal function that checks CRC of all widget structures.
+*
+* The function calculates CRC of all widget structures and compare it
+* to the stored CRCs. It is called by the Cy_CapSense_RunSelfTest() function.
+* In the first case of failed comparison the function updates
+* testResultMask and returns the status. Next widgets are not checked.
+* The function use the Cy_CapSense_CheckCRCWidget() function.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the test processing:
+* - CY_CAPSENSE_BIST_SUCCESS_E if all widget CRC are OK;
+* - CY_CAPSENSE_BIST_FAIL_E if any widget CRC is wrong.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_CheckAllWidgetCRC(
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_SUCCESS_E;
+ uint32_t widgetId;
+
+ for (widgetId = 0u; widgetId < context->ptrCommonConfig->numWd; widgetId++)
+ {
+ if (CY_CAPSENSE_BIST_SUCCESS_E != (Cy_CapSense_CheckCRCWidget(widgetId, context)))
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ break;
+ }
+ }
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_UpdateCrcWidget
+****************************************************************************//**
+*
+* The internal function updates the CRC
+* of the \ref cy_stc_capsense_widget_context_t data structure
+* for the specified widget.
+*
+* The function implements the following functionality:
+* - Executes the Cy_CapSense_GetCRC() routine for the specified widget.
+* - Updates the self-test CRC array with the CRC value, calculated for the
+* specified widget.
+*
+* The CRC value is stored in the special wdgtCrc[CY_CAPSENSE_WIDGET_COUNT] array
+* declared in the cycfg_capsense.c file.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_UpdateCrcWidget(
+ uint32 widgetId,
+ cy_stc_capsense_context_t * context)
+{
+ uint16_t crcValue;
+
+ crcValue = Cy_CapSense_GetCrcWidget(widgetId, context);
+
+ /* Write the calculated CRC value to the self-test CRC array */
+ context->ptrBistContext->ptrWdgtCrc[widgetId] = crcValue;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckIntegritySensorBaseline
+****************************************************************************//**
+*
+* Checks if the baseline of the specified sensor is not corrupted
+* by comparing it with its inverse copy and checks if the baseline is
+* within the specified range.
+*
+* The function checks whether or not the baseline binary inverted to
+* its inverse copy is saved to the self-test baseline-inverse structure
+* and is within the user-defined limits. If the baseline does
+* not match its inverse copy or if the baseline is out of the user-defined
+* limits, the function sets the CY_CAPSENSE_BIST_BSLN_INTEGRITY bit
+* in the .testResultMask field of the \ref cy_stc_capsense_bist_context_t
+* structure.
+*
+* The test is integrated into the CapSense Middleware. All CapSense
+* processing functions like Cy_CapSense_ProcessAllWidgets()
+* or Cy_CapSense_UpdateSensorBaseline() automatically verify the baseline
+* value before using it and update its inverse copy after processing.
+* If a baseline update fails, a CY_RET_BAD_DATA result
+* is returned. The baseline initialization functions do not verify the
+* baseline and update the baseline inverse copy.
+*
+* This function does not update the CY_CAPSENSE_WD_WORKING_MASK bit of
+* the .status field in \ref cy_stc_capsense_widget_context_t structure
+* and is not available in the Cy_CapSense_RunSelfTest() function.
+*
+* Use this function to verify the uniformity of sensors, for example, at
+* mass-production or during an operation phase together with the
+* Cy_CapSense_CheckIntegritySensorRawcount() function.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID number of the sensor within the widget.
+* A macro for the sensor ID within the specified widget can be found in
+* the CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__SNS_ID.
+*
+* \param baselineHighLimit
+* Specifies the upper limit for a baseline.
+*
+* \param baselineLowLimit
+* Specifies the lower limit for a baseline.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The baseline is within the
+* specified range.
+* - CY_CAPSENSE_BIST_FAIL_E - The test failed and the baseline
+* is not binary inverted to its inverse
+* copy or is out of the specified limits.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* The test was not executed.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The test was not
+* executed.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorBaseline(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ uint16_t baselineHighLimit,
+ uint16_t baselineLowLimit,
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ uint32_t freqChIndex;
+ uint16_t bslnInv;
+ uint32_t freqChNumber;
+ uint32_t cxtOffset;
+ cy_stc_capsense_sensor_context_t *ptrSnsCxt;
+ cy_stc_capsense_widget_config_t const *ptrWdgtCfg;
+
+ if(NULL != context)
+ {
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ if ((context->ptrCommonConfig->numWd > widgetId) &&
+ (context->ptrWdConfig[widgetId].numSns > sensorId))
+ {
+ /* Get a pointer to the specified widget configuration structure */
+ ptrWdgtCfg = &context->ptrWdConfig[widgetId];
+ /* Get a pointer to the specified sensor context structure */
+ ptrSnsCxt = &ptrWdgtCfg->ptrSnsContext[sensorId];
+ /* Check for multi-frequency scan */
+ freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
+ /* Check baselines for all frequencies */
+ for(freqChIndex = 0u; freqChIndex < freqChNumber; freqChIndex++)
+ {
+ cxtOffset = sensorId + (freqChIndex * context->ptrCommonConfig->numSns);
+ bslnInv = (uint16_t)(~(ptrWdgtCfg->ptrBslnInv[cxtOffset]));
+ if ((ptrSnsCxt->bsln != bslnInv) ||
+ (ptrSnsCxt->bsln > baselineHighLimit) ||
+ (ptrSnsCxt->bsln < baselineLowLimit))
+ {
+ context->ptrBistContext->testResultMask |= (uint32_t)CY_CAPSENSE_BIST_BSLN_INTEGRITY;
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ break;
+ }
+ else
+ {
+ if (CY_CAPSENSE_BIST_FAIL_E != result)
+ {
+ result = CY_CAPSENSE_BIST_SUCCESS_E;
+ }
+ }
+ ptrSnsCxt += context->ptrCommonConfig->numSns;
+ }
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckIntegritySensorRawcount
+****************************************************************************//**
+*
+* Checks the raw count of the specified widget/sensor is within the specified
+* range.
+*
+* The raw count is within a specific range (based on the calibration target)
+* for good units. The function checks whether or not the raw count is within
+* the user-defined limits in the ranges function arguments.
+* If the raw count is out of limits, this function sets the
+* CY_CAPSENSE_BIST_RAW_INTEGRITY bit in the .testResultMask field of the
+* \ref cy_stc_capsense_bist_context_t structure.
+*
+* This function does not update the CY_CAPSENSE_WD_WORKING_MASK bit of
+* the .status field in \ref cy_stc_capsense_widget_context_t structure
+* and is not available in the Cy_CapSense_RunSelfTest() function.
+*
+* Use this function to verify the uniformity of sensors, for example, at
+* mass-production or during an operation phase together with the
+* Cy_CapSense_CheckIntegritySensorBaseline() function.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID number of the sensor within the widget.
+* A macro for the sensor ID within the specified widget can be found in
+* the CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__SNS_ID.
+*
+* \param rawcountHighLimit
+* Specifies the upper limit for the widget/sensor raw count.
+*
+* \param rawcountLowLimit
+* Specifies the lower limit for the widget/sensor raw count.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The raw count is within the
+* specified range.
+* - CY_CAPSENSE_BIST_FAIL_E - The test failed and raw count is out
+* of the specified limits.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* The test was not executed.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The test was not
+* executed.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorRawcount(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ uint16_t rawcountHighLimit,
+ uint16_t rawcountLowLimit,
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ uint32_t freqChIndex;
+ uint32_t freqChNumber;
+ cy_stc_capsense_sensor_context_t *ptrSnsCxt;
+ cy_stc_capsense_widget_config_t const *ptrWdgtCfg;
+
+ if(NULL != context)
+ {
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ if ((context->ptrCommonConfig->numWd > widgetId) &&
+ (context->ptrWdConfig[widgetId].numSns > sensorId))
+ {
+ /* Find a pointer to the specified widget configuration structure */
+ ptrWdgtCfg = &context->ptrWdConfig[widgetId];
+ /* Find a pointer to the specified sensor context structure */
+ ptrSnsCxt = &ptrWdgtCfg->ptrSnsContext[sensorId];
+ /* Check for multi-frequency scan */
+ freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
+ /* Check raw counts for all frequencies */
+ for(freqChIndex = 0u; freqChIndex < freqChNumber; freqChIndex++)
+ {
+ if ((ptrSnsCxt->raw > rawcountHighLimit) ||
+ (ptrSnsCxt->raw < rawcountLowLimit))
+ {
+ context->ptrBistContext->testResultMask |= (uint32_t)CY_CAPSENSE_BIST_RAW_INTEGRITY;
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ break;
+ }
+ else
+ {
+ if (CY_CAPSENSE_BIST_FAIL_E != result)
+ {
+ result = CY_CAPSENSE_BIST_SUCCESS_E;
+ }
+ }
+ ptrSnsCxt += context->ptrCommonConfig->numSns;
+ }
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckIntegritySensorPins
+****************************************************************************//**
+*
+* Checks the specified widget/sensor for shorts to GND, VDD or other sensors.
+*
+* This function performs several sub-tests to verify the specified sensor
+* is not electrically shorted and is in a good condition to reliably detect
+* user interactions.
+*
+* This function performs tests to check if the specified sensor is shorted to:
+* * GND
+* * VDD
+* * Other GPIOs used by CapSense (such as sensors, Tx, Rx,
+* shield electrodes, and external capacitors)
+* * Other non-CapSense GPIOs (only if they are configured
+* in a strong high or low state during the test execution).
+*
+* The absolute resistance of an electrical short must be less than 1500 Ohm
+* including all series resistors on a sensor for a short to be detected
+* to GND, VDD or GPIOs. For example, if a series resistor on a sensor is
+* 560 Ohm (as recommended) and the sensor is shorted with another sensor,
+* the function can detect a short with a short resistance up to 380 Ohm as
+* there are two 560 ohm resistors between the shorted sensor GPIOs.
+*
+* The function executes the following flow to detect a short:
+* * Configures all CapSense controlled GPIOs to strong-drive-high,
+* and the specified sensor GPIO to resistive pull down mode.
+* * Waits for a delay (defined by .snsIntgShortSettlingTime field
+* of the \ref cy_stc_capsense_bist_context_t structure) to get established
+* all transient processes.
+* * Checks the status of the specified sensor for the expected state
+* (logic low).
+* * Configures all CapSense controlled GPIOs to strong-drive-low,
+* and the specified sensor GPIO to resistive pull up mode.
+* * Waits for the above mentioned delay.
+* * Checks the status of the specified sensor for the expected state
+* (logic high).
+* * Stores the test result in the CapSense Data Structure.
+* A short is reported only when the sensor status check returns
+* an unexpected state.
+*
+* Due to the sensor parasitic capacitance and internal pull-up/down resistance,
+* logic high-to-low (and vice versa) transitions require a settling time before
+* checking the sensor status. A 2us delay is used as a settling time and can
+* be changed using the .snsIntgShortSettlingTime field
+* of the cy_stc_capsense_bist_context_t structure.
+*
+* If a short is detected this function updates the following statuses:
+* * The widget ID is stored to the .shortedWdId field
+* of the \ref cy_stc_capsense_bist_context_t structure.
+* * The sensor ID is stored to the .shortedSnsId field
+* of the \ref cy_stc_capsense_bist_context_t structure.
+* * The CY_CAPSENSE_BIST_SNS_SHORT bit is set in the .testResultMask field
+* of the \ref cy_stc_capsense_bist_context_t structure.
+* * If CY_CAPSENSE_BIST_SNS_SHORT is already set due to a previously
+* detected fault on any of the sensor, this function does not update
+* the .shortedWdId and .shortedSnsId fields. For this reason,
+* clear the CY_CAPSENSE_BIST_SNS_SHORT bit prior calling this function.
+* * The widget is disabled by clearing the CY_CAPSENSE_WD_WORKING_MASK bit
+* in the .status field of the \ref cy_stc_capsense_widget_context_t structure
+* of the specified widget.
+* The disabled widget is ignored by high-level functions of scanning / data
+* processing. To restore the widget operation
+* the application layer should manually set the CY_CAPSENSE_WD_WORKING_MASK
+* bit.
+*
+* To check all the project sensors at once, use the Cy_CapSense_RunSelfTest()
+* function with the CY_CAPSENSE_BIST_SNS_SHORT mask.
+*
+* To detect an electrical short or fault condition with resistance
+* higher than 1500 ohm, the Cy_CapSense_GetSensorCapacitance() function can
+* be used as the fault condition affects the measured sensor capacitance.
+*
+* This test can be executed only if the CapSense Middleware is in the IDLE
+* state. This function must not be called while CapSense Middleware is busy.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID of the sensor (electrode for CSX widgets) within the widget
+* to be tested.
+*
+* For the CSD widgets, a macro for the sensor ID within the specified widget
+* can be found in the CapSense Configuration header file (cycfg_capsense.h)
+* defined as CY_CAPSENSE__SNS_ID.
+*
+* For the CSX widgets, sensorId is an electrode ID and is defined as Rx ID
+* or Tx ID. The first Rx in a widget corresponds to electrodeId = 0, the
+* second Rx in a widget corresponds to electrodeId = 1, and so on.
+* The last Tx in a widget corresponds to electrodeId = (RxNum + TxNum - 1).
+* Macros for Rx and Tx IDs can be found in the CapSense Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense__RX_ID
+* * CapSense__TX_ID.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The sensor pin(s) are valid
+* for CapSense operations.
+* - CY_CAPSENSE_BIST_FAIL_E - A short is detected on the
+* specified sensor.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* The test was not executed.
+* - CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a
+* previous operation. The function
+* was not executed.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The test was not
+* executed.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorPins(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ uint32_t numWdgtElectrodes;
+
+ if(NULL != context)
+ {
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ if (context->ptrCommonConfig->numWd > widgetId)
+ {
+ /* Get a total number of the widget elements: for CSX it is numRows + numCols, for CSD it is totalNumSns */
+ if ((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E == context->ptrWdConfig[widgetId].senseMethod)
+ {
+ /* For the CSX widgets, get the index of the Rx electrode */
+ numWdgtElectrodes = context->ptrWdConfig[widgetId].numRows +
+ (uint32_t)context->ptrWdConfig[widgetId].numCols;
+ }
+ else
+ {
+ numWdgtElectrodes = context->ptrWdConfig[widgetId].numSns;
+ }
+ if (numWdgtElectrodes > sensorId)
+ {
+ /* Initialize the result */
+ result = CY_CAPSENSE_BIST_SUCCESS_E;
+ /* Release previously-captured HW resources by the other mode and capture them for BIST */
+ if (CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchSensingMode(
+ (uint8_t)CY_CAPSENSE_SENSE_METHOD_BIST_E, context))
+ {
+ /* Switch the HW resource configuration to the sensor short test */
+ Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_SHORT_E, context);
+
+ /* Set all CapSense pins to strong-high */
+ Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+ Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+ Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+ /* Wait for the maximum possible external capacitor charging time */
+ Cy_SysLib_DelayUs(context->ptrBistContext->capacitorSettlingTime);
+
+ if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_SnsShortCheckSensor(widgetId, sensorId, CY_CAPSENSE_BIST_DR_PIN2VDD, context))
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ }
+
+ /* Set all CapSense pins to strong-low */
+ Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ /* Wait for the maximum possible external capacitor charging time */
+ Cy_SysLib_DelayUs(context->ptrBistContext->capacitorSettlingTime);
+
+ if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_SnsShortCheckSensor(widgetId, sensorId, CY_CAPSENSE_BIST_DR_PIN2GND, context))
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_HW_BUSY_E;
+ }
+ }
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SnsShortCheckSensor
+****************************************************************************//**
+*
+* The internal function checks if the specified sensor element is shorted
+* to the VDD or GND level by configuring each of its electrodes to pull-up or
+* pull-down and check their state.
+*
+* An additional delay is added between configuring the electrode and
+* reading its state to establish the transition process for cases
+* with big capacitance and short resistance.
+* The function assumes all rest electrodes are set to strong drive mode,
+* so the sensor-to-sensor short condition is also detected.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID of the sensor element within the widget to change
+* its pin state.
+* * For the CSD widgets, use the sensor ID. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* file defined as CY_CAPSENSE__SNS_ID.
+* * For the CSX widgets use either Rx ID or Tx ID.
+* The first Rx in a widget corresponds to sensorElement = 0; the second
+* Rx in a widget corresponds to sensorElement = 1, and so on.
+* The last Tx in a widget corresponds to sensorElement = (RxNum + TxNum - 1).
+* A macro for the Rx ID or Tx ID can be found in the cycfg_capsense.h
+* file defined as CY_CAPSENSE___ID.
+*
+* \param mode
+* Specifies the test mode, either:
+* * CY_CAPSENSE_BIST_DR_PIN2GND means sensor is configured
+* to pull-up and checked for logical 0
+* * CY_CAPSENSE_BIST_DR_PIN2VDD means sensor is configured
+* to pull-down and checked for logical 1
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The sensor pin(s) are not shorted.
+* - CY_CAPSENSE_BIST_FAIL_E - A short is detected on the specified sensor.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_SnsShortCheckSensor(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ uint32_t mode,
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_bist_status_t result;
+ uint32_t ioSnsId;
+
+ if ((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E == context->ptrWdConfig[widgetId].senseMethod)
+ {
+ /* For the CSX widgets, get the index of the Rx electrode */
+ ioSnsId = sensorId / context->ptrWdConfig[widgetId].numRows;
+ result = Cy_CapSense_SnsShortCheckElectrode(widgetId, ioSnsId, mode, context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E == result)
+ {
+ /* For the CSX widgets, get the index of the Tx electrode */
+ ioSnsId = (uint32_t)(sensorId % context->ptrWdConfig[widgetId].numRows) +
+ (uint32_t)context->ptrWdConfig[widgetId].numCols;
+ result = Cy_CapSense_SnsShortCheckElectrode(widgetId, ioSnsId, mode, context);
+ }
+ }
+ else
+ {
+ result = Cy_CapSense_SnsShortCheckElectrode(widgetId, sensorId, mode, context);
+ }
+
+ if (CY_CAPSENSE_BIST_SUCCESS_E != result)
+ {
+ Cy_CapSense_SnsShortUpdateTestResult(widgetId, sensorId, context);
+ }
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: CapSense_SnsShortCheckElectrode
+****************************************************************************//**
+*
+* This internal function checks if a sensor or Rx or Tx electrode is shorted
+* to VDD or GND by configuring each of its pins to pull-up or pull-down
+* and checks its state.
+*
+* An additional delay is added between configuring the electrode and
+* reading its state to establish the transition process for cases
+* with big capacitance and short resistance.
+* The function assumes all rest electrodes are set to strong drive mode,
+* so the sensor-to-sensor short condition is also detected.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param ioSnsId
+* Specifies the ID number of the sensor (Rx or Tx electrode for CSX widgets)
+* within the widget to be processed.
+*
+* \param mode
+* Specifies the test mode, either:
+* * CY_CAPSENSE_BIST_DR_PIN2GND means sensor is configured
+* to pull-up and checked for logical 0
+* * CY_CAPSENSE_BIST_DR_PIN2VDD means sensor is configured
+* to pull-down and checked for logical 1
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The sensor pin(s) are not shorted.
+* - CY_CAPSENSE_BIST_FAIL_E - A short is detected on the specified sensor.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_SnsShortCheckElectrode(
+ uint32_t widgetId,
+ uint32_t ioSnsId,
+ uint32_t mode,
+ const cy_stc_capsense_context_t * context)
+{
+ uint32_t i;
+ uint32_t eltdNum;
+ uint32_t eltdState;
+ uint32_t eltdDM = CY_GPIO_DM_PULLDOWN;
+ cy_en_capsense_bist_status_t result;
+ const cy_stc_capsense_pin_config_t *ioPtr = context->ptrWdConfig[widgetId].ptrEltdConfig[ioSnsId].ptrPin;
+
+ if (CY_CAPSENSE_BIST_DR_PIN2GND == mode)
+ {
+ eltdDM = CY_GPIO_DM_PULLUP;
+ }
+
+ eltdNum = context->ptrWdConfig[widgetId].ptrEltdConfig[ioSnsId].numPins;
+
+ /* Loop through all electrodes of the specified sensor */
+ for (i = 0u; i < eltdNum; i++)
+ {
+ /* Set pin Drive mode and data register */
+ Cy_CapSense_SetPinDr(ioPtr, (mode ^ 0x01u));
+ Cy_CapSense_SetPinPc(ioPtr, eltdDM);
+ /* Wait for establishing the transition process */
+ Cy_SysLib_DelayUs((uint16_t)context->ptrBistContext->snsIntgShortSettlingTime);
+ /* Read the electrode state */
+ eltdState = Cy_GPIO_Read(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber);
+ if (CY_CAPSENSE_BIST_DR_PIN2GND != eltdState)
+ {
+ eltdState = CY_CAPSENSE_BIST_DR_PIN2VDD;
+ }
+ /* Revert the electrode to the default Drive mode */
+ Cy_CapSense_SetPinDr(ioPtr, mode);
+ Cy_CapSense_SetPinPc(ioPtr, CY_GPIO_DM_STRONG_IN_OFF);
+ /* Check the electrode state */
+ if (mode == eltdState)
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ break;
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_SUCCESS_E;
+ }
+ /* Get the next electrode */
+ ioPtr++;
+ }
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SnsShortUpdateTestResult
+****************************************************************************//**
+* The internal function updates the BIST data structure and Widget Working bit
+* in the .status field of the cy_stc_capsense_widget_context_t structure.
+*
+* The function resets a Widget Working bit, checks the .testResultMask field
+* of the cy_stc_capsense_bist_context_t structure
+* for the CY_CAPSENSE_BIST_SNS_INTEGRITY bit and if it was not set to 1,
+* the function sets it and memorizes widgetId and sensorId
+* in corresponding fields of the cy_stc_capsense_bist_context_t structure.
+*
+* \param widgetId
+* Specifies the ID number of the widget to be processed.
+*
+* \param sensorId
+* Specifies the ID number of the sensor within the widget which
+* will be processed.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_SnsShortUpdateTestResult(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ cy_stc_capsense_context_t * context)
+{
+ context->ptrWdContext[widgetId].status &= (uint8_t)~CY_CAPSENSE_WD_WORKING_MASK;
+ if (0Lu == (context->ptrBistContext->testResultMask & CY_CAPSENSE_BIST_SNS_INTEGRITY))
+ {
+ /* Write to the BIST context structure widgetId and sensorId of the first shorted sensor */
+ context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SNS_INTEGRITY;
+ context->ptrBistContext->shortedWdId = (uint8_t)widgetId;
+ context->ptrBistContext->shortedSnsId = (uint8_t)sensorId;
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SnsShortCheckAllSensors
+****************************************************************************//**
+*
+* The internal function that checks for all the sensors short.
+*
+* The function that checks for shorts on VDD/GND or to another sensors of all
+* sensor (not electrode) by using the Cy_CapSense_SnsShortCheckSensor() function.
+* The function is called by the Cy_CapSense_RunSelfTest() function.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the test processing:
+* - CY_CAPSENSE_BIST_SUCCESS_E if test passed successfully;
+* - CY_CAPSENSE_BIST_FAIL_E if any sensor of any widget is
+* shorted to VDD or GND.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_SnsShortCheckAllSensors(
+ cy_stc_capsense_context_t * context)
+{
+ uint32_t widgetId;
+ uint32_t sensorId;
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_SUCCESS_E;
+
+ /* Previously-captured HW resources were released by the other mode in the RunSelfTest function */
+ /* Switch HW resource configuration to sensor short test */
+ Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_SHORT_E, context);
+
+ Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+ Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+ Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+ /* Wait for the maximum possible external capacitor charging time */
+ Cy_SysLib_DelayUs(context->ptrBistContext->capacitorSettlingTime);
+
+ for (widgetId = 0u; widgetId < context->ptrCommonConfig->numWd; widgetId++)
+ {
+ for (sensorId = 0u; sensorId < context->ptrWdConfig[widgetId].numSns; sensorId++)
+ {
+ if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_SnsShortCheckSensor(widgetId, sensorId, CY_CAPSENSE_BIST_DR_PIN2VDD, context))
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ break;
+ }
+ }
+ }
+
+ Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ /* Wait for the maximum possible external capacitor charging time */
+ Cy_SysLib_DelayUs(context->ptrBistContext->capacitorSettlingTime);
+
+ for (widgetId = 0u; widgetId < context->ptrCommonConfig->numWd; widgetId++)
+ {
+ for (sensorId = 0u; sensorId < context->ptrWdConfig[widgetId].numSns; sensorId++)
+ {
+ if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_SnsShortCheckSensor(widgetId, sensorId, CY_CAPSENSE_BIST_DR_PIN2GND, context))
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ break;
+ }
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SetPinDr
+****************************************************************************//**
+*
+* The internal function that sets a certain pin output data register (DR).
+*
+* The function sets a pin output data register (DR) in a desired state.
+*
+* \param *ioPtr
+* A pointer to the specified pin in the widget pin configuration structure.
+*
+* \param value
+* A port output data which will be set for the pin.
+*
+*******************************************************************************/
+static void Cy_CapSense_SetPinDr(
+ cy_stc_capsense_pin_config_t const *ioPtr,
+ uint32_t value)
+{
+ uint32_t interruptState;
+
+ /* Set a data register */
+ interruptState = Cy_SysLib_EnterCriticalSection();
+ Cy_GPIO_Write(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber, value);
+ Cy_SysLib_ExitCriticalSection(interruptState);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SetPinPc
+****************************************************************************//**
+*
+* The internal function that sets a certain pin output drive mode (PC).
+*
+* The function sets a pin port control register (PC) in a desired state.
+*
+* \param *ioPtr
+* A pointer to the specified pin in the widget pin configuration structure.
+*
+* \param value
+* Drive mode to be set for the pin.
+*
+*******************************************************************************/
+static void Cy_CapSense_SetPinPc(
+ cy_stc_capsense_pin_config_t const *ioPtr,
+ uint32_t value)
+{
+ uint32_t interruptState;
+
+ /* Update the port configuration register (Drive mode) */
+ interruptState = Cy_SysLib_EnterCriticalSection();
+ Cy_GPIO_SetDrivemode(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber, value);
+ Cy_SysLib_ExitCriticalSection(interruptState);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceSensor
+****************************************************************************//**
+*
+* Measures the specified CSD sensor / CSX electrode capacitance.
+*
+* This function measures the capacitance of the sensor (electrode for CSX
+* widgets) and returns the measurement status. For a CSX sensor, the
+* measurement is done on either Rx or Tx electrode.
+* For a CSD sensor, measurement is done on a sensor (refer to the
+* sensorId parameter description).
+* If the specified sensor (electrode) is a ganged sensor, the capacitance
+* is measured for all the pins ganged together that belong to this sensor
+* (electrode).
+*
+* The measured capacitance is stored in the .eltdCap[] array.
+* The .ptrEltdCapacitance field of the
+* \ref cy_stc_capsense_widget_config_t structure contains a pointer to
+* the first widget sensor (electrode) element within the .eltdCap[] array.
+*
+* In addition to the measuring sensor (electrode) capacitance, this function
+* is used to identify various fault conditions with sensors such
+* as electrically-opened sensors. For example, the PCB track is broken
+* or shorted to other nodes in the system - in all of these conditions,
+* this function returns elevated capacitance which can be compared
+* against predetermined capacitance for the sensor to detect a
+* fault condition.
+*
+* The sensor capacitance is measured independently of the sensor scan
+* configuration. For the capacitance measurement, the CSD sensing method is used.
+* The measurements consists of up to four scans with different IDAC current.
+* The IDAC current of the first measurement is 6 uA and each next measurement
+* the IDAC current increase by four times. The default scanning parameters
+* are the following:
+* * I (6 uA) is the current equal to IDAC Gain * IDAC Code
+* (Compensation IDAC is disabled).
+* * Res (12 bits) is the scanning resolution.
+* * Vref (1.2 V) is the reference voltage.
+* * SnsClk (375 kHz) is the sensor clock frequency.
+*
+* If the scanning raw count is within 7.5% to 45% range of a maximum raw count
+* the raw count is converted into capacitance using the following equation:
+*
+* Cs = Rawcount * I / ((2^Res - 1) * Vref * SnsClk)
+*
+* where:
+* * Cs is the sensor capacitance.
+* * Rawcount is the measured raw count value.
+*
+* If the raw count is less than 7.5% of the maximum limit (2^Res - 1), the
+* function stops scanning the sequence and returns the
+* CY_CAPSENSE_BIST_LOW_LIMIT_E status.
+*
+* If the raw count is between 7.5% and 45% of the maximum, the function
+* calculates the sensor capacitance, updates the register map and
+* returns CY_CAPSENSE_BIST_SUCCESS_E status.
+*
+* If the raw count is above 45% of the maximum, the function repeats
+* scanning with a 4x increased IDAC current (up to four scans in total).
+*
+* The minimum measurable input by this function is 1pF and the
+* maximum is either 384pF or limited by the RC time constant
+* (Cs < 1 / (2*5*SnsClk*R), where R is the total sensor series
+* resistance that includes on-chip GPIO resistance ~500 Ohm and
+* external series resistance). The measurement accuracy is about 15%.
+*
+* By default, all CapSense sensors (electrodes) that are not being
+* measured are configured to the strong-drive-low state. The shield electrode
+* is also configured to the strong-drive-low state.
+*
+* By default, the Cmod capacitor is used for the measurement. If a dedicated
+* Cmod is not available (e.g. the design has CSX widgets only), CintA and CintB
+* capacitors are combined together by the firmware to form a single integration
+* capacitor for the measurement.
+*
+* The sensor measurement can be done on all the sensors using
+* the Cy_CapSense_RunSelfTest() function along with
+* the CY_CAPSENSE_BIST_SNS_CAP mask.
+*
+* This function must not be called while the CSD HW block is busy by another
+* state.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID of the sensor (electrode for CSX widgets) within the widget
+* to be measured.
+*
+* For the CSD widgets, a macro for the sensor ID within the specified widget
+* can be found in the CapSense Configuration header file (cycfg_capsense.h)
+* defined as CY_CAPSENSE__SNS_ID.
+*
+* For the CSX widgets, sensorId is an electrode ID and is defined as Rx ID
+* or Tx ID. The first Rx in a widget corresponds to electrodeId = 0, the
+* second Rx in a widget corresponds to electrodeId = 1, and so on.
+* The last Tx in a widget corresponds to electrodeId = (RxNum + TxNum - 1).
+* Macros for Rx and Tx IDs can be found in the CapSense Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense__RX_ID
+* * CapSense__TX_ID.
+*
+* \param ptrValue
+* The pointer to the measured capacitance in femtofarads.
+* The user declares a variable of the uint32_t type and passes the variable
+* pointer as the function parameter. If the ptrValue parameter is NULL,
+* the capacitance value is not returned through the parameter but still stored
+* in the corresponding field of the data structure.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes
+* successfully, the result is valid.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* The measurement was not executed.
+* - CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a
+* previous operation.
+* The measurement was not executed.
+* - CY_CAPSENSE_BIST_LOW_LIMIT_E - The measurement was executed and
+* the scanning result is below
+* the minimum possible value.
+* The measurement result could be invalid.
+* The sensor might be shorted to VDD
+* or a sensor PCB track
+* was broken (open sensor).
+* - CY_CAPSENSE_BIST_HIGH_LIMIT_E - The measurement was executed and
+* the scanning result is above the
+* maximum possible value.
+* The measurement result could be invalid.
+* The sensor might be shorted to GND.
+* - CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during
+* the measurement.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The measurement was not
+* executed.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSensor(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ uint32_t * ptrValue,
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ cy_en_capsense_bist_io_state_t desiredIoState;
+ uint32_t numWdgtElectrodes;
+ cy_en_capsense_bist_hw_config_t hwConfiguration;
+ uint32_t convNumber;
+
+ if(NULL != context)
+ {
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ if ((context->ptrCommonConfig->numWd > widgetId))
+ {
+ /* Get a total number of the widget elements: for CSX, it is numRows + numCols, for CSD, it is totalNumSns */
+ if ((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E == context->ptrWdConfig[widgetId].senseMethod)
+ {
+ /* For CSX widgets, get the index of the Rx electrode */
+ numWdgtElectrodes = context->ptrWdConfig[widgetId].numRows +
+ (uint32_t)context->ptrWdConfig[widgetId].numCols;
+ }
+ else
+ {
+ numWdgtElectrodes = context->ptrWdConfig[widgetId].numSns;
+ }
+ if (numWdgtElectrodes > sensorId)
+ {
+ /* Release previously-captured HW resources by other mode and capture them for BIST */
+ if (CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchSensingMode(
+ (uint8_t)CY_CAPSENSE_SENSE_METHOD_BIST_E, context))
+ {
+ /* Set the BUSY status */
+ context->ptrCommonContext->status = CY_CAPSENSE_BUSY;
+ /* Choose an inactive sensor connection (ISC) depending on the widget type */
+ switch (context->ptrWdConfig[widgetId].senseMethod)
+ {
+ case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E:
+ desiredIoState = context->ptrBistContext->eltdCapCsdISC;
+ break;
+ case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E:
+ desiredIoState = context->ptrBistContext->eltdCapCsxISC;
+ break;
+ default:
+ desiredIoState = CY_CAPSENSE_BIST_IO_UNDEFINED_E;
+ break;
+ }
+
+ hwConfiguration = CY_CAPSENSE_BIST_HW_ELTD_CAP_E;
+ if (CY_CAPSENSE_BIST_IO_SHIELD_E == desiredIoState)
+ {
+ hwConfiguration = CY_CAPSENSE_BIST_HW_ELTD_CAP_SH_E;
+ }
+ /* Switch the HW resource configuration to the sensor element capacitance measurement */
+ Cy_CapSense_BistSwitchHwConfig(hwConfiguration, context);
+ Cy_CapSense_BistSwitchAllSnsPinState(desiredIoState, context);
+ Cy_CapSense_BistSwitchAllShieldPinState(desiredIoState, context);
+ /* Set the divider value for the mod clock 1u lower than the desired divider */
+ Cy_CapSense_SetClkDivider(((uint32_t)context->ptrBistContext->eltdCapModClk - 1u), context);
+ /* Set the divider value for the sense clock (1u lower than the desired divider) */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD, ((uint32_t)context->ptrBistContext->eltdCapSnsClk - 1u));
+ /* Calculate the number of sub-conversions */
+ convNumber = (uint32_t)((0x01uL << context->ptrBistContext->eltdCapResolution) / context->ptrBistContext->eltdCapSnsClk);
+ if (convNumber == 0u)
+ {
+ convNumber = 1u;
+ }
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_NORM_CNT, convNumber);
+
+ Cy_CapSense_BistConnectElectrode(widgetId, sensorId, context);
+ result = Cy_CapSense_BistMeasureCapacitanceSensor(&context->ptrWdConfig[widgetId].ptrEltdCapacitance[sensorId], context);
+ Cy_CapSense_BistDisconnectElectrode(widgetId, sensorId, context);
+ if(NULL != ptrValue)
+ {
+ *ptrValue = context->ptrWdConfig[widgetId].ptrEltdCapacitance[sensorId];
+ }
+ /* Clear the BUSY flag */
+ context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY;
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_HW_BUSY_E;
+ }
+ }
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceShield
+****************************************************************************//**
+*
+* Measures shield electrode capacitance.
+*
+* This function measures the capacitance of the shield electrode and
+* returns a status of this measurement. The measurement result in femtofarads
+* is stored in the .shieldCap field of the \ref cy_stc_capsense_bist_context_t
+* structure. If the shield consists of several electrodes, the total
+* capacitance of all shield electrodes is reported.
+*
+* This function uses an algorithm identical to the sensor capacitance
+* measurement. Refer to the Cy_CapSense_MeasureCapacitanceSensor() function
+* for more details.
+*
+* In addition to measuring shield capacitance, this function is used to
+* identify various fault conditions with a shield electrode such as an
+* electrically open shield electrode, e.g. the PCB track is broken or
+* shorted to other nodes in the system - in all of these conditions,
+* this function returns elevated capacitance that can be compared
+* against pre-determined capacitance for the shield electrode to
+* detect a fault condition.
+*
+* By default, all CapSense sensors (electrodes) are configured to
+* the strong-drive-low state.
+*
+* By default, the Cmod capacitor is used for the measurement. If a dedicated
+* Cmod is not available (e.g. the design has CSX widgets only), CintA and CintB
+* capacitors are combined together by the firmware to form a single integration
+* capacitor which is used for measurement.
+*
+* This test can be executed using the CapSense_RunSelfTest()
+* function with the CY_CAPSENSE_BIST_SHIELD_CAP mask.
+*
+* \param ptrValue
+* The pointer to the variable the measured capacitance is stored. The user
+* should declare a variable of uint32_t type and pass the variable pointer as
+* the function parameter. If the ptrValue parameter is NULL then the shield
+* capacitance value is not returned through the parameter but is still stored
+* in the .shieldCap field of the \ref cy_stc_capsense_bist_context_t structure.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes
+* successfully, the result is valid.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* The measurement was not executed.
+* - CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a
+* previous operation. The measurement
+* was not executed.
+* - CY_CAPSENSE_BIST_LOW_LIMIT_E - The measurement was executed but
+* the measured raw count is below
+* the minimum possible value.
+* The measurement result could be invalid.
+* The shield might be shorted to VDD
+* or a shield PCB track
+* is broken (the open shield electrode).
+* - CY_CAPSENSE_BIST_HIGH_LIMIT_E - The measurement was executed but the
+* measured raw count is above the
+* maximum possible value.
+* The measurement result is invalid.
+* The sensor might be shorted to GND.
+* - CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during
+* the measurement.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The measurement was not
+* executed.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceShield(
+ uint32_t * ptrValue,
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ uint32_t convNumber;
+
+ if(NULL != context)
+ {
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ if((0u != context->ptrCommonConfig->csdShieldNumPin) ||
+ (CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->shieldCapISC))
+ {
+ /* Release previously-captured HW resources by the other mode and capture them for BIST */
+ if (CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_BIST_E, context))
+ {
+ /* Set the BUSY status */
+ context->ptrCommonContext->status = CY_CAPSENSE_BUSY;
+
+ /* Set all sensor pins to an ISC */
+ if(CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->shieldCapISC)
+ {
+ Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_SENSE_E, context);
+ }
+ else
+ {
+ Cy_CapSense_BistSwitchAllSnsPinState(context->ptrBistContext->shieldCapISC, context);
+ }
+
+ /* Connect shield electrode(s) to Analog bus A to measure the capacitance */
+ Cy_CapSense_SetShieldPinState(CY_CAPSENSE_CSD_SCAN_PIN_DM, 0u, CY_CAPSENSE_HSIOM_SEL_CSD_SENSE, context);
+ /* Switch theHW resource configuration to the sensor short test */
+ Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_ELTD_CAP_E, context);
+ /* Set the divider value for mod clock (1u lower than the desired divider) */
+ Cy_CapSense_SetClkDivider(((uint32_t)context->ptrBistContext->eltdCapModClk - 1u), context);
+ /* Set the divider value for the sense clock (1u lower than the desired divider) */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD, ((uint32_t)context->ptrBistContext->eltdCapSnsClk - 1u));
+ /* Calculate the conversion number to rich the desired resolution */
+ convNumber = (uint32_t)((0x01uL << context->ptrBistContext->eltdCapResolution) / context->ptrBistContext->eltdCapSnsClk);
+ if (convNumber == 0u)
+ {
+ convNumber = 1u;
+ }
+
+ /* Set Number Of Conversions based on scanning resolution */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_NORM_CNT, convNumber);
+ /* Measure and store the shield electrode(s) capacitance value, return the value and status */
+ result = Cy_CapSense_BistMeasureCapacitanceSensor(&context->ptrBistContext->shieldCap, context);
+ if(NULL != ptrValue)
+ {
+ *ptrValue = context->ptrBistContext->shieldCap;
+ }
+
+ /* Clear the BUSY flag */
+ context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY;
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_HW_BUSY_E;
+ }
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceSensorExt
+****************************************************************************//**
+*
+* Measures specified widget/sensor (electrode) capacitance using specified
+* scanning parameters.
+*
+* This function performs a single scan using the CSD sensing method and then
+* converts the measured raw count into capacitance using the following equation:
+*
+* Cs = Rawcount * I / ((2^Res - 1) * Vref * SnsClk)
+*
+* Where:
+* * Cs is the sensor capacitance.
+* * Rawcount is the measured raw count value.
+* * I is the current equal to IDAC gain * IDAC code
+* (Compensation IDAC is disabled).
+* * Res is the scanning resolution.
+* * Vref is the reference voltage.
+* * SnsClk is the sensor clock frequency.
+*
+* By default,the Cmod capacitor is used for the measurement. If a dedicated
+* Cmod is not available (e.g. the design has CSX widgets only), the CintA and
+* CintB capacitors are combined together by the firmware to form a single
+* integration capacitor for the measurement.
+*
+* This function must not be called while the CSD HW block is busy by another
+* state.
+*
+* It is not recommended to use this function in application code. The function
+* usage requires expert knowledge of the CapSense HW block, details of operation,
+* details of scanning parameters, and their interdependencies. The function
+* does not perform parameter values validation, and it is easy to break
+* CapSense operation using this function.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID of the sensor (electrode for CSX widgets) within the widget
+* to be measured.
+*
+* For the CSD widgets, a macro for the sensor ID within the specified widget
+* can be found in the CapSense Configuration header file (cycfg_capsense.h)
+* defined as CY_CAPSENSE__SNS_ID.
+*
+* For the CSX widgets, sensorId is an electrode ID and is defined as Rx ID
+* or Tx ID. The first Rx in a widget corresponds to electrodeId = 0, the
+* second Rx in a widget corresponds to electrodeId = 1, and so on.
+* The last Tx in a widget corresponds to electrodeId = (RxNum + TxNum - 1).
+* Macros for Rx and Tx IDs can be found in the CapSense Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense__RX_ID
+* * CapSense__TX_ID.
+*
+* \param ptrScanConfig
+* The pointer to the scan configuration parameter structure. The user
+* should initialize all the scan configuration parameters before
+* the function usage.
+*
+* \param ptrValue
+* The pointer to the result of scan. The result is calculated as a sensor
+* capacitance value in femtofarads. The user
+* declares a variable of uint32_t type and passes the variable pointer as
+* the function parameter.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The scan completes successfully,
+* the calculated capacitance value is valid.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* The measurement was not executed.
+* - CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a
+* previous operation. The measurement
+* was not executed.
+* - CY_CAPSENSE_BIST_TIMEOUT_E - The software watchdog timeout occurred
+* during the scan, the scan was not
+* completed, the calculated
+* capacitance is invalid.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The measurement was not
+* executed.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSensorExt(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ cy_stc_capsense_bist_custom_parameters_t * ptrScanConfig,
+ uint32_t * ptrValue,
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ cy_en_capsense_bist_io_state_t desiredIoState;
+ cy_en_capsense_bist_hw_config_t hwConfiguration;
+ uint32_t numWdgtElectrodes;
+ uint32_t rawCountTmp;
+ uint32_t idacIdx;
+ uint32_t idacCode;
+ uint32_t snsClkFreqHz;
+ uint32_t rawMaxNum;
+ uint32_t vRefMv;
+ uint32_t temp;
+ uint64_t cp;
+ uint32_t modClkDivider;
+ uint32_t snsClkDivider;
+ uint32_t cpuFreqMHz;
+ uint32_t watchdogPeriod;
+ uint64_t isBusyWatchdogTimeUs;
+
+
+ if((NULL != context) && (NULL != ptrScanConfig))
+ {
+ idacIdx = (uint32_t)ptrScanConfig->idacGainIndex;
+ idacCode = (uint32_t)ptrScanConfig->idacMod;
+ if (0u == ptrScanConfig->modClk)
+ {
+ ptrScanConfig->modClk = 1u;
+ }
+ snsClkFreqHz = context->ptrCommonConfig->periClkHz / ptrScanConfig->modClk / ptrScanConfig->snsClk;
+ rawMaxNum = ((uint32_t)ptrScanConfig->convNum * (uint32_t)ptrScanConfig->snsClk) - 1u;
+
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ if ((context->ptrCommonConfig->numWd > widgetId))
+ {
+ /* Get a total number of widget elements: for CSX, it is numRows + numCols, for CSD, it is totalNumSns */
+ if ((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E == context->ptrWdConfig[widgetId].senseMethod)
+ {
+ /* For CSX widgets, get the index of the Rx electrode */
+ numWdgtElectrodes = context->ptrWdConfig[widgetId].numRows +
+ (uint32_t)context->ptrWdConfig[widgetId].numCols;
+ desiredIoState = context->ptrBistContext->eltdCapCsxISC;
+ }
+ else
+ {
+ numWdgtElectrodes = context->ptrWdConfig[widgetId].numSns;
+ desiredIoState = context->ptrBistContext->eltdCapCsdISC;
+ }
+ if (numWdgtElectrodes > sensorId)
+ {
+ /* Release previously-captured HW resources by the other mode and capture them for BIST */
+ if (CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchSensingMode(
+ (uint8_t)CY_CAPSENSE_SENSE_METHOD_BIST_E, context))
+ {
+ /* Set the BUSY status */
+ context->ptrCommonContext->status = CY_CAPSENSE_BUSY;
+ hwConfiguration = CY_CAPSENSE_BIST_HW_ELTD_CAP_E;
+ if (CY_CAPSENSE_BIST_IO_SHIELD_E == desiredIoState)
+ {
+ hwConfiguration = CY_CAPSENSE_BIST_HW_ELTD_CAP_SH_E;
+ }
+ /* Switch the HW resource configuration to sensor short test */
+ Cy_CapSense_BistSwitchHwConfig(hwConfiguration, context);
+ Cy_CapSense_BistSwitchAllSnsPinState(desiredIoState, context);
+ Cy_CapSense_BistSwitchAllShieldPinState(desiredIoState, context);
+ /* Calculate the VrefHigh voltage */
+ vRefMv = Cy_CapSense_GetVrefHighMv((uint32_t)ptrScanConfig->vrefGain, context);
+
+ /* RefGen initialization */
+ temp = CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_RES_EN_Msk |
+ ((uint32_t)ptrScanConfig->vrefGain << CSD_REFGEN_GAIN_Pos);
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+ {
+ temp = CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk;
+ }
+ #endif
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_REFGEN, temp);
+
+ /* Connect the specified sensor (CSX electrode) */
+ Cy_CapSense_BistConnectElectrode(widgetId, sensorId, context);
+ /* Set the divider value for the mod clock (1u lower than the desired divider) */
+ Cy_CapSense_SetClkDivider(((uint32_t)ptrScanConfig->modClk - 1u), context);
+ /* Set the divider value for the sense clock (1u lower than the desired divider) */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SENSE_PERIOD, ((uint32_t)ptrScanConfig->snsClk - 1u));
+ /* Set Number Of Conversions for the custom scan */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_NORM_CNT, (uint32_t)ptrScanConfig->convNum);
+ /* Setup the IDAC code and Gain */
+ Cy_CSD_WriteBits(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IDACA,
+ CY_CAPSENSE_BIST_IDAC_BITS_TO_WRITE,
+ context->ptrCommonConfig->idacGainTable[idacIdx].gainReg | idacCode |
+ CSD_IDACA_LEG1_MODE_Msk | CSD_IDACA_LEG2_MODE_Msk);
+ /* Perform scanning */
+ result = Cy_CapSense_BistMeasureCapacitanceSensorRun(context);
+ if (CY_CAPSENSE_BIST_TIMEOUT_E != result)
+ {
+ modClkDivider = ptrScanConfig->modClk;
+ snsClkDivider = ptrScanConfig->snsClk;
+
+ if(0u == snsClkDivider)
+ {
+ snsClkDivider = 1u;
+ }
+
+ isBusyWatchdogTimeUs = (uint64_t)ptrScanConfig->convNum;
+ isBusyWatchdogTimeUs *= (uint64_t)snsClkDivider * modClkDivider * CY_CAPSENSE_CONVERSION_MEGA;
+ isBusyWatchdogTimeUs /= context->ptrCommonConfig->periClkHz;
+
+ if(0u == isBusyWatchdogTimeUs)
+ {
+ isBusyWatchdogTimeUs = 1u;
+ }
+
+ isBusyWatchdogTimeUs *= CY_CAPSENSE_BIST_WATCHDOG_MARGIN_COEFF;
+
+ cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
+ watchdogPeriod = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz,
+ CY_CAPSENSE_BIST_CAP_MEAS_WDT_CYCLES_PER_LOOP);
+
+ /* Wait for the end of the scan and get the raw counts */
+ if (0u == Cy_CapSense_BistWaitEndOfScan(watchdogPeriod, context))
+ {
+ result = CY_CAPSENSE_BIST_TIMEOUT_E;
+ }
+ else
+ {
+ rawCountTmp = (Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase,
+ CY_CSD_REG_OFFSET_RESULT_VAL1) &
+ CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK);
+ /* Capacitance calculation and storage */
+ if(NULL != ptrValue)
+ {
+ cp = ((uint64_t)context->ptrCommonConfig->idacGainTable[idacIdx].gainValue) * (uint64_t)idacCode;
+ cp *= (uint64_t)rawCountTmp;
+ cp *= CY_CAPSENSE_CONVERSION_MEGA;
+ cp /= (uint64_t)rawMaxNum;
+ cp /= (uint64_t)snsClkFreqHz;
+ cp /= (uint64_t)vRefMv;
+ if (((uint64_t)CY_CAPSENSE_BIST_CP_MAX_VALUE) < cp)
+ {
+ cp = (uint64_t)CY_CAPSENSE_BIST_CP_MAX_VALUE;
+ }
+ *ptrValue = (uint32_t)cp;
+ }
+ result = CY_CAPSENSE_BIST_SUCCESS_E;
+ }
+ }
+ /* Clear all interrupt pending requests */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR,
+ CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR);
+ /* Disconnect the sensor */
+ Cy_CapSense_BistDisconnectElectrode(widgetId, sensorId, context);
+ /* Clear the BUSY flag */
+ context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY;
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_HW_BUSY_E;
+ }
+ }
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceCapInit
+****************************************************************************//**
+*
+* This internal function calculates the parameters for sensor or shield
+* capacitance measurements and register values before speeding up
+* the execution.
+*
+* It is called by Cy_CapSense_BistDsInitialize() once at the CapSense MW start.
+*
+* The following parameters of cy_stc_capsense_bist_context_t are used as
+* an input for the calculation:
+* * .eltdCapModClk
+* * .eltdCapSnsClk
+* * .eltdCapVrefMv
+* * .eltdCapResolution
+*
+* The function checks for parameter limitations and corrects the values before
+* the calculation if they exceed.
+*
+* The following parameters of cy_stc_capsense_bist_context_t are updated
+* by the calculation:
+* * .eltdCapModClk
+* * .eltdCapSnsClk
+* * .eltdCapSnsClkFreqHz
+* * .eltdCapVrefGain
+* * .eltdCapVrefMv
+* * .eltdCapResolution
+*
+* Restarting CapSense MW or calling of the Cy_CapSense_BistDsInitialize()
+* function overwrites the output parameters.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistMeasureCapacitanceSensorInit(
+ cy_stc_capsense_context_t * context)
+{
+ uint32_t temp;
+ cy_stc_capsense_bist_context_t * ptrBistCxt = context->ptrBistContext;
+
+ /* ModClk */
+ if (0u == ptrBistCxt->eltdCapModClk)
+ {
+ ptrBistCxt->eltdCapModClk = 1u;
+ }
+ if (CY_CAPSENSE_BIST_ELTD_CAP_MAX_MODCLK < (context->ptrCommonConfig->periClkHz / ptrBistCxt->eltdCapModClk))
+ {
+ ptrBistCxt->eltdCapModClk <<= 1u;
+ }
+
+ /* SnsClk */
+ if (0u == ptrBistCxt->eltdCapSnsClk)
+ {
+ /*
+ * Calculate the snsClc divider with rounding to achieve a frequency closer to
+ * CY_CAPSENSE_BIST_ELTD_CAP_SNSCLK_DEFAULT snsClk
+ */
+ ptrBistCxt->eltdCapSnsClk = (uint16_t)(((context->ptrCommonConfig->periClkHz / ptrBistCxt->eltdCapModClk) +
+ (CY_CAPSENSE_BIST_ELTD_CAP_SNSCLK_DEFAULT >> 1uL)) / CY_CAPSENSE_BIST_ELTD_CAP_SNSCLK_DEFAULT);
+ }
+ /* Check the snsClk divider value */
+ if (CY_CAPSENSE_BIST_SNS_CLK_MIN_DIVIDER > ptrBistCxt->eltdCapSnsClk)
+ {
+ ptrBistCxt->eltdCapSnsClk = CY_CAPSENSE_BIST_SNS_CLK_MIN_DIVIDER;
+ }
+ if (CY_CAPSENSE_BIST_SNS_CLK_MAX_DIVIDER < ptrBistCxt->eltdCapSnsClk)
+ {
+ ptrBistCxt->eltdCapSnsClk = CY_CAPSENSE_BIST_SNS_CLK_MAX_DIVIDER;
+ }
+ ptrBistCxt->eltdCapSnsClkFreqHz = context->ptrCommonConfig->periClkHz / ptrBistCxt->eltdCapModClk / ptrBistCxt->eltdCapSnsClk;
+
+ /* Reference Voltage */
+ if(ptrBistCxt->eltdCapVrefMv == 0u)
+ {
+ /* Get the recommended reference voltage */
+ temp = CY_CAPSENSE_BIST_CAP_MEAS_VREF_MV_DEFAULT;
+ }
+ else
+ {
+ /* Use the user-defined reference voltage */
+ temp = (uint32_t)ptrBistCxt->eltdCapVrefMv;
+ }
+ ptrBistCxt->eltdCapVrefGain = (uint8_t)Cy_CapSense_GetVrefHighGain(temp, context);
+ ptrBistCxt->eltdCapVrefMv = (uint16_t)Cy_CapSense_GetVrefHighMv((uint32_t)ptrBistCxt->eltdCapVrefGain, context);
+
+ /* Resolution */
+ if (CY_CAPSENSE_BIST_ELTD_CAP_MAX_RESOLUTION < ptrBistCxt->eltdCapResolution)
+ {
+ ptrBistCxt->eltdCapResolution = CY_CAPSENSE_BIST_ELTD_CAP_MAX_RESOLUTION;
+ }
+ if (CY_CAPSENSE_BIST_ELTD_CAP_MIN_RESOLUTION > ptrBistCxt->eltdCapResolution)
+ {
+ ptrBistCxt->eltdCapResolution = CY_CAPSENSE_BIST_ELTD_CAP_MIN_RESOLUTION;
+ }
+
+ /* HW block register pre-calculation */
+ /* BYP switch selection */
+ ptrBistCxt->regSwBypSel = CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK;
+ ptrBistCxt->regSwBypSelShield = CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK;
+ if (0u != context->ptrCommonConfig->csdShieldEn)
+ {
+ ptrBistCxt->regSwBypSel = CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK | CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYB_MSK;
+ ptrBistCxt->regSwBypSelShield = CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK | CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYB_MSK;
+ }
+
+ ptrBistCxt->regAmbuf = 0u;
+ ptrBistCxt->regSwResInit = ((uint32_t)context->ptrCommonConfig->csdInitSwRes << CSD_SW_RES_RES_HCAV_Pos) |
+ ((uint32_t)context->ptrCommonConfig->csdInitSwRes << CSD_SW_RES_RES_HCBV_Pos);
+ ptrBistCxt->regSwResScan = ((uint32_t)context->ptrCommonConfig->csdShieldSwRes << CSD_SW_RES_RES_HCBV_Pos) |
+ ((uint32_t)context->ptrCommonConfig->csdShieldSwRes << CSD_SW_RES_RES_HCBG_Pos);
+ ptrBistCxt->regIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 | CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2);
+ ptrBistCxt->regSwDsiSel = CY_CAPSENSE_BIST_SW_DSI_SEL_DEFAULT;
+ ptrBistCxt->regSwRefgenSel = CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGR_MSK;
+
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ if (CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+ {
+ ptrBistCxt->regSwRefgenSel = CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRP_MSK;
+ }
+ #endif
+
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdEn)
+ {
+ switch (context->ptrInternalContext->csdCmodConnection)
+ {
+ case (uint8_t)CY_CAPSENSE_CMODPAD_E:
+ ptrBistCxt->regSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CMOD_MSK;
+ break;
+ case (uint8_t)CY_CAPSENSE_CTANKPAD_E:
+ ptrBistCxt->regSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CSH_TANK_MSK;
+ break;
+ default:
+ break;
+ }
+ if ((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn) &&
+ (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn))
+ {
+ switch (context->ptrInternalContext->csdCshConnection)
+ {
+ case (uint8_t)CY_CAPSENSE_CMODPAD_E:
+ ptrBistCxt->regSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CMOD_MSK;
+ break;
+ case (uint8_t)CY_CAPSENSE_CTANKPAD_E:
+ ptrBistCxt->regSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CSH_TANK_MSK;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ else
+ {
+ ptrBistCxt->regSwDsiSel = CY_CAPSENSE_CSD_SW_DSI_SEL_CMOD_MSK |
+ CY_CAPSENSE_CSD_SW_DSI_SEL_CSH_TANK_MSK;
+ }
+ #endif
+
+ /* Prepares a CONFIG register value */
+ if ((context->ptrCommonConfig->periClkHz / context->ptrBistContext->eltdCapModClk) > CY_CAPSENSE_MOD_CSD_CLK_24000000_HZ)
+ {
+ ptrBistCxt->regConfig = CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_48MHZ;
+ }
+ else if ((context->ptrCommonConfig->periClkHz / context->ptrBistContext->eltdCapModClk) > CY_CAPSENSE_MOD_CSD_CLK_12000000_HZ)
+ {
+ ptrBistCxt->regConfig = CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_24MHZ;
+ }
+ else
+ {
+ ptrBistCxt->regConfig = CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_12MHZ;
+ }
+
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ if (CY_CAPSENSE_IREF_PASS == context->ptrCommonConfig->ssIrefSource)
+ {
+ ptrBistCxt->regConfig |= CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK;
+ }
+ #endif
+
+ ptrBistCxt->regConfig |= CSD_CONFIG_SENSE_EN_Msk | CSD_CONFIG_ENABLE_Msk;
+
+ ptrBistCxt->regSwShieldSelScan = 0u;
+ ptrBistCxt->regSwShieldSelScanShield = 0u;
+ if (0u != context->ptrCommonConfig->csdShieldEn)
+ {
+ if (0u != context->ptrCommonConfig->csdCTankShieldEn)
+ {
+ ptrBistCxt->regSwShieldSelScan = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI1_HSCMP;
+ ptrBistCxt->regSwShieldSelScanShield = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI1_HSCMP;
+ }
+ else
+ {
+ ptrBistCxt->regSwShieldSelScan = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI1 |
+ CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI2_HSCMP;
+ ptrBistCxt->regSwShieldSelScanShield = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI1 |
+ CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI2_HSCMP;
+ }
+ }
+
+ /* High-Speed Comparator initialization */
+ ptrBistCxt->regHscmpScan = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
+ ptrBistCxt->regHscmpScanShield = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
+ if (0u == context->ptrCommonConfig->csdShieldEn)
+ {
+ ptrBistCxt->regHscmpScan = 0u;
+ ptrBistCxt->regHscmpScanShield = 0u;
+ }
+
+ ptrBistCxt->regSwHsPSelCmodInit = 0u;
+ ptrBistCxt->regSwHsPSelCtankInit = 0u;
+ ptrBistCxt->regSwHsPSelScan = 0u;
+ ptrBistCxt->regSwHsPSelScanShield = 0u;
+ switch (context->ptrInternalContext->csdCmodConnection)
+ {
+ case (uint8_t)CY_CAPSENSE_CMODPAD_E:
+ ptrBistCxt->regSwHsPSelCmodInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
+ break;
+ case (uint8_t)CY_CAPSENSE_CSHIELDPAD_E:
+ ptrBistCxt->regSwHsPSelCmodInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
+ break;
+ default:
+ ptrBistCxt->regSwHsPSelCmodInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
+ break;
+ }
+
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn)
+ {
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn)
+ {
+ switch (context->ptrInternalContext->csdCshConnection)
+ {
+ case (uint8_t)CY_CAPSENSE_CMODPAD_E:
+ ptrBistCxt->regSwHsPSelCtankInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
+ ptrBistCxt->regSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
+ ptrBistCxt->regSwHsPSelScanShield = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
+ break;
+ case (uint8_t)CY_CAPSENSE_CSHIELDPAD_E:
+ ptrBistCxt->regSwHsPSelCtankInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
+ ptrBistCxt->regSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
+ ptrBistCxt->regSwHsPSelScanShield = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
+ break;
+ default:
+ ptrBistCxt->regSwHsPSelCtankInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
+ ptrBistCxt->regSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
+ ptrBistCxt->regSwHsPSelScanShield = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
+ break;
+ }
+ }
+ else
+ {
+ ptrBistCxt->regSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMB_STATIC_CLOSE;
+ ptrBistCxt->regSwHsPSelScanShield = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMB_STATIC_CLOSE;
+ }
+ }
+
+ /* Pre-calculate config with a shield */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn)
+ {
+ if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+ {
+ ptrBistCxt->regAmbuf = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_NORM;
+ ptrBistCxt->regAmbufShield = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_NORM;
+ }
+ else
+ {
+ ptrBistCxt->regAmbuf = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_HI;
+ ptrBistCxt->regAmbufShield = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_HI;
+ }
+ }
+ else
+ {
+ ptrBistCxt->regAmbuf = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_OFF;
+ ptrBistCxt->regAmbufShield = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_OFF;
+ }
+
+ /* Switch AMUXBUF selection */
+ ptrBistCxt->regSwAmuxbufSel = 0u;
+ ptrBistCxt->regSwAmuxbufSelShield = 0u;
+ if (0u != context->ptrCommonConfig->csdShieldEn)
+ {
+ if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT <= context->ptrCommonConfig->vdda)
+ {
+ ptrBistCxt->regSwAmuxbufSel = CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_IRH_STATIC_CLOSE |
+ CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_ICB_PHI2;
+ ptrBistCxt->regSwAmuxbufSelShield = CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_IRH_STATIC_CLOSE |
+ CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_ICB_PHI2;
+ }
+ }
+
+ ptrBistCxt->regIoSelShield = CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 | CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 |
+ CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY | CY_CAPSENSE_CSD_TX_AMUXB_EN_PHI2_DELAY;
+ ptrBistCxt->regConfigShield = ptrBistCxt->regConfig |
+ (((uint32_t)context->ptrCommonConfig->csdShieldDelay) << CY_CAPSENSE_CSD_CONFIG_SHIELD_DELAY_POS);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSensorEnable
+****************************************************************************//**
+*
+* The internal function sets up the CSD HW block to perform electrode
+* (sensor or shield) capacitance measuring.
+*
+* This function prepares the CSD HW block to CSD sensing mode
+* with BIST-defined parameters.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistMeasureCapacitanceSensorEnable(
+ cy_stc_capsense_context_t * context)
+{
+ CSD_Type * ptrCsdHwBase = context->ptrCommonConfig->ptrCsdBase;
+
+ /* Connect External Capacitor as CMOD to AMUXBUS-A and to CSDCOMP */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdEn)
+ {
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCmod,
+ (uint32_t)context->ptrCommonConfig->pinCmod, CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_P_SEL, context->ptrInternalContext->csdRegSwCmpPSel);
+
+ if ((0u != context->ptrCommonConfig->csdShieldEn) &&
+ (0u != context->ptrCommonConfig->csdCTankShieldEn))
+ {
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh,
+ CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXB);
+ }
+ }
+ else
+ {
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA,
+ (uint32_t)context->ptrCommonConfig->pinCintA, CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB,
+ (uint32_t)context->ptrCommonConfig->pinCintB, CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_P_SEL,
+ CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPT_STATIC_CLOSE | CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPM_STATIC_CLOSE);
+ }
+
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CONFIG, context->ptrBistContext->regConfig);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_REFGEN, CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_RES_EN_Msk |
+ ((uint32_t)context->ptrBistContext->eltdCapVrefGain << CSD_REFGEN_GAIN_Pos));
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+ {
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_REFGEN, CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk);
+ }
+ #endif
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR_MASK, CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_AMBUF, context->ptrBistContext->regAmbuf);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_CTL, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_TIME, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IDACA, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IDACB, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SENSE_DUTY, CY_CAPSENSE_CSD_SENSE_DUTY_CFG);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR_SET, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_INIT_CNT, (uint32_t)context->ptrBistContext->fineInitTime);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, context->ptrBistContext->regSwRefgenSel);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_N_SEL, CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_CLOSE);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_N_SEL, CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_AMUXBUF_SEL, context->ptrBistContext->regSwAmuxbufSel);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_BYP_SEL, context->ptrBistContext->regSwBypSel);
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IO_SEL, context->ptrBistContext->regIoSel);
+ #endif
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_DSI_SEL, context->ptrBistContext->regSwDsiSel);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSensorShieldEnable
+****************************************************************************//**
+*
+* The internal function sets up the CSD HW block to perform electrode
+* (sensor or shield) capacitance measuring with a configured shield.
+*
+* This function prepares HW of the CapSense block to CSD sensing mode
+* with BIST-defined parameters with inactive sensor connection (ISC) set
+* to the shield.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistMeasureCapacitanceSensorShieldEnable(
+ cy_stc_capsense_context_t * context)
+{
+ CSD_Type * ptrCsdHwBase = context->ptrCommonConfig->ptrCsdBase;
+
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdEn)
+ {
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCmod,
+ (uint32_t)context->ptrCommonConfig->pinCmod, CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_P_SEL, context->ptrInternalContext->csdRegSwCmpPSel);
+
+ if ((0u != context->ptrCommonConfig->csdShieldEn) &&
+ (0u != context->ptrCommonConfig->csdCTankShieldEn))
+ {
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh,
+ CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXB);
+ }
+ }
+ else
+ {
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA,
+ (uint32_t)context->ptrCommonConfig->pinCintA, CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB,
+ (uint32_t)context->ptrCommonConfig->pinCintB, CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_P_SEL,
+ CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPT_STATIC_CLOSE | CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPM_STATIC_CLOSE);
+ }
+
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CONFIG, context->ptrBistContext->regConfigShield);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_REFGEN, CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_RES_EN_Msk |
+ ((uint32_t)context->ptrBistContext->eltdCapVrefGain << CSD_REFGEN_GAIN_Pos));
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+ {
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_REFGEN, CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk);
+ }
+ #endif
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR_MASK, CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_AMBUF, context->ptrBistContext->regAmbufShield);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_CTL, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_TIME, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IDACA, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IDACB, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SENSE_DUTY, CY_CAPSENSE_CSD_SENSE_DUTY_CFG);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR_SET, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_INIT_CNT, (uint32_t)context->ptrBistContext->fineInitTime);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, context->ptrBistContext->regSwRefgenSel);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_N_SEL, CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_CLOSE);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_N_SEL, CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrBistContext->regSwHsPSelScanShield);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_AMUXBUF_SEL, context->ptrBistContext->regSwAmuxbufSelShield);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_BYP_SEL, context->ptrBistContext->regSwBypSelShield);
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IO_SEL, context->ptrBistContext->regIoSelShield);
+ #endif
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_DSI_SEL, context->ptrBistContext->regSwDsiSel);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSensor
+****************************************************************************//**
+*
+* This internal function measures a capacitance attached to AMUXBUS.
+*
+* The function measures Cp of a certain electrode (CSD sensor or shield or CSX
+* Rx/Tx electrode) by using CSD mode and defined IDAC configuration,
+* sense clock frequency and resolution.
+* The range for sensor measuring is 1 to 360 pF.
+* The function performs up to 4 CSD scans with fixed IDAC values
+* to reach a defined target of raw counts in the range from 7% to 45%
+* of the maximum raw count value. This range provides a possibility of
+* classical raw counts formula usage for capacitance calculation.
+* The function stores the Cp value
+* in the corresponding element of the eltdCap[CY_CAPSENSE_ELTD_COUNT] array.
+*
+* \param cpPtr
+* The pointer to the uint32_t to store measured value of the capacitance.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes
+* successfully, the result is valid.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* - CY_CAPSENSE_BIST_LOW_LIMIT_E - The measured capacitance is below
+* the minimum possible value.
+* The measurement result is invalid.
+* The sensor might be shorted to VDD or a sensor
+* PCB track was broken (open sensor).
+* - CY_CAPSENSE_BIST_HIGH_LIMIT_E - The measured capacitance is above the
+* maximum possible value.
+* The measurement result is invalid.
+* The sensor might be shorted to GND.
+* - CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during
+* the measurement, the measurement may need
+* to be repeated.
+* - CY_CAPSENSE_BIST_TIMEOUT_E - The scan reached the timeout. It can be caused
+* by a measured capacitance short or CSD HW block
+* failure or invalid configuration. You may need to
+* repeat the measurement after the issue fix.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensor(
+ uint32_t * cpPtr,
+ cy_stc_capsense_context_t * context)
+{
+ const uint32_t idacGainIdxTable[] = {2u, 2u, 4u, 5u};
+ const uint32_t idacCodeTable[]= {20u, 80u, 40u, 80u};
+ cy_en_capsense_bist_status_t result;
+ uint32_t rawMaxNum = (0x01uL << context->ptrBistContext->eltdCapResolution) - 1u;
+ uint32_t rawMinLimit = (rawMaxNum * CY_CAPSENSE_BIST_ELTD_CAP_MIN_RAW_PROMILLE) / CY_CAPSENSE_BIST_PROMILLE_FACTOR;
+ uint32_t rawMaxLimit = (rawMaxNum * CY_CAPSENSE_BIST_ELTD_CAP_MAX_RAW_PROMILLE) / CY_CAPSENSE_BIST_PROMILLE_FACTOR;
+ uint32_t counter = 0u;
+ uint32_t idacCode;
+ uint32_t idacIdx;
+ uint32_t rawCountTmp = rawMaxNum;
+ uint64_t cp;
+ uint32_t modClkDivider;
+ uint32_t cpuFreqMHz;
+ uint32_t watchdogPeriod;
+ uint64_t isBusyWatchdogTimeUs;
+
+
+ /* Perform up to 4 scans to measure Cp */
+ do
+ {
+ /* Setup scan parameters: IDAC and Gain */
+ idacCode = idacCodeTable[counter];
+ idacIdx = idacGainIdxTable[counter];
+ Cy_CSD_WriteBits(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IDACA,
+ CY_CAPSENSE_BIST_IDAC_BITS_TO_WRITE,
+ context->ptrCommonConfig->idacGainTable[idacIdx].gainReg | idacCode |
+ CSD_IDACA_LEG1_MODE_Msk | CSD_IDACA_LEG2_MODE_Msk);
+ /* Perform scanning */
+ result = Cy_CapSense_BistMeasureCapacitanceSensorRun(context);
+ if (CY_CAPSENSE_BIST_TIMEOUT_E != result)
+ {
+
+ modClkDivider = context->ptrBistContext->eltdCapModClk;
+ if(0u == modClkDivider)
+ {
+ modClkDivider = 1u;
+ }
+
+ isBusyWatchdogTimeUs = (uint64_t)((uint64_t)0x01 << context->ptrBistContext->eltdCapResolution);
+ isBusyWatchdogTimeUs *= (uint64_t)modClkDivider * CY_CAPSENSE_CONVERSION_MEGA;
+ isBusyWatchdogTimeUs /= context->ptrCommonConfig->periClkHz;
+
+ if(0u == isBusyWatchdogTimeUs)
+ {
+ isBusyWatchdogTimeUs = 1u;
+ }
+
+ isBusyWatchdogTimeUs *= CY_CAPSENSE_BIST_WATCHDOG_MARGIN_COEFF;
+
+ cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
+ watchdogPeriod = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz,
+ CY_CAPSENSE_BIST_CAP_MEAS_WDT_CYCLES_PER_LOOP);
+
+ /* Wait for an end of the scan and get a raw count */
+ if (0u != Cy_CapSense_BistWaitEndOfScan(watchdogPeriod, context))
+ {
+ rawCountTmp = Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_RESULT_VAL1) &
+ CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK;
+ /* Check for the measurement result status */
+ if ((rawCountTmp < rawMinLimit) && (0u == counter))
+ {
+ result = CY_CAPSENSE_BIST_LOW_LIMIT_E;
+ }
+ if ((rawCountTmp > rawMaxLimit) && (3u == counter))
+ {
+ result = CY_CAPSENSE_BIST_HIGH_LIMIT_E;
+ }
+ if ((rawCountTmp >= rawMinLimit) && (rawCountTmp <= rawMaxLimit))
+ {
+ result = CY_CAPSENSE_BIST_SUCCESS_E;
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_TIMEOUT_E;
+ }
+ }
+ if (CY_CAPSENSE_BIST_TIMEOUT_E == result)
+ {
+ break;
+ }
+ counter++;
+ }
+ while ((CY_CAPSENSE_BIST_SUCCESS_E != result) && (CY_CAPSENSE_BIST_LOW_LIMIT_E != result) &&
+ (CY_CAPSENSE_BIST_HIGH_LIMIT_E != result) && (counter < CY_CAPSENSE_BIST_ELTD_CAP_CYCLES_NUM));
+ /* Clear all interrupt pending requests */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR);
+
+ if ((CY_CAPSENSE_BIST_TIMEOUT_E != result))
+ {
+ /* Capacitance calculation and storage to the data structure */
+ cp = ((uint64_t)context->ptrCommonConfig->idacGainTable[idacIdx].gainValue) * (uint64_t)idacCode;
+ cp *= (uint64_t)rawCountTmp;
+ cp *= CY_CAPSENSE_CONVERSION_MEGA;
+ cp /= (uint64_t)rawMaxNum;
+ cp /= (uint64_t)context->ptrBistContext->eltdCapSnsClkFreqHz;
+ cp /= (uint64_t)context->ptrBistContext->eltdCapVrefMv;
+ if (((uint64_t)CY_CAPSENSE_BIST_CP_MAX_VALUE) < cp)
+ {
+ cp = (uint64_t)CY_CAPSENSE_BIST_CP_MAX_VALUE;
+ }
+ *cpPtr = (uint32_t)cp;
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSensorRun
+****************************************************************************//**
+*
+* This internal function performs coarse initialization for Cmod and Csh
+* (or CintA and CintB for only CSX configurations) and triggers a scan
+* for the sensor or shield electrode capacitance measurement.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the starting execution:
+* - CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is successfully started
+* and is busy with scanning.
+* - CY_CAPSENSE_BIST_TIMEOUT_E - The pre-charge of the integration capacitor
+* reached a timeout.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensorRun(
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_HW_BUSY_E;
+ CSD_Type * ptrCsdHwBase = context->ptrCommonConfig->ptrCsdBase;
+ uint32_t cpuFreqMHz;
+ uint32_t watchdogCounter;
+
+ /* Approximate duration of Wait For Init loop */
+ const uint32_t intrInitLoopDuration = 5uL;
+ const uint32_t initWatchdogTimeUs = CY_CAPSENSE_BIST_PRECHARGE_WATCHDOG_TIME_US;
+
+ Cy_CapSense_DischargeExtCapacitors(context);
+
+ /* External capacitor pre-charging */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CSDCMP, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_HSCMP, CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_RES, context->ptrBistContext->regSwResInit);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, 0u);
+
+ if ((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn) &&
+ (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn))
+ {
+ /* Clear previous interrupts */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR);
+
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrBistContext->regSwHsPSelCtankInit);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_HSCMP);
+
+ /* Start SEQUENCER for coarse initialization for Ctank */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_SEQ_MODE_MSK |
+ CY_CAPSENSE_CSD_SEQ_START_START_MSK |
+ CY_CAPSENSE_BIST_FSM_AZ0_SKIP |
+ CY_CAPSENSE_BIST_FSM_AZ1_SKIP);
+ /* Init Watchdog Counter to prevent a hang */
+ cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
+ watchdogCounter = Cy_CapSense_WatchdogCyclesNum(initWatchdogTimeUs, cpuFreqMHz, intrInitLoopDuration);
+ watchdogCounter = Cy_CapSense_WaitForSeqIdle(watchdogCounter, context);
+
+ if (0u == watchdogCounter)
+ {
+ /* Set the sequencer to the idle state if the coarse initialization fails */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK);
+ result = CY_CAPSENSE_BIST_TIMEOUT_E;
+ }
+ }
+
+ if (CY_CAPSENSE_BIST_HW_BUSY_E == result)
+ {
+ /* Clear previous interrupts */
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR);
+
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrBistContext->regSwHsPSelCmodInit);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_HSCMP);
+
+ /* Start SEQUENCER for coarse initialization for Cmod */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_SEQ_MODE_MSK |
+ CY_CAPSENSE_CSD_SEQ_START_START_MSK |
+ CY_CAPSENSE_BIST_FSM_AZ0_SKIP |
+ CY_CAPSENSE_BIST_FSM_AZ1_SKIP);
+ /* Init Watchdog Counter to prevent a hang */
+ cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
+ watchdogCounter = Cy_CapSense_WatchdogCyclesNum(initWatchdogTimeUs, cpuFreqMHz, intrInitLoopDuration);
+ watchdogCounter = Cy_CapSense_WaitForSeqIdle(watchdogCounter, context);
+
+ if (0u == watchdogCounter)
+ {
+ /* Set the sequencer to the idle state if the coarse initialization fails */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK);
+ result = CY_CAPSENSE_BIST_TIMEOUT_E;
+ }
+ }
+
+ /* Scanning */
+ if (CY_CAPSENSE_BIST_HW_BUSY_E == result)
+ {
+ /* Clear previous interrupts */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR);
+
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CSDCMP, CY_CAPSENSE_CSD_CSDCMP_CSDCMP_EN_MSK);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_RES, context->ptrBistContext->regSwResScan);
+
+ if (CY_CAPSENSE_BIST_HW_ELTD_CAP_SH_E != context->ptrBistContext->hwConfig)
+ {
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrBistContext->regSwHsPSelScan);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_HSCMP, context->ptrBistContext->regHscmpScan);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, context->ptrBistContext->regSwShieldSelScan);
+ }
+ else
+ {
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, context->ptrBistContext->regSwHsPSelScanShield);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_HSCMP, context->ptrBistContext->regHscmpScanShield);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, context->ptrBistContext->regSwShieldSelScanShield);
+ }
+
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_CSD_SEQ_START_AZ0_SKIP_MSK |
+ CY_CAPSENSE_CSD_SEQ_START_AZ1_SKIP_MSK |
+ CY_CAPSENSE_CSD_SEQ_START_START_MSK);
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSensorAll
+****************************************************************************//**
+*
+* This internal function measures all the sensors Cp capacitance.
+*
+* This function measures Cp of all the sensors by using the
+* CapSense_GetSensorCapacitance function.
+* The function stores the Cp values in the corresponding BIST data
+* structure registers.
+* The function is called by the Cy_CapSense_RunSelfTest() function.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the measuring process:
+* - CY_CAPSENSE_BIST_SUCCESS_E if all the measurements passed successfully.
+* - CY_CAPSENSE_BIST_FAIL_E if any measurement was failed.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensorAll(
+ cy_stc_capsense_context_t * context)
+{
+ uint32_t widgetId;
+ uint32_t sensorElement;
+ uint32_t numWdgtElectrodes;
+ uint32_t snsCap;
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_SUCCESS_E;
+
+ /* Loop through all the widgets */
+ for (widgetId = 0u; widgetId < context->ptrCommonConfig->numWd; widgetId++)
+ {
+ /* Get a total number of the widget elements: for CSX, it is numRows + numCols, for CSD, it is totalNumSns */
+ if ((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E == context->ptrWdConfig[widgetId].senseMethod)
+ {
+ numWdgtElectrodes = context->ptrWdConfig[widgetId].numRows +
+ (uint32_t)context->ptrWdConfig[widgetId].numCols;
+ }
+ else
+ {
+ numWdgtElectrodes = context->ptrWdConfig[widgetId].numSns;
+ }
+ /* Loop through all the sensor electrodes */
+ for (sensorElement = 0u; sensorElement < numWdgtElectrodes; sensorElement++)
+ {
+ if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_MeasureCapacitanceSensor(widgetId, sensorElement, &snsCap, context))
+ {
+ if (CY_CAPSENSE_BIST_SUCCESS_E == result)
+ {
+ result = CY_CAPSENSE_BIST_FAIL_E;
+ }
+ }
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceCap
+****************************************************************************//**
+*
+* Measures the capacitance of the specified CapSense integration
+* (external) capacitor.
+*
+* The function measures the capacitance of the specified external capacitor
+* such as Cmod and returns the result through ptrValue, alternatively
+* the measurement result is stored in the corresponding field of the
+* \ref cy_stc_capsense_bist_context_t structure (either .cModCap, .cIntACap,
+* .cIntBCap, or .cShieldCap).
+*
+* The maximum measurement capacitance is 25nF. The measurement accuracy is
+* up to 15%. The measurement resolution is 10 bit which corresponds to the
+* maximum capacitance specified by the maxCapacitance parameter. The bigger
+* specified maximum capacitance is, the bigger capacitance value is for
+* one measured count.
+* It is recommended to specify the maximum capacitance twice bigger as the
+* nominal capacitor capacitance. For example, if the nominal Cmod value
+* is 2.2nF, the maxCapacitance parameter is set to 4nF-5nF.
+*
+* The function configures all CapSense pins to Strong-drive-low mode that
+* allows detecting a short of the measured capacitor to other pins.
+*
+* To measure all the available capacitors, the Cy_CapSense_RunSelfTest()
+* function can be used with the CY_CAPSENSE_BIST_SNS_SHORT mask. The measured
+* results are stored in the corresponding field of the
+* \ref cy_stc_capsense_bist_context_t structure.
+*
+* Measurement can be done only if the CapSense Middleware is in the IDLE
+* state. This function must not be called while the CapSense Middleware is busy.
+* The function is blocking, i.e. waits for the measurement to be completed
+* prior to returning to the caller.
+*
+* \param integrationCapId
+* Indexes of external capacitors to measure their capacitance.
+* There are macros for each of them, namely:
+* * CY_CAPSENSE_BIST_CMOD_ID for the CSD method Cmod capacitor
+* * CY_CAPSENSE_BIST_CINTA_ID for the CSX method CintA capacitor
+* * CY_CAPSENSE_BIST_CINTB_ID for the CSX method CintB capacitor
+* * CY_CAPSENSE_BIST_CSH_ID for the CSD method Csh capacitor
+*
+* \param ptrValue
+* The pointer to the result of the measurement. The result is calculated as
+* a specified capacitor capacitance value in picofarads. The user
+* declares a variable of the uint32_t type and passes the pointer to this
+* variable as the function parameter. If the ptrValue parameter is NULL then
+* the capacitance value is not returned through the parameter but stored to the
+* corresponding field of the \ref cy_stc_capsense_bist_context_t structure.
+*
+* \param maxCapacitance
+* An expected by the user maximum value of the measured capacitance in
+* nanofarads in the range from 1 to 25 nF.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes
+* successfully, the result is valid.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* The measurement was not executed.
+* - CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with
+* a previous operation. The measurement
+* was not executed.
+* - CY_CAPSENSE_BIST_LOW_LIMIT_E - The measurement was performed
+* but the scanning result is
+* below the minimum possible value.
+* The measurement result could be invalid.
+* The capacitor might be shorted to
+* VDD or a PCB track
+* is broken (open capacitor).
+* - CY_CAPSENSE_BIST_HIGH_LIMIT_E - The measurement was performed but
+* the scanning result is above the
+* maximum possible value.
+* The measurement result could be invalid.
+* The capacitor might be shorted to GND.
+* - CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during
+* the measurement.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The measurement was not
+* executed.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceCap(
+ cy_en_capsense_bist_external_cap_id_t integrationCapId,
+ uint32_t * ptrValue,
+ uint32_t maxCapacitance,
+ cy_stc_capsense_context_t * context)
+{
+ uint32_t extCapValue = 0u;
+ GPIO_PRT_Type * ptrCapPort = NULL;
+ uint32_t capacitorPin = 0u;
+ uint16_t * ptrResult = NULL;
+ uint32_t idacCode = 0u;
+ uint32_t idacIdx = 0u;
+ uint32_t idacGain = 0u;
+ uint64_t tempIDAC;
+ cy_en_capsense_bist_status_t bistStatus = CY_CAPSENSE_BIST_SUCCESS_E;
+
+ if ((NULL == context) || (CY_CAPSENSE_BIST_CAP_MEAS_MAX_CAP < maxCapacitance) || (0u == maxCapacitance))
+ {
+ bistStatus = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ }
+ if (CY_CAPSENSE_ENABLE != context->ptrCommonConfig->bistEn)
+ {
+ bistStatus = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ if (CY_CAPSENSE_SUCCESS_E != Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_BIST_E, context))
+ {
+ bistStatus = CY_CAPSENSE_BIST_HW_BUSY_E;
+ }
+
+ if (CY_CAPSENSE_BIST_SUCCESS_E == bistStatus)
+ {
+ switch (integrationCapId)
+ {
+ case CY_CAPSENSE_BIST_CMOD_ID_E:
+ if (CY_CAPSENSE_ENABLE != context->ptrCommonConfig->csdEn)
+ {
+ bistStatus = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ }
+ ptrCapPort = context->ptrCommonConfig->portCmod;
+ capacitorPin = (uint32_t)context->ptrCommonConfig->pinCmod;
+ ptrResult = &context->ptrBistContext->cModCap;
+ break;
+ case CY_CAPSENSE_BIST_CINTA_ID_E:
+ if (CY_CAPSENSE_ENABLE != context->ptrCommonConfig->csxEn)
+ {
+ bistStatus = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ }
+ ptrCapPort = context->ptrCommonConfig->portCintA;
+ capacitorPin = (uint32_t)context->ptrCommonConfig->pinCintA;
+ ptrResult = &context->ptrBistContext->cIntACap;
+ break;
+ case CY_CAPSENSE_BIST_CINTB_ID_E:
+ if (CY_CAPSENSE_ENABLE != context->ptrCommonConfig->csxEn)
+ {
+ bistStatus = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ }
+ ptrCapPort = context->ptrCommonConfig->portCintB;
+ capacitorPin = (uint32_t)context->ptrCommonConfig->pinCintB;
+ ptrResult = &context->ptrBistContext->cIntBCap;
+ break;
+ case CY_CAPSENSE_BIST_CSH_ID_E:
+ if ((CY_CAPSENSE_ENABLE != context->ptrCommonConfig->csdEn) ||
+ (CY_CAPSENSE_ENABLE != context->ptrCommonConfig->csdShieldEn) ||
+ (CY_CAPSENSE_ENABLE != context->ptrCommonConfig->csdCTankShieldEn))
+ {
+ bistStatus = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ }
+ ptrCapPort = context->ptrCommonConfig->portCsh;
+ capacitorPin = (uint32_t)context->ptrCommonConfig->pinCsh;
+ ptrResult = &context->ptrBistContext->cShieldCap;
+ break;
+ default:
+ bistStatus = CY_CAPSENSE_BIST_BAD_PARAM_E;
+ break;
+ }
+ }
+
+ if (CY_CAPSENSE_BIST_SUCCESS_E == bistStatus)
+ {
+ /* Set the BUSY status */
+ context->ptrCommonContext->status = CY_CAPSENSE_BUSY;
+ Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_EXTERNAL_CAP_E, context);
+
+ /* Calculate the needed IDAC value */
+ tempIDAC = ((((((uint64_t)CY_CAPSENSE_BIST_CAP_MEAS_ACCURACY_FACTOR *
+ (uint64_t)context->ptrBistContext->extCapVrefMv) *
+ (uint64_t)context->ptrCommonConfig->periClkHz) * (uint64_t)maxCapacitance) /
+ (uint64_t)context->ptrBistContext->extCapModClk) /
+ (uint64_t)context->ptrBistContext->extCapSnsClk) /
+ (uint64_t)CY_CAPSENSE_BIST_PROMILLE_FACTOR;
+ /* IDAC Gain - LSB */
+ tempIDAC = (tempIDAC + (CY_CAPSENSE_BIST_IDAC_MAX - 1u)) / CY_CAPSENSE_BIST_IDAC_MAX;
+ /* Search for corresponding IDAC gain */
+ while(idacIdx < (CY_CAPSENSE_IDAC_GAIN_NUMBER - 1u))
+ {
+ if (context->ptrCommonConfig->idacGainTable[idacIdx].gainValue > (uint32_t)tempIDAC)
+ {
+ break;
+ }
+ idacIdx++;
+ }
+ idacGain = context->ptrCommonConfig->idacGainTable[idacIdx].gainValue;
+ /* Calculate the IDAC code */
+ idacCode = (uint32_t)((((tempIDAC * CY_CAPSENSE_BIST_IDAC_MAX) + idacGain) - 1u) / idacGain);
+ if (CY_CAPSENSE_BIST_IDAC_MAX < idacCode)
+ {
+ idacCode = CY_CAPSENSE_BIST_IDAC_MAX;
+ }
+ if (0u == idacCode)
+ {
+ idacCode = 1u;
+ }
+
+ context->ptrBistContext->extCapIdacPa = idacCode * idacGain;
+ Cy_CSD_WriteReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_IDACA, CY_CAPSENSE_BIST_CAP_IDAC_MODE_DEFAULT |
+ idacCode | context->ptrCommonConfig->idacGainTable[idacIdx].gainReg);
+
+ /* Connect the capacitor to the analog bus for further measurement */
+ Cy_CapSense_SsConfigPinRegisters(ptrCapPort, capacitorPin, CY_CAPSENSE_CSD_SCAN_PIN_DM, CY_CAPSENSE_HSIOM_SEL_CSD_SENSE);
+ /* Perform the measurement */
+ bistStatus = Cy_CapSense_BistMeasureCapacitanceCapRun(&extCapValue, context);
+ /* Disconnect and discharge the capacitor */
+ Cy_CapSense_SsConfigPinRegisters(ptrCapPort, capacitorPin, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
+ Cy_GPIO_Clr(ptrCapPort, capacitorPin);
+
+ if (CY_CAPSENSE_BIST_TIMEOUT_E != bistStatus)
+ {
+ *ptrResult = (uint16_t)extCapValue;
+ if(NULL != ptrValue)
+ {
+ *ptrValue = extCapValue;
+ }
+ }
+ /* Clear the BUSY flag */
+ context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY;
+ }
+ return (bistStatus);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceCapInit
+****************************************************************************//**
+*
+* This internal function calculates the parameters for the external capacitor
+* capacitance measurement and register values before speeding up
+* the execution.
+*
+* It is called by Cy_CapSense_BistDsInitialize() once at CapSense MW start.
+*
+* The following parameters of cy_stc_capsense_bist_context_t are used as
+* an input for the calculation:
+* * .extCapModClk
+* * .extCapVrefMv
+* * .extCapModClk
+*
+* The following parameters of cy_stc_capsense_bist_context_t are updated
+* by the calculation:
+* * .extCapModClk
+* * .extCapVrefMv
+* * .extCapVrefGain
+* * .extCapWDT
+*
+* Restarting CapSense MW or calling of the Cy_CapSense_BistDsInitialize()
+* function overwrites the output parameters.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistMeasureCapacitanceCapInit(
+ cy_stc_capsense_context_t * context)
+{
+ uint32_t temp;
+ cy_stc_capsense_bist_context_t * ptrBistCxt = context->ptrBistContext;
+
+ if (0u == ptrBistCxt->extCapModClk)
+ {
+ ptrBistCxt->extCapModClk = 1u;
+ }
+ while (CY_CAPSENSE_BIST_CAP_MEAS_MAX_MODCLK < (context->ptrCommonConfig->periClkHz / ptrBistCxt->extCapModClk))
+ {
+ ptrBistCxt->extCapModClk <<= 1u;
+ }
+
+ if(ptrBistCxt->extCapVrefMv == 0u)
+ {
+ /* Get the recommended reference voltage */
+ temp = CY_CAPSENSE_BIST_CAP_MEAS_VREF_MV_DEFAULT;
+ }
+ else
+ {
+ /* Use the user-defined reference voltage */
+ temp = (uint32_t)ptrBistCxt->extCapVrefMv;
+ }
+ ptrBistCxt->extCapVrefGain = (uint8_t)Cy_CapSense_GetVrefHighGain(temp, context);
+ ptrBistCxt->extCapVrefMv = (uint16_t)Cy_CapSense_GetVrefHighMv((uint32_t)ptrBistCxt->extCapVrefGain, context);
+
+ ptrBistCxt->extCapWDT = CY_CAPSENSE_BIST_CAP_MEAS_WDT_TIMEOUT;
+ ptrBistCxt->capacitorSettlingTime = CY_CAPSENSE_BIST_CAP_SETTLING_TIME_DEFAULT;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceCapEnable
+****************************************************************************//**
+*
+* This internal function configures the CSD HW block operation and
+* the HW block-level analog routing to the external capacitor capacitance
+* measurement test.
+*
+* Sets up the CSD HW block to perform the external capacitor capacitance
+* measuring.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistMeasureCapacitanceCapEnable(
+ cy_stc_capsense_context_t * context)
+{
+ CSD_Type * ptrCsdHwBase = context->ptrCommonConfig->ptrCsdBase;
+
+ /* Disable all interrupts from the HW block */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR_MASK, CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR_MASK);
+ /* Clear all pending interrupt requests */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR);
+
+ /* Set the divider value for mod clock (1u lower than the desired divider) */
+ Cy_CapSense_SetClkDivider(((uint32_t)context->ptrBistContext->extCapModClk - 1u), context);
+
+ Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ /* Wait for the maximum possible external capacitor charging time */
+ Cy_SysLib_DelayUs(context->ptrBistContext->capacitorSettlingTime);
+
+ /* Initialize the CSD registers to perform external capacitor capacitance measurement */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CONFIG, CY_CAPSENSE_BIST_CAP_CONFIG_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, CY_CAPSENSE_BIST_CAP_SW_REFGEN_SEL_SRSS_DEFAULT);
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ if (CY_CAPSENSE_IREF_PASS == context->ptrCommonConfig->ssIrefSource)
+ {
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CONFIG, CY_CAPSENSE_BIST_CAP_CONFIG_IREF_DEFAULT);
+ }
+ if (CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+ {
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, CY_CAPSENSE_BIST_CAP_SW_REFGEN_SEL_PASS_DEFAULT);
+ }
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IO_SEL, CY_CAPSENSE_BIST_CAP_IO_SEL_DEFAULT);
+ #endif
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_REFGEN, CY_CAPSENSE_BIST_CAP_REFGEN_DEFAULT | ((uint32_t)context->ptrBistContext->extCapVrefGain << CSD_REFGEN_GAIN_Pos));
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+ {
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_REFGEN, CY_CAPSENSE_BIST_CAP_REFGEN_LOW_VOLTAGE_DEFAULT);
+ }
+ #endif
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CSDCMP, CY_CAPSENSE_BIST_CAP_CSDCMP_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SENSE_DUTY, CY_CAPSENSE_BIST_CAP_SENSE_DUTY_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SENSE_PERIOD, (uint32_t)context->ptrBistContext->extCapSnsClk - 1u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_NORM_CNT, 1u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_TIME, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_INIT_CNT, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_CTL, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IDACA, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IDACB, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR_SET, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_HSCMP, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_AMBUF, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_RES, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_N_SEL, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, 0u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_AMUXBUF_SEL, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_DSI_SEL, 0uL);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_BYP_SEL, CY_CAPSENSE_BIST_CAP_SW_BYP_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_N_SEL, CY_CAPSENSE_BIST_CAP_SW_CMP_N_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_P_SEL, CY_CAPSENSE_BIST_CAP_SW_CMP_P_SEL_DEFAULT);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceCapRun
+****************************************************************************//**
+*
+* This internal function starts the specific scan for the external capacitor
+* capacitance measurement.
+*
+* \param ptrExtCapValue
+* The pointer to the result of the measurement in picofarads.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes
+* successfully, the result is valid.
+* - CY_CAPSENSE_BIST_LOW_LIMIT_E - A measured capacitance is below
+* the minimum possible value.
+* The measurement result is invalid.
+* The capacitor might be shorted to VDD or a
+* PCB track is broken (open capacitor).
+* - CY_CAPSENSE_BIST_HIGH_LIMIT_E - The measured capacitance is above the
+* maximum possible value.
+* The measurement result is invalid.
+* The capacitor might be shorted to GND.
+* - CY_CAPSENSE_BIST_TIMEOUT_E - The measuring scan is not finished properly
+* and reached the timeout.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceCapRun(
+ uint32_t * ptrExtCapValue,
+ cy_stc_capsense_context_t * context)
+{
+ uint32_t tempRawcount;
+ uint64_t tempCapacitance;
+ cy_en_capsense_bist_status_t bistStatus = CY_CAPSENSE_BIST_TIMEOUT_E;
+ CSD_Type * ptrCsdHwBase = context->ptrCommonConfig->ptrCsdBase;
+ uint32_t watchdogPeriod;
+
+ watchdogPeriod = Cy_CapSense_WatchdogCyclesNum(
+ (uint32_t)context->ptrBistContext->extCapWDT,
+ (context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA),
+ CY_CAPSENSE_BIST_CAP_MEAS_WDT_CYCLES_PER_LOOP);
+
+ /* Clear all pending interrupt requests */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR);
+
+ /* Start SEQUENCER for fine initialization and then for conversion */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_BIST_CAP_SEQ_START_DEFAULT);
+
+ /* Wait for the end of the scan and get the raw counts */
+ if (0u != Cy_CapSense_BistWaitEndOfScan(watchdogPeriod, context))
+ {
+ tempRawcount = Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_RESULT_VAL1) &
+ CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK;
+
+ /* Check for the measurement result status */
+ if (CY_CAPSENSE_BIST_CAP_MEAS_MIN_RAWCOUNT > tempRawcount)
+ {
+ bistStatus = CY_CAPSENSE_BIST_LOW_LIMIT_E;
+ }
+ else if (((uint32_t)context->ptrBistContext->extCapSnsClk - CY_CAPSENSE_BIST_CAP_MEAS_DUTY_WIDTH) < tempRawcount)
+ {
+ bistStatus = CY_CAPSENSE_BIST_HIGH_LIMIT_E;
+ }
+ else
+ {
+ bistStatus = CY_CAPSENSE_BIST_SUCCESS_E;
+ }
+
+ /* Calculate the capacitance value in pF */
+ tempCapacitance = (((((uint64_t)context->ptrBistContext->extCapIdacPa *
+ (uint64_t)context->ptrBistContext->extCapModClk) * (uint64_t)tempRawcount) *
+ (uint64_t)CY_CAPSENSE_BIST_PROMILLE_FACTOR) /
+ (uint64_t)context->ptrCommonConfig->periClkHz) /
+ (uint64_t)context->ptrBistContext->extCapVrefMv;
+ *ptrExtCapValue = (uint32_t)tempCapacitance;
+ }
+
+ return (bistStatus);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceCapAll
+****************************************************************************//**
+*
+* This internal function measures capacitance of all external capacitors.
+*
+* The function measures capacitances of all external capacitors Cmod,
+* Csh, CintA, CintB (if available in a design).
+* The function stores cap values in the corresponding registers.
+* The function is called by the Cy_CapSense_RunSelfTest() function.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes
+* successfully, the result is valid.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* - CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a previous
+* operation.
+* - CY_CAPSENSE_BIST_LOW_LIMIT_E - A measured capacitance is below
+* the minimum possible value.
+* The measurement result is invalid.
+* The capacitor might be shorted to VDD or a
+* PCB track is broken (open capacitor).
+* - CY_CAPSENSE_BIST_HIGH_LIMIT_E - The measured capacitance is above the
+* maximum possible value.
+* The measurement result is invalid.
+* The capacitor might be shorted to GND.
+* - CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during
+* the measurement, you may need to repeat the measurement.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceCapAll(
+ cy_stc_capsense_context_t * context)
+{
+ uint32_t capCapacitance = 0u;
+ cy_en_capsense_bist_status_t tempStatus;
+ cy_en_capsense_bist_status_t bistStatus = CY_CAPSENSE_BIST_SUCCESS_E;
+
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdEn)
+ {
+ tempStatus = Cy_CapSense_MeasureCapacitanceCap(CY_CAPSENSE_BIST_CMOD_ID_E, &capCapacitance,
+ CY_CAPSENSE_BIST_CAP_MEAS_CMOD_MAX_VALUE, context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != tempStatus)
+ {
+ bistStatus = tempStatus;
+ }
+ if ((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn) &&
+ (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn))
+ {
+ tempStatus = Cy_CapSense_MeasureCapacitanceCap(CY_CAPSENSE_BIST_CSH_ID_E, &capCapacitance,
+ CY_CAPSENSE_BIST_CAP_MEAS_CSH_MAX_VALUE, context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != tempStatus)
+ {
+ bistStatus = tempStatus;
+ }
+ }
+ }
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csxEn)
+ {
+ tempStatus = Cy_CapSense_MeasureCapacitanceCap(CY_CAPSENSE_BIST_CINTA_ID_E, &capCapacitance,
+ CY_CAPSENSE_BIST_CAP_MEAS_CINT_MAX_VALUE, context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != tempStatus)
+ {
+ bistStatus = tempStatus;
+ }
+ tempStatus = Cy_CapSense_MeasureCapacitanceCap(CY_CAPSENSE_BIST_CINTB_ID_E, &capCapacitance,
+ CY_CAPSENSE_BIST_CAP_MEAS_CINT_MAX_VALUE, context);
+ if (CY_CAPSENSE_BIST_SUCCESS_E != tempStatus)
+ {
+ bistStatus = tempStatus;
+ }
+ }
+
+ return (bistStatus);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureVdda
+****************************************************************************//**
+*
+* Measures a VDDA voltage, returns the measured voltage in
+* millivolts through the ptrValue argument and stores it to the .vddaVoltage
+* field of the \ref cy_stc_capsense_bist_context_t structure.
+*
+* This function measures the device analog supply voltage (VDDA) without need
+* of explicitly connecting VDDA to any additional GPIO input.
+* This capability can be used in variate cases, for example to monitor
+* the battery voltage.
+*
+* A measurement can be done only if the CapSense middleware is in the IDLE
+* state. This function must not be called while the CapSense middleware is busy.
+* The function is blocking, i.e. waits for the conversion to be completed
+* prior to returning to the caller.
+*
+* \param ptrValue
+* The pointer to the uint32_t to store measured VDDA voltage value.
+* If the ptrValue parameter is NULL then VDDA voltage value is not returned
+* through the parameter and is stored in the .vddaVoltage
+* field of the \ref cy_stc_capsense_bist_context_t structure.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The measurement executed
+* successfully.
+* - CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid.
+* The measurement was not executed.
+* - CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during
+* the measurement.
+* - CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the
+* configuration. The measurement was not
+* executed.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureVdda(
+ uint32_t * ptrValue,
+ cy_stc_capsense_context_t * context)
+{
+ cy_en_capsense_return_status_t csStatus;
+ cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+
+ if (NULL != context)
+ {
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ csStatus = Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_SENSE_METHOD_BIST_E, context);
+
+ if (CY_CAPSENSE_SUCCESS_E == csStatus)
+ {
+ Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_VDDA_E, context);
+ result = Cy_CapSense_BistMeasureVddaRun(context);
+ if ((NULL != ptrValue) && (CY_CAPSENSE_BIST_SUCCESS_E == result))
+ {
+ *ptrValue = (uint16_t)context->ptrBistContext->vddaVoltage;
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_ERROR_E;
+ }
+ }
+ else
+ {
+ result = CY_CAPSENSE_BIST_FEATURE_DISABLED_E;
+ }
+ }
+
+ return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureVddaInit
+****************************************************************************//**
+*
+* This internal function calculates the parameters for VDDA measurement
+* and register values before speeding up the execution.
+*
+* It is called by Cy_CapSense_BistDsInitialize() once at the CapSense MW start.
+*
+* The following parameters of cy_stc_capsense_bist_context_t are used as
+* an input for the calculation:
+* * .vddaModClk
+* * .vddaVrefMv
+*
+* The following parameters of cy_stc_capsense_bist_context_t are updated
+* by the calculation:
+* * .vddaModClk
+* * .vddaVrefMv
+* * .vddaVrefGain
+* * .vddaIdacDefault
+* * .vddaAzCycles
+* * .vddaAcqCycles
+*
+* Restarting CapSense MW or calling of the Cy_CapSense_BistDsInitialize()
+* function overwrites the output parameters.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistMeasureVddaInit(cy_stc_capsense_context_t * context)
+{
+ uint32_t idacVal;
+ uint32_t vddaValMv;
+ uint32_t vrefValMv;
+ uint32_t maxVoltageMv;
+ uint32_t fsmFreqHz;
+
+ vddaValMv = (uint32_t)context->ptrCommonConfig->vdda;
+ vrefValMv = (uint32_t)context->ptrBistContext->vddaVrefMv;
+
+ /* Check for the Vref limitations */
+ if (vrefValMv > (vddaValMv - CY_CAPSENSE_BIST_VDDA_MIN_DIFF))
+ {
+ vrefValMv = (vddaValMv - CY_CAPSENSE_BIST_VDDA_MIN_DIFF);
+ }
+ if(vrefValMv < CY_CAPSENSE_BIST_VDDA_VREF_MIN_MV)
+ {
+ vrefValMv = CY_CAPSENSE_BIST_VDDA_VREF_MIN_MV;
+ }
+
+ /* Calculate the refgen gain for the desired reference voltage */
+ context->ptrBistContext->vddaVrefGain = (uint8_t)Cy_CapSense_GetVrefHighGain(vrefValMv, context);
+ /* Calculate the reference voltage */
+ vrefValMv = Cy_CapSense_GetVrefHighMv((uint32_t)context->ptrBistContext->vddaVrefGain, context);
+
+ /* Update the nominal Vref to real Vref considering available trimming for SRSS */
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ if(CY_CAPSENSE_VREF_SRSS == context->ptrCommonConfig->ssVrefSource)
+ {
+ vrefValMv = Cy_CSD_GetVrefTrim(vrefValMv);
+ }
+ #endif
+
+ maxVoltageMv = (((vddaValMv - vrefValMv) > vrefValMv) ? (vddaValMv - vrefValMv) : vrefValMv);
+
+ if (context->ptrBistContext->vddaModClk == 0u)
+ {
+ context->ptrBistContext->vddaModClk = 1u;
+ }
+ if ((context->ptrCommonConfig->periClkHz / context->ptrBistContext->vddaModClk) > CY_CAPSENSE_BIST_VDDA_MAX_MODCLK)
+ {
+ context->ptrBistContext->vddaModClk++;
+ }
+ idacVal = (context->ptrCommonConfig->periClkHz / CY_CAPSENSE_BIST_VDDA_RES) / context->ptrBistContext->vddaModClk;
+ idacVal = (((idacVal * maxVoltageMv) / CY_CAPSENSE_CONVERSION_MEGA) * CY_CAPSENSE_BIST_VDDA_CREF) /
+ CY_CAPSENSE_BIST_VDDA_IDAC_LSB;
+
+ if (CY_CAPSENSE_BIST_IDAC_MAX < idacVal)
+ {
+ idacVal = CY_CAPSENSE_BIST_IDAC_MAX;
+ }
+ if (0u == idacVal)
+ {
+ idacVal = 1u;
+ }
+
+ context->ptrBistContext->vddaIdacDefault = (uint8_t)idacVal;
+ context->ptrBistContext->vddaVrefMv = (uint16_t)vrefValMv;
+
+ fsmFreqHz = (context->ptrCommonConfig->periClkHz / context->ptrBistContext->vddaModClk) /
+ CY_CAPSENSE_BIST_VDDA_SENSE_PERIOD_DEFAULT;
+ context->ptrBistContext->vddaAzCycles = (uint8_t)((CY_CAPSENSE_BIST_VDDA_AZ_TIME_US * fsmFreqHz) /
+ CY_CAPSENSE_CONVERSION_MEGA);
+ context->ptrBistContext->vddaAcqCycles = (uint8_t)((CY_CAPSENSE_BIST_VDDA_ACQ_TIME_US * fsmFreqHz) /
+ CY_CAPSENSE_CONVERSION_MEGA);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureVddaEnable
+****************************************************************************//**
+*
+* This internal function configures the CSD HW block operation and the
+* block-level analog routing for the VDDA measurement.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistMeasureVddaEnable(cy_stc_capsense_context_t * context)
+{
+ uint32_t temp;
+ CSD_Type * ptrCsdHwBase = context->ptrCommonConfig->ptrCsdBase;
+
+ /* Disable all interrupts from the HW block */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR_MASK, CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR_MASK);
+ /* Clear all pending interrupt requests */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR);
+
+ /* Set the divider value for mod clock (1u lower than the desired divider) */
+ Cy_CapSense_SetClkDivider(((uint32_t)context->ptrBistContext->vddaModClk - 1u), context);
+
+ Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+ /* Wait for the maximum possible external capacitor charging time */
+ Cy_SysLib_DelayUs(context->ptrBistContext->capacitorSettlingTime);
+
+ /* Configure the HW block for operation in VDDA measurement mode */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CONFIG, CY_CAPSENSE_BIST_VDDA_CONFIG_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGR_MSK);
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ if (CY_CAPSENSE_IREF_PASS == context->ptrCommonConfig->ssIrefSource)
+ {
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CONFIG,
+ CY_CAPSENSE_BIST_VDDA_CONFIG_DEFAULT | CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK);
+ }
+ if (CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+ {
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_REFGEN_SEL, CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRP_MSK);
+ }
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IO_SEL, CY_CAPSENSE_BIST_VDDA_IO_SEL_DEFAULT);
+ #endif
+
+ /* RefGen initialization */
+ temp = CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_RES_EN_Msk |
+ ((uint32_t)(context->ptrBistContext->vddaVrefGain) << CSD_REFGEN_GAIN_Pos);
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+ {
+ temp = CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk;
+ }
+ #endif
+
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_HSCMP, CY_CAPSENSE_BIST_VDDA_HSCMP_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_AMBUF, CY_CAPSENSE_BIST_VDDA_AMBUF_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_REFGEN, temp);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SENSE_PERIOD, (uint32_t)CY_CAPSENSE_BIST_VDDA_SENSE_PERIOD_DEFAULT - 1u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_CSDCMP, CY_CAPSENSE_BIST_VDDA_CSDCMP_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IDACA, CY_CAPSENSE_BIST_VDDA_IDACA_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_IDACB, (uint32_t)CY_CAPSENSE_BIST_VDDA_IDACB_DEFAULT |
+ context->ptrBistContext->vddaIdacDefault);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_TIME, (uint32_t)context->ptrBistContext->vddaAzCycles - 1u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_CTL, (uint32_t)context->ptrBistContext->vddaAcqCycles - 1u);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SENSE_DUTY, CY_CAPSENSE_BIST_VDDA_SENSE_DUTY_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_INIT_CNT, CY_CAPSENSE_BIST_VDDA_SEQ_INIT_CNT_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_NORM_CNT, CY_CAPSENSE_BIST_VDDA_SEQ_NORM_CNT_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_RES, CY_CAPSENSE_BIST_VDDA_SW_RES_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_P_SEL, CY_CAPSENSE_BIST_VDDA_SW_HS_P_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_HS_N_SEL, CY_CAPSENSE_BIST_VDDA_SW_HS_N_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, CY_CAPSENSE_BIST_VDDA_SW_SHIELD_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_AMUXBUF_SEL, CY_CAPSENSE_BIST_VDDA_SW_AMUXBUF_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_BYP_SEL, CY_CAPSENSE_BIST_VDDA_SW_BYP_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_P_SEL, CY_CAPSENSE_BIST_VDDA_SW_CMP_P_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_CMP_N_SEL, CY_CAPSENSE_BIST_VDDA_SW_CMP_N_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_FW_MOD_SEL, CY_CAPSENSE_BIST_VDDA_SW_FW_MOD_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_FW_TANK_SEL, CY_CAPSENSE_BIST_VDDA_SW_FW_TANK_SEL_DEFAULT);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_DSI_SEL, CY_CAPSENSE_BIST_VDDA_SW_DSI_SEL_DEFAULT);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureVddaRun
+****************************************************************************//**
+*
+* This internal function initiates the analog to digital conversion and
+* converts the measurement result to the voltage in millivolts.
+*
+* The function performs the following tasks:
+* * Measures the time to bring Cref1 + Cref2 up from Vssa to Vrefhi.
+* * Measures the time to bring Cref1 + Cref2 back up to Vrefhi
+* (after bringing them down for time A/2 cycles with IDACB sinking).
+* * Measures the time to bring Cref1 + Cref2 from Vdda to Vrefhi.
+* * Converts the results of measurements to millivolts.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes
+* successfully, the result is valid.
+* - CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during
+* the measurement, you may need to repeat
+* the measurement.
+*
+*******************************************************************************/
+static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureVddaRun(
+ cy_stc_capsense_context_t * context)
+{
+ uint32_t vddaValue;
+ uint32_t tVssa2Vref = 0u;
+ uint32_t tRecover = 0u;
+ uint32_t tVdda2Vref = 0u;
+ uint32_t watchdogPeriod;
+ uint32_t watchdogCounter;
+ cy_en_csd_status_t conversionStatus;
+ cy_en_capsense_bist_status_t retStatus = CY_CAPSENSE_BIST_SUCCESS_E;
+ CSD_Type * ptrCsdHwBase = context->ptrCommonConfig->ptrCsdBase;
+
+ watchdogPeriod = Cy_CapSense_WatchdogCyclesNum(
+ CY_CAPSENSE_BIST_VDDA_WDT_TIMEOUT,
+ (context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA),
+ CY_CAPSENSE_BIST_VDDA_WDT_CYCLES_PER_LOOP);
+
+ /* Set the BUSY status */
+ context->ptrCommonContext->status = CY_CAPSENSE_BUSY;
+
+ /*
+ * Phase 1:
+ * Measures the time to bring Cref1 + Cref2 up from Vssa to Vrefhi
+ */
+ Cy_CSD_WriteBits(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_CTL, CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK,
+ (uint32_t)CY_CAPSENSE_BIST_VDDA_MEASMODE_VREF);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_BIST_VDDA_SEQ_START_MEASURE);
+ watchdogCounter = watchdogPeriod;
+ do
+ {
+ conversionStatus = Cy_CSD_GetConversionStatus(ptrCsdHwBase, context->ptrCommonConfig->ptrCsdContext);
+ watchdogCounter--;
+ }
+ while((CY_CSD_BUSY == conversionStatus) && (0u != watchdogCounter));
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR);
+ tVssa2Vref = Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_RES);
+ if ((0u != (tVssa2Vref & CY_CAPSENSE_CSD_ADC_RES_ADC_OVERFLOW_MSK)) || (0u == watchdogCounter))
+ {
+ retStatus = CY_CAPSENSE_BIST_ERROR_E;
+ }
+
+ /*
+ * Phase 2:
+ * Measures the time to bring Cref1 + Cref2 back up to Vrefhi
+ * (after bringing them down for time A/2 cycles with IDACB sinking)
+ */
+ if(CY_CAPSENSE_BIST_SUCCESS_E == retStatus)
+ {
+ Cy_CSD_WriteBits(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_CTL, CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK,
+ (uint32_t)CY_CAPSENSE_BIST_VDDA_MEASMODE_VREFBY2);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_BIST_VDDA_SEQ_START_MEASURE);
+ watchdogCounter = watchdogPeriod;
+ do
+ {
+ conversionStatus = Cy_CSD_GetConversionStatus(ptrCsdHwBase, context->ptrCommonConfig->ptrCsdContext);
+ watchdogCounter--;
+ }
+ while((CY_CSD_BUSY == conversionStatus) && (0u != watchdogCounter));
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR);
+ tRecover = Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_RES);
+ if ((0u != (tRecover & CY_CAPSENSE_CSD_ADC_RES_ADC_OVERFLOW_MSK)) || (0u == watchdogCounter))
+ {
+ retStatus = CY_CAPSENSE_BIST_ERROR_E;
+ }
+ }
+
+ /*
+ * Phase 3:
+ * Measures the time to bring Cref1 + Cref2 from Vdda to Vrefhi
+ */
+ if(CY_CAPSENSE_BIST_SUCCESS_E == retStatus)
+ {
+ /* Connect VDDA to csdbusb */
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SW_SHIELD_SEL, CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_STATIC_CLOSE);
+ Cy_CSD_WriteBits(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_CTL, CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK,
+ (uint32_t)CY_CAPSENSE_BIST_VDDA_MEASMODE_VIN);
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_SEQ_START, CY_CAPSENSE_BIST_VDDA_SEQ_START_MEASURE);
+ watchdogCounter = watchdogPeriod;
+ do
+ {
+ conversionStatus = Cy_CSD_GetConversionStatus(ptrCsdHwBase, context->ptrCommonConfig->ptrCsdContext);
+ watchdogCounter--;
+ }
+ while((CY_CSD_BUSY == conversionStatus) && (0u != watchdogCounter));
+ Cy_CSD_WriteReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR, CY_CAPSENSE_CSD_INTR_ALL_MSK);
+ (void)Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_INTR);
+ tVdda2Vref = Cy_CSD_ReadReg(ptrCsdHwBase, CY_CSD_REG_OFFSET_ADC_RES);
+ if ((0u != (tVdda2Vref & CY_CAPSENSE_CSD_ADC_RES_ADC_OVERFLOW_MSK)) || (0u == watchdogCounter))
+ {
+ retStatus = CY_CAPSENSE_BIST_ERROR_E;
+ }
+ }
+
+ /*
+ * Phase 4:
+ * Convert the results of measurements to millivolts.
+ */
+ if(CY_CAPSENSE_BIST_SUCCESS_E == retStatus)
+ {
+ tVssa2Vref &= CY_CAPSENSE_CSD_ADC_RES_VALUE_MSK;
+ tRecover &= CY_CAPSENSE_CSD_ADC_RES_VALUE_MSK;
+ tVdda2Vref &= CY_CAPSENSE_CSD_ADC_RES_VALUE_MSK;
+
+ /* Adjust tVdda2Vref based on IDAC sink / source mismatch */
+ tVdda2Vref = (((2u * tRecover) * tVdda2Vref) + (tVssa2Vref >> 1u)) / tVssa2Vref;
+ /* Calculate VDDA */
+ vddaValue = context->ptrBistContext->vddaVrefMv;
+ vddaValue += ((vddaValue * tVdda2Vref) + (tVssa2Vref >> 1uL)) / tVssa2Vref;
+ /* Check for overflow */
+ if (CY_CAPSENSE_BIST_VDDA_MAX_16_BITS < vddaValue)
+ {
+ vddaValue = CY_CAPSENSE_BIST_VDDA_MAX_16_BITS;
+ }
+ context->ptrBistContext->vddaVoltage = (uint16_t)vddaValue;
+ }
+
+ /* Clear the BUSY flag */
+ context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY;
+
+ return (retStatus);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistInitialize
+****************************************************************************//**
+*
+* The internal function initializes some critical parameters
+* for Built-in Self-test (BIST) mode.
+*
+* This function prepares the resource capturing to execute the BIST functions.
+* The HW resource configuring is performed by the Cy_CapSense_BistSwitchHwConfig()
+* function depending on a the type of the test to be executed.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistInitialize(cy_stc_capsense_context_t * context)
+{
+ /*
+ * This function prepares the BIST HW and pins re-configuring by setting some
+ * critical internal parameters to undefined states.
+ * Use this function after switching from CSD or CSX sensing modes.
+ */
+ context->ptrBistContext->hwConfig = CY_CAPSENSE_BIST_HW_UNDEFINED_E;
+ context->ptrBistContext->currentISC = CY_CAPSENSE_BIST_IO_UNDEFINED_E;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDisableMode
+****************************************************************************//**
+*
+* This internal function releases HW resources and pins captured by BIST
+* to be used by other CapSense modes.
+*
+* This function releases the shared HW resources like connection
+* to the analog bus.
+* The function does not configure CSD HW block registers to the default state.
+* It is used by the Cy_CapSense_SwitchSensingMode() function only at switching
+* to another sensing mode.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistDisableMode(cy_stc_capsense_context_t * context)
+{
+ Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_UNDEFINED_E, context);
+
+ Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_UNDEFINED_E, context);
+ Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_UNDEFINED_E, context);
+ Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDsInitialize
+****************************************************************************//**
+*
+* This internal function initializes the BIST cy_stc_capsense_bist_context_t
+* data structure parameters to be used in the test execution.
+*
+* The function is called once at the CapSense start and performs the CSD HW block
+* register pre-calculation based on the configured parameters.
+*
+* Some of the parameters of the \ref cy_stc_capsense_bist_context_t structure
+* can be changed in the run-time, but some changes require repeating the call
+* of this function to the re-calculate register values.
+* Refer to description of the following functions which parameters are used
+* as an input and which are outputs:
+* * Cy_CapSense_BistMeasureCapacitanceSensorInit()
+* * Cy_CapSense_BistMeasureCapacitanceCapInit()
+* * Cy_CapSense_BistMeasureVddaInit()
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistDsInitialize(cy_stc_capsense_context_t * context)
+{
+ uint32_t wdIndex;
+ uint32_t wdNum = (uint32_t)context->ptrCommonConfig->numWd;
+
+ /* Initialize CRC and status for all widgets */
+ for (wdIndex = 0u; wdIndex < wdNum; wdIndex++)
+ {
+ Cy_CapSense_UpdateCrcWidget(wdIndex, context);
+ context->ptrWdContext[wdIndex].status |= (uint8_t)CY_CAPSENSE_WD_WORKING_MASK;
+ }
+
+ Cy_CapSense_BistMeasureCapacitanceSensorInit(context);
+ Cy_CapSense_BistMeasureCapacitanceCapInit(context);
+ Cy_CapSense_BistMeasureVddaInit(context);
+
+ context->ptrBistContext->hwConfig = CY_CAPSENSE_BIST_HW_UNDEFINED_E;
+ context->ptrBistContext->currentISC = CY_CAPSENSE_BIST_IO_UNDEFINED_E;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistSwitchHwConfig
+****************************************************************************//**
+*
+* This internal function switches the CSD HW block configuration for
+* BIST operations.
+*
+* The function checks the current CSD HW block configuration.
+* If it differs from a desired configuration, the function disables the current
+* configuration and sets the desired one.
+*
+* \param hwCfg
+* Specifies the desired configuration.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistSwitchHwConfig(
+ cy_en_capsense_bist_hw_config_t hwCfg,
+ cy_stc_capsense_context_t * context)
+{
+ if (context->ptrBistContext->hwConfig != hwCfg)
+ {
+ context->ptrBistContext->hwConfig = hwCfg;
+ /* Enable the specified mode */
+ switch(hwCfg)
+ {
+ case CY_CAPSENSE_BIST_HW_SHORT_E:
+ {
+ /* Nothing to do */
+ break;
+ }
+ case CY_CAPSENSE_BIST_HW_ELTD_CAP_E:
+ {
+ Cy_CapSense_BistMeasureCapacitanceSensorEnable(context);
+ break;
+ }
+ case CY_CAPSENSE_BIST_HW_ELTD_CAP_SH_E:
+ {
+ Cy_CapSense_BistMeasureCapacitanceSensorShieldEnable(context);
+ break;
+ }
+ case CY_CAPSENSE_BIST_HW_EXTERNAL_CAP_E:
+ {
+ Cy_CapSense_BistMeasureCapacitanceCapEnable(context);
+ break;
+ }
+ case CY_CAPSENSE_BIST_HW_VDDA_E:
+ {
+ Cy_CapSense_BistMeasureVddaEnable(context);
+ break;
+ }
+ default:
+ {
+ /* Nothing to do */
+ break;
+ }
+ }
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistSwitchAllSnsPinState
+****************************************************************************//**
+*
+* This internal function sets all the port control (PC), data (DR) and HSIOM
+* registers of all sensor pins to the desired state.
+*
+* The function sets the desired state for the pin port control register (PC),
+* the output data register (DR) and the HSIOM register for all sensor pins
+* (Drive Mode, output state, and HSIOM state).
+*
+* \param desiredPinState
+* Specifies the desired pin state. See the possible states
+* in the cy_en_capsense_bist_io_state_t enum description.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistSwitchAllSnsPinState(
+ cy_en_capsense_bist_io_state_t desiredPinState,
+ const cy_stc_capsense_context_t * context)
+{
+ uint32_t desiredDriveMode = CY_GPIO_DM_ANALOG;
+ en_hsiom_sel_t desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+ uint32_t desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+
+ if (context->ptrBistContext->currentISC != desiredPinState)
+ {
+ /* Change Drive mode and HSIOM depending on the current inactive sensor connection */
+ if (CY_CAPSENSE_BIST_IO_STRONG_E == desiredPinState)
+ {
+ desiredDriveMode = CY_GPIO_DM_STRONG_IN_OFF;
+ desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+ desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+ }
+ else if (CY_CAPSENSE_BIST_IO_SENSE_E == desiredPinState)
+ {
+ desiredDriveMode = CY_CAPSENSE_CSD_SCAN_PIN_DM;
+ desiredHsiom = CY_CAPSENSE_HSIOM_SEL_CSD_SENSE;
+ desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+ }
+ else if (CY_CAPSENSE_BIST_IO_SHIELD_E == desiredPinState)
+ {
+ desiredDriveMode = CY_CAPSENSE_CSD_SCAN_PIN_DM;
+ desiredHsiom = CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD;
+ desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+ }
+ else if (CY_CAPSENSE_BIST_IO_STRONG_HIGH_E == desiredPinState)
+ {
+ desiredDriveMode = CY_GPIO_DM_STRONG_IN_OFF;
+ desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+ desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2VDD;
+ }
+ else
+ {
+ }
+ /* Set all sensor electrodes to the desired state.*/
+ Cy_CapSense_SetIOsInDesiredState(desiredDriveMode, desiredPinOutput, desiredHsiom, context);
+ context->ptrBistContext->currentISC = desiredPinState;
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistSwitchAllShieldPinState
+****************************************************************************//**
+*
+* This internal function sets all the port control (PC), data (DR) and HSIOM
+* registers of all shield pins to the desired state.
+*
+* The function sets the desired state for the pin port control register (PC),
+* the output data register (DR) and the HSIOM register for all shield pins
+* (Drive Mode, output state, and HSIOM state).
+*
+* \param desiredPinState
+* Specifies the desired pin state. See the possible states
+* in the cy_en_capsense_bist_io_state_t enum description.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistSwitchAllShieldPinState(
+ cy_en_capsense_bist_io_state_t desiredPinState,
+ const cy_stc_capsense_context_t * context)
+{
+ uint32_t desiredDriveMode = CY_GPIO_DM_ANALOG;
+ en_hsiom_sel_t desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+ uint32_t desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+
+ if ((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdEn) &&
+ (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn))
+ {
+ /* Change Drive mode and HSIOM depending on the current inactive sensor connection */
+ if (CY_CAPSENSE_BIST_IO_STRONG_E == desiredPinState)
+ {
+ desiredDriveMode = CY_GPIO_DM_STRONG_IN_OFF;
+ desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+ desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+ }
+ else if (CY_CAPSENSE_BIST_IO_SENSE_E == desiredPinState)
+ {
+ desiredDriveMode = CY_CAPSENSE_CSD_SCAN_PIN_DM;
+ desiredHsiom = CY_CAPSENSE_HSIOM_SEL_CSD_SENSE;
+ desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+ }
+ else if (CY_CAPSENSE_BIST_IO_SHIELD_E == desiredPinState)
+ {
+ desiredDriveMode = CY_CAPSENSE_CSD_SCAN_PIN_DM;
+ desiredHsiom = CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD;
+ desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+ }
+ else if (CY_CAPSENSE_BIST_IO_STRONG_HIGH_E == desiredPinState)
+ {
+ desiredDriveMode = CY_GPIO_DM_STRONG_IN_OFF;
+ desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+ desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2VDD;
+ }
+ else
+ {
+ }
+ /* Set all CapSense pins to the desired state */
+ Cy_CapSense_SetShieldPinState(desiredDriveMode, desiredPinOutput, desiredHsiom, context);
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistSwitchAllExternalCapPinState
+****************************************************************************//**
+*
+* The internal function sets all the port control (PC), data (DR) and HSIOM
+* registers of all external capacitor pins to the desired state.
+*
+* The function sets the desired state for the pin port control register (PC),
+* the output data register (DR) and the HSIOM register for all external
+* capacitor pins (Drive Mode, output state, and HSIOM state).
+*
+* \param desiredPinState
+* Specifies the desired pin state. See the possible states
+* in the cy_en_capsense_bist_io_state_t enum description.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistSwitchAllExternalCapPinState(
+ cy_en_capsense_bist_io_state_t desiredPinState,
+ const cy_stc_capsense_context_t * context)
+{
+ /* If CSD is enabled, set the Cmod pin to the desired state */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdEn)
+ {
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
+ if (CY_CAPSENSE_BIST_IO_STRONG_HIGH_E == desiredPinState)
+ {
+ Cy_GPIO_Set(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod);
+ }
+ else
+ {
+ Cy_GPIO_Clr(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod);
+ }
+
+ /* If Csh is enabled, set the Csh pin to the desired state */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn)
+ {
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
+ if (CY_CAPSENSE_BIST_IO_STRONG_HIGH_E == desiredPinState)
+ {
+ Cy_GPIO_Set(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh);
+ }
+ else
+ {
+ Cy_GPIO_Clr(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh);
+ }
+ }
+ }
+
+ /* If CSX is enabled, set the CintA and CintB pins to the desired state */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csxEn)
+ {
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA, (uint32_t)context->ptrCommonConfig->pinCintA, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
+ Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB, (uint32_t)context->ptrCommonConfig->pinCintB, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
+ if (CY_CAPSENSE_BIST_IO_STRONG_HIGH_E == desiredPinState)
+ {
+ Cy_GPIO_Set(context->ptrCommonConfig->portCintA, (uint32_t)context->ptrCommonConfig->pinCintA);
+ Cy_GPIO_Set(context->ptrCommonConfig->portCintB, (uint32_t)context->ptrCommonConfig->pinCintB);
+ }
+ else
+ {
+ Cy_GPIO_Clr(context->ptrCommonConfig->portCintA, (uint32_t)context->ptrCommonConfig->pinCintA);
+ Cy_GPIO_Clr(context->ptrCommonConfig->portCintB, (uint32_t)context->ptrCommonConfig->pinCintB);
+ }
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SetShieldPinState
+****************************************************************************//**
+*
+* This internal function sets all the port control (PC), data (DR) and HSIOM
+* registers of all shield pins to the desired state.
+*
+* The function sets the desired state of the pin the port control register (PC),
+* output data register (DR) and HSIOM register for all shield (if defined) pins
+* (Drive Mode, output state and HSIOM state).
+* The function is called by the Cy_CapSense_BistSwitchAllShieldPinState()
+* function and by the shield capacity measurement test. Do not call this
+* function directly from the application program - the project
+* behavior is unpredictable.
+*
+* \param desiredDriveMode
+* Specifies the desired pin control port (PC) configuration.
+*
+* \param desiredPinOutput
+* Specifies the desired pin output data register (DR) state.
+*
+* \param desiredHsiom
+* Specifies the desired pin HSIOM state.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_SetShieldPinState(
+ uint32_t desiredDriveMode,
+ uint32_t desiredPinOutput,
+ en_hsiom_sel_t desiredHsiom,
+ const cy_stc_capsense_context_t * context)
+{
+ uint32_t loopIndex;
+ const cy_stc_capsense_pin_config_t * ptrPinCfg;
+
+ /* Set the shield pins to the desired state */
+ ptrPinCfg = context->ptrShieldPinConfig;
+ for (loopIndex = 0u; loopIndex < context->ptrCommonConfig->csdShieldNumPin; loopIndex++)
+ {
+ Cy_CapSense_SsConfigPinRegisters(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber, desiredDriveMode, desiredHsiom);
+ if (0u != desiredPinOutput)
+ {
+ Cy_GPIO_Set(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber);
+ }
+ else
+ {
+ Cy_GPIO_Clr(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber);
+ }
+ /* Get a next electrode */
+ ptrPinCfg++;
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistConnectElectrode
+****************************************************************************//**
+*
+* This internal function connects the electrode (including a ganged one)
+* to the CSD HW block via the AMUX bus.
+*
+* The function gets the pin configuration registers addresses, their shifts and
+* masks from the cy_stc_capsense_pin_config_t object. Based on this data, it
+* updates the HSIOM and PC registers.
+*
+* Do not call this function directly from the application program -
+* the project behavior is unpredictable.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param electrodeId
+* Specifies the ID of the sensor (electrode for CSX widgets) within the widget
+* to be measured.
+*
+* For the CSD widgets, a macro for the electrodeId is identical
+* to the sensor ID within the specified widget and can be found
+* in the CapSense Configuration header file (cycfg_capsense.h)
+* defined as CY_CAPSENSE__SNS_ID.
+*
+* For the CSX widgets, the electrodeId is defined as Rx electrode ID
+* or Tx electrode ID. The first Rx in a widget corresponds to electrodeId = 0,
+* the second Rx in a widget corresponds to electrodeId = 1, and so on.
+* The last Tx in a widget corresponds to electrodeId = (RxNum + TxNum - 1).
+* Macros for Rx and Tx IDs can be found in the CapSense Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense__RX_ID
+* * CapSense__TX_ID.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistConnectElectrode(
+ uint32_t widgetId,
+ uint32_t electrodeId,
+ const cy_stc_capsense_context_t * context)
+{
+ uint32_t i;
+ const cy_stc_capsense_electrode_config_t * ptrEltdCfg = &context->ptrWdConfig[widgetId].ptrEltdConfig[electrodeId];
+ const cy_stc_capsense_pin_config_t * ptrPinCfg = ptrEltdCfg->ptrPin;
+
+ /* Connect all electrode pins */
+ for(i = 0u; i < ptrEltdCfg->numPins; i++)
+ {
+ Cy_CapSense_SsConfigPinRegisters(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber,
+ CY_CAPSENSE_CSD_SCAN_PIN_DM, CY_CAPSENSE_HSIOM_SEL_CSD_SENSE);
+ ptrPinCfg++;
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDisconnectElectrode
+****************************************************************************//**
+*
+* This internal function disconnects the electrode (including a ganged one)
+* from the CSD HW block and sets all its pins to the configured
+* in the .snsCapCsdISC or .snsCapCsxISC fields
+* of the cy_stc_capsense_bist_context_t structure.
+*
+* The function gets the pin configuration registers addresses, their shifts and
+* masks from the cy_stc_capsense_pin_config_t object. Based on this data, it
+* updates the HSIOM and PC registers.
+*
+* Do not call this function directly from the application program -
+* the project behavior is unpredictable.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param electrodeId
+* Specifies the ID of the sensor (electrode for CSX widgets) within the widget
+* to be measured.
+*
+* For the CSD widgets, a macro for the electrodeId is identical
+* to the sensor ID within the specified widget and can be found
+* in the CapSense Configuration header file (cycfg_capsense.h)
+* defined as CY_CAPSENSE__SNS_ID.
+*
+* For the CSX widgets, the electrode ID is defined as Rx electrode ID
+* or Tx electrode ID. The first Rx in a widget corresponds to electrodeId = 0,
+* the second Rx in a widget corresponds to electrodeId = 1, and so on.
+* The last Tx in a widget corresponds to electrodeId = (RxNum + TxNum - 1).
+* Macros for Rx and Tx IDs can be found in the CapSense Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense__RX_ID
+* * CapSense__TX_ID.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistDisconnectElectrode(
+ uint32_t widgetId,
+ uint32_t electrodeId,
+ const cy_stc_capsense_context_t * context)
+
+{
+ uint32_t i;
+ uint32_t driveModeTmp;
+ en_hsiom_sel_t hsiomTmp;
+ const cy_stc_capsense_electrode_config_t * ptrEltdCfg = &context->ptrWdConfig[widgetId].ptrEltdConfig[electrodeId];
+ const cy_stc_capsense_pin_config_t * ptrPinCfg = ptrEltdCfg->ptrPin;
+
+ /* Change Drive mode and HSIOM depending on the current inactive sensor connection */
+ switch (context->ptrBistContext->currentISC)
+ {
+ case CY_CAPSENSE_BIST_IO_STRONG_E:
+ driveModeTmp = CY_GPIO_DM_STRONG_IN_OFF;
+ hsiomTmp = CY_CAPSENSE_HSIOM_SEL_GPIO;
+ break;
+ case CY_CAPSENSE_BIST_IO_SHIELD_E:
+ driveModeTmp = CY_CAPSENSE_CSD_SCAN_PIN_DM;
+ hsiomTmp = CY_CAPSENSE_HSIOM_SEL_AMUXB;
+ break;
+ default:
+ driveModeTmp = CY_GPIO_DM_ANALOG;
+ hsiomTmp = CY_CAPSENSE_HSIOM_SEL_GPIO;
+ break;
+ }
+
+ /* Disconnect all electrode pins */
+ for(i = 0u; i < ptrEltdCfg->numPins; i++)
+ {
+ Cy_CapSense_SsConfigPinRegisters(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber, driveModeTmp, hsiomTmp);
+ Cy_GPIO_Clr(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber);
+
+ ptrPinCfg++;
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistWaitEndOfScan
+****************************************************************************//**
+*
+* This internal function checks for the scan status. If the scan ends before
+* the software watch-dog triggering, the function returns a non-zero watch-dog
+* cycles number. If the software watch-dog triggers during the scan,
+* the function returns zero.
+*
+* \param watchdogCycleNum
+* A watch-dog cycle number to check a timeout.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns watch-dog counter. If it is equal to zero, it means timeout happened.
+*
+*******************************************************************************/
+static uint32_t Cy_CapSense_BistWaitEndOfScan(
+ uint32_t watchdogCycleNum,
+ const cy_stc_capsense_context_t * context)
+{
+ uint32_t watchdogCounter = watchdogCycleNum;
+
+ while (((Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR) &
+ CY_CAPSENSE_CSD_INTR_SAMPLE_MSK) == 0u) && (0u != watchdogCounter))
+ {
+ watchdogCounter--;
+ }
+
+ return (watchdogCounter);
+}
+
+
+#endif /* CY_IP_MXCSDV2 */
+
+
+/* [] END OF FILE */
diff --git a/cy_capsense_selftest.h b/cy_capsense_selftest.h
new file mode 100644
index 0000000..14c010e
--- /dev/null
+++ b/cy_capsense_selftest.h
@@ -0,0 +1,153 @@
+/***************************************************************************//**
+* \file cy_capsense_selftest.h
+* \version 2.10
+*
+* \brief
+* This file provides the function prototypes of the BIST module.
+*
+********************************************************************************
+* \copyright
+* Copyright 2019-2020, Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_SELFTEST_H)
+#define CY_CAPSENSE_SELFTEST_H
+
+#include "cy_syslib.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* Sense Clock frequency in Hz for sensors capacitance measurement. */
+#define CY_CAPSENSE_BIST_ELTD_CAP_SNSCLK_DEFAULT (375000uL)
+/* The default maximum possible external capacitor charge/discharge time in microseconds */
+#define CY_CAPSENSE_BIST_CAP_SETTLING_TIME_DEFAULT (2u)
+
+/* The all available tests mask for the Cy_CapSense_RunSelfTest() function */
+#define CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK (CY_CAPSENSE_BIST_CRC_WDGT | \
+ CY_CAPSENSE_BIST_SNS_INTEGRITY | \
+ CY_CAPSENSE_BIST_SNS_CAP | \
+ CY_CAPSENSE_BIST_SHIELD_CAP | \
+ CY_CAPSENSE_BIST_EXTERNAL_CAP |\
+ CY_CAPSENSE_BIST_VDDA)
+
+
+/*******************************************************************************
+* 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
+*******************************************************************************/
+
+/******************************************************************************/
+/** \addtogroup group_capsense_high_level *//** \{ */
+/******************************************************************************/
+
+cy_en_capsense_bist_status_t Cy_CapSense_RunSelfTest(
+ uint32_t testEnMask,
+ cy_stc_capsense_context_t * context);
+
+/** \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_low_level *//** \{ */
+/******************************************************************************/
+
+cy_en_capsense_bist_status_t Cy_CapSense_CheckCRCWidget(
+ uint32_t widgetId,
+ cy_stc_capsense_context_t * context);
+cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorRawcount(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ uint16_t rawcountHighLimit,
+ uint16_t rawcountLowLimit,
+ cy_stc_capsense_context_t * context);
+cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorBaseline(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ uint16_t baselineHighLimit,
+ uint16_t baselineLowLimit,
+ cy_stc_capsense_context_t * context);
+cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorPins(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ cy_stc_capsense_context_t * context);
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSensor(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ uint32_t * ptrValue,
+ cy_stc_capsense_context_t * context);
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceShield(
+ uint32_t * ptrValue,
+ cy_stc_capsense_context_t * context);
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceCap(
+ cy_en_capsense_bist_external_cap_id_t integrationCapId,
+ uint32_t * ptrValue,
+ uint32_t maxCapacitance,
+ cy_stc_capsense_context_t * context);
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureVdda(
+ uint32_t * ptrValue,
+ cy_stc_capsense_context_t * context);
+
+/** \} */
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSensorExt(
+ uint32_t widgetId,
+ uint32_t sensorId,
+ cy_stc_capsense_bist_custom_parameters_t * ptrScanConfig,
+ uint32_t * ptrValue,
+ cy_stc_capsense_context_t * context);
+void Cy_CapSense_BistInitialize(
+ cy_stc_capsense_context_t * context);
+void Cy_CapSense_BistDisableMode(
+ cy_stc_capsense_context_t * context);
+void Cy_CapSense_BistDsInitialize(
+ cy_stc_capsense_context_t * context);
+void Cy_CapSense_UpdateCrcWidget(
+ uint32 widgetId,
+ cy_stc_capsense_context_t * context);
+
+
+/** \} \endcond */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* CY_IP_MXCSDV2 */
+
+#endif /* CY_CAPSENSE_SELFTEST_H */
+
+
+/* [] END OF FILE */
diff --git a/cy_capsense_sensing.c b/cy_capsense_sensing.c
index 3488ff6..a88d236 100644
--- a/cy_capsense_sensing.c
+++ b/cy_capsense_sensing.c
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_sensing.c
-* \version 2.0
+* \version 2.10
*
* \brief
* This file contains the source of functions common for different sensing
@@ -8,7 +8,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -27,26 +27,47 @@
#include "cy_capsense_csx.h"
#include "cy_capsense_csd.h"
#include "cy_capsense_lib.h"
+#include "cy_capsense_selftest.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
/*******************************************************************************
* Constants
*******************************************************************************/
-#define CY_CAPSENSE_AUTOTUNE_CALIBRATION_RESOLUTION (12u)
-#define CY_CAPSENSE_AUTOTUNE_CALIBRATION_FREQ_KHZ (1500u)
-#define CY_CAPSENSE_CSD_SNS_FREQ_KHZ_MAX (6000u)
-#define CY_CAPSENSE_CSD_AUTOTUNE_CAL_UNITS (1000u)
-#define CY_CAPSENSE_AUTOTUNE_CP_MAX (69000Lu)
-
-#define CY_CAPSENSE_EXT_CAP_DISCHARGE_TIME (1u)
-
-#define CY_CAPSENSE_VREF_GAIN_MAX (32u)
-#define CY_CAPSENSE_VREF_VDDA_MIN_DIFF (600u)
-#define CY_CAPSENSE_VREF_SRSS_MV (800u)
-#define CY_CAPSENSE_VREF_PASS_MV (1200u)
-
+#define CY_CAPSENSE_AUTOTUNE_CALIBRATION_RESOLUTION (12u)
+#define CY_CAPSENSE_AUTOTUNE_CALIBRATION_FREQ_KHZ (1500u)
+#define CY_CAPSENSE_CSD_SNS_FREQ_KHZ_MAX (6000u)
+#define CY_CAPSENSE_CSD_AUTOTUNE_CAL_UNITS (1000u)
+#define CY_CAPSENSE_AUTOTUNE_CP_MAX (69000Lu)
+
+#define CY_CAPSENSE_EXT_CAP_DISCHARGE_TIME (1u)
+
+#define CY_CAPSENSE_VREF_GAIN_MAX (32u)
+#define CY_CAPSENSE_VREF_VDDA_MIN_DIFF (600u)
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_VREF_SRSS_MV (1200u)
+#else
+ #define CY_CAPSENSE_VREF_SRSS_MV (800u)
+#endif
+#define CY_CAPSENSE_VREF_PASS_MV (1200u)
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_VREF_RANGE_0 (4700u)
+ #define CY_CAPSENSE_VREF_RANGE_1 (3200u)
+ #define CY_CAPSENSE_VREF_RANGE_2 (2600u)
+ #define CY_CAPSENSE_VREF_VALUE_0 (2743u)
+ #define CY_CAPSENSE_VREF_VALUE_1 (2021u)
+ #define CY_CAPSENSE_VREF_VALUE_2 (1477u)
+ #define CY_CAPSENSE_VREF_VALUE_MIN (1200u)
+#else
+ #define CY_CAPSENSE_VREF_RANGE_0 (2750u)
+ #define CY_CAPSENSE_VREF_RANGE_1 (2200u)
+ #define CY_CAPSENSE_VREF_VALUE_0 (2133u)
+ #define CY_CAPSENSE_VREF_VALUE_1 (1600u)
+ #define CY_CAPSENSE_VREF_VALUE_MIN_SRSS (1164u)
+ #define CY_CAPSENSE_VREF_VALUE_MIN_PASS (1200u)
+#endif
const cy_stc_csd_config_t cy_capsense_csdCfg = CY_CAPSENSE_CSD_CONFIG_DEFAULT;
@@ -57,8 +78,8 @@ const cy_stc_csd_config_t cy_capsense_csdCfg = CY_CAPSENSE_CSD_CONFIG_DEFAULT;
****************************************************************************//**
*
* This function returns a status of the CapSense middleware whether a scan is
-* currently in progress or not.
-*
+* currently in progress or not.
+*
* If the middleware is busy, a new scan or setup widgets should not be initiated.
*
* \param context
@@ -85,7 +106,7 @@ uint32_t Cy_CapSense_IsBusy(const cy_stc_capsense_context_t * context)
* by the flags parameter.
*
* \details
-* This is an internal function. Do not call this function directly from
+* This is an internal function. Do not call this function directly from
* the application program.
*
* \param context
@@ -105,7 +126,7 @@ void Cy_CapSense_SetBusyFlags(cy_stc_capsense_context_t * context)
* 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
+* This is an internal function. Do not call this function directly from
* the application program.
*
* \param context
@@ -116,14 +137,14 @@ void Cy_CapSense_ClrBusyFlags(cy_stc_capsense_context_t * context)
{
/* Clear busy flag */
context->ptrCommonContext->status &= (uint32_t)(~((uint32_t)CY_CAPSENSE_BUSY));
-
+
/* Reset scan flags */
context->ptrActiveScanSns->scanScopeAll = CY_CAPSENSE_SCAN_SCOPE_SGL_WD;
context->ptrActiveScanSns->scanScopeSns = CY_CAPSENSE_SCAN_SCOPE_UND;
-
- /* Mark completion of scan cycle */
+
+ /* Mark completion of scan cycle */
context->ptrCommonContext->scanCounter++;
-
+
if(NULL != context->ptrCommonContext->ptrEOSCallback)
{
context->ptrCommonContext->ptrEOSCallback(context->ptrActiveScanSns);
@@ -154,11 +175,11 @@ void Cy_CapSense_ClrBusyFlags(cy_stc_capsense_context_t * context)
* function is called more than once, it does not break the middleware operation,
* but only the last initialized widget is in effect.
*
-* The status of a sensor scan must be checked using the Cy_CapSense_IsBusy()
+* The status of a sensor scan must be checked using the Cy_CapSense_IsBusy()
* function prior to starting a next scan or setting up another widget.
-*
+*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param context
@@ -171,12 +192,12 @@ void Cy_CapSense_ClrBusyFlags(cy_stc_capsense_context_t * context)
* disabled.
* - CY_RET_INVALID_STATE - The previous scanning is not completed and
* the CSD HW block is busy.
-* - CY_RET_UNKNOWN - An unknown sensing method is used by the widget or
+* - CY_RET_UNKNOWN - An unknown sensing method is used by the widget or
* any other spurious error occurred.
*
**********************************************************************************/
cy_status Cy_CapSense_SetupWidget(
- uint32_t widgetId,
+ uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
cy_status widgetStatus;
@@ -206,7 +227,6 @@ cy_status Cy_CapSense_SetupWidget(
break;
default:
- widgetStatus = CY_RET_UNKNOWN;
break;
}
widgetStatus = CY_RET_SUCCESS;
@@ -227,15 +247,15 @@ cy_status Cy_CapSense_SetupWidget(
* Initiates scanning of all the sensors in the widget initialized by
* Cy_CapSense_SetupWidget(), if no scan is in progress.
*
-* Prior to calling this function to scan sensors, the widget required
+* 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) trigged
-* at the end of each scan completion. Hence, status of the current scan
-* should be checked using the Cy_CapSense_IsBusy() and wait until all scans
-* in the current widget are finished prior to starting the next scan or
+* exits the function. The scan for the remaining sensors in the widget is
+* initiated in the interrupt service routine (part of middleware) trigged
+* at the end of each scan completion. Hence, status of the current scan
+* should be checked using the Cy_CapSense_IsBusy() and wait until all scans
+* in the current widget are finished prior to starting the next scan or
* initializing another widget.
*
* \param context
@@ -285,9 +305,9 @@ cy_status Cy_CapSense_Scan(cy_stc_capsense_context_t * context)
****************************************************************************//**
*
* Performs extended initialization for the specified widget and also performs
-* initialization required for a specific sensor in the widget.
-*
-* This function requires using the Cy_CapSense_ScanExt() function to
+* initialization required for a specific sensor in the widget.
+*
+* This function requires using the Cy_CapSense_ScanExt() function to
* initiate a scan.
*
* This function does the same as Cy_CapSense_SetupWidget() and also
@@ -306,12 +326,12 @@ cy_status Cy_CapSense_Scan(cy_stc_capsense_context_t * context)
* use cases (for faster execution time or pipeline scanning, for example).
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param sensorId
-* Specifies the ID number of the sensor within the widget. A macro for the
-* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE__SNS_ID.
*
* \param context
@@ -319,8 +339,8 @@ cy_status Cy_CapSense_Scan(cy_stc_capsense_context_t * context)
*
**********************************************************************************/
cy_status Cy_CapSense_SetupWidgetExt(
- uint32_t widgetId,
- uint32_t sensorId,
+ uint32_t widgetId,
+ uint32_t sensorId,
cy_stc_capsense_context_t * context)
{
cy_status widgetStatus = CY_RET_BAD_PARAM;
@@ -351,7 +371,6 @@ cy_status Cy_CapSense_SetupWidgetExt(
break;
default:
- widgetStatus = CY_RET_UNKNOWN;
break;
}
widgetStatus = CY_RET_SUCCESS;
@@ -375,7 +394,7 @@ cy_status Cy_CapSense_SetupWidgetExt(
* widget.
*
* This function performs single scanning of one sensor in the widget configured
-* by the Cy_CapSense_SetupWidgetExt() function.
+* by the Cy_CapSense_SetupWidgetExt() function.
*
* Calling this function directly from the application program is not
* recommended. This function is used to implement only the user's specific
@@ -414,11 +433,11 @@ cy_status Cy_CapSense_ScanExt(cy_stc_capsense_context_t * context)
switch(context->ptrActiveScanSns->ptrWdConfig->senseMethod)
{
case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E:
- Cy_CapSense_CSDScan_Call(context);
+ Cy_CapSense_CSDScanExt(context);
break;
case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E:
- Cy_CapSense_CSXScan_Call(context);
+ Cy_CapSense_CSXScanExt(context);
break;
default:
@@ -435,19 +454,19 @@ cy_status Cy_CapSense_ScanExt(cy_stc_capsense_context_t * context)
****************************************************************************//**
*
* Initiates scanning of all enabled widgets (and sensors) in the project.
-*
+*
* The tasks of both Cy_CapSense_SetupWidget() and Cy_CapSense_Scan() functions
-* are executed by this function. The status of a sensor scan must be checked
-* using the Cy_CapSense_IsBusy() prior to starting the next scan or setting
+* are executed by this function. The status of a sensor scan must be checked
+* using the Cy_CapSense_IsBusy() prior to starting the next scan or setting
* up another widget.
-*
-* This function initiates a scan only for the first sensor in the first widget
+*
+* This function initiates a scan only for the first sensor in the first widget
* and then exits the function. The scan for the remaining sensors are initiated
-* in the interrupt service routine (part of middleware) trigged at the end
-* of each scan completion. Hence, the status of the current scan should be
-* checked using the Cy_CapSense_IsBusy() and wait until all scans is finished
+* in the interrupt service routine (part of middleware) trigged at the end
+* of each scan completion. Hence, the status of the current scan should be
+* checked using the Cy_CapSense_IsBusy() and wait until all scans is finished
* prior to starting a next scan or initializing another widget.
-*
+*
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
@@ -455,7 +474,7 @@ cy_status Cy_CapSense_ScanExt(cy_stc_capsense_context_t * context)
* Returns the status of the operation:
* - CY_RET_SUCCESS - Scanning is successfully started.
* - CY_RET_BAD_PARAM - All the widgets are disabled.
-* - CY_RET_INVALID_STATE - The previous scanning is not completed and the
+* - CY_RET_INVALID_STATE - The previous scanning is not completed and the
* CSD HW block is busy.
* - CY_RET_UNKNOWN - There are unknown errors.
*
@@ -474,7 +493,7 @@ cy_status Cy_CapSense_ScanAllWidgets(cy_stc_capsense_context_t * context)
else
{
/*
- * Set up first widget. If widget returned error,
+ * Set up first widget. If widget returned error,
* set up next, continue same until widget does not return error.
*/
for (wdgtIndex = 0u; wdgtIndex < context->ptrCommonConfig->numWd; wdgtIndex++)
@@ -483,7 +502,7 @@ cy_status Cy_CapSense_ScanAllWidgets(cy_stc_capsense_context_t * context)
if (CY_RET_SUCCESS == scanStatus)
{
ptrActive->scanScopeAll = CY_CAPSENSE_SCAN_SCOPE_ALL_WD;
-
+
/* Initiate scan and quit loop */
scanStatus = Cy_CapSense_Scan(context);
@@ -500,7 +519,7 @@ cy_status Cy_CapSense_ScanAllWidgets(cy_stc_capsense_context_t * context)
* Function Name: Cy_CapSense_InternalPreCalculation
****************************************************************************//**
*
-* Calculate different internal parameters, register values in advance to
+* Calculate different internal parameters, register values in advance to
* speed up execution time.
*
* \param context
@@ -517,7 +536,7 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
cy_status initStatus = CY_RET_SUCCESS;
uint32_t wdgtIndex;
uint32_t temp;
-
+
if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdEn)
{
if ((context->ptrCommonConfig->portCmodPadNum == context->ptrCommonConfig->portCmodNum) &&
@@ -575,7 +594,11 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
initStatus = CY_RET_BAD_PARAM;
}
}
-
+ else
+ {
+ context->ptrInternalContext->csdCshConnection = 0u;
+ }
+
/* Switch CSD Comparator Selection */
switch (context->ptrInternalContext->csdCmodConnection)
{
@@ -589,6 +612,7 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
context->ptrInternalContext->csdRegSwCmpPSel = CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPT_STATIC_CLOSE;
break;
}
+ context->ptrInternalContext->csdRegSwCmpNSel = CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE;
/* Defines the drive mode of pins depending on the Inactive sensor connection setting */
switch (context->ptrCommonConfig->csdInactiveSnsConnection)
@@ -598,23 +622,26 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
context->ptrInternalContext->csdInactiveSnsHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
break;
case CY_CAPSENSE_SNS_CONNECTION_SHIELD:
- context->ptrInternalContext->csdInactiveSnsDm = CY_GPIO_DM_STRONG_IN_OFF;
+ context->ptrInternalContext->csdInactiveSnsDm = CY_CAPSENSE_CSD_SCAN_PIN_DM;
context->ptrInternalContext->csdInactiveSnsHsiom = CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD;
break;
case CY_CAPSENSE_SNS_CONNECTION_GROUND:
default:
- context->ptrInternalContext->csdInactiveSnsDm = CY_GPIO_DM_STRONG;
+ context->ptrInternalContext->csdInactiveSnsDm = CY_GPIO_DM_STRONG_IN_OFF;
context->ptrInternalContext->csdInactiveSnsHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
break;
}
-
+
/* Prepares CONFIG register value */
context->ptrInternalContext->csdRegConfig = 0u;
/* Iref Source */
- if (CY_CAPSENSE_IREF_PASS == context->ptrCommonConfig->ssIrefSource)
- {
- context->ptrInternalContext->csdRegConfig |= CSD_CONFIG_IREF_SEL_Msk;
- }
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ if (CY_CAPSENSE_IREF_PASS == context->ptrCommonConfig->ssIrefSource)
+ {
+ context->ptrInternalContext->csdRegConfig |= CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK;
+ }
+ #endif
+
/* Filter Delay */
temp = context->ptrCommonConfig->periClkHz / context->ptrCommonContext->modCsdClk;
if (temp > CY_CAPSENSE_MOD_CSD_CLK_24000000_HZ)
@@ -635,46 +662,100 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
context->ptrInternalContext->csdRegConfig |= CSD_CONFIG_SENSE_EN_Msk;
/* Power On */
context->ptrInternalContext->csdRegConfig |= CSD_CONFIG_ENABLE_Msk;
-
- /* High Speed comparator positive input selection */
+
+ context->ptrInternalContext->csdRegSwHsPSelCmodInit = 0u;
+ context->ptrInternalContext->csdRegSwHsPSelCtankInit = 0u;
context->ptrInternalContext->csdRegSwHsPSelScan = 0u;
- context->ptrInternalContext->csdRegSwHsPSelInit = 0u;
- /* Switch Comparator Selection */
+
switch (context->ptrInternalContext->csdCmodConnection)
{
case (uint8_t)CY_CAPSENSE_CMODPAD_E:
- context->ptrInternalContext->csdRegSwHsPSelInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
+ context->ptrInternalContext->csdRegSwHsPSelCmodInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
break;
case (uint8_t)CY_CAPSENSE_CSHIELDPAD_E:
- context->ptrInternalContext->csdRegSwHsPSelInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
+ context->ptrInternalContext->csdRegSwHsPSelCmodInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
break;
default:
- context->ptrInternalContext->csdRegSwHsPSelInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
+ context->ptrInternalContext->csdRegSwHsPSelCmodInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
break;
}
- if (0u != context->ptrCommonConfig->csdShieldEn)
+
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn)
{
- context->ptrInternalContext->csdRegSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMB_STATIC_CLOSE;
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn)
+ {
+ switch (context->ptrInternalContext->csdCshConnection)
+ {
+ case (uint8_t)CY_CAPSENSE_CMODPAD_E:
+ context->ptrInternalContext->csdRegSwHsPSelCtankInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
+ context->ptrInternalContext->csdRegSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE;
+ break;
+ case (uint8_t)CY_CAPSENSE_CSHIELDPAD_E:
+ context->ptrInternalContext->csdRegSwHsPSelCtankInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
+ context->ptrInternalContext->csdRegSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE;
+ break;
+ default:
+ context->ptrInternalContext->csdRegSwHsPSelCtankInit = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
+ context->ptrInternalContext->csdRegSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE;
+ break;
+
+ }
+ }
+ else
+ {
+ context->ptrInternalContext->csdRegSwHsPSelScan = CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMB_STATIC_CLOSE;
+ }
}
-
+
/* BYP switch selection */
context->ptrInternalContext->csdRegSwBypSel = CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK;
if (0u != context->ptrCommonConfig->csdShieldEn)
{
context->ptrInternalContext->csdRegSwBypSel = CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK | CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYB_MSK;
}
-
+
/* Switch resistance selection */
+ context->ptrInternalContext->csdRegSwResInit = ((uint32_t)context->ptrCommonConfig->csdInitSwRes << CSD_SW_RES_RES_HCAV_Pos) |
+ ((uint32_t)context->ptrCommonConfig->csdInitSwRes << CSD_SW_RES_RES_HCBV_Pos);
context->ptrInternalContext->csdRegSwResScan = ((uint32_t)context->ptrCommonConfig->csdShieldSwRes << CSD_SW_RES_RES_HCBV_Pos) |
- ((uint32_t)context->ptrCommonConfig->csdShieldSwRes << CSD_SW_RES_RES_HCBG_Pos);
- /* Switch resistance selection */
- context->ptrInternalContext->csdRegSwResInit = ((uint32_t)context->ptrCommonConfig->csdInitSwRes << CSD_SW_RES_RES_HCAV_Pos);
-
+ ((uint32_t)context->ptrCommonConfig->csdShieldSwRes << CSD_SW_RES_RES_HCBG_Pos);
+
+ /* Switch DSI selection */
+ context->ptrInternalContext->csdRegSwDsiSel = CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL;
+
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ switch (context->ptrInternalContext->csdCmodConnection)
+ {
+ case (uint8_t)CY_CAPSENSE_CMODPAD_E:
+ context->ptrInternalContext->csdRegSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CMOD_MSK;
+ break;
+ case (uint8_t)CY_CAPSENSE_CTANKPAD_E:
+ context->ptrInternalContext->csdRegSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CSH_TANK_MSK;
+ break;
+ default:
+ break;
+ }
+ if ((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn) &&
+ (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn))
+ {
+ switch (context->ptrInternalContext->csdCshConnection)
+ {
+ case (uint8_t)CY_CAPSENSE_CMODPAD_E:
+ context->ptrInternalContext->csdRegSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CMOD_MSK;
+ break;
+ case (uint8_t)CY_CAPSENSE_CTANKPAD_E:
+ context->ptrInternalContext->csdRegSwDsiSel |= CY_CAPSENSE_CSD_SW_DSI_SEL_CSH_TANK_MSK;
+ break;
+ default:
+ break;
+ }
+ }
+ #endif
+
if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn)
{
- if (CY_CAPSENSE_2000_MV > context->ptrCommonConfig->vdda)
+ if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
{
-
context->ptrInternalContext->csdRegAmuxbufInit = CY_CAPSENSE_CSD_AMBUF_PWR_MODE_NORM;
}
else
@@ -691,16 +772,15 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
context->ptrInternalContext->csdRegSwAmuxbufSel = 0u;
if (0u != context->ptrCommonConfig->csdShieldEn)
{
- if (((CY_CAPSENSE_2000_MV > context->ptrCommonConfig->vdda) &&
+ if (((CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda) &&
(CY_CAPSENSE_IDAC_SINKING == context->ptrCommonConfig->csdChargeTransfer)) ||
- ((CY_CAPSENSE_2000_MV <= context->ptrCommonConfig->vdda) &&
+ ((CY_CAPSENSE_LOW_VOLTAGE_LIMIT <= context->ptrCommonConfig->vdda) &&
(CY_CAPSENSE_IDAC_SOURCING == context->ptrCommonConfig->csdChargeTransfer)))
{
context->ptrInternalContext->csdRegSwAmuxbufSel = CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_IRH_STATIC_CLOSE | CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_ICB_PHI2;
}
}
- /* Switch Shield selection */
- context->ptrInternalContext->csdRegSwShieldSelInit = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_HSCMP;
+
context->ptrInternalContext->csdRegSwShieldSelScan = 0u;
if (0u != context->ptrCommonConfig->csdShieldEn)
{
@@ -712,7 +792,7 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
}
else
{
- context->ptrInternalContext->csdRegSwShieldSelScan = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_HSCMP;
+ context->ptrInternalContext->csdRegSwShieldSelScan = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI1_HSCMP;
}
}
else
@@ -730,20 +810,18 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
}
}
- /* High-Speed Comparator config */
+ /* High-Speed Comparator initialization */
context->ptrInternalContext->csdRegHscmpInit = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
-
+ context->ptrInternalContext->csdRegHscmpScan = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
if (CY_CAPSENSE_IDAC_SINKING == context->ptrCommonConfig->csdChargeTransfer)
{
- context->ptrInternalContext->csdRegHscmpScan = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK |
- CY_CAPSENSE_CSD_HSCMP_HSCMP_INVERT_MSK;
+ context->ptrInternalContext->csdRegHscmpScan = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK | CY_CAPSENSE_CSD_HSCMP_HSCMP_INVERT_MSK;
}
- else
+ if (0u == context->ptrCommonConfig->csdShieldEn)
{
- context->ptrInternalContext->csdRegHscmpScan = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
+ context->ptrInternalContext->csdRegHscmpScan = 0u;
}
-
/* IDACs Config */
context->ptrInternalContext->csdIdacAConfig = context->ptrCommonConfig->idacGainTable[0u].gainReg;
context->ptrInternalContext->csdIdacBConfig = context->ptrCommonConfig->idacGainTable[0u].gainReg;
@@ -766,7 +844,7 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
context->ptrInternalContext->csdIdacAConfig |= (CY_CAPSENSE_CSD_IDACA_LEG1_MODE_CSD << CY_CAPSENSE_CSD_IDACA_LEG1_MODE_POS);
context->ptrInternalContext->csdIdacAConfig |= (CY_CAPSENSE_CSD_IDACA_LEG2_MODE_CSD << CY_CAPSENSE_CSD_IDACA_LEG2_MODE_POS);
context->ptrInternalContext->csdIdacAConfig |= (CY_CAPSENSE_CSD_IDACA_LEG1_EN_MSK);
-
+
context->ptrInternalContext->csdIdacBConfig |= (CY_CAPSENSE_CSD_IDACB_LEG1_MODE_CSD_STATIC << CY_CAPSENSE_CSD_IDACB_LEG1_MODE_POS);
context->ptrInternalContext->csdIdacBConfig |= (CY_CAPSENSE_CSD_IDACB_LEG2_MODE_CSD_STATIC << CY_CAPSENSE_CSD_IDACB_LEG2_MODE_POS);
if (0u != context->ptrCommonConfig->csdIdacCompEn)
@@ -774,40 +852,21 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
context->ptrInternalContext->csdIdacBConfig |= (CY_CAPSENSE_CSD_IDACB_LEG1_EN_MSK);
}
- /* Switch Csh tank selection */
- context->ptrInternalContext->csdRegSwFwTankSelScan = 0u;
- context->ptrInternalContext->csdRegSwFwTankSelInit = 0u;
- if ((0u != context->ptrCommonConfig->csdShieldEn) &&
- (0u != context->ptrCommonConfig->csdCTankShieldEn) &&
- ((uint8_t)CY_CAPSENSE_CTANKPAD_E == context->ptrInternalContext->csdCshConnection))
- {
- context->ptrInternalContext->csdRegSwFwTankSelScan = (CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2PT_STATIC_CLOSE |
- CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CB_STATIC_CLOSE);
- }
-
- if (((uint8_t)CY_CAPSENSE_CTANKPAD_E == context->ptrInternalContext->csdCmodConnection) ||
- ((uint8_t)CY_CAPSENSE_CTANKPAD_E == context->ptrInternalContext->csdCshConnection))
- {
- context->ptrInternalContext->csdRegSwFwTankSelInit = (CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2PT_STATIC_CLOSE |
- CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2MA_STATIC_CLOSE |
- CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CA_STATIC_CLOSE);
- }
-
/* IO Control Selection */
if (CY_CAPSENSE_IDAC_SINKING == context->ptrCommonConfig->csdChargeTransfer)
{
if (0u != context->ptrCommonConfig->csdShieldEn)
{
- context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
+ context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 |
- CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY |
+ CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY |
CY_CAPSENSE_CSD_TX_AMUXB_EN_PHI2_DELAY |
- CY_CAPSENSE_CSD_TX_OUT_MSK |
+ CY_CAPSENSE_CSD_TX_OUT_MSK |
CY_CAPSENSE_CSD_TX_N_OUT_STATIC_CLOSE);
}
else
{
- context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
+ context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 |
CY_CAPSENSE_CSD_TX_N_OUT_STATIC_CLOSE);
}
@@ -816,84 +875,63 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
{
if (0u != context->ptrCommonConfig->csdShieldEn)
{
- context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
+ context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 |
- CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY |
+ CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY |
CY_CAPSENSE_CSD_TX_AMUXB_EN_PHI2_DELAY);
}
else
{
- context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
+ context->ptrInternalContext->csdRegIoSel = (CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 |
CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2);
}
}
if(context->ptrCommonConfig->csdVref == 0u)
{
- /*
- * Get the recommended Vref voltage value if the Custom Vref option is not used.
- */
- temp = Cy_CapSense_GetVrefAutoMv((uint32_t)context->ptrCommonConfig->vdda);
- }
- else
- {
- /*
- * Initialize the Temp variable with the user defined Vref voltage if the
- * Custom Vref option is used.
- */
- temp = context->ptrCommonConfig->csdVref;
- }
-
- if(CY_CAPSENSE_VREF_SRSS == context->ptrCommonConfig->ssVrefSource)
- {
- /*
- * Calculate the VrefHigh Gain for the desired Vref voltage when SRSS is used as the Vref source.
- */
- temp = (uint8_t)Cy_CapSense_GetVrefHighGain((uint32_t)context->ptrCommonConfig->vdda,
- CY_CAPSENSE_VREF_SRSS_MV, temp);
- /*
- * Calculates the VrefHigh voltage, when SRSS is used as the Vref source.
- */
- context->ptrInternalContext->csdVrefVoltageMv = (uint16_t)Cy_CapSense_GetVrefHighMv(CY_CAPSENSE_VREF_SRSS_MV, temp);
- }
- else if(CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
- {
- /*
- * Calculate the VrefHigh Gain for the desired Vref voltage when PASS is used as the Vref source.
- */
- temp = (uint8_t)Cy_CapSense_GetVrefHighGain((uint32_t)context->ptrCommonConfig->vdda,
- CY_CAPSENSE_VREF_PASS_MV, temp);
- /*
- * Calculates the VrefHigh voltage, when SRSS is used as the Vref source.
- */
- context->ptrInternalContext->csdVrefVoltageMv = (uint16_t)Cy_CapSense_GetVrefHighMv(CY_CAPSENSE_VREF_PASS_MV, temp);
+ /* Get the recommended Vref voltage value if the Custom Vref option is not used */
+ temp = Cy_CapSense_GetVrefAutoMv(context);
}
else
{
- /*
- * Pass the Vref source voltage to the VrefHigh output in case if the Vref source in unknown.
- */
- temp = (uint8_t)(CY_CAPSENSE_VREF_GAIN_MAX - 1u);
+ /* Initialize the Temp variable with the user defined Vref voltage */
+ temp = (uint32_t)context->ptrCommonConfig->csdVref;
+ if(temp > (uint32_t)((uint32_t)context->ptrCommonConfig->vdda - CY_CAPSENSE_VREF_VDDA_MIN_DIFF))
+ {
+ temp = (uint32_t)context->ptrCommonConfig->vdda - CY_CAPSENSE_VREF_VDDA_MIN_DIFF;
+ }
}
+ /* Calculate the VrefHigh Gain for the desired Vref voltage when PASS is used as the Vref source. */
+ temp = Cy_CapSense_GetVrefHighGain(temp, context);
+ /* Calculates the VrefHigh voltage, when SRSS is used as the Vref source. */
+ context->ptrInternalContext->csdVrefVoltageMv = (uint16_t)Cy_CapSense_GetVrefHighMv(temp, context);
context->ptrInternalContext->csdVrefGain = (uint8_t)temp;
+
+ /* RefGen initialization */
context->ptrInternalContext->csdRegRefgen = (CSD_REFGEN_REFGEN_EN_Msk |
CSD_REFGEN_RES_EN_Msk |
- (temp << CSD_REFGEN_GAIN_Pos));
- }
+ (uint32_t)(temp << CSD_REFGEN_GAIN_Pos));
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+ {
+ context->ptrInternalContext->csdRegRefgen = (CSD_REFGEN_REFGEN_EN_Msk |
+ CSD_REFGEN_BYPASS_Msk);
+ }
+ #endif
- /* Common initialization */
-
- /* Initialize RefGen Gain and Vref switches for sensing operation */
- if(CY_CAPSENSE_VREF_SRSS != context->ptrCommonConfig->ssVrefSource)
- {
- context->ptrInternalContext->csxRegRefgen = CY_CAPSENSE_DEFAULT_CSD_REFGEN_CFG | 0x00001F00uL;
- context->ptrInternalContext->regSwRefGenSel = 0x00100000uL;
- }
- else
- {
- context->ptrInternalContext->csxRegRefgen = CY_CAPSENSE_DEFAULT_CSD_REFGEN_CFG | 0x00001500uL;
- context->ptrInternalContext->regSwRefGenSel = 0x10000000uL;
+ /* SW_RefGen_SEL initialization */
+ context->ptrInternalContext->csdRegSwRefGenSel = CSD_SW_REFGEN_SEL_SW_SGR_Msk;
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ if(CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+ {
+ context->ptrInternalContext->csdRegSwRefGenSel = CSD_SW_REFGEN_SEL_SW_SGRP_Msk;
+ }
+ #endif
+ if (0u != context->ptrCommonConfig->csdIdacCompEn)
+ {
+ context->ptrInternalContext->csdRegSwRefGenSel |= CSD_SW_REFGEN_SEL_SW_IAIB_Msk;
+ }
}
/* Initialize maxRawCount for all CSX widgets */
@@ -901,33 +939,39 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
{
if ((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E == context->ptrWdConfig[wdgtIndex].senseMethod)
{
- context->ptrWdContext[wdgtIndex].maxRawCount =
+ context->ptrWdContext[wdgtIndex].maxRawCount =
(uint16_t)(((uint32_t)0x01u << context->ptrWdContext[wdgtIndex].resolution) - 1u);
}
if ((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E == context->ptrWdConfig[wdgtIndex].senseMethod)
{
- context->ptrWdContext[wdgtIndex].maxRawCount = (uint16_t)(context->ptrWdContext[wdgtIndex].resolution *
+ context->ptrWdContext[wdgtIndex].maxRawCount = (uint16_t)(context->ptrWdContext[wdgtIndex].resolution *
(context->ptrWdContext[wdgtIndex].snsClk - CY_CAPSENSE_CSX_DEADBAND_CYCLES_NUMBER));
}
}
+ /* CSX Initialization */
if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csxEn)
{
-
- /*
- * CSX Initialization
- */
+ context->ptrInternalContext->csxRegSwRefGenSel = CSD_SW_REFGEN_SEL_SW_SGR_Msk;
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ if(CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+ {
+ context->ptrInternalContext->csxRegSwRefGenSel = CSD_SW_REFGEN_SEL_SW_SGRP_Msk;
+ }
+ #endif
+
/* Initialize CONFIG register values */
context->ptrInternalContext->csxRegConfigInit = CY_CAPSENSE_DEFAULT_CSD_CONFIG_CFG;
context->ptrInternalContext->csxRegConfigScan = CY_CAPSENSE_PRESCAN_CSD_CONFIG_CFG;
-
- if(CY_CAPSENSE_IREF_SRSS != context->ptrCommonConfig->ssIrefSource)
- {
- context->ptrInternalContext->csxRegConfigInit |= 0x00000001uL;
- context->ptrInternalContext->csxRegConfigScan |= 0x00000001uL;
- }
+ #if (CY_CAPSENSE_PSOC6_CSDV2)
+ if(CY_CAPSENSE_IREF_PASS == context->ptrCommonConfig->ssIrefSource)
+ {
+ context->ptrInternalContext->csxRegConfigInit |= CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK;
+ context->ptrInternalContext->csxRegConfigScan |= CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK;
+ }
+ #endif
- /* Initialize FilterDelay for CSX sensing */
+ /* Initialize FilterDelay for CSX sensing */
if (CY_CAPSENSE_MOD_CSD_CLK_12000000_HZ < context->ptrCommonConfig->periClkHz)
{
/* Calculate CSX modClk in Hz */
@@ -951,7 +995,7 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
}
/* Default switch resistance selection */
- context->ptrInternalContext->csxRegSwResInit =
+ context->ptrInternalContext->csxRegSwResInit =
(((uint32_t)context->ptrCommonConfig->csxInitShieldSwRes << CSD_SW_RES_RES_HCAV_Pos) |
((uint32_t)context->ptrCommonConfig->csxInitShieldSwRes << CSD_SW_RES_RES_HCAG_Pos) |
((uint32_t)context->ptrCommonConfig->csxInitShieldSwRes << CSD_SW_RES_RES_HCBV_Pos) |
@@ -959,17 +1003,53 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
((uint32_t)context->ptrCommonConfig->csxInitSwRes << CSD_SW_RES_RES_F1PM_Pos) |
((uint32_t)context->ptrCommonConfig->csxInitSwRes << CSD_SW_RES_RES_F2PT_Pos));
/* Switch resistance selection for scan */
- context->ptrInternalContext->csxRegSwResScan =
+ context->ptrInternalContext->csxRegSwResScan =
(((uint32_t)context->ptrCommonConfig->csxScanShieldSwRes << CSD_SW_RES_RES_HCAV_Pos) |
((uint32_t)context->ptrCommonConfig->csxScanShieldSwRes << CSD_SW_RES_RES_HCAG_Pos) |
((uint32_t)context->ptrCommonConfig->csxScanShieldSwRes << CSD_SW_RES_RES_HCBV_Pos) |
((uint32_t)context->ptrCommonConfig->csxScanShieldSwRes << CSD_SW_RES_RES_HCBG_Pos) |
((uint32_t)context->ptrCommonConfig->csxScanSwRes << CSD_SW_RES_RES_F1PM_Pos) |
((uint32_t)context->ptrCommonConfig->csxScanSwRes << CSD_SW_RES_RES_F2PT_Pos));
+
/* Switch resistance selection for precharge */
context->ptrInternalContext->csxRegSwResPrech = context->ptrInternalContext->csxRegSwResInit;
+
+ /* AMUXBUF_CFG / AMUXBUF_SEL_CFG / SW_CMP_N_SEL initialization */
+ context->ptrInternalContext->csxRegAMuxBuf = CY_CAPSENSE_DEFAULT_CSD_AMBUF_CFG;
+ context->ptrInternalContext->csxRegRefgenSel = CY_CAPSENSE_DEFAULT_CSD_SW_AMUXBUF_SEL_CFG;
+ context->ptrInternalContext->csxRegSwCmpNSel = CY_CAPSENSE_DEFAULT_CSD_SW_CMP_N_SEL_CFG;
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if (context->ptrCommonConfig->vdda < CY_CAPSENSE_LOW_VOLTAGE_LIMIT)
+ {
+ context->ptrInternalContext->csxRegAMuxBuf = CY_CAPSENSE_LOW_VOLTAGE_CSD_AMBUF_CFG;
+ context->ptrInternalContext->csxRegRefgenSel = CY_CAPSENSE_LOW_VOLTAGE_CSD_SW_AMUXBUF_SEL_CFG;
+ context->ptrInternalContext->csxRegSwCmpNSel = CY_CAPSENSE_LOW_VOLTAGE_CSD_SW_CMP_N_SEL_CFG;
+ }
+ #endif
+
+ /* REFGEN_CFG initialization */
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if (context->ptrCommonConfig->vdda < CY_CAPSENSE_LOW_VOLTAGE_LIMIT)
+ {
+ context->ptrInternalContext->csxRegRefgen = CY_CAPSENSE_LOW_VOLTAGE_CSD_REFGEN_CFG;
+ }
+ else
+ {
+ context->ptrInternalContext->csxRegRefgen = CY_CAPSENSE_DEFAULT_CSD_REFGEN_CFG;
+ }
+ #else
+ /* Initialize RefGen Gain and Vref switches for sensing operation */
+ if(CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+ {
+ context->ptrInternalContext->csxRegRefgen = CY_CAPSENSE_PASS_CSD_REFGEN_CFG;
+ }
+ else
+ {
+ context->ptrInternalContext->csxRegRefgen = CY_CAPSENSE_SRSS_CSD_REFGEN_CFG;
+ }
+ #endif
}
-
+
return (initStatus);
}
@@ -982,7 +1062,7 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
* of the CapSense middleware. This function is called from
* the Cy_CapSense_Init() prior to calling any other function of the middleware.
*
-* This function
+* This function
* 1. Depending on the configuration, the function initializes the CSD HW block
* for the corresponding sensing mode.
* 2. Sets all IOs into the default state.
@@ -1004,20 +1084,17 @@ cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context
cy_status Cy_CapSense_SsInitialize(cy_stc_capsense_context_t * context)
{
cy_status initStatus;
-
+
initStatus = Cy_CapSense_InternalPreCalculation(context);
-
+
Cy_CapSense_InitializeSourceSenseClk(context);
- /* Set all IO states to default state */
- Cy_CapSense_SetIOsInDefaultState(context);
+ /* Set all IO states to the default state */
+ Cy_CapSense_SetIOsInDesiredState(CY_GPIO_DM_STRONG_IN_OFF, 0u, CY_CAPSENSE_HSIOM_SEL_GPIO, context);
Cy_CapSense_SetSpecificIOsInDefaultState(context);
- /*
- * The CSD HW block is initialized in the Setup Widget functions based
- * on widget sensing method.
- */
- Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_UNDEFINED_E, context);
+ /* The CSD HW block is initialized in the Setup Widget functions based on widget sensing method */
+ (void)Cy_CapSense_SwitchSensingMode((uint8_t)CY_CAPSENSE_UNDEFINED_E, context);
return (initStatus);
}
@@ -1028,49 +1105,49 @@ cy_status Cy_CapSense_SsInitialize(cy_stc_capsense_context_t * context)
****************************************************************************//**
*
* Sets the state (drive mode and HSIOM state) of the GPIO used by a sensor.
-*
-* The possible states are GND, Shield, High-Z, Tx, Rx, and Sensor.
-* If the sensor specified in the input parameter is a ganged sensor, then
+*
+* The possible states are GND, Shield, High-Z, Tx, Rx, and Sensor.
+* If the sensor specified in the input parameter is a ganged sensor, then
* the state of all GPIOs associated with the ganged sensor is updated.
-*
-* To access a sensor of CSD of button or slider widgets, use the sensor ID.
-* To access a sensor of CSD matrix button or touchpad widgets,
-* use either row ID or column ID as appropriate.
+*
+* To access a sensor of CSD of button or slider widgets, use the sensor ID.
+* To access a sensor of CSD matrix button or touchpad widgets,
+* use either row ID or column ID as appropriate.
* To access sensor CSX widgets, use either Rx ID or Tx ID as appropriate.
-*
-* This function accepts the CY_CAPSENSE_SHIELD and CY_CAPSENSE_SENSOR states
-* as an input only if there is at least one CSD widget in the project.
-* Similarly, this function accepts the CY_CAPSENSE_TX_PIN and
-* CY_CAPSENSE_RX_PIN states as an input only if there is at least one
+*
+* This function accepts the CY_CAPSENSE_SHIELD and CY_CAPSENSE_SENSOR states
+* as an input only if there is at least one CSD widget in the project.
+* Similarly, this function accepts the CY_CAPSENSE_TX_PIN and
+* CY_CAPSENSE_RX_PIN states as an input only if there is at least one
* CSX widget in the project.
-*
+*
* This function must not be called while the middleware is in the busy state.
-* Calling this function directly from the application program is not
-* recommended. This function is used to implement only the custom-specific
-* use cases.
-*
-* Functions that perform a setup and scan of a sensor/widget automatically
-* set the required pin states for a sensor as required and overwrite changes
-* made by this function to a sensor that are going to be scanned. Therefore
-* the Cy_CapSense_SetPinState() function could be called in StartSample
-* callback (see the \ref group_capsense_callbacks section for details)
+* Calling this function directly from the application program is not
+* recommended. This function is used to implement only the custom-specific
+* use cases.
+*
+* Functions that perform a setup and scan of a sensor/widget automatically
+* set the required pin states for a sensor as required and overwrite changes
+* made by this function to a sensor that are going to be scanned. Therefore
+* the Cy_CapSense_SetPinState() function could be called in StartSample
+* callback (see the \ref group_capsense_callbacks section for details)
* or with low-level functions that perform a single-sensor scanning.
-*
+*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param sensorElement
* Specifies the ID of the sensor element within the widget to change
* its pin state.
-* * For the CSD widgets use the sensor ID. A macro for the
-* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* * For the CSD widgets use the sensor ID. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE__SNS_ID.
* * For the CSX widgets use either Rx ID or Tx ID.
* The first Rx in a widget corresponds to sensorElement = 0; the second
* Rx in a widget corresponds to sensorElement = 1, and so on.
* The last Tx in a widget corresponds to sensorElement = (RxNum + TxNum - 1).
-* A macro for the Rx ID or Tx ID can be found in the cycfg_capsense.h
+* A macro for the Rx ID or Tx ID can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE___ID.
*
* \param state
@@ -1079,7 +1156,7 @@ cy_status Cy_CapSense_SsInitialize(cy_stc_capsense_context_t * context)
* 2. CY_CAPSENSE_HIGHZ - The drive mode of the pin is set to High-Z
* Analog.
* 3. CY_CAPSENSE_SHIELD - The shield signal is routed to the pin
-* (available only if CSD sensing method with
+* (available only if CSD sensing method with
* shield electrode is enabled).
* 4. CY_CAPSENSE_SENSOR - The pin is connected to the scanning bus
* (available only if CSD sensing method is enabled).
@@ -1095,23 +1172,23 @@ cy_status Cy_CapSense_SsInitialize(cy_stc_capsense_context_t * context)
* Returns the operation status:
* - CY_RET_SUCCESS - Indicates the successful electrode setting.
* - CY_RET_BAD_PARAM - 1) widgetID or sensorElement are not valid;
-* 2) the CSD sensing method is disabled for desired
+* 2) the CSD sensing method is disabled for desired
* CY_CAPSENSE_SHIELD or CY_CAPSENSE_SENSOR states;
-* 3) the CSX sensing method is disabled for desired
+* 3) the CSX sensing method is disabled for desired
* CY_CAPSENSE_TX_PIN or CY_CAPSENSE_RX_PIN states.
*
* \funcusage
-*
-* An example of using the Cy_CapSense_SetPinState() function to perform
+*
+* An example of using the Cy_CapSense_SetPinState() function to perform
* sensor state re-configuration:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_SetPinState
-*
+*
*******************************************************************************/
cy_status Cy_CapSense_SetPinState(
- uint32_t widgetId,
- uint32_t sensorElement,
- uint32_t state,
- cy_stc_capsense_context_t * context)
+ uint32_t widgetId,
+ uint32_t sensorElement,
+ uint32_t state,
+ const cy_stc_capsense_context_t * context)
{
cy_status connState = CY_RET_BAD_PARAM;
uint32_t eltdNum;
@@ -1119,24 +1196,27 @@ cy_status Cy_CapSense_SetPinState(
uint32_t interruptState;
cy_stc_capsense_pin_config_t const * ioPtr;
cy_stc_capsense_widget_config_t const * ptrWdCfg = &context->ptrWdConfig[widgetId];
-
+ cy_stc_capsense_electrode_config_t const * ptrSnsEltdConfig;
+
if (context->ptrCommonConfig->numWd > widgetId)
{
/* Get number of electrodes within the widget */
eltdNum = (uint32_t)ptrWdCfg->numCols + ptrWdCfg->numRows;
if (((uint8_t)CY_CAPSENSE_CSD_SENSING_METHOD == (uint32_t)ptrWdCfg->senseMethod) &&
- (((uint8_t)CY_CAPSENSE_WD_BUTTON_E == ptrWdCfg->wdType) ||
+ (((uint8_t)CY_CAPSENSE_WD_BUTTON_E == ptrWdCfg->wdType) ||
((uint8_t)CY_CAPSENSE_WD_LINEAR_SLIDER_E == ptrWdCfg->wdType) ||
((uint8_t)CY_CAPSENSE_WD_RADIAL_SLIDER_E == ptrWdCfg->wdType)))
{
eltdNum = context->ptrWdConfig->numSns;
}
-
+
if (eltdNum > sensorElement)
{
+ /* Set the pointer to the specified sensor element configuration structure */
+ ptrSnsEltdConfig = &ptrWdCfg->ptrEltdConfig[sensorElement];
/* Get number of electrode's pins and a pointer to the electrode's pin structure */
- eltdNum = ptrWdCfg->ptrEltdConfig->numPins;
- ioPtr = ptrWdCfg->ptrEltdConfig->ptrPin;
+ eltdNum = ptrSnsEltdConfig->numPins;
+ ioPtr = ptrSnsEltdConfig->ptrPin;
/* Loop through all pins of the specified sensor electrode */
for (eltdIndex = 0u; eltdIndex < eltdNum; eltdIndex++)
{
@@ -1152,7 +1232,7 @@ cy_status Cy_CapSense_SetPinState(
Cy_GPIO_SetDrivemode(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber, CY_GPIO_DM_STRONG_IN_OFF);
Cy_GPIO_Clr(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber);
Cy_SysLib_ExitCriticalSection(interruptState);
-
+
connState = CY_RET_SUCCESS;
break;
@@ -1161,7 +1241,7 @@ cy_status Cy_CapSense_SetPinState(
Cy_GPIO_SetDrivemode(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber, CY_GPIO_DM_ANALOG);
Cy_GPIO_Clr(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber);
Cy_SysLib_ExitCriticalSection(interruptState);
-
+
connState = CY_RET_SUCCESS;
break;
@@ -1170,7 +1250,7 @@ cy_status Cy_CapSense_SetPinState(
{
/* Enable sensor */
Cy_CapSense_CSDConnectSns(ioPtr, context);
-
+
connState = CY_RET_SUCCESS;
}
break;
@@ -1178,17 +1258,17 @@ cy_status Cy_CapSense_SetPinState(
case CY_CAPSENSE_SHIELD:
if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn)
{
- Cy_CapSense_SsConfigPinRegisters(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber,
+ Cy_CapSense_SsConfigPinRegisters(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber,
CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD);
connState = CY_RET_SUCCESS;
}
break;
case CY_CAPSENSE_TX_PIN:
-
+
if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csxEn)
{
- Cy_CapSense_SsConfigPinRegisters(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber,
+ Cy_CapSense_SsConfigPinRegisters(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber,
CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD);
connState = CY_RET_SUCCESS;
}
@@ -1197,7 +1277,7 @@ cy_status Cy_CapSense_SetPinState(
case CY_CAPSENSE_RX_PIN:
if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csxEn)
{
- Cy_CapSense_SsConfigPinRegisters(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber,
+ Cy_CapSense_SsConfigPinRegisters(ioPtr->pcPtr, (uint32_t)ioPtr->pinNumber,
CY_GPIO_DM_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
connState = CY_RET_SUCCESS;
}
@@ -1238,73 +1318,130 @@ cy_status Cy_CapSense_SetPinState(
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
+* \return status
+* Returns the operation status:
+* - CY_CAPSENSE_SUCCESS_E - Indicates the successful mode switching or
+* the CSD HW block is in the same mode as desired.
+* - CY_CAPSENSE_HW_BUSY_E - The CSD HW block is busy with previous operation.
+* - CY_CAPSENSE_HW_LOCKED_E - The CSD HW block is captured by another middleware.
+*
*******************************************************************************/
-void Cy_CapSense_SwitchSensingMode(uint8_t mode, cy_stc_capsense_context_t * context)
+cy_en_capsense_return_status_t Cy_CapSense_SwitchSensingMode(uint8_t mode, cy_stc_capsense_context_t * context)
{
+ cy_en_capsense_return_status_t switchStatus;
+
if (context->ptrActiveScanSns->currentSenseMethod != mode)
{
- /* The requested mode differs from the current one. Disable the current mode. */
- switch(context->ptrActiveScanSns->currentSenseMethod)
+ /* Check the CSD HW lock status */
+ if(CY_CSD_CAPSENSE_KEY == Cy_CSD_GetLockStatus(context->ptrCommonConfig->ptrCsdBase,
+ context->ptrCommonConfig->ptrCsdContext))
{
- case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E:
- Cy_CapSense_CSDDisableMode_Call(context);
- break;
- case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E:
- Cy_CapSense_CSXDisableMode_Call(context);
- break;
- default:
- break;
- }
+ if (CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(context))
+ {
+ /* The requested mode differs from the current one. Disable the current mode. */
+ switch(context->ptrActiveScanSns->currentSenseMethod)
+ {
+ case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E:
+ Cy_CapSense_CSDDisableMode_Call(context);
+ break;
+ case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E:
+ Cy_CapSense_CSXDisableMode_Call(context);
+ break;
+ case (uint8_t)CY_CAPSENSE_SENSE_METHOD_BIST_E:
+ Cy_CapSense_BistDisableMode_Call(context);
+ break;
+ default:
+ break;
+ }
+
+ context->ptrActiveScanSns->currentSenseMethod = mode;
+
+ /* Enable the specified mode */
+ switch(context->ptrActiveScanSns->currentSenseMethod)
+ {
+ case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E:
+ Cy_CapSense_CSDInitialize_Call(context);
+ break;
+ case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E:
+ Cy_CapSense_CSXInitialize_Call(context);
+ break;
+ case (uint8_t)CY_CAPSENSE_SENSE_METHOD_BIST_E:
+ Cy_CapSense_BistInitialize_Call(context);
+ break;
+ default:
+ break;
+ }
- context->ptrActiveScanSns->currentSenseMethod = mode;
-
- /* Enable the specified mode */
- switch(context->ptrActiveScanSns->currentSenseMethod)
+ switchStatus = CY_CAPSENSE_SUCCESS_E;
+ }
+ else
+ {
+ switchStatus = CY_CAPSENSE_HW_BUSY_E;
+ }
+ }
+ else
{
- case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E:
- Cy_CapSense_CSDInitialize_Call(context);
- break;
- case (uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E:
- Cy_CapSense_CSXInitialize_Call(context);
- break;
- default:
- break;
+ switchStatus = CY_CAPSENSE_HW_LOCKED_E;
}
}
+ else
+ {
+ switchStatus = CY_CAPSENSE_SUCCESS_E;
+ }
+
+ return (switchStatus);
}
/*******************************************************************************
-* Function Name: Cy_CapSense_SetIOsInDefaultState
+* Function Name: Cy_CapSense_SetIOsInDesiredState
****************************************************************************//**
*
-* Sets all CapSense pins into a default state.
+* Sets all CapSense pins into a desired state.
*
* \details
-* Sets all the CSD/CSX IOs into a default state:
+* Sets all the CSD/CSX IOs into a desired state.
+* Default state:
* - HSIOM - Disconnected, the GPIO mode.
* - DM - Strong drive.
* - State - Zero.
*
* Do not call this function directly from the application program.
*
+* \param desiredDriveMode
+* Specifies the desired pin control port (PC) configuration.
+*
+* \param desiredPinOutput
+* Specifies the desired pin output data register (DR) state.
+*
+* \param desiredHsiom
+* Specifies the desired pin HSIOM state.
+*
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
*******************************************************************************/
-void Cy_CapSense_SetIOsInDefaultState(const cy_stc_capsense_context_t * context)
+void Cy_CapSense_SetIOsInDesiredState(
+ uint32_t desiredDriveMode,
+ uint32_t desiredPinOutput,
+ en_hsiom_sel_t desiredHsiom,
+ const cy_stc_capsense_context_t * context)
{
uint32_t loopIndex;
- uint32_t interruptState;
const cy_stc_capsense_pin_config_t * ptrPinCfg = context->ptrPinConfig;
/* Loop through all electrodes */
for (loopIndex = 0u; loopIndex < context->ptrCommonConfig->numPin; loopIndex++)
{
- interruptState = Cy_SysLib_EnterCriticalSection();
- Cy_GPIO_Pin_FastInit(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber,
- CY_GPIO_DM_STRONG, 0u, CY_CAPSENSE_HSIOM_SEL_GPIO);
- Cy_SysLib_ExitCriticalSection(interruptState);
+ Cy_CapSense_SsConfigPinRegisters(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber, desiredDriveMode, desiredHsiom);
+ if (0u != desiredPinOutput)
+ {
+ Cy_GPIO_Set(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber);
+ }
+ else
+ {
+ Cy_GPIO_Clr(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber);
+ }
/* Get next electrode */
ptrPinCfg++;
@@ -1316,10 +1453,10 @@ void Cy_CapSense_SetIOsInDefaultState(const cy_stc_capsense_context_t * context)
* Function Name: Cy_CapSense_SetSpecificIOsInDefaultState
****************************************************************************//**
*
-* Sets all CapSense pins into a default state.
+* Sets specific CapSense pins into a default state.
*
* \details
-* Sets all external capacitors and shield electrodes into a default state:
+* Sets all external capacitors and shield electrodes into the default state:
* - HSIOM - Disconnected, the GPIO mode.
* - DM - High-Z Analog.
*
@@ -1340,7 +1477,7 @@ void Cy_CapSense_SetSpecificIOsInDefaultState(const cy_stc_capsense_context_t *
{
/* Disconnect shields */
Cy_CapSense_CSDDisableShieldElectrodes(context);
-
+
if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn)
{
/* Csh pin to default state */
@@ -1381,7 +1518,7 @@ void Cy_CapSense_SsPostAllWidgetsScan(cy_stc_capsense_context_t * context)
cy_status postScanStatus;
cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
uint32_t widgetId = (uint32_t)ptrActive->widgetIndex + 1u;
-
+
do
{
if (context->ptrCommonConfig->numWd > widgetId)
@@ -1416,24 +1553,24 @@ void Cy_CapSense_SsPostAllWidgetsScan(cy_stc_capsense_context_t * context)
****************************************************************************//**
*
* Implements interrupt service routine for CapSense Middleware.
-*
-* The CSD HW block generates an interrupt at end of every sensor scan.
-* The CapSense middleware uses this interrupt to implement a
-* non-blocking sensor scan method, in which only the first sensor scan is
-* initiated by the application program and subsequent sensor scans are
-* initiated in the interrupt service routine as soon as the current scan
-* is completed. The above stated interrupt service routine is implemented
-* as a part of the CapSense middleware.
-*
-* The CapSense middleware does not initialize or modify the priority
-* of interrupts. For the operation of middleware, the application program
-* must configure CSD interrupt and assign interrupt vector to
-* the Cy_CapSense_InterruptHandler() function. Refer to function
+*
+* The CSD HW block generates an interrupt at end of every sensor scan.
+* The CapSense middleware uses this interrupt to implement a
+* non-blocking sensor scan method, in which only the first sensor scan is
+* initiated by the application program and subsequent sensor scans are
+* initiated in the interrupt service routine as soon as the current scan
+* is completed. The above stated interrupt service routine is implemented
+* as a part of the CapSense middleware.
+*
+* The CapSense middleware does not initialize or modify the priority
+* of interrupts. For the operation of middleware, the application program
+* must configure CSD interrupt and assign interrupt vector to
+* the Cy_CapSense_InterruptHandler() function. Refer to function
* usage example for details.
-*
+*
* \param base
-* The pointer to the base register address of the CSD HW block. A macro for
-* the pointer can be found in cycfg_peripherals.h file defined as
+* The pointer to the base register address of the CSD HW block. A macro for
+* the pointer can be found in cycfg_peripherals.h file defined as
* \_HW. If no name is specified then the default name
* is used csd_\_csd_\_HW.
*
@@ -1448,9 +1585,9 @@ void Cy_CapSense_SsPostAllWidgetsScan(cy_stc_capsense_context_t * context)
* Cy_CapSense_InterruptHandler() function from a CSD ISR.
*
* \funcusage
-*
+*
* An example of the ISR initialization:
-*
+*
* The CapSense_ISR_cfg variable should be declared by the application
* program according to the examples below:
* For Core CM0+:
@@ -1458,35 +1595,35 @@ void Cy_CapSense_SsPostAllWidgetsScan(cy_stc_capsense_context_t * context)
*
* For Core CM4:
* \snippet capsense/snippet/main.c snippet_m4_capsense_interrupt_source_declaration
-*
+*
* The CapSense interrupt handler should be defined by the application program
* according to the example below:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_IntHandler
-*
-* Then, the application program should configure and enable the CSD block interrupt
-* between calls of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions:
+*
+* Then, the application program should configure and enable the CSD block interrupt
+* between calls of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions:
* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Initialization
-*
-* CapSense_HW is the pointer to the base register address of
-* the CSD HW block. A macro for the pointer can be found in the cycfg_peripherals.h
-* file defined as \_HW. If no name specified,
+*
+* CapSense_HW is the pointer to the base register address of
+* the CSD HW block. A macro for the pointer can be found in the cycfg_peripherals.h
+* file defined as \_HW. If no name specified,
* the default name is used csd_\_csd_\_HW.
-*
+*
* An example of sharing the CSD HW block by the CapSense and CSDADC middleware.
* Declares the CapSense_ISR_cfg variable:
* \snippet capsense/snippet/main.c snippet_m4_capsense_interrupt_source_declaration
-*
+*
* Declares the CSDADC_ISR_cfg variable:
* \snippet capsense/snippet/main.c snippet_m4_adc_interrupt_source_declaration
-*
+*
* Defines the CapSense interrupt handler:
* \snippet capsense/snippet/main.c snippet_CapSense_Interrupt
-*
+*
* Defines the CSDADC interrupt handler:
* \snippet capsense/snippet/main.c snippet_CSDADC_Interrupt
-*
+*
* The part of the main.c FW flow:
-* \snippet capsense/snippet/main.c snippet_Cy_CapSense_TimeMultiplex
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_TimeMultiplex
*
*******************************************************************************/
void Cy_CapSense_InterruptHandler(const CSD_Type * base, cy_stc_capsense_context_t * context)
@@ -1507,7 +1644,7 @@ void Cy_CapSense_InterruptHandler(const CSD_Type * base, cy_stc_capsense_context
* Cy_CapSense_CalibrateAllWidgets(), but only for a specified widget.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param context
@@ -1545,6 +1682,11 @@ cy_status Cy_CapSense_CalibrateWidget(uint32_t widgetId, cy_stc_capsense_context
break;
}
}
+ /* Update CRC if BIST is enabled */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ Cy_CapSense_UpdateCrcWidget(widgetId, context);
+ }
return calibrateStatus;
}
@@ -1554,19 +1696,19 @@ cy_status Cy_CapSense_CalibrateWidget(uint32_t widgetId, cy_stc_capsense_context
* Function Name: Cy_CapSense_CalibrateAllWidgets
****************************************************************************//**
*
-* Executes the IDAC calibration for all the sensors in all widgets in
+* Executes the IDAC calibration for all the sensors in all widgets in
* the middleware to default target value.
-*
-* This function detects the sensing method used by each widget and performs
-* a successive approximation search algorithm to find the appropriate modulator
-* and compensation IDAC (if enabled) values for all sensors in CSD widgets
-* and/or IDAC values for all sensors in CSX widgets to make sensor raw count
+*
+* This function detects the sensing method used by each widget and performs
+* a successive approximation search algorithm to find the appropriate modulator
+* and compensation IDAC (if enabled) values for all sensors in CSD widgets
+* and/or IDAC values for all sensors in CSX widgets to make sensor raw count
* to the default value level.
-*
-* Calibration returns CYRET_BAD_DATA if resulted raw count is outside
+*
+* Calibration returns CY_RET_BAD_DATA if resulted raw count is outside
* the limits.
-*
-* This function could be used only if Enable IDAC auto-calibration parameter
+*
+* This function could be used only if Enable IDAC auto-calibration parameter
* is enabled for CSD and/or CSX widgets.
*
* \param context
@@ -1597,10 +1739,10 @@ cy_status Cy_CapSense_CalibrateAllWidgets(cy_stc_capsense_context_t * context)
* Function Name: Cy_CapSense_CalibrateAllCsdWidgets
****************************************************************************//**
*
-* Executes the IDAC calibration for all the sensors in CSD widgets to
+* Executes the IDAC calibration for all the sensors in CSD widgets to
* the default target value.
-*
-* This function performs exact same tasks of Cy_CapSense_CalibrateAllWidgets(),
+*
+* This function performs exact same tasks of Cy_CapSense_CalibrateAllWidgets(),
* but only for CSD widgets.
*
* \param context
@@ -1624,6 +1766,11 @@ cy_status Cy_CapSense_CalibrateAllCsdWidgets(cy_stc_capsense_context_t * context
calibrateStatus |= Cy_CapSense_CSDCalibrateWidget_Call(widgetId,
(uint32_t)context->ptrCommonConfig->csdRawTarget,
context);
+ /* Update CRC if BIST is enabled */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ Cy_CapSense_UpdateCrcWidget(widgetId, context);
+ }
}
}
@@ -1635,10 +1782,10 @@ cy_status Cy_CapSense_CalibrateAllCsdWidgets(cy_stc_capsense_context_t * context
* Function Name: Cy_CapSense_CalibrateAllCsxWidgets
****************************************************************************//**
*
-* Executes the IDAC calibration for all the sensors in CSX widgets to
+* Executes the IDAC calibration for all the sensors in CSX widgets to
* the default target value.
-*
-* This function performs the exact same tasks of Cy_CapSense_CalibrateAllWidgets(),
+*
+* This function performs the exact same tasks of Cy_CapSense_CalibrateAllWidgets(),
* but only for CSX widgets.
*
* \param context
@@ -1660,6 +1807,11 @@ cy_status Cy_CapSense_CalibrateAllCsxWidgets(cy_stc_capsense_context_t * context
if((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E == context->ptrWdConfig[widgetId].senseMethod)
{
calibrateStatus |= Cy_CapSense_CSXCalibrateWidget(widgetId, (uint32_t)context->ptrCommonConfig->csxRawTarget, context);
+ /* Update CRC if BIST is enabled */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ Cy_CapSense_UpdateCrcWidget(widgetId, context);
+ }
}
}
@@ -1678,7 +1830,7 @@ cy_status Cy_CapSense_CalibrateAllCsxWidgets(cy_stc_capsense_context_t * context
*
* This function performs the following tasks:
* - Calibrate Modulator and Compensation IDACs.
-* - Tune the Sense Clock optimal value to get a Sense Clock period greater
+* - Tune the Sense Clock optimal value to get a Sense Clock period greater
* than 2*5*R*Cp.
* - Calculate the resolution for the optimal finger capacitance.
*
@@ -1717,12 +1869,12 @@ cy_status Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context)
*
* This function performs the following tasks:
* - Calibrate Modulator and Compensation IDACs.
-* - Tune the Sense Clock optimal value to get a Sense Clock period greater
+* - Tune the Sense Clock optimal value to get a Sense Clock period greater
* than 2*5*R*Cp.
* - Calculate the resolution for the optimal finger capacitance.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param context
@@ -1735,11 +1887,11 @@ cy_status Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context)
*
*******************************************************************************/
cy_status Cy_CapSense_SsAutoTuneWidget(
- uint32_t widgetId,
+ uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
cy_status autoTuneStatus = CY_RET_SUCCESS;
-
+
uint32_t snsIndex;
uint32_t inputSnsClk;
uint32_t minSnsClkDiv;
@@ -1757,16 +1909,16 @@ cy_status Cy_CapSense_SsAutoTuneWidget(
const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdCfg->ptrWdContext;
cy_stc_capsense_sensor_context_t * ptrSnsCtx;
-
+
/* Store sense clock source to be restored at the end of function */
snsClkSourceAuto = ptrWdCxt->snsClkSource;
-
+
/* Find input of sensor clock frequency */
- inputSnsClk = context->ptrCommonConfig->periClkHz /
+ inputSnsClk = context->ptrCommonConfig->periClkHz /
context->ptrCommonContext->modCsdClk /
CY_CAPSENSE_CSD_AUTOTUNE_CAL_UNITS;
-
- minSnsClkDiv = context->ptrCommonConfig->periClkHz /
+
+ minSnsClkDiv = context->ptrCommonConfig->periClkHz /
context->ptrCommonContext->modCsdClk /
CY_CAPSENSE_CSD_SNS_FREQ_KHZ_MAX;
if (CY_CAPSENSE_MIN_SNS_CLK_DIVIDER > minSnsClkDiv)
@@ -1905,11 +2057,11 @@ cy_status Cy_CapSense_SsAutoTuneWidget(
ptrWdCxt->rowSnsClk = (uint16_t)minSnsClkDiv;
}
}
-
+
/* Check tuning results */
if (CY_CAPSENSE_AUTOTUNE_CP_MAX < maxCp)
{
- autoTuneStatus = CYRET_BAD_DATA;
+ autoTuneStatus = CY_RET_BAD_DATA;
}
/*
@@ -1957,6 +2109,11 @@ cy_status Cy_CapSense_SsAutoTuneWidget(
autoTuneStatus |= Cy_CapSense_CSDCalibrateWidget_Call(widgetId,
(uint32_t)context->ptrCommonConfig->csdRawTarget,
context);
+ /* Update CRC if BIST is enabled */
+ if (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->bistEn)
+ {
+ Cy_CapSense_UpdateCrcWidget(widgetId, context);
+ }
return autoTuneStatus;
}
@@ -1976,7 +2133,7 @@ void Cy_CapSense_InitializeSourceSenseClk(const cy_stc_capsense_context_t * cont
{
uint32_t wdIndex;
const cy_stc_capsense_widget_config_t * ptrWdCfg = context->ptrWdConfig;
-
+
for (wdIndex = 0u; wdIndex < context->ptrCommonConfig->numWd; wdIndex++)
{
switch(ptrWdCfg->senseMethod)
@@ -2006,11 +2163,11 @@ void Cy_CapSense_InitializeSourceSenseClk(const cy_stc_capsense_context_t * cont
*
* The SSC polynomial size in the auto mode is found based on the following
* requirements:
-* - an LFSR value should be selected so that the max clock dither
+* - an LFSR value should be selected so that the max clock dither
* is limited with +/-10%.
-* - at least one full spread spectrum polynomial should pass during
+* - at least one full spread spectrum polynomial should pass during
* the scan time.
-* - the value of the number of conversions should be an integer multiple
+* - the value of the number of conversions should be an integer multiple
* of the repeat period of the programmed LFSR_SIZE.
*
* \param clkDivider
@@ -2019,7 +2176,7 @@ void Cy_CapSense_InitializeSourceSenseClk(const cy_stc_capsense_context_t * cont
* \param conversionsNum
* The widget conversion number.
*
-* \return
+* \return
* Returns the size of LFSR value for the SENSE_PERIOD register.
*
*******************************************************************************/
@@ -2055,7 +2212,7 @@ uint32_t Cy_CapSense_SsCalcLfsrSize(uint32_t clkDivider, uint32_t conversionsNum
lfsrSize = CY_CAPSENSE_CLK_SOURCE_DIRECT;
}
}
-
+
return lfsrSize;
}
@@ -2079,7 +2236,7 @@ void Cy_CapSense_DischargeExtCapacitors(cy_stc_capsense_context_t * context)
uint32_t cmodPcReg = 0uL;
uint32_t cintAPcReg = 0uL;
uint32_t cintBPcReg = 0uL;
-
+
en_hsiom_sel_t cshHsiomReg = CY_CAPSENSE_HSIOM_SEL_GPIO;
en_hsiom_sel_t cmodHsiomReg = CY_CAPSENSE_HSIOM_SEL_GPIO;
en_hsiom_sel_t cintAHsiomReg = CY_CAPSENSE_HSIOM_SEL_GPIO;
@@ -2092,14 +2249,14 @@ void Cy_CapSense_DischargeExtCapacitors(cy_stc_capsense_context_t * context)
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCmod,
(uint32_t)context->ptrCommonConfig->pinCmod, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
Cy_GPIO_Clr(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod);
-
- if((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn) &&
+
+ if((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn) &&
(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn))
{
Cy_CapSense_SsReadPinRegisters(context->ptrCommonConfig->portCsh,
(uint32_t)context->ptrCommonConfig->pinCsh, &cshPcReg, &cshHsiomReg);
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh,
- (uint32_t)context->ptrCommonConfig->pinCsh, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
+ (uint32_t)context->ptrCommonConfig->pinCsh, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
Cy_GPIO_Clr(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh);
}
}
@@ -2111,7 +2268,7 @@ void Cy_CapSense_DischargeExtCapacitors(cy_stc_capsense_context_t * context)
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA,
(uint32_t)context->ptrCommonConfig->pinCintA, CY_GPIO_DM_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
Cy_GPIO_Clr(context->ptrCommonConfig->portCintA, (uint32_t)context->ptrCommonConfig->pinCintA);
-
+
Cy_CapSense_SsReadPinRegisters(context->ptrCommonConfig->portCintB,
(uint32_t)context->ptrCommonConfig->pinCintB, &cintBPcReg, &cintBHsiomReg);
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB,
@@ -2125,8 +2282,8 @@ void Cy_CapSense_DischargeExtCapacitors(cy_stc_capsense_context_t * context)
{
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCmod,
(uint32_t)context->ptrCommonConfig->pinCmod, cmodPcReg, cmodHsiomReg);
-
- if((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn) &&
+
+ if((CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdShieldEn) &&
(CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCTankShieldEn))
{
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh,
@@ -2138,7 +2295,7 @@ void Cy_CapSense_DischargeExtCapacitors(cy_stc_capsense_context_t * context)
{
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA,
(uint32_t)context->ptrCommonConfig->pinCintA, cintAPcReg, cintAHsiomReg);
-
+
Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB,
(uint32_t)context->ptrCommonConfig->pinCintB, cintBPcReg, cintBHsiomReg);
}
@@ -2153,12 +2310,12 @@ void Cy_CapSense_DischargeExtCapacitors(cy_stc_capsense_context_t * context)
* pointers for further faster access to widget/sensor parameters.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param sensorId
-* Specifies the ID number of the sensor within the widget. A macro for the
-* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE__SNS_ID.
*
* \param context
@@ -2166,8 +2323,8 @@ void Cy_CapSense_DischargeExtCapacitors(cy_stc_capsense_context_t * context)
*
*******************************************************************************/
void Cy_CapSense_InitActivePtr(
- uint32_t widgetId,
- uint32_t sensorId,
+ uint32_t widgetId,
+ uint32_t sensorId,
cy_stc_capsense_context_t * context)
{
Cy_CapSense_InitActivePtrWd(widgetId, context);
@@ -2179,15 +2336,15 @@ void Cy_CapSense_InitActivePtr(
* Function Name: Cy_CapSense_InitActivePtrSns
****************************************************************************//**
*
-* Initializes active scan sensor structure with pointers to sensor
+* Initializes active scan sensor structure with pointers to sensor
* for further faster access to widget/sensor parameters.
*
* This function supposes that the Cy_CapSense_InitActivePtrWd() function
* is called before.
*
* \param sensorId
-* Specifies the ID number of the sensor within the widget. A macro for the
-* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE__SNS_ID.
*
* \param context
@@ -2195,7 +2352,7 @@ void Cy_CapSense_InitActivePtr(
*
*******************************************************************************/
void Cy_CapSense_InitActivePtrSns(
- uint32_t sensorId,
+ uint32_t sensorId,
cy_stc_capsense_context_t * context)
{
cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
@@ -2215,14 +2372,14 @@ void Cy_CapSense_InitActivePtrSns(
ptrActive->sensorIndex = (uint16_t)sensorId;
ptrActive->ptrSnsContext = &ptrActive->ptrWdConfig->ptrSnsContext[sensorId];
ptrActive->connectedSnsState = CY_CAPSENSE_SNS_DISCONNECTED;
-
+
numberRows = ptrActive->ptrWdConfig->numRows;
numberCols = ptrActive->ptrWdConfig->numCols;
ptrActive->rxIndex = (uint8_t)numberCols;
ptrActive->txIndex = (uint8_t)numberRows;
ptrActive->ptrRxConfig = &ptrActive->ptrWdConfig->ptrEltdConfig[sensorId / numberRows];
ptrActive->ptrTxConfig = &ptrActive->ptrWdConfig->ptrEltdConfig[numberCols + (sensorId % numberRows)];
-
+
break;
default:
break;
@@ -2236,11 +2393,11 @@ void Cy_CapSense_InitActivePtrSns(
* Initializes active scan sensor structure with pointers to current widget
* for further faster access to widget/sensor parameters.
*
-* This function does not update pointers to current sensor and the
+* This function does not update pointers to current sensor and the
* Cy_CapSense_InitActivePtrSns() function should be called after current one.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param context
@@ -2248,7 +2405,7 @@ void Cy_CapSense_InitActivePtrSns(
*
*******************************************************************************/
void Cy_CapSense_InitActivePtrWd(
- uint32_t widgetId,
+ uint32_t widgetId,
cy_stc_capsense_context_t * context)
{
cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
@@ -2280,14 +2437,22 @@ void Cy_CapSense_InitActivePtrWd(
*
*******************************************************************************/
void Cy_CapSense_SsConfigPinRegisters(
- GPIO_PRT_Type * base,
- uint32_t pinNum,
- uint32_t dm,
+ GPIO_PRT_Type * base,
+ uint32_t pinNum,
+ uint32_t dm,
en_hsiom_sel_t hsiom)
{
uint32_t interruptState = Cy_SysLib_EnterCriticalSection();
- Cy_GPIO_SetDrivemode(base, pinNum, dm);
- Cy_GPIO_SetHSIOM(base, pinNum, hsiom);
+ if (CY_CAPSENSE_HSIOM_SEL_GPIO == hsiom)
+ {
+ Cy_GPIO_SetHSIOM(base, pinNum, hsiom);
+ Cy_GPIO_SetDrivemode(base, pinNum, dm);
+ }
+ else
+ {
+ Cy_GPIO_SetDrivemode(base, pinNum, dm);
+ Cy_GPIO_SetHSIOM(base, pinNum, hsiom);
+ }
Cy_SysLib_ExitCriticalSection(interruptState);
}
@@ -2337,7 +2502,7 @@ void Cy_CapSense_SsReadPinRegisters(GPIO_PRT_Type * base, uint32_t pinNum, uint3
*
*******************************************************************************/
void Cy_CapSense_SetClkDivider(
- uint32_t dividerValue,
+ uint32_t dividerValue,
const cy_stc_capsense_context_t * context)
{
uint32_t dividerIndex = (uint32_t)context->ptrCommonConfig->periDividerIndex;
@@ -2373,8 +2538,8 @@ void Cy_CapSense_SetClkDivider(
*
*******************************************************************************/
uint32_t Cy_CapSense_WatchdogCyclesNum(
- uint32_t desiredTimeUs,
- uint32_t cpuFreqMHz,
+ uint32_t desiredTimeUs,
+ uint32_t cpuFreqMHz,
uint32_t cyclesPerLoop)
{
uint32_t retVal;
@@ -2392,6 +2557,82 @@ uint32_t Cy_CapSense_WatchdogCyclesNum(
}
+/*******************************************************************************
+* Function Name: Cy_CapSense_WaitForSeqIdle
+****************************************************************************//**
+*
+* This internal function checks the state of the CSD HW sequencer. If the
+* sequencer is switched to the IDLE state before the software timeout,
+* the function returns a non-zero. If the software watchdog is triggered
+* during the scan, the function returns zero.
+*
+* \param watchdogCycleNum
+* A watchdog cycle number to check a timeout.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns watchdog counter. If it is equal to zero, it means timeout happened.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_WaitForSeqIdle(
+ uint32_t watchdogCycleNum,
+ const cy_stc_capsense_context_t * context)
+{
+ uint32_t watchdogCounter = watchdogCycleNum;
+
+ while((0u != (CY_CAPSENSE_CSD_SEQ_START_START_MSK &
+ Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_SEQ_START))))
+ {
+ if(0uL == watchdogCounter)
+ {
+ break;
+ }
+
+ watchdogCounter--;
+ }
+
+
+ return (watchdogCounter);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_WaitEndOfScan
+****************************************************************************//**
+*
+* This internal function checks for the scan status. If the scan ends before
+* the software watchdog triggering, the function returns a non-zero watchdog
+* cycles number. If the software watchdog triggers during the scan,
+* the function returns zero.
+*
+* \param watchdogCycleNum
+* A watchdog cycle number to check a timeout.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns watchdog counter. If it is equal to zero, it means timeout happened.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_WaitEndOfScan(
+ uint32_t watchdogCycleNum,
+ const cy_stc_capsense_context_t * context)
+{
+ uint32_t watchdogCounter = watchdogCycleNum;
+
+ while (((Cy_CSD_ReadReg(context->ptrCommonConfig->ptrCsdBase, CY_CSD_REG_OFFSET_INTR) &
+ CY_CAPSENSE_CSD_INTR_SAMPLE_MSK) == 0u) && (0u != watchdogCounter))
+ {
+ watchdogCounter--;
+ }
+
+ return (watchdogCounter);
+}
+
+
/*******************************************************************************
* Function Name: Cy_CapSense_CalibrateCheck
****************************************************************************//**
@@ -2403,7 +2644,7 @@ uint32_t Cy_CapSense_WatchdogCyclesNum(
* error.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param target
@@ -2417,13 +2658,13 @@ uint32_t Cy_CapSense_WatchdogCyclesNum(
*
*******************************************************************************/
cy_status Cy_CapSense_CalibrateCheck(
- uint32_t widgetId,
- uint32_t target,
+ uint32_t widgetId,
+ uint32_t target,
uint32_t senseMethod,
const cy_stc_capsense_context_t * context)
{
cy_status calibrateStatus = CY_RET_SUCCESS;
- uint32_t rawcount;
+ uint32_t tmpRawcount;
uint32_t snsIndex;
uint32_t upperLimit;
uint32_t lowerLimit;
@@ -2437,15 +2678,15 @@ cy_status Cy_CapSense_CalibrateCheck(
/* Calculate acceptable raw count range based on the resolution, target and error */
if((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSD_E == senseMethod)
{
- rawcount = (1uL << context->ptrWdContext[widgetId].resolution) - 1u;
+ tmpRawcount = (1uL << context->ptrWdContext[widgetId].resolution) - 1u;
calibrationError = context->ptrCommonConfig->csdCalibrationError;
}
else
{
- rawcount = context->ptrWdContext[widgetId].maxRawCount;
+ tmpRawcount = context->ptrWdContext[widgetId].maxRawCount;
calibrationError = context->ptrCommonConfig->csxCalibrationError;
}
-
+
lowerLimit = 0u;
if (target > calibrationError)
@@ -2457,21 +2698,21 @@ cy_status Cy_CapSense_CalibrateCheck(
{
upperLimit = CY_CAPSENSE_PERCENTAGE_100;
}
- lowerLimit = (rawcount * lowerLimit) / CY_CAPSENSE_PERCENTAGE_100;
- upperLimit = (rawcount * upperLimit) / CY_CAPSENSE_PERCENTAGE_100;
+ lowerLimit = (tmpRawcount * lowerLimit) / CY_CAPSENSE_PERCENTAGE_100;
+ upperLimit = (tmpRawcount * upperLimit) / CY_CAPSENSE_PERCENTAGE_100;
freqChNumber = (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->mfsEn) ? 3u : 1u;
-
- /* Check whether rawcount is in the defined range */
+
+ /* Check whether sensors' rawcount is in the defined range */
for (freqChIndex = 0u; freqChIndex < freqChNumber; freqChIndex++)
{
ptrSnsCxt = ptrChCxt;
for(snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
{
- rawcount = ptrSnsCxt->raw;
- if ((rawcount < lowerLimit) || (rawcount > upperLimit))
+ tmpRawcount = ptrSnsCxt->raw;
+ if ((tmpRawcount < lowerLimit) || (tmpRawcount > upperLimit))
{
- calibrateStatus = CYRET_BAD_DATA;
+ calibrateStatus = CY_RET_BAD_DATA;
break;
}
ptrSnsCxt++;
@@ -2489,43 +2730,57 @@ cy_status Cy_CapSense_CalibrateCheck(
*
* Finds the optimal Vref value based on the VDDA voltage.
*
-* \param vddaMv
-* Device VDDA voltage.
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the recommended reference voltage based on the configuration.
*
*******************************************************************************/
-uint32_t Cy_CapSense_GetVrefAutoMv(uint32_t vddaMv)
+uint32_t Cy_CapSense_GetVrefAutoMv(const cy_stc_capsense_context_t * context)
{
+ uint32_t vddaMv = (uint32_t)context->ptrCommonConfig->vdda;
uint32_t vrefHighVoltageMv;
- if(vddaMv >= 2750u)
- {
- /*
- * The recommended VrefHigh Voltage for the VDDA >= 2.75V.
- */
- vrefHighVoltageMv = 2133u;
- }
- else if(vddaMv >= 2200u)
- {
- /*
- * The recommended VrefHigh Voltage for the 2.2V - 2.75V VDDA range.
- */
- vrefHighVoltageMv = 1600u;
- }
- else if(vddaMv >= 1800u)
- {
- /*
- * The recommended VrefHigh Voltage for the 1.8V - 2.20V VDDA range.
- */
- vrefHighVoltageMv = 1164u;
- }
- else
- {
- /*
- * The recommended VrefHigh Voltage for the VDDA < 1.80V.
- */
- vrefHighVoltageMv = 800u;
- }
-
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ if(vddaMv >= CY_CAPSENSE_VREF_RANGE_0)
+ {
+ vrefHighVoltageMv = CY_CAPSENSE_VREF_VALUE_0;
+ }
+ else if(vddaMv >= CY_CAPSENSE_VREF_RANGE_1)
+ {
+ vrefHighVoltageMv = CY_CAPSENSE_VREF_VALUE_1;
+ }
+ else if(vddaMv >= CY_CAPSENSE_VREF_RANGE_2)
+ {
+ vrefHighVoltageMv = CY_CAPSENSE_VREF_VALUE_2;
+ }
+ else
+ {
+ vrefHighVoltageMv = CY_CAPSENSE_VREF_VALUE_MIN;
+ }
+ #else
+ if(vddaMv >= CY_CAPSENSE_VREF_RANGE_0)
+ {
+ vrefHighVoltageMv = CY_CAPSENSE_VREF_VALUE_0;
+ }
+ else if(vddaMv >= CY_CAPSENSE_VREF_RANGE_1)
+ {
+ vrefHighVoltageMv = CY_CAPSENSE_VREF_VALUE_1;
+ }
+ else
+ {
+ if (CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+ {
+ vrefHighVoltageMv = CY_CAPSENSE_VREF_VALUE_MIN_PASS;
+ }
+ else
+ {
+ vrefHighVoltageMv = CY_CAPSENSE_VREF_VALUE_MIN_SRSS;
+ }
+ }
+ #endif
+
return(vrefHighVoltageMv);
}
@@ -2535,31 +2790,38 @@ uint32_t Cy_CapSense_GetVrefAutoMv(uint32_t vddaMv)
****************************************************************************//**
*
* Calculates the VrefHigh Gain, based on the values of the device VDDA voltage,
-* the Vref source voltage, and the desired VrefHigh voltage.
-*
-* \param vddaMv
-* Device VDDA voltage.
-*
-* \param vrefInputMv
-* Vref source voltage.
+* the Vref source voltage, and the desired VrefHigh voltage.
*
* \param vrefDesiredMv
* Desired VrefHigh voltage.
*
-* \return
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
* Returns the lowest Gain code required to produce the VrefHigh voltage,
* when the VrefHigh is close to the desired voltage (passed through the
* vrefDesiredMv parameter) but not greater than the desired voltage.
*
*******************************************************************************/
-uint32_t Cy_CapSense_GetVrefHighGain(uint32_t vddaMv, uint32_t vrefInputMv, uint32_t vrefDesiredMv)
+uint32_t Cy_CapSense_GetVrefHighGain(uint32_t vrefDesiredMv, const cy_stc_capsense_context_t * context)
{
uint32_t vferhiGain;
+ uint32_t vrefInputMv;
- if(vrefDesiredMv > (vddaMv - CY_CAPSENSE_VREF_VDDA_MIN_DIFF))
- {
- vrefDesiredMv = (vddaMv - CY_CAPSENSE_VREF_VDDA_MIN_DIFF);
- }
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ (void) context;
+ vrefInputMv = CY_CAPSENSE_VREF_SRSS_MV;
+ #else
+ if (CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+ {
+ vrefInputMv = CY_CAPSENSE_VREF_PASS_MV;
+ }
+ else
+ {
+ vrefInputMv = CY_CAPSENSE_VREF_SRSS_MV;
+ }
+ #endif
vferhiGain = ((CY_CAPSENSE_VREF_GAIN_MAX * vrefInputMv) - 1u) / (vrefDesiredMv + 1u);
@@ -2573,29 +2835,43 @@ uint32_t Cy_CapSense_GetVrefHighGain(uint32_t vddaMv, uint32_t vrefInputMv, uint
/*******************************************************************************
-* Function Name: Cy_CapSense_GetVrefhiAutoMv
+* Function Name: Cy_CapSense_GetVrefHighMv
****************************************************************************//**
*
* Calculates the VrefHigh voltage, based on the Gain code and the Vref source
* voltage.
*
-* \param vrefInputMv
-* Vref source voltage.
-*
* \param vrefGain
* The Gain code.
*
-* \return
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
* Returns the VrefHigh voltage in mV, to be produced for the specified vref Gain
* code and Vref source voltage.
*
*******************************************************************************/
-uint32_t Cy_CapSense_GetVrefHighMv(uint32_t vrefInputMv, uint32_t vrefGain)
+uint32_t Cy_CapSense_GetVrefHighMv(uint32_t vrefGain, const cy_stc_capsense_context_t * context)
{
uint32_t vrefHighMv;
+ uint32_t vrefInputMv;
+
+ #if (CY_CAPSENSE_PSOC4_CSDV2)
+ (void) context;
+ vrefInputMv = CY_CAPSENSE_VREF_SRSS_MV;
+ #else
+ if (CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+ {
+ vrefInputMv = CY_CAPSENSE_VREF_PASS_MV;
+ }
+ else
+ {
+ vrefInputMv = CY_CAPSENSE_VREF_SRSS_MV;
+ }
+ #endif
- vrefHighMv = (CY_CAPSENSE_VREF_GAIN_MAX * vrefInputMv) + ((vrefGain + 1u) >> 1u);
- vrefHighMv /= (vrefGain + 1u);
+ vrefHighMv = (CY_CAPSENSE_VREF_GAIN_MAX * vrefInputMv) / (vrefGain + 1u);
return (vrefHighMv);
}
diff --git a/cy_capsense_sensing.h b/cy_capsense_sensing.h
index 8e5e98f..0044dee 100644
--- a/cy_capsense_sensing.h
+++ b/cy_capsense_sensing.h
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_sensing.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the function prototypes specific to the sensing module.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -23,7 +23,7 @@
#include "cy_capsense_common.h"
#include "cy_capsense_structure.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
@@ -51,8 +51,8 @@ void Cy_CapSense_InterruptHandler(const CSD_Type * base, cy_stc_capsense_context
/******************************************************************************/
cy_status Cy_CapSense_SetupWidgetExt(
- uint32_t widgetId,
- uint32_t sensorId,
+ uint32_t widgetId,
+ uint32_t sensorId,
cy_stc_capsense_context_t * context);
cy_status Cy_CapSense_ScanExt(cy_stc_capsense_context_t * context);
@@ -62,10 +62,10 @@ cy_status Cy_CapSense_CalibrateAllCsdWidgets(cy_stc_capsense_context_t * context
cy_status Cy_CapSense_CalibrateAllCsxWidgets(cy_stc_capsense_context_t * context);
cy_status Cy_CapSense_SetPinState(
- uint32_t widgetId,
- uint32_t sensorElement,
- uint32_t state,
- cy_stc_capsense_context_t * context);
+ uint32_t widgetId,
+ uint32_t sensorElement,
+ uint32_t state,
+ const cy_stc_capsense_context_t * context);
/** \} */
@@ -78,11 +78,15 @@ void Cy_CapSense_SetBusyFlags(cy_stc_capsense_context_t * context);
void Cy_CapSense_ClrBusyFlags(cy_stc_capsense_context_t * context);
cy_status Cy_CapSense_SsInitialize(cy_stc_capsense_context_t * context);
void Cy_CapSense_SsPostAllWidgetsScan(cy_stc_capsense_context_t * context);
-void Cy_CapSense_SetIOsInDefaultState(const cy_stc_capsense_context_t * context);
+void Cy_CapSense_SetIOsInDesiredState(
+ uint32_t desiredDriveMode,
+ uint32_t desiredPinOutput,
+ en_hsiom_sel_t desiredHsiom,
+ const cy_stc_capsense_context_t * context);
void Cy_CapSense_SetSpecificIOsInDefaultState(const cy_stc_capsense_context_t * context);
-void Cy_CapSense_SwitchSensingMode(uint8_t mode, cy_stc_capsense_context_t * context);
+cy_en_capsense_return_status_t Cy_CapSense_SwitchSensingMode(uint8_t mode, cy_stc_capsense_context_t * context);
cy_status Cy_CapSense_SsAutoTune(cy_stc_capsense_context_t * context);
cy_status Cy_CapSense_SsAutoTuneWidget(uint32_t widgetId, cy_stc_capsense_context_t * context);
@@ -104,10 +108,12 @@ uint32_t Cy_CapSense_WatchdogCyclesNum(uint32_t desiredTimeUs, uint32_t cpuFreqM
cy_status Cy_CapSense_CalibrateCheck(uint32_t widgetId, uint32_t target, uint32_t senseMethod,
const cy_stc_capsense_context_t * context);
-uint32_t Cy_CapSense_GetVrefAutoMv(uint32_t vddaMv);
-uint32_t Cy_CapSense_GetVrefHighGain(uint32_t vddaMv, uint32_t vrefInputMv, uint32_t vrefDesiredMv);
-uint32_t Cy_CapSense_GetVrefHighMv(uint32_t vrefInputMv, uint32_t vrefGain);
+uint32_t Cy_CapSense_GetVrefAutoMv(const cy_stc_capsense_context_t * context);
+uint32_t Cy_CapSense_GetVrefHighGain(uint32_t vrefDesiredMv, const cy_stc_capsense_context_t * context);
+uint32_t Cy_CapSense_GetVrefHighMv(uint32_t vrefGain, const cy_stc_capsense_context_t * context);
cy_status Cy_CapSense_InternalPreCalculation(cy_stc_capsense_context_t * context);
+uint32_t Cy_CapSense_WaitForSeqIdle(uint32_t watchdogCycleNum, const cy_stc_capsense_context_t * context);
+uint32_t Cy_CapSense_WaitEndOfScan(uint32_t watchdogCycleNum, const cy_stc_capsense_context_t * context);
/** \} \endcond */
@@ -176,22 +182,22 @@ extern const cy_stc_csd_config_t cy_capsense_csdCfg;
/*******************************************************************************
* CSD HW Waveform Selection values
*******************************************************************************/
-#define CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN (0x00000000uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED (0x00000001uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI1 (0x00000002uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI2 (0x00000003uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP (0x00000004uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP (0x00000005uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_HSCMP (0x00000006uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_SENSE_INV (0x00000007uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI1_DELAY (0x00000008uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI2_DELAY (0x00000009uL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI1_INV (0x0000000AuL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI2_INV (0x0000000BuL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP_INV (0x0000000CuL)
-#define CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP_INV (0x0000000DuL)
-#define CY_CAPSENSE_CSD_WAVEFORM_HSCMP_INV (0x0000000EuL)
-#define CY_CAPSENSE_CSD_WAVEFORM_SENSE (0x0000000FuL)
+#define CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN (0x00000000uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED (0x00000001uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI1 (0x00000002uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI2 (0x00000003uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP (0x00000004uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP (0x00000005uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_HSCMP (0x00000006uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_SENSE_INV (0x00000007uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI1_DELAY (0x00000008uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI2_DELAY (0x00000009uL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI1_INV (0x0000000AuL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI2_INV (0x0000000BuL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP_INV (0x0000000CuL)
+#define CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP_INV (0x0000000DuL)
+#define CY_CAPSENSE_CSD_WAVEFORM_HSCMP_INV (0x0000000EuL)
+#define CY_CAPSENSE_CSD_WAVEFORM_SENSE (0x0000000FuL)
/*******************************************************************************
@@ -199,332 +205,348 @@ extern const cy_stc_csd_config_t cy_capsense_csdCfg;
*******************************************************************************/
/* CSD_CONFIG register masks */
-#define CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK (CSD_CONFIG_IREF_SEL_Msk)
-#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_2_CYCLES (0x00000002uL)
-#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_3_CYCLES (0x00000003uL)
-#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_4_CYCLES (0x00000004uL)
-#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_POS (CSD_CONFIG_FILTER_DELAY_Pos)
-#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_MSK (CSD_CONFIG_FILTER_DELAY_Msk)
-#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_12MHZ (CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_2_CYCLES << CSD_CONFIG_FILTER_DELAY_Pos)
-#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_24MHZ (CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_3_CYCLES << CSD_CONFIG_FILTER_DELAY_Pos)
-#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_48MHZ (CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_4_CYCLES << CSD_CONFIG_FILTER_DELAY_Pos)
-#define CY_CAPSENSE_CSD_CONFIG_SHIELD_DELAY_MSK (CSD_CONFIG_SHIELD_DELAY_Msk)
-#define CY_CAPSENSE_CSD_CONFIG_SHIELD_DELAY_POS (CSD_CONFIG_SHIELD_DELAY_Pos)
-#define CY_CAPSENSE_CSD_CONFIG_SENSE_EN_MSK (CSD_CONFIG_SENSE_EN_Msk)
-#define CY_CAPSENSE_CSD_CONFIG_DSI_COUNT_SEL_POS (CSD_CONFIG_DSI_COUNT_SEL_Pos)
-#define CY_CAPSENSE_CSD_CONFIG_DSI_COUNT_SEL_MSK (CSD_CONFIG_DSI_COUNT_SEL_Msk)
-#define CY_CAPSENSE_CSD_CONFIG_SAMPLE_SYNC_MSK (CSD_CONFIG_SAMPLE_SYNC_Msk)
-#define CY_CAPSENSE_CSD_CONFIG_ENABLE_MSK (CSD_CONFIG_ENABLE_Msk)
+#if (CY_CAPSENSE_PSOC6_CSDV2)
+ #define CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK (CSD_CONFIG_IREF_SEL_Msk)
+#endif
+
+#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_2_CYCLES (0x00000002uL)
+#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_3_CYCLES (0x00000003uL)
+#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_4_CYCLES (0x00000004uL)
+#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_POS (CSD_CONFIG_FILTER_DELAY_Pos)
+#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_MSK (CSD_CONFIG_FILTER_DELAY_Msk)
+#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_12MHZ (CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_2_CYCLES << CSD_CONFIG_FILTER_DELAY_Pos)
+#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_24MHZ (CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_3_CYCLES << CSD_CONFIG_FILTER_DELAY_Pos)
+#define CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_48MHZ (CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_4_CYCLES << CSD_CONFIG_FILTER_DELAY_Pos)
+#define CY_CAPSENSE_CSD_CONFIG_SHIELD_DELAY_MSK (CSD_CONFIG_SHIELD_DELAY_Msk)
+#define CY_CAPSENSE_CSD_CONFIG_SHIELD_DELAY_POS (CSD_CONFIG_SHIELD_DELAY_Pos)
+#define CY_CAPSENSE_CSD_CONFIG_SENSE_EN_MSK (CSD_CONFIG_SENSE_EN_Msk)
+#define CY_CAPSENSE_CSD_CONFIG_DSI_COUNT_SEL_POS (CSD_CONFIG_DSI_COUNT_SEL_Pos)
+#define CY_CAPSENSE_CSD_CONFIG_DSI_COUNT_SEL_MSK (CSD_CONFIG_DSI_COUNT_SEL_Msk)
+#define CY_CAPSENSE_CSD_CONFIG_SAMPLE_SYNC_MSK (CSD_CONFIG_SAMPLE_SYNC_Msk)
+#define CY_CAPSENSE_CSD_CONFIG_ENABLE_MSK (CSD_CONFIG_ENABLE_Msk)
/* CSD_STAT_SEQ register masks */
-#define CY_CAPSENSE_CSD_STAT_SEQ_SEQ_STATE_MSK (CSD_STAT_SEQ_SEQ_STATE_Msk)
+#define CY_CAPSENSE_CSD_STAT_SEQ_SEQ_STATE_MSK (CSD_STAT_SEQ_SEQ_STATE_Msk)
+
+/* CSD_DSI_SEL register masks */
+#define CY_CAPSENSE_CSD_SW_DSI_SEL_CSH_TANK_MSK (0x00000001uL)
+#define CY_CAPSENSE_CSD_SW_DSI_SEL_CMOD_MSK (0x00000010uL)
/* CSD_RESULT_VAL1 register masks */
-#define CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK (CSD_RESULT_VAL1_VALUE_Msk)
-#define CY_CAPSENSE_CSD_RESULT_VAL1_BAD_CONVS_MSK (CSD_RESULT_VAL1_BAD_CONVS_Msk)
-#define CY_CAPSENSE_CSD_RESULT_VAL1_BAD_CONVS_POS (CSD_RESULT_VAL1_BAD_CONVS_Pos)
+#define CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK (CSD_RESULT_VAL1_VALUE_Msk)
+#define CY_CAPSENSE_CSD_RESULT_VAL1_BAD_CONVS_MSK (CSD_RESULT_VAL1_BAD_CONVS_Msk)
+#define CY_CAPSENSE_CSD_RESULT_VAL1_BAD_CONVS_POS (CSD_RESULT_VAL1_BAD_CONVS_Pos)
/* CSD_RESULT_VAL2 register masks */
-#define CY_CAPSENSE_CSD_RESULT_VAL2_VALUE_MSK (CSD_RESULT_VAL2_VALUE_Msk)
+#define CY_CAPSENSE_CSD_RESULT_VAL2_VALUE_MSK (CSD_RESULT_VAL2_VALUE_Msk)
+
+/* CSD_ADC_RES register masks */
+#define CY_CAPSENSE_CSD_ADC_RES_VALUE_MSK (CSD_ADC_RES_VIN_CNT_Msk)
+#define CY_CAPSENSE_CSD_ADC_RES_ADC_OVERFLOW_MSK (CSD_ADC_RES_ADC_OVERFLOW_Msk)
+
+/* CSD_ADC_CTL register masks */
+#define CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK (CSD_ADC_CTL_ADC_MODE_Msk)
/* CSD_INTR register masks */
-#define CY_CAPSENSE_CSD_INTR_SAMPLE_MSK (CSD_INTR_SAMPLE_Msk)
-#define CY_CAPSENSE_CSD_INTR_INIT_MSK (CSD_INTR_INIT_Msk)
-#define CY_CAPSENSE_CSD_INTR_ADC_RES_MSK (CSD_INTR_ADC_RES_Msk)
-#define CY_CAPSENSE_CSD_INTR_ALL_MSK (CSD_INTR_SAMPLE_Msk | CSD_INTR_INIT_Msk | CSD_INTR_ADC_RES_Msk)
+#define CY_CAPSENSE_CSD_INTR_SAMPLE_MSK (CSD_INTR_SAMPLE_Msk)
+#define CY_CAPSENSE_CSD_INTR_INIT_MSK (CSD_INTR_INIT_Msk)
+#define CY_CAPSENSE_CSD_INTR_ADC_RES_MSK (CSD_INTR_ADC_RES_Msk)
+#define CY_CAPSENSE_CSD_INTR_ALL_MSK (CSD_INTR_SAMPLE_Msk | CSD_INTR_INIT_Msk | CSD_INTR_ADC_RES_Msk)
/* CSD_INTR_MASK register masks */
-#define CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK (CSD_INTR_MASK_SAMPLE_Msk)
-#define CY_CAPSENSE_CSD_INTR_MASK_INIT_MSK (CSD_INTR_MASK_INIT_Msk)
-#define CY_CAPSENSE_CSD_INTR_MASK_ADC_RES_MSK (CSD_INTR_MASK_ADC_RES_Msk)
-#define CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK (0uL)
+#define CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK (CSD_INTR_MASK_SAMPLE_Msk)
+#define CY_CAPSENSE_CSD_INTR_MASK_INIT_MSK (CSD_INTR_MASK_INIT_Msk)
+#define CY_CAPSENSE_CSD_INTR_MASK_ADC_RES_MSK (CSD_INTR_MASK_ADC_RES_Msk)
+#define CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK (0uL)
/* CSD_HSCMP register masks */
-#define CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK (CSD_HSCMP_HSCMP_EN_Msk)
-#define CY_CAPSENSE_CSD_HSCMP_HSCMP_INVERT_MSK (CSD_HSCMP_HSCMP_INVERT_Msk)
-#define CY_CAPSENSE_CSD_HSCMP_AZ_EN_MSK (CSD_HSCMP_AZ_EN_Msk)
+#define CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK (CSD_HSCMP_HSCMP_EN_Msk)
+#define CY_CAPSENSE_CSD_HSCMP_HSCMP_INVERT_MSK (CSD_HSCMP_HSCMP_INVERT_Msk)
+#define CY_CAPSENSE_CSD_HSCMP_AZ_EN_MSK (CSD_HSCMP_AZ_EN_Msk)
/* CSD_AMBUF register masks */
-#define CY_CAPSENSE_CSD_AMBUF_PWR_MODE_OFF (0uL)
-#define CY_CAPSENSE_CSD_AMBUF_PWR_MODE_NORM (1uL)
-#define CY_CAPSENSE_CSD_AMBUF_PWR_MODE_HI (2uL)
+#define CY_CAPSENSE_CSD_AMBUF_PWR_MODE_OFF (0uL)
+#define CY_CAPSENSE_CSD_AMBUF_PWR_MODE_NORM (1uL)
+#define CY_CAPSENSE_CSD_AMBUF_PWR_MODE_HI (2uL)
/* CSD_REFGEN register masks */
-#define CY_CAPSENSE_CSD_REFGEN_REFGEN_EN_MSK (CSD_REFGEN_REFGEN_EN_Msk)
-#define CY_CAPSENSE_CSD_REFGEN_BYPASS_MSK (CSD_REFGEN_BYPASS_Msk)
-#define CY_CAPSENSE_CSD_REFGEN_VDDA_EN_MSK (CSD_REFGEN_VDDA_EN_Msk)
-#define CY_CAPSENSE_CSD_REFGEN_RES_EN_MSK (CSD_REFGEN_RES_EN_Msk)
-#define CY_CAPSENSE_CSD_REFGEN_GAIN_POS (CSD_REFGEN_GAIN_Pos)
-#define CY_CAPSENSE_CSD_REFGEN_GAIN_MSK (CSD_REFGEN_GAIN_Msk)
-#define CY_CAPSENSE_CSD_REFGEN_VREFLO_SEL_MSK (CSD_REFGEN_VREFLO_SEL_Msk)
-#define CY_CAPSENSE_CSD_REFGEN_VREFLO_INT_MSK (CSD_REFGEN_VREFLO_INT_Msk)
+#define CY_CAPSENSE_CSD_REFGEN_REFGEN_EN_MSK (CSD_REFGEN_REFGEN_EN_Msk)
+#define CY_CAPSENSE_CSD_REFGEN_BYPASS_MSK (CSD_REFGEN_BYPASS_Msk)
+#define CY_CAPSENSE_CSD_REFGEN_VDDA_EN_MSK (CSD_REFGEN_VDDA_EN_Msk)
+#define CY_CAPSENSE_CSD_REFGEN_RES_EN_MSK (CSD_REFGEN_RES_EN_Msk)
+#define CY_CAPSENSE_CSD_REFGEN_GAIN_POS (CSD_REFGEN_GAIN_Pos)
+#define CY_CAPSENSE_CSD_REFGEN_GAIN_MSK (CSD_REFGEN_GAIN_Msk)
+#define CY_CAPSENSE_CSD_REFGEN_VREFLO_SEL_MSK (CSD_REFGEN_VREFLO_SEL_Msk)
+#define CY_CAPSENSE_CSD_REFGEN_VREFLO_INT_MSK (CSD_REFGEN_VREFLO_INT_Msk)
-#define CY_CAPSENSE_VREF_HI_OVERSHOOT_CORRECTION (0x00000001uL)
+#define CY_CAPSENSE_VREF_HI_OVERSHOOT_CORRECTION (0x00000001uL)
/* CSD_CSDCMP register masks */
-#define CY_CAPSENSE_CSD_CSDCMP_CSDCMP_DISABLED (0uL)
-#define CY_CAPSENSE_CSD_CSDCMP_CSDCMP_EN_MSK (CSD_CSDCMP_CSDCMP_EN_Msk)
-#define CY_CAPSENSE_CSD_CSDCMP_CMP_PHASE_FULL (0uL << CSD_CSDCMP_CMP_PHASE_Pos)
-#define CY_CAPSENSE_CSD_CSDCMP_CMP_PHASE_PHI1 (1uL << CSD_CSDCMP_CMP_PHASE_Pos)
-#define CY_CAPSENSE_CSD_CSDCMP_CMP_PHASE_PHI2 (2uL << CSD_CSDCMP_CMP_PHASE_Pos)
-#define CY_CAPSENSE_CSD_CSDCMP_CMP_PHASE_PHI1_2 (3uL << CSD_CSDCMP_CMP_PHASE_Pos)
-#define CY_CAPSENSE_CSD_CSDCMP_AZ_EN_MSK (CSD_CSDCMP_AZ_EN_Msk)
+#define CY_CAPSENSE_CSD_CSDCMP_CSDCMP_EN_MSK (CSD_CSDCMP_CSDCMP_EN_Msk)
+#define CY_CAPSENSE_CSD_CSDCMP_CMP_PHASE_PHI2_MSK (0x0200u)
/* CSD_SENSE_PERIOD register masks */
-#define CY_CAPSENSE_CSD_SENSE_PERIOD_SENSE_DIV_MSK (CSD_SENSE_PERIOD_SENSE_DIV_Msk)
-#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_MSK (CSD_SENSE_PERIOD_LFSR_SIZE_Msk)
-#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_POS (CSD_SENSE_PERIOD_LFSR_SIZE_Pos)
-#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SCALE_MSK (CSD_SENSE_PERIOD_LFSR_SCALE_Msk)
-#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_CLEAR_MSK (CSD_SENSE_PERIOD_LFSR_CLEAR_Msk)
-#define CY_CAPSENSE_CSD_SENSE_PERIOD_SEL_LFSR_MSB_MSK (CSD_SENSE_PERIOD_SEL_LFSR_MSB_Msk)
-#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_BITS_MSK (CSD_SENSE_PERIOD_LFSR_BITS_Msk)
+#define CY_CAPSENSE_CSD_SENSE_PERIOD_SENSE_DIV_MSK (CSD_SENSE_PERIOD_SENSE_DIV_Msk)
+#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_MSK (CSD_SENSE_PERIOD_LFSR_SIZE_Msk)
+#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_POS (CSD_SENSE_PERIOD_LFSR_SIZE_Pos)
+#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SCALE_MSK (CSD_SENSE_PERIOD_LFSR_SCALE_Msk)
+#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_CLEAR_MSK (CSD_SENSE_PERIOD_LFSR_CLEAR_Msk)
+#define CY_CAPSENSE_CSD_SENSE_PERIOD_SEL_LFSR_MSB_MSK (CSD_SENSE_PERIOD_SEL_LFSR_MSB_Msk)
+#define CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_BITS_MSK (CSD_SENSE_PERIOD_LFSR_BITS_Msk)
/* CSD_SENSE_DUTY register masks */
-#define CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_WIDTH_MSK (CSD_SENSE_DUTY_SENSE_WIDTH_Msk)
-#define CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_POL_MSK (CSD_SENSE_DUTY_SENSE_POL_Msk)
-#define CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_POL_PHI_LOW (0uL)
-#define CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_POL_PHI_HIGH (CSD_SENSE_DUTY_SENSE_POL_Msk)
-#define CY_CAPSENSE_CSD_SENSE_DUTY_OVERLAP_PHI1_MSK (CSD_SENSE_DUTY_OVERLAP_PHI1_Msk)
-#define CY_CAPSENSE_CSD_SENSE_DUTY_OVERLAP_PHI2_MSK (CSD_SENSE_DUTY_OVERLAP_PHI2_Msk)
-
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMPM_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMPM_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMPT_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMPT_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMPS_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMPS_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMA_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMMA_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMMA_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMB_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMMB_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMB_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMMB_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMRH_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMRH_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMRH_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMRH_Pos)
-
-#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_N_SEL_SW_HCRH_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_N_SEL_SW_HCRH_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRL_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_N_SEL_SW_HCRL_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRL_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_N_SEL_SW_HCRL_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCCD_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_N_SEL_SW_HCCD_Pos)
-#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCCD_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_N_SEL_SW_HCCD_Pos)
-
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_PHI1_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_PHI2_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
-
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_PHI1_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_PHI2_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
-
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI1_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI2_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
+#define CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_WIDTH_MSK (CSD_SENSE_DUTY_SENSE_WIDTH_Msk)
+#define CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_POL_MSK (CSD_SENSE_DUTY_SENSE_POL_Msk)
+#define CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_POL_PHI_LOW (0uL)
+#define CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_POL_PHI_HIGH (CSD_SENSE_DUTY_SENSE_POL_Msk)
+#define CY_CAPSENSE_CSD_SENSE_DUTY_OVERLAP_PHI1_MSK (CSD_SENSE_DUTY_OVERLAP_PHI1_Msk)
+#define CY_CAPSENSE_CSD_SENSE_DUTY_OVERLAP_PHI2_MSK (CSD_SENSE_DUTY_OVERLAP_PHI2_Msk)
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_CSD_SENSE_DUTY_CFG (CSD_SENSE_DUTY_OVERLAP_PHI1_Msk | CSD_SENSE_DUTY_OVERLAP_PHI2_Msk)
+#else
+ #define CY_CAPSENSE_CSD_SENSE_DUTY_CFG (CY_CAPSENSE_CSD_SENSE_DUTY_SENSE_POL_PHI_HIGH)
+#endif
+
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMPM_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPM_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMPM_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMPT_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPT_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMPT_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMPS_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMPS_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMPS_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMA_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMMA_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMMA_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMB_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMMB_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMMB_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMMB_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMRH_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_P_SEL_SW_HMRH_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_P_SEL_SW_HMRH_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_P_SEL_SW_HMRH_Pos)
+
+#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_N_SEL_SW_HCRH_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_N_SEL_SW_HCRH_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRL_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_N_SEL_SW_HCRL_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRL_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_N_SEL_SW_HCRL_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCCD_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_HS_N_SEL_SW_HCCD_Pos)
+#define CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCCD_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_HS_N_SEL_SW_HCCD_Pos)
+
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_PHI1_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_PHI2_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_SHIELD_SEL_SW_HCAV_Pos)
+
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_PHI1_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_PHI2_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAG_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_SHIELD_SEL_SW_HCAG_Pos)
+
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI1_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_PHI2_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_SHIELD_SEL_SW_HCBV_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI1_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI2_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
-#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI1_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI1_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_PHI2_HSCMP (CY_CAPSENSE_CSD_WAVEFORM_PHI2_HSCMP << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
+#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
#define CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBG_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_SHIELD_SEL_SW_HCBG_Pos)
-#define CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_IRLB_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_AMUXBUF_SEL_SW_IRLB_Pos)
-#define CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_IRH_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_AMUXBUF_SEL_SW_IRH_Pos)
-#define CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_ICB_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_AMUXBUF_SEL_SW_ICB_Pos)
-#define CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_DEFAULT (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN)
+#define CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_IRLB_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_AMUXBUF_SEL_SW_IRLB_Pos)
+#define CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_IRH_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_AMUXBUF_SEL_SW_IRH_Pos)
+#define CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_ICB_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_AMUXBUF_SEL_SW_ICB_Pos)
+#define CY_CAPSENSE_CSD_SW_AMUXBUF_SEL_SW_DEFAULT (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN)
/* CSD_SW_BYP_SEL register masks */
-#define CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK (CSD_SW_BYP_SEL_SW_BYA_Msk)
-#define CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYB_MSK (CSD_SW_BYP_SEL_SW_BYB_Msk)
-
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPM_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFPM_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPM_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFPM_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPT_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFPT_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPT_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFPT_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPS_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFPS_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPS_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFPS_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFMA_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFMA_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFMA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFMA_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFCA_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFCA_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFCA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFCA_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFCA_MSK (CSD_SW_CMP_P_SEL_SW_SFCA_Msk)
-
-#define CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_N_SEL_SW_SCRH_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_N_SEL_SW_SCRH_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRL_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_N_SEL_SW_SCRL_Pos)
-#define CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRL_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_N_SEL_SW_SCRL_Pos)
+#define CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYA_MSK (CSD_SW_BYP_SEL_SW_BYA_Msk)
+#define CY_CAPSENSE_CSD_SW_BYP_SEL_SW_BYB_MSK (CSD_SW_BYP_SEL_SW_BYB_Msk)
+
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPM_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFPM_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPM_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFPM_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPT_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFPT_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPT_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFPT_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPS_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFPS_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFPS_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFPS_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFMA_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFMA_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFMA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFMA_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFCA_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_P_SEL_SW_SFCA_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFCA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_P_SEL_SW_SFCA_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_P_SEL_SW_SFCA_MSK (CSD_SW_CMP_P_SEL_SW_SFCA_Msk)
+
+#define CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_N_SEL_SW_SCRH_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_N_SEL_SW_SCRH_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRL_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_SW_CMP_N_SEL_SW_SCRL_Pos)
+#define CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRL_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_CMP_N_SEL_SW_SCRL_Pos)
/* CSD_SW_REFGEN_SEL register masks */
-#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_IAIB_MSK (CSD_SW_REFGEN_SEL_SW_IAIB_Msk)
-#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_IBCB_MSK (CSD_SW_REFGEN_SEL_SW_IBCB_Msk)
-#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGMB_MSK (CSD_SW_REFGEN_SEL_SW_SGMB_Msk)
-#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRP_MSK (CSD_SW_REFGEN_SEL_SW_SGRP_Msk)
-#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRE_MSK (CSD_SW_REFGEN_SEL_SW_SGRE_Msk)
-#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGR_MSK (CSD_SW_REFGEN_SEL_SW_SGR_Msk)
-
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1PM_MSK (CSD_SW_FW_MOD_SEL_SW_F1PM_Msk)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1PM_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_F1PM_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1MA_MSK (CSD_SW_FW_MOD_SEL_SW_F1MA_Msk)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1MA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_F1MA_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1CA_MSK (CSD_SW_FW_MOD_SEL_SW_F1CA_Msk)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1CA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_F1CA_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1CA_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_FW_MOD_SEL_SW_F1CA_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CC_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_C1CC_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CC_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_C1CC_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CD_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_C1CD_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CD_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_C1CD_Pos)
-
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2PT_MSK (CSD_SW_FW_TANK_SEL_SW_F2PT_Msk)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2PT_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_F2PT_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2MA_MSK (CSD_SW_FW_TANK_SEL_SW_F2MA_Msk)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2MA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_F2MA_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CA_MSK (CSD_SW_FW_TANK_SEL_SW_F2CA_Msk)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_F2CA_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CB_MSK (CSD_SW_FW_TANK_SEL_SW_F2CB_Msk)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CB_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_F2CB_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CA_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_FW_TANK_SEL_SW_F2CA_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CB_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_FW_TANK_SEL_SW_F2CB_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CC_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_C2CC_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CC_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_C2CC_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CD_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_C2CD_Pos)
-#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CD_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_C2CD_Pos)
-
-#define CY_CAPSENSE_CSD_TX_OUT_MSK (CSD_IO_SEL_CSD_TX_OUT_Msk)
-#define CY_CAPSENSE_CSD_TX_OUT_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_IO_SEL_CSD_TX_OUT_Pos)
-
-#define CY_CAPSENSE_CSD_TX_OUT_EN_MSK (CSD_IO_SEL_CSD_TX_OUT_EN_Msk)
-#define CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY (CY_CAPSENSE_CSD_WAVEFORM_PHI1_DELAY << 4u)
-#define CY_CAPSENSE_CSD_TX_AMUXB_EN_MSK (CSD_IO_SEL_CSD_TX_AMUXB_EN_Msk)
-#define CY_CAPSENSE_CSD_TX_AMUXB_EN_PHI2_DELAY (CY_CAPSENSE_CSD_WAVEFORM_PHI2_DELAY << 12u)
-#define CY_CAPSENSE_CSD_TX_N_OUT_MSK (CSD_IO_SEL_CSD_TX_N_OUT_Msk)
-#define CY_CAPSENSE_CSD_TX_N_OUT_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_OPEN << CSD_IO_SEL_CSD_TX_N_OUT_Pos)
-#define CY_CAPSENSE_CSD_TX_N_OUT_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_IO_SEL_CSD_TX_N_OUT_Pos)
-#define CY_CAPSENSE_CSD_TX_N_OUT_EN_MSK (CSD_IO_SEL_CSD_TX_N_OUT_EN_Msk)
-#define CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_IO_SEL_CSD_TX_N_OUT_EN_Pos)
-#define CY_CAPSENSE_CSD_TX_N_AMUXA_EN_MSK (CSD_IO_SEL_CSD_TX_N_AMUXA_EN_Msk)
-#define CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_IO_SEL_CSD_TX_N_AMUXA_EN_Pos)
+#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_IAIB_MSK (CSD_SW_REFGEN_SEL_SW_IAIB_Msk)
+#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_IBCB_MSK (CSD_SW_REFGEN_SEL_SW_IBCB_Msk)
+#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGMB_MSK (CSD_SW_REFGEN_SEL_SW_SGMB_Msk)
+#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRP_MSK (CSD_SW_REFGEN_SEL_SW_SGRP_Msk)
+#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRE_MSK (CSD_SW_REFGEN_SEL_SW_SGRE_Msk)
+#define CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGR_MSK (CSD_SW_REFGEN_SEL_SW_SGR_Msk)
+
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1PM_MSK (CSD_SW_FW_MOD_SEL_SW_F1PM_Msk)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1PM_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_F1PM_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1MA_MSK (CSD_SW_FW_MOD_SEL_SW_F1MA_Msk)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1MA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_F1MA_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1CA_MSK (CSD_SW_FW_MOD_SEL_SW_F1CA_Msk)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1CA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_F1CA_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_F1CA_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_FW_MOD_SEL_SW_F1CA_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CC_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_C1CC_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CC_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_C1CC_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CD_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_C1CD_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_MOD_SEL_SW_C1CD_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_MOD_SEL_SW_C1CD_Pos)
+
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2PT_MSK (CSD_SW_FW_TANK_SEL_SW_F2PT_Msk)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2PT_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_F2PT_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2MA_MSK (CSD_SW_FW_TANK_SEL_SW_F2MA_Msk)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2MA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_F2MA_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CA_MSK (CSD_SW_FW_TANK_SEL_SW_F2CA_Msk)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CA_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_F2CA_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CB_MSK (CSD_SW_FW_TANK_SEL_SW_F2CB_Msk)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CB_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_F2CB_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CA_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_FW_TANK_SEL_SW_F2CA_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_F2CB_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_SW_FW_TANK_SEL_SW_F2CB_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CC_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_C2CC_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CC_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_C2CC_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CD_STATIC_OPEN (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_C2CD_Pos)
+#define CY_CAPSENSE_CSD_SW_FW_TANK_SEL_SW_C2CD_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_SW_FW_TANK_SEL_SW_C2CD_Pos)
+
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_CSD_TX_OUT_MSK (0u)
+ #define CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY (0u)
+ #define CY_CAPSENSE_CSD_TX_AMUXB_EN_PHI2_DELAY (0u)
+ #define CY_CAPSENSE_CSD_TX_N_OUT_STATIC_CLOSE (0u)
+ #define CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 (0u)
+ #define CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 (0u)
+#else
+ #define CY_CAPSENSE_CSD_TX_OUT_MSK (CSD_IO_SEL_CSD_TX_OUT_Msk)
+ #define CY_CAPSENSE_CSD_TX_OUT_EN_PHI1_DELAY (CY_CAPSENSE_CSD_WAVEFORM_PHI1_DELAY << 4u)
+ #define CY_CAPSENSE_CSD_TX_AMUXB_EN_PHI2_DELAY (CY_CAPSENSE_CSD_WAVEFORM_PHI2_DELAY << 12u)
+ #define CY_CAPSENSE_CSD_TX_N_OUT_STATIC_CLOSE (CY_CAPSENSE_CSD_WAVEFORM_STATIC_CLOSED << CSD_IO_SEL_CSD_TX_N_OUT_Pos)
+ #define CY_CAPSENSE_CSD_TX_N_OUT_EN_PHI1 (CY_CAPSENSE_CSD_WAVEFORM_PHI1 << CSD_IO_SEL_CSD_TX_N_OUT_EN_Pos)
+ #define CY_CAPSENSE_CSD_TX_N_AMUXA_EN_PHI2 (CY_CAPSENSE_CSD_WAVEFORM_PHI2 << CSD_IO_SEL_CSD_TX_N_AMUXA_EN_Pos)
+#endif
/* CSD_SEQ_INIT_CNT register masks */
-#define CY_CAPSENSE_CSD_SEQ_INIT_CNT_CONV_CNT_MSK (CSD_SEQ_INIT_CNT_CONV_CNT_Msk)
+#define CY_CAPSENSE_CSD_SEQ_INIT_CNT_CONV_CNT_MSK (CSD_SEQ_INIT_CNT_CONV_CNT_Msk)
/* CSD_SEQ_NORM_CNT register masks */
-#define CY_CAPSENSE_CSD_SEQ_NORM_CNT_CONV_CNT_MSK (CSD_SEQ_NORM_CNT_CONV_CNT_Msk)
+#define CY_CAPSENSE_CSD_SEQ_NORM_CNT_CONV_CNT_MSK (CSD_SEQ_NORM_CNT_CONV_CNT_Msk)
/* CSD_SEQ_START register masks */
-#define CY_CAPSENSE_CSD_SEQ_START_START_MSK (CSD_SEQ_START_START_Msk)
-#define CY_CAPSENSE_CSD_SEQ_START_SEQ_MODE_MSK (CSD_SEQ_START_SEQ_MODE_Msk)
-#define CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK (CSD_SEQ_START_ABORT_Msk)
-#define CY_CAPSENSE_CSD_SEQ_START_DSI_START_EN_MSK (CSD_SEQ_START_DSI_START_EN_Msk)
-#define CY_CAPSENSE_CSD_SEQ_START_AZ0_SKIP_MSK (CSD_SEQ_START_AZ0_SKIP_Msk)
-#define CY_CAPSENSE_CSD_SEQ_START_AZ1_SKIP_MSK (CSD_SEQ_START_AZ1_SKIP_Msk)
+#define CY_CAPSENSE_CSD_SEQ_START_START_MSK (CSD_SEQ_START_START_Msk)
+#define CY_CAPSENSE_CSD_SEQ_START_SEQ_MODE_MSK (CSD_SEQ_START_SEQ_MODE_Msk)
+#define CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK (CSD_SEQ_START_ABORT_Msk)
+#define CY_CAPSENSE_CSD_SEQ_START_DSI_START_EN_MSK (CSD_SEQ_START_DSI_START_EN_Msk)
+#define CY_CAPSENSE_CSD_SEQ_START_AZ0_SKIP_MSK (CSD_SEQ_START_AZ0_SKIP_Msk)
+#define CY_CAPSENSE_CSD_SEQ_START_AZ1_SKIP_MSK (CSD_SEQ_START_AZ1_SKIP_Msk)
-#define CY_CAPSENSE_CSD_IDAC_BITS_USED (7u)
+#define CY_CAPSENSE_CSD_IDAC_BITS_USED (7u)
-#define CY_CAPSENSE_CAL_MIDDLE_VALUE (1u << (CY_CAPSENSE_CSD_IDAC_BITS_USED - 1u))
-#define CY_CAPSENSE_CAL_IDAC_MAX_VALUE ((uint8_t)(1u << CY_CAPSENSE_CSD_IDAC_BITS_USED) - 1u)
+#define CY_CAPSENSE_CAL_MIDDLE_VALUE (1u << (CY_CAPSENSE_CSD_IDAC_BITS_USED - 1u))
+#define CY_CAPSENSE_CAL_IDAC_MAX_VALUE ((uint8_t)(1u << CY_CAPSENSE_CSD_IDAC_BITS_USED) - 1u)
/* CSD_IDACA register masks */
-#define CY_CAPSENSE_CSD_IDACA_VAL_MSK (CSD_IDACA_VAL_Msk)
-#define CY_CAPSENSE_CSD_IDACA_VAL_POS (CSD_IDACA_VAL_Pos)
-
-#define CY_CAPSENSE_CSD_IDACA_POL_DYN_MSK (CSD_IDACA_POL_DYN_Msk)
-#define CY_CAPSENSE_CSD_IDACA_POL_DYN_POS (CSD_IDACA_POL_DYN_Pos)
-
-#define CY_CAPSENSE_CSD_IDACA_POLARITY_MSK (CSD_IDACA_POLARITY_Msk)
-#define CY_CAPSENSE_CSD_IDACA_POLARITY_POS (CSD_IDACA_POLARITY_Pos)
-#define CY_CAPSENSE_CSD_IDACA_POLARITY_VSSA_SRC (0uL)
-#define CY_CAPSENSE_CSD_IDACA_POLARITY_VDDA_SNK (1uL)
-#define CY_CAPSENSE_CSD_IDACA_POLARITY_SENSE (2uL)
-#define CY_CAPSENSE_CSD_IDACA_POLARITY_SENSE_INV (3uL)
-
-#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_MSK (CSD_IDACA_BAL_MODE_Msk)
-#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_POS (CSD_IDACA_BAL_MODE_Pos)
-#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_FULL (0uL)
-#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_PHI1 (1uL)
-#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_PHI2 (2uL)
-#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_PHI1_2 (3uL)
-
-#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_MSK (CSD_IDACA_LEG1_MODE_Msk)
-#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_POS (CSD_IDACA_LEG1_MODE_Pos)
-#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_GP_STATIC (0uL)
-#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_GP (1uL)
-#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_CSD_STATIC (2uL)
-#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_CSD (3uL)
-
-#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_MSK (CSD_IDACA_LEG2_MODE_Msk)
-#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_POS (CSD_IDACA_LEG2_MODE_Pos)
-#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_GP_STATIC (0uL)
-#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_GP (1uL)
-#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_CSD_STATIC (2uL)
-#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_CSD (3uL)
-
-#define CY_CAPSENSE_CSD_IDACA_RANGE_MSK (CSD_IDACA_RANGE_Msk)
-#define CY_CAPSENSE_CSD_IDACA_RANGE_POS (CSD_IDACA_RANGE_Pos)
-#define CY_CAPSENSE_CSD_IDACA_RANGE_IDAC_LO (0uL)
-#define CY_CAPSENSE_CSD_IDACA_RANGE_IDAC_MED (1uL)
-#define CY_CAPSENSE_CSD_IDACA_RANGE_IDAC_HI (2uL)
-
-#define CY_CAPSENSE_CSD_IDACA_LEG1_EN_MSK (CSD_IDACA_LEG1_EN_Msk)
-#define CY_CAPSENSE_CSD_IDACA_LEG2_EN_MSK (CSD_IDACA_LEG2_EN_Msk)
+#define CY_CAPSENSE_CSD_IDACA_VAL_MSK (CSD_IDACA_VAL_Msk)
+#define CY_CAPSENSE_CSD_IDACA_VAL_POS (CSD_IDACA_VAL_Pos)
+
+#define CY_CAPSENSE_CSD_IDACA_POL_DYN_MSK (CSD_IDACA_POL_DYN_Msk)
+#define CY_CAPSENSE_CSD_IDACA_POL_DYN_POS (CSD_IDACA_POL_DYN_Pos)
+
+#define CY_CAPSENSE_CSD_IDACA_POLARITY_MSK (CSD_IDACA_POLARITY_Msk)
+#define CY_CAPSENSE_CSD_IDACA_POLARITY_POS (CSD_IDACA_POLARITY_Pos)
+#define CY_CAPSENSE_CSD_IDACA_POLARITY_VSSA_SRC (0uL)
+#define CY_CAPSENSE_CSD_IDACA_POLARITY_VDDA_SNK (1uL)
+#define CY_CAPSENSE_CSD_IDACA_POLARITY_SENSE (2uL)
+#define CY_CAPSENSE_CSD_IDACA_POLARITY_SENSE_INV (3uL)
+
+#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_MSK (CSD_IDACA_BAL_MODE_Msk)
+#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_POS (CSD_IDACA_BAL_MODE_Pos)
+#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_FULL (0uL)
+#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_PHI1 (1uL)
+#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_PHI2 (2uL)
+#define CY_CAPSENSE_CSD_IDACA_BALL_MODE_PHI1_2 (3uL)
+
+#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_MSK (CSD_IDACA_LEG1_MODE_Msk)
+#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_POS (CSD_IDACA_LEG1_MODE_Pos)
+#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_GP_STATIC (0uL)
+#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_GP (1uL)
+#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_CSD_STATIC (2uL)
+#define CY_CAPSENSE_CSD_IDACA_LEG1_MODE_CSD (3uL)
+
+#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_MSK (CSD_IDACA_LEG2_MODE_Msk)
+#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_POS (CSD_IDACA_LEG2_MODE_Pos)
+#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_GP_STATIC (0uL)
+#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_GP (1uL)
+#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_CSD_STATIC (2uL)
+#define CY_CAPSENSE_CSD_IDACA_LEG2_MODE_CSD (3uL)
+
+#define CY_CAPSENSE_CSD_IDACA_RANGE_MSK (CSD_IDACA_RANGE_Msk)
+#define CY_CAPSENSE_CSD_IDACA_RANGE_POS (CSD_IDACA_RANGE_Pos)
+#define CY_CAPSENSE_CSD_IDACA_RANGE_IDAC_LO (0uL)
+#define CY_CAPSENSE_CSD_IDACA_RANGE_IDAC_MED (1uL)
+#define CY_CAPSENSE_CSD_IDACA_RANGE_IDAC_HI (2uL)
+
+#define CY_CAPSENSE_CSD_IDACA_LEG1_EN_MSK (CSD_IDACA_LEG1_EN_Msk)
+#define CY_CAPSENSE_CSD_IDACA_LEG2_EN_MSK (CSD_IDACA_LEG2_EN_Msk)
/* CSD_IDACB register masks */
#define CY_CAPSENSE_CSD_IDACB_VAL_MSK (CSD_IDACB_VAL_Msk)
#define CY_CAPSENSE_CSD_IDACB_VAL_POS (CSD_IDACB_VAL_Pos)
-#define CY_CAPSENSE_CSD_IDACB_POL_DYN_MSK (CSD_IDACB_POL_DYN_Msk)
-#define CY_CAPSENSE_CSD_IDACB_POL_DYN_POS (CSD_IDACB_POL_DYN_Pos)
-#define CY_CAPSENSE_CSD_IDACB_POL_DYN_STATIC (0uL)
-#define CY_CAPSENSE_CSD_IDACB_POL_DYN_DYNAMIC (1uL)
-
-#define CY_CAPSENSE_CSD_IDACB_POLARITY_MSK (CSD_IDACB_POLARITY_Msk)
-#define CY_CAPSENSE_CSD_IDACB_POLARITY_POS (CSD_IDACB_POLARITY_Pos)
-#define CY_CAPSENSE_CSD_IDACB_POLARITY_VSSA_SRC (0uL)
-#define CY_CAPSENSE_CSD_IDACB_POLARITY_VDDA_SNK (1uL)
-#define CY_CAPSENSE_CSD_IDACB_POLARITY_SENSE (2uL)
-#define CY_CAPSENSE_CSD_IDACB_POLARITY_SENSE_INV (3uL)
-
-#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_MSK (CSD_IDACB_BAL_MODE_Msk)
-#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_POS (CSD_IDACB_BAL_MODE_Pos)
-#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_FULL (0uL)
-#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_PHI1 (1uL)
-#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_PHI2 (2uL)
-#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_PHI1_2 (3uL)
-
-#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_MSK (CSD_IDACB_LEG1_MODE_Msk)
-#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_POS (CSD_IDACB_LEG1_MODE_Pos)
-#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_GP_STATIC (0uL)
-#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_GP (1uL)
-#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_CSD_STATIC (2uL)
-#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_CSD (3uL)
-
-#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_MSK (CSD_IDACB_LEG2_MODE_Msk)
-#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_POS (CSD_IDACB_LEG2_MODE_Pos)
-#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_GP_STATIC (0uL)
-#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_GP (1uL)
-#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_CSD_STATIC (2uL)
-#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_CSD (3uL)
-
-#define CY_CAPSENSE_CSD_IDACB_RANGE_MSK (CSD_IDACB_RANGE_Msk)
-#define CY_CAPSENSE_CSD_IDACB_RANGE_POS (CSD_IDACB_RANGE_Pos)
-#define CY_CAPSENSE_CSD_IDACB_RANGE_IDAC_LO (0uL)
-#define CY_CAPSENSE_CSD_IDACB_RANGE_IDAC_MED (1uL)
-#define CY_CAPSENSE_CSD_IDACB_RANGE_IDAC_HI (2uL)
-
-#define CY_CAPSENSE_CSD_IDACB_LEG1_EN_MSK (CSD_IDACB_LEG1_EN_Msk)
-#define CY_CAPSENSE_CSD_IDACB_LEG2_EN_MSK (CSD_IDACB_LEG2_EN_Msk)
-#define CY_CAPSENSE_CSD_IDACB_LEG3_EN_MSK (CSD_IDACB_LEG3_EN_Msk)
+#define CY_CAPSENSE_CSD_IDACB_POL_DYN_MSK (CSD_IDACB_POL_DYN_Msk)
+#define CY_CAPSENSE_CSD_IDACB_POL_DYN_POS (CSD_IDACB_POL_DYN_Pos)
+#define CY_CAPSENSE_CSD_IDACB_POL_DYN_STATIC (0uL)
+#define CY_CAPSENSE_CSD_IDACB_POL_DYN_DYNAMIC (1uL)
+
+#define CY_CAPSENSE_CSD_IDACB_POLARITY_MSK (CSD_IDACB_POLARITY_Msk)
+#define CY_CAPSENSE_CSD_IDACB_POLARITY_POS (CSD_IDACB_POLARITY_Pos)
+#define CY_CAPSENSE_CSD_IDACB_POLARITY_VSSA_SRC (0uL)
+#define CY_CAPSENSE_CSD_IDACB_POLARITY_VDDA_SNK (1uL)
+#define CY_CAPSENSE_CSD_IDACB_POLARITY_SENSE (2uL)
+#define CY_CAPSENSE_CSD_IDACB_POLARITY_SENSE_INV (3uL)
+
+#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_MSK (CSD_IDACB_BAL_MODE_Msk)
+#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_POS (CSD_IDACB_BAL_MODE_Pos)
+#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_FULL (0uL)
+#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_PHI1 (1uL)
+#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_PHI2 (2uL)
+#define CY_CAPSENSE_CSD_IDACB_BALL_MODE_PHI1_2 (3uL)
+
+#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_MSK (CSD_IDACB_LEG1_MODE_Msk)
+#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_POS (CSD_IDACB_LEG1_MODE_Pos)
+#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_GP_STATIC (0uL)
+#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_GP (1uL)
+#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_CSD_STATIC (2uL)
+#define CY_CAPSENSE_CSD_IDACB_LEG1_MODE_CSD (3uL)
+
+#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_MSK (CSD_IDACB_LEG2_MODE_Msk)
+#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_POS (CSD_IDACB_LEG2_MODE_Pos)
+#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_GP_STATIC (0uL)
+#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_GP (1uL)
+#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_CSD_STATIC (2uL)
+#define CY_CAPSENSE_CSD_IDACB_LEG2_MODE_CSD (3uL)
+
+#define CY_CAPSENSE_CSD_IDACB_RANGE_MSK (CSD_IDACB_RANGE_Msk)
+#define CY_CAPSENSE_CSD_IDACB_RANGE_POS (CSD_IDACB_RANGE_Pos)
+#define CY_CAPSENSE_CSD_IDACB_RANGE_IDAC_LO (0uL)
+#define CY_CAPSENSE_CSD_IDACB_RANGE_IDAC_MED (1uL)
+#define CY_CAPSENSE_CSD_IDACB_RANGE_IDAC_HI (2uL)
+
+#define CY_CAPSENSE_CSD_IDACB_LEG1_EN_MSK (CSD_IDACB_LEG1_EN_Msk)
+#define CY_CAPSENSE_CSD_IDACB_LEG2_EN_MSK (CSD_IDACB_LEG2_EN_Msk)
+#define CY_CAPSENSE_CSD_IDACB_LEG3_EN_MSK (CSD_IDACB_LEG3_EN_Msk)
/*******************************************************************************
* PRS & LFSR masks
@@ -542,13 +564,27 @@ extern const cy_stc_csd_config_t cy_capsense_csdCfg;
#define CY_CAPSENSE_SNSCLK_LFSR_THRESHOLD (CY_CAPSENSE_LFSR_DITHER_PERCENTAGE * CY_CAPSENSE_SNSCLK_LFSR_RANGE)
/*******************************************************************************
-* HSIOM Macros redefinition for readability
+* HSIOM and PC Macros redefinition platform dependent and for readability
*******************************************************************************/
-#define CY_CAPSENSE_HSIOM_SEL_GPIO (HSIOM_SEL_GPIO)
-#define CY_CAPSENSE_HSIOM_SEL_CSD_SENSE (HSIOM_SEL_ACT_3)
-#define CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD (HSIOM_SEL_ACT_2)
-#define CY_CAPSENSE_HSIOM_SEL_AMUXA (HSIOM_SEL_AMUXA)
-#define CY_CAPSENSE_HSIOM_SEL_AMUXB (HSIOM_SEL_AMUXB)
+#if (CY_CAPSENSE_PSOC4_CSDV2)
+ #define CY_CAPSENSE_HSIOM_SEL_GPIO (HSIOM_SEL_GPIO)
+ #define CY_CAPSENSE_HSIOM_SEL_CSD_SENSE (HSIOM_SEL_CSD_SENSE)
+ #define CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD (HSIOM_SEL_CSD_SHIELD)
+ #define CY_CAPSENSE_HSIOM_SEL_AMUXA (HSIOM_SEL_AMUXA)
+ #define CY_CAPSENSE_HSIOM_SEL_AMUXB (HSIOM_SEL_AMUXB)
+ #define CY_CAPSENSE_CSD_SCAN_PIN_DM (CY_GPIO_DM_ANALOG)
+ #define CY_CAPSENSE_CSX_TX_SCAN_PIN_HSIOM (HSIOM_SEL_CSD_SENSE)
+ #define CY_CAPSENSE_CSX_CINT_SCAN_PIN_HSIOM (HSIOM_SEL_AMUXA)
+#else
+ #define CY_CAPSENSE_HSIOM_SEL_GPIO (HSIOM_SEL_GPIO)
+ #define CY_CAPSENSE_HSIOM_SEL_CSD_SENSE (HSIOM_SEL_ACT_3)
+ #define CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD (HSIOM_SEL_ACT_2)
+ #define CY_CAPSENSE_HSIOM_SEL_AMUXA (HSIOM_SEL_AMUXA)
+ #define CY_CAPSENSE_HSIOM_SEL_AMUXB (HSIOM_SEL_AMUXB)
+ #define CY_CAPSENSE_CSD_SCAN_PIN_DM (CY_GPIO_DM_STRONG_IN_OFF)
+ #define CY_CAPSENSE_CSX_TX_SCAN_PIN_HSIOM (HSIOM_SEL_ACT_2)
+ #define CY_CAPSENSE_CSX_CINT_SCAN_PIN_HSIOM (HSIOM_SEL_GPIO)
+#endif
/*******************************************************************************
* Clock Macros
@@ -568,7 +604,7 @@ extern const cy_stc_csd_config_t cy_capsense_csdCfg;
#define CY_CAPSENSE_PERI_CLK_KHZ (50000000U / 1000U)
#define CY_CAPSENSE_PERI_CLK_MHZ (CY_CAPSENSE_PERI_CLK_KHZ / 1000U)
-
+
#define CY_CAPSENSE_CPU_CLK_KHZ (50000000U / 1000U)
#define CY_CAPSENSE_CPU_CLK_MHZ (CY_CAPSENSE_CPU_CLK_KHZ / 1000U)
diff --git a/cy_capsense_structure.c b/cy_capsense_structure.c
index f47d0a0..cff4864 100644
--- a/cy_capsense_structure.c
+++ b/cy_capsense_structure.c
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_structure.c
-* \version 2.0
+* \version 2.10
*
* \brief
* This file defines the data structure global variables and provides the
@@ -8,7 +8,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -18,12 +18,29 @@
#include
#include
#include "cy_syslib.h"
+#include "cy_utils.h"
#include "cy_capsense_common.h"
#include "cy_capsense_structure.h"
+#include "cy_capsense_selftest.h"
#include "cy_capsense_lib.h"
#include "cy_csd.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
+
+/*******************************************************************************
+* Local definition
+*******************************************************************************/
+#define CY_CAPSENSE_DS_PARAM_TYPE_UINT8 (1u)
+#define CY_CAPSENSE_DS_PARAM_TYPE_UINT16 (2u)
+#define CY_CAPSENSE_DS_PARAM_TYPE_UINT32 (3u)
+#define CY_CAPSENSE_UINT16_ALIGN_MASK (1u)
+#define CY_CAPSENSE_UINT32_ALIGN_MASK (3u)
+#define CY_CAPSENSE_PARAM_TYPE_OFFSET (24u)
+#define CY_CAPSENSE_PARAM_TYPE_MASK (3uL << CY_CAPSENSE_PARAM_TYPE_OFFSET)
+#define CY_CAPSENSE_PARAM_CRC_OFFSET (26u)
+#define CY_CAPSENSE_PARAM_CRC_MASK (1uL << CY_CAPSENSE_PARAM_CRC_OFFSET)
+#define CY_CAPSENSE_PARAM_WIDGET_OFFSET (16u)
+#define CY_CAPSENSE_PARAM_WIDGET_MASK (0xFFuL << CY_CAPSENSE_PARAM_WIDGET_OFFSET)
/*******************************************************************************
@@ -33,8 +50,8 @@
* Reports whether any widget has detected touch.
*
* This function reports whether any widget has detected a touch by extracting
-* information from the widget status registers. This function does
-* not process widget data but extracts previously processed results
+* information from the widget status registers. This function does
+* not process widget data but extracts previously processed results
* from the \ref group_capsense_structures.
*
* \param context
@@ -68,11 +85,11 @@ uint32_t Cy_CapSense_IsAnyWidgetActive(const cy_stc_capsense_context_t * context
*
* This function reports whether the specified widget has detected a touch by
* extracting information from the widget status register.
-* This function does not process widget data but extracts previously processed
+* This function does not process widget data but extracts previously processed
* results from the \ref group_capsense_structures.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param context
@@ -87,7 +104,7 @@ uint32_t Cy_CapSense_IsAnyWidgetActive(const cy_stc_capsense_context_t * context
*
*******************************************************************************/
uint32_t Cy_CapSense_IsWidgetActive(
- uint32_t widgetId,
+ uint32_t widgetId,
const cy_stc_capsense_context_t * context)
{
uint32_t result = 0uL;
@@ -108,20 +125,20 @@ uint32_t Cy_CapSense_IsWidgetActive(
*
* This function reports whether the specified sensor in the widget has detected a
* touch by extracting information from the widget status register.
-* This function does not process widget or sensor data but extracts previously
+* This function does not process widget or sensor data but extracts previously
* processed results from the \ref group_capsense_structures.
*
-* For proximity sensors, this function returns the proximity detection status.
+* For proximity sensors, this function returns the proximity detection status.
* To get the touch status of proximity sensors, use the
* Cy_CapSense_IsProximitySensorActive() function.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
-*
+*
* \param sensorId
-* Specifies the ID number of the sensor within the widget. A macro for the
-* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE__SNS_ID.
*
* \param context
@@ -137,8 +154,8 @@ uint32_t Cy_CapSense_IsWidgetActive(
*
*******************************************************************************/
uint32_t Cy_CapSense_IsSensorActive(
- uint32_t widgetId,
- uint32_t sensorId,
+ uint32_t widgetId,
+ uint32_t sensorId,
const cy_stc_capsense_context_t * context)
{
uint32_t result = 0uL;
@@ -160,19 +177,19 @@ uint32_t Cy_CapSense_IsSensorActive(
*
* Reports the status of the specified proximity widget/sensor.
*
-* This function reports whether the specified proximity sensor has detected
-* a touch or proximity event by extracting information from the widget
-* status register. This function is used only with proximity widgets.
-* This function does not process widget data but extracts previously processed
+* This function reports whether the specified proximity sensor has detected
+* a touch or proximity event by extracting information from the widget
+* status register. This function is used only with proximity widgets.
+* This function does not process widget data but extracts previously processed
* results from the \ref group_capsense_structures.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param sensorId
-* Specifies the ID number of the sensor within the widget. A macro for the
-* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
* file defined as CY_CAPSENSE__SNS_ID.
*
* \param context
@@ -188,8 +205,8 @@ uint32_t Cy_CapSense_IsSensorActive(
*
*******************************************************************************/
uint32_t Cy_CapSense_IsProximitySensorActive(
- uint32_t widgetId,
- uint32_t sensorId,
+ uint32_t widgetId,
+ uint32_t sensorId,
const cy_stc_capsense_context_t * context)
{
uint32_t result = 0uL;
@@ -204,7 +221,7 @@ uint32_t Cy_CapSense_IsProximitySensorActive(
}
}
}
-
+
return result;
}
@@ -213,31 +230,31 @@ uint32_t Cy_CapSense_IsProximitySensorActive(
* Function Name: Cy_CapSense_GetTouchInfo
****************************************************************************//**
*
-* Reports the details of touch position detected on the specified touchpad,
+* Reports the details of touch position detected on the specified touchpad,
* matrix buttons or slider widgets.
*
-* This function does not process widget data but extracts previously processed
+* This function does not process widget data but extracts previously processed
* results from the \ref group_capsense_structures.
*
* \param widgetId
-* Specifies the ID number of the widget. A macro for the widget ID can be found
+* Specifies the ID number of the widget. A macro for the widget ID can be found
* in the cycfg_capsense.h file defined as CY_CAPSENSE__WDGT_ID.
*
* \param context
* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
*
* \return
-* Returns the pointer to widget cy_stc_capsense_touch_t structure that
+* Returns the pointer to widget cy_stc_capsense_touch_t structure that
* contains number of positions and data about each position.
-*
+*
*
*******************************************************************************/
cy_stc_capsense_touch_t * Cy_CapSense_GetTouchInfo(
- uint32_t widgetId,
+ uint32_t widgetId,
const cy_stc_capsense_context_t * context)
{
cy_stc_capsense_touch_t * ptrTouch = NULL;
-
+
const cy_stc_capsense_widget_config_t * ptrWdCfg;
if (widgetId < context->ptrCommonConfig->numWd)
@@ -255,7 +272,7 @@ cy_stc_capsense_touch_t * Cy_CapSense_GetTouchInfo(
break;
}
}
-
+
return ptrTouch;
}
@@ -278,7 +295,7 @@ cy_stc_capsense_touch_t * Cy_CapSense_GetTouchInfo(
cy_status Cy_CapSense_CheckConfigIntegrity(const cy_stc_capsense_context_t * context)
{
cy_status result = CY_RET_SUCCESS;
-
+
const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig;
const cy_stc_capsense_common_context_t * ptrCommonCxt = context->ptrCommonContext;
const cy_stc_capsense_internal_context_t * ptrInternalCxt = context->ptrInternalContext;
@@ -287,34 +304,178 @@ cy_status Cy_CapSense_CheckConfigIntegrity(const cy_stc_capsense_context_t * con
const cy_stc_capsense_pin_config_t * ptrPinCfg = context->ptrPinConfig;
const cy_stc_capsense_pin_config_t * ptrShieldPinCfg = context->ptrShieldPinConfig;
const cy_stc_active_scan_sns_t * ptrActScanSns = context->ptrActiveScanSns;
-
- if (ptrCommonCfg == NULL) {result |= CY_RET_BAD_DATA;}
- if (ptrCommonCxt == NULL) {result |= CY_RET_BAD_DATA;}
- if (ptrInternalCxt == NULL) {result |= CY_RET_BAD_DATA;}
- if (ptrWdCfg == NULL) {result |= CY_RET_BAD_DATA;}
- if (ptrWdCxt == NULL) {result |= CY_RET_BAD_DATA;}
- if (ptrPinCfg == NULL) {result |= CY_RET_BAD_DATA;}
- if (ptrCommonCfg->csdShieldEn != 0u)
+
+ if (ptrCommonCfg == NULL) {result = CY_RET_BAD_DATA;}
+ if (ptrCommonCxt == NULL) {result = CY_RET_BAD_DATA;}
+ if (ptrInternalCxt == NULL) {result = CY_RET_BAD_DATA;}
+ if (ptrWdCfg == NULL) {result = CY_RET_BAD_DATA;}
+ if (ptrWdCxt == NULL) {result = CY_RET_BAD_DATA;}
+ if (ptrPinCfg == NULL) {result = CY_RET_BAD_DATA;}
+ if (ptrActScanSns == NULL) {result = CY_RET_BAD_DATA;}
+
+ if(CY_RET_SUCCESS == result)
{
- if((ptrCommonCfg->csdShieldNumPin > 0u) && (ptrShieldPinCfg == NULL))
+ if (ptrCommonCfg->csdShieldEn != 0u)
+ {
+ if((ptrCommonCfg->csdShieldNumPin > 0u) && (ptrShieldPinCfg == NULL))
+ {
+ result = CY_RET_BAD_DATA;
+ }
+ }
+
+ if (ptrCommonCfg->bistEn != 0u)
{
- result |= CY_RET_BAD_DATA;
+ if(context->ptrBistContext == NULL)
+ {
+ result = CY_RET_BAD_DATA;
+ }
}
}
- if (ptrActScanSns == NULL) {result |= CY_RET_BAD_DATA;}
-
-
+
return (result);
}
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GetCRC
+****************************************************************************//**
+*
+* Calculates CRC for the specified buffer and length.
+*
+* This API is used for the CRC protection of a packet received from
+* the CapSense Tuner tool and for BIST operations.
+* CRC polynomial is 0xAC9A. It has a Hamming distance 5 for data words
+* up to 241 bits.
+*
+* Reference: "P. Koopman, T. Chakravarthy,
+* "Cyclic Redundancy Code (CRC) Polynomial Selection for Embedded Networks",
+* The International Conference on Dependable Systems and Networks, DSN-2004"
+*
+* \param ptrData
+* The pointer to the data.
+*
+* \param len
+* The length of the data in bytes.
+*
+* \return
+* Returns a calculated CRC-16 value.
+*
+*******************************************************************************/
+uint16_t Cy_CapSense_GetCRC(const uint8_t *ptrData, uint32_t len)
+{
+ uint32_t idx;
+ uint32_t actualCrc = 0u;
+ const uint16_t crcTable[] =
+ {
+ 0x0000u, 0xAC9Au, 0xF5AEu, 0x5934u, 0x47C6u, 0xEB5Cu, 0xB268u, 0x1EF2u,
+ 0x8F8Cu, 0x2316u, 0x7A22u, 0xD6B8u, 0xC84Au, 0x64D0u, 0x3DE4u, 0x917Eu
+ };
+
+ for (;len-- > 0u;)
+ {
+ /* Process HI Nibble */
+ idx = ((actualCrc >> 12u) ^ (((uint32_t)*ptrData) >> 4u)) & 0xFLu;
+ actualCrc = crcTable[idx] ^ (actualCrc << 4u);
+
+ /* Process LO Nibble */
+ idx = ((actualCrc >> 12u) ^ (uint32_t)*ptrData) & 0xFLu;
+ actualCrc = crcTable[idx] ^ (actualCrc << 4u);
+
+ ptrData++;
+ }
+
+ return (uint16_t)actualCrc;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GetCrcWidget
+****************************************************************************//**
+*
+* Calculates CRC for the specified widget. This function implements the
+* following functionality:
+* - Fills the \ref cy_stc_capsense_widget_crc_data_t with 0.
+* - Initializes fields of the \ref cy_stc_capsense_widget_crc_data_t with the
+* data from corresponding fields of the \ref cy_stc_capsense_widget_context_t.
+* - Executes the Cy_CapSense_GetCRC() routine for full
+* \ref cy_stc_capsense_widget_crc_data_t, structure, including padding.
+* If the CSD tuning mode is set to SmartSense (Full Auto-Tune) then the fields
+* of the \ref cy_stc_capsense_widget_context_t that changing it's value in the
+* run-time will be excluded from CRC calculation for the CSD widgets.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CapSense Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE__WDGT_ID.
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a calculated CRC-16 value.
+*
+*******************************************************************************/
+uint16_t Cy_CapSense_GetCrcWidget(
+ uint32_t widgetId,
+ cy_stc_capsense_context_t * context)
+{
+ uint16_t crcValue;
+ cy_stc_capsense_widget_context_t * ptrWdCxt;
+ const cy_stc_capsense_widget_config_t * ptrWdCfg;
+ cy_stc_capsense_widget_crc_data_t crcDataVal;
+
+ /* Get a pointer to the specified widget config structure */
+ ptrWdCfg = &context->ptrWdConfig[widgetId];
+
+ /* Get a pointer to the specified widget context structure */
+ ptrWdCxt = &context->ptrWdContext[widgetId];
+
+ (void)memset((void*)&crcDataVal, 0, sizeof(crcDataVal));
+
+ crcDataVal.fingerCapVal = ptrWdCxt->fingerCap;
+ crcDataVal.sigPFCVal = ptrWdCxt->sigPFC;
+ crcDataVal.resolutionVal = ptrWdCxt->resolution;
+ crcDataVal.lowBslnRstVal = ptrWdCxt->lowBslnRst;
+ crcDataVal.snsClkVal = ptrWdCxt->snsClk;
+ crcDataVal.rowSnsClkVal = ptrWdCxt->rowSnsClk;
+ crcDataVal.onDebounceVal = ptrWdCxt->onDebounce;
+ crcDataVal.snsClkSourceVal = ptrWdCxt->snsClkSource;
+ crcDataVal.idacModVal[0u] = ptrWdCxt->idacMod[0u];
+ crcDataVal.idacModVal[1u] = ptrWdCxt->idacMod[1u];
+ crcDataVal.idacModVal[2u] = ptrWdCxt->idacMod[2u];
+ crcDataVal.idacGainIndexVal = ptrWdCxt->idacGainIndex;
+ crcDataVal.rowIdacModVal[0u] = ptrWdCxt->rowIdacMod[0u];
+ crcDataVal.rowIdacModVal[1u] = ptrWdCxt->rowIdacMod[1u];
+ crcDataVal.rowIdacModVal[2u] = ptrWdCxt->rowIdacMod[2u];
+
+
+ if(((uint8_t)CY_CAPSENSE_SENSE_METHOD_CSX_E == ptrWdCfg->senseMethod) ||
+ (CY_CAPSENSE_CSD_SS_DIS == context->ptrCommonConfig->csdAutotuneEn))
+ {
+ crcDataVal.fingerThVal = ptrWdCxt->fingerTh;
+ crcDataVal.proxThVal = ptrWdCxt->proxTh;
+ crcDataVal.noiseThVal = ptrWdCxt->noiseTh;
+ crcDataVal.nNoiseThVal = ptrWdCxt->nNoiseTh;
+ crcDataVal.hysteresisVal = ptrWdCxt->hysteresis;
+
+ }
+
+ crcValue = Cy_CapSense_GetCRC((uint8_t *)(&crcDataVal), sizeof(crcDataVal));
+
+ return (crcValue);
+}
+
+
/**< Internal wrapper functions for the flash optimization */
/*******************************************************************************
* Function Name: Cy_CapSense_CSDCalibrateWidget_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CSDCalibrateWidget function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CSDCalibrateWidget() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CSDCalibrateWidget().
*
* \param widgetId
@@ -343,8 +504,10 @@ cy_status Cy_CapSense_CSDCalibrateWidget_Call(
* Function Name: Cy_CapSense_CSDSetupWidget_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CSDSetupWidget function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CSDSetupWidget() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
*
* For the operation details, refer to the Cy_CapSense_CSDSetupWidget().
*
@@ -369,9 +532,10 @@ void Cy_CapSense_CSDSetupWidget_Call(
* Function Name: Cy_CapSense_CSDScan_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CSDScan function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CSDScan() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CSDScan().
*
* \param context
@@ -393,9 +557,10 @@ void Cy_CapSense_CSDScan_Call(
* Function Name: Cy_CapSense_CSXSetupWidget_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CSXSetupWidget function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CSXSetupWidget() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CSXSetupWidget().
*
* \param widgetId
@@ -419,9 +584,10 @@ void Cy_CapSense_CSXSetupWidget_Call(
* Function Name: Cy_CapSense_CSXScan_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CSXScan function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CSXScan() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CSXScan().
*
* \param context
@@ -443,9 +609,10 @@ void Cy_CapSense_CSXScan_Call(
* Function Name: Cy_CapSense_CalibrateAllCsdWidgets_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CalibrateAllCsdWidgets function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CalibrateAllCsdWidgets() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CalibrateAllCsdWidgets().
*
* \param context
@@ -470,9 +637,10 @@ cy_status Cy_CapSense_CalibrateAllCsdWidgets_Call(
* Function Name: Cy_CapSense_CalibrateAllCsxWidgets_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CalibrateAllCsxWidgets function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CalibrateAllCsxWidgets() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CalibrateAllCsxWidgets().
*
* \param context
@@ -497,9 +665,10 @@ cy_status Cy_CapSense_CalibrateAllCsxWidgets_Call(
* Function Name: Cy_CapSense_CSDDisableMode_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CSDDisableMode function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CSDDisableMode() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CSDDisableMode().
*
* \param context
@@ -521,9 +690,10 @@ void Cy_CapSense_CSDDisableMode_Call(
* Function Name: Cy_CapSense_CSDInitialize_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CSDInitialize function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CSDInitialize() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CSDInitialize().
*
* \param context
@@ -545,9 +715,10 @@ void Cy_CapSense_CSDInitialize_Call(
* Function Name: Cy_CapSense_DpProcessButton_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_DpProcessButton function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_DpProcessButton() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_DpProcessButton().
*
* \param ptrWdConfig
@@ -571,9 +742,10 @@ void Cy_CapSense_DpProcessButton_Call(
* Function Name: Cy_CapSense_DpProcessCsxTouchpad_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_DpProcessCsxTouchpad function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_DpProcessCsxTouchpad() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_DpProcessCsxTouchpad().
*
* \param ptrWdConfig
@@ -597,9 +769,10 @@ void Cy_CapSense_DpProcessCsxTouchpad_Call(
* Function Name: Cy_CapSense_DpProcessProximity_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_DpProcessProximity function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_DpProcessProximity() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_DpProcessProximity().
*
* \param ptrWdConfig
@@ -623,9 +796,10 @@ void Cy_CapSense_DpProcessProximity_Call(
* Function Name: Cy_CapSense_DpProcessCsdTouchpad_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_DpProcessCsdTouchpad function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_DpProcessCsdTouchpad() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_DpProcessCsdTouchpad().
*
* \param ptrWdConfig
@@ -649,9 +823,10 @@ void Cy_CapSense_DpProcessCsdTouchpad_Call(
* Function Name: Cy_CapSense_DpProcessSlider_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_DpProcessSlider function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_DpProcessSlider() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_DpProcessSlider().
*
* \param ptrWdConfig
@@ -675,9 +850,10 @@ void Cy_CapSense_DpProcessSlider_Call(
* Function Name: Cy_CapSense_DpProcessCsdMatrix_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_DpProcessCsdMatrix function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_DpProcessCsdMatrix() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_DpProcessCsdMatrix().
*
* \param ptrWdConfig
@@ -702,8 +878,11 @@ void Cy_CapSense_DpProcessCsdMatrix_Call(
****************************************************************************//**
*
* This is a wrapper function for calling
-* the Cy_CapSense_DpProcessCsdWidgetStatus function. All details,
-* parameters and return,* For the operation details, refer to the Cy_CapSense_DpProcessCsdWidgetStatus().
+* the Cy_CapSense_DpProcessCsdWidgetStatus() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_DpProcessCsdWidgetStatus().
*
* \param ptrWdConfig
* \param context
@@ -727,8 +906,11 @@ void Cy_CapSense_DpProcessCsdWidgetStatus_Call(
****************************************************************************//**
*
* This is a wrapper function for calling
-* the Cy_CapSense_DpProcessCsdWidgetRawCounts function. All details,
-* parameters and return,* For the operation details, refer to the Cy_CapSense_DpProcessCsdWidgetRawCounts().
+* the Cy_CapSense_DpProcessCsdWidgetRawCounts() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_DpProcessCsdWidgetRawCounts().
*
* \param ptrWdConfig
* \param context
@@ -756,8 +938,11 @@ uint32_t Cy_CapSense_DpProcessCsdWidgetRawCounts_Call(
****************************************************************************//**
*
* This is a wrapper function for calling
-* the Cy_CapSense_DpProcessCsxWidgetStatus function. All details,
-* parameters and return,* For the operation details, refer to the Cy_CapSense_DpProcessCsxWidgetStatus().
+* the Cy_CapSense_DpProcessCsxWidgetStatus() function. All details,
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_DpProcessCsxWidgetStatus().
*
* \param ptrWdConfig
* \param context
@@ -781,8 +966,11 @@ void Cy_CapSense_DpProcessCsxWidgetStatus_Call(
****************************************************************************//**
*
* This is a wrapper function for calling
-* the Cy_CapSense_DpProcessCsxWidgetRawCounts function. All details,
-* parameters and return,* For the operation details, refer to the Cy_CapSense_DpProcessCsxWidgetRawCounts().
+* the Cy_CapSense_DpProcessCsxWidgetRawCounts() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_DpProcessCsxWidgetRawCounts().
*
* \param ptrWdConfig
* \param context
@@ -809,8 +997,11 @@ uint32_t Cy_CapSense_DpProcessCsxWidgetRawCounts_Call(
****************************************************************************//**
*
* This is a wrapper function for calling
-* the Cy_CapSense_DpAdvancedCentroidTouchpad function. All details, parameters
-* and return,* For the operation details, refer to the Cy_CapSense_DpAdvancedCentroidTouchpad().
+* the Cy_CapSense_DpAdvancedCentroidTouchpad() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_DpAdvancedCentroidTouchpad().
*
* \param newTouch
* \param ptrWdConfig
@@ -835,9 +1026,10 @@ void Cy_CapSense_DpAdvancedCentroidTouchpad_Call(
* Function Name: Cy_CapSense_InitPositionFilters_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_InitPositionFilters function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_InitPositionFilters() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_InitPositionFilters().
*
* \param filterConfig
@@ -865,9 +1057,10 @@ void Cy_CapSense_InitPositionFilters_Call(
* Function Name: Cy_CapSense_RunPositionFilters_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_RunPositionFilters function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_RunPositionFilters() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_RunPositionFilters().
*
* \param ptrWdConfig
@@ -895,9 +1088,10 @@ void Cy_CapSense_RunPositionFilters_Call(
* Function Name: Cy_CapSense_ProcessPositionFilters_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_ProcessPositionFilters function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_ProcessPositionFilters() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_ProcessPositionFilters().
*
* \param newTouch
@@ -923,9 +1117,10 @@ void Cy_CapSense_ProcessPositionFilters_Call(
* Function Name: Cy_CapSense_InitializeAllFilters_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_InitializeAllFilters function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_InitializeAllFilters() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_InitializeAllFilters().
*
* \param context
@@ -948,8 +1143,11 @@ void Cy_CapSense_InitializeAllFilters_Call(
****************************************************************************//**
*
* This is a wrapper function for calling
-* the Cy_CapSense_FtRunEnabledFiltersInternal function. All details,
-* parameters and return,* For the operation details, refer to the Cy_CapSense_FtRunEnabledFiltersInternal().
+* the Cy_CapSense_FtRunEnabledFiltersInternal() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_FtRunEnabledFiltersInternal().
*
* \param ptrWdConfig
* \param ptrSnsContext
@@ -978,9 +1176,10 @@ void Cy_CapSense_FtRunEnabledFiltersInternal_Call(
* Function Name: Cy_CapSense_CSXDisableMode_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CSXDisableMode function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CSXDisableMode() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CSXDisableMode().
*
* \param context
@@ -1002,9 +1201,10 @@ void Cy_CapSense_CSXDisableMode_Call(
* Function Name: Cy_CapSense_CSXInitialize_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_CSXInitialize function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_CSXInitialize() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_CSXInitialize().
*
* \param context
@@ -1027,8 +1227,11 @@ void Cy_CapSense_CSXInitialize_Call(
****************************************************************************//**
*
* This is a wrapper function for calling
-* the Cy_CapSense_AdaptiveFilterInitialize_Lib function. All details,
-* parameters and return,* For the operation details, refer to the Cy_CapSense_AdaptiveFilterInitialize_Lib().
+* the Cy_CapSense_AdaptiveFilterInitialize_Lib() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_AdaptiveFilterInitialize_Lib().
*
* \param config
* \param positionContext
@@ -1053,9 +1256,10 @@ void Cy_CapSense_AdaptiveFilterInitialize_Lib_Call(
* Function Name: Cy_CapSense_AdaptiveFilterRun_Lib_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_AdaptiveFilterRun_Lib function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_AdaptiveFilterRun_Lib() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_AdaptiveFilterRun_Lib().
*
* \param config
@@ -1085,9 +1289,10 @@ void Cy_CapSense_AdaptiveFilterRun_Lib_Call(
* Function Name: Cy_CapSense_BallisticMultiplier_Lib_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_BallisticMultiplier_Lib function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_BallisticMultiplier_Lib() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_BallisticMultiplier_Lib().
*
* \param config
@@ -1120,9 +1325,10 @@ void Cy_CapSense_BallisticMultiplier_Lib_Call(
* Function Name: Cy_CapSense_DpUpdateThresholds_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_DpUpdateThresholds function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_DpUpdateThresholds() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_DpUpdateThresholds().
*
* \param ptrWdContext
@@ -1151,8 +1357,11 @@ void Cy_CapSense_DpUpdateThresholds_Call(
****************************************************************************//**
*
* This is a wrapper function for calling
-* the Cy_CapSense_InitializeNoiseEnvelope_Lib function. All details,
-* parameters and return,* For the operation details, refer to the Cy_CapSense_InitializeNoiseEnvelope_Lib().
+* the Cy_CapSense_InitializeNoiseEnvelope_Lib() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_InitializeNoiseEnvelope_Lib().
*
* \param rawCount
* \param sigPFC
@@ -1179,9 +1388,10 @@ void Cy_CapSense_InitializeNoiseEnvelope_Lib_Call(
* Function Name: Cy_CapSense_RunNoiseEnvelope_Lib_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_RunNoiseEnvelope_Lib function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_RunNoiseEnvelope_Lib() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_RunNoiseEnvelope_Lib().
*
* \param rawCount
@@ -1210,9 +1420,10 @@ void Cy_CapSense_RunNoiseEnvelope_Lib_Call(
* Function Name: Cy_CapSense_SsAutoTune_Call
****************************************************************************//**
*
-* This is a wrapper of the Cy_CapSense_SsAutoTune function.
-* It calls this function if the corresponding function pointer is initialized.
+* This is a wrapper of the Cy_CapSense_SsAutoTune() function.
*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
* For the operation details, refer to the Cy_CapSense_SsAutoTune().
*
* \param context
@@ -1233,6 +1444,287 @@ cy_status Cy_CapSense_SsAutoTune_Call(
}
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDisableMode_Call
+****************************************************************************//**
+*
+* This is a wrapper of the Cy_CapSense_BistDisableMode() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_BistDisableMode().
+*
+* \param context
+*
+*******************************************************************************/
+void Cy_CapSense_BistDisableMode_Call(
+ cy_stc_capsense_context_t * context)
+{
+ cy_stc_capsense_fptr_config_t * ptrFptrCfg = (cy_stc_capsense_fptr_config_t *)context->ptrFptrConfig;
+
+ if(NULL != ptrFptrCfg->fptrBistDisableMode)
+ {
+ ptrFptrCfg->fptrBistDisableMode(context);
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistInitialize_Call
+****************************************************************************//**
+*
+* This is a wrapper of the Cy_CapSense_BistInitialize() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_BistInitialize().
+*
+* \param context
+*
+*******************************************************************************/
+void Cy_CapSense_BistInitialize_Call(
+ cy_stc_capsense_context_t * context)
+{
+ cy_stc_capsense_fptr_config_t * ptrFptrCfg = (cy_stc_capsense_fptr_config_t *)context->ptrFptrConfig;
+
+ if(NULL != ptrFptrCfg->fptrBistInitialize)
+ {
+ ptrFptrCfg->fptrBistInitialize(context);
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDsInitialize_Call
+****************************************************************************//**
+*
+* This is a wrapper of the Cy_CapSense_BistDsInitialize() function.
+*
+* The wrapper calls the function if the corresponding function pointer
+* is initialized.
+* For the operation details, refer to the Cy_CapSense_BistDsInitialize().
+*
+* \param context
+*
+*******************************************************************************/
+void Cy_CapSense_BistDsInitialize_Call(
+ cy_stc_capsense_context_t * context)
+{
+ cy_stc_capsense_fptr_config_t * ptrFptrCfg = (cy_stc_capsense_fptr_config_t *)context->ptrFptrConfig;
+
+ if(NULL != ptrFptrCfg->fptrBistDsInitialize)
+ {
+ ptrFptrCfg->fptrBistDsInitialize(context);
+ }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GetParam
+****************************************************************************//**
+*
+* Gets a value of the specified parameter from the cy_capsense_tuner structure.
+*
+* This function gets the value of the specified parameter by the paramId
+* argument. The paramId for each register of cy_capsense_tuner is available
+* in the cycfg_capsense.h file as CY_CAPSENSE__PARAM_ID.
+* The paramId is a special enumerated value generated by the CapSense
+* Configurator. The format of paramId is as follows:
+* 1. [ byte 3 byte 2 byte 1 byte 0 ]
+* 2. [ RRRRRUTT IIIIIIII MMMMMMMM LLLLLLLL ]
+* 3. U - indicates if the parameter affects the RAM Widget Object CRC.
+* 4. T - encodes the parameter type:
+* * 01b: uint8_t
+* * 10b: uint16_t
+* * 11b: uint32_t
+* 5. I - specifies that the widgetId parameter belongs to.
+* 6. M,L - the parameter offset MSB and LSB accordingly in cy_capsense_tuner.
+* 7. R - reserved
+*
+* \param paramId
+* Specifies the ID of parameter to get its value.
+* A macro for the parameter ID can be found in the cycsg_capsense.h file
+* defined as CY_CAPSENSE__PARAM_ID.
+*
+* \param value
+* The pointer to a variable to be updated with the obtained value.
+*
+* \param ptrTuner
+* The pointer to the cy_capsense_tuner variable of cy_stc_capsense_tuner_t.
+* The cy_capsense_tuner is declared in CapSense Configurator generated files:
+* * cycfg_capsense.c/h
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the operation. If CY_RET_SUCCESS is not received,
+* either paramId is invalid or ptrTuner is null.
+*
+*******************************************************************************/
+cy_status Cy_CapSense_GetParam(
+ uint32_t paramId,
+ uint32_t * value,
+ const uint8_t * ptrTuner,
+ const cy_stc_capsense_context_t * context)
+{
+ cy_status result = CY_RET_BAD_PARAM;
+ uint32_t paramType;
+ uint32_t paramOffset;
+
+ (void)context;
+ if ((value != NULL) && (ptrTuner != NULL))
+ {
+ /* Check parameter type, offset alignment and read data */
+ paramType = (paramId & CY_CAPSENSE_PARAM_TYPE_MASK) >> CY_CAPSENSE_PARAM_TYPE_OFFSET;
+ paramOffset = CY_LO16(paramId);
+ switch (paramType)
+ {
+ case CY_CAPSENSE_DS_PARAM_TYPE_UINT32:
+ if (0u == (paramOffset & CY_CAPSENSE_UINT32_ALIGN_MASK))
+ {
+ *value = *((uint32_t *)(&ptrTuner[paramOffset]));
+ result = CY_RET_SUCCESS;
+ }
+ break;
+ case CY_CAPSENSE_DS_PARAM_TYPE_UINT16:
+ if (0u == (paramOffset & CY_CAPSENSE_UINT16_ALIGN_MASK))
+ {
+ *value = (uint32_t)(*((uint16_t *)(&ptrTuner[paramOffset])));
+ result = CY_RET_SUCCESS;
+ }
+ break;
+ case CY_CAPSENSE_DS_PARAM_TYPE_UINT8:
+ *value = (uint32_t)(ptrTuner[paramOffset]);
+ result = CY_RET_SUCCESS;
+ break;
+ default:
+ break;
+ }
+ }
+ return result;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SetParam
+****************************************************************************//**
+*
+* Sets a new value for the specified parameter in cy_capsense_tuner structure.
+*
+* This function sets the value of the specified parameter by the paramId
+* argument. The paramId for each register of cy_capsense_tuner is available
+* in the cycfg_capsense.h file as CY_CAPSENSE__PARAM_ID.
+* The paramId is a special enumerated value generated by the CapSense
+* Configurator. The format of paramId is as follows:
+* 1. [ byte 3 byte 2 byte 1 byte 0 ]
+* 2. [ RRRRRUTT IIIIIIII MMMMMMMM LLLLLLLL ]
+* 3. U - indicates if the parameter affects the RAM Widget Object CRC.
+* 4. T - encodes the parameter type:
+* * 01b: uint8_t
+* * 10b: uint16_t
+* * 11b: uint32_t
+* 5. I - specifies that the widgetId parameter belongs to
+* 6. M,L - the parameter offset MSB and LSB accordingly in cy_capsense_tuner.
+* 7. R - reserved
+*
+* This function writes specified value into the desired register without
+* other registers update. It is application layer responsibility to keep all
+* the data structure registers aligned. Repeated call of
+* Cy_CapSense_Enable() function helps aligning dependent register values.
+*
+* This function updates also the widget CRC field if Built-in Self-test
+* is enabled and paramId requires that.
+*
+* \param paramId
+* Specifies the ID of parameter to set its value.
+* A macro for the parameter ID can be found in the cycsg_capsense.h file
+* defined as CY_CAPSENSE__PARAM_ID.
+*
+* \param value
+* Specifies the new parameter's value.
+*
+* \param ptrTuner
+* The pointer to the cy_capsense_tuner variable of cy_stc_capsense_tuner_t.
+* The cy_capsense_tuner is declared in CapSense Configurator generated files:
+* * cycfg_capsense.c/h
+*
+* \param context
+* The pointer to the CapSense context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the operation. If CY_RET_SUCCESS is not received,
+* the parameter was not updated with the new value, either paramId is invalid
+* or ptrTuner is null.
+*
+*******************************************************************************/
+cy_status Cy_CapSense_SetParam(
+ uint32_t paramId,
+ uint32_t value,
+ uint8_t * ptrTuner,
+ cy_stc_capsense_context_t * context)
+{
+ cy_status result = CY_RET_BAD_PARAM;
+ uint32_t paramOffset;
+ uint32_t paramWidget;
+ uint32_t paramType;
+ uint32_t paramCrc;
+
+ if ((context != NULL) && (ptrTuner != NULL))
+ {
+ result = CY_RET_SUCCESS;
+
+ /* Parse paramId */
+ paramOffset = CY_LO16(paramId);
+ paramType = (paramId & CY_CAPSENSE_PARAM_TYPE_MASK) >> CY_CAPSENSE_PARAM_TYPE_OFFSET;
+ paramCrc = (paramId & CY_CAPSENSE_PARAM_CRC_MASK) >> CY_CAPSENSE_PARAM_CRC_OFFSET;
+ paramWidget = (paramId & CY_CAPSENSE_PARAM_WIDGET_MASK) >> CY_CAPSENSE_PARAM_WIDGET_OFFSET;
+ if ((paramWidget > context->ptrCommonConfig->numWd) &&
+ (0u != paramCrc) &&
+ (0u != context->ptrCommonConfig->bistEn))
+ {
+ result = CY_RET_BAD_PARAM;
+ }
+
+ /* Check parameter type, offset alignment, write the specified parameter */
+ if (CY_RET_SUCCESS == result)
+ {
+ switch (paramType)
+ {
+ case CY_CAPSENSE_DS_PARAM_TYPE_UINT32:
+ if (0u == (paramOffset & CY_CAPSENSE_UINT32_ALIGN_MASK))
+ {
+ *((uint32_t *)(&ptrTuner[paramOffset])) = value;
+ }
+ break;
+ case CY_CAPSENSE_DS_PARAM_TYPE_UINT16:
+ if (0u == (paramOffset & CY_CAPSENSE_UINT16_ALIGN_MASK))
+ {
+ *((uint16_t *)(&ptrTuner[paramOffset])) = (uint16_t)value;
+ }
+ break;
+ case CY_CAPSENSE_DS_PARAM_TYPE_UINT8:
+ ptrTuner[paramOffset] = (uint8_t)value;
+ break;
+ default:
+ result = CY_RET_BAD_PARAM;
+ break;
+ }
+ }
+
+ /* Update widget CRC if needed */
+ if ((CY_RET_SUCCESS == result) &&
+ (0u != context->ptrCommonConfig->bistEn) &&
+ (0u != paramCrc))
+ {
+ Cy_CapSense_UpdateCrcWidget(paramWidget, context);
+ }
+ }
+
+ return result;
+}
+
+
#endif /* CY_IP_MXCSDV2 */
diff --git a/cy_capsense_structure.h b/cy_capsense_structure.h
index 8112be5..b4b19e7 100644
--- a/cy_capsense_structure.h
+++ b/cy_capsense_structure.h
@@ -1,6 +1,6 @@
/***************************************************************************//**
* \file cy_capsense_structure.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the top-level declarations of the CapSense data
@@ -8,7 +8,7 @@
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -25,7 +25,7 @@
#include "cy_capsense_gesture_lib.h"
#include "cy_capsense_common.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
@@ -43,7 +43,7 @@ extern "C" {
/** Defines MW Tuner module states */
typedef enum
{
- CY_CAPSENSE_TU_FSM_RUNNING = 0x00u, /**< Running state is a state when CapSense middleware is not
+ CY_CAPSENSE_TU_FSM_RUNNING = 0x00u, /**< Running state is a state when CapSense middleware is not
* blocked by the CapSense Tuner tool and application program continuously scans */
CY_CAPSENSE_TU_FSM_SUSPENDED = 0x01u, /**< Scanning is suspended */
CY_CAPSENSE_TU_FSM_ONE_SCAN = 0x03u, /**< Scanning is suspended after one scan cycle */
@@ -79,8 +79,19 @@ typedef enum
CY_CAPSENSE_UNDEFINED_E = 0x00u, /**< Undefined method used at initialization or releasing the CSD HW block */
CY_CAPSENSE_SENSE_METHOD_CSD_E = 0x01u, /**< CSD sensing method */
CY_CAPSENSE_SENSE_METHOD_CSX_E = 0x02u, /**< CSX sensing method */
+ CY_CAPSENSE_SENSE_METHOD_BIST_E = 0x03u, /**< BIST sensing method */
} cy_en_capsense_sensing_method_t;
+/** Defines CapSense return statuses types */
+typedef enum
+{
+ CY_CAPSENSE_SUCCESS_E = 0x00u, /**< The success return status */
+ CY_CAPSENSE_BAD_PARAM_E = 0x01u, /**< One or more invalid input parameters */
+ CY_CAPSENSE_HW_LOCKED_E = 0x02u, /**< The CSD HW block is captured by another middleware */
+ CY_CAPSENSE_HW_BUSY_E = 0x03u, /**< The CSD HW block is busy by previous operation */
+ CY_CAPSENSE_TIMEOUT_E = 0x04u, /**< The CSD HW block operation was not finished correctly */
+} cy_en_capsense_return_status_t;
+
/** Defines types of electrode */
typedef enum
{
@@ -111,6 +122,51 @@ typedef enum
} cy_en_capsense_callback_event_t;
+/** Defines HW configurations types for BIST operations */
+typedef enum
+{
+ CY_CAPSENSE_BIST_HW_UNDEFINED_E = 0x00u, /**< Initialization or releasing the CSD HW block */
+ CY_CAPSENSE_BIST_HW_SHORT_E = 0x01u, /**< Short tests */
+ CY_CAPSENSE_BIST_HW_ELTD_CAP_E = 0x02u, /**< Sensor and shield electrodes capacitance measurements with disabled shield */
+ CY_CAPSENSE_BIST_HW_EXTERNAL_CAP_E = 0x03u, /**< External capacitors capacitance measurements */
+ CY_CAPSENSE_BIST_HW_VDDA_E = 0x04u, /**< VDDA measurement */
+ CY_CAPSENSE_BIST_HW_ELTD_CAP_SH_E = 0x05u, /**< Sensor electrodes capacitance measurements with configured shield */
+} cy_en_capsense_bist_hw_config_t;
+
+
+/** Defines BIST IO Configuration */
+typedef enum
+{
+ CY_CAPSENSE_BIST_IO_UNDEFINED_E = 0x00u, /**< The undefined state. Pins are disconnected from AMuxBus */
+ CY_CAPSENSE_BIST_IO_STRONG_E = 0x01u, /**< The drive mode is set to Strong in off - Low.
+ * The HSIOM is set to GPIO */
+ CY_CAPSENSE_BIST_IO_HIGHZA_E = 0x02u, /**< The drive mode is set to High-Z.
+ * The HSIOM is set to GPIO */
+ CY_CAPSENSE_BIST_IO_SENSE_E = 0x03u, /**< The drive mode is set to High-Z/Strong in off (depending on the device platform).
+ * The HSIOM is set to CSD sense connection. */
+ CY_CAPSENSE_BIST_IO_SHIELD_E = 0x04u, /**< The drive mode is set to High-Z/Strong in off (depending on the device platform).
+ * The HSIOM is set to CSD shield connection. */
+ CY_CAPSENSE_BIST_IO_STRONG_HIGH_E = 0x05u, /**< The drive mode is set to Strong in off - High.
+ * The HSIOM is set to GPIO */
+} cy_en_capsense_bist_io_state_t;
+
+
+/** Defines BIST result statuses */
+typedef enum
+{
+ CY_CAPSENSE_BIST_SUCCESS_E = 0x00u, /**< The success test status */
+ CY_CAPSENSE_BIST_BAD_PARAM_E = 0x01u, /**< The bad input parameters test status */
+ CY_CAPSENSE_BIST_HW_BUSY_E = 0x02u, /**< The CSD HW block is busy by previous operation */
+ CY_CAPSENSE_BIST_LOW_LIMIT_E = 0x03u, /**< The status for a low limit reached during the test */
+ CY_CAPSENSE_BIST_HIGH_LIMIT_E = 0x04u, /**< The status for a high limit reached during the test */
+ CY_CAPSENSE_BIST_ERROR_E = 0x05u, /**< The status for an error occurred during the test.
+ The test is not completed */
+ CY_CAPSENSE_BIST_FEATURE_DISABLED_E = 0x06u, /**< The BIST feature is disabled. */
+ CY_CAPSENSE_BIST_TIMEOUT_E = 0x07u, /**< The status for a timeout occurred during the test */
+ CY_CAPSENSE_BIST_FAIL_E = 0x0Fu, /**< The failed test status */
+} cy_en_capsense_bist_status_t;
+
+
/** \} */
@@ -138,15 +194,15 @@ typedef struct
typedef struct
{
uint32_t velocity; /**< The square of the "speed" (maximum distance change per refresh interval) threshold
- * distinguishing a fast finger movement from separate finger touches
+ * distinguishing a fast finger movement from separate finger touches
* (in [pixels/refresh interval]).
* Squared speeds exceeding this value indicate separate finger touches.
- * Squared speeds below this value indicate fast single finger movement. */
+ * Squared speeds below this value indicate fast single finger movement. */
cy_stc_capsense_position_t oldPeak[CY_CAPSENSE_CSX_TOUCHPAD_MAX_PEAKS];
/**< Touch Positions */
uint8_t oldPeakNumber; /**< Number of detected peaks */
uint8_t oldActiveIdsMask; /**< Mask of used IDs */
-} cy_stc_capsense_csx_touch_history_t;
+} cy_stc_capsense_csx_touch_history_t;
/** Internal CSX Touchpad buffer structure for CSX for Touchpads' processing */
typedef struct
@@ -170,7 +226,7 @@ typedef struct
/** Widget context structure */
typedef struct
{
- uint16_t fingerCap; /**< Widget finger capacitance parameter used for the CSD
+ uint16_t fingerCap; /**< Widget finger capacitance parameter used for the CSD
* widgets only when SmartSense is enabled */
uint16_t sigPFC; /**< The 75% of signal per user-defined finger capacitance */
uint16_t resolution; /**< Provides scan resolution for the CSD Widgets.
@@ -178,10 +234,10 @@ typedef struct
uint16_t maxRawCount; /**< Calculated maximum raw count of widget */
uint16_t fingerTh; /**< Widget Finger Threshold */
uint16_t proxTh; /**< Widget Proximity Threshold */
- uint16_t lowBslnRst; /**< The widget low baseline reset count. Specifies the number
- * of samples the sensor signal must be below the Negative
+ uint16_t lowBslnRst; /**< The widget low baseline reset count. Specifies the number
+ * of samples the sensor signal must be below the Negative
* Noise Threshold \ref nNoiseTh to trigger a baseline reset */
- uint16_t snsClk; /**< Sense Clock Divider. For the Matrix Buttons and Touchpad widgets
+ uint16_t snsClk; /**< Sense Clock Divider. For the Matrix Buttons and Touchpad widgets
* specifies the column sense clock divider */
uint16_t rowSnsClk; /**< Row Sense Clock Divider for the Matrix Buttons and Touchpad widgets */
uint16_t gestureDetected; /**< Mask of detected gestures */
@@ -197,27 +253,27 @@ typedef struct
* * 3 - touch reported on the third consecutive detection */
uint8_t snsClkSource; /**< Widget clock source:
* * bit[7] - Indicates auto mode of clock source selection
- * * bit[0:6] - Clock source:
- * * 0 - Direct (CY_CAPSENSE_CLK_SOURCE_DIRECT)
- * * 1 - SSC6 (CY_CAPSENSE_CLK_SOURCE_SSC6)
- * * 2 - SSC7 (CY_CAPSENSE_CLK_SOURCE_SSC7)
- * * 3 - SSC9 (CY_CAPSENSE_CLK_SOURCE_SSC9)
- * * 4 - SSC10 (CY_CAPSENSE_CLK_SOURCE_SSC10)
- * * 5 - PRS8 (CY_CAPSENSE_CLK_SOURCE_PRS8)
+ * * bit[0:6] - Clock source:
+ * * 0 - Direct (CY_CAPSENSE_CLK_SOURCE_DIRECT)
+ * * 1 - SSC6 (CY_CAPSENSE_CLK_SOURCE_SSC6)
+ * * 2 - SSC7 (CY_CAPSENSE_CLK_SOURCE_SSC7)
+ * * 3 - SSC9 (CY_CAPSENSE_CLK_SOURCE_SSC9)
+ * * 4 - SSC10 (CY_CAPSENSE_CLK_SOURCE_SSC10)
+ * * 5 - PRS8 (CY_CAPSENSE_CLK_SOURCE_PRS8)
* * 6 - PRS12 (CY_CAPSENSE_CLK_SOURCE_PRS12) */
- uint8_t idacMod[CY_CAPSENSE_FREQ_CHANNELS_NUM]; /**< Sets the current of the modulation IDAC for the CSD widgets.
- * For the CSD Touchpad and Matrix Button widgets sets the current of the
+ uint8_t idacMod[CY_CAPSENSE_FREQ_CHANNELS_NUM]; /**< Sets the current of the modulation IDAC for the CSD widgets.
+ * For the CSD Touchpad and Matrix Button widgets sets the current of the
* modulation IDAC for the column sensors. Not used for the CSX widgets. */
uint8_t idacGainIndex; /**< Index of IDAC gain in table \ref cy_stc_capsense_idac_gain_table_t */
- uint8_t rowIdacMod[CY_CAPSENSE_FREQ_CHANNELS_NUM]; /**< Sets the current of the modulation IDAC for the row sensors
+ uint8_t rowIdacMod[CY_CAPSENSE_FREQ_CHANNELS_NUM]; /**< Sets the current of the modulation IDAC for the row sensors
* for the CSD Touchpad and Matrix Button widgets. Not used for the CSX widgets. */
uint8_t bslnCoeff; /**< Baseline IIR filter coefficient. Lower value leads to higher filtering. */
- uint8_t status; /**< Contains masks:
+ uint8_t status; /**< Contains masks:
* * bit[0] - Widget Active (CY_CAPSENSE_WD_ACTIVE_MASK)
* * bit[1] - Widget Disabled (CY_CAPSENSE_WD_DISABLE_MASK)
- * * bit[2] - Widget Working (CY_CAPSENSE_WD_WORKING_MASK) - reserved */
- cy_stc_capsense_touch_t wdTouch; /**< Widget touch structure used for Matrix Buttons, Sliders, and Touchpads */
-} cy_stc_capsense_widget_context_t;
+ * * bit[2] - Widget Working (CY_CAPSENSE_WD_WORKING_MASK) */
+ cy_stc_capsense_touch_t wdTouch; /**< Widget touch structure used for Matrix Buttons, Sliders, and Touchpads */
+} cy_stc_capsense_widget_context_t;
/** Pin configuration structure */
typedef struct
@@ -237,24 +293,24 @@ typedef struct
/** Configuration structure of advanced touchpad */
typedef struct
{
- uint16_t penultimateTh; /**< Defines a threshold for determining arrival at edges. This
- * value may have to be increased for small diamonds, so that the edge handling is
- * initiated sooner. If this number is too high, there is jumping at the edge with
- * a smaller finger. If this number is too low, there is jumping at the edge with a
+ uint16_t penultimateTh; /**< Defines a threshold for determining arrival at edges. This
+ * value may have to be increased for small diamonds, so that the edge handling is
+ * initiated sooner. If this number is too high, there is jumping at the edge with
+ * a smaller finger. If this number is too low, there is jumping at the edge with a
* larger finger. */
- uint16_t virtualSnsTh; /**< Defines a virtual sensor signal. This value should be set
- * to the value of any sensor when a medium-sized finger is placed directly over
- * it. If this value is too high, a position is reported nearer the edge than ideal
- * position. If this value is too low, a position is reported nearer the middle of
+ uint16_t virtualSnsTh; /**< Defines a virtual sensor signal. This value should be set
+ * to the value of any sensor when a medium-sized finger is placed directly over
+ * it. If this value is too high, a position is reported nearer the edge than ideal
+ * position. If this value is too low, a position is reported nearer the middle of
* touchpad. */
- uint8_t crossCouplingTh; /**< Defines cross coupling threshold. It is subtracted from
+ uint8_t crossCouplingTh; /**< Defines cross coupling threshold. It is subtracted from
* sensor signals at centroid position calculation to improve the accuracy.
- * The threshold should be equal to a sensor signal when your finger is near the
- * sensor, but not touching the sensor. This can be determined by slowly dragging
- * your finger across the panel and finding the inflection point of the difference
- * counts at the base of the curve. The difference value at this point should be
+ * The threshold should be equal to a sensor signal when your finger is near the
+ * sensor, but not touching the sensor. This can be determined by slowly dragging
+ * your finger across the panel and finding the inflection point of the difference
+ * counts at the base of the curve. The difference value at this point should be
* the Cross-coupling threshold. */
- uint8_t reserved0; /**< Reserved field */
+ uint8_t reserved0; /**< Reserved field */
uint8_t reserved1; /**< Reserved field */
uint8_t reserved2; /**< Reserved field */
} cy_stc_capsense_advanced_touchpad_config_t;
@@ -265,11 +321,13 @@ typedef struct
cy_stc_capsense_widget_context_t * ptrWdContext; /**< Pointer to context structure of this widget */
cy_stc_capsense_sensor_context_t * ptrSnsContext; /**< Pointer to the first object of sensor context structure that belongs to this widget */
const cy_stc_capsense_electrode_config_t * ptrEltdConfig; /**< Pointer to the first object of electrode configuration structure that belongs to this widget */
+ uint32_t * ptrEltdCapacitance; /**< Pointer to the first object in the electrode capacitance array that belongs to this widget */
+ uint16_t * ptrBslnInv; /**< Pointer to the first object in the sensor baseline inversion array that belongs to this widget */
- cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNoiseEnvelope;
+ cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNoiseEnvelope;
/**< Pointer to the noise envelope filter used by SmartSense */
uint16_t * ptrRawFilterHistory; /**< Pointer to the raw count filter history of the widget */
- uint8_t * ptrRawFilterHistoryLow; /**< Pointer to the raw count filter history extended of the widget */
+ uint8_t * ptrRawFilterHistoryLow; /**< Pointer to the raw count filter history extended of the widget */
uint32_t iirCoeff; /**< Raw count IIR filter coefficient. Smaller value leads to higher filtering */
uint8_t * ptrDebounceArr; /**< Pointer to the debounce array of the widget */
@@ -279,7 +337,7 @@ typedef struct
uint16_t xResolution; /**< Keeps maximum position value. For Touchpads X-axis maximum position */
uint16_t yResolution; /**< For Touchpads Y-Axis maximum position */
uint16_t numSns; /**< The total number of sensors:
- * For CSD widgets: WD_NUM_ROWS + WD_NUM_COLS.
+ * For CSD widgets: WD_NUM_ROWS + WD_NUM_COLS.
* For CSX widgets: WD_NUM_ROWS * WD_NUM_COLS. */
uint8_t numCols; /**< For CSD Button and Proximity Widgets, the number of sensors.
* For CSD Slider Widget, the number of segments.
@@ -324,15 +382,16 @@ typedef struct
uint32_t periClkHz; /**< Peripheral clock in Hz */
uint16_t vdda; /**< VDDA in mV */
uint16_t numPin; /**< Total number of IOs. */
- uint16_t numSns; /**< The total number of sensors. It is equal to the number of objects with raw count.
- * * For CSD widgets: WD_NUM_ROWS + WD_NUM_COLS
+ uint16_t numSns; /**< The total number of sensors. It is equal to the number of objects with raw count.
+ * * For CSD widgets: WD_NUM_ROWS + WD_NUM_COLS
* * For CSX widgets: WD_NUM_ROWS * WD_NUM_COLS */
- uint8_t numWd; /**< Total number of widgets */
+ uint8_t numWd; /**< Total number of widgets */
uint8_t csdEn; /**< CSD sensing method enabled, at least one CSD widget is configured */
uint8_t csxEn; /**< CSX sensing method enabled, at least one CSX widget is configured */
uint8_t mfsEn; /**< Multi-frequency Scan (MFS) enabled */
uint8_t positionFilterEn; /**< Position filtering enabled */
+ uint8_t bistEn; /**< Built-in Self-test (BIST) enabled */
uint8_t periDividerType; /**< Peripheral clock type (8- or 16-bit type) */
uint8_t periDividerIndex; /**< Peripheral divider index */
@@ -343,7 +402,7 @@ typedef struct
uint16_t proxTouchCoeff; /**< Proximity touch coefficient in percentage used in SmartSense */
uint8_t swSensorAutoResetEn; /**< Sensor auto reset enabled */
-
+
uint8_t portCmodPadNum; /**< Number of port of dedicated Cmod pad */
uint8_t pinCmodPad; /**< Position of the dedicated Cmod pad in the port */
uint8_t portCshPadNum; /**< Number of port of dedicated Csh pad */
@@ -377,7 +436,7 @@ typedef struct
* * CY_CAPSENSE_SNS_CONNECTION_GROUND */
uint8_t csdShieldDelay; /**< Shield signal delay */
uint16_t csdVref; /**< Vref for CSD method */
- uint16_t csdRConst; /**< Sensor resistance in series used by SmartSense */
+ uint16_t csdRConst; /**< Sensor resistance in series used by SmartSense */
uint8_t csdCTankShieldEn; /**< Csh enabled */
uint8_t csdShieldNumPin; /**< Number of shield IOs */
uint8_t csdShieldSwRes; /**< Shield switch resistance */
@@ -392,11 +451,11 @@ typedef struct
uint8_t csdIdacMin; /**< Min acceptable IDAC value in CSD calibration */
uint8_t csdIdacCompEn; /**< Compensation IDAC enabled */
uint8_t csdFineInitTime; /**< Number of dummy SnsClk periods at fine initialization */
- uint8_t csdIdacRowColAlignEn; /**< Row-Column alignment enabled. It adjusts modulator IDAC for rows
+ uint8_t csdIdacRowColAlignEn; /**< Row-Column alignment enabled. It adjusts modulator IDAC for rows
* and for columns to achieve the similar sensitivity */
- uint8_t csdMfsDividerOffsetF1; /**< Frequency divider offset for channel 1. This value is added to
+ uint8_t csdMfsDividerOffsetF1; /**< Frequency divider offset for channel 1. This value is added to
* base (channel 0) SnsClk divider to form channel 1 frequency */
- uint8_t csdMfsDividerOffsetF2; /**< Frequency divider offset for channel 2. This value is added to
+ uint8_t csdMfsDividerOffsetF2; /**< Frequency divider offset for channel 2. This value is added to
* base (channel 0) SnsClk divider to form channel 2 frequency */
uint8_t csxRawTarget; /**< Raw count target in percentage for CSX calibration */
uint8_t csxIdacGainInitIndex; /**< IDAC gain for CSX method */
@@ -408,12 +467,119 @@ typedef struct
uint8_t csxScanSwRes; /**< Switch resistance at scanning */
uint8_t csxInitShieldSwRes; /**< Switch resistance at fine initialization */
uint8_t csxScanShieldSwRes; /**< Switch resistance at scanning */
- uint8_t csxMfsDividerOffsetF1; /**< Frequency divider offset for channel 1. This value is added to
+ uint8_t csxMfsDividerOffsetF1; /**< Frequency divider offset for channel 1. This value is added to
* base (channel 0) Tx divider to form channel 1 frequency */
- uint8_t csxMfsDividerOffsetF2; /**< Frequency divider offset for channel 2. This value is added to
+ uint8_t csxMfsDividerOffsetF2; /**< Frequency divider offset for channel 2. This value is added to
* base (channel 0) Tx divider to form channel 2 frequency */
} cy_stc_capsense_common_config_t;
+
+/** Declares BIST Context Data Structure */
+typedef struct
+{
+ uint32_t testResultMask; /**< The bit mask of test results (PASS/FAIL) */
+
+ uint16_t wdgtCrcCalc; /**< A calculated by test CRC for a widget context structure */
+ uint8_t crcWdgtId; /**< The first CRC failed widget ID */
+
+ uint8_t shortedWdId; /**< The first shorted to GND/VDDA/ELTD widget ID */
+ uint8_t shortedSnsId; /**< The first shorted to GND/VDDA/ELTD sensor ID */
+
+ uint16_t * ptrWdgtCrc; /**< The pointer to the widget CRC array */
+
+ uint32_t shieldCap; /**< The shield capacitance measurement result in femtofarads */
+ uint16_t cModCap; /**< The Cmod capacitance measurement result in picofarads */
+ uint16_t cIntACap; /**< The CintA capacitance measurement result in picofarads */
+ uint16_t cIntBCap; /**< The CIntB capacitance measurement result in picofarads */
+ uint16_t cShieldCap; /**< The Cshield capacitance measurement result in picofarads */
+
+ uint16_t vddaVoltage; /**< The result of VDDA measurement in millivolts */
+
+ cy_en_capsense_bist_hw_config_t hwConfig; /**< A HW configuration for BIST operations */
+ cy_en_capsense_bist_io_state_t currentISC; /**< The current state of sensors when not being measured during the sensor capacitance measurement */
+ cy_en_capsense_bist_io_state_t shieldCapISC; /**< The state of sensors when not being measured during the shield capacitance measurement.
+ * * CY_CAPSENSE_SNS_CONNECTION_HIGHZ
+ * * CY_CAPSENSE_SNS_CONNECTION_SHIELD
+ * * CY_CAPSENSE_SNS_CONNECTION_GROUND */
+ cy_en_capsense_bist_io_state_t eltdCapCsdISC; /**< The state of sensors when not being measured during the CSD sensor capacitance measurement.
+ The states are the same as of the previous parameter */
+ cy_en_capsense_bist_io_state_t eltdCapCsxISC; /**< The state of sensors when not being measured during the CSX sensor capacitance measurement.
+ * * CY_CAPSENSE_SNS_CONNECTION_HIGHZ
+ * * CY_CAPSENSE_SNS_CONNECTION_GROUND */
+
+ uint16_t eltdCapModClk; /**< The ModClk divider for electrode capacitance measurement scans */
+ uint16_t eltdCapSnsClk; /**< The SnsClk divider for electrode capacitance measurement scans */
+ uint32_t eltdCapSnsClkFreqHz; /**< The value of the SnsClk frequency is Hz */
+ uint16_t eltdCapResolution; /**< The resolution for electrode capacitance measurement scans */
+ uint16_t eltdCapVrefMv; /**< The Vref value in mV for electrode capacitance measurement scans */
+ uint8_t eltdCapVrefGain; /**< The Vref gain for electrode capacitance measurement scans */
+
+ uint8_t fineInitTime; /**< Number of dummy SnsClk periods at fine initialization for BIST scans */
+
+ uint8_t snsIntgShortSettlingTime; /**< The sensor and shield short check time in microseconds */
+ uint16_t capacitorSettlingTime; /**< The maximum possible external capacitor charge/discharge time in microseconds */
+
+ uint16_t vddaModClk; /**< The ModClk divider for VDDA measurements */
+ uint16_t vddaVrefMv; /**< The Vref value in mV for VDDA measurements */
+ uint8_t vddaVrefGain; /**< The Vref gain for VDDA measurements */
+ uint8_t vddaIdacDefault; /**< The IDAC default code for Vdda measurements */
+ uint8_t vddaAzCycles; /**< The auto-zero time in Sns cycles for Vdda measurements */
+ uint8_t vddaAcqCycles; /**< The acquisition time in Sns cycles - 1 for Vdda measurements */
+
+ uint16_t extCapModClk; /**< The ModClk divider for external capacitor capacity measurements */
+ uint16_t extCapSnsClk; /**< The SnsClk divider for external capacitor capacity measurements */
+ uint16_t extCapVrefMv; /**< The Vref value in mV for external capacitor capacity measurements */
+ uint8_t extCapVrefGain; /**< The Vref gain for external capacitor capacitance measurements */
+ uint32_t extCapIdacPa; /**< The IDAC value in pA for external capacitor capacity measurements */
+ uint16_t extCapWDT; /**< The SW watchdog timeout used to prevent a hang in case of short */
+
+ uint32_t regSwHsPSelScan; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwHsPSelCmodInit; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwHsPSelCtankInit; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwDsiSel; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwShieldSelScan; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwResInit; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwResScan; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwBypSel; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwAmuxbufSel; /**< Internal pre-calculated data for faster operation */
+ uint32_t regAmbuf; /**< Internal pre-calculated data for faster operation */
+ uint32_t regHscmpScan; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwRefgenSel; /**< Internal pre-calculated data for faster operation */
+ uint32_t regConfig; /**< Internal pre-calculated data for faster operation */
+ uint32_t regIoSel; /**< Internal pre-calculated data for faster operation */
+
+ uint32_t regAmbufShield; /**< Internal pre-calculated data for faster operation */
+ uint32_t regHscmpScanShield; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwShieldSelScanShield; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwHsPSelScanShield; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwBypSelShield; /**< Internal pre-calculated data for faster operation */
+ uint32_t regSwAmuxbufSelShield; /**< Internal pre-calculated data for faster operation */
+ uint32_t regConfigShield; /**< Internal pre-calculated data for faster operation */
+ uint32_t regIoSelShield; /**< Internal pre-calculated data for faster operation */
+}
+cy_stc_capsense_bist_context_t;
+
+
+/** Declares the BIST structure with custom scan parameters */
+typedef struct
+{
+ cy_en_capsense_bist_io_state_t customISC; /**< The inactive state of sensors during the custom scan */
+ uint16_t modClk; /**< The ModClk divider for a custom scan. The minimum value is 1 and the maximum depends on a divider type,
+ but for a reliable CSD HW block operation, it is recommended to provide
+ a modulation clock frequency in the range from 1 to 50 MHz */
+ uint16_t snsClk; /**< The SnsClk divider for a custom scan. The minimum value is 4 and the maximum is 4095,
+ but for a reliable CSD HW block operation, it is recommended to provide
+ an sensor clock frequency in the range from 100 to 6000 kHz */
+ uint16_t convNum; /**< The number of conversions for a custom scan. The maximum raw counts is equal (convNum * snsClkDivider - 1),
+ that corresponds to (2^Resolution - 1) in older notations. The minimum value is 4 and the maximum is 65535,
+ but as the maximum raw counts is 65535, the convNum value should be less than (65536 / snsClkDivider) */
+ uint8_t vrefGain; /**< The Vref gain for a custom scan */
+ uint8_t idacMod; /**< Sets the code of the modulation IDAC for a custom scan */
+ uint8_t idacGainIndex; /**< Index of IDAC gain in table \ref cy_stc_capsense_idac_gain_table_t */
+ uint8_t fineInitTime; /**< Number of dummy SnsClk periods at fine initialization for a custom scan */
+}cy_stc_capsense_bist_custom_parameters_t;
+
+
/** Declares active sensor details */
typedef struct
{
@@ -428,7 +594,7 @@ typedef struct
cy_stc_capsense_sensor_context_t * ptrSnsContext; /**< Pointer to the sensor context structure */
- volatile uint16_t sensorIndex; /**< Current sensor ID */
+ volatile uint16_t sensorIndex; /**< Current sensor ID */
volatile uint8_t widgetIndex; /**< Current widget ID */
volatile uint8_t rxIndex; /**< Current Rx ID */
volatile uint8_t txIndex; /**< Current Tx ID */
@@ -446,30 +612,35 @@ typedef struct
uint32_t csdInactiveSnsDm; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegConfig; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegSwHsPSelScan; /**< Internal pre-calculated data for faster operation */
- uint32_t csdRegSwHsPSelInit; /**< Internal pre-calculated data for faster operation */
+ uint32_t csdRegSwHsPSelCmodInit; /**< Internal pre-calculated data for faster operation */
+ uint32_t csdRegSwHsPSelCtankInit; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegSwBypSel; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegSwResScan; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegSwResInit; /**< Internal pre-calculated data for faster operation */
+ uint32_t csdRegSwDsiSel; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegAmuxbufInit; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegSwAmuxbufSel; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegSwShieldSelScan; /**< Internal pre-calculated data for faster operation */
- uint32_t csdRegSwShieldSelInit; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegHscmpInit; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegHscmpScan; /**< Internal pre-calculated data for faster operation */
uint32_t csdIdacAConfig; /**< Internal pre-calculated data for faster operation */
uint32_t csdIdacBConfig; /**< Internal pre-calculated data for faster operation */
- uint32_t csdRegSwFwTankSelScan; /**< Internal pre-calculated data for faster operation */
- uint32_t csdRegSwFwTankSelInit; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegSwCmpPSel; /**< Internal pre-calculated data for faster operation */
+ uint32_t csdRegSwCmpNSel; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegIoSel; /**< Internal pre-calculated data for faster operation */
uint32_t csdRegRefgen; /**< Internal pre-calculated data for faster operation */
+ uint32_t csdRegSwRefGenSel; /**< Internal pre-calculated data for faster operation */
+
uint32_t csxRegConfigInit; /**< Internal pre-calculated data for faster operation */
uint32_t csxRegConfigScan; /**< Internal pre-calculated data for faster operation */
uint32_t csxRegSwResInit; /**< Internal pre-calculated data for faster operation */
uint32_t csxRegSwResPrech; /**< Internal pre-calculated data for faster operation */
uint32_t csxRegSwResScan; /**< Internal pre-calculated data for faster operation */
+ uint32_t csxRegAMuxBuf; /**< Internal pre-calculated data for faster operation */
uint32_t csxRegRefgen; /**< Internal pre-calculated data for faster operation */
- uint32_t regSwRefGenSel; /**< Internal pre-calculated data for faster operation */
+ uint32_t csxRegRefgenSel; /**< Internal pre-calculated data for faster operation */
+ uint32_t csxRegSwCmpNSel; /**< Internal pre-calculated data for faster operation */
+ uint32_t csxRegSwRefGenSel; /**< Internal pre-calculated data for faster operation */
uint8_t csdCmodConnection; /**< Internal pre-calculated data for faster operation */
uint8_t csdCshConnection; /**< Internal pre-calculated data for faster operation */
@@ -478,6 +649,30 @@ typedef struct
uint16_t csdVrefVoltageMv; /**< Internal pre-calculated data for faster operation */
}cy_stc_capsense_internal_context_t;
+
+/** Declares the structure that is intended to store the \ref cy_stc_capsense_widget_context_t
+ data structure fields, the CRC checking should be applied for. */
+typedef struct
+{
+ uint16_t fingerThVal; /**< The value of the .fingerTh field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint16_t proxThVal; /**< The value of the .proxTh field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint16_t fingerCapVal; /**< The value of the .fingerCap field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint16_t sigPFCVal; /**< The value of the .sigPFC field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint16_t resolutionVal; /**< The value of the .resolution field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint16_t lowBslnRstVal; /**< The value of the .lowBslnRst field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint16_t snsClkVal; /**< The value of the .snsClk field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint16_t rowSnsClkVal; /**< The value of the .rowSnsClk field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint8_t onDebounceVal; /**< The value of the .onDebounce field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint8_t snsClkSourceVal; /**< The value of the .snsClkSource field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint8_t idacModVal[CY_CAPSENSE_FREQ_CHANNELS_NUM]; /**< The value of the .idacMod field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint8_t idacGainIndexVal; /**< The value of the .idacGainIndex field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint8_t rowIdacModVal[CY_CAPSENSE_FREQ_CHANNELS_NUM]; /**< The value of the .rowIdacMod field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint8_t noiseThVal; /**< The value of the .noiseTh field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint8_t nNoiseThVal; /**< The value of the .nNoiseTh field of the \ref cy_stc_capsense_widget_context_t structure */
+ uint8_t hysteresisVal; /**< The value of the .hysteresis field of the \ref cy_stc_capsense_widget_context_t structure */
+}cy_stc_capsense_widget_crc_data_t;
+
+
/**
* Provides the typedef for the callback function that is intended to be called when
* the \ref cy_en_capsense_callback_event_t events occurs.
@@ -485,17 +680,17 @@ typedef struct
typedef void (*cy_capsense_callback_t)(cy_stc_active_scan_sns_t * ptrActiveScan);
/**
-* Provides the typedef for the callback function that is called by the
-* Cy_CapSense_RunTuner() function to establish communication with
-* the CapSense Tuner tool to monitor CapSense operation.
+* Provides the typedef for the callback function that is called by the
+* Cy_CapSense_RunTuner() function to establish communication with
+* the CapSense Tuner tool to monitor CapSense operation.
* Refer to \ref group_capsense_callbacks section.
*/
typedef void (*cy_capsense_tuner_send_callback_t)(void * context);
/**
-* Provides the typedef for the callback function that is called by the
-* Cy_CapSense_RunTuner() function to establish communication with
-* the CapSense Tuner tool to support life-time tunning.
+* Provides the typedef for the callback function that is called by the
+* Cy_CapSense_RunTuner() function to establish communication with
+* the CapSense Tuner tool to support life-time tunning.
* Refer to \ref group_capsense_callbacks section.
*/
typedef void (*cy_capsense_tuner_receive_callback_t)(uint8_t ** commandPacket, uint8_t ** tunerPacket, void * context);
@@ -511,13 +706,13 @@ typedef void (*cy_capsense_tuner_receive_callback_t)(uint8_t ** commandPacket, u
/** Declares top-level Context Data Structure */
typedef struct
{
- uint16_t configId; /**< 16-bit CRC calculated by the CapSense Configurator tool for the CapSense configuration.
+ uint16_t configId; /**< 16-bit CRC calculated by the CapSense Configurator tool for the CapSense configuration.
* Used by the CapSense Tuner tool to identify if the FW corresponds to the specific user configuration. */
- uint16_t tunerCmd; /**< Tuner Command Register \ref cy_en_capsense_tuner_cmd_t.
+ uint16_t tunerCmd; /**< Tuner Command Register \ref cy_en_capsense_tuner_cmd_t.
* Used for the communication between the CapSense Tuner tool and the middleware */
uint16_t scanCounter; /**< This counter increments after each scan. */
uint8_t tunerSt; /**< State of CapSense middleware tuner module. \ref cy_en_capsense_tuner_state_t */
- uint8_t initDone; /**< Keep information whether initialization was done or not */
+ uint8_t initDone; /**< Keep information whether initialization was done or not */
cy_capsense_callback_t ptrSSCallback; /**< Pointer to a user's Start Sample callback function. Refer to \ref group_capsense_callbacks section */
cy_capsense_callback_t ptrEOSCallback; /**< Pointer to a user's End Of Scan callback function. Refer to \ref group_capsense_callbacks section */
@@ -525,9 +720,9 @@ typedef struct
cy_capsense_tuner_receive_callback_t ptrTunerReceiveCallback; /**< Pointer to a user's tuner callback function. Refer to \ref group_capsense_callbacks section */
volatile uint32_t status; /**< Middleware status information, scan in progress or not */
- uint32_t timestampInterval; /**< Timestamp interval used at increasing the timestamp by Cy_CapSense_IncrementGestureTimestamp() */
+ uint32_t timestampInterval; /**< Timestamp interval used at increasing the timestamp by Cy_CapSense_IncrementGestureTimestamp() */
uint32_t timestamp; /**< Current timestamp should be kept updated and operational, which is vital for the
- * operation of Gesture and Ballistic multiplier features */
+ * operation of Gesture and Ballistic multiplier features */
uint8_t modCsdClk; /**< The modulator clock divider for the CSD widgets */
uint8_t modCsxClk; /**< The modulator clock divider for the CSX widgets */
uint8_t tunerCnt; /**< Command counter of CapSense middleware tuner module */
@@ -546,6 +741,7 @@ typedef struct
const cy_stc_capsense_pin_config_t * ptrShieldPinConfig; /**< Pointer to the shield pin configuration structure */
cy_stc_active_scan_sns_t * ptrActiveScanSns; /**< Pointer to the current active sensor structure */
const void * ptrFptrConfig; /**< Pointer to the function pointers structure */
+ cy_stc_capsense_bist_context_t * ptrBistContext; /**< Pointer to the BIST context structure */
} cy_stc_capsense_context_t;
/** The type of a pointer to the Cy_CapSense_CSDSetupWidget() function */
@@ -640,7 +836,7 @@ typedef void (*cy_func_capsense_init_position_filters_ptr_t)
/** The type of a pointer to the Cy_CapSense_DpProcessButton() function */
typedef void (*cy_func_capsense_dp_process_button_ptr_t)
(const cy_stc_capsense_widget_config_t * ptrWdConfig,
- cy_stc_capsense_context_t * context);
+ const cy_stc_capsense_context_t * context);
/** The type of a pointer to the Cy_CapSense_DpProcessSlider() function */
typedef void (*cy_func_capsense_dp_process_slider_ptr_t)
(const cy_stc_capsense_widget_config_t * ptrWdConfig,
@@ -648,7 +844,7 @@ typedef void (*cy_func_capsense_dp_process_slider_ptr_t)
/** The type of a pointer to the Cy_CapSense_DpProcessCsdMatrix() function */
typedef void (*cy_func_capsense_dp_process_csd_matrix_ptr_t)
(const cy_stc_capsense_widget_config_t * ptrWdConfig,
- cy_stc_capsense_context_t * context);
+ const cy_stc_capsense_context_t * context);
/** The type of a pointer to the Cy_CapSense_DpProcessCsdTouchpad() function */
typedef void (*cy_func_capsense_dp_process_csd_touchpad_ptr_t)
(const cy_stc_capsense_widget_config_t * ptrWdConfig,
@@ -659,7 +855,7 @@ typedef void (*cy_func_capsense_dp_advanced_centroid_touchpad_ptr_t)
const cy_stc_capsense_widget_config_t * ptrWdConfig);
/** The type of a pointer to the Cy_CapSense_DpProcessProximity() function */
typedef void (*cy_func_capsense_dp_process_proximity_ptr_t)
- (cy_stc_capsense_widget_config_t const * ptrWdConfig);
+ (const cy_stc_capsense_widget_config_t * ptrWdConfig);
/** The type of a pointer to the Cy_CapSense_DpProcessCsxTouchpad() function */
typedef void (*cy_func_capsense_dp_process_csx_touchpad_ptr_t)
(const cy_stc_capsense_widget_config_t * ptrWdConfig,
@@ -693,70 +889,86 @@ typedef void (*cy_func_capsense_initialize_noise_envelope_lib_ptr_t)
(uint16_t rawCount,
uint16_t sigPFC,
cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNoiseEnvelope);
+/** The type of a pointer to the Cy_CapSense_BistInitialize() function */
+typedef void (*cy_func_capsense_bist_initialize_ptr_t)
+ (cy_stc_capsense_context_t * context);
+/** The type of a pointer to the Cy_CapSense_BistDisableMode() function */
+typedef void (*cy_func_capsense_bist_disable_mode_ptr_t)
+ (cy_stc_capsense_context_t * context);
+/** The type of a pointer to the Cy_CapSense_BistDsInitialize() function */
+typedef void (*cy_func_capsense_bist_ds_initialize_ptr_t)
+ (cy_stc_capsense_context_t * context);
+
/** Function pointers configuration structure */
typedef struct
{
- cy_func_capsense_csd_setup_widget_ptr_t fptrCSDSetupWidget; /**< The Cy_CapSense_CSDSetupWidget() function pointer*/
+ cy_func_capsense_csd_setup_widget_ptr_t fptrCSDSetupWidget; /**< The Cy_CapSense_CSDSetupWidget() function pointer */
cy_func_capsense_csd_scan_ptr_t fptrCSDScan; /**< The Cy_CapSense_CSDScan() function pointer */
cy_func_capsense_dp_process_csd_widget_raw_counts_ptr_t fptrDpProcessCsdWidgetRawCounts;
- /**< The Cy_CapSense_DpProcessCsdWidgetRawCounts() function pointer*/
+ /**< The Cy_CapSense_DpProcessCsdWidgetRawCounts() function pointer */
cy_func_capsense_dp_process_csd_widget_status_ptr_t fptrDpProcessCsdWidgetStatus;
- /**< The Cy_CapSense_DpProcessCsdWidgetStatus() function pointer*/
- cy_func_capsense_csd_disable_mode_ptr_t fptrCSDDisableMode; /**< The Cy_CapSense_CSDDisableMode() function pointer*/
- cy_func_capsense_csd_initialize_ptr_t fptrCSDInitialize; /**< The Cy_CapSense_CSDInitialize() function pointer*/
- cy_func_capsense_csd_scan_isr_ptr_t fptrCSDScanISR; /**< The Cy_CapSense_CSDScanISR() function pointer*/
- cy_func_capsense_csx_setup_widget_ptr_t fptrCSXSetupWidget; /**< The Cy_CapSense_CSXSetupWidget() function pointer*/
- cy_func_capsense_csx_scan_ptr_t fptrCSXScan; /**< The Cy_CapSense_CSXScan() function pointer*/
+ /**< The Cy_CapSense_DpProcessCsdWidgetStatus() function pointer */
+ cy_func_capsense_csd_disable_mode_ptr_t fptrCSDDisableMode; /**< The Cy_CapSense_CSDDisableMode() function pointer */
+ cy_func_capsense_csd_initialize_ptr_t fptrCSDInitialize; /**< The Cy_CapSense_CSDInitialize() function pointer */
+ cy_func_capsense_csd_scan_isr_ptr_t fptrCSDScanISR; /**< The Cy_CapSense_CSDScanISR() function pointer */
+ cy_func_capsense_csx_setup_widget_ptr_t fptrCSXSetupWidget; /**< The Cy_CapSense_CSXSetupWidget() function pointer */
+ cy_func_capsense_csx_scan_ptr_t fptrCSXScan; /**< The Cy_CapSense_CSXScan() function pointer */
cy_capsense_dp_process_csx_widget_raw_counts_ptr_t fptrDpProcessCsxWidgetRawCounts;
- /**< The Cy_CapSense_DpProcessCsxWidgetRawCounts() function pointer*/
+ /**< The Cy_CapSense_DpProcessCsxWidgetRawCounts() function pointer */
cy_func_capsense_dp_process_csx_widget_status_ptr_t fptrDpProcessCsxWidgetStatus;
- /**< The Cy_CapSense_DpProcessCsxWidgetStatus() function pointer*/
- cy_func_capsense_csx_initialize_ptr_t fptrCSXInitialize; /**< The Cy_CapSense_CSXInitialize() function pointer*/
- cy_func_capsense_csx_disablemode_ptr_t fptrCSXDisableMode; /**< The Cy_CapSense_CSXDisableMode() function pointer*/
- cy_func_capsense_csx_scan_isr_ptr_t fptrCSXScanISR; /**< The Cy_CapSense_CSXScanISR() function pointer*/
+ /**< The Cy_CapSense_DpProcessCsxWidgetStatus() function pointer */
+ cy_func_capsense_csx_initialize_ptr_t fptrCSXInitialize; /**< The Cy_CapSense_CSXInitialize() function pointer */
+ cy_func_capsense_csx_disablemode_ptr_t fptrCSXDisableMode; /**< The Cy_CapSense_CSXDisableMode() function pointer */
+ cy_func_capsense_csx_scan_isr_ptr_t fptrCSXScanISR; /**< The Cy_CapSense_CSXScanISR() function pointer */
cy_func_capsense_adaptive_filter_initialize_lib_ptr_t fptrAdaptiveFilterInitializeLib;
- /**< The Cy_CapSense_AdaptiveFilterInitialize_Lib() function pointer*/
- cy_func_capsense_adaptive_filter_run_lib_ptr_t fptrAdaptiveFilterRunLib; /**< The Cy_CapSense_AdaptiveFilterRun_Lib() function pointer*/
+ /**< The Cy_CapSense_AdaptiveFilterInitialize_Lib() function pointer */
+ cy_func_capsense_adaptive_filter_run_lib_ptr_t fptrAdaptiveFilterRunLib; /**< The Cy_CapSense_AdaptiveFilterRun_Lib() function pointer */
cy_func_capsense_ballistic_multiplier_lib_ptr_t fptrBallisticMultiplierLib;
- /**< The Cy_CapSense_BallisticMultiplier_Lib() function pointer*/
+ /**< The Cy_CapSense_BallisticMultiplier_Lib() function pointer */
cy_func_capsense_initialize_all_filters_ptr_t fptrInitializeAllFilters;
- /**< The Cy_CapSense_InitializeAllFilters() function pointer*/
+ /**< The Cy_CapSense_InitializeAllFilters() function pointer */
cy_func_capsense_ft_run_enabled_filters_internal_ptr_t fptrFtRunEnabledFiltersInternal;
- /**< The Cy_CapSense_FtRunEnabledFiltersInternal() function pointer*/
+ /**< The Cy_CapSense_FtRunEnabledFiltersInternal() function pointer */
cy_func_capsense_process_position_filters_ptr_t fptrProcessPositionFilters;
- /**< The Cy_CapSense_ProcessPositionFilters() function pointer*/
+ /**< The Cy_CapSense_ProcessPositionFilters() function pointer */
cy_func_capsense_run_position_filters_ptr_t fptrRunPositionFilters;
- /**< The Cy_CapSense_RunPositionFilters() function pointer*/
+ /**< The Cy_CapSense_RunPositionFilters() function pointer */
cy_func_capsense_init_position_filters_ptr_t fptrInitPositionFilters;
- /**< The Cy_CapSense_InitPositionFilters() function pointer*/
+ /**< The Cy_CapSense_InitPositionFilters() function pointer */
cy_func_capsense_dp_process_button_ptr_t fptrDpProcessButton;
- /**< The Cy_CapSense_DpProcessButton() function pointer*/
+ /**< The Cy_CapSense_DpProcessButton() function pointer */
cy_func_capsense_dp_process_slider_ptr_t fptrDpProcessSlider;
- /**< The Cy_CapSense_DpProcessSlider() function pointer*/
+ /**< The Cy_CapSense_DpProcessSlider() function pointer */
cy_func_capsense_dp_process_csd_matrix_ptr_t fptrDpProcessCsdMatrix;
- /**< The Cy_CapSense_DpProcessCsdMatrix() function pointer*/
+ /**< The Cy_CapSense_DpProcessCsdMatrix() function pointer */
cy_func_capsense_dp_process_csd_touchpad_ptr_t fptrDpProcessCsdTouchpad;
- /**< The Cy_CapSense_DpProcessCsdTouchpad() function pointer*/
+ /**< The Cy_CapSense_DpProcessCsdTouchpad() function pointer */
cy_func_capsense_dp_advanced_centroid_touchpad_ptr_t fptrDpAdvancedCentroidTouchpad;
- /**< The Cy_CapSense_DpAdvancedCentroidTouchpad() function pointer*/
+ /**< The Cy_CapSense_DpAdvancedCentroidTouchpad() function pointer */
cy_func_capsense_dp_process_proximity_ptr_t fptrDpProcessProximity;
- /**< The Cy_CapSense_DpProcessProximity() function pointer*/
+ /**< The Cy_CapSense_DpProcessProximity() function pointer */
cy_func_capsense_dp_process_csx_touchpad_ptr_t fptrDpProcessCsxTouchpad;
- /**< The Cy_CapSense_DpProcessCsxTouchpad() function pointer*/
+ /**< The Cy_CapSense_DpProcessCsxTouchpad() function pointer */
cy_func_capsense_calibrate_all_csd_widgets_ptr_t fptrCalibrateAllCsdWidgets;
- /**< The Cy_CapSense_CalibrateAllCsdWidgets() function pointer*/
+ /**< The Cy_CapSense_CalibrateAllCsdWidgets() function pointer */
cy_func_capsense_csd_calibrate_widget_ptr_t fptrCSDCalibrateWidget;
- /**< The Cy_CapSense_CSDCalibrateWidget() function pointer*/
+ /**< The Cy_CapSense_CSDCalibrateWidget() function pointer */
cy_func_capsense_calibrate_all_csx_widgets_ptr_t fptrCalibrateAllCsxWidgets;
- /**< The Cy_CapSense_CalibrateAllCsxWidgets() function pointer*/
- cy_func_capsense_ss_auto_tune_ptr_t fptrSsAutoTune; /**< The Cy_CapSense_SsAutoTune() function pointer*/
+ /**< The Cy_CapSense_CalibrateAllCsxWidgets() function pointer */
+ cy_func_capsense_ss_auto_tune_ptr_t fptrSsAutoTune; /**< The Cy_CapSense_SsAutoTune() function pointer */
cy_func_capsense_run_noise_envelope_lib_ptr_t fptrRunNoiseEnvelopeLib;
- /**< The Cy_CapSense_RunNoiseEnvelope_Lib() function pointer*/
+ /**< The Cy_CapSense_RunNoiseEnvelope_Lib() function pointer */
cy_func_capsense_dp_update_thresholds_ptr_t fptrDpUpdateThresholds;
- /**< The Cy_CapSense_DpUpdateThresholds() function pointer*/
+ /**< The Cy_CapSense_DpUpdateThresholds() function pointer */
cy_func_capsense_initialize_noise_envelope_lib_ptr_t fptrInitializeNoiseEnvelopeLib;
- /**< The Cy_CapSense_InitializeNoiseEnvelope_Lib() function pointer*/
+ /**< The Cy_CapSense_InitializeNoiseEnvelope_Lib() function pointer */
+ cy_func_capsense_bist_initialize_ptr_t fptrBistInitialize;
+ /**< The Cy_CapSense_BistInitialize() function pointer */
+ cy_func_capsense_bist_disable_mode_ptr_t fptrBistDisableMode;
+ /**< The Cy_CapSense_BistDisableMode() function pointer */
+ cy_func_capsense_bist_ds_initialize_ptr_t fptrBistDsInitialize;
+ /**< The Cy_CapSense_BistDsInitialize() function pointer */
} cy_stc_capsense_fptr_config_t;
/** \} */
@@ -772,20 +984,40 @@ typedef struct
uint32_t Cy_CapSense_IsAnyWidgetActive(const cy_stc_capsense_context_t * context);
uint32_t Cy_CapSense_IsWidgetActive(
- uint32_t widgetId,
+ uint32_t widgetId,
const cy_stc_capsense_context_t * context);
uint32_t Cy_CapSense_IsSensorActive(
- uint32_t widgetId,
- uint32_t sensorId,
+ uint32_t widgetId,
+ uint32_t sensorId,
const cy_stc_capsense_context_t * context);
uint32_t Cy_CapSense_IsProximitySensorActive(
- uint32_t widgetId,
- uint32_t sensorId,
+ uint32_t widgetId,
+ uint32_t sensorId,
const cy_stc_capsense_context_t * context);
cy_stc_capsense_touch_t * Cy_CapSense_GetTouchInfo(
- uint32_t widgetId,
+ uint32_t widgetId,
const cy_stc_capsense_context_t * context);
+/** \} */
+
+
+/******************************************************************************/
+/** \addtogroup group_capsense_low_level *//** \{ */
+/******************************************************************************/
+
+cy_status Cy_CapSense_GetParam(
+ uint32_t paramId,
+ uint32_t * value,
+ const uint8_t * ptrTuner,
+ const cy_stc_capsense_context_t * context);
+cy_status Cy_CapSense_SetParam(
+ uint32_t paramId,
+ uint32_t value,
+ uint8_t * ptrTuner,
+ cy_stc_capsense_context_t * context);
+uint16_t Cy_CapSense_GetCRC(
+ const uint8_t *ptrData,
+ uint32_t len);
/** \} */
@@ -915,6 +1147,15 @@ void Cy_CapSense_RunNoiseEnvelope_Lib_Call(
const cy_stc_capsense_context_t * context);
cy_status Cy_CapSense_SsAutoTune_Call(
cy_stc_capsense_context_t * context);
+void Cy_CapSense_BistInitialize_Call(
+ cy_stc_capsense_context_t * context);
+void Cy_CapSense_BistDisableMode_Call(
+ cy_stc_capsense_context_t * context);
+void Cy_CapSense_BistDsInitialize_Call(
+ cy_stc_capsense_context_t * context);
+uint16_t Cy_CapSense_GetCrcWidget(
+ uint32_t widgetId,
+ cy_stc_capsense_context_t * context);
/** \} \endcond */
diff --git a/cy_capsense_tuner.c b/cy_capsense_tuner.c
index dd146a2..f90cb14 100644
--- a/cy_capsense_tuner.c
+++ b/cy_capsense_tuner.c
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_tuner.c
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides the source code for the Tuner module functions.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -21,7 +21,7 @@
#include "cy_capsense_control.h"
#include "cy_capsense_common.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
/*******************************************************************************
@@ -185,7 +185,7 @@ uint32_t Cy_CapSense_RunTuner(cy_stc_capsense_context_t * context)
receiveCallback(&commandPacket, &tunerStructure, context);
/* If command exists and is correct then read command */
- if ((NULL != commandPacket) || (NULL != tunerStructure))
+ if ((NULL != commandPacket) && (NULL != tunerStructure))
{
if (CY_CAPSENSE_COMMAND_OK == Cy_CapSense_CheckTunerCmdIntegrity(commandPacket))
{
@@ -227,29 +227,32 @@ uint32_t Cy_CapSense_RunTuner(cy_stc_capsense_context_t * context)
break;
case (uint16_t)CY_CAPSENSE_TU_CMD_WRITE_E:
- /* Tuner state is not changed */
- cmdOffset = (uint32_t)((uint32_t)commandPacket[CY_CAPSENSE_COMMAND_OFFS_0_IDX] << CY_CAPSENSE_MSB_SHIFT) |
- (uint32_t)commandPacket[CY_CAPSENSE_COMMAND_OFFS_1_IDX];
- cmdSize = commandPacket[CY_CAPSENSE_COMMAND_SIZE_0_IDX];
-
- if (1u == cmdSize)
- {
- tunerStructure[cmdOffset] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 3u];
- }
- else if (2u == cmdSize)
- {
- tunerStructure[cmdOffset + 1u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 2u];
- tunerStructure[cmdOffset + 0u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 3u];
- }
- else
+ if((NULL != receiveCallback) && (NULL != commandPacket) && (NULL != tunerStructure))
{
- tunerStructure[cmdOffset + 3u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 0u];
- tunerStructure[cmdOffset + 2u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 1u];
- tunerStructure[cmdOffset + 1u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 2u];
- tunerStructure[cmdOffset + 0u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 3u];
- }
+ /* Tuner state is not changed */
+ cmdOffset = (uint32_t)((uint32_t)commandPacket[CY_CAPSENSE_COMMAND_OFFS_0_IDX] << CY_CAPSENSE_MSB_SHIFT) |
+ (uint32_t)commandPacket[CY_CAPSENSE_COMMAND_OFFS_1_IDX];
+ cmdSize = commandPacket[CY_CAPSENSE_COMMAND_SIZE_0_IDX];
- updateFlag = 1u;
+ if (1u == cmdSize)
+ {
+ tunerStructure[cmdOffset] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 3u];
+ }
+ else if (2u == cmdSize)
+ {
+ tunerStructure[cmdOffset + 1u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 2u];
+ tunerStructure[cmdOffset + 0u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 3u];
+ }
+ else
+ {
+ tunerStructure[cmdOffset + 3u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 0u];
+ tunerStructure[cmdOffset + 2u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 1u];
+ tunerStructure[cmdOffset + 1u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 2u];
+ tunerStructure[cmdOffset + 0u] = commandPacket[CY_CAPSENSE_COMMAND_DATA_0_IDX + 3u];
+ }
+
+ updateFlag = 1u;
+ }
break;
default:
@@ -356,7 +359,7 @@ uint32_t Cy_CapSense_CheckTunerCmdIntegrity(const uint8_t * commandPacket)
{
crcValue = (uint16_t)((uint16_t)commandPacket[CY_CAPSENSE_COMMAND_CRC_0_IDX] << CY_CAPSENSE_MSB_SHIFT);
crcValue |= (uint16_t)commandPacket[CY_CAPSENSE_COMMAND_CRC_1_IDX];
- if (crcValue != Cy_CapSense_CalculateCrc16(&commandPacket[0u], CY_CAPSENSE_COMMAND_CRC_DATA_SIZE))
+ if (crcValue != Cy_CapSense_GetCRC(&commandPacket[0u], CY_CAPSENSE_COMMAND_CRC_DATA_SIZE))
{
cmdCheckStatus = CY_CAPSENSE_WRONG_CRC;
}
@@ -365,57 +368,6 @@ uint32_t Cy_CapSense_CheckTunerCmdIntegrity(const uint8_t * commandPacket)
return cmdCheckStatus;
}
-
-/*******************************************************************************
-* Function Name: Cy_CapSense_CalculateCrc16
-****************************************************************************//**
-*
-* Calculates CRC for the specified buffer and length. CRC Poly: 0xAC9A
-*
-* This API is used for the CRC protection of a packet received from
-* the CapSense Tuner tool. CRC polynomial is 0xAC9A. It has a Hamming
-* distance 5 for data words up to 241 bits.
-*
-* Reference: "P. Koopman, T. Chakravarthy,
-* "Cyclic Redundancy Code (CRC) Polynomial Selection for Embedded Networks",
-* The International Conference on Dependable Systems and Networks, DSN-2004"
-*
-* \param ptrData
-* The pointer to the data.
-*
-* \param len
-* The length of the data in bytes.
-*
-* \return
-* Returns a calculated CRC-16 value.
-*
-*******************************************************************************/
-uint16 Cy_CapSense_CalculateCrc16(const uint8_t *ptrData, uint32_t len)
-{
- uint32_t idx;
- uint32_t actualCrc = 0u;
- const uint16_t crcTable[] =
- {
- 0x0000u, 0xAC9Au, 0xF5AEu, 0x5934u, 0x47C6u, 0xEB5Cu, 0xB268u, 0x1EF2u,
- 0x8F8Cu, 0x2316u, 0x7A22u, 0xD6B8u, 0xC84Au, 0x64D0u, 0x3DE4u, 0x917Eu
- };
-
- for (;len-- > 0u;)
- {
- /* Process HI Nibble */
- idx = ((actualCrc >> 12u) ^ (((uint32)*ptrData) >> 4u)) & 0xFLu;
- actualCrc = crcTable[idx] ^ (actualCrc << 4u);
-
- /* Process LO Nibble */
- idx = ((actualCrc >> 12u) ^ (uint32)*ptrData) & 0xFLu;
- actualCrc = crcTable[idx] ^ (actualCrc << 4u);
-
- ptrData++;
- }
-
- return (uint16_t)actualCrc;
-}
-
#endif /* CY_IP_MXCSDV2 */
diff --git a/cy_capsense_tuner.h b/cy_capsense_tuner.h
index 9c9504d..43558ef 100644
--- a/cy_capsense_tuner.h
+++ b/cy_capsense_tuner.h
@@ -1,13 +1,13 @@
/***************************************************************************//**
* \file cy_capsense_tuner.h
-* \version 2.0
+* \version 2.10
*
* \brief
* This file provides CapSense MW Tuner module function prototypes.
*
********************************************************************************
* \copyright
-* Copyright 2018-2019, Cypress Semiconductor Corporation. All rights reserved.
+* Copyright 2018-2020, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
@@ -20,7 +20,7 @@
#include "cy_syslib.h"
#include "cy_capsense_structure.h"
-#if defined(CY_IP_MXCSDV2)
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
#if defined(__cplusplus)
extern "C" {
@@ -83,7 +83,6 @@ uint32_t Cy_CapSense_CheckTunerCmdIntegrity(const uint8_t * commandPacket);
/******************************************************************************/
void Cy_CapSense_TuInitialize(cy_stc_capsense_context_t * context);
-uint16 Cy_CapSense_CalculateCrc16(const uint8_t *ptrData, uint32_t len);
/*******************************************************************************
@@ -105,6 +104,29 @@ __STATIC_INLINE uint32_t Cy_CapSense_CheckCommandIntegrity(const uint8_t * comma
return(Cy_CapSense_CheckTunerCmdIntegrity(commandPacket));
}
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CalculateCrc16
+****************************************************************************//**
+*
+* This function is obsolete and kept for backward compatibility only.
+* The Cy_CapSense_GetCRC() function should be used instead.
+*
+* \param ptrData
+* The pointer to the data.
+*
+* \param len
+* The length of the data in bytes.
+*
+* \return
+* Returns a calculated CRC-16 value.
+*
+*******************************************************************************/
+__STATIC_INLINE uint16_t Cy_CapSense_CalculateCrc16(const uint8_t *ptrData, uint32_t len)
+{
+ return(Cy_CapSense_GetCRC(ptrData, len));
+}
+
/** \} \endcond */
diff --git a/docs/capsense_api_reference_manual/html/annotated.html b/docs/capsense_api_reference_manual/html/annotated.html
index 24ca871..f1014d8 100644
--- a/docs/capsense_api_reference_manual/html/annotated.html
+++ b/docs/capsense_api_reference_manual/html/annotated.html
@@ -6,7 +6,7 @@
-Cypress CapSense Middleware Library 2.0: Data Structures
+Cypress CapSense Middleware Library 2.10: Data Structures
@@ -30,7 +30,7 @@
Declares the structure that is intended to store the cy_stc_capsense_widget_context_t data structure fields, the CRC checking should be applied for
@@ -134,7 +137,7 @@
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
diff --git a/docs/capsense_api_reference_manual/html/classes.html b/docs/capsense_api_reference_manual/html/classes.html
index 5bb64e2..550c34f 100644
--- a/docs/capsense_api_reference_manual/html/classes.html
+++ b/docs/capsense_api_reference_manual/html/classes.html
@@ -6,7 +6,7 @@
-Cypress CapSense Middleware Library 2.0: Data Structure Index
+Cypress CapSense Middleware Library 2.10: Data Structure Index
@@ -30,7 +30,7 @@
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
The 'cy_capsense_context' variable that is used as the parameter of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions is declared in the cycfg_capsense.h file.
The CapSense_ISR_cfg variable should be declared by the application program according to the examples below:
- For CM0+ core:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = NvicMux2_IRQn, /* CM0+ interrupt is NVIC #2 */
.cm0pSrc = csd_interrupt_IRQn, /* Source of NVIC #2 is the CSD interrupt */
.intrPriority = 3u, /* Interrupt priority is 3 */
};
For CM4 core:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* Interrupt source is the CSD interrupt */
.intrPriority = 7u, /* Interrupt priority is 7 */
};
The CapSense interrupt handler should be declared by the application program according to the example below:
The CapSense_HW is the pointer to the base register address of the CSD HW block. A macro for the pointer can be found in cycfg_peripherals.h file defined as <Csd_Personality_Name>_HW. If no name specified then the default name is used csd_<Block_Number>_csd_<Block_Number>_HW.
+ For CM0+ core:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* CM0+ interrupt is NVIC #2 */
.intrPriority = 3u, /* Interrupt priority is 3 */
};
For CM4 core:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* Interrupt source is the CSD interrupt */
.intrPriority = 7u, /* Interrupt priority is 7 */
};
The CapSense interrupt handler should be declared by the application program according to the example below:
The CapSense_HW is the pointer to the base register address of the CSD HW block. A macro for the pointer can be found in cycfg_peripherals.h file defined as <Csd_Personality_Name>_HW. If no name specified then the default name is used csd_<Block_Number>_csd_<Block_Number>_HW.
The 'cy_capsense_context' variable that is used as the parameter of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions is declared in the cycfg_capsense.h file.
The CapSense_ISR_cfg variable should be declared by the application program according to the examples below:
- For CM0+ core:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = NvicMux2_IRQn, /* CM0+ interrupt is NVIC #2 */
.cm0pSrc = csd_interrupt_IRQn, /* Source of NVIC #2 is the CSD interrupt */
.intrPriority = 3u, /* Interrupt priority is 3 */
};
For CM4 core:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* Interrupt source is the CSD interrupt */
.intrPriority = 7u, /* Interrupt priority is 7 */
};
The CapSense interrupt handler should be declared by the application program according to the example below:
The CapSense_HW is the pointer to the base register address of the CSD HW block. A macro for the pointer can be found in cycfg_peripherals.h file defined as <Csd_Personality_Name>_HW. If no name is specified then the default name is used csd_<Block_Number>_csd_<Block_Number>_HW.
+ For CM0+ core:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* CM0+ interrupt is NVIC #2 */
.intrPriority = 3u, /* Interrupt priority is 3 */
};
For CM4 core:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* Interrupt source is the CSD interrupt */
.intrPriority = 7u, /* Interrupt priority is 7 */
};
The CapSense interrupt handler should be declared by the application program according to the example below:
The CapSense_HW is the pointer to the base register address of the CSD HW block. A macro for the pointer can be found in cycfg_peripherals.h file defined as <Csd_Personality_Name>_HW. If no name is specified then the default name is used csd_<Block_Number>_csd_<Block_Number>_HW.
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 to scan and process data for a specific widget. This function is called only after all the sensors in the widgets are scanned. A disabled widget is not processed by this function.
-
A pipeline scan method (i.e. during scanning of a widget performing processing of the previously scanned widget) can be implemented using this function and it may reduce the total execution time, increase the refresh rate and decrease the average power consumption.
A pipeline scan method (i.e. during scanning of a current widget (N), perform 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.
Handles CPU active to System Deep Sleep power mode transition for the CapSense middleware.
+
Calling this function directly from the application program is not recommended. Instead, Cy_SysPm_CpuEnterDeepSleep() should be used for the CPU active to System Deep Sleep power mode transition of the device.
Note
After the CPU Deep Sleep transition, the device automatically goes to System Deep Sleep if all conditions are fulfilled: another core is in CPU Deep Sleep, all the peripherals are ready to System Deep Sleep, etc. (see details in the device TRM).
+
For proper operation of the CapSense middleware during the CPU active to System Deep Sleep mode transition, a callback to this function should be registered using the Cy_SysPm_RegisterCallback() function with CY_SYSPM_DEEPSLEEP type. After the callback is registered, this function is called by the Cy_SysPm_CpuEnterDeepSleep() function to prepare the middleware to the device power mode transition.
+
When this function is called with CY_SYSPM_CHECK_READY as input, this function returns CY_SYSPM_SUCCESS if no scanning is in progress. Otherwise CY_SYSPM_FAIL is returned. If CY_SYSPM_FAIL status is returned, a device cannot change the power mode without completing the current scan as a transition to System Deep Sleep during the scan can disrupt the middleware operation.
+
For details of SysPm types and macros refer to the SysPm section of the PDL documentation.
Parameters
callbackParams
Refer to the description of the cy_stc_syspm_callback_params_t type in the Peripheral Driver Library documentation.
The function (Gesture detection functionality) requires a timestamp for its operation. The timestamp should be initialized and maintained in the application program prior to calling this function. See the descriptions of the Cy_CapSense_SetGestureTimestamp() and Cy_CapSense_IncrementGestureTimestamp() functions for details.
Runs built-in self-tests specified by the test enable mask.
+
The function performs various self-tests on all the enabled widgets and sensors in the project. Select the required set of tests using the bit-mask in testEnMask parameter.
+
Use CY_CAPSENSE_TST_RUN_SELF_TEST_MASK to execute all the self-tests or any combination of the masks (defined in testEnMask parameter) to specify the desired test list.
+
To execute a single-element test (i.e. for one widget or one sensor), the following low-level functions are available:
Refer to these functions descriptions for detail information on the corresponding test.
+
Parameters
+
+
testEnMask
Specifies the tests to be executed. Each bit corresponds to one test. It is possible to launch the function with any combination of the available tests.
+
CY_CAPSENSE_BIST_CRC_WDGT - Verifies the RAM widget structure CRC for all the widgets.
+
CY_CAPSENSE_BIST_SNS_INTEGRITY - Checks all the sensors for a short to GND / VDD / other sensors.
+
CY_CAPSENSE_BIST_SNS_CAP - Measures all the sensors capacitance.
+
CY_CAPSENSE_BIST_SHIELD_CAP - Measures the shield capacitance.
+
CY_CAPSENSE_BIST_EXTERNAL_CAP - Measures the capacitance of the available external capacitors.
+
CY_CAPSENSE_BIST_VDDA - Measures the VDDA voltage.
+
CY_CAPSENSE_TST_RUN_SELF_TEST_MASK - Executes all available tests.
Returns a bit-mask with a status of execution of the specified tests:
+
CY_CAPSENSE_BIST_SUCCESS_E - All the tests passed successfully.
+
CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the configuration. The function was not performed.
+
CY_CAPSENSE_BIST_BAD_PARAM_E - A non-defined test was requested in the testEnMask parameter or the context is a NULL pointer. The function was not performed.
+
CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a previous operation. The function was not performed.
+
CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during the measurement, you may need to repeat the measurement.
+
CY_CAPSENSE_BIST_FAIL_E - Any of tests specified by the testEnMask parameters has faulted.
This function does not start sensor scanning. The Cy_CapSense_Scan() function must be called to start the scan sensors in the widget. If this function is called more than once, it does not break the middleware operation, but only the last initialized widget is in effect.
The status of a sensor scan must be checked using the Cy_CapSense_IsBusy() function prior to starting a next scan or setting up another widget.
Then, the application program should configure and enable the CSD block interrupt between calls of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions:
/* Capture the CSD HW block and initialize it to the default state. */
CapSense_HW is the pointer to the base register address of the CSD HW block. A macro for the pointer can be found in the cycfg_peripherals.h file defined as <Csd_Personality_Name>_HW. If no name specified, the default name is used csd_<Block_Number>_csd_<Block_Number>_HW.
+ For Core CM0+:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* CM0+ interrupt is NVIC #2 */
.intrPriority = 3u, /* Interrupt priority is 3 */
};
For Core CM4:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* Interrupt source is the CSD interrupt */
.intrPriority = 7u, /* Interrupt priority is 7 */
};
The CapSense interrupt handler should be defined by the application program according to the example below:
Then, the application program should configure and enable the CSD block interrupt between calls of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions:
/* Capture the CSD HW block and initialize it to the default state. */
CapSense_HW is the pointer to the base register address of the CSD HW block. A macro for the pointer can be found in the cycfg_peripherals.h file defined as <Csd_Personality_Name>_HW. If no name specified, the default name is used csd_<Block_Number>_csd_<Block_Number>_HW.
An example of sharing the CSD HW block by the CapSense and CSDADC middleware.
- Declares the CapSense_ISR_cfg variable:
const cy_stc_sysint_t CapSense_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* Interrupt source is the CSD interrupt */
.intrPriority = 7u, /* Interrupt priority is 7 */
};
Declares the CSDADC_ISR_cfg variable:
const cy_stc_sysint_t CSDADC_ISR_cfg =
{
.intrSrc = csd_interrupt_IRQn, /* Interrupt source is the CSD interrupt */
Checks if the baseline of the specified sensor is not corrupted by comparing it with its inverse copy and checks if the baseline is within the specified range. More...
Measures a VDDA voltage, returns the measured voltage in millivolts through the ptrValue argument and stores it to the .vddaVoltage field of the cy_stc_capsense_bist_context_t structure. More...
Performs a successive approximation search algorithm to find appropriate modulator and compensation IDAC (if enabled) values for all sensors in the specified widget that provide the raw count to the level specified by the target parameter.
-
Calibration returns CYRET_BAD_DATA if the achieved raw count is outside of the range specified by the target and acceptable calibration deviation parameters.
+
Calibration returns CY_RET_BAD_DATA if the achieved raw count is outside of the range specified by the target and acceptable calibration deviation parameters.
This function could be used when the CSD Enable IDAC auto-calibration parameter is enabled. Do not use this function when the SmartSense auto-tuning mode is configured.
Cy_CapSense_CSDConnectSns() function, hence all GPIOs connected using this function must be disconnected using the Cy_CapSense_CSDDisconnectSns() function prior to initializing new widgets. Use this function in StartSample callback (see the Callbacks section for details) or with low-level functions that perform a single-sensor scanning.
+
The functions that perform a setup and scan of a sensor/widget do not take into account changes in the design made by the Cy_CapSense_CSDConnectSns() function, hence all GPIOs connected using this function must be disconnected using the Cy_CapSense_CSDDisconnectSns() function prior to initializing new widgets. Use this function in StartSample callback (see the Callbacks section for details) or with low-level functions that perform a single-sensor scanning.
Scanning should be completed before calling this function.
This function works identically to the Cy_CapSense_CSDConnectSns() function except it disconnects the specified port pin used by the sensor.
+
This function can be used to disconnect a sensor connected using the Cy_CapSense_CSDConnectSns() function. In addition, this function can be used to customize a default sensor connection by disconnecting one or more already connected sensors prior to initiating a scan of the sensor.
+
This function works identically to the Cy_CapSense_CSDConnectSns() function except it disconnects the specified port pin used by the sensor.
Scanning should be completed before calling this function.
Performs a successive approximation search algorithm to find appropriate IDAC values for all sensors in the specified widget that provide the raw count to the level specified by the target parameter.
-
Calibration returns CYRET_BAD_DATA if the achieved raw count is outside of the range specified by the target and acceptable calibration deviation parameters.
+
Calibration returns CY_RET_BAD_DATA if the achieved raw count is outside of the range specified by the target and acceptable calibration deviation parameters.
This function could be used when the CSX Enable IDAC auto-calibration parameter is enabled.
This function performs scanning of a specific sensor in the widget previously initialized using the Cy_CapSense_CSXSetupWidgetExt() function.
This function is called when no scanning is in progress. I.e. Cy_CapSense_IsBusy() returns a non-busy status and the widget must be preconfigured using Cy_CapSense_CSXSetupWidgetExt() function prior to calling this function. Calling this function directly from the application program is not recommended. This function is used to implement only the user's specific use cases (for example faster execution).
-
This function does not disconnect sensor GPIOs from CSD HW block at the end of a scan, therefore making subsequent scan of the same sensor is faster. If sensor must be disconnected after the scan, the Cy_CapSense_CSXDisconnectTx() or Cy_CapSense_CSXDisconnectRx() functions can be used.
+
This function does not disconnect sensor GPIOs from CSD HW block at the end of a scan, therefore making subsequent scan of the same sensor is faster. If sensor must be disconnected after the scan, the Cy_CapSense_CSXDisconnectTx() or Cy_CapSense_CSXDisconnectRx() functions can be used.
Cy_CapSense_CSXConnectRx() function. Hence all GPIOs connected using this function must be disconnected using the Cy_CapSense_CSXDisconnectRx() function prior to initializing new widgets. Use this function in StartSample callback (see the Callbacks section for details) or with low-level functions that perform a single-sensor scanning.
+
The functions that perform a setup and scan of a sensor/widget do not take into account changes in the design made by the Cy_CapSense_CSXConnectRx() function. Hence all GPIOs connected using this function must be disconnected using the Cy_CapSense_CSXDisconnectRx() function prior to initializing new widgets. Use this function in StartSample callback (see the Callbacks section for details) or with low-level functions that perform a single-sensor scanning.
Scanning should be completed before calling this function.
Cy_CapSense_CSXConnectTx() function. Hence all GPIOs connected using this function must be disconnected using the Cy_CapSense_CSXDisconnectTx() function prior to initializing new widgets. Use this function in StartSample callback (see the Callbacks section for details) or with low-level functions that perform a single-sensor scanning.
+
The functions that perform a setup and scan of a sensor/widget do not take into account changes in the design made by the Cy_CapSense_CSXConnectTx() function. Hence all GPIOs connected using this function must be disconnected using the Cy_CapSense_CSXDisconnectTx() function prior to initializing new widgets. Use this function in StartSample callback (see the Callbacks section for details) or with low-level functions that perform a single-sensor scanning.
Scanning should be completed before calling this function.
This function can be used to disconnect a sensor connected using the Cy_CapSense_CSXConnectRx() function. In addition, this function can be used to customize default sensor connection by disconnecting one or more already connected sensors prior to initiating scan of the sensor.
This function works identically to the Cy_CapSense_CSDConnectRx() function except it disconnects the specified port pin used by the sensor.
Scanning should be completed before calling this function.
This function can be used to disconnect a sensor connected using the Cy_CapSense_CSXConnectTx() function. In addition, this function can be used to customize default sensor connection by disconnecting one or more already connected sensors prior to initiating scan of the sensor.
This function works identically to the Cy_CapSense_CSDConnectTx() function except it disconnects the specified port pin used by the sensor.
Scanning should be completed before calling this function.
This function validates the data integrity of the cy_stc_capsense_widget_context_t data structure of the specified widget by calculating the CRC and comparing it with the stored CRC value of the specified widget.
+
Initially, after the device power up, the Cy_CapSense_Enable() function calculates CRC for each widget and stores them in the .ptrWdgtCrc[] array of the cy_stc_capsense_bist_context_t structure. The test execution compares this stored CRC value with the newly calculated and if the stored and calculated CRC values differ:
The CY_CAPSENSE_BIST_CRC_WDGT bit is set in the .testResultMask field.
+
+
The function never clears the CY_CAPSENSE_BIST_CRC_WDGT bit. If the CY_CAPSENSE_BIST_CRC_WDGT bit is set, the wdgtCrcCalc and .crcWdgtId fields are not updated.
You can initiate this test by the Cy_CapSense_RunSelfTest() function with the CY_CAPSENSE_BIST_CRC_WDGT mask as an input.
+
The function clears the CY_CAPSENSE_WD_WORKING_MASK bit of the .status field in cy_stc_capsense_widget_context_t structure if the calculated CRC value differs to the stored CRC value. Those non-working widgets are skipped by the high-level scanning and processing functions. Restoring a widget to its working state should be done by the application level.
+
For details of the used CRC algorithm, refer to the Cy_CapSense_GetCRC() function.
+
Parameters
+
+
widgetId
Specifies the ID number of the widget. A macro for the widget ID can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as CY_CAPSENSE_<WidgetName>_WDGT_ID.
Checks the raw count of the specified widget/sensor is within the specified range.
+
The raw count is within a specific range (based on the calibration target) for good units. The function checks whether or not the raw count is within the user-defined limits in the ranges function arguments. If the raw count is out of limits, this function sets the CY_CAPSENSE_BIST_RAW_INTEGRITY bit in the .testResultMask field of the cy_stc_capsense_bist_context_t structure.
Use this function to verify the uniformity of sensors, for example, at mass-production or during an operation phase together with the Cy_CapSense_CheckIntegritySensorBaseline() function.
+
Parameters
+
+
widgetId
Specifies the ID number of the widget. A macro for the widget ID can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as CY_CAPSENSE_<WidgetName>_WDGT_ID.
+
sensorId
Specifies the ID number of the sensor within the widget. A macro for the sensor ID within the specified widget can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_ID.
+
rawcountHighLimit
Specifies the upper limit for the widget/sensor raw count.
+
rawcountLowLimit
Specifies the lower limit for the widget/sensor raw count.
Checks if the baseline of the specified sensor is not corrupted by comparing it with its inverse copy and checks if the baseline is within the specified range.
+
The function checks whether or not the baseline binary inverted to its inverse copy is saved to the self-test baseline-inverse structure and is within the user-defined limits. If the baseline does not match its inverse copy or if the baseline is out of the user-defined limits, the function sets the CY_CAPSENSE_BIST_BSLN_INTEGRITY bit in the .testResultMask field of the cy_stc_capsense_bist_context_t structure.
+
The test is integrated into the CapSense Middleware. All CapSense processing functions like Cy_CapSense_ProcessAllWidgets() or Cy_CapSense_UpdateSensorBaseline() automatically verify the baseline value before using it and update its inverse copy after processing. If a baseline update fails, a CY_RET_BAD_DATA result is returned. The baseline initialization functions do not verify the baseline and update the baseline inverse copy.
Use this function to verify the uniformity of sensors, for example, at mass-production or during an operation phase together with the Cy_CapSense_CheckIntegritySensorRawcount() function.
+
Parameters
+
+
widgetId
Specifies the ID number of the widget. A macro for the widget ID can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as CY_CAPSENSE_<WidgetName>_WDGT_ID.
+
sensorId
Specifies the ID number of the sensor within the widget. A macro for the sensor ID within the specified widget can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_ID.
Checks the specified widget/sensor for shorts to GND, VDD or other sensors.
+
This function performs several sub-tests to verify the specified sensor is not electrically shorted and is in a good condition to reliably detect user interactions.
+
This function performs tests to check if the specified sensor is shorted to:
+
GND
+
VDD
+
Other GPIOs used by CapSense (such as sensors, Tx, Rx, shield electrodes, and external capacitors)
+
Other non-CapSense GPIOs (only if they are configured in a strong high or low state during the test execution).
+
+
The absolute resistance of an electrical short must be less than 1500 Ohm including all series resistors on a sensor for a short to be detected to GND, VDD or GPIOs. For example, if a series resistor on a sensor is 560 Ohm (as recommended) and the sensor is shorted with another sensor, the function can detect a short with a short resistance up to 380 Ohm as there are two 560 ohm resistors between the shorted sensor GPIOs.
+
The function executes the following flow to detect a short:
+
Configures all CapSense controlled GPIOs to strong-drive-high, and the specified sensor GPIO to resistive pull down mode.
+
Waits for a delay (defined by .snsIntgShortSettlingTime field of the cy_stc_capsense_bist_context_t structure) to get established all transient processes.
+
Checks the status of the specified sensor for the expected state (logic low).
+
Configures all CapSense controlled GPIOs to strong-drive-low, and the specified sensor GPIO to resistive pull up mode.
+
Waits for the above mentioned delay.
+
Checks the status of the specified sensor for the expected state (logic high).
+
Stores the test result in the CapSense Data Structure. A short is reported only when the sensor status check returns an unexpected state.
+
+
Due to the sensor parasitic capacitance and internal pull-up/down resistance, logic high-to-low (and vice versa) transitions require a settling time before checking the sensor status. A 2us delay is used as a settling time and can be changed using the .snsIntgShortSettlingTime field of the cy_stc_capsense_bist_context_t structure.
+
If a short is detected this function updates the following statuses:
If CY_CAPSENSE_BIST_SNS_SHORT is already set due to a previously detected fault on any of the sensor, this function does not update the .shortedWdId and .shortedSnsId fields. For this reason, clear the CY_CAPSENSE_BIST_SNS_SHORT bit prior calling this function.
+
The widget is disabled by clearing the CY_CAPSENSE_WD_WORKING_MASK bit in the .status field of the cy_stc_capsense_widget_context_t structure of the specified widget. The disabled widget is ignored by high-level functions of scanning / data processing. To restore the widget operation the application layer should manually set the CY_CAPSENSE_WD_WORKING_MASK bit.
+
+
To check all the project sensors at once, use the Cy_CapSense_RunSelfTest() function with the CY_CAPSENSE_BIST_SNS_SHORT mask.
+
To detect an electrical short or fault condition with resistance higher than 1500 ohm, the Cy_CapSense_GetSensorCapacitance() function can be used as the fault condition affects the measured sensor capacitance.
+
This test can be executed only if the CapSense Middleware is in the IDLE state. This function must not be called while CapSense Middleware is busy.
+
Parameters
+
+
widgetId
Specifies the ID number of the widget. A macro for the widget ID can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as CY_CAPSENSE_<WidgetName>_WDGT_ID.
+
sensorId
Specifies the ID of the sensor (electrode for CSX widgets) within the widget to be tested.
+
+
+
+
For the CSD widgets, a macro for the sensor ID within the specified widget can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_ID.
+
For the CSX widgets, sensorId is an electrode ID and is defined as Rx ID or Tx ID. The first Rx in a widget corresponds to electrodeId = 0, the second Rx in a widget corresponds to electrodeId = 1, and so on. The last Tx in a widget corresponds to electrodeId = (RxNum + TxNum - 1). Macros for Rx and Tx IDs can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as:
Measures the specified CSD sensor / CSX electrode capacitance.
+
This function measures the capacitance of the sensor (electrode for CSX widgets) and returns the measurement status. For a CSX sensor, the measurement is done on either Rx or Tx electrode. For a CSD sensor, measurement is done on a sensor (refer to the sensorId parameter description). If the specified sensor (electrode) is a ganged sensor, the capacitance is measured for all the pins ganged together that belong to this sensor (electrode).
+
The measured capacitance is stored in the .eltdCap[] array. The .ptrEltdCapacitance field of the cy_stc_capsense_widget_config_t structure contains a pointer to the first widget sensor (electrode) element within the .eltdCap[] array.
+
In addition to the measuring sensor (electrode) capacitance, this function is used to identify various fault conditions with sensors such as electrically-opened sensors. For example, the PCB track is broken or shorted to other nodes in the system - in all of these conditions, this function returns elevated capacitance which can be compared against predetermined capacitance for the sensor to detect a fault condition.
+
The sensor capacitance is measured independently of the sensor scan configuration. For the capacitance measurement, the CSD sensing method is used. The measurements consists of up to four scans with different IDAC current. The IDAC current of the first measurement is 6 uA and each next measurement the IDAC current increase by four times. The default scanning parameters are the following:
+
I (6 uA) is the current equal to IDAC Gain * IDAC Code (Compensation IDAC is disabled).
+
Res (12 bits) is the scanning resolution.
+
Vref (1.2 V) is the reference voltage.
+
SnsClk (375 kHz) is the sensor clock frequency.
+
+
If the scanning raw count is within 7.5% to 45% range of a maximum raw count the raw count is converted into capacitance using the following equation:
+
Cs = Rawcount * I / ((2^Res - 1) * Vref * SnsClk)
+
where:
+
Cs is the sensor capacitance.
+
Rawcount is the measured raw count value.
+
+
If the raw count is less than 7.5% of the maximum limit (2^Res - 1), the function stops scanning the sequence and returns the CY_CAPSENSE_BIST_LOW_LIMIT_E status.
+
If the raw count is between 7.5% and 45% of the maximum, the function calculates the sensor capacitance, updates the register map and returns CY_CAPSENSE_BIST_SUCCESS_E status.
+
If the raw count is above 45% of the maximum, the function repeats scanning with a 4x increased IDAC current (up to four scans in total).
+
The minimum measurable input by this function is 1pF and the maximum is either 384pF or limited by the RC time constant (Cs < 1 / (2*5*SnsClk*R), where R is the total sensor series resistance that includes on-chip GPIO resistance ~500 Ohm and external series resistance). The measurement accuracy is about 15%.
+
By default, all CapSense sensors (electrodes) that are not being measured are configured to the strong-drive-low state. The shield electrode is also configured to the strong-drive-low state.
+
By default, the Cmod capacitor is used for the measurement. If a dedicated Cmod is not available (e.g. the design has CSX widgets only), CintA and CintB capacitors are combined together by the firmware to form a single integration capacitor for the measurement.
+
The sensor measurement can be done on all the sensors using the Cy_CapSense_RunSelfTest() function along with the CY_CAPSENSE_BIST_SNS_CAP mask.
+
This function must not be called while the CSD HW block is busy by another state.
+
Parameters
+
+
widgetId
Specifies the ID number of the widget. A macro for the widget ID can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as CY_CAPSENSE_<WidgetName>_WDGT_ID.
+
sensorId
Specifies the ID of the sensor (electrode for CSX widgets) within the widget to be measured.
+
+
+
+
For the CSD widgets, a macro for the sensor ID within the specified widget can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_ID.
+
For the CSX widgets, sensorId is an electrode ID and is defined as Rx ID or Tx ID. The first Rx in a widget corresponds to electrodeId = 0, the second Rx in a widget corresponds to electrodeId = 1, and so on. The last Tx in a widget corresponds to electrodeId = (RxNum + TxNum - 1). Macros for Rx and Tx IDs can be found in the CapSense Configuration header file (cycfg_capsense.h) defined as:
+
CapSense_<WidgetName>_RX<RXNumber>_ID
+
CapSense_<WidgetName>_TX<TXNumber>_ID.
+
+
Parameters
+
+
ptrValue
The pointer to the measured capacitance in femtofarads. The user declares a variable of the uint32_t type and passes the variable pointer as the function parameter. If the ptrValue parameter is NULL, the capacitance value is not returned through the parameter but still stored in the corresponding field of the data structure.
CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes successfully, the result is valid.
+
CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid. The measurement was not executed.
+
CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a previous operation. The measurement was not executed.
+
CY_CAPSENSE_BIST_LOW_LIMIT_E - The measurement was executed and the scanning result is below the minimum possible value. The measurement result could be invalid. The sensor might be shorted to VDD or a sensor PCB track was broken (open sensor).
+
CY_CAPSENSE_BIST_HIGH_LIMIT_E - The measurement was executed and the scanning result is above the maximum possible value. The measurement result could be invalid. The sensor might be shorted to GND.
+
CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during the measurement.
+
CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the configuration. The measurement was not executed.
This function measures the capacitance of the shield electrode and returns a status of this measurement. The measurement result in femtofarads is stored in the .shieldCap field of the cy_stc_capsense_bist_context_t structure. If the shield consists of several electrodes, the total capacitance of all shield electrodes is reported.
+
This function uses an algorithm identical to the sensor capacitance measurement. Refer to the Cy_CapSense_MeasureCapacitanceSensor() function for more details.
+
In addition to measuring shield capacitance, this function is used to identify various fault conditions with a shield electrode such as an electrically open shield electrode, e.g. the PCB track is broken or shorted to other nodes in the system - in all of these conditions, this function returns elevated capacitance that can be compared against pre-determined capacitance for the shield electrode to detect a fault condition.
+
By default, all CapSense sensors (electrodes) are configured to the strong-drive-low state.
+
By default, the Cmod capacitor is used for the measurement. If a dedicated Cmod is not available (e.g. the design has CSX widgets only), CintA and CintB capacitors are combined together by the firmware to form a single integration capacitor which is used for measurement.
+
This test can be executed using the CapSense_RunSelfTest() function with the CY_CAPSENSE_BIST_SHIELD_CAP mask.
+
Parameters
+
+
ptrValue
The pointer to the variable the measured capacitance is stored. The user should declare a variable of uint32_t type and pass the variable pointer as the function parameter. If the ptrValue parameter is NULL then the shield capacitance value is not returned through the parameter but is still stored in the .shieldCap field of the cy_stc_capsense_bist_context_t structure.
CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes successfully, the result is valid.
+
CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid. The measurement was not executed.
+
CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a previous operation. The measurement was not executed.
+
CY_CAPSENSE_BIST_LOW_LIMIT_E - The measurement was executed but the measured raw count is below the minimum possible value. The measurement result could be invalid. The shield might be shorted to VDD or a shield PCB track is broken (the open shield electrode).
+
CY_CAPSENSE_BIST_HIGH_LIMIT_E - The measurement was executed but the measured raw count is above the maximum possible value. The measurement result is invalid. The sensor might be shorted to GND.
+
CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during the measurement.
+
CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the configuration. The measurement was not executed.
Measures the capacitance of the specified CapSense integration (external) capacitor.
+
The function measures the capacitance of the specified external capacitor such as Cmod and returns the result through ptrValue, alternatively the measurement result is stored in the corresponding field of the cy_stc_capsense_bist_context_t structure (either .cModCap, .cIntACap, .cIntBCap, or .cShieldCap).
+
The maximum measurement capacitance is 25nF. The measurement accuracy is up to 15%. The measurement resolution is 10 bit which corresponds to the maximum capacitance specified by the maxCapacitance parameter. The bigger specified maximum capacitance is, the bigger capacitance value is for one measured count. It is recommended to specify the maximum capacitance twice bigger as the nominal capacitor capacitance. For example, if the nominal Cmod value is 2.2nF, the maxCapacitance parameter is set to 4nF-5nF.
+
The function configures all CapSense pins to Strong-drive-low mode that allows detecting a short of the measured capacitor to other pins.
+
To measure all the available capacitors, the Cy_CapSense_RunSelfTest() function can be used with the CY_CAPSENSE_BIST_SNS_SHORT mask. The measured results are stored in the corresponding field of the cy_stc_capsense_bist_context_t structure.
+
Measurement can be done only if the CapSense Middleware is in the IDLE state. This function must not be called while the CapSense Middleware is busy. The function is blocking, i.e. waits for the measurement to be completed prior to returning to the caller.
+
Parameters
+
+
integrationCapId
Indexes of external capacitors to measure their capacitance. There are macros for each of them, namely:
+
CY_CAPSENSE_BIST_CMOD_ID for the CSD method Cmod capacitor
+
CY_CAPSENSE_BIST_CINTA_ID for the CSX method CintA capacitor
+
CY_CAPSENSE_BIST_CINTB_ID for the CSX method CintB capacitor
+
CY_CAPSENSE_BIST_CSH_ID for the CSD method Csh capacitor
+
+
+
ptrValue
The pointer to the result of the measurement. The result is calculated as a specified capacitor capacitance value in picofarads. The user declares a variable of the uint32_t type and passes the pointer to this variable as the function parameter. If the ptrValue parameter is NULL then the capacitance value is not returned through the parameter but stored to the corresponding field of the cy_stc_capsense_bist_context_t structure.
+
maxCapacitance
An expected by the user maximum value of the measured capacitance in nanofarads in the range from 1 to 25 nF.
CY_CAPSENSE_BIST_SUCCESS_E - The measurement completes successfully, the result is valid.
+
CY_CAPSENSE_BIST_BAD_PARAM_E - The input parameter is invalid. The measurement was not executed.
+
CY_CAPSENSE_BIST_HW_BUSY_E - The CSD HW block is busy with a previous operation. The measurement was not executed.
+
CY_CAPSENSE_BIST_LOW_LIMIT_E - The measurement was performed but the scanning result is below the minimum possible value. The measurement result could be invalid. The capacitor might be shorted to VDD or a PCB track is broken (open capacitor).
+
CY_CAPSENSE_BIST_HIGH_LIMIT_E - The measurement was performed but the scanning result is above the maximum possible value. The measurement result could be invalid. The capacitor might be shorted to GND.
+
CY_CAPSENSE_BIST_ERROR_E - An unexpected fault occurred during the measurement.
+
CY_CAPSENSE_BIST_FEATURE_DISABLED_E - The BIST feature is disabled in the configuration. The measurement was not executed.
Measures a VDDA voltage, returns the measured voltage in millivolts through the ptrValue argument and stores it to the .vddaVoltage field of the cy_stc_capsense_bist_context_t structure.
+
This function measures the device analog supply voltage (VDDA) without need of explicitly connecting VDDA to any additional GPIO input. This capability can be used in variate cases, for example to monitor the battery voltage.
+
A measurement can be done only if the CapSense middleware is in the IDLE state. This function must not be called while the CapSense middleware is busy. The function is blocking, i.e. waits for the conversion to be completed prior to returning to the caller.
+
Parameters
+
+
ptrValue
The pointer to the uint32_t to store measured VDDA voltage value. If the ptrValue parameter is NULL then VDDA voltage value is not returned through the parameter and is stored in the .vddaVoltage field of the cy_stc_capsense_bist_context_t structure.
Cy_CapSense_SetPinState() function could be called in StartSample callback (see the Callbacks section for details) or with low-level functions that perform a single-sensor scanning.
+
Functions that perform a setup and scan of a sensor/widget automatically set the required pin states for a sensor as required and overwrite changes made by this function to a sensor that are going to be scanned. Therefore the Cy_CapSense_SetPinState() function could be called in StartSample callback (see the Callbacks section for details) or with low-level functions that perform a single-sensor scanning.
Parameters
widgetId
Specifies the ID number of the widget. A macro for the widget ID can be found in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
Gets a value of the specified parameter from the cy_capsense_tuner structure.
+
This function gets the value of the specified parameter by the paramId argument. The paramId for each register of cy_capsense_tuner is available in the cycfg_capsense.h file as CY_CAPSENSE_<ParameterName>_PARAM_ID. The paramId is a special enumerated value generated by the CapSense Configurator. The format of paramId is as follows:
+
[ byte 3 byte 2 byte 1 byte 0 ]
+
[ RRRRRUTT IIIIIIII MMMMMMMM LLLLLLLL ]
+
U - indicates if the parameter affects the RAM Widget Object CRC.
+
T - encodes the parameter type:
+
01b: uint8_t
+
10b: uint16_t
+
11b: uint32_t
+
+
+
I - specifies that the widgetId parameter belongs to.
+
M,L - the parameter offset MSB and LSB accordingly in cy_capsense_tuner.
+
R - reserved
+
+
Parameters
+
+
paramId
Specifies the ID of parameter to get its value. A macro for the parameter ID can be found in the cycsg_capsense.h file defined as CY_CAPSENSE_<ParameterName>_PARAM_ID.
+
value
The pointer to a variable to be updated with the obtained value.
+
ptrTuner
The pointer to the cy_capsense_tuner variable of cy_stc_capsense_tuner_t. The cy_capsense_tuner is declared in CapSense Configurator generated files:
Sets a new value for the specified parameter in cy_capsense_tuner structure.
+
This function sets the value of the specified parameter by the paramId argument. The paramId for each register of cy_capsense_tuner is available in the cycfg_capsense.h file as CY_CAPSENSE_<ParameterName>_PARAM_ID. The paramId is a special enumerated value generated by the CapSense Configurator. The format of paramId is as follows:
+
[ byte 3 byte 2 byte 1 byte 0 ]
+
[ RRRRRUTT IIIIIIII MMMMMMMM LLLLLLLL ]
+
U - indicates if the parameter affects the RAM Widget Object CRC.
+
T - encodes the parameter type:
+
01b: uint8_t
+
10b: uint16_t
+
11b: uint32_t
+
+
+
I - specifies that the widgetId parameter belongs to
+
M,L - the parameter offset MSB and LSB accordingly in cy_capsense_tuner.
+
R - reserved
+
+
This function writes specified value into the desired register without other registers update. It is application layer responsibility to keep all the data structure registers aligned. Repeated call of Cy_CapSense_Enable() function helps aligning dependent register values.
+
This function updates also the widget CRC field if Built-in Self-test is enabled and paramId requires that.
+
Parameters
+
+
paramId
Specifies the ID of parameter to set its value. A macro for the parameter ID can be found in the cycsg_capsense.h file defined as CY_CAPSENSE_<ParameterName>_PARAM_ID.
+
value
Specifies the new parameter's value.
+
ptrTuner
The pointer to the cy_capsense_tuner variable of cy_stc_capsense_tuner_t. The cy_capsense_tuner is declared in CapSense Configurator generated files:
Returns the status of the operation. If CY_RET_SUCCESS is not received, the parameter was not updated with the new value, either paramId is invalid or ptrTuner is null.
Calculates CRC for the specified buffer and length.
+
This API is used for the CRC protection of a packet received from the CapSense Tuner tool and for BIST operations. CRC polynomial is 0xAC9A. It has a Hamming distance 5 for data words up to 241 bits.
+
Reference: "P. Koopman, T. Chakravarthy,
+"Cyclic Redundancy Code (CRC) Polynomial Selection for Embedded Networks",
+The International Conference on Dependable Systems and Networks, DSN-2004"
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
An error in touch calculation or number of detected touches is above supported touches.
@@ -174,7 +174,7 @@
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
Declares the structure that is intended to store the cy_stc_capsense_widget_context_t data structure fields, the CRC checking should be applied for. More...
If you are doing your own project, remember to include cycfg.h file:
#include "cycfg.h"
and call the resource initialization functions in main() at the beginning:
init_cycfg_clocks();
init_cycfg_routing();
init_cycfg_peripherals();
+
If you are doing your own project, remember to include cycfg.h file:
#include "cycfg.h"
and call the resource initialization functions in main() at the beginning:
init_cycfg_all();
Summary of Application Programming Interface (API)
The CapSense operates on the top of the CapSense Sigma Delta (CSD) driver. Refer to the PDL API Reference Manual.
This document provides descriptions of the functions in the CapSense middleware library, and descriptions of the data structures (register map) used by the middleware library.
@@ -143,22 +143,25 @@
Supported Software and Tools
-
This version of the CapSense Middleware was validated for compatibility with the following Software and Tools:
-
+
This version of the CapSense Middleware was validated for compatibility with the following Software and Tools:
Software and Tools
Version
-
ModusToolbox Software Environment
2.0
+
ModusToolbox Software Environment
2.1
+
+
- ModusToolbox Device Configurator
2.1
-
- ModusToolbox Device Configurator
2.0
+
- ModusToolbox CSD Personality for PSoC4 devices in Device Configurator
1.0
-
- ModusToolbox CSD Personality in Device Configurator
2.0
+
- ModusToolbox CSD Personality for PSoC6 devices in Device Configurator
2.0
-
- ModusToolbox CapSense Configurator tool
2.0
+
- ModusToolbox CapSense Configurator tool
3.0
-
- ModusToolbox CapSense Tuner tool
2.0
+
- ModusToolbox CapSense Tuner tool
3.0
-
PSoC6 Peripheral Driver Library (PDL)
1.2.0
+
PSoC4 Peripheral Driver Library (PDL)
1.0.0
+
+
PSoC6 Peripheral Driver Library (PDL)
1.5.0
GCC Compiler
7.2.1
@@ -166,7 +169,7 @@
Arm Compiler 6 (Note 1)
6.11
-
MBED OS
5.13.1
+
MBED OS (only for PSoC6)
5.15.1
FreeRTOS
10.0.1
@@ -183,7 +186,7 @@
The specified version of the ModusToolbox Device Configurator and the CSD personality are used to re-generate the device configuration.
The specified version of the ModusToolbox CapSense Configurator is used to re-generate the middleware configuration.
The toolchains are set up properly for your environment per the settings outlined in the Supported Software and Tools.
-
The project is re-built once the the toolchains are configured and the configuration is completed.
+
The project is re-built once the toolchains are configured and the configuration is completed.
You might need to re-generate the configuration structures for either the device initialization code or the middleware initialization code.
Launch the ModusToolbox Device Configurator and perform the File->Save command to re-generate the device initialization code.
@@ -199,67 +202,69 @@
The measurements were done with GCC compiler configured in the Release mode with optimization set for Size.
-
Configuration:
Configuration 1
Configuration 2
Configuration 3
Configuration 4
Configuration 5
+
Configuration:
Configuration 1
Configuration 2
Configuration 3
Configuration 4
Configuration 5
Configuration 6
Configuration 7
+
+
Flash:
< 13600
< 15750
< 18700
< 20300
< 28400
< 19900
< 34700
-
Flash:
< 12000
< 14050
< 17400
< 18600
< 27000
+
SRAM:
< 400
< 730
< 2200
< 1080
< 4280
< 600
< 4480
-
SRAM:
< 370
< 700
< 2180
< 1050
< 4250
+
Widgets
-
Widgets
+
CSD Button
1 (6 sensors)
1 (6 sensors)
1 (2 sensors)
1 (6 sensors)
1 (6 sensors)
1 (6 sensors)
-
CSD Button
1 (6 sensors)
1 (6 sensors)
1 (2 sensors)
1 (6 sensors)
+
CSD Matrix Buttons
-
CSD Matrix Buttons
+
CSD Slider
1 (9 segments)
1 (9 segments)
1 (9 segments)
-
CSD Slider
1 (9 segments)
1 (9 segments)
+
CSD Touchpad
1 (9 Cols and 8 Rows)
1 (9 Cols and 8 Rows)
1 (9 Cols and 8 Rows)
-
CSD Touchpad
1 (9 Cols and 8 Rows)
1 (9 Cols and 8 Rows)
+
CSD Proximity
1 (1 sensor)
1 (1 sensor)
1 (1 sensor)
1 (1 sensor)
-
CSD Proximity
1 (1 sensor)
1 (1 sensor)
1 (1 sensor)
+
CSX Button
-
CSX Button
+
CSX Matrix Buttons
1 (3 Rx and 3 Tx)
1 (3 Rx and 3 Tx)
-
CSX Matrix Buttons
1 (3 Rx and 3 Tx)
+
CSX Touchpad
1 (9 Rx and 8 Tx)
1 (9 Rx and 8 Tx)
1 (9 Rx and 8 Tx)
-
CSX Touchpad
1 (9 Rx and 8 Tx)
1 (9 Rx and 8 Tx)
+
Features
-
Features
+
Gesture
enabled
enabled
enabled
enabled
-
Gesture
enabled
enabled
enabled
+
Ballistic Multiplier
enabled
enabled
enabled
-
Ballistic Multiplier
enabled
enabled
+
Centroid Type
3x3
3x3
5x5 CSD, 3x3 CSX
5x5 CSD, 3x3 CSX
-
Centroid Type
3x3
3x3
5x5 CSD, 3x3 CSX
+
Supported fingers on touchpad
2
1
2
2
-
Supported fingers on touchpad
2
1
2
+
Shield
enabled
enabled
enabled
enabled
-
Shield
enabled
enabled
enabled
+
SmartSense
enabled
enabled
-
SmartSense
enabled
+
CSD auto-calibration
enabled
enabled
enabled
enabled
enabled
enabled
-
CSD auto-calibration
enabled
enabled
enabled
enabled
+
CSX auto-calibration
enabled
enabled
enabled
-
CSX auto-calibration
enabled
enabled
+
Self-test
enabled
enabled
-
Raw Count Filters
+
Raw Count Filters
-
IIR
enabled
enabled
enabled
+
IIR
enabled
enabled
enabled
enabled
-
Median
enabled
enabled
enabled
+
Median
enabled
enabled
enabled
enabled
-
Average
+
Average
-
Position Filters
+
Position Filters
-
IIR
+
IIR
-
Median
enabled
enabled
enabled
+
Median
enabled
enabled
enabled
enabled
-
Average
+
Average
-
Adaptive IIR
enabled
enabled
enabled
+
Adaptive IIR
enabled
enabled
enabled
enabled
-
Jitter
enabled
enabled
enabled
+
Jitter
enabled
enabled
enabled
enabled
MISRA-C Compliance
@@ -284,6 +289,23 @@
319100
GPIO simultaneous operation with unrestricted strength and frequency creates noise that can affect CapSense operation.
Scanning a sensor with low capacitance (about 8pF and less) with low frequency (around 300kHz and less) might lead to raw count variation from scan to scan.
There are several possible workarounds:
+
Increase the Scan resolution.
+
Increase the Sense clock frequency. For the best results, perform scanning with as high as possible Sense clock frequency.
+
If shield is required for a design, enable the shield tank (Csh) capacitor.
+
Increase the sensor capacitance by changing its layout or introduce extra capacitor between the sensor pin and ground.
+
Increase number of Fine initialization cycles. Open the cycfg_capsense.c file and modify the .csdFineInitTime field of the cy_capsense_commonConfig structure.
+
Increase the CSD init switch resistance. Open the cycfg_capsernse.c file and update the .csdInitSwRes field of the cy_capsense_commonConfig structure with the CY_CAPSENSE_INIT_SW_RES_HIGH value.
+
+
+
+
3191
Channel 0 is scanned with the incorrect settings when all of the following conditions are met:
+
Added memory usage section to the CapSense API Ref Guide
User experience improvement
Updated documentation
User experience improvement
@@ -339,7 +392,7 @@
More Information
-
Important information about the CapSense-technology overview, appropriate Cypress device for the design, CapSense system and sensor design guidelines, different interfaces and tuning guidelines necessary for a successful design of a CapSense system is available in the Getting Started with CapSense document and the product-specific CapSense design guide. Cypress highly recommends starting with these documents. They can be found on the Cypress web site at www.cypress.com. For details about application notes, code examples, and kits, see the References section in this datasheet.
+
Important information about the CapSense-technology overview, appropriate Cypress device for the design, CapSense system and sensor design guidelines, different interfaces and tuning guidelines necessary for a successful design of a CapSense system is available in the Getting Started with CapSense document and the product-specific CapSense design guide. Cypress highly recommends starting with these documents. They can be found on the Cypress web site at www.cypress.com.
For more information, refer to the following documents:
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
Callbacks allow the user to execute Custom code called from the CapSense middleware when an event occurs
@@ -109,7 +110,7 @@
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
The minimum value is 1 and the maximum depends on a divider type, but for a reliable CSD HW block operation, it is recommended to provide a modulation clock frequency in the range from 1 to 50 MHz
The minimum value is 4 and the maximum is 4095, but for a reliable CSD HW block operation, it is recommended to provide an sensor clock frequency in the range from 100 to 6000 kHz
The maximum raw counts is equal (convNum * snsClkDivider - 1), that corresponds to (2^Resolution - 1) in older notations. The minimum value is 4 and the maximum is 65535, but as the maximum raw counts is 65535, the convNum value should be less than (65536 / snsClkDivider)
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
The Cy_CapSense_BistDsInitialize() function pointer.
+
@@ -242,7 +254,7 @@
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
Internal pre-calculated data for faster operation.
@@ -226,7 +242,7 @@
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.
- Generated for Cypress CapSense Middleware Library 2.0 by Cypress Semiconductor Corporation.
+ Generated for Cypress CapSense Middleware Library 2.10 by Cypress Semiconductor Corporation.
All rights reserved.